commit 36629604f4fb46a0fcde9e8da0ef8fc5d9c5d84d
parent f5c92970174dd6999b74217f7d39bc2a5eda0d69
Author: erai <erai@omiltem.net>
Date: Wed, 20 Nov 2024 22:34:47 -0500
convert colon cast to as
Diffstat:
M | alloc.om | | | 12 | ++++++------ |
M | as.om | | | 48 | ++++++++++++++++++++++++------------------------ |
M | bufio.om | | | 22 | +++++++++++----------- |
M | cc1.om | | | 152 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | chacha20.om | | | 102 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | cout.om | | | 36 | ++++++++++++++++++------------------ |
M | cpio.om | | | 4 | ++-- |
M | decl.om | | | 34 | +++++++++++++++++----------------- |
M | ed25519.om | | | 310 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | genlex.om | | | 74 | +++++++++++++++++++++++++++++++++++++------------------------------------- |
M | kernel.om | | | 934 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | lib.om | | | 74 | +++++++++++++++++++++++++++++++++++++------------------------------------- |
M | ls.om | | | 2 | +- |
M | node.om | | | 18 | +++++++++--------- |
M | parse2.om | | | 28 | ++++++++++++++-------------- |
M | peg.om | | | 40 | ++++++++++++++++++++-------------------- |
M | peglib.om | | | 52 | ++++++++++++++++++++++++++-------------------------- |
M | poly1305.om | | | 54 | +++++++++++++++++++++++++++--------------------------- |
M | sh.om | | | 48 | ++++++++++++++++++++++++------------------------ |
M | sha256.om | | | 238 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | sha512.om | | | 74 | +++++++++++++++++++++++++++++++++++++------------------------------------- |
M | sshd.om | | | 242 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | syscall.om | | | 30 | +++++++++++++++--------------- |
M | type.om | | | 16 | ++++++++-------- |
24 files changed, 1322 insertions(+), 1322 deletions(-)
diff --git a/alloc.om b/alloc.om
@@ -9,7 +9,7 @@ struct alloc {
}
setup_alloc(c: *alloc) {
- c.page = 0: *page;
+ c.page = 0 as *page;
}
alloc(c: *alloc, size: int): *byte {
@@ -29,16 +29,16 @@ alloc(c: *alloc, size: int): *byte {
if (mret == -1) {
die("out of memory");
}
- ret = mret: *byte;
+ ret = mret as *byte;
return ret;
}
page = c.page;
if (page) {
if (size <= page.size - page.fill) {
- mret = page.ptr:int + page.fill;
+ mret = page.ptr as int + page.fill;
page.fill = page.fill + size;
- ret = mret: *byte;
+ ret = mret as *byte;
return ret;
}
}
@@ -50,8 +50,8 @@ alloc(c: *alloc, size: int): *byte {
die("out of memory");
}
- page = mret: *page;
- page.ptr = (&page[1]): *byte;
+ page = mret as *page;
+ page.ptr = (&page[1]) as *byte;
ret = page.ptr;
page.size = psize - sizeof(*page);
page.fill = size;
diff --git a/as.om b/as.om
@@ -194,14 +194,14 @@ struct symbol {
setup_assembler(a: *alloc): *assembler {
var c: *assembler;
- c = alloc(a, sizeof(*c)): *assembler;
+ c = alloc(a, sizeof(*c)) as *assembler;
c.a = a;
- c.out = 0: *file;
+ c.out = 0 as *file;
c.at = 160; // elf header + program header + multiboot header
- c.text = 0:*chunk;
- c.text_end = 0:*chunk;
+ c.text = 0 as *chunk;
+ c.text_end = 0 as *chunk;
c.bits32 = 0;
- c.symbols = 0:*symbol;
+ c.symbols = 0 as *symbol;
c.num_sections = 0;
add_section(c, "", SHT_NULL);
add_section(c, ".text", SHT_PROGBITS);
@@ -217,9 +217,9 @@ add_section(c: *assembler, name: *byte, type: int) {
emit_align(c, 16, OP_NOP);
- s = alloc(c.a, sizeof(*s)):*section;
+ s = alloc(c.a, sizeof(*s)) as *section;
- s.next = 0:*section;
+ s.next = 0 as *section;
s.name = name;
s.start = c.at;
s.end = c.at;
@@ -287,9 +287,9 @@ open_output(c: *assembler, filename: *byte) {
mklabel(c: *assembler): *label {
var l: *label;
- l = alloc(c.a, sizeof(*l)):*label;
+ l = alloc(c.a, sizeof(*l)) as *label;
- l.fix = 0:*fixup;
+ l.fix = 0 as *fixup;
l.at = 0;
l.fixed = 0;
@@ -310,12 +310,12 @@ reserve(c: *assembler, n: int) {
}
m = alloc(c.a, n);
- b = alloc(c.a, sizeof(*b)):*chunk;
+ b = alloc(c.a, sizeof(*b)) as *chunk;
b.buf = m;
b.fill = 0;
b.cap = n;
- b.next = 0:*chunk;
+ b.next = 0 as *chunk;
if (c.text_end) {
c.text_end.next = b;
@@ -329,17 +329,17 @@ reserve(c: *assembler, n: int) {
// Add a single byte to the output
emit(c: *assembler, x: int) {
reserve(c, 1);
- c.text_end.buf[c.text_end.fill] = x:byte;
+ c.text_end.buf[c.text_end.fill] = x as byte;
c.text_end.fill = c.text_end.fill + 1;
c.at = c.at + 1;
}
// Fix a single reference
fixup(c: *assembler, here: *byte, delta: int) {
- here[0] = delta: byte;
- here[1] = (delta >> 8): byte;
- here[2] = (delta >> 16): byte;
- here[3] = (delta >> 24): byte;
+ here[0] = delta as byte;
+ here[1] = (delta >> 8) as byte;
+ here[2] = (delta >> 16) as byte;
+ here[3] = (delta >> 24) as byte;
}
// Add an new fixup for the current position
@@ -356,7 +356,7 @@ addfixup(c: *assembler, l: *label) {
if (l.fixed) {
fixup(c, here, l.at - c.at);
} else {
- f = alloc(c.a, sizeof(*f)): *fixup;
+ f = alloc(c.a, sizeof(*f)) as *fixup;
f.next = l.fix;
f.ptr = here;
@@ -390,7 +390,7 @@ fixup_label(c: *assembler, l: *label) {
add_symbol(c: *assembler, name: *byte, l: *label) {
var s: *symbol;
- s = alloc(c.a, sizeof(*s)):*symbol;
+ s = alloc(c.a, sizeof(*s)) as *symbol;
s.next = c.symbols;
s.name = name;
@@ -437,7 +437,7 @@ emit_blob(c: *assembler, s: *byte, n: int) {
if i == n {
break;
}
- as_emit(c, s[i]:int);
+ as_emit(c, s[i] as int);
i = i + 1;
}
as_emit(c, 0);
@@ -472,7 +472,7 @@ emit_str(c: *assembler, s: *byte) {
if (!s[i]) {
break;
}
- as_emit(c, s[i]:int);
+ as_emit(c, s[i] as int);
i = i + 1;
}
as_emit(c, 0);
@@ -928,7 +928,7 @@ emit_strtab_str(c: *assembler, s: *byte): int {
i = 0;
loop {
- as_emit(c, s[i]:int);
+ as_emit(c, s[i] as int);
if !s[i] {
break;
@@ -953,7 +953,7 @@ emit_sections(c: *assembler): int {
var y: *symbol;
var n: int;
- add_symbol(c, "", 0:*label);
+ add_symbol(c, "", 0 as *label);
s = find_section(c, "");
s.start = 0;
@@ -1222,7 +1222,7 @@ writeout(c: *assembler, start: *label, kstart: *label) {
kentry = 0;
}
- shoff = emit_sections(c: *assembler);
+ shoff = emit_sections(c as *assembler);
// magic
putchar(c, 0x7f);
@@ -1470,7 +1470,7 @@ writeout(c: *assembler, start: *label, kstart: *label) {
if (i >= b.fill) {
break;
}
- putchar(c, b.buf[i]: int);
+ putchar(c, b.buf[i] as int);
i = i + 1;
}
b = b.next;
diff --git a/bufio.om b/bufio.om
@@ -11,7 +11,7 @@ struct file {
fopen(fd: int, a: *alloc): *file {
var f: *file;
- f = alloc(a, sizeof(*f)): *file;
+ f = alloc(a, sizeof(*f)) as *file;
f.fd = fd;
f.a = a;
@@ -34,7 +34,7 @@ fclose(f: *file): void {
free(f.a, f.buf);
- free(f.a, f: *byte);
+ free(f.a, f as *byte);
}
fflush(f: *file): void {
@@ -91,7 +91,7 @@ fputc(f: *file, ch: int): void {
fflush(f);
}
- f.buf[f.w] = ch: byte;
+ f.buf[f.w] = ch as byte;
f.w = f.w + 1;
if (ch == '\n') {
@@ -110,7 +110,7 @@ fgetc(f: *file): int {
return -1;
}
- ch = f.buf[f.r]: int;
+ ch = f.buf[f.r] as int;
f.r = f.r + 1;
@@ -122,24 +122,24 @@ fgets(f: *file, buf: *byte, len: int): int {
var c: int;
if len == 1 {
- buf[0] = 0:byte;
+ buf[0] = 0 as byte;
return 0;
}
i = 0;
loop {
if i + 1 == len {
- buf[i] = 0:byte;
+ buf[i] = 0 as byte;
return i;
}
c = fgetc(f);
if c == -1 || c == '\n' {
- buf[i] = 0:byte;
+ buf[i] = 0 as byte;
return i;
}
- buf[i] = c:byte;
+ buf[i] = c as byte;
i = i + 1;
}
}
@@ -151,7 +151,7 @@ fputs(f: *file, s: *byte) {
if !s[i] {
break;
}
- fputc(f, s[i]:int);
+ fputc(f, s[i] as int);
i = i + 1;
}
}
@@ -163,7 +163,7 @@ fputb(f: *file, s: *byte, n: int) {
if i >= n {
break;
}
- fputc(f, s[i]:int);
+ fputc(f, s[i] as int);
i = i + 1;
}
}
@@ -225,7 +225,7 @@ freadall(f: *file, size: *int): *byte {
}
}
- ret[i] = ch:byte;
+ ret[i] = ch as byte;
i = i + 1;
}
}
diff --git a/cc1.om b/cc1.om
@@ -51,27 +51,27 @@ cdie(c: *compiler, msg: *byte) {
comp_setup(a: *alloc): *compiler {
var c: *compiler;
- c = alloc(a, sizeof(*c)): *compiler;
+ c = alloc(a, sizeof(*c)) as *compiler;
c.a = a;
c.p = setup_parser(a);
- c.filename = 0:*byte;
+ c.filename = 0 as *byte;
c.lineno = 0;
c.colno = 0;
c.s = setup_assembler(a);
- c.decls = 0:*decl;
+ c.decls = 0 as *decl;
c.do_cout = 0;
- c.cout = 0:*file;
+ c.cout = 0 as *file;
- c.start = 0:*label;
- c.kstart = 0:*label;
+ c.start = 0 as *label;
+ c.kstart = 0 as *label;
- c.used_top = 0:*decl;
+ c.used_top = 0 as *decl;
return c;
}
@@ -169,13 +169,13 @@ compile(c: *compiler, p: *node) {
}
// Check usage
- d = find(c, "_start", 0:*byte, 0);
+ d = find(c, "_start", 0 as *byte, 0);
if (d && d.func_defined) {
c.start = d.func_label;
mark_func_used(c, d);
}
- d = find(c, "_kstart", 0:*byte, 0);
+ d = find(c, "_kstart", 0 as *byte, 0);
if (d && d.func_defined) {
c.kstart = d.func_label;
mark_func_used(c, d);
@@ -233,7 +233,7 @@ mark_expr_used(c: *compiler, d: *decl, n: *node) {
}
return;
} else if kind == N_IDENT {
- v = find(c, n.s, 0:*byte, 0);
+ v = find(c, n.s, 0 as *byte, 0);
if v && v.enum_defined {
return;
}
@@ -243,7 +243,7 @@ mark_expr_used(c: *compiler, d: *decl, n: *node) {
return;
}
- v = find(c, n.s, 0:*byte, 0);
+ v = find(c, n.s, 0 as *byte, 0);
if v && v.func_defined {
mark_func_used(c, v);
return;
@@ -352,7 +352,7 @@ defextern(c: *compiler, n: *node): *decl {
t = prototype(c, n.b);
- d = find(c, name, 0:*byte, 1);
+ d = find(c, name, 0 as *byte, 1);
if (d.func_defined) {
cdie(c, "duplicate function");
@@ -425,7 +425,7 @@ defstruct(c: *compiler, n: *node) {
cdie(c, "reserved word");
}
- d = find(c, name, 0:*byte, 1);
+ d = find(c, name, 0 as *byte, 1);
if (d.struct_defined) {
cdie(c, "duplicate struct");
@@ -449,7 +449,7 @@ defunion(c: *compiler, n: *node) {
cdie(c, "reserved word");
}
- d = find(c, name, 0:*byte, 1);
+ d = find(c, name, 0 as *byte, 1);
if (d.struct_defined) {
cdie(c, "duplicate struct");
@@ -476,7 +476,7 @@ defenum(c: *compiler, n: *node) {
c.colno = n.a.colno;
name = n.a.a.s;
- d = find(c, name, 0:*byte, 1);
+ d = find(c, name, 0 as *byte, 1);
if (d.enum_defined) {
cdie(c, "duplicate enum");
@@ -622,7 +622,7 @@ compile_func(c: *compiler, d: *decl) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
emit_preamble(c.s, d.func_preamble, pragma);
- compile_stmt(c, d, d.func_def.b, 0:*label, 0:*label);
+ compile_stmt(c, d, d.func_def.b, 0 as *label, 0 as *label);
emit_num(c.s, 0);
if (pragma) {
@@ -685,7 +685,7 @@ typecheck_expr(c: *compiler, d: *decl, n: *node, rhs: int) {
}
if (n.a.kind == N_IDENT) {
- v = find(c, n.a.s, 0:*byte, 0);
+ v = find(c, n.a.s, 0 as *byte, 0);
if (v && v.enum_defined) {
cdie(c, "type error");
}
@@ -694,13 +694,13 @@ typecheck_expr(c: *compiler, d: *decl, n: *node, rhs: int) {
if (v && v.var_defined) {
n.a.t = v.var_type;
} else if !strcmp(n.a.s, "_include") {
- v = find(c, n.a.s, 0:*byte, 0);
+ v = find(c, n.a.s, 0 as *byte, 0);
if (!v || !v.func_defined) {
cdie(c, "no such function");
}
n.a.t = v.func_type;
} else {
- v = find(c, n.a.s, 0:*byte, 0);
+ v = find(c, n.a.s, 0 as *byte, 0);
if (!v || !v.func_defined) {
cdie(c, "no such function");
}
@@ -717,7 +717,7 @@ typecheck_expr(c: *compiler, d: *decl, n: *node, rhs: int) {
if (n.b) {
unify(c, n.a.t.arg, n.b.t);
} else {
- unify(c, n.a.t.arg, 0: *type);
+ unify(c, n.a.t.arg, 0 as *type);
}
n.t = n.a.t.val;
@@ -744,7 +744,7 @@ typecheck_expr(c: *compiler, d: *decl, n: *node, rhs: int) {
n.t = v.member_type;
} else if (kind == N_IDENT) {
- v = find(c, n.s, 0:*byte, 0);
+ v = find(c, n.s, 0 as *byte, 0);
if (v && v.enum_defined) {
n.t = mktype0(c, TY_INT);
return;
@@ -756,7 +756,7 @@ typecheck_expr(c: *compiler, d: *decl, n: *node, rhs: int) {
return;
}
- v = find(c, n.s, 0:*byte, 0);
+ v = find(c, n.s, 0 as *byte, 0);
if (v && v.func_defined) {
n.t = v.func_type;
return;
@@ -1350,7 +1350,7 @@ compile_expr(c: *compiler, d: *decl, n: *node, rhs: int) {
}
if (n.a.kind == N_IDENT) {
- v = find(c, n.a.s, 0:*byte, 0);
+ v = find(c, n.a.s, 0 as *byte, 0);
if (v && v.enum_defined) {
cdie(c, "type error");
}
@@ -1361,10 +1361,10 @@ compile_expr(c: *compiler, d: *decl, n: *node, rhs: int) {
emit_load(c.s, n.a.t);
emit_call(c.s, count_args(c, n.a.t.arg));
} else if !strcmp(n.a.s, "_include") {
- v = find(c, n.a.s, 0:*byte, 0);
+ v = find(c, n.a.s, 0 as *byte, 0);
compile_include(c, n);
} else {
- v = find(c, n.a.s, 0:*byte, 0);
+ v = find(c, n.a.s, 0 as *byte, 0);
emit_lcall(c.s, v.func_label, count_args(c, n.a.t.arg));
}
} else {
@@ -1375,7 +1375,7 @@ compile_expr(c: *compiler, d: *decl, n: *node, rhs: int) {
if (n.b) {
unify(c, n.a.t.arg, n.b.t);
} else {
- unify(c, n.a.t.arg, 0: *type);
+ unify(c, n.a.t.arg, 0 as *type);
}
} else if (kind == N_DOT) {
compile_expr(c, d, n.a, 0);
@@ -1394,7 +1394,7 @@ compile_expr(c: *compiler, d: *decl, n: *node, rhs: int) {
emit_load(c.s, n.t);
}
} else if (kind == N_IDENT) {
- v = find(c, n.s, 0:*byte, 0);
+ v = find(c, n.s, 0 as *byte, 0);
if (v && v.enum_defined) {
emit_num(c.s, v.enum_value);
return;
@@ -1409,7 +1409,7 @@ compile_expr(c: *compiler, d: *decl, n: *node, rhs: int) {
return;
}
- v = find(c, n.s, 0:*byte, 0);
+ v = find(c, n.s, 0 as *byte, 0);
if (v && v.func_defined) {
emit_ptr(c.s, v.func_label);
return;
@@ -1663,7 +1663,7 @@ compile_stmt(c: *compiler, d: *decl, n: *node, top: *label, out: *label) {
kind = n.kind;
if (kind == N_CONDLIST) {
ifout = mklabel(c.s);
- no = 0: *label;
+ no = 0 as *label;
loop {
if (no) {
fixup_label(c.s, no);
@@ -1811,7 +1811,7 @@ emit_ssr(c: *compiler) {
as_opr(c.s, OP_PUSHR, R_RAX);
- d = find(c, "_ssr", 0:*byte, 1);
+ d = find(c, "_ssr", 0 as *byte, 1);
if (d.func_defined && d.func_label.fixed) {
as_jmp(c.s, OP_CALL, d.func_label);
}
@@ -1928,7 +1928,7 @@ emit_isr(c: *compiler) {
as_modrm(c.s, OP_LOAD, R_RAX, R_RBP, 0, 0, 176 + 48);
as_modrm(c.s, OP_STORE, R_RAX, R_RBP, 0, 0, 152);
- d = find(c, "_isr", 0:*byte, 1);
+ d = find(c, "_isr", 0 as *byte, 1);
if (d.func_defined && d.func_label.fixed) {
as_jmp(c.s, OP_CALL, d.func_label);
}
@@ -1975,7 +1975,7 @@ emit_isr(c: *compiler) {
emit_builtin(c: *compiler) {
var d: *decl;
- d = find(c, "syscall", 0:*byte, 1);
+ d = find(c, "syscall", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -1984,14 +1984,14 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "_restorer", 0:*byte, 1);
+ d = find(c, "_restorer", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
emit_restorer(c.s);
}
- d = find(c, "_include", 0:*byte, 1);
+ d = find(c, "_include", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2001,7 +2001,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "ud2", 0:*byte, 1);
+ d = find(c, "ud2", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2011,7 +2011,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "cpuid", 0:*byte, 1);
+ d = find(c, "cpuid", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2037,7 +2037,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "inb", 0:*byte, 1);
+ d = find(c, "inb", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2048,7 +2048,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "outb", 0:*byte, 1);
+ d = find(c, "outb", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2060,7 +2060,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "inw", 0:*byte, 1);
+ d = find(c, "inw", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2072,7 +2072,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "outw", 0:*byte, 1);
+ d = find(c, "outw", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2085,7 +2085,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "ind", 0:*byte, 1);
+ d = find(c, "ind", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2096,7 +2096,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "outd", 0:*byte, 1);
+ d = find(c, "outd", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2108,7 +2108,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "rdmsr", 0:*byte, 1);
+ d = find(c, "rdmsr", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2122,7 +2122,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "wrmsr", 0:*byte, 1);
+ d = find(c, "wrmsr", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2137,7 +2137,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "rdcr0", 0:*byte, 1);
+ d = find(c, "rdcr0", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2147,7 +2147,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "wrcr0", 0:*byte, 1);
+ d = find(c, "wrcr0", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2158,7 +2158,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "rdcr2", 0:*byte, 1);
+ d = find(c, "rdcr2", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2168,7 +2168,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "wrcr2", 0:*byte, 1);
+ d = find(c, "wrcr2", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2179,7 +2179,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "rdcr3", 0:*byte, 1);
+ d = find(c, "rdcr3", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2189,7 +2189,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "wrcr3", 0:*byte, 1);
+ d = find(c, "wrcr3", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2200,7 +2200,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "rdcr4", 0:*byte, 1);
+ d = find(c, "rdcr4", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2210,7 +2210,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "wrcr4", 0:*byte, 1);
+ d = find(c, "wrcr4", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2221,7 +2221,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "lgdt", 0:*byte, 1);
+ d = find(c, "lgdt", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2238,7 +2238,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "lidt", 0:*byte, 1);
+ d = find(c, "lidt", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2255,7 +2255,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "lldt", 0:*byte, 1);
+ d = find(c, "lldt", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2266,7 +2266,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "ltr", 0:*byte, 1);
+ d = find(c, "ltr", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2277,7 +2277,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "lseg", 0:*byte, 1);
+ d = find(c, "lseg", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2313,7 +2313,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "hlt", 0:*byte, 1);
+ d = find(c, "hlt", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2323,7 +2323,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "cli", 0:*byte, 1);
+ d = find(c, "cli", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2333,7 +2333,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "sti", 0:*byte, 1);
+ d = find(c, "sti", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2343,7 +2343,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "rdflags", 0:*byte, 1);
+ d = find(c, "rdflags", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2352,7 +2352,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "wrflags", 0:*byte, 1);
+ d = find(c, "wrflags", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2364,7 +2364,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "wbinvld", 0:*byte, 1);
+ d = find(c, "wbinvld", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2375,7 +2375,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "invlpg", 0:*byte, 1);
+ d = find(c, "invlpg", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2386,21 +2386,21 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "_ssr0", 0:*byte, 1);
+ d = find(c, "_ssr0", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
emit_ssr(c);
}
- d = find(c, "_isr0", 0:*byte, 1);
+ d = find(c, "_isr0", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
emit_isr(c);
}
- d = find(c, "_rgs", 0:*byte, 1);
+ d = find(c, "_rgs", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2412,7 +2412,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "_r32", 0:*byte, 1);
+ d = find(c, "_r32", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2425,7 +2425,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "_w32", 0:*byte, 1);
+ d = find(c, "_w32", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2439,7 +2439,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "_r16", 0:*byte, 1);
+ d = find(c, "_r16", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2453,7 +2453,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "_w16", 0:*byte, 1);
+ d = find(c, "_w16", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2467,7 +2467,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "_rdrand", 0:*byte, 1);
+ d = find(c, "_rdrand", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2477,7 +2477,7 @@ emit_builtin(c: *compiler) {
emit_ret(c.s);
}
- d = find(c, "taskswitch", 0:*byte, 1);
+ d = find(c, "taskswitch", 0 as *byte, 1);
if (d.func_defined && !d.func_label.fixed) {
fixup_label(c.s, d.func_label);
add_symbol(c.s, d.name, d.func_label);
@@ -2636,12 +2636,12 @@ main(argc: int, argv: **byte, envp: **byte) {
continue;
}
- if (argv[i][0] == '-':byte) {
+ if (argv[i][0] == '-' as byte) {
die("invalid argument");
}
- tmp = alloc(&a, sizeof(*tmp)):*name_node;
- tmp.next = 0:*name_node;
+ tmp = alloc(&a, sizeof(*tmp)) as *name_node;
+ tmp.next = 0 as *name_node;
tmp.name = argv[i];
*link = tmp;
link = &tmp.next;
diff --git a/chacha20.om b/chacha20.om
@@ -48,61 +48,61 @@ chacha20_block(block: *byte, key: *byte, counter: int, nonce: *byte) {
var s: *int;
var i: int;
- initial = (&_initial):*int;
- s = (&_s):*int;
+ initial = (&_initial) as *int;
+ s = (&_s) as *int;
s[0] = 0x61707865;
s[1] = 0x3320646e;
s[2] = 0x79622d32;
s[3] = 0x6b206574;
- s[4] = key[0]:int
- | (key[1]:int << 8)
- | (key[2]:int << 16)
- | (key[3]:int << 24);
- s[5] = key[4]:int
- | (key[5]:int << 8)
- | (key[6]:int << 16)
- | (key[7]:int << 24);
- s[6] = key[8]:int
- | (key[9]:int << 8)
- | (key[10]:int << 16)
- | (key[11]:int << 24);
- s[7] = key[12]:int
- | (key[13]:int << 8)
- | (key[14]:int << 16)
- | (key[15]:int << 24);
- s[8] = key[16]:int
- | (key[17]:int << 8)
- | (key[18]:int << 16)
- | (key[19]:int << 24);
- s[9] = key[20]:int
- | (key[21]:int << 8)
- | (key[22]:int << 16)
- | (key[23]:int << 24);
- s[10] = key[24]:int
- | (key[25]:int << 8)
- | (key[26]:int << 16)
- | (key[27]:int << 24);
- s[11] = key[28]:int
- | (key[29]:int << 8)
- | (key[30]:int << 16)
- | (key[31]:int << 24);
+ s[4] = key[0] as int
+ | (key[1] as int << 8)
+ | (key[2] as int << 16)
+ | (key[3] as int << 24);
+ s[5] = key[4] as int
+ | (key[5] as int << 8)
+ | (key[6] as int << 16)
+ | (key[7] as int << 24);
+ s[6] = key[8] as int
+ | (key[9] as int << 8)
+ | (key[10] as int << 16)
+ | (key[11] as int << 24);
+ s[7] = key[12] as int
+ | (key[13] as int << 8)
+ | (key[14] as int << 16)
+ | (key[15] as int << 24);
+ s[8] = key[16] as int
+ | (key[17] as int << 8)
+ | (key[18] as int << 16)
+ | (key[19] as int << 24);
+ s[9] = key[20] as int
+ | (key[21] as int << 8)
+ | (key[22] as int << 16)
+ | (key[23] as int << 24);
+ s[10] = key[24] as int
+ | (key[25] as int << 8)
+ | (key[26] as int << 16)
+ | (key[27] as int << 24);
+ s[11] = key[28] as int
+ | (key[29] as int << 8)
+ | (key[30] as int << 16)
+ | (key[31] as int << 24);
s[12] = counter & (-1 >> 32);
- s[13] = nonce[0]:int
- | (nonce[1]:int << 8)
- | (nonce[2]:int << 16)
- | (nonce[3]:int << 24);
- s[14] = nonce[4]:int
- | (nonce[5]:int << 8)
- | (nonce[6]:int << 16)
- | (nonce[7]:int << 24);
- s[15] = nonce[8]:int
- | (nonce[9]:int << 8)
- | (nonce[10]:int << 16)
- | (nonce[11]:int << 24);
+ s[13] = nonce[0] as int
+ | (nonce[1] as int << 8)
+ | (nonce[2] as int << 16)
+ | (nonce[3] as int << 24);
+ s[14] = nonce[4] as int
+ | (nonce[5] as int << 8)
+ | (nonce[6] as int << 16)
+ | (nonce[7] as int << 24);
+ s[15] = nonce[8] as int
+ | (nonce[9] as int << 8)
+ | (nonce[10] as int << 16)
+ | (nonce[11] as int << 24);
i = 0;
loop {
@@ -143,10 +143,10 @@ chacha20_block(block: *byte, key: *byte, counter: int, nonce: *byte) {
if i == 16 {
break;
}
- block[i * 4] = s[i]:byte;
- block[i * 4 + 1] = (s[i] >> 8):byte;
- block[i * 4 + 2] = (s[i] >> 16):byte;
- block[i * 4 + 3] = (s[i] >> 24):byte;
+ block[i * 4] = s[i] as byte;
+ block[i * 4 + 1] = (s[i] >> 8) as byte;
+ block[i * 4 + 2] = (s[i] >> 16) as byte;
+ block[i * 4 + 3] = (s[i] >> 24) as byte;
i = i + 1;
}
}
@@ -157,7 +157,7 @@ chacha20_stream(cipher: *byte, plain: *byte, len: int, index: *int, key: *byte,
var i: int;
var j: int;
- block = (&_block):*byte;
+ block = (&_block) as *byte;
j = 0;
loop {
diff --git a/cout.om b/cout.om
@@ -147,9 +147,9 @@ ctranslate_type2(c: *compiler, ty: *type, name: *byte, args: *node) {
if arg {
loop {
if args {
- ctranslate_type(c, arg.val, args.a.a.s, 0, 0:*node);
+ ctranslate_type(c, arg.val, args.a.a.s, 0, 0 as *node);
} else {
- ctranslate_type(c, arg.val, "", 0, 0:*node);
+ ctranslate_type(c, arg.val, "", 0, 0 as *node);
}
arg = arg.arg;
if arg {
@@ -241,7 +241,7 @@ ctranslate_struct(c: *compiler, d: *decl) {
v = find(c, d.name, n.a.a.s, 0);
fputs(c.cout, "\t");
- ctranslate_type(c, v.member_type, n.a.a.s, 0, 0:*node);
+ ctranslate_type(c, v.member_type, n.a.a.s, 0, 0 as *node);
fputs(c.cout, ";\n");
n = n.b;
@@ -278,7 +278,7 @@ ctranslate_vars(c: *compiler, n: *node) {
ctranslate_vars(c, n.a);
} else if kind == N_VARDECL {
fputs(c.cout, "\t");
- ctranslate_type(c, n.t, n.a.s, 0, 0:*node);
+ ctranslate_type(c, n.t, n.a.s, 0, 0 as *node);
fputs(c.cout, " = ");
ctranslate_zero(c, n.t);
fputs(c.cout, ";\n");
@@ -295,7 +295,7 @@ ctranslate_str(c: *compiler, s: *byte) {
break;
}
- ch = s[i]:int;
+ ch = s[i] as int;
if ch < 32 || ch > 127 || ch == '\\' || ch == '"' {
fputc(c.cout, '\\');
@@ -431,19 +431,19 @@ ctranslate_expr(c: *compiler, n: *node) {
ctranslate_expr(c, n.a);
} else if n.kind == N_NEG {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(-(unsigned long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))");
} else if n.kind == N_NOT {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(~(unsigned long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))");
} else if n.kind == N_ADD {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(((unsigned long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))+((unsigned long)(");
@@ -451,7 +451,7 @@ ctranslate_expr(c: *compiler, n: *node) {
fputs(c.cout, ")))");
} else if n.kind == N_SUB {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(((unsigned long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))-((unsigned long)(");
@@ -459,7 +459,7 @@ ctranslate_expr(c: *compiler, n: *node) {
fputs(c.cout, ")))");
} else if n.kind == N_MUL {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(((long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))*((long)(");
@@ -467,7 +467,7 @@ ctranslate_expr(c: *compiler, n: *node) {
fputs(c.cout, ")))");
} else if n.kind == N_DIV {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(((long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))/((long)(");
@@ -475,7 +475,7 @@ ctranslate_expr(c: *compiler, n: *node) {
fputs(c.cout, ")))");
} else if n.kind == N_MOD {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(((long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))%((long)(");
@@ -483,7 +483,7 @@ ctranslate_expr(c: *compiler, n: *node) {
fputs(c.cout, ")))");
} else if n.kind == N_LSH {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(((unsigned long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))<<((unsigned long)(");
@@ -491,7 +491,7 @@ ctranslate_expr(c: *compiler, n: *node) {
fputs(c.cout, ")))");
} else if n.kind == N_RSH {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(((unsigned long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))>>((unsigned long)(");
@@ -499,7 +499,7 @@ ctranslate_expr(c: *compiler, n: *node) {
fputs(c.cout, ")))");
} else if n.kind == N_AND {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(((unsigned long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))&((unsigned long)(");
@@ -507,7 +507,7 @@ ctranslate_expr(c: *compiler, n: *node) {
fputs(c.cout, ")))");
} else if n.kind == N_OR {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(((unsigned long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))|((unsigned long)(");
@@ -515,7 +515,7 @@ ctranslate_expr(c: *compiler, n: *node) {
fputs(c.cout, ")))");
} else if n.kind == N_XOR {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")(((unsigned long)(");
ctranslate_expr(c, n.a);
fputs(c.cout, "))^((unsigned long)(");
@@ -523,7 +523,7 @@ ctranslate_expr(c: *compiler, n: *node) {
fputs(c.cout, ")))");
} else if n.kind == N_CAST {
fputs(c.cout, "(");
- ctranslate_type(c, n.t, "", 0, 0:*node);
+ ctranslate_type(c, n.t, "", 0, 0 as *node);
fputs(c.cout, ")");
ctranslate_expr(c, n.a);
} else {
diff --git a/cpio.om b/cpio.om
@@ -85,7 +85,7 @@ main(argc: int, argv: **byte, envp: **byte) {
exit(1);
}
- if fstat(fd, (&stat):*byte) < 0 {
+ if fstat(fd, (&stat) as *byte) < 0 {
fflush(stdout);
fdputs(2, "stat failed: ");
fdputs(2, name);
@@ -194,7 +194,7 @@ fputh(f: *file, x: int) {
i = i - 4;
- fputc(f, "0123456789abcdef"[(x >> i) & 15]:int);
+ fputc(f, "0123456789abcdef"[(x >> i) & 15] as int);
}
}
diff --git a/decl.om b/decl.om
@@ -44,7 +44,7 @@ find(c: *compiler, name: *byte, member_name: *byte, make: int): *decl {
var link: **decl;
var dir: int;
- p = 0: *decl;
+ p = 0 as *decl;
link = &c.decls;
loop {
d = *link;
@@ -79,44 +79,44 @@ find(c: *compiler, name: *byte, member_name: *byte, make: int): *decl {
if (!make) {
- return 0:*decl;
+ return 0 as *decl;
}
- d = alloc(c.a, sizeof(*d)): *decl;
+ d = alloc(c.a, sizeof(*d)) as *decl;
d.name = name;
d.member_name = member_name;
d.p = p;
- d.l = 0:*decl;
- d.r = 0:*decl;
+ d.l = 0 as *decl;
+ d.r = 0 as *decl;
- d.used_next = 0:*decl;
+ d.used_next = 0 as *decl;
d.func_defined = 0;
- d.func_type = 0:*type;
+ d.func_type = 0 as *type;
d.func_label = mklabel(c.s);
- d.func_def = 0:*node;
+ d.func_def = 0 as *node;
d.func_used = 0;
d.struct_defined = 0;
d.struct_size = 0;
d.struct_layout_done = 0;
- d.struct_def = 0:*node;
+ d.struct_def = 0 as *node;
d.member_defined = 0;
- d.member_type = 0:*type;
+ d.member_type = 0 as *type;
d.member_offset = 0;
- d.member_def = 0:*node;
+ d.member_def = 0 as *node;
d.enum_defined = 0;
d.enum_value = 0;
- d.enum_def = 0:*node;
+ d.enum_def = 0 as *node;
d.var_defined = 0;
- d.var_type = 0:*type;
+ d.var_type = 0 as *type;
d.var_offset = 0;
- d.var_def = 0:*node;
+ d.var_def = 0 as *node;
d.goto_defined = 0;
d.goto_label = mklabel(c.s);
@@ -132,7 +132,7 @@ first_decl(c: *compiler): *decl {
d = c.decls;
if (!d) {
- return 0:*decl;
+ return 0 as *decl;
}
loop {
@@ -146,7 +146,7 @@ first_decl(c: *compiler): *decl {
next_decl(c: *compiler, d: *decl): *decl {
if (!d) {
- return 0:*decl;
+ return 0 as *decl;
}
if (d.r) {
@@ -163,7 +163,7 @@ next_decl(c: *compiler, d: *decl): *decl {
loop {
if (!d.p) {
- return 0:*decl;
+ return 0 as *decl;
}
if (d.p.l == d) {
diff --git a/ed25519.om b/ed25519.om
@@ -181,7 +181,7 @@ ed25519_mul(r: *int, a: *int, b: *int) {
var c: int;
var i: int;
- x = (&_x):*int;
+ x = (&_x) as *int;
x[0] = 0;
x[1] = 0;
@@ -256,7 +256,7 @@ ed25519_inv(r: *int, a: *int) {
var x: *int;
var i: int;
- x = (&_x):*int;
+ x = (&_x) as *int;
i = 0;
loop {
@@ -544,14 +544,14 @@ ed25519_decode(p: *int, y: *byte): int {
a = &_a.x0;
b = &_b.x0;
- xy[8] = y[0]:int | (y[1]:int << 8) | (y[2]:int << 16) | (y[3]:int << 24);
- xy[9] = y[4]:int | (y[5]:int << 8) | (y[6]:int << 16) | (y[7]:int << 24);
- xy[10] = y[8]:int | (y[9]:int << 8) | (y[10]:int << 16) | (y[11]:int << 24);
- xy[11] = y[12]:int | (y[13]:int << 8) | (y[14]:int << 16) | (y[15]:int << 24);
- xy[12] = y[16]:int | (y[17]:int << 8) | (y[18]:int << 16) | (y[19]:int << 24);
- xy[13] = y[20]:int | (y[21]:int << 8) | (y[22]:int << 16) | (y[23]:int << 24);
- xy[14] = y[24]:int | (y[25]:int << 8) | (y[26]:int << 16) | (y[27]:int << 24);
- xy[15] = (y[28]:int | (y[29]:int << 8) | (y[30]:int << 16) | (y[31]:int << 24)) & (-1 >> 33);
+ xy[8] = y[0] as int | (y[1] as int << 8) | (y[2] as int << 16) | (y[3] as int << 24);
+ xy[9] = y[4] as int | (y[5] as int << 8) | (y[6] as int << 16) | (y[7] as int << 24);
+ xy[10] = y[8] as int | (y[9] as int << 8) | (y[10] as int << 16) | (y[11] as int << 24);
+ xy[11] = y[12] as int | (y[13] as int << 8) | (y[14] as int << 16) | (y[15] as int << 24);
+ xy[12] = y[16] as int | (y[17] as int << 8) | (y[18] as int << 16) | (y[19] as int << 24);
+ xy[13] = y[20] as int | (y[21] as int << 8) | (y[22] as int << 16) | (y[23] as int << 24);
+ xy[14] = y[24] as int | (y[25] as int << 8) | (y[26] as int << 16) | (y[27] as int << 24);
+ xy[15] = (y[28] as int | (y[29] as int << 8) | (y[30] as int << 16) | (y[31] as int << 24)) & (-1 >> 33);
ed25519_mul(a, &xy[8], &xy[8]);
ed25519_d(b);
@@ -566,7 +566,7 @@ ed25519_decode(p: *int, y: *byte): int {
return 0;
}
- ed25519_set_lsb(xy, y[31]:int >> 7);
+ ed25519_set_lsb(xy, y[31] as int >> 7);
p[0] = xy[0];
p[1] = xy[1];
@@ -589,38 +589,38 @@ ed25519_decode(p: *int, y: *byte): int {
}
ed25519_encode(dest: *byte, p: *int) {
- dest[0] = p[8]:byte;
- dest[1] = (p[8] >> 8):byte;
- dest[2] = (p[8] >> 16):byte;
- dest[3] = (p[8] >> 24):byte;
- dest[4] = p[9]:byte;
- dest[5] = (p[9] >> 8):byte;
- dest[6] = (p[9] >> 16):byte;
- dest[7] = (p[9] >> 24):byte;
- dest[8] = p[10]:byte;
- dest[9] = (p[10] >> 8):byte;
- dest[10] = (p[10] >> 16):byte;
- dest[11] = (p[10] >> 24):byte;
- dest[12] = p[11]:byte;
- dest[13] = (p[11] >> 8):byte;
- dest[14] = (p[11] >> 16):byte;
- dest[15] = (p[11] >> 24):byte;
- dest[16] = p[12]:byte;
- dest[17] = (p[12] >> 8):byte;
- dest[18] = (p[12] >> 16):byte;
- dest[19] = (p[12] >> 24):byte;
- dest[20] = p[13]:byte;
- dest[21] = (p[13] >> 8):byte;
- dest[22] = (p[13] >> 16):byte;
- dest[23] = (p[13] >> 24):byte;
- dest[24] = p[14]:byte;
- dest[25] = (p[14] >> 8):byte;
- dest[26] = (p[14] >> 16):byte;
- dest[27] = (p[14] >> 24):byte;
- dest[28] = p[15]:byte;
- dest[29] = (p[15] >> 8):byte;
- dest[30] = (p[15] >> 16):byte;
- dest[31] = (p[15] >> 24):byte | ((p[0] & 1) << 7):byte;
+ dest[0] = p[8] as byte;
+ dest[1] = (p[8] >> 8) as byte;
+ dest[2] = (p[8] >> 16) as byte;
+ dest[3] = (p[8] >> 24) as byte;
+ dest[4] = p[9] as byte;
+ dest[5] = (p[9] >> 8) as byte;
+ dest[6] = (p[9] >> 16) as byte;
+ dest[7] = (p[9] >> 24) as byte;
+ dest[8] = p[10] as byte;
+ dest[9] = (p[10] >> 8) as byte;
+ dest[10] = (p[10] >> 16) as byte;
+ dest[11] = (p[10] >> 24) as byte;
+ dest[12] = p[11] as byte;
+ dest[13] = (p[11] >> 8) as byte;
+ dest[14] = (p[11] >> 16) as byte;
+ dest[15] = (p[11] >> 24) as byte;
+ dest[16] = p[12] as byte;
+ dest[17] = (p[12] >> 8) as byte;
+ dest[18] = (p[12] >> 16) as byte;
+ dest[19] = (p[12] >> 24) as byte;
+ dest[20] = p[13] as byte;
+ dest[21] = (p[13] >> 8) as byte;
+ dest[22] = (p[13] >> 16) as byte;
+ dest[23] = (p[13] >> 24) as byte;
+ dest[24] = p[14] as byte;
+ dest[25] = (p[14] >> 8) as byte;
+ dest[26] = (p[14] >> 16) as byte;
+ dest[27] = (p[14] >> 24) as byte;
+ dest[28] = p[15] as byte;
+ dest[29] = (p[15] >> 8) as byte;
+ dest[30] = (p[15] >> 16) as byte;
+ dest[31] = (p[15] >> 24) as byte | ((p[0] & 1) << 7) as byte;
}
ed25519_pub(pub: *byte, b: *byte) {
@@ -631,7 +631,7 @@ ed25519_pub(pub: *byte, b: *byte) {
var _s: _ed25519_limb;
var s: *int;
- h = (&_h):*byte;
+ h = (&_h) as *byte;
a = &_a.x0;
s = &_s.x0;
@@ -670,11 +670,11 @@ ed25519_sign(sig: *byte, b: *byte, msg: *byte, len: int) {
var _k: _ed25519_limb;
var k: *int;
- h = (&_h):*byte;
- hr = (&_hr):*byte;
- hk = (&_hk):*byte;
+ h = (&_h) as *byte;
+ hr = (&_hr) as *byte;
+ hk = (&_hk) as *byte;
a = &_a.x0;
- pub = (&_pub):*byte;
+ pub = (&_pub) as *byte;
rb = &_rb.x0;
s = &_s.x0;
r = &_r.x0;
@@ -811,7 +811,7 @@ ed25519_ma_l(x: *int, a: *int, b: *int, y: *int) {
var c: int;
var i: int;
- z = (&_z):*int;
+ z = (&_z) as *int;
z[0] = 0;
z[1] = 0;
@@ -876,61 +876,61 @@ ed25519_reduce_l(x: *int, a: *byte) {
var _z: _ed25519_point;
var z: *int;
- z = (&_z):*int;
-
- z[0] = a[0]:int | (a[1]:int << 8) | (a[2]:int << 16) | (a[3]:int << 24);
- z[1] = a[4]:int | (a[5]:int << 8) | (a[6]:int << 16) | (a[7]:int << 24);
- z[2] = a[8]:int | (a[9]:int << 8) | (a[10]:int << 16) | (a[11]:int << 24);
- z[3] = a[12]:int | (a[13]:int << 8) | (a[14]:int << 16) | (a[15]:int << 24);
- z[4] = a[16]:int | (a[17]:int << 8) | (a[18]:int << 16) | (a[19]:int << 24);
- z[5] = a[20]:int | (a[21]:int << 8) | (a[22]:int << 16) | (a[23]:int << 24);
- z[6] = a[24]:int | (a[25]:int << 8) | (a[26]:int << 16) | (a[27]:int << 24);
- z[7] = a[28]:int | (a[29]:int << 8) | (a[30]:int << 16) | (a[31]:int << 24);
- z[8] = a[32]:int | (a[33]:int << 8) | (a[34]:int << 16) | (a[35]:int << 24);
- z[9] = a[36]:int | (a[37]:int << 8) | (a[38]:int << 16) | (a[39]:int << 24);
- z[10] = a[40]:int | (a[41]:int << 8) | (a[42]:int << 16) | (a[43]:int << 24);
- z[11] = a[44]:int | (a[45]:int << 8) | (a[46]:int << 16) | (a[47]:int << 24);
- z[12] = a[48]:int | (a[49]:int << 8) | (a[50]:int << 16) | (a[51]:int << 24);
- z[13] = a[52]:int | (a[53]:int << 8) | (a[54]:int << 16) | (a[55]:int << 24);
- z[14] = a[56]:int | (a[57]:int << 8) | (a[58]:int << 16) | (a[59]:int << 24);
- z[15] = a[60]:int | (a[61]:int << 8) | (a[62]:int << 16) | (a[63]:int << 24);
+ z = (&_z) as *int;
+
+ z[0] = a[0] as int | (a[1] as int << 8) | (a[2] as int << 16) | (a[3] as int << 24);
+ z[1] = a[4] as int | (a[5] as int << 8) | (a[6] as int << 16) | (a[7] as int << 24);
+ z[2] = a[8] as int | (a[9] as int << 8) | (a[10] as int << 16) | (a[11] as int << 24);
+ z[3] = a[12] as int | (a[13] as int << 8) | (a[14] as int << 16) | (a[15] as int << 24);
+ z[4] = a[16] as int | (a[17] as int << 8) | (a[18] as int << 16) | (a[19] as int << 24);
+ z[5] = a[20] as int | (a[21] as int << 8) | (a[22] as int << 16) | (a[23] as int << 24);
+ z[6] = a[24] as int | (a[25] as int << 8) | (a[26] as int << 16) | (a[27] as int << 24);
+ z[7] = a[28] as int | (a[29] as int << 8) | (a[30] as int << 16) | (a[31] as int << 24);
+ z[8] = a[32] as int | (a[33] as int << 8) | (a[34] as int << 16) | (a[35] as int << 24);
+ z[9] = a[36] as int | (a[37] as int << 8) | (a[38] as int << 16) | (a[39] as int << 24);
+ z[10] = a[40] as int | (a[41] as int << 8) | (a[42] as int << 16) | (a[43] as int << 24);
+ z[11] = a[44] as int | (a[45] as int << 8) | (a[46] as int << 16) | (a[47] as int << 24);
+ z[12] = a[48] as int | (a[49] as int << 8) | (a[50] as int << 16) | (a[51] as int << 24);
+ z[13] = a[52] as int | (a[53] as int << 8) | (a[54] as int << 16) | (a[55] as int << 24);
+ z[14] = a[56] as int | (a[57] as int << 8) | (a[58] as int << 16) | (a[59] as int << 24);
+ z[15] = a[60] as int | (a[61] as int << 8) | (a[62] as int << 16) | (a[63] as int << 24);
ed25519_mod_l(x, z);
}
ed25519_encode_l(dest: *byte, p: *int) {
- dest[0] = p[0]:byte;
- dest[1] = (p[0] >> 8):byte;
- dest[2] = (p[0] >> 16):byte;
- dest[3] = (p[0] >> 24):byte;
- dest[4] = p[1]:byte;
- dest[5] = (p[1] >> 8):byte;
- dest[6] = (p[1] >> 16):byte;
- dest[7] = (p[1] >> 24):byte;
- dest[8] = p[2]:byte;
- dest[9] = (p[2] >> 8):byte;
- dest[10] = (p[2] >> 16):byte;
- dest[11] = (p[2] >> 24):byte;
- dest[12] = p[3]:byte;
- dest[13] = (p[3] >> 8):byte;
- dest[14] = (p[3] >> 16):byte;
- dest[15] = (p[3] >> 24):byte;
- dest[16] = p[4]:byte;
- dest[17] = (p[4] >> 8):byte;
- dest[18] = (p[4] >> 16):byte;
- dest[19] = (p[4] >> 24):byte;
- dest[20] = p[5]:byte;
- dest[21] = (p[5] >> 8):byte;
- dest[22] = (p[5] >> 16):byte;
- dest[23] = (p[5] >> 24):byte;
- dest[24] = p[6]:byte;
- dest[25] = (p[6] >> 8):byte;
- dest[26] = (p[6] >> 16):byte;
- dest[27] = (p[6] >> 24):byte;
- dest[28] = p[7]:byte;
- dest[29] = (p[7] >> 8):byte;
- dest[30] = (p[7] >> 16):byte;
- dest[31] = (p[7] >> 24):byte;
+ dest[0] = p[0] as byte;
+ dest[1] = (p[0] >> 8) as byte;
+ dest[2] = (p[0] >> 16) as byte;
+ dest[3] = (p[0] >> 24) as byte;
+ dest[4] = p[1] as byte;
+ dest[5] = (p[1] >> 8) as byte;
+ dest[6] = (p[1] >> 16) as byte;
+ dest[7] = (p[1] >> 24) as byte;
+ dest[8] = p[2] as byte;
+ dest[9] = (p[2] >> 8) as byte;
+ dest[10] = (p[2] >> 16) as byte;
+ dest[11] = (p[2] >> 24) as byte;
+ dest[12] = p[3] as byte;
+ dest[13] = (p[3] >> 8) as byte;
+ dest[14] = (p[3] >> 16) as byte;
+ dest[15] = (p[3] >> 24) as byte;
+ dest[16] = p[4] as byte;
+ dest[17] = (p[4] >> 8) as byte;
+ dest[18] = (p[4] >> 16) as byte;
+ dest[19] = (p[4] >> 24) as byte;
+ dest[20] = p[5] as byte;
+ dest[21] = (p[5] >> 8) as byte;
+ dest[22] = (p[5] >> 16) as byte;
+ dest[23] = (p[5] >> 24) as byte;
+ dest[24] = p[6] as byte;
+ dest[25] = (p[6] >> 8) as byte;
+ dest[26] = (p[6] >> 16) as byte;
+ dest[27] = (p[6] >> 24) as byte;
+ dest[28] = p[7] as byte;
+ dest[29] = (p[7] >> 8) as byte;
+ dest[30] = (p[7] >> 16) as byte;
+ dest[31] = (p[7] >> 24) as byte;
}
ed25519_eq(a: *int, b: *int): int {
@@ -977,13 +977,13 @@ ed25519_verify(sig: *byte, pub: *byte, msg: *byte, len: int): int {
var _sk: _sha512_digest;
var sk: *byte;
- a = (&_a):*int;
- b = (&_b):*int;
- r = (&_r):*int;
- s = (&_s):*int;
- k = (&_k):*int;
- hk = (&_hk):*byte;
- sk = (&_sk):*byte;
+ a = (&_a) as *int;
+ b = (&_b) as *int;
+ r = (&_r) as *int;
+ s = (&_s) as *int;
+ k = (&_k) as *int;
+ hk = (&_hk) as *byte;
+ sk = (&_sk) as *byte;
// A = public key
if !ed25519_decode(a, pub){
@@ -1099,14 +1099,14 @@ x25519_decode(uv: *int, u: *byte): int {
v = &_v.x0;
- uv[0] = u[0]:int | (u[1]:int << 8) | (u[2]:int << 16) | (u[3]:int << 24);
- uv[1] = u[4]:int | (u[5]:int << 8) | (u[6]:int << 16) | (u[7]:int << 24);
- uv[2] = u[8]:int | (u[9]:int << 8) | (u[10]:int << 16) | (u[11]:int << 24);
- uv[3] = u[12]:int | (u[13]:int << 8) | (u[14]:int << 16) | (u[15]:int << 24);
- uv[4] = u[16]:int | (u[17]:int << 8) | (u[18]:int << 16) | (u[19]:int << 24);
- uv[5] = u[20]:int | (u[21]:int << 8) | (u[22]:int << 16) | (u[23]:int << 24);
- uv[6] = u[24]:int | (u[25]:int << 8) | (u[26]:int << 16) | (u[27]:int << 24);
- uv[7] = (u[28]:int | (u[29]:int << 8) | (u[30]:int << 16) | (u[31]:int << 24)) & (-1 >> 33);
+ uv[0] = u[0] as int | (u[1] as int << 8) | (u[2] as int << 16) | (u[3] as int << 24);
+ uv[1] = u[4] as int | (u[5] as int << 8) | (u[6] as int << 16) | (u[7] as int << 24);
+ uv[2] = u[8] as int | (u[9] as int << 8) | (u[10] as int << 16) | (u[11] as int << 24);
+ uv[3] = u[12] as int | (u[13] as int << 8) | (u[14] as int << 16) | (u[15] as int << 24);
+ uv[4] = u[16] as int | (u[17] as int << 8) | (u[18] as int << 16) | (u[19] as int << 24);
+ uv[5] = u[20] as int | (u[21] as int << 8) | (u[22] as int << 16) | (u[23] as int << 24);
+ uv[6] = u[24] as int | (u[25] as int << 8) | (u[26] as int << 16) | (u[27] as int << 24);
+ uv[7] = (u[28] as int | (u[29] as int << 8) | (u[30] as int << 16) | (u[31] as int << 24)) & (-1 >> 33);
ed25519_reduce(uv);
@@ -1124,43 +1124,43 @@ x25519_decode(uv: *int, u: *byte): int {
}
x25519_encode(u: *byte, uv: *int) {
- u[0] = uv[0]:byte;
- u[1] = (uv[0] >> 8):byte;
- u[2] = (uv[0] >> 16):byte;
- u[3] = (uv[0] >> 24):byte;
- u[4] = uv[1]:byte;
- u[5] = (uv[1] >> 8):byte;
- u[6] = (uv[1] >> 16):byte;
- u[7] = (uv[1] >> 24):byte;
- u[8] = uv[2]:byte;
- u[9] = (uv[2] >> 8):byte;
- u[10] = (uv[2] >> 16):byte;
- u[11] = (uv[2] >> 24):byte;
- u[12] = uv[3]:byte;
- u[13] = (uv[3] >> 8):byte;
- u[14] = (uv[3] >> 16):byte;
- u[15] = (uv[3] >> 24):byte;
- u[16] = uv[4]:byte;
- u[17] = (uv[4] >> 8):byte;
- u[18] = (uv[4] >> 16):byte;
- u[19] = (uv[4] >> 24):byte;
- u[20] = uv[5]:byte;
- u[21] = (uv[5] >> 8):byte;
- u[22] = (uv[5] >> 16):byte;
- u[23] = (uv[5] >> 24):byte;
- u[24] = uv[6]:byte;
- u[25] = (uv[6] >> 8):byte;
- u[26] = (uv[6] >> 16):byte;
- u[27] = (uv[6] >> 24):byte;
- u[28] = uv[7]:byte;
- u[29] = (uv[7] >> 8):byte;
- u[30] = (uv[7] >> 16):byte;
- u[31] = (uv[7] >> 24):byte;
+ u[0] = uv[0] as byte;
+ u[1] = (uv[0] >> 8) as byte;
+ u[2] = (uv[0] >> 16) as byte;
+ u[3] = (uv[0] >> 24) as byte;
+ u[4] = uv[1] as byte;
+ u[5] = (uv[1] >> 8) as byte;
+ u[6] = (uv[1] >> 16) as byte;
+ u[7] = (uv[1] >> 24) as byte;
+ u[8] = uv[2] as byte;
+ u[9] = (uv[2] >> 8) as byte;
+ u[10] = (uv[2] >> 16) as byte;
+ u[11] = (uv[2] >> 24) as byte;
+ u[12] = uv[3] as byte;
+ u[13] = (uv[3] >> 8) as byte;
+ u[14] = (uv[3] >> 16) as byte;
+ u[15] = (uv[3] >> 24) as byte;
+ u[16] = uv[4] as byte;
+ u[17] = (uv[4] >> 8) as byte;
+ u[18] = (uv[4] >> 16) as byte;
+ u[19] = (uv[4] >> 24) as byte;
+ u[20] = uv[5] as byte;
+ u[21] = (uv[5] >> 8) as byte;
+ u[22] = (uv[5] >> 16) as byte;
+ u[23] = (uv[5] >> 24) as byte;
+ u[24] = uv[6] as byte;
+ u[25] = (uv[6] >> 8) as byte;
+ u[26] = (uv[6] >> 16) as byte;
+ u[27] = (uv[6] >> 24) as byte;
+ u[28] = uv[7] as byte;
+ u[29] = (uv[7] >> 8) as byte;
+ u[30] = (uv[7] >> 16) as byte;
+ u[31] = (uv[7] >> 24) as byte;
}
x25519_base(u: *byte) {
bzero(u, 32);
- u[0] = 9:byte;
+ u[0] = 9 as byte;
}
x25519(uk: *byte, u: *byte, k: *byte): int {
@@ -1264,12 +1264,12 @@ ed25519_set_lsb(xy: *int, lsb: int) {
}
ed25519_clamp(k: *int, b: *byte) {
- k[0] = (b[0]:int | (b[1]:int << 8) | (b[2]:int << 16) | (b[3]:int << 24)) & -8;
- k[1] = b[4]:int | (b[5]:int << 8) | (b[6]:int << 16) | (b[7]:int << 24);
- k[2] = b[8]:int | (b[9]:int << 8) | (b[10]:int << 16) | (b[11]:int << 24);
- k[3] = b[12]:int | (b[13]:int << 8) | (b[14]:int << 16) | (b[15]:int << 24);
- k[4] = b[16]:int | (b[17]:int << 8) | (b[18]:int << 16) | (b[19]:int << 24);
- k[5] = b[20]:int | (b[21]:int << 8) | (b[22]:int << 16) | (b[23]:int << 24);
- k[6] = b[24]:int | (b[25]:int << 8) | (b[26]:int << 16) | (b[27]:int << 24);
- k[7] = ((b[28]:int | (b[29]:int << 8) | (b[30]:int << 16) | (b[31]:int << 24)) & (-1 >> 33)) | (1 << 30);
+ k[0] = (b[0] as int | (b[1] as int << 8) | (b[2] as int << 16) | (b[3] as int << 24)) & -8;
+ k[1] = b[4] as int | (b[5] as int << 8) | (b[6] as int << 16) | (b[7] as int << 24);
+ k[2] = b[8] as int | (b[9] as int << 8) | (b[10] as int << 16) | (b[11] as int << 24);
+ k[3] = b[12] as int | (b[13] as int << 8) | (b[14] as int << 16) | (b[15] as int << 24);
+ k[4] = b[16] as int | (b[17] as int << 8) | (b[18] as int << 16) | (b[19] as int << 24);
+ k[5] = b[20] as int | (b[21] as int << 8) | (b[22] as int << 16) | (b[23] as int << 24);
+ k[6] = b[24] as int | (b[25] as int << 8) | (b[26] as int << 16) | (b[27] as int << 24);
+ k[7] = ((b[28] as int | (b[29] as int << 8) | (b[30] as int << 16) | (b[31] as int << 24)) & (-1 >> 33)) | (1 << 30);
}
diff --git a/genlex.om b/genlex.om
@@ -8,13 +8,13 @@ getchar(): int {
if (ret == 0) {
return -1;
}
- return b: int;
+ return b as int;
}
putchar(ch: int): void {
var b: byte;
var ret: int;
- b = ch: byte;
+ b = ch as byte;
ret = write(1, &b, 1);
if (ret != 1) {
exit(3);
@@ -44,15 +44,15 @@ setup(c: *compiler): void {
c.lineno = 1;
c.colno = 1;
c.tt = 0;
- c.n = 0: *nfa;
+ c.n = 0 as *nfa;
c.tmax = 256;
c.tlen = 0;
c.buf = alloc(&c.a, c.tmax);
- c.tags = 0: *tag;
+ c.tags = 0 as *tag;
c.ntags = 0;
c.nnfa = 0;
c.ndfa = 0;
- c.d = 0:*dfa;
+ c.d = 0 as *dfa;
feed(c);
}
@@ -82,7 +82,7 @@ enum {
}
feed(c: *compiler): void {
- c.n = 0:*nfa;
+ c.n = 0 as *nfa;
c.tlen = 0;
loop {
@@ -156,12 +156,12 @@ feed_ident(c: *compiler): void {
break;
}
- c.buf[c.tlen] = c.nc:byte;
+ c.buf[c.tlen] = c.nc as byte;
c.tlen = c.tlen + 1;
if (c.tlen == c.tmax) {
die("ident too long");
}
- c.buf[c.tlen] = 0:byte;
+ c.buf[c.tlen] = 0 as byte;
feedc(c);
}
@@ -239,7 +239,7 @@ feed_literal(c: *compiler): void {
feed_escape(c);
}
- a = nfa_literal(c, c.nc: byte);
+ a = nfa_literal(c, c.nc as byte);
c.n = nfa_concat(c, c.n, a);
feedc(c);
@@ -266,7 +266,7 @@ feed_charset(c: *compiler): void {
if (i == 256) {
break;
}
- c.buf[i] = 0: byte;
+ c.buf[i] = 0 as byte;
i = i + 1;
}
@@ -292,7 +292,7 @@ feed_charset(c: *compiler): void {
if (i == 256) {
break;
}
- c.buf[i] = 1:byte;
+ c.buf[i] = 1 as byte;
i = i + 1;
}
}
@@ -334,7 +334,7 @@ feed_charset(c: *compiler): void {
if (i >= right) {
break;
}
- c.buf[i] = mode: byte;
+ c.buf[i] = mode as byte;
i = i + 1;
}
}
@@ -388,7 +388,7 @@ feed_charset(c: *compiler): void {
parse_ident(c: *compiler): *tag {
var t: *tag;
if (c.tt != T_IDENT) {
- return 0: *tag;
+ return 0 as *tag;
}
t = find_tag(c, c.buf);
feed(c);
@@ -413,7 +413,7 @@ intern(c: *compiler): *byte {
s[i] = c.buf[i];
i = i + 1;
}
- s[c.tlen] = 0:byte;
+ s[c.tlen] = 0 as byte;
return s;
}
@@ -431,8 +431,8 @@ find_tag(c: *compiler, s: *byte): *tag {
}
link = &t.next;
}
- t = alloc(&c.a, sizeof(*t)): *tag;
- t.next = 0:*tag;
+ t = alloc(&c.a, sizeof(*t)) as *tag;
+ t.next = 0 as *tag;
t.s = intern(c);
t.id = c.ntags;
c.ntags = c.ntags + 1;
@@ -453,13 +453,13 @@ struct nfa {
nfa_empty(c: *compiler): *nfa {
var n: *nfa;
- n = alloc(&c.a, sizeof(*n)):*nfa;
+ n = alloc(&c.a, sizeof(*n)) as *nfa;
n.id = c.nnfa;
n.left = -1;
n.right = -1;
n.live = 0;
- n.a = 0:*nfa;
- n.b = 0:*nfa;
+ n.a = 0 as *nfa;
+ n.b = 0 as *nfa;
n.end = n;
c.nnfa = c.nnfa + 1;
return n;
@@ -468,7 +468,7 @@ nfa_empty(c: *compiler): *nfa {
nfa_literal(c: *compiler, a: byte): *nfa {
var n: *nfa;
n = nfa_empty(c);
- n.left = a:int;
+ n.left = a as int;
n.right = n.left + 1;
return n;
}
@@ -517,7 +517,7 @@ nfa_star(c: *compiler, a: *nfa): *nfa {
parse_literal(c: *compiler): *nfa {
var n: *nfa;
if (c.tt != T_LITERAL) {
- return 0:*nfa;
+ return 0 as *nfa;
}
n = c.n;
feed(c);
@@ -527,7 +527,7 @@ parse_literal(c: *compiler): *nfa {
parse_charset(c: *compiler): *nfa {
var n: *nfa;
if (c.tt != T_CHARSET) {
- return 0:*nfa;
+ return 0 as *nfa;
}
n = c.n;
feed(c);
@@ -537,7 +537,7 @@ parse_charset(c: *compiler): *nfa {
parse_dot(c: *compiler): *nfa {
var n: *nfa;
if (c.tt != T_DOT) {
- return 0:*nfa;
+ return 0 as *nfa;
}
feed(c);
n = nfa_empty(c);
@@ -581,7 +581,7 @@ parse_primary(c: *compiler): *nfa {
return n;
}
- return 0: *nfa;
+ return 0 as *nfa;
}
// post := primary
@@ -593,7 +593,7 @@ parse_post(c: *compiler): *nfa {
n = parse_primary(c);
if (!n) {
- return 0: *nfa;
+ return 0 as *nfa;
}
loop {
@@ -620,7 +620,7 @@ parse_concat(c: *compiler): *nfa {
n = parse_post(c);
if (!n) {
- return 0:*nfa;
+ return 0 as *nfa;
}
loop {
@@ -668,7 +668,7 @@ parse_decl(c: *compiler): *nfa {
t = parse_ident(c);
if (!t) {
- return 0: *nfa;
+ return 0 as *nfa;
}
if (c.tt != T_EQUALS) {
@@ -695,7 +695,7 @@ parse_program(c: *compiler): *nfa {
var n: *nfa;
var p: *nfa;
- p = 0: *nfa;
+ p = 0 as *nfa;
loop {
n = parse_decl(c);
if (!n) {
@@ -731,9 +731,9 @@ struct nlist {
alloc_nlist(c: *compiler, l: *nlist, cap: int): void {
l.cap = cap;
- l.live = alloc(&c.a, sizeof(*l.live) * cap):**nfa;
+ l.live = alloc(&c.a, sizeof(*l.live) * cap) as **nfa;
l.fill = 0;
- l.tag = 0:*tag;
+ l.tag = 0 as *tag;
}
activate(l: *nlist, n: *nfa): void {
@@ -876,13 +876,13 @@ nlist_sort(l: *nlist): void {
alloc_link(c: *compiler): **dfa {
var link: **dfa;
var i: int;
- link = alloc(&c.a, sizeof(*link) * 256): **dfa;
+ link = alloc(&c.a, sizeof(*link) * 256) as **dfa;
i = 0;
loop {
if (i == 256) {
break;
}
- link[i] = 0:*dfa;
+ link[i] = 0 as *dfa;
i = i + 1;
}
return link;
@@ -913,7 +913,7 @@ nlist2dfa(c: *compiler, l: *nlist): *dfa {
var j: int;
if (l.fill == 0 && !l.tag) {
- return 0:*dfa;
+ return 0 as *dfa;
}
link = &c.d;
@@ -934,12 +934,12 @@ nlist2dfa(c: *compiler, l: *nlist): *dfa {
}
}
- d = alloc(&c.a, sizeof(*d)): *dfa;
+ d = alloc(&c.a, sizeof(*d)) as *dfa;
d.id = c.ndfa;
d.link = alloc_link(c);
nlist_copy(c, &d.key, l);
- d.l = 0: *dfa;
- d.r = 0: *dfa;
+ d.l = 0 as *dfa;
+ d.r = 0 as *dfa;
d.seen = 0;
c.ndfa = c.ndfa + 1;
@@ -986,7 +986,7 @@ deactivate(l: *nlist): void {
loop {
if (i >= l.fill) {
l.fill = 0;
- l.tag = 0: *tag;
+ l.tag = 0 as *tag;
break;
}
l.live[i].live = 0;
diff --git a/kernel.om b/kernel.om
@@ -118,7 +118,7 @@ bzero(s: *byte, size: int) {
if i == size {
break;
}
- s[i] = 0:byte;
+ s[i] = 0 as byte;
i = i + 1;
}
}
@@ -200,7 +200,7 @@ panic(r: *regs) {
break;
}
- sp = sp:*int[0];
+ sp = sp as *int[0];
i = i + 1;
if i == 8 {
@@ -259,7 +259,7 @@ fill_idt(s: *int) {
} else {
ist = 1;
}
- idt_gate(&s[i * 2], _isr0:int + i * 16, 0, ist);
+ idt_gate(&s[i * 2], _isr0 as int + i * 16, 0, ist);
i = i + 1;
}
}
@@ -291,7 +291,7 @@ bytesum(a: *byte, n: int): byte {
var x: byte;
i = 0;
- x = 0:byte;
+ x = 0 as byte;
loop {
if i == n {
return x;
@@ -305,15 +305,15 @@ bytesum(a: *byte, n: int): byte {
ptov(p: int): *byte {
if p < (1 << 30) {
- return (p - 0x80000000): *byte;
+ return (p - 0x80000000) as *byte;
} else {
- return (p + (-1 << 47)): *byte;
+ return (p + (-1 << 47)) as *byte;
}
}
vtop(v: *byte): int {
var va: int;
- va = v:int;
+ va = v as int;
// direct map
if va >= (-1 << 47) && va < (-1 << 46) {
@@ -332,7 +332,7 @@ acpi_len(p: int): int {
if p == 0 {
return 0;
}
- return _r32((ptov(p):int + 4):*byte);
+ return _r32((ptov(p) as int + 4) as *byte);
}
valid_table(p: int, sig: *byte): int {
@@ -350,7 +350,7 @@ valid_table(p: int, sig: *byte): int {
return 0;
}
- if bytesum(v, len):int != 0 {
+ if bytesum(v, len) as int != 0 {
return 0;
}
@@ -379,7 +379,7 @@ _kputh(x: int, d: int) {
break;
}
d = d - 4;
- kputc("0123456789abcdef"[(x >> d) & 15]:int);
+ kputc("0123456789abcdef"[(x >> d) & 15] as int);
}
}
@@ -472,14 +472,14 @@ map_pci(pa: int): *byte {
global.mmio = global.mmio - (1 << 31);
va = global.mmio;
pt4p = global.kpt;
- pt4 = ptov(pt4p):*int;
- v2 = ((va: int) >> 30) & 511;
- pt3 = ptov(pt4[511] & -4096):*int;
+ pt4 = ptov(pt4p) as *int;
+ v2 = ((va as int) >> 30) & 511;
+ pt3 = ptov(pt4[511] & -4096) as *int;
flags = 0x93;
pt3[v2] = (pa & -(1 << 30)) | flags;
pt3[v2 + 1] = ((pa + (1 << 30)) & -(1 << 30)) | flags;
invlpt();
- return (va + (pa & ((1 << 30) - 1))):*byte;
+ return (va + (pa & ((1 << 30) - 1))) as *byte;
}
struct pcidev {
@@ -514,14 +514,14 @@ scan_pci(base: *byte, visit: func(dev: *pcidev)) {
dev.addr = &base[i * 4096];
dev.bus = i;
- dev.type = base[i * 4096 + 14]:int;
+ dev.type = base[i * 4096 + 14] as int;
- dev.vid = (base[i * 4096 + 0]:int)
- + (base[i * 4096 + 1]:int << 8);
- dev.did = (base[i * 4096 + 2]:int)
- + (base[i * 4096 + 3]:int << 8);
- dev.cls = base[i * 4096 + 11]: int;
- dev.subcls = base[i * 4096 + 10]: int;
+ dev.vid = (base[i * 4096 + 0] as int)
+ + (base[i * 4096 + 1] as int << 8);
+ dev.did = (base[i * 4096 + 2] as int)
+ + (base[i * 4096 + 3] as int << 8);
+ dev.cls = base[i * 4096 + 11] as int;
+ dev.subcls = base[i * 4096 + 10] as int;
dev.bar0 = _r32(&base[i * 4096 + 16 + 4 * 0]);
dev.bar1 = _r32(&base[i * 4096 + 16 + 4 * 1]);
dev.bar2 = _r32(&base[i * 4096 + 16 + 4 * 2]);
@@ -536,23 +536,23 @@ scan_pci(base: *byte, visit: func(dev: *pcidev)) {
continue;
}
- dev.msi = 0:*byte;
+ dev.msi = 0 as *byte;
if dev.type == 0 {
- cap = base[i * 4096 + 0x34]: int;
+ cap = base[i * 4096 + 0x34] as int;
loop {
if cap == 0 || cap > 4094 {
break;
}
- capid = base[i * 4096 + cap]:int;
+ capid = base[i * 4096 + cap] as int;
if capid == 5 {
dev.msi = &base[i * 4096 + cap];
break;
}
- cap = base[i * 4096 + cap + 1]:int;
+ cap = base[i * 4096 + cap + 1] as int;
}
}
@@ -599,11 +599,11 @@ onesum(h: *byte, n: int, s: int): int {
break;
}
if i + 1 == n {
- s = s + (h[i]:int << 8);
+ s = s + (h[i] as int << 8);
s = (s & 0xffff) + ((s >> 16) & 1);
break;
}
- s = s + (h[i]:int << 8) + (h[i + 1]:int);
+ s = s + (h[i] as int << 8) + (h[i + 1] as int);
s = (s & 0xffff) + ((s >> 16) & 1);
i = i + 2;
}
@@ -642,8 +642,8 @@ vblit(v: *vga) {
var d: *int;
var s: *int;
- d = v.base:*int;
- s = v.fb:*int;
+ d = v.base as *int;
+ s = v.fb as *int;
i = 0;
loop {
@@ -667,8 +667,8 @@ vclear(v: *vga) {
if i == v.cx * v.cy {
return;
}
- v.fb[2 * i] = 0:byte;
- v.fb[2 * i + 1] = 0x0f:byte;
+ v.fb[2 * i] = 0 as byte;
+ v.fb[2 * i + 1] = 0x0f as byte;
i = i + 1;
}
vblit(v);
@@ -682,8 +682,8 @@ vshift(v: *vga) {
if i == v.cx * v.cy {
break;
}
- v.fb[2 * i] = 0:byte;
- v.fb[2 * i + 1] = 0x0f:byte;
+ v.fb[2 * i] = 0 as byte;
+ v.fb[2 * i + 1] = 0x0f as byte;
i = i + 1;
}
if v.y > 0 {
@@ -705,8 +705,8 @@ vputc(v: *vga, c: int) {
vblit(v);
}
} else {
- v.fb[(v.y * v.cx + v.x) * 2] = c:byte;
- v.fb[(v.y * v.cx + v.x) * 2 + 1] = 0x0f:byte;
+ v.fb[(v.y * v.cx + v.x) * 2] = c as byte;
+ v.fb[(v.y * v.cx + v.x) * 2 + 1] = 0x0f as byte;
v.x = v.x + 1;
if v.x == v.cx {
v.x = 0;
@@ -736,7 +736,7 @@ kputs(s: *byte) {
if !s[i] {
break;
}
- vputc(&global.vga, s[i]:int);
+ vputc(&global.vga, s[i] as int);
i = i + 1;
}
}
@@ -751,7 +751,7 @@ struct arp_entry {
struct tcp_state {
state: int;
- event_func: func(tcb:*tcp_state);
+ event_func: func(tcb: *tcp_state);
// Network tuple
peer_ip: int;
@@ -832,7 +832,7 @@ struct free_range {
}
g(): *global {
- return _rgs(0):**global[0];
+ return _rgs(0) as **global[0];
}
rand(): int {
@@ -851,7 +851,7 @@ memset(dest: *byte, c: int, size: int) {
if i == size {
break;
}
- dest[i] = c:byte;
+ dest[i] = c as byte;
i = i + 1;
}
}
@@ -922,16 +922,16 @@ insert_sort(arr: *void, nitems: int, size: int, cmp: (func(a: *void, b: *void):
j = i - 1;
- b = (&arr:*byte[size * i]):*void;
+ b = (&arr as *byte[size * i]) as *void;
loop {
- a = (&arr:*byte[size * j]):*void;
+ a = (&arr as *byte[size * j]) as *void;
if cmp(a, b) <= 0 {
break;
}
- memswap(a: *byte, b: *byte, size);
+ memswap(a as *byte, b as *byte, size);
if j == 0 {
break;
@@ -947,8 +947,8 @@ insert_sort(arr: *void, nitems: int, size: int, cmp: (func(a: *void, b: *void):
mmap_cmp(a: *void, b: *void): int {
var a_addr: int;
var b_addr: int;
- a_addr = a:*int[0];
- b_addr = b:*int[0];
+ a_addr = a as *int[0];
+ b_addr = b as *int[0];
if a_addr < b_addr {
return -1;
} else if a_addr > b_addr {
@@ -968,11 +968,11 @@ free(p: *byte) {
return;
}
- if p:int & 4095 != 0 {
+ if p as int & 4095 != 0 {
kdie("BAD FREE");
}
- fp = p:*free_page;
+ fp = p as *free_page;
fp.pa = vtop(p);
flags = rdflags();
@@ -1040,7 +1040,7 @@ direct_map(brk: *int) {
pa = 0;
pt4p = global.kpt;
- pt4 = ptov(pt4p):*int;
+ pt4 = ptov(pt4p) as *int;
brk[0] = (brk[0] + 4095) & -4096;
@@ -1051,9 +1051,9 @@ direct_map(brk: *int) {
n = 512;
- pt3 = brk[0]:*int;
+ pt3 = brk[0] as *int;
brk[0] = brk[0] + 4096;
- pt3p = (pt3:int) & ((1 << 31) - 1);
+ pt3p = (pt3 as int) & ((1 << 31) - 1);
i = (va >> 39) & 511;
pt4[i] = pt3p | 0x003;
@@ -1087,8 +1087,8 @@ invlpt() {
wrcr3(global.kpt);
return;
}
- tpt = ptov(t.pt):*int;
- kpt = ptov(global.kpt):*int;
+ tpt = ptov(t.pt) as *int;
+ kpt = ptov(global.kpt) as *int;
i = 256;
loop {
if i == 512 {
@@ -1153,7 +1153,7 @@ realtek_mkring(ring: *realtek_ring, rx: int) {
ring.count = 4096 >> 4;
ring.index = 0;
ring.ringp = alloc_page();
- ring.ring = ptov(ring.ringp):*realtek_desc;
+ ring.ring = ptov(ring.ringp) as *realtek_desc;
i = 0;
loop {
if i == ring.count {
@@ -1219,7 +1219,7 @@ init_realtek(dev: *pcidev) {
outd(io + 0xec, 0x00000010);
var mac: int;
- realtek_port = alloc():*realtek_port;
+ realtek_port = alloc() as *realtek_port;
realtek_port.io = io;
mac = ind(io); mac = mac + (ind(io + 4) << 32);
realtek_port.mac = ((mac >> 40) & 0xff)
@@ -1475,14 +1475,14 @@ struct txinfo {
alloc_tx(): *txinfo {
var pkt: *txinfo;
- pkt = alloc():*txinfo;
- bzero(pkt: *byte, 4096);
- pkt.buf = &(pkt:*byte)[1024];
+ pkt = alloc() as *txinfo;
+ bzero(pkt as *byte, 4096);
+ pkt.buf = &(pkt as *byte)[1024];
return pkt;
}
free_tx(pkt: *txinfo) {
- free(pkt:*byte);
+ free(pkt as *byte);
}
send_realtek(pkt: *txinfo) {
@@ -1520,22 +1520,22 @@ send_ether(pkt: *txinfo) {
pkt.buf = &pkt.buf[-14];
pkt.len = pkt.len + 14;
- pkt.buf[0] = (pkt.ether_dest >> 40):byte;
- pkt.buf[1] = (pkt.ether_dest >> 32):byte;
- pkt.buf[2] = (pkt.ether_dest >> 24):byte;
- pkt.buf[3] = (pkt.ether_dest >> 16):byte;
- pkt.buf[4] = (pkt.ether_dest >> 8):byte;
- pkt.buf[5] = pkt.ether_dest:byte;
+ pkt.buf[0] = (pkt.ether_dest >> 40) as byte;
+ pkt.buf[1] = (pkt.ether_dest >> 32) as byte;
+ pkt.buf[2] = (pkt.ether_dest >> 24) as byte;
+ pkt.buf[3] = (pkt.ether_dest >> 16) as byte;
+ pkt.buf[4] = (pkt.ether_dest >> 8) as byte;
+ pkt.buf[5] = pkt.ether_dest as byte;
- pkt.buf[6] = (pkt.ether_src >> 40):byte;
- pkt.buf[7] = (pkt.ether_src >> 32):byte;
- pkt.buf[8] = (pkt.ether_src >> 24):byte;
- pkt.buf[9] = (pkt.ether_src >> 16):byte;
- pkt.buf[10] = (pkt.ether_src >> 8):byte;
- pkt.buf[11] = pkt.ether_src:byte;
+ pkt.buf[6] = (pkt.ether_src >> 40) as byte;
+ pkt.buf[7] = (pkt.ether_src >> 32) as byte;
+ pkt.buf[8] = (pkt.ether_src >> 24) as byte;
+ pkt.buf[9] = (pkt.ether_src >> 16) as byte;
+ pkt.buf[10] = (pkt.ether_src >> 8) as byte;
+ pkt.buf[11] = pkt.ether_src as byte;
- pkt.buf[12] = (pkt.ether_type >> 8): byte;
- pkt.buf[13] = pkt.ether_type: byte;
+ pkt.buf[12] = (pkt.ether_type >> 8) as byte;
+ pkt.buf[13] = pkt.ether_type as byte;
send_realtek(pkt);
}
@@ -1562,50 +1562,50 @@ send_arp2(port: *realtek_port, tha: int, tpa: int) {
pkt.port = port;
// htype
- pkt.buf[0] = 0:byte;
- pkt.buf[1] = 1:byte;
+ pkt.buf[0] = 0 as byte;
+ pkt.buf[1] = 1 as byte;
// ptype
- pkt.buf[2] = (ET_IP >> 8):byte;
- pkt.buf[3] = (ET_IP):byte;
+ pkt.buf[2] = (ET_IP >> 8) as byte;
+ pkt.buf[3] = (ET_IP) as byte;
// hlen
- pkt.buf[4] = 6:byte;
+ pkt.buf[4] = 6 as byte;
// plen
- pkt.buf[5] = 4:byte;
+ pkt.buf[5] = 4 as byte;
// oper
- pkt.buf[6] = 0: byte;
- pkt.buf[7] = 2: byte;
+ pkt.buf[6] = 0 as byte;
+ pkt.buf[7] = 2 as byte;
// sha
- pkt.buf[8] = (sha >> 40): byte;
- pkt.buf[9] = (sha >> 32): byte;
- pkt.buf[10] = (sha >> 24): byte;
- pkt.buf[11] = (sha >> 16): byte;
- pkt.buf[12] = (sha >> 8): byte;
- pkt.buf[13] = sha: byte;
+ pkt.buf[8] = (sha >> 40) as byte;
+ pkt.buf[9] = (sha >> 32) as byte;
+ pkt.buf[10] = (sha >> 24) as byte;
+ pkt.buf[11] = (sha >> 16) as byte;
+ pkt.buf[12] = (sha >> 8) as byte;
+ pkt.buf[13] = sha as byte;
// spa
- pkt.buf[14] = (spa >> 24): byte;
- pkt.buf[15] = (spa >> 16): byte;
- pkt.buf[16] = (spa >> 8): byte;
- pkt.buf[17] = spa: byte;
+ pkt.buf[14] = (spa >> 24) as byte;
+ pkt.buf[15] = (spa >> 16) as byte;
+ pkt.buf[16] = (spa >> 8) as byte;
+ pkt.buf[17] = spa as byte;
// tha
- pkt.buf[18] = (tha >> 40): byte;
- pkt.buf[19] = (tha >> 32): byte;
- pkt.buf[20] = (tha >> 24): byte;
- pkt.buf[21] = (tha >> 16): byte;
- pkt.buf[22] = (tha >> 8): byte;
- pkt.buf[23] = tha: byte;
+ pkt.buf[18] = (tha >> 40) as byte;
+ pkt.buf[19] = (tha >> 32) as byte;
+ pkt.buf[20] = (tha >> 24) as byte;
+ pkt.buf[21] = (tha >> 16) as byte;
+ pkt.buf[22] = (tha >> 8) as byte;
+ pkt.buf[23] = tha as byte;
// tpa
- pkt.buf[24] = (tpa >> 24): byte;
- pkt.buf[25] = (tpa >> 16): byte;
- pkt.buf[26] = (tpa >> 8): byte;
- pkt.buf[27] = tpa: byte;
+ pkt.buf[24] = (tpa >> 24) as byte;
+ pkt.buf[25] = (tpa >> 16) as byte;
+ pkt.buf[26] = (tpa >> 8) as byte;
+ pkt.buf[27] = tpa as byte;
pkt.len = 28;
@@ -1643,53 +1643,53 @@ rx_arp(pkt: *rxinfo) {
}
// Hardware type
- x = (pkt.arp[0]:int << 8) + pkt.arp[1]:int;
+ x = (pkt.arp[0] as int << 8) + pkt.arp[1] as int;
if x != ARP_ETHER {
return;
}
// Protocol type
- x = (pkt.arp[2]:int << 8) + pkt.arp[3]:int;
+ x = (pkt.arp[2] as int << 8) + pkt.arp[3] as int;
if x != ET_IP {
return;
}
// Hardware and protocol length
- x = (pkt.arp[4]:int << 8) + pkt.arp[5]:int;
+ x = (pkt.arp[4] as int << 8) + pkt.arp[5] as int;
if x != 0x0604 {
return;
}
// Operation
- pkt.arp_op = (pkt.arp[6]:int << 8) + pkt.arp[7]:int;
+ pkt.arp_op = (pkt.arp[6] as int << 8) + pkt.arp[7] as int;
if pkt.arp_op != 1 && pkt.arp_op != 2 {
return;
}
- pkt.arp_ether_src = (pkt.arp[8]:int << 40)
- + (pkt.arp[9]:int << 32)
- + (pkt.arp[10]:int << 24)
- + (pkt.arp[11]:int << 16)
- + (pkt.arp[12]:int << 8)
- + pkt.arp[13]:int;
+ pkt.arp_ether_src = (pkt.arp[8] as int << 40)
+ + (pkt.arp[9] as int << 32)
+ + (pkt.arp[10] as int << 24)
+ + (pkt.arp[11] as int << 16)
+ + (pkt.arp[12] as int << 8)
+ + pkt.arp[13] as int;
- pkt.arp_ip_src = (pkt.arp[14]:int << 24)
- + (pkt.arp[15]:int << 16)
- + (pkt.arp[16]:int << 8)
- + pkt.arp[17]:int;
+ pkt.arp_ip_src = (pkt.arp[14] as int << 24)
+ + (pkt.arp[15] as int << 16)
+ + (pkt.arp[16] as int << 8)
+ + pkt.arp[17] as int;
- pkt.arp_ether_dest = (pkt.arp[18]:int << 40)
- + (pkt.arp[19]:int << 32)
- + (pkt.arp[20]:int << 24)
- + (pkt.arp[21]:int << 16)
- + (pkt.arp[22]:int << 8)
- + pkt.arp[23]:int;
+ pkt.arp_ether_dest = (pkt.arp[18] as int << 40)
+ + (pkt.arp[19] as int << 32)
+ + (pkt.arp[20] as int << 24)
+ + (pkt.arp[21] as int << 16)
+ + (pkt.arp[22] as int << 8)
+ + pkt.arp[23] as int;
- pkt.arp_ip_dest = (pkt.arp[24]:int << 24)
- + (pkt.arp[25]:int << 16)
- + (pkt.arp[26]:int << 8)
- + pkt.arp[27]:int;
+ pkt.arp_ip_dest = (pkt.arp[24] as int << 24)
+ + (pkt.arp[25] as int << 16)
+ + (pkt.arp[26] as int << 8)
+ + pkt.arp[27] as int;
handle_arp(pkt);
}
@@ -1708,50 +1708,50 @@ send_arp1(port: *realtek_port, tha: int, tpa: int) {
pkt.port = port;
// htype
- pkt.buf[0] = 0:byte;
- pkt.buf[1] = 1:byte;
+ pkt.buf[0] = 0 as byte;
+ pkt.buf[1] = 1 as byte;
// ptype
- pkt.buf[2] = (ET_IP >> 8):byte;
- pkt.buf[3] = (ET_IP):byte;
+ pkt.buf[2] = (ET_IP >> 8) as byte;
+ pkt.buf[3] = (ET_IP) as byte;
// hlen
- pkt.buf[4] = 6:byte;
+ pkt.buf[4] = 6 as byte;
// plen
- pkt.buf[5] = 4:byte;
+ pkt.buf[5] = 4 as byte;
// oper
- pkt.buf[6] = 0: byte;
- pkt.buf[7] = 1: byte;
+ pkt.buf[6] = 0 as byte;
+ pkt.buf[7] = 1 as byte;
// sha
- pkt.buf[8] = (sha >> 40): byte;
- pkt.buf[9] = (sha >> 32): byte;
- pkt.buf[10] = (sha >> 24): byte;
- pkt.buf[11] = (sha >> 16): byte;
- pkt.buf[12] = (sha >> 8): byte;
- pkt.buf[13] = sha: byte;
+ pkt.buf[8] = (sha >> 40) as byte;
+ pkt.buf[9] = (sha >> 32) as byte;
+ pkt.buf[10] = (sha >> 24) as byte;
+ pkt.buf[11] = (sha >> 16) as byte;
+ pkt.buf[12] = (sha >> 8) as byte;
+ pkt.buf[13] = sha as byte;
// spa
- pkt.buf[14] = (spa >> 24): byte;
- pkt.buf[15] = (spa >> 16): byte;
- pkt.buf[16] = (spa >> 8): byte;
- pkt.buf[17] = spa: byte;
+ pkt.buf[14] = (spa >> 24) as byte;
+ pkt.buf[15] = (spa >> 16) as byte;
+ pkt.buf[16] = (spa >> 8) as byte;
+ pkt.buf[17] = spa as byte;
// tha
- pkt.buf[18] = (tha >> 40): byte;
- pkt.buf[19] = (tha >> 32): byte;
- pkt.buf[20] = (tha >> 24): byte;
- pkt.buf[21] = (tha >> 16): byte;
- pkt.buf[22] = (tha >> 8): byte;
- pkt.buf[23] = tha: byte;
+ pkt.buf[18] = (tha >> 40) as byte;
+ pkt.buf[19] = (tha >> 32) as byte;
+ pkt.buf[20] = (tha >> 24) as byte;
+ pkt.buf[21] = (tha >> 16) as byte;
+ pkt.buf[22] = (tha >> 8) as byte;
+ pkt.buf[23] = tha as byte;
// tpa
- pkt.buf[24] = (tpa >> 24): byte;
- pkt.buf[25] = (tpa >> 16): byte;
- pkt.buf[26] = (tpa >> 8): byte;
- pkt.buf[27] = tpa: byte;
+ pkt.buf[24] = (tpa >> 24) as byte;
+ pkt.buf[25] = (tpa >> 16) as byte;
+ pkt.buf[26] = (tpa >> 8) as byte;
+ pkt.buf[27] = tpa as byte;
pkt.len = 28;
@@ -1841,49 +1841,49 @@ send_ip(pkt: *txinfo) {
pkt.len = pkt.len + 20;
// version + ihl
- pkt.buf[0] = 0x45:byte;
+ pkt.buf[0] = 0x45 as byte;
// dscp
- pkt.buf[1] = 0:byte;
+ pkt.buf[1] = 0 as byte;
// length
- pkt.buf[2] = (pkt.len >> 8):byte;
- pkt.buf[3] = pkt.len:byte;
+ pkt.buf[2] = (pkt.len >> 8) as byte;
+ pkt.buf[3] = pkt.len as byte;
// identifier
id = rand();
- pkt.buf[4] = (id >> 8):byte;
- pkt.buf[5] = id:byte;
+ pkt.buf[4] = (id >> 8) as byte;
+ pkt.buf[5] = id as byte;
// fragment offset
- pkt.buf[6] = 0:byte;
- pkt.buf[7] = 0:byte;
+ pkt.buf[6] = 0 as byte;
+ pkt.buf[7] = 0 as byte;
// ttl
- pkt.buf[8] = 64:byte;
+ pkt.buf[8] = 64 as byte;
// proto
- pkt.buf[9] = pkt.ip_proto:byte;
+ pkt.buf[9] = pkt.ip_proto as byte;
// checksum
- pkt.buf[10] = 0:byte;
- pkt.buf[11] = 0:byte;
+ pkt.buf[10] = 0 as byte;
+ pkt.buf[11] = 0 as byte;
// src
- pkt.buf[12] = (pkt.ip_src >> 24):byte;
- pkt.buf[13] = (pkt.ip_src >> 16):byte;
- pkt.buf[14] = (pkt.ip_src >> 8):byte;
- pkt.buf[15] = pkt.ip_src:byte;
+ pkt.buf[12] = (pkt.ip_src >> 24) as byte;
+ pkt.buf[13] = (pkt.ip_src >> 16) as byte;
+ pkt.buf[14] = (pkt.ip_src >> 8) as byte;
+ pkt.buf[15] = pkt.ip_src as byte;
// dest
- pkt.buf[16] = (pkt.ip_dest >> 24):byte;
- pkt.buf[17] = (pkt.ip_dest >> 16):byte;
- pkt.buf[18] = (pkt.ip_dest >> 8):byte;
- pkt.buf[19] = pkt.ip_dest:byte;
+ pkt.buf[16] = (pkt.ip_dest >> 24) as byte;
+ pkt.buf[17] = (pkt.ip_dest >> 16) as byte;
+ pkt.buf[18] = (pkt.ip_dest >> 8) as byte;
+ pkt.buf[19] = pkt.ip_dest as byte;
sum = ~onesum(pkt.buf, 20, 0);
- pkt.buf[10] = (sum >> 8):byte;
- pkt.buf[11] = sum:byte;
+ pkt.buf[10] = (sum >> 8) as byte;
+ pkt.buf[11] = sum as byte;
send_ether(pkt);
}
@@ -1894,18 +1894,18 @@ send_icmp(pkt: *txinfo) {
pkt.buf = &pkt.buf[-8];
pkt.len = pkt.len + 8;
- pkt.buf[0] = pkt.icmp_type:byte;
- pkt.buf[1] = pkt.icmp_code:byte;
- pkt.buf[2] = 0:byte;
- pkt.buf[3] = 0:byte;
- pkt.buf[4] = (pkt.icmp_id >> 8):byte;
- pkt.buf[5] = pkt.icmp_id:byte;
- pkt.buf[6] = (pkt.icmp_seq >> 8):byte;
- pkt.buf[7] = pkt.icmp_seq:byte;
+ pkt.buf[0] = pkt.icmp_type as byte;
+ pkt.buf[1] = pkt.icmp_code as byte;
+ pkt.buf[2] = 0 as byte;
+ pkt.buf[3] = 0 as byte;
+ pkt.buf[4] = (pkt.icmp_id >> 8) as byte;
+ pkt.buf[5] = pkt.icmp_id as byte;
+ pkt.buf[6] = (pkt.icmp_seq >> 8) as byte;
+ pkt.buf[7] = pkt.icmp_seq as byte;
sum = ~onesum(pkt.buf, pkt.len, 0);
- pkt.buf[2] = (sum >> 8):byte;
- pkt.buf[3] = sum:byte;
+ pkt.buf[2] = (sum >> 8) as byte;
+ pkt.buf[3] = sum as byte;
pkt.ip_proto = IP_ICMP;
@@ -1946,11 +1946,11 @@ rx_icmp(pkt: *rxinfo) {
return;
}
- pkt.icmp_type = pkt.icmp[0]:int;
- pkt.icmp_code = pkt.icmp[1]:int;
+ pkt.icmp_type = pkt.icmp[0] as int;
+ pkt.icmp_code = pkt.icmp[1] as int;
- pkt.icmp_id = (pkt.icmp[4]:int << 8) + pkt.icmp[5]:int;
- pkt.icmp_seq = (pkt.icmp[6]:int << 8) + pkt.icmp[7]:int;
+ pkt.icmp_id = (pkt.icmp[4] as int << 8) + pkt.icmp[5] as int;
+ pkt.icmp_seq = (pkt.icmp[6] as int << 8) + pkt.icmp[7] as int;
pkt.icmp_seg = &pkt.icmp[8];
pkt.icmp_seg_len = pkt.icmp_len - 8;
@@ -1966,14 +1966,14 @@ send_udp(pkt: *txinfo) {
pkt.buf = &pkt.buf[-8];
pkt.len = pkt.len + 8;
- pkt.buf[0] = (pkt.udp_src >> 8): byte;
- pkt.buf[1] = pkt.udp_src: byte;
- pkt.buf[2] = (pkt.udp_dest >> 8): byte;
- pkt.buf[3] = pkt.udp_dest: byte;
- pkt.buf[4] = (pkt.len >> 8): byte;
- pkt.buf[5] = pkt.len: byte;
- pkt.buf[6] = 0: byte;
- pkt.buf[7] = 0: byte;
+ pkt.buf[0] = (pkt.udp_src >> 8) as byte;
+ pkt.buf[1] = pkt.udp_src as byte;
+ pkt.buf[2] = (pkt.udp_dest >> 8) as byte;
+ pkt.buf[3] = pkt.udp_dest as byte;
+ pkt.buf[4] = (pkt.len >> 8) as byte;
+ pkt.buf[5] = pkt.len as byte;
+ pkt.buf[6] = 0 as byte;
+ pkt.buf[7] = 0 as byte;
sum = (pkt.ip_src & 0xffff)
+ ((pkt.ip_src >> 16) & 0xffff)
@@ -1983,8 +1983,8 @@ send_udp(pkt: *txinfo) {
+ pkt.len;
sum = ~onesum(pkt.buf, pkt.len, sum);
- pkt.buf[6] = (sum >> 8):byte;
- pkt.buf[7] = sum:byte;
+ pkt.buf[6] = (sum >> 8) as byte;
+ pkt.buf[7] = sum as byte;
send_ip(pkt);
}
@@ -2016,8 +2016,8 @@ rx_udp(pkt: *rxinfo) {
return;
}
- len = (pkt.udp[4]:int << 8)
- + pkt.udp[5]:int;
+ len = (pkt.udp[4] as int << 8)
+ + pkt.udp[5] as int;
if len < 8 || len > pkt.udp_len {
return;
}
@@ -2031,11 +2031,11 @@ rx_udp(pkt: *rxinfo) {
}
}
- pkt.udp_src = (pkt.udp[0]:int << 8)
- + pkt.udp[1]:int;
+ pkt.udp_src = (pkt.udp[0] as int << 8)
+ + pkt.udp[1] as int;
- pkt.udp_dest = (pkt.udp[2]:int << 8)
- + pkt.udp[3]:int;
+ pkt.udp_dest = (pkt.udp[2] as int << 8)
+ + pkt.udp[3] as int;
pkt.udp_seg = &pkt.udp[8];
pkt.udp_seg_len = pkt.udp_len - 8;
@@ -2054,25 +2054,25 @@ send_tcp(pkt: *txinfo) {
bzero(pkt.buf, len);
- pkt.buf[0] = (pkt.tcp_src >> 8):byte;
- pkt.buf[1] = pkt.tcp_src:byte;
- pkt.buf[2] = (pkt.tcp_dest >> 8):byte;
- pkt.buf[3] = pkt.tcp_dest:byte;
+ pkt.buf[0] = (pkt.tcp_src >> 8) as byte;
+ pkt.buf[1] = pkt.tcp_src as byte;
+ pkt.buf[2] = (pkt.tcp_dest >> 8) as byte;
+ pkt.buf[3] = pkt.tcp_dest as byte;
- pkt.buf[4] = (pkt.tcp_seq >> 24):byte;
- pkt.buf[5] = (pkt.tcp_seq >> 16):byte;
- pkt.buf[6] = (pkt.tcp_seq >> 8):byte;
- pkt.buf[7] = pkt.tcp_seq:byte;
+ pkt.buf[4] = (pkt.tcp_seq >> 24) as byte;
+ pkt.buf[5] = (pkt.tcp_seq >> 16) as byte;
+ pkt.buf[6] = (pkt.tcp_seq >> 8) as byte;
+ pkt.buf[7] = pkt.tcp_seq as byte;
- pkt.buf[8] = (pkt.tcp_ack >> 24):byte;
- pkt.buf[9] = (pkt.tcp_ack >> 16):byte;
- pkt.buf[10] = (pkt.tcp_ack >> 8):byte;
- pkt.buf[11] = pkt.tcp_ack:byte;
+ pkt.buf[8] = (pkt.tcp_ack >> 24) as byte;
+ pkt.buf[9] = (pkt.tcp_ack >> 16) as byte;
+ pkt.buf[10] = (pkt.tcp_ack >> 8) as byte;
+ pkt.buf[11] = pkt.tcp_ack as byte;
- pkt.buf[12] = (len << 2):byte;
- pkt.buf[13] = pkt.tcp_flags:byte;
- pkt.buf[14] = (pkt.tcp_win >> 8):byte;
- pkt.buf[15] = pkt.tcp_win:byte;
+ pkt.buf[12] = (len << 2) as byte;
+ pkt.buf[13] = pkt.tcp_flags as byte;
+ pkt.buf[14] = (pkt.tcp_win >> 8) as byte;
+ pkt.buf[15] = pkt.tcp_win as byte;
memcpy(&pkt.buf[20], pkt.tcp_opt, pkt.tcp_opt_len);
@@ -2084,8 +2084,8 @@ send_tcp(pkt: *txinfo) {
+ pkt.len;
sum = ~onesum(pkt.buf, pkt.len, sum);
- pkt.buf[16] = (sum >> 8):byte;
- pkt.buf[17] = sum:byte;
+ pkt.buf[16] = (sum >> 8) as byte;
+ pkt.buf[17] = sum as byte;
pkt.ip_proto = IP_TCP;
@@ -2107,12 +2107,12 @@ alloc_tcp(): *tcp_state {
loop {
if i == global.tcp_count {
wrflags(flags);
- return 0:*tcp_state;
+ return 0 as *tcp_state;
}
if !global.tcp[i] {
- tcb = alloc():*tcp_state;
- bzero(tcb:*byte, sizeof(*tcb));
+ tcb = alloc() as *tcp_state;
+ bzero(tcb as *byte, sizeof(*tcb));
tcb.recv_buf = alloc();
tcb.send_buf = alloc();
global.tcp[i] = tcb;
@@ -2137,14 +2137,14 @@ tcp_free(tcb: *tcp_state) {
break;
}
if global.tcp[i] == tcb {
- global.tcp[i] = 0:*tcp_state;
+ global.tcp[i] = 0 as *tcp_state;
break;
}
i = i + 1;
}
free(tcb.send_buf);
free(tcb.recv_buf);
- free(tcb:*byte);
+ free(tcb as *byte);
wrflags(flags);
}
@@ -2193,7 +2193,7 @@ task_ssh(t: *task) {
var c: byte;
var n: int;
var m: int;
- tcb = t.a:*tcp_state;
+ tcb = t.a as *tcp_state;
kputs("accept\n");
buf = alloc();
loop {
@@ -2229,7 +2229,7 @@ task_ssh(t: *task) {
tcp_ssh(tcb: *tcp_state) {
if !tcb.task {
- tcb.task = spawn(task_ssh, "sshd", tcb:*void);
+ tcb.task = spawn(task_ssh, "sshd", tcb as *void);
}
}
@@ -2242,7 +2242,7 @@ send_rst(pkt: *rxinfo) {
tx.tcp_src = pkt.tcp_dest;
tx.tcp_dest = pkt.tcp_src;
tx.tcp_win = 0;
- tx.tcp_opt = 0:*byte;
+ tx.tcp_opt = 0 as *byte;
tx.tcp_opt_len = 0;
tx.len = 0;
@@ -2273,7 +2273,7 @@ send_ack(tcb: *tcp_state) {
tx.tcp_src = tcb.sock_port;
tx.tcp_dest = tcb.peer_port;
tx.tcp_win = 4096 - tcb.recv_len;
- tx.tcp_opt = 0:*byte;
+ tx.tcp_opt = 0 as *byte;
tx.tcp_opt_len = 0;
tx.len = 0;
@@ -2300,7 +2300,7 @@ send_psh(tcb: *tcp_state) {
tx.tcp_src = tcb.sock_port;
tx.tcp_dest = tcb.peer_port;
tx.tcp_win = 4096 - tcb.recv_len;
- tx.tcp_opt = 0:*byte;
+ tx.tcp_opt = 0 as *byte;
tx.tcp_opt_len = 0;
len = tcb.send_len;
@@ -2405,7 +2405,7 @@ find_tcb(pkt: *rxinfo): *tcp_state {
i = i + 1;
}
- return 0:*tcp_state;
+ return 0 as *tcp_state;
}
handle_syn(tcb: *tcp_state, pkt: *rxinfo) {
@@ -2443,7 +2443,7 @@ handle_syn(tcb: *tcp_state, pkt: *rxinfo) {
tx.tcp_src = c.sock_port;
tx.tcp_dest = c.peer_port;
tx.tcp_win = 4096 - c.recv_len;
- tx.tcp_opt = 0:*byte;
+ tx.tcp_opt = 0 as *byte;
tx.tcp_opt_len = 0;
tx.len = 0;
@@ -2719,23 +2719,23 @@ rx_tcp(pkt: *rxinfo) {
return;
}
- pkt.tcp_src = (pkt.tcp[0]:int << 8)
- + pkt.tcp[1]:int;
- pkt.tcp_dest = (pkt.tcp[2]:int << 8)
- + pkt.tcp[3]:int;
- pkt.tcp_seq = (pkt.tcp[4]:int << 24)
- + (pkt.tcp[5]:int << 16)
- + (pkt.tcp[6]:int << 8)
- + pkt.tcp[7]:int;
- pkt.tcp_ack = (pkt.tcp[8]:int << 24)
- + (pkt.tcp[9]:int << 16)
- + (pkt.tcp[10]:int << 8)
- + pkt.tcp[11]:int;
- pkt.tcp_flags = pkt.tcp[13]:int;
- pkt.tcp_win = (pkt.tcp[14]:int << 8)
- + pkt.tcp[15]:int;
-
- off = (pkt.tcp[12]:int >> 4) << 2;
+ pkt.tcp_src = (pkt.tcp[0] as int << 8)
+ + pkt.tcp[1] as int;
+ pkt.tcp_dest = (pkt.tcp[2] as int << 8)
+ + pkt.tcp[3] as int;
+ pkt.tcp_seq = (pkt.tcp[4] as int << 24)
+ + (pkt.tcp[5] as int << 16)
+ + (pkt.tcp[6] as int << 8)
+ + pkt.tcp[7] as int;
+ pkt.tcp_ack = (pkt.tcp[8] as int << 24)
+ + (pkt.tcp[9] as int << 16)
+ + (pkt.tcp[10] as int << 8)
+ + pkt.tcp[11] as int;
+ pkt.tcp_flags = pkt.tcp[13] as int;
+ pkt.tcp_win = (pkt.tcp[14] as int << 8)
+ + pkt.tcp[15] as int;
+
+ off = (pkt.tcp[12] as int >> 4) << 2;
if off < 20 || off > pkt.tcp_len {
return;
}
@@ -2764,34 +2764,34 @@ rx_ip(pkt: *rxinfo) {
return;
}
- if pkt.ip[0] != 0x45:byte {
+ if pkt.ip[0] != 0x45 as byte {
return;
}
- len = (pkt.ip[2]:int << 8)
- + pkt.ip[3]:int;
+ len = (pkt.ip[2] as int << 8)
+ + pkt.ip[3] as int;
if len < 20 || len > pkt.ip_len {
return;
}
pkt.ip_len = len;
- frag = (pkt.ip[6]:int << 8)
- + pkt.ip[7]:int;
+ frag = (pkt.ip[6] as int << 8)
+ + pkt.ip[7] as int;
if frag & (1 << 15) != 0 || frag & 8191 != 0 {
return;
}
- pkt.ip_proto = pkt.ip[9]:int;
+ pkt.ip_proto = pkt.ip[9] as int;
- pkt.ip_src = (pkt.ip[12]:int << 24)
- + (pkt.ip[13]:int << 16)
- + (pkt.ip[14]:int << 8)
- + pkt.ip[15]:int;
- pkt.ip_dest = (pkt.ip[16]:int << 24)
- + (pkt.ip[17]:int << 16)
- + (pkt.ip[18]:int << 8)
- + pkt.ip[19]:int;
+ pkt.ip_src = (pkt.ip[12] as int << 24)
+ + (pkt.ip[13] as int << 16)
+ + (pkt.ip[14] as int << 8)
+ + pkt.ip[15] as int;
+ pkt.ip_dest = (pkt.ip[16] as int << 24)
+ + (pkt.ip[17] as int << 16)
+ + (pkt.ip[18] as int << 8)
+ + pkt.ip[19] as int;
// Pesudo header sum
pkt.ip_psum = (pkt.ip_src & 0xffff)
@@ -2827,20 +2827,20 @@ rx_ether(pkt: *rxinfo) {
return;
}
- pkt.ether_dest = (pkt.ether[0]:int << 40)
- + (pkt.ether[1]:int << 32)
- + (pkt.ether[2]:int << 24)
- + (pkt.ether[3]:int << 16)
- + (pkt.ether[4]:int << 8)
- + pkt.ether[5]:int;
- pkt.ether_src = (pkt.ether[6]:int << 40)
- + (pkt.ether[7]:int << 32)
- + (pkt.ether[8]:int << 24)
- + (pkt.ether[9]:int << 16)
- + (pkt.ether[10]:int << 8)
- + pkt.ether[11]:int;
- pkt.ether_type = (pkt.ether[12]:int << 8)
- + (pkt.ether[13]:int);
+ pkt.ether_dest = (pkt.ether[0] as int << 40)
+ + (pkt.ether[1] as int << 32)
+ + (pkt.ether[2] as int << 24)
+ + (pkt.ether[3] as int << 16)
+ + (pkt.ether[4] as int << 8)
+ + pkt.ether[5] as int;
+ pkt.ether_src = (pkt.ether[6] as int << 40)
+ + (pkt.ether[7] as int << 32)
+ + (pkt.ether[8] as int << 24)
+ + (pkt.ether[9] as int << 16)
+ + (pkt.ether[10] as int << 8)
+ + pkt.ether[11] as int;
+ pkt.ether_type = (pkt.ether[12] as int << 8)
+ + (pkt.ether[13] as int);
if pkt.ether_type == ET_ARP {
pkt.arp = &pkt.ether[14];
@@ -2982,8 +2982,8 @@ init_ahci_port(ahci: *byte, i: int) {
_w32(&port[0x30], -1);
var ahci_port: *ahci_port;
- ahci_port = ptov(alloc_page()): *ahci_port;
- ahci_port.next = 0:*ahci_port;
+ ahci_port = ptov(alloc_page()) as *ahci_port;
+ ahci_port.next = 0 as *ahci_port;
ahci_port.ahci = ahci;
ahci_port.port = port;
@@ -3070,31 +3070,31 @@ fill_fis_h2d(ahci_port: *ahci_port, cmd: int, lba: int) {
bzero(ahci_port.ctab, 4096);
// Fill command FIS
- ahci_port.ctab[0] = 0x27:byte;
- ahci_port.ctab[1] = 0x80:byte;
- ahci_port.ctab[2] = cmd:byte;
- ahci_port.ctab[3] = 0:byte;
+ ahci_port.ctab[0] = 0x27 as byte;
+ ahci_port.ctab[1] = 0x80 as byte;
+ ahci_port.ctab[2] = cmd as byte;
+ ahci_port.ctab[3] = 0 as byte;
- ahci_port.ctab[4] = lba:byte;
- ahci_port.ctab[5] = (lba >> 8):byte;
- ahci_port.ctab[6] = (lba >> 16):byte;
- ahci_port.ctab[7] = (1 << 6):byte;
+ ahci_port.ctab[4] = lba as byte;
+ ahci_port.ctab[5] = (lba >> 8) as byte;
+ ahci_port.ctab[6] = (lba >> 16) as byte;
+ ahci_port.ctab[7] = (1 << 6) as byte;
- ahci_port.ctab[8] = (lba >> 24):byte;
- ahci_port.ctab[9] = (lba >> 32):byte;
- ahci_port.ctab[10] = (lba >> 40):byte;
- ahci_port.ctab[11] = 0:byte;
+ ahci_port.ctab[8] = (lba >> 24) as byte;
+ ahci_port.ctab[9] = (lba >> 32) as byte;
+ ahci_port.ctab[10] = (lba >> 40) as byte;
+ ahci_port.ctab[11] = 0 as byte;
// Count of sectors
- ahci_port.ctab[12] = (size >> 9):byte;
- ahci_port.ctab[13] = (size >> 17):byte;
- ahci_port.ctab[14] = 0:byte;
- ahci_port.ctab[15] = 0:byte;
+ ahci_port.ctab[12] = (size >> 9) as byte;
+ ahci_port.ctab[13] = (size >> 17) as byte;
+ ahci_port.ctab[14] = 0 as byte;
+ ahci_port.ctab[15] = 0 as byte;
- ahci_port.ctab[16] = 0:byte;
- ahci_port.ctab[17] = 0:byte;
- ahci_port.ctab[18] = 0:byte;
- ahci_port.ctab[19] = 0:byte;
+ ahci_port.ctab[16] = 0 as byte;
+ ahci_port.ctab[17] = 0 as byte;
+ ahci_port.ctab[18] = 0 as byte;
+ ahci_port.ctab[19] = 0 as byte;
// Fill PRDT
_w32(&ahci_port.ctab[0x80], ahci_port.bufp);
@@ -3151,12 +3151,12 @@ tick(r: *regs) {
// round robin schedule
cur = global.curtask;
- memcpy((&cur.regs):*byte, r:*byte, sizeof(*r));
+ memcpy((&cur.regs) as *byte, r as *byte, sizeof(*r));
schedule();
next = global.curtask;
- memcpy(r:*byte, (&next.regs):*byte, sizeof(*r));
+ memcpy(r as *byte, (&next.regs) as *byte, sizeof(*r));
}
freept(pt: int) {
@@ -3172,14 +3172,14 @@ free_task(t: *task) {
}
if t.files[i] {
vclose(t.files[i]);
- t.files[i] = 0:*vfile;
+ t.files[i] = 0 as *vfile;
}
i = i + 1;
}
vclose(t.cwd);
freept(t.pt);
free(t.stack);
- free(t:*byte);
+ free(t as *byte);
}
schedule() {
@@ -3293,14 +3293,14 @@ xxd(data: *byte, len: int) {
}
if i + j < len {
- kputh8(data[i + j]: int);
+ kputh8(data[i + j] as int);
} else {
kputc(' ');
kputc(' ');
}
if i + j + 1 < len {
- kputh8(data[i + j + 1]: int);
+ kputh8(data[i + j + 1] as int);
} else {
kputc(' ');
kputc(' ');
@@ -3319,8 +3319,8 @@ xxd(data: *byte, len: int) {
break;
}
- if data[i + j]:int >= 0x20 && data[i + j]:int < 0x80 {
- kputc(data[i + j]: int);
+ if data[i + j] as int >= 0x20 && data[i + j] as int < 0x80 {
+ kputc(data[i + j] as int);
} else {
kputc('.');
}
@@ -3442,7 +3442,7 @@ read_rtc() {
break;
}
- days_since_epoch = days_since_epoch + (days_in_month[i]:int - '0' + 28);
+ days_since_epoch = days_since_epoch + (days_in_month[i] as int - '0' + 28);
i = i + 1;
}
@@ -3469,15 +3469,15 @@ spawn(f: (func(t: *task)), name: *byte, a: *void): *task {
var next: *task;
var flags: int;
global = g();
- t = alloc():*task;
- bzero(t:*byte, sizeof(*t));
- t.files = alloc(): **vfile;
- bzero(t.files:*byte, 4096);
+ t = alloc() as *task;
+ bzero(t as *byte, sizeof(*t));
+ t.files = alloc() as **vfile;
+ bzero(t.files as *byte, 4096);
t.stack = alloc();
bzero(t.stack, 4096);
t.name = name;
- t.regs.rsp = (t.stack:int) + 4096;
- t.regs.rip = _tstart:int;
+ t.regs.rsp = (t.stack as int) + 4096;
+ t.regs.rip = _tstart as int;
t.regs.cs = 8;
t.regs.ss = 16;
t.f = f;
@@ -3559,7 +3559,7 @@ strndup(s: *byte, n: int): *byte {
}
r = alloc();
memcpy(r, s, n);
- r[n] = 0:byte;
+ r[n] = 0 as byte;
return r;
}
@@ -3571,14 +3571,14 @@ mkvnode(): *vnode {
var v: *vnode;
var global: *global;
global = g();
- v = alloc():*vnode;
+ v = alloc() as *vnode;
v.refcount = 1;
global.next_ino = global.next_ino + 1;
v.nlink = 0;
v.ino = global.next_ino;
v.size = 0;
- v.pages = 0:*vpage;
- v.ents = 0:*vent;
+ v.pages = 0 as *vpage;
+ v.ents = 0 as *vent;
return v;
}
@@ -3587,7 +3587,7 @@ mkfile(v: *vnode, mode: int): *vfile {
if !v {
v = mkvnode();
}
- f = alloc():*vfile;
+ f = alloc() as *vfile;
f.refcount = 1;
f.mode = mode;
f.offset = 0;
@@ -3597,7 +3597,7 @@ mkfile(v: *vnode, mode: int): *vfile {
mkroot(): *vfile {
var f: *vfile;
- f = mkfile(0:*vnode, S_IFDIR);
+ f = mkfile(0 as *vnode, S_IFDIR);
f.node.nlink = 1;
vlink(f, ".", 1, f);
return f;
@@ -3626,7 +3626,7 @@ vlink(d: *vfile, name: *byte, nlen: int, f: *vfile) {
e.node.nlink = e.node.nlink - 1;
e.node = vnodedup(f.node);
} else {
- e = alloc():*vent;
+ e = alloc() as *vent;
e.name = strndup(name, nlen);
e.node = vnodedup(f.node);
f.node.nlink = f.node.nlink + 1;
@@ -3643,7 +3643,7 @@ vlookup(d: *vfile, name: *byte, nlen: int, flags: int, mode: int): *vfile {
var e: *vent;
if !d {
- return 0:*vfile;
+ return 0 as *vfile;
}
e = efind(d, name, nlen);
@@ -3654,15 +3654,15 @@ vlookup(d: *vfile, name: *byte, nlen: int, flags: int, mode: int): *vfile {
f = mkfile(e.node, S_IFREG);
}
} else {
- f = 0:*vfile;
+ f = 0 as *vfile;
}
if flags & O_CREAT && !f {
if flags & O_DIRECTORY {
- f = mkfile(0:*vnode, S_IFDIR);
+ f = mkfile(0 as *vnode, S_IFDIR);
vlink(f, ".", 1, f);
} else {
- f = mkfile(0:*vnode, S_IFREG);
+ f = mkfile(0 as *vnode, S_IFREG);
}
vlink(d, name, nlen, f);
}
@@ -3674,12 +3674,12 @@ vlookup(d: *vfile, name: *byte, nlen: int, flags: int, mode: int): *vfile {
if flags & O_DIRECTORY {
if f.mode != S_IFDIR {
vclose(f);
- return 0: *vfile;
+ return 0 as *vfile;
}
} else {
if f.mode != S_IFREG {
vclose(f);
- return 0: *vfile;
+ return 0 as *vfile;
}
}
@@ -3696,7 +3696,7 @@ vopen(name: *byte, flags: int, mode: int): *vfile {
global = g();
- if name[0] == '/':byte {
+ if name[0] == '/' as byte {
d = vdup(global.root);
} else {
d = vdup(global.curtask.cwd);
@@ -3708,7 +3708,7 @@ vopen(name: *byte, flags: int, mode: int): *vfile {
if !name[i] {
break;
}
- if name[i] != '/':byte {
+ if name[i] != '/' as byte {
n = i + 1;
}
i = i + 1;
@@ -3719,7 +3719,7 @@ vopen(name: *byte, flags: int, mode: int): *vfile {
loop {
if j == n {
break;
- } else if name[j] == '/':byte {
+ } else if name[j] == '/' as byte {
if i == j {
i = i + 1;
j = j + 1;
@@ -3762,16 +3762,16 @@ vrelease_page(p: *vpage) {
q = p.parent;
if q {
if q.left == p {
- q.left = 0:*vpage;
+ q.left = 0 as *vpage;
} else {
- q.right = 0:*vpage;
+ q.right = 0 as *vpage;
}
}
- p.parent = 0:*vpage;
+ p.parent = 0 as *vpage;
free(p.page);
- free(p:*byte);
+ free(p as *byte);
p = q;
}
@@ -3792,11 +3792,11 @@ vrelease(v: *vnode): int {
n = e.next;
vrelease(e.node);
free(e.name);
- free(e:*byte);
+ free(e as *byte);
e = n;
}
vrelease_page(v.pages);
- free(v:*byte);
+ free(v as *byte);
return 0;
}
@@ -3814,7 +3814,7 @@ vclose(f: *vfile): int {
n = f.node;
- free(f:*byte);
+ free(f as *byte);
return vrelease(n);
}
@@ -3853,10 +3853,10 @@ vwrite_page(v: *vnode, o: int, b: *byte, n: int): int {
p = v.pages;
if !p {
- q = alloc(): *vpage;
- q.parent = 0:*vpage;
- q.left = 0:*vpage;
- q.right = 0:*vpage;
+ q = alloc() as *vpage;
+ q.parent = 0 as *vpage;
+ q.left = 0 as *vpage;
+ q.right = 0 as *vpage;
q.offset = key;
q.page = alloc();
bzero(q.page, 4096);
@@ -3867,10 +3867,10 @@ vwrite_page(v: *vnode, o: int, b: *byte, n: int): int {
loop {
if key < p.offset {
if !p.left {
- q = alloc(): *vpage;
+ q = alloc() as *vpage;
q.parent = p;
- q.left = 0:*vpage;
- q.right = 0:*vpage;
+ q.left = 0 as *vpage;
+ q.right = 0 as *vpage;
q.offset = key;
q.page = alloc();
bzero(q.page, 4096);
@@ -3881,10 +3881,10 @@ vwrite_page(v: *vnode, o: int, b: *byte, n: int): int {
}
} else if key > p.offset {
if ! p.right {
- q = alloc(): *vpage;
+ q = alloc() as *vpage;
q.parent = p;
- q.left = 0:*vpage;
- q.right = 0:*vpage;
+ q.left = 0 as *vpage;
+ q.right = 0 as *vpage;
q.offset = key;
q.page = alloc();
bzero(q.page, 4096);
@@ -4038,7 +4038,7 @@ _ssr(r: *regs) {
kputs("read\n");
r.rax = -1;
} else if r.rax == 1 {
- xxd(r.rsi:*byte, r.rdx);
+ xxd(r.rsi as *byte, r.rdx);
r.rax = r.rdx;
} else if r.rax == 2 {
kputs("open\n");
@@ -4122,12 +4122,12 @@ parse_hex32(i: int, r: *byte, n: int, x: *int): int {
j = j - 4;
- if r[i] >= '0':byte && r[i] <= '9':byte {
- z = z | ((r[i]:int - '0') << j);
- } else if r[i] >= 'a':byte && r[i] <= 'f':byte {
- z = z | ((r[i]:int - 'a' + 10) << j);
- } else if r[i] >= 'A':byte && r[i] <= 'F':byte {
- z = z | ((r[i]:int - 'A' + 10) << j);
+ if r[i] >= '0' as byte && r[i] <= '9' as byte {
+ z = z | ((r[i] as int - '0') << j);
+ } else if r[i] >= 'a' as byte && r[i] <= 'f' as byte {
+ z = z | ((r[i] as int - 'a' + 10) << j);
+ } else if r[i] >= 'A' as byte && r[i] <= 'F' as byte {
+ z = z | ((r[i] as int - 'A' + 10) << j);
} else {
return -1;
}
@@ -4268,7 +4268,7 @@ initramfs_create(name: *byte, data: *byte, size: int, mode: int) {
userswitch(entry: int, stack: int) {
var r: regs;
var discard: regs;
- bzero((&r):*byte, sizeof(r));
+ bzero((&r) as *byte, sizeof(r));
r.rflags = 0x200;
r.rip = entry;
r.cs = 40 | 3;
@@ -4285,34 +4285,34 @@ map_user(vaddr: int): *byte {
var i: int;
if (vaddr >> 47) != 0 || (vaddr & 4095) != 0 {
- return 0: *byte;
+ return 0 as *byte;
}
global = g();
task = global.curtask;
- pt = ptov(task.pt):*int;
+ pt = ptov(task.pt) as *int;
i = (vaddr >> 39) & 255;
if !pt[i] {
pt[i] = alloc_page() | 7;
bzero(ptov(pt[i] & -4096), 4096);
}
- pt = ptov(pt[i] & -4096):*int;
+ pt = ptov(pt[i] & -4096) as *int;
i = (vaddr >> 30) & 511;
if !pt[i] {
pt[i] = alloc_page() | 7;
bzero(ptov(pt[i] & -4096), 4096);
}
- pt = ptov(pt[i] & -4096):*int;
+ pt = ptov(pt[i] & -4096) as *int;
i = (vaddr >> 21) & 511;
if !pt[i] {
pt[i] = alloc_page() | 7;
bzero(ptov(pt[i] & -4096), 4096);
}
- pt = ptov(pt[i] & -4096):*int;
+ pt = ptov(pt[i] & -4096) as *int;
i = (vaddr >> 12) & 511;
if !pt[i] {
@@ -4321,7 +4321,7 @@ map_user(vaddr: int): *byte {
return ptov(pt[i] & -4096);
}
- return 0:*byte;
+ return 0 as *byte;
}
vload(f: *vfile, offset: int, vaddr: int, filesz: int, memsz: int): int {
@@ -4381,7 +4381,7 @@ vload(f: *vfile, offset: int, vaddr: int, filesz: int, memsz: int): int {
return 0;
}
-map_stack(argc: int, argv: **byte, envc: int, envv: **byte):int {
+map_stack(argc: int, argv: **byte, envc: int, envv: **byte): int {
var m: *int;
var i: int;
var sp: int;
@@ -4389,7 +4389,7 @@ map_stack(argc: int, argv: **byte, envc: int, envv: **byte):int {
var len: int;
sp = 0x7fffe000;
- m = map_user(sp): *int;
+ m = map_user(sp) as *int;
if !m {
return 0;
@@ -4413,7 +4413,7 @@ map_stack(argc: int, argv: **byte, envc: int, envv: **byte):int {
return 0;
}
- memcpy(&(m:*byte)[n], argv[i], len + 1);
+ memcpy(&(m as *byte)[n], argv[i], len + 1);
m[i + 1] = sp + n;
@@ -4433,7 +4433,7 @@ map_stack(argc: int, argv: **byte, envc: int, envv: **byte):int {
return 0;
}
- memcpy(&(m:*byte)[n], envv[i], len + 1);
+ memcpy(&(m as *byte)[n], envv[i], len + 1);
m[argc + i + 1] = sp + n;
@@ -4487,11 +4487,11 @@ vexec(prog: *byte, argv: **byte, envp: **byte): int {
bzero(ptov(t.pt), 4096);
head = alloc();
- args = alloc():**byte;
- envs = alloc():**byte;
+ args = alloc() as **byte;
+ envs = alloc() as **byte;
nargs = 0;
nenv = 0;
- f = 0:*vfile;
+ f = 0 as *vfile;
// Copy args
if argv {
@@ -4529,7 +4529,7 @@ vexec(prog: *byte, argv: **byte, envp: **byte): int {
}
n = vread(f, head, 4096);
- if n >= 2 && head[0] == '#':byte && head[1] == '!':byte {
+ if n >= 2 && head[0] == '#' as byte && head[1] == '!' as byte {
nargs = nargs + 1;
i = nargs;
loop {
@@ -4545,7 +4545,7 @@ vexec(prog: *byte, argv: **byte, envp: **byte): int {
if i == n {
goto fail;
}
- if head[i] == '\n':byte {
+ if head[i] == '\n' as byte {
break;
}
i = i + 1;
@@ -4560,7 +4560,7 @@ vexec(prog: *byte, argv: **byte, envp: **byte): int {
args[1] = strdup(prog);
prog = args[0];
vclose(f);
- f = 0: *vfile;
+ f = 0 as *vfile;
continue;
}
@@ -4575,74 +4575,74 @@ vexec(prog: *byte, argv: **byte, envp: **byte): int {
}
// magic
- if !(head[0]:int == 0x7f && head[1]:int == 0x45 && head[2]:int == 0x4c && head[3]:int == 0x46) {
+ if !(head[0] as int == 0x7f && head[1] as int == 0x45 && head[2] as int == 0x4c && head[3] as int == 0x46) {
goto fail;
}
// 64 bit
- if head[4]:int != 2 {
+ if head[4] as int != 2 {
goto fail;
}
// little endian
- if head[5]:int != 1 {
+ if head[5] as int != 1 {
goto fail;
}
// version
- if head[6]:int != 1 {
+ if head[6] as int != 1 {
goto fail;
}
// executable
- if head[17]:int != 0 || head[16]:int != 2 {
+ if head[17] as int != 0 || head[16] as int != 2 {
goto fail;
}
// machine
- if head[19]:int != 0 || head[18]:int != 0x3e {
+ if head[19] as int != 0 || head[18] as int != 0x3e {
goto fail;
}
// version
- if !(head[23]:int == 0 && head[22]:int == 0 && head[21]:int == 0 && head[20]:int == 1) {
+ if !(head[23] as int == 0 && head[22] as int == 0 && head[21] as int == 0 && head[20] as int == 1) {
goto fail;
}
// ehsize
- if !(head[0x35]:int == 0 && head[0x34]:int == 0x40) {
+ if !(head[0x35] as int == 0 && head[0x34] as int == 0x40) {
goto fail;
}
// phentsize
- if !(head[0x37]:int == 0 && head[0x36]:int == 0x38) {
+ if !(head[0x37] as int == 0 && head[0x36] as int == 0x38) {
goto fail;
}
// entry point
- entry = head[24]:int
- | (head[25]:int << 8)
- | (head[26]:int << 16)
- | (head[27]:int << 24)
- | (head[28]:int << 32)
- | (head[29]:int << 40)
- | (head[30]:int << 48)
- | (head[31]:int << 56);
+ entry = head[24] as int
+ | (head[25] as int << 8)
+ | (head[26] as int << 16)
+ | (head[27] as int << 24)
+ | (head[28] as int << 32)
+ | (head[29] as int << 40)
+ | (head[30] as int << 48)
+ | (head[31] as int << 56);
if entry < 0 {
goto fail;
}
- phoff = head[32]:int
- | (head[33]:int << 8)
- | (head[34]:int << 16)
- | (head[35]:int << 24)
- | (head[36]:int << 32)
- | (head[37]:int << 40)
- | (head[38]:int << 48)
- | (head[39]:int << 56);
+ phoff = head[32] as int
+ | (head[33] as int << 8)
+ | (head[34] as int << 16)
+ | (head[35] as int << 24)
+ | (head[36] as int << 32)
+ | (head[37] as int << 40)
+ | (head[38] as int << 48)
+ | (head[39] as int << 56);
- phnum = head[0x38]:int
- | (head[0x39]:int << 8);
+ phnum = head[0x38] as int
+ | (head[0x39] as int << 8);
if phnum > 64 {
goto fail;
}
@@ -4666,42 +4666,42 @@ vexec(prog: *byte, argv: **byte, envp: **byte): int {
break;
}
- p_type = head[i * 56 + 0]:int
- | (head[i * 56 + 1]:int << 8)
- | (head[i * 56 + 2]:int << 16)
- | (head[i * 56 + 3]:int << 24);
- p_offset = head[i * 56 + 8]:int
- | (head[i * 56 + 9]:int << 8)
- | (head[i * 56 + 10]:int << 16)
- | (head[i * 56 + 11]:int << 24)
- | (head[i * 56 + 12]:int << 32)
- | (head[i * 56 + 13]:int << 40)
- | (head[i * 56 + 14]:int << 48)
- | (head[i * 56 + 15]:int << 56);
- p_vaddr = head[i * 56 + 16]:int
- | (head[i * 56 + 17]:int << 8)
- | (head[i * 56 + 18]:int << 16)
- | (head[i * 56 + 19]:int << 24)
- | (head[i * 56 + 20]:int << 32)
- | (head[i * 56 + 21]:int << 40)
- | (head[i * 56 + 22]:int << 48)
- | (head[i * 56 + 23]:int << 56);
- p_filesz = head[i * 56 + 32]:int
- | (head[i * 56 + 33]:int << 8)
- | (head[i * 56 + 34]:int << 16)
- | (head[i * 56 + 35]:int << 24)
- | (head[i * 56 + 36]:int << 32)
- | (head[i * 56 + 37]:int << 40)
- | (head[i * 56 + 38]:int << 48)
- | (head[i * 56 + 39]:int << 56);
- p_memsz = head[i * 56 + 40]:int
- | (head[i * 56 + 41]:int << 8)
- | (head[i * 56 + 42]:int << 16)
- | (head[i * 56 + 43]:int << 24)
- | (head[i * 56 + 44]:int << 32)
- | (head[i * 56 + 45]:int << 40)
- | (head[i * 56 + 46]:int << 48)
- | (head[i * 56 + 47]:int << 56);
+ p_type = head[i * 56 + 0] as int
+ | (head[i * 56 + 1] as int << 8)
+ | (head[i * 56 + 2] as int << 16)
+ | (head[i * 56 + 3] as int << 24);
+ p_offset = head[i * 56 + 8] as int
+ | (head[i * 56 + 9] as int << 8)
+ | (head[i * 56 + 10] as int << 16)
+ | (head[i * 56 + 11] as int << 24)
+ | (head[i * 56 + 12] as int << 32)
+ | (head[i * 56 + 13] as int << 40)
+ | (head[i * 56 + 14] as int << 48)
+ | (head[i * 56 + 15] as int << 56);
+ p_vaddr = head[i * 56 + 16] as int
+ | (head[i * 56 + 17] as int << 8)
+ | (head[i * 56 + 18] as int << 16)
+ | (head[i * 56 + 19] as int << 24)
+ | (head[i * 56 + 20] as int << 32)
+ | (head[i * 56 + 21] as int << 40)
+ | (head[i * 56 + 22] as int << 48)
+ | (head[i * 56 + 23] as int << 56);
+ p_filesz = head[i * 56 + 32] as int
+ | (head[i * 56 + 33] as int << 8)
+ | (head[i * 56 + 34] as int << 16)
+ | (head[i * 56 + 35] as int << 24)
+ | (head[i * 56 + 36] as int << 32)
+ | (head[i * 56 + 37] as int << 40)
+ | (head[i * 56 + 38] as int << 48)
+ | (head[i * 56 + 39] as int << 56);
+ p_memsz = head[i * 56 + 40] as int
+ | (head[i * 56 + 41] as int << 8)
+ | (head[i * 56 + 42] as int << 16)
+ | (head[i * 56 + 43] as int << 24)
+ | (head[i * 56 + 44] as int << 32)
+ | (head[i * 56 + 45] as int << 40)
+ | (head[i * 56 + 46] as int << 48)
+ | (head[i * 56 + 47] as int << 56);
if p_type == 1 {
if vload(f, p_offset, p_vaddr, p_filesz, p_memsz) != 0 {
@@ -4740,8 +4740,8 @@ vexec(prog: *byte, argv: **byte, envp: **byte): int {
i = i + 1;
}
free(head);
- free(args:*byte);
- free(envs:*byte);
+ free(args as *byte);
+ free(envs as *byte);
freept(pt);
userswitch(entry, stack);
kdie("unreachable");
@@ -4771,8 +4771,8 @@ vexec(prog: *byte, argv: **byte, envp: **byte): int {
i = i + 1;
}
free(head);
- free(args:*byte);
- free(envs:*byte);
+ free(args as *byte);
+ free(envs as *byte);
freept(t.pt);
t.pt = pt;
return -1;
@@ -4782,7 +4782,7 @@ task_init(t: *task) {
// open("/dev/null") => 0
// open("/dev/tty") => 1
// dup(1) => 2
- if vexec("/init", 0:**byte, 0:**byte) != 0 {
+ if vexec("/init", 0 as **byte, 0 as **byte) != 0 {
kdie("failed to exec init");
}
}
@@ -4808,40 +4808,40 @@ _kstart(mb: int) {
var mmap_count: int;
var fr: *free_range;
- bzero((&task):*byte, sizeof(task));
+ bzero((&task) as *byte, sizeof(task));
task.next = &task;
task.prev = &task;
task.name = "_kstart";
task.pt = rdcr3();
- bzero((&global):*byte, sizeof(global));
+ bzero((&global) as *byte, sizeof(global));
global.ptr = &global;
global.ip = (192 << 24) + (168 << 16) + (1 << 8) + 148;
global.ip_gw = (192 << 24) + (168 << 16) + (1 << 8) + 1;
global.ip_mask = 20;
global.curtask = &task;
- wrmsr(0xc0000101, global.ptr:int);
+ wrmsr(0xc0000101, global.ptr as int);
global.mmio = -(1 << 31);
- brk = ptov(1024 * 1024 * 3):int;
+ brk = ptov(1024 * 1024 * 3) as int;
- vinit(&global.vga, ptov(0xB8000), brk:*byte);
+ vinit(&global.vga, ptov(0xB8000), brk as *byte);
brk = brk + 4096;
vclear(&global.vga);
kputs("Starting up\n");
- global.fr = 0:*free_range;
- global.fp = 0:*free_page;
+ global.fr = 0 as *free_range;
+ global.fp = 0 as *free_page;
global.kpt = rdcr3();
mbinfo = ptov(mb);
- mmap = ptov(_r32(&mbinfo[48]) + 4): *int;
+ mmap = ptov(_r32(&mbinfo[48]) + 4) as *int;
mmap_len = _r32(&mbinfo[44]);
mmap_count = mmap_len / 24;
- insert_sort(mmap:*void, mmap_count, 24, mmap_cmp);
+ insert_sort(mmap as *void, mmap_count, 24, mmap_cmp);
var i: int;
var mmap_start: int;
@@ -4872,8 +4872,8 @@ _kstart(mb: int) {
mmap_start = 0x400000;
}
- if mmap_start < mmap_end && _r32((&mmap[i * 3 + 2]):*byte) == 1 {
- fr = brk: *free_range;
+ if mmap_start < mmap_end && _r32((&mmap[i * 3 + 2]) as *byte) == 1 {
+ fr = brk as *free_range;
brk = brk + sizeof(*fr);
fr.next = global.fr;
fr.start = mmap_start;
@@ -4888,18 +4888,18 @@ _kstart(mb: int) {
direct_map(&brk);
// Zero tss and add interrupt stacks
- tss = brk: *int;
+ tss = brk as *int;
tss_size = 104;
brk = brk + tss_size;
- bzero(tss: *byte, tss_size);
+ bzero(tss as *byte, tss_size);
// Fill idt with interrupt gates
- idt = brk: *int;
+ idt = brk as *int;
idt_size = 4096;
brk = brk + idt_size;
fill_idt(idt);
- gdt = brk: *int;
+ gdt = brk as *int;
gdt_size = 8 * 9;
// Null segment
@@ -4917,12 +4917,12 @@ _kstart(mb: int) {
// User data segment
gdt[6] = 0x0000f200 << 32;
// Task segment
- gdt_tss(&gdt[7], tss: int, tss_size, 0x89, 0);
+ gdt_tss(&gdt[7], tss as int, tss_size, 0x89, 0);
// Load gdt idt tss and segments
lgdt(gdt, gdt_size);
lseg(8, 16);
- wrmsr(0xc0000101, global.ptr:int);
+ wrmsr(0xc0000101, global.ptr as int);
lldt(0);
ltr(7 * 8);
lidt(idt, idt_size);
@@ -4930,7 +4930,7 @@ _kstart(mb: int) {
// STAR
wrmsr(0xc0000081, ((24 + 3) << 48) | (8 << 32));
// LSTAR
- wrmsr(0xc0000082, (_ssr0): int);
+ wrmsr(0xc0000082, (_ssr0) as int);
// FMASK
wrmsr(0xc0000084, -1);
// EFER
@@ -4939,13 +4939,13 @@ _kstart(mb: int) {
// interrupt stack
brk = (brk + 4095) & -4096;
brk = brk + 64 * 1024;
- ((tss:int + 0x24):*int)[0] = brk;
- ((tss:int + 0x04):*int)[0] = brk;
+ ((tss as int + 0x24) as *int)[0] = brk;
+ ((tss as int + 0x04) as *int)[0] = brk;
// nmi stack
brk = (brk + 4095) & -4096;
brk = brk + 64 * 1024;
- ((tss:int + 0x2c):*int)[0] = brk;
+ ((tss as int + 0x2c) as *int)[0] = brk;
// mask pic
outb(IO_PIC1 + 1, 0xff);
@@ -4977,12 +4977,12 @@ _kstart(mb: int) {
outb(IO_PIC2 + 1, 0xff);
// Allocate network state tables
- global.arp = alloc():*arp_entry;
+ global.arp = alloc() as *arp_entry;
global.arp_count = 4096 / sizeof(*global.arp);
- global.tcp = alloc():**tcp_state;
+ global.tcp = alloc() as **tcp_state;
global.tcp_count = 4096 / sizeof(*global.tcp);
- bzero(global.arp: *byte, 4096);
- bzero(global.tcp: *byte, 4096);
+ bzero(global.arp as *byte, 4096);
+ bzero(global.tcp as *byte, 4096);
read_rtc();
sti();
@@ -4998,7 +4998,7 @@ _kstart(mb: int) {
kdie("No mcfg?\n");
}
- pcip = (ptov(mcfg + 44):*int)[0];
+ pcip = (ptov(mcfg + 44) as *int)[0];
if !pcip {
kdie("No pci?\n");
}
@@ -5021,7 +5021,7 @@ _kstart(mb: int) {
parse_initramfs();
- spawn(task_init, "init", 0:*void);
+ spawn(task_init, "init", 0 as *void);
// Wait for interrupts
kputs("zzz\n");
diff --git a/lib.om b/lib.om
@@ -8,7 +8,7 @@ strlen(s: *byte): int {
var ret: int;
ret = 0;
loop {
- if (s[ret] == 0:byte) {
+ if (s[ret] == 0 as byte) {
return ret;
}
ret = ret + 1;
@@ -51,7 +51,7 @@ strcmp(a: *byte, b: *byte): int {
return -1;
}
- if (a[i] == 0:byte) {
+ if (a[i] == 0 as byte) {
return 0;
}
@@ -64,7 +64,7 @@ fdgetc(fd: int): int {
var ret: int;
ret = read(fd, &b, 1);
if (ret == 1) {
- return b:int;
+ return b as int;
} else if (ret == 0) {
return -1;
} else {
@@ -75,7 +75,7 @@ fdgetc(fd: int): int {
fdputc(fd: int, ch: int) {
var b: byte;
var ret: int;
- b = ch: byte;
+ b = ch as byte;
ret = write(fd, &b, 1);
if (ret != 1) {
exit(3);
@@ -111,7 +111,7 @@ fdputh(fd: int, n: int) {
fdputh(fd, n);
}
- fdputc(fd, "0123456789abcdef"[d]:int);
+ fdputc(fd, "0123456789abcdef"[d] as int);
}
fdputhn(fd: int, x: int, d: int) {
@@ -120,7 +120,7 @@ fdputhn(fd: int, x: int, d: int) {
break;
}
d = d - 4;
- fdputc(fd, "0123456789abcdef"[(x >> d) & 15]:int);
+ fdputc(fd, "0123456789abcdef"[(x >> d) & 15] as int);
}
}
@@ -175,8 +175,8 @@ xxd_line(line: *byte, offset: int, data: *byte, len: int) {
line[i + 5] = d[(offset >> 8) & 15];
line[i + 6] = d[(offset >> 4) & 15];
line[i + 7] = d[offset & 15];
- line[i + 8] = ':':byte;
- line[i + 9] = ' ':byte;
+ line[i + 8] = ':' as byte;
+ line[i + 9] = ' ' as byte;
i = i + 10;
@@ -187,28 +187,28 @@ xxd_line(line: *byte, offset: int, data: *byte, len: int) {
}
if j < len {
- line[i] = d[(data[j]:int >> 4) & 15];
- line[i + 1] = d[data[j]:int & 15];
+ line[i] = d[(data[j] as int >> 4) & 15];
+ line[i + 1] = d[data[j] as int & 15];
} else {
- line[i] = ' ':byte;
- line[i + 1] = ' ':byte;
+ line[i] = ' ' as byte;
+ line[i + 1] = ' ' as byte;
}
if j + 1 < len {
- line[i + 2] = d[(data[j + 1]:int >> 4) & 15];
- line[i + 3] = d[data[j + 1]:int & 15];
+ line[i + 2] = d[(data[j + 1] as int >> 4) & 15];
+ line[i + 3] = d[data[j + 1] as int & 15];
} else {
- line[i + 2] = ' ':byte;
- line[i + 3] = ' ':byte;
+ line[i + 2] = ' ' as byte;
+ line[i + 3] = ' ' as byte;
}
- line[i + 4] = ' ':byte;
+ line[i + 4] = ' ' as byte;
j = j + 2;
i = i + 5;
}
- line[i] = ' ':byte;
+ line[i] = ' ' as byte;
i = i + 1;
j = 0;
@@ -217,20 +217,20 @@ xxd_line(line: *byte, offset: int, data: *byte, len: int) {
break;
}
- if data[j]:int >= 0x20 && data[j]:int < 0x80 {
+ if data[j] as int >= 0x20 && data[j] as int < 0x80 {
line[i] = data[j];
} else {
- line[i] = '.':byte;
+ line[i] = '.' as byte;
}
j = j + 1;
i = i + 1;
}
- line[i] = '\n':byte;
+ line[i] = '\n' as byte;
i = i + 1;
- line[i] = 0:byte;
+ line[i] = 0 as byte;
}
fdxxd(fd: int, data: *byte, len: int) {
@@ -254,14 +254,14 @@ fdxxd(fd: int, data: *byte, len: int) {
}
if i + j < len {
- fdputh8(fd, data[i + j]: int);
+ fdputh8(fd, data[i + j] as int);
} else {
fdputc(fd, ' ');
fdputc(fd, ' ');
}
if i + j + 1 < len {
- fdputh8(fd, data[i + j + 1]: int);
+ fdputh8(fd, data[i + j + 1] as int);
} else {
fdputc(fd, ' ');
fdputc(fd, ' ');
@@ -280,8 +280,8 @@ fdxxd(fd: int, data: *byte, len: int) {
break;
}
- if data[i + j]:int >= 0x20 && data[i + j]:int < 0x80 {
- fdputc(fd, data[i + j]: int);
+ if data[i + j] as int >= 0x20 && data[i + j] as int < 0x80 {
+ fdputc(fd, data[i + j] as int);
} else {
fdputc(fd, '.');
}
@@ -302,7 +302,7 @@ bzero(s: *byte, size: int) {
if i == size {
break;
}
- s[i] = 0:byte;
+ s[i] = 0 as byte;
i = i + 1;
}
}
@@ -319,7 +319,7 @@ memset(dest: *byte, c: int, size: int) {
if i == size {
break;
}
- dest[i] = c:byte;
+ dest[i] = c as byte;
i = i + 1;
}
}
@@ -361,7 +361,7 @@ unhex(dest: *byte, src: *byte): int {
i = 0;
dlen = 0;
loop {
- x = src[i]:int;
+ x = src[i] as int;
if x == 0 {
break;
@@ -383,7 +383,7 @@ unhex(dest: *byte, src: *byte): int {
continue;
}
- y = src[i + 1]:int;
+ y = src[i + 1] as int;
if y == 0 {
break;
@@ -400,7 +400,7 @@ unhex(dest: *byte, src: *byte): int {
continue;
}
- dest[dlen] = ((x << 4) | y):byte;
+ dest[dlen] = ((x << 4) | y) as byte;
dlen = dlen + 1;
i = i + 2;
}
@@ -488,7 +488,7 @@ hex2int(s: *byte, len: int, ok: *int): int {
break;
}
- d = s[i]:int;
+ d = s[i] as int;
if d == '_' {
i = i + 1;
@@ -537,7 +537,7 @@ dec2int(s: *byte, len: int, ok: *int): int {
break;
}
- d = s[i]:int;
+ d = s[i] as int;
if d == '_' {
i = i + 1;
continue;
@@ -596,7 +596,7 @@ unescape(s: *byte, i: *int, len: int, ok: *int): int {
return 0;
}
- ch = s[*i]:int;
+ ch = s[*i] as int;
*i = *i + 1;
if ch != '\\' {
@@ -608,7 +608,7 @@ unescape(s: *byte, i: *int, len: int, ok: *int): int {
return 0;
}
- ch = s[*i]:int;
+ ch = s[*i] as int;
*i = *i + 1;
if ch == 't' {
@@ -629,7 +629,7 @@ unescape(s: *byte, i: *int, len: int, ok: *int): int {
return 0;
}
- ch = s[*i]:int;
+ ch = s[*i] as int;
*i = *i + 1;
hex = hexdig(ch, ok) * 16;
@@ -642,7 +642,7 @@ unescape(s: *byte, i: *int, len: int, ok: *int): int {
return 0;
}
- ch = s[*i]:int;
+ ch = s[*i] as int;
*i = *i + 1;
hex = hex | hexdig(ch, ok);
diff --git a/ls.om b/ls.om
@@ -33,7 +33,7 @@ main(argc: int, argv: **byte, envp: **byte) {
fdputs(1, &buf[i + 19]);
fdputc(1, ' ');
- i = i + ((&buf[i + 16]):*int[0] & 0xffff);
+ i = i + ((&buf[i + 16]) as *int[0] & 0xffff);
}
}
diff --git a/node.om b/node.om
@@ -74,26 +74,26 @@ enum {
mknode(c: *parser, kind: int, a: *node, b: *node): *node {
var ret: *node;
- ret = alloc(c.a, sizeof(*ret)):*node;
+ ret = alloc(c.a, sizeof(*ret)) as *node;
ret.kind = kind;
ret.a = a;
ret.b = b;
- ret.filename = 0:*byte;
+ ret.filename = 0 as *byte;
ret.lineno = 0;
ret.colno = 0;
ret.n = 0;
- ret.s = 0:*byte;
- ret.t = 0:*type;
+ ret.s = 0 as *byte;
+ ret.t = 0 as *type;
fillpos(c, ret);
return ret;
}
mknode0(c: *parser, kind: int): *node {
- return mknode(c, kind, 0:*node, 0:*node);
+ return mknode(c, kind, 0 as *node, 0 as *node);
}
mknode1(c: *parser, kind: int, a: *node): *node {
- return mknode(c, kind, a, 0:*node);
+ return mknode(c, kind, a, 0 as *node);
}
concat_program(a: *node, b: *node): *node {
@@ -203,15 +203,15 @@ show_node(out: *file, n: *node) {
fputc(out, '"');
i = 0;
loop {
- ch = n.s[i]:int;
+ ch = n.s[i] as int;
if !ch {
break;
}
if ch < 32 || ch > 127 || ch == '\\' || ch == '"' {
fputc(out, '\\');
fputc(out, 'x');
- fputc(out, hex[ch >> 4]:int);
- fputc(out, hex[ch & 15]:int);
+ fputc(out, hex[ch >> 4] as int);
+ fputc(out, hex[ch & 15] as int);
} else {
fputc(out, ch);
}
diff --git a/parse2.om b/parse2.om
@@ -6,7 +6,7 @@ struct parser {
setup_parser(a: *alloc): *parser {
var c: *parser;
- c = alloc(a, sizeof(*c)):*parser;
+ c = alloc(a, sizeof(*c)) as *parser;
c.a = a;
@@ -56,7 +56,7 @@ reconstruct(c: *parser, pn: *peg_node): *node {
var p: *node;
assert(pn.tag == P_grammar, "grammar");
- ret = 0:*node;
+ ret = 0 as *node;
link = &ret;
pn = pn.child;
@@ -103,7 +103,7 @@ reconstruct_intern(c: *parser, pn: *peg_node, s: *byte, len: int): *node {
n.s[i] = s[i];
i = i + 1;
}
- n.s[i] = 0:byte;
+ n.s[i] = 0 as byte;
return n;
}
@@ -119,7 +119,7 @@ reconstruct_enum_item(c: *parser, pn: *peg_node): *node {
assert(pn.tag == P_enum_item, "enum_item");
a = reconstruct_ident(c, pn.child);
- b = 0:*node;
+ b = 0 as *node;
if pn.child.next {
b = reconstruct_expr(c, pn.child.next);
@@ -138,7 +138,7 @@ reconstruct_enum(c: *parser, pn: *peg_node): *node {
var n: *node;
assert(pn.tag == P_enum_decl, "enum_decl");
- n = mknode(c, N_ENUM, 0:*node, 0:*node);
+ n = mknode(c, N_ENUM, 0 as *node, 0 as *node);
copypos(n, pn);
pn = pn.child.next;
@@ -181,7 +181,7 @@ reconstruct_func_type(c: *parser, pn: *peg_node): *node {
var link: **node;
assert(pn.tag == P_func_type, "func_type");
- n = mknode(c, N_FUNCTYPE, 0:*node, 0:*node);
+ n = mknode(c, N_FUNCTYPE, 0 as *node, 0 as *node);
copypos(n, pn);
pn = pn.child;
@@ -254,7 +254,7 @@ reconstruct_member_list(c: *parser, pn: *peg_node): *node {
var ret: *node;
var link: **node;
- ret = 0:*node;
+ ret = 0 as *node;
link = &ret;
loop {
if !pn {
@@ -533,7 +533,7 @@ reconstruct_args(c: *parser, pn: *peg_node): *node {
var a: *node;
var n: *node;
- ret = 0:*node;
+ ret = 0 as *node;
link = &ret;
loop {
if !pn {
@@ -668,10 +668,10 @@ reconstruct_str(c: *parser, pn: *peg_node): *node {
if !ok {
die("invalid escape");
}
- s[j] = ch:byte;
+ s[j] = ch as byte;
j = j + 1;
}
- s[j] = 0:byte;
+ s[j] = 0 as byte;
n = mknode0(c, N_STR);
copypos(n, pn);
n.s = s;
@@ -766,7 +766,7 @@ reconstruct_if(c: *parser, pn: *peg_node): *node {
*link = n;
link = &n.b;
} else if pn.tag == P_else_stmt {
- a = 0:*node;
+ a = 0 as *node;
b = reconstruct_compound(c, pn.child.next);
n = mknode1(c, N_CONDLIST, mknode(c, N_COND, a, b));
copypos(n, pn);
@@ -814,7 +814,7 @@ reconstruct_return(c: *parser, pn: *peg_node): *node {
var a: *node;
var n: *node;
assert(pn.tag == P_return_stmt, "return_stmt");
- a = 0:*node;
+ a = 0 as *node;
if pn.child.next {
a = reconstruct_expr(c, pn.child.next);
}
@@ -874,7 +874,7 @@ reconstruct_expr_stmt(c: *parser, pn: *peg_node): *node {
reconstruct_empty(c: *parser, pn: *peg_node): *node {
assert(pn.tag == P_empty_stmt, "empty_stmt");
- return 0:*node;
+ return 0 as *node;
}
reconstruct_compound(c: *parser, pn: *peg_node): *node {
@@ -884,7 +884,7 @@ reconstruct_compound(c: *parser, pn: *peg_node): *node {
var link: **node;
assert(pn.tag == P_compound_stmt, "compound_stmt");
pn = pn.child;
- ret = 0:*node;
+ ret = 0 as *node;
link = &ret;
loop {
if ! pn {
diff --git a/peg.om b/peg.om
@@ -19,9 +19,9 @@ decode_look(n: *peg_node): int {
ret = LOOK_NORMAL;
if n.child.tag == PEG_lookop {
- if n.child.str[0] == '!':byte {
+ if n.child.str[0] == '!' as byte {
ret = LOOK_NOT;
- } else if n.child.str[0] == '&':byte {
+ } else if n.child.str[0] == '&' as byte {
ret = LOOK_AND;
}
}
@@ -47,15 +47,15 @@ decode_count(n: *peg_node): int {
}
if n.tag == PEG_countop {
- if n.str[0] == '?':byte {
+ if n.str[0] == '?' as byte {
if ret == EXACTLY_ONE {
ret = ZERO_OR_ONE;
} else if ret == ONE_OR_MORE {
ret = ZERO_OR_MORE;
}
- } else if n.str[0] == '*':byte {
+ } else if n.str[0] == '*' as byte {
ret = ZERO_OR_MORE;
- } else if n.str[0] == '+':byte {
+ } else if n.str[0] == '+' as byte {
if ret == ZERO_OR_ONE {
ret = ZERO_OR_MORE;
} else if ret == EXACTLY_ONE {
@@ -88,13 +88,13 @@ translate_literal(c: *peg_compiler, n: *peg_node) {
break;
}
- ch = n.str[i]:int;
+ ch = n.str[i] as int;
if ch < 32 || ch > 127 || ch == '\\' || ch == '"' {
fputc(c.out, '\\');
fputc(c.out, 'x');
- fputc(c.out, hex[ch >> 4]:int);
- fputc(c.out, hex[ch & 15]:int);
+ fputc(c.out, hex[ch >> 4] as int);
+ fputc(c.out, hex[ch & 15] as int);
} else {
fputc(c.out, ch);
}
@@ -112,7 +112,7 @@ parse_escape(s: *byte, i: *int, n: int): int {
die("invalid escape");
}
- nc = s[*i]:int;
+ nc = s[*i] as int;
*i = *i + 1;
if nc == 't' {
@@ -137,11 +137,11 @@ parse_escape(s: *byte, i: *int, n: int): int {
if n - *i < 2 {
die("invalid escape");
}
- nc = hexdig(s[*i]:int, &ok) * 16;
+ nc = hexdig(s[*i] as int, &ok) * 16;
if !ok {
die("invalid hex");
}
- nc = nc + hexdig(s[*i + 1]:int, &ok);
+ nc = nc + hexdig(s[*i + 1] as int, &ok);
if !ok {
die("invalid hex");
}
@@ -172,14 +172,14 @@ translate_charset(c: *peg_compiler, n: *peg_node) {
break;
}
- ch = n.str[i]:int;
+ ch = n.str[i] as int;
i = i + 1;
if ch == '\\' {
ch = parse_escape(n.str, &i, len);
}
- if i < len && n.str[i] == '-':byte {
+ if i < len && n.str[i] == '-' as byte {
i = i + 1;
if i == len {
@@ -188,7 +188,7 @@ translate_charset(c: *peg_compiler, n: *peg_node) {
a = ch;
- ch = n.str[i]:int;
+ ch = n.str[i] as int;
i = i + 1;
if ch == '\\' {
@@ -202,12 +202,12 @@ translate_charset(c: *peg_compiler, n: *peg_node) {
break;
}
- c.scratch[a] = 1:byte;
+ c.scratch[a] = 1 as byte;
a = a + 1;
}
} else {
- c.scratch[ch] = 1:byte;
+ c.scratch[ch] = 1 as byte;
}
}
@@ -217,7 +217,7 @@ translate_charset(c: *peg_compiler, n: *peg_node) {
if i == 256 {
break;
}
- count = count + c.scratch[i]:int;
+ count = count + c.scratch[i] as int;
i = i + 1;
}
@@ -244,8 +244,8 @@ translate_charset(c: *peg_compiler, n: *peg_node) {
if ch < 32 || ch > 127 || ch == '\\' || ch == '"' {
fputc(c.out, '\\');
fputc(c.out, 'x');
- fputc(c.out, hex[i >> 4]:int);
- fputc(c.out, hex[i & 15]:int);
+ fputc(c.out, hex[i >> 4] as int);
+ fputc(c.out, hex[i & 15] as int);
} else {
fputc(c.out, i);
}
@@ -448,7 +448,7 @@ translate(c: *peg_compiler, n: *peg_node) {
setup_peg(a: *alloc, prefix: *byte): *peg_compiler {
var c: *peg_compiler;
- c = alloc(a, sizeof(*c)): *peg_compiler;
+ c = alloc(a, sizeof(*c)) as *peg_compiler;
c.a = a;
c.prefix = prefix;
c.scratch = alloc(c.a, 256);
diff --git a/peglib.om b/peglib.om
@@ -92,7 +92,7 @@ fail(c: *peg) {
c.fail_tag = c.tag;
c.fail_line = c.line;
c.fail_col = c.col;
- c.fail_literal = 0:*byte;
+ c.fail_literal = 0 as *byte;
}
c.sp = c.sp - 1;
@@ -111,7 +111,7 @@ get(c: *peg): int {
return -1;
}
- ch = c.src[c.pos]:int;
+ ch = c.src[c.pos] as int;
c.pos = c.pos + 1;
c.col = c.col + 1;
@@ -138,7 +138,7 @@ literal(c: *peg, s: *byte): int {
}
ch = get(c);
- if ch != (s[i]:int) {
+ if ch != (s[i] as int) {
fail(c);
c.fail_literal = s;
return 0;
@@ -175,13 +175,13 @@ leave(c: *peg, tag: int) {
if c.op == c.cap {
if c.cap == 0 {
c.cap = 1024;
- c.out = alloc(c.a, c.cap * sizeof(c.out[0])):*peg_op;
+ c.out = alloc(c.a, c.cap * sizeof(c.out[0])) as *peg_op;
} else {
c.cap = c.cap * 2;
tmp = alloc(c.a, c.cap * sizeof(c.out[0]));
- memcpy(tmp, c.out:*byte, c.op * sizeof(c.out[0]));
- free(c.a, c.out:*byte);
- c.out = tmp:*peg_op;
+ memcpy(tmp, c.out as *byte, c.op * sizeof(c.out[0]));
+ free(c.a, c.out as *byte);
+ c.out = tmp as *peg_op;
}
}
@@ -209,7 +209,7 @@ charset(c: *peg, s: *byte): int {
return 0;
}
- if ch == (s[i]:int) {
+ if ch == (s[i] as int) {
break;
}
@@ -236,7 +236,7 @@ construct(c: *peg, sp: int): *peg_node {
var n: *peg_node;
var link: **peg_node;
- c.nstack[0] = 0:*peg_node;
+ c.nstack[0] = 0 as *peg_node;
i = 0;
loop {
@@ -245,11 +245,11 @@ construct(c: *peg, sp: int): *peg_node {
}
if c.out[i].tag != sp {
- n = alloc(c.a, sizeof(*n)):*peg_node;
+ n = alloc(c.a, sizeof(*n)) as *peg_node;
n.tag = c.out[i].tag;
- n.next = 0:*peg_node;
- n.child = 0:*peg_node;
+ n.next = 0 as *peg_node;
+ n.child = 0 as *peg_node;
n.str = &c.src[c.out[i].start];
n.len = c.out[i].end - c.out[i].start;
n.filename = c.filename;
@@ -281,7 +281,7 @@ construct(c: *peg, sp: int): *peg_node {
die("node overflow");
}
} else {
- n = 0:*peg_node;
+ n = 0 as *peg_node;
}
c.nstack[c.np] = n;
@@ -294,7 +294,7 @@ construct(c: *peg, sp: int): *peg_node {
peg_new(filename: *byte, src: *byte, len: int, a: *alloc, grammar: (func(c:*peg):int), tag_to_str: (func(t:int):*byte)): *peg {
var c: *peg;
- c = alloc(a, sizeof(*c)):*peg;
+ c = alloc(a, sizeof(*c)) as *peg;
c.a = a;
@@ -315,19 +315,19 @@ peg_new(filename: *byte, src: *byte, len: int, a: *alloc, grammar: (func(c:*peg)
c.fail_tag = 0;
c.fail_line = 0;
c.fail_col = 0;
- c.fail_literal = 0:*byte;
+ c.fail_literal = 0 as *byte;
c.limit = 1024;
- c.stack = alloc(a, c.limit * sizeof(*c.stack)):*peg_frame;
+ c.stack = alloc(a, c.limit * sizeof(*c.stack)) as *peg_frame;
c.sp = 0;
c.depth = 0;
c.op = 0;
- c.out = 0:*peg_op;
+ c.out = 0 as *peg_op;
c.cap = 0;
c.ncap = 1024;
- c.nstack = alloc(a, c.ncap * sizeof(*c.nstack)):**peg_node;
+ c.nstack = alloc(a, c.ncap * sizeof(*c.nstack)) as **peg_node;
c.np = 0;
return c;
@@ -369,7 +369,7 @@ peg_reset(c: *peg, filename: *byte, src: *byte, len: int) {
c.fail_tag = 0;
c.fail_line = 0;
c.fail_col = 0;
- c.fail_literal = 0:*byte;
+ c.fail_literal = 0 as *byte;
c.depth = 0;
c.sp = 0;
c.op = 0;
@@ -377,10 +377,10 @@ peg_reset(c: *peg, filename: *byte, src: *byte, len: int) {
}
peg_free(c: *peg) {
- free(c.a, c.stack: *byte);
- free(c.a, c.nstack: *byte);
- free(c.a, c.out: *byte);
- free(c.a, c: *byte);
+ free(c.a, c.stack as *byte);
+ free(c.a, c.nstack as *byte);
+ free(c.a, c.out as *byte);
+ free(c.a, c as *byte);
}
peg_show(c: *peg, out: *file, n: *peg_node) {
@@ -411,12 +411,12 @@ peg_show(c: *peg, out: *file, n: *peg_node) {
break;
}
- ch = n.str[i]:int;
+ ch = n.str[i] as int;
if ch < 32 || ch > 127 || ch == '\\' || ch == '"' {
fputc(out, '\\');
fputc(out, 'x');
- fputc(out, hex[ch >> 4]:int);
- fputc(out, hex[ch & 15]:int);
+ fputc(out, hex[ch >> 4] as int);
+ fputc(out, hex[ch & 15] as int);
} else {
fputc(out, ch);
}
diff --git a/poly1305.om b/poly1305.om
@@ -39,31 +39,31 @@ poly1305_load(dest: *int, src: *byte, n: int) {
if i == n {
break;
}
- dest[i] = src[i * 4]:int
- | (src[i * 4 + 1]:int << 8)
- | (src[i * 4 + 2]:int << 16)
- | (src[i * 4 + 3]:int << 24);
+ dest[i] = src[i * 4] as int
+ | (src[i * 4 + 1] as int << 8)
+ | (src[i * 4 + 2] as int << 16)
+ | (src[i * 4 + 3] as int << 24);
i = i + 1;
}
}
poly1305_digest(dest: *byte, src: *int) {
- dest[0] = src[0]:byte;
- dest[1] = (src[0] >> 8):byte;
- dest[2] = (src[0] >> 16):byte;
- dest[3] = (src[0] >> 24):byte;
- dest[4] = src[1]:byte;
- dest[5] = (src[1] >> 8):byte;
- dest[6] = (src[1] >> 16):byte;
- dest[7] = (src[1] >> 24):byte;
- dest[8] = src[2]:byte;
- dest[9] = (src[2] >> 8):byte;
- dest[10] = (src[2] >> 16):byte;
- dest[11] = (src[2] >> 24):byte;
- dest[12] = src[3]:byte;
- dest[13] = (src[3] >> 8):byte;
- dest[14] = (src[3] >> 16):byte;
- dest[15] = (src[3] >> 24):byte;
+ dest[0] = src[0] as byte;
+ dest[1] = (src[0] >> 8) as byte;
+ dest[2] = (src[0] >> 16) as byte;
+ dest[3] = (src[0] >> 24) as byte;
+ dest[4] = src[1] as byte;
+ dest[5] = (src[1] >> 8) as byte;
+ dest[6] = (src[1] >> 16) as byte;
+ dest[7] = (src[1] >> 24) as byte;
+ dest[8] = src[2] as byte;
+ dest[9] = (src[2] >> 8) as byte;
+ dest[10] = (src[2] >> 16) as byte;
+ dest[11] = (src[2] >> 24) as byte;
+ dest[12] = src[3] as byte;
+ dest[13] = (src[3] >> 8) as byte;
+ dest[14] = (src[3] >> 16) as byte;
+ dest[15] = (src[3] >> 24) as byte;
}
poly1305_add(a: *int, x: *int) {
@@ -81,7 +81,7 @@ poly1305_mul(a: *int, r: *int) {
var i: int;
var c: int;
- x = (&_x):*int;
+ x = (&_x) as *int;
x[0] = 0;
x[1] = 0;
@@ -159,7 +159,7 @@ poly1305_pad(dest: *int, msg: *byte, n: int) {
var pad: *byte;
var i: int;
- pad = (&_pad):*byte;
+ pad = (&_pad) as *byte;
i = 0;
loop {
@@ -172,7 +172,7 @@ poly1305_pad(dest: *int, msg: *byte, n: int) {
i = i + 1;
}
- pad[i] = 1:byte;
+ pad[i] = 1 as byte;
i = i + 1;
loop {
@@ -180,7 +180,7 @@ poly1305_pad(dest: *int, msg: *byte, n: int) {
break;
}
- pad[i] = 0:byte;
+ pad[i] = 0 as byte;
i = i + 1;
}
@@ -197,9 +197,9 @@ poly1305(mac: *byte, key: *byte, msg: *byte, len: int) {
var s: *int;
var i: int;
- a = (&_a):*int;
- r = (&_r):*int;
- s = (&_s):*int;
+ a = (&_a) as *int;
+ r = (&_r) as *int;
+ s = (&_s) as *int;
a[0] = 0;
a[1] = 0;
diff --git a/sh.om b/sh.om
@@ -30,7 +30,7 @@ enum {
feedc(s: *shell) {
if s.script[0] {
- s.c = s.script[0]:int;
+ s.c = s.script[0] as int;
s.script = &s.script[1];
return;
}
@@ -50,7 +50,7 @@ feedw(s: *shell) {
if s.c == -1 {
die("unexpected EOF");
}
- s.buf[s.len] = s.c:byte;
+ s.buf[s.len] = s.c as byte;
s.len = s.len + 1;
feedc(s);
}
@@ -267,8 +267,8 @@ struct cmd {
mkcmd(s: *shell, kind: int): *cmd {
var c: *cmd;
- c = alloc(s.a, sizeof(*c)):*cmd;
- bzero(c:*byte, sizeof(*c));
+ c = alloc(s.a, sizeof(*c)) as *cmd;
+ bzero(c as *byte, sizeof(*c));
c.kind = kind;
return c;
}
@@ -286,7 +286,7 @@ parse_command(s: *shell): *cmd {
c = parse_and_or(s);
if !c {
- return 0:*cmd;
+ return 0 as *cmd;
}
if s.tt != T_LF {
@@ -306,12 +306,12 @@ parse_and_or(s: *shell): *cmd {
var p: *cmd;
var t: *cmd;
- c = 0:*cmd;
+ c = 0 as *cmd;
link = &c;
c = parse_pipeline(s);
if !c {
- return 0:*cmd;
+ return 0 as *cmd;
}
loop {
@@ -355,7 +355,7 @@ parse_pipeline(s: *shell): *cmd {
var p: *cmd;
var t: *cmd;
- c = 0:*cmd;
+ c = 0 as *cmd;
link = &c;
if s.tt == T_NOT {
@@ -374,7 +374,7 @@ parse_pipeline(s: *shell): *cmd {
} else {
c = parse_compound(s);
if !c {
- return 0:*cmd;
+ return 0 as *cmd;
}
}
@@ -416,7 +416,7 @@ parse_compound(s: *shell): *cmd {
return c;
}
- return 0:*cmd;
+ return 0 as *cmd;
}
// subshell = '(' command_list ')'
@@ -426,11 +426,11 @@ parse_subshell(s: *shell): *cmd {
var link: **cmd;
var t: *cmd;
- body = 0:*cmd;
+ body = 0 as *cmd;
link = &body;
if s.tt != T_LPAR {
- return 0:*cmd;
+ return 0 as *cmd;
}
feed(s);
@@ -481,13 +481,13 @@ parse_for(s: *shell): *cmd {
var t: *cmd;
var w: *byte;
- arg = 0:*cmd;
+ arg = 0 as *cmd;
arg_link = &arg;
- body = 0:*cmd;
+ body = 0 as *cmd;
body_link = &body;
if !parse_keyword(s, "for") {
- return 0:*cmd;
+ return 0 as *cmd;
}
w = take(s);
@@ -552,9 +552,9 @@ parse_simple(s: *shell): *cmd {
var t: *cmd;
var w: *byte;
- arg = 0:*cmd;
+ arg = 0 as *cmd;
arg_link = &arg;
- redir = 0:*cmd;
+ redir = 0 as *cmd;
redir_link = &redir;
w = take(s);
@@ -569,7 +569,7 @@ parse_simple(s: *shell): *cmd {
*redir_link = t;
redir_link = &t.next;
} else {
- return 0: *cmd;
+ return 0 as *cmd;
}
}
@@ -604,7 +604,7 @@ parse_redir_list(s: *shell): *cmd {
var t: *cmd;
var link: **cmd;
- c = 0:*cmd;
+ c = 0 as *cmd;
link = &c;
loop {
@@ -621,12 +621,12 @@ take(s: *shell): *byte {
var w: *byte;
if s.tt != T_WORD {
- return 0: *byte;
+ return 0 as *byte;
}
w = alloc(s.a, s.len + 1);
memcpy(w, s.buf, s.len);
- w[s.len] = 0:byte;
+ w[s.len] = 0 as byte;
feed(s);
return w;
@@ -660,7 +660,7 @@ parse_redir(s: *shell): *cmd {
return c;
}
- return 0:*cmd;
+ return 0 as *cmd;
}
execute_command(s: *shell, c: *cmd) {
@@ -718,7 +718,7 @@ main(argc: int, argv: **byte, envp: **byte) {
var fd: int;
setup_alloc(&a);
- bzero((&s):*byte, sizeof(s));
+ bzero((&s) as *byte, sizeof(s));
s.a = &a;
if argc <= 1 {
@@ -726,7 +726,7 @@ main(argc: int, argv: **byte, envp: **byte) {
s.script = "";
s.prog = "";
s.argc = 0;
- s.argv = 0:**byte;
+ s.argv = 0 as **byte;
} else if strcmp(argv[1], "--") == 0 {
s.scriptfd = 0;
s.script = "";
diff --git a/sha256.om b/sha256.om
@@ -118,70 +118,70 @@ sha256_rounds(ctx: *sha256_ctx, block: *byte) {
r.g = ctx.g;
r.h = ctx.h;
- w[0] = (block[0]:int << 24)
- | (block[1]:int << 16)
- | (block[2]:int << 8)
- | block[3]:int;
- w[1] = (block[4]:int << 24)
- | (block[5]:int << 16)
- | (block[6]:int << 8)
- | block[7]:int;
- w[2] = (block[8]:int << 24)
- | (block[9]:int << 16)
- | (block[10]:int << 8)
- | block[11]:int;
- w[3] = (block[12]:int << 24)
- | (block[13]:int << 16)
- | (block[14]:int << 8)
- | block[15]:int;
- w[4] = (block[16]:int << 24)
- | (block[17]:int << 16)
- | (block[18]:int << 8)
- | block[19]:int;
- w[5] = (block[20]:int << 24)
- | (block[21]:int << 16)
- | (block[22]:int << 8)
- | block[23]:int;
- w[6] = (block[24]:int << 24)
- | (block[25]:int << 16)
- | (block[26]:int << 8)
- | block[27]:int;
- w[7] = (block[28]:int << 24)
- | (block[29]:int << 16)
- | (block[30]:int << 8)
- | block[31]:int;
- w[8] = (block[32]:int << 24)
- | (block[33]:int << 16)
- | (block[34]:int << 8)
- | block[35]:int;
- w[9] = (block[36]:int << 24)
- | (block[37]:int << 16)
- | (block[38]:int << 8)
- | block[39]:int;
- w[10] = (block[40]:int << 24)
- | (block[41]:int << 16)
- | (block[42]:int << 8)
- | block[43]:int;
- w[11] = (block[44]:int << 24)
- | (block[45]:int << 16)
- | (block[46]:int << 8)
- | block[47]:int;
- w[12] = (block[48]:int << 24)
- | (block[49]:int << 16)
- | (block[50]:int << 8)
- | block[51]:int;
- w[13] = (block[52]:int << 24)
- | (block[53]:int << 16)
- | (block[54]:int << 8)
- | block[55]:int;
- w[14] = (block[56]:int << 24)
- | (block[57]:int << 16)
- | (block[58]:int << 8)
- | block[59]:int;
- w[15] = (block[60]:int << 24)
- | (block[61]:int << 16)
- | (block[62]:int << 8)
- | block[63]:int;
+ w[0] = (block[0] as int << 24)
+ | (block[1] as int << 16)
+ | (block[2] as int << 8)
+ | block[3] as int;
+ w[1] = (block[4] as int << 24)
+ | (block[5] as int << 16)
+ | (block[6] as int << 8)
+ | block[7] as int;
+ w[2] = (block[8] as int << 24)
+ | (block[9] as int << 16)
+ | (block[10] as int << 8)
+ | block[11] as int;
+ w[3] = (block[12] as int << 24)
+ | (block[13] as int << 16)
+ | (block[14] as int << 8)
+ | block[15] as int;
+ w[4] = (block[16] as int << 24)
+ | (block[17] as int << 16)
+ | (block[18] as int << 8)
+ | block[19] as int;
+ w[5] = (block[20] as int << 24)
+ | (block[21] as int << 16)
+ | (block[22] as int << 8)
+ | block[23] as int;
+ w[6] = (block[24] as int << 24)
+ | (block[25] as int << 16)
+ | (block[26] as int << 8)
+ | block[27] as int;
+ w[7] = (block[28] as int << 24)
+ | (block[29] as int << 16)
+ | (block[30] as int << 8)
+ | block[31] as int;
+ w[8] = (block[32] as int << 24)
+ | (block[33] as int << 16)
+ | (block[34] as int << 8)
+ | block[35] as int;
+ w[9] = (block[36] as int << 24)
+ | (block[37] as int << 16)
+ | (block[38] as int << 8)
+ | block[39] as int;
+ w[10] = (block[40] as int << 24)
+ | (block[41] as int << 16)
+ | (block[42] as int << 8)
+ | block[43] as int;
+ w[11] = (block[44] as int << 24)
+ | (block[45] as int << 16)
+ | (block[46] as int << 8)
+ | block[47] as int;
+ w[12] = (block[48] as int << 24)
+ | (block[49] as int << 16)
+ | (block[50] as int << 8)
+ | block[51] as int;
+ w[13] = (block[52] as int << 24)
+ | (block[53] as int << 16)
+ | (block[54] as int << 8)
+ | block[55] as int;
+ w[14] = (block[56] as int << 24)
+ | (block[57] as int << 16)
+ | (block[58] as int << 8)
+ | block[59] as int;
+ w[15] = (block[60] as int << 24)
+ | (block[61] as int << 16)
+ | (block[62] as int << 8)
+ | block[63] as int;
sha256_round(&r, w, 0x428a2f98);
sha256_round(&r, w, 0x71374491);
@@ -264,7 +264,7 @@ sha256_finish(ctx: *sha256_ctx, nblocks: int, data: *byte, len: int) {
var pad: int;
var i: int;
- final = (&_final):*byte;
+ final = (&_final) as *byte;
pad = nblocks * 512;
@@ -293,7 +293,7 @@ sha256_finish(ctx: *sha256_ctx, nblocks: int, data: *byte, len: int) {
i = i + 1;
}
- final[i] = 0x80:byte;
+ final[i] = 0x80 as byte;
i = i + 1;
loop {
@@ -301,7 +301,7 @@ sha256_finish(ctx: *sha256_ctx, nblocks: int, data: *byte, len: int) {
break;
}
- final[i] = 0:byte;
+ final[i] = 0 as byte;
i = i + 1;
}
@@ -315,57 +315,57 @@ sha256_finish(ctx: *sha256_ctx, nblocks: int, data: *byte, len: int) {
break;
}
- final[i] = 0:byte;
+ final[i] = 0 as byte;
i = i + 1;
}
}
- final[56] = (pad >> 56):byte;
- final[57] = (pad >> 48):byte;
- final[58] = (pad >> 40):byte;
- final[59] = (pad >> 32):byte;
- final[60] = (pad >> 24):byte;
- final[61] = (pad >> 16):byte;
- final[62] = (pad >> 8):byte;
- final[63] = pad:byte;
+ final[56] = (pad >> 56) as byte;
+ final[57] = (pad >> 48) as byte;
+ final[58] = (pad >> 40) as byte;
+ final[59] = (pad >> 32) as byte;
+ final[60] = (pad >> 24) as byte;
+ final[61] = (pad >> 16) as byte;
+ final[62] = (pad >> 8) as byte;
+ final[63] = pad as byte;
sha256_rounds(ctx, final);
}
sha256_digest(digest: *byte, ctx: *sha256_ctx) {
- digest[0] = (ctx.a >> 24):byte;
- digest[1] = (ctx.a >> 16):byte;
- digest[2] = (ctx.a >> 8):byte;
- digest[3] = ctx.a:byte;
- digest[4] = (ctx.b >> 24):byte;
- digest[5] = (ctx.b >> 16):byte;
- digest[6] = (ctx.b >> 8):byte;
- digest[7] = ctx.b:byte;
- digest[8] = (ctx.c >> 24):byte;
- digest[9] = (ctx.c >> 16):byte;
- digest[10] = (ctx.c >> 8):byte;
- digest[11] = ctx.c:byte;
- digest[12] = (ctx.d >> 24):byte;
- digest[13] = (ctx.d >> 16):byte;
- digest[14] = (ctx.d >> 8):byte;
- digest[15] = ctx.d:byte;
- digest[16] = (ctx.e >> 24):byte;
- digest[17] = (ctx.e >> 16):byte;
- digest[18] = (ctx.e >> 8):byte;
- digest[19] = ctx.e:byte;
- digest[20] = (ctx.f >> 24):byte;
- digest[21] = (ctx.f >> 16):byte;
- digest[22] = (ctx.f >> 8):byte;
- digest[23] = ctx.f:byte;
- digest[24] = (ctx.g >> 24):byte;
- digest[25] = (ctx.g >> 16):byte;
- digest[26] = (ctx.g >> 8):byte;
- digest[27] = ctx.g:byte;
- digest[28] = (ctx.h >> 24):byte;
- digest[29] = (ctx.h >> 16):byte;
- digest[30] = (ctx.h >> 8):byte;
- digest[31] = ctx.h:byte;
+ digest[0] = (ctx.a >> 24) as byte;
+ digest[1] = (ctx.a >> 16) as byte;
+ digest[2] = (ctx.a >> 8) as byte;
+ digest[3] = ctx.a as byte;
+ digest[4] = (ctx.b >> 24) as byte;
+ digest[5] = (ctx.b >> 16) as byte;
+ digest[6] = (ctx.b >> 8) as byte;
+ digest[7] = ctx.b as byte;
+ digest[8] = (ctx.c >> 24) as byte;
+ digest[9] = (ctx.c >> 16) as byte;
+ digest[10] = (ctx.c >> 8) as byte;
+ digest[11] = ctx.c as byte;
+ digest[12] = (ctx.d >> 24) as byte;
+ digest[13] = (ctx.d >> 16) as byte;
+ digest[14] = (ctx.d >> 8) as byte;
+ digest[15] = ctx.d as byte;
+ digest[16] = (ctx.e >> 24) as byte;
+ digest[17] = (ctx.e >> 16) as byte;
+ digest[18] = (ctx.e >> 8) as byte;
+ digest[19] = ctx.e as byte;
+ digest[20] = (ctx.f >> 24) as byte;
+ digest[21] = (ctx.f >> 16) as byte;
+ digest[22] = (ctx.f >> 8) as byte;
+ digest[23] = ctx.f as byte;
+ digest[24] = (ctx.g >> 24) as byte;
+ digest[25] = (ctx.g >> 16) as byte;
+ digest[26] = (ctx.g >> 8) as byte;
+ digest[27] = ctx.g as byte;
+ digest[28] = (ctx.h >> 24) as byte;
+ digest[29] = (ctx.h >> 16) as byte;
+ digest[30] = (ctx.h >> 8) as byte;
+ digest[31] = ctx.h as byte;
}
sha256(digest: *byte, data: *byte, dlen: int) {
@@ -385,9 +385,9 @@ sha256_hmac(mac: *byte, key: *byte, klen: int, data: *byte, dlen: int) {
var ctx: sha256_ctx;
var i: int;
- digest = (&_digest):*byte;
- ipad = (&_ipad):*byte;
- opad = (&_opad):*byte;
+ digest = (&_digest) as *byte;
+ ipad = (&_ipad) as *byte;
+ opad = (&_opad) as *byte;
i = 0;
loop {
@@ -395,7 +395,7 @@ sha256_hmac(mac: *byte, key: *byte, klen: int, data: *byte, dlen: int) {
break;
}
- digest[i] = 0: byte;
+ digest[i] = 0 as byte;
i = i + 1;
}
@@ -421,8 +421,8 @@ sha256_hmac(mac: *byte, key: *byte, klen: int, data: *byte, dlen: int) {
break;
}
- ipad[i] = digest[i] ^ (0x36:byte);
- opad[i] = digest[i] ^ (0x5c:byte);
+ ipad[i] = digest[i] ^ (0x36 as byte);
+ opad[i] = digest[i] ^ (0x5c as byte);
i = i + 1;
}
@@ -446,12 +446,12 @@ sha256_update(ctx: *sha256_ctx, msg: *byte, len: int) {
if o != 0 {
r = 64 - o;
if len < r {
- memcpy(&(&ctx.block):*byte[o], msg, len);
+ memcpy(&(&ctx.block) as *byte[o], msg, len);
ctx.len = ctx.len + len;
return;
} else {
- memcpy(&(&ctx.block):*byte[o], msg, r);
- sha256_rounds(ctx, (&ctx.block):*byte);
+ memcpy(&(&ctx.block) as *byte[o], msg, r);
+ sha256_rounds(ctx, (&ctx.block) as *byte);
ctx.len = ctx.len + r;
len = len - r;
msg = &msg[r];
@@ -460,7 +460,7 @@ sha256_update(ctx: *sha256_ctx, msg: *byte, len: int) {
loop {
if len < 64 {
- memcpy((&ctx.block):*byte, msg, len);
+ memcpy((&ctx.block) as *byte, msg, len);
ctx.len = ctx.len + len;
return;
}
@@ -474,6 +474,6 @@ sha256_update(ctx: *sha256_ctx, msg: *byte, len: int) {
}
sha256_final(digest: *byte, ctx: *sha256_ctx) {
- sha256_finish(ctx, ctx.len >> 6, (&ctx.block):*byte, ctx.len & 63);
+ sha256_finish(ctx, ctx.len >> 6, (&ctx.block) as *byte, ctx.len & 63);
sha256_digest(digest, ctx);
}
diff --git a/sha512.om b/sha512.om
@@ -101,7 +101,7 @@ sha512_rounds(ctx: *sha512_ctx, block: *byte) {
var _w: _sha512_block;
var w: *int;
var i: int;
- w = (&_w):*int;
+ w = (&_w) as *int;
r.a = ctx.a;
r.b = ctx.b;
@@ -118,14 +118,14 @@ sha512_rounds(ctx: *sha512_ctx, block: *byte) {
break;
}
- w[i] = (block[0]:int << 56)
- | (block[1]:int << 48)
- | (block[2]:int << 40)
- | (block[3]:int << 32)
- | (block[4]:int << 24)
- | (block[5]:int << 16)
- | (block[6]:int << 8)
- | block[7]:int;
+ w[i] = (block[0] as int << 56)
+ | (block[1] as int << 48)
+ | (block[2] as int << 40)
+ | (block[3] as int << 32)
+ | (block[4] as int << 24)
+ | (block[5] as int << 16)
+ | (block[6] as int << 8)
+ | block[7] as int;
block = &block[8];
i = i + 1;
@@ -226,7 +226,7 @@ sha512_finish(ctx: *sha512_ctx, nblocks: int, data: *byte, len: int) {
var _final: _sha512_block;
var final: *byte;
var pad: int;
- final = (&_final):*byte;
+ final = (&_final) as *byte;
pad = nblocks * 1024;
loop {
@@ -244,21 +244,21 @@ sha512_finish(ctx: *sha512_ctx, nblocks: int, data: *byte, len: int) {
bzero(final, 128);
memcpy(final, data, len);
- final[len] = 0x80:byte;
+ final[len] = 0x80 as byte;
if len + 17 > 128 {
sha512_rounds(ctx, final);
bzero(final, 128);
}
- final[120] = (pad >> 56):byte;
- final[121] = (pad >> 48):byte;
- final[122] = (pad >> 40):byte;
- final[123] = (pad >> 32):byte;
- final[124] = (pad >> 24):byte;
- final[125] = (pad >> 16):byte;
- final[126] = (pad >> 8):byte;
- final[127] = pad:byte;
+ final[120] = (pad >> 56) as byte;
+ final[121] = (pad >> 48) as byte;
+ final[122] = (pad >> 40) as byte;
+ final[123] = (pad >> 32) as byte;
+ final[124] = (pad >> 24) as byte;
+ final[125] = (pad >> 16) as byte;
+ final[126] = (pad >> 8) as byte;
+ final[127] = pad as byte;
sha512_rounds(ctx, final);
}
@@ -272,14 +272,14 @@ sha512_digest(digest: *byte, ctx: *sha512_ctx) {
if i == 8 {
break;
}
- digest[0] = (r[i] >> 56):byte; digest = &digest[1];
- digest[0] = (r[i] >> 48):byte; digest = &digest[1];
- digest[0] = (r[i] >> 40):byte; digest = &digest[1];
- digest[0] = (r[i] >> 32):byte; digest = &digest[1];
- digest[0] = (r[i] >> 24):byte; digest = &digest[1];
- digest[0] = (r[i] >> 16):byte; digest = &digest[1];
- digest[0] = (r[i] >> 8):byte; digest = &digest[1];
- digest[0] = r[i]:byte; digest = &digest[1];
+ digest[0] = (r[i] >> 56) as byte; digest = &digest[1];
+ digest[0] = (r[i] >> 48) as byte; digest = &digest[1];
+ digest[0] = (r[i] >> 40) as byte; digest = &digest[1];
+ digest[0] = (r[i] >> 32) as byte; digest = &digest[1];
+ digest[0] = (r[i] >> 24) as byte; digest = &digest[1];
+ digest[0] = (r[i] >> 16) as byte; digest = &digest[1];
+ digest[0] = (r[i] >> 8) as byte; digest = &digest[1];
+ digest[0] = r[i] as byte; digest = &digest[1];
i = i + 1;
}
}
@@ -301,9 +301,9 @@ sha512_hmac(mac: *byte, key: *byte, klen: int, data: *byte, dlen: int) {
var ctx: sha512_ctx;
var i: int;
- digest = (&_digest):*byte;
- ipad = (&_ipad):*byte;
- opad = (&_opad):*byte;
+ digest = (&_digest) as *byte;
+ ipad = (&_ipad) as *byte;
+ opad = (&_opad) as *byte;
if (klen <= 128) {
bzero(digest, 128);
@@ -318,8 +318,8 @@ sha512_hmac(mac: *byte, key: *byte, klen: int, data: *byte, dlen: int) {
break;
}
- ipad[i] = digest[i] ^ (0x36:byte);
- opad[i] = digest[i] ^ (0x5c:byte);
+ ipad[i] = digest[i] ^ (0x36 as byte);
+ opad[i] = digest[i] ^ (0x5c as byte);
i = i + 1;
}
@@ -343,12 +343,12 @@ sha512_update(ctx: *sha512_ctx, msg: *byte, len: int) {
if o != 0 {
r = 128 - o;
if len < r {
- memcpy(&(&ctx.block):*byte[o], msg, len);
+ memcpy(&(&ctx.block) as *byte[o], msg, len);
ctx.len = ctx.len + len;
return;
} else {
- memcpy(&(&ctx.block):*byte[o], msg, r);
- sha512_rounds(ctx, (&ctx.block):*byte);
+ memcpy(&(&ctx.block) as *byte[o], msg, r);
+ sha512_rounds(ctx, (&ctx.block) as *byte);
ctx.len = ctx.len + r;
len = len - r;
msg = &msg[r];
@@ -357,7 +357,7 @@ sha512_update(ctx: *sha512_ctx, msg: *byte, len: int) {
loop {
if len < 128 {
- memcpy((&ctx.block):*byte, msg, len);
+ memcpy((&ctx.block) as *byte, msg, len);
ctx.len = ctx.len + len;
return;
}
@@ -371,6 +371,6 @@ sha512_update(ctx: *sha512_ctx, msg: *byte, len: int) {
}
sha512_final(digest: *byte, ctx: *sha512_ctx) {
- sha512_finish(ctx, ctx.len >> 7, (&ctx.block):*byte, ctx.len & 127);
+ sha512_finish(ctx, ctx.len >> 7, (&ctx.block) as *byte, ctx.len & 127);
sha512_digest(digest, ctx);
}
diff --git a/sshd.om b/sshd.om
@@ -18,12 +18,12 @@ read_line(fd: int, buf: *byte, max: int): int {
return 0;
}
- if c == '\n':byte {
- buf[len] = 0:byte;
+ if c == '\n' as byte {
+ buf[len] = 0 as byte;
return len;
}
- if c == '\r':byte {
+ if c == '\r' as byte {
continue;
}
@@ -81,7 +81,7 @@ read_rand(buf: *byte, n: int) {
if i == n {
break;
}
- buf[i] = _rdrand():byte;
+ buf[i] = _rdrand() as byte;
i = i + 1;
}
}
@@ -106,39 +106,39 @@ read_frame(ctx: *sshd_ctx) {
var _mac: _sha256_digest;
var mac: *byte;
- nonce = (&_nonce):*byte;
- mackey = (&_mackey):*byte;
- mac = (&_mac):*byte;
+ nonce = (&_nonce) as *byte;
+ mackey = (&_mackey) as *byte;
+ mac = (&_mac) as *byte;
if read_fill(ctx.fd, ctx.buf, 4) != 0 {
die("truncated");
}
if ctx.en_client_to_server {
- nonce[0] = 0:byte;
- nonce[1] = 0:byte;
- nonce[2] = 0:byte;
- nonce[3] = 0:byte;
- nonce[4] = (ctx.seq_client_to_server >> 56):byte;
- nonce[5] = (ctx.seq_client_to_server >> 48):byte;
- nonce[6] = (ctx.seq_client_to_server >> 40):byte;
- nonce[7] = (ctx.seq_client_to_server >> 32):byte;
- nonce[8] = (ctx.seq_client_to_server >> 24):byte;
- nonce[9] = (ctx.seq_client_to_server >> 16):byte;
- nonce[10] = (ctx.seq_client_to_server >> 8):byte;
- nonce[11] = ctx.seq_client_to_server:byte;
+ nonce[0] = 0 as byte;
+ nonce[1] = 0 as byte;
+ nonce[2] = 0 as byte;
+ nonce[3] = 0 as byte;
+ nonce[4] = (ctx.seq_client_to_server >> 56) as byte;
+ nonce[5] = (ctx.seq_client_to_server >> 48) as byte;
+ nonce[6] = (ctx.seq_client_to_server >> 40) as byte;
+ nonce[7] = (ctx.seq_client_to_server >> 32) as byte;
+ nonce[8] = (ctx.seq_client_to_server >> 24) as byte;
+ nonce[9] = (ctx.seq_client_to_server >> 16) as byte;
+ nonce[10] = (ctx.seq_client_to_server >> 8) as byte;
+ nonce[11] = ctx.seq_client_to_server as byte;
seq = 0;
- chacha20_stream((&tmp):*byte, ctx.buf, 4, &seq, &((&ctx.ek_client_to_server):*byte)[32], nonce);
+ chacha20_stream((&tmp) as *byte, ctx.buf, 4, &seq, &((&ctx.ek_client_to_server) as *byte)[32], nonce);
minlen = 16;
align = 8;
maclen = 16;
- len = ((&tmp):*byte)[3]:int
- | (((&tmp):*byte)[2]:int << 8)
- | (((&tmp):*byte)[1]:int << 16)
- | (((&tmp):*byte)[0]:int << 24);
+ len = ((&tmp) as *byte)[3] as int
+ | (((&tmp) as *byte)[2] as int << 8)
+ | (((&tmp) as *byte)[1] as int << 16)
+ | (((&tmp) as *byte)[0] as int << 24);
if len % align != 0 {
die("not aligned");
@@ -148,10 +148,10 @@ read_frame(ctx: *sshd_ctx) {
align = 8;
maclen = 0;
- len = ctx.buf[3]:int
- | (ctx.buf[2]:int << 8)
- | (ctx.buf[1]:int << 16)
- | (ctx.buf[0]:int << 24);
+ len = ctx.buf[3] as int
+ | (ctx.buf[2] as int << 8)
+ | (ctx.buf[1] as int << 16)
+ | (ctx.buf[0] as int << 24);
if (len + 4) % align != 0 {
die("not aligned");
@@ -173,17 +173,17 @@ read_frame(ctx: *sshd_ctx) {
if ctx.en_client_to_server {
bzero(mackey, 64);
seq = 0;
- chacha20_stream(mackey, mackey, 64, &seq, (&ctx.ek_client_to_server):*byte, nonce);
+ chacha20_stream(mackey, mackey, 64, &seq, (&ctx.ek_client_to_server) as *byte, nonce);
poly1305(mac, mackey, ctx.buf, len + 4);
if memcmp(mac, &ctx.buf[len + 4], 16) {
die("mac");
}
- memcpy(ctx.buf, (&tmp):*byte, 4);
+ memcpy(ctx.buf, (&tmp) as *byte, 4);
seq = 64;
- chacha20_stream(&ctx.buf[4], &ctx.buf[4], len, &seq, (&ctx.ek_client_to_server):*byte, nonce);
+ chacha20_stream(&ctx.buf[4], &ctx.buf[4], len, &seq, (&ctx.ek_client_to_server) as *byte, nonce);
}
- padlen = ctx.buf[4]:int;
+ padlen = ctx.buf[4] as int;
if padlen < 4 || padlen > len - 1 {
die("bad padding");
@@ -207,8 +207,8 @@ write_frame(ctx: *sshd_ctx) {
var _mackey: _sha512_digest;
var mackey: *byte;
- nonce = (&_nonce):*byte;
- mackey = (&_mackey):*byte;
+ nonce = (&_nonce) as *byte;
+ mackey = (&_mackey) as *byte;
if ctx.en_server_to_client {
minlen = 16;
@@ -216,18 +216,18 @@ write_frame(ctx: *sshd_ctx) {
maclen = 16;
padlen = align - ((ctx.framelen + 1) % align);
- nonce[0] = 0:byte;
- nonce[1] = 0:byte;
- nonce[2] = 0:byte;
- nonce[3] = 0:byte;
- nonce[4] = (ctx.seq_server_to_client >> 56):byte;
- nonce[5] = (ctx.seq_server_to_client >> 48):byte;
- nonce[6] = (ctx.seq_server_to_client >> 40):byte;
- nonce[7] = (ctx.seq_server_to_client >> 32):byte;
- nonce[8] = (ctx.seq_server_to_client >> 24):byte;
- nonce[9] = (ctx.seq_server_to_client >> 16):byte;
- nonce[10] = (ctx.seq_server_to_client >> 8):byte;
- nonce[11] = ctx.seq_server_to_client:byte;
+ nonce[0] = 0 as byte;
+ nonce[1] = 0 as byte;
+ nonce[2] = 0 as byte;
+ nonce[3] = 0 as byte;
+ nonce[4] = (ctx.seq_server_to_client >> 56) as byte;
+ nonce[5] = (ctx.seq_server_to_client >> 48) as byte;
+ nonce[6] = (ctx.seq_server_to_client >> 40) as byte;
+ nonce[7] = (ctx.seq_server_to_client >> 32) as byte;
+ nonce[8] = (ctx.seq_server_to_client >> 24) as byte;
+ nonce[9] = (ctx.seq_server_to_client >> 16) as byte;
+ nonce[10] = (ctx.seq_server_to_client >> 8) as byte;
+ nonce[11] = ctx.seq_server_to_client as byte;
} else {
minlen = 16;
align = 8;
@@ -254,21 +254,21 @@ write_frame(ctx: *sshd_ctx) {
len = padlen + ctx.framelen + 1;
ctx.frame = &ctx.frame[-5];
- ctx.frame[0] = (len >> 24):byte;
- ctx.frame[1] = (len >> 16):byte;
- ctx.frame[2] = (len >> 8):byte;
- ctx.frame[3] = len:byte;
- ctx.frame[4] = padlen:byte;
+ ctx.frame[0] = (len >> 24) as byte;
+ ctx.frame[1] = (len >> 16) as byte;
+ ctx.frame[2] = (len >> 8) as byte;
+ ctx.frame[3] = len as byte;
+ ctx.frame[4] = padlen as byte;
read_rand(&ctx.frame[ctx.framelen + 5], padlen);
ctx.framelen = ctx.framelen + 5 + padlen;
if ctx.en_server_to_client {
seq = 0;
- chacha20_stream(ctx.buf, ctx.buf, 4, &seq, &((&ctx.ek_server_to_client):*byte)[32], nonce);
+ chacha20_stream(ctx.buf, ctx.buf, 4, &seq, &((&ctx.ek_server_to_client) as *byte)[32], nonce);
seq = 0;
- chacha20_stream(mackey, mackey, 64, &seq, (&ctx.ek_server_to_client):*byte, nonce);
+ chacha20_stream(mackey, mackey, 64, &seq, (&ctx.ek_server_to_client) as *byte, nonce);
seq = 64;
- chacha20_stream(&ctx.buf[4], &ctx.buf[4], len, &seq, (&ctx.ek_server_to_client):*byte, nonce);
+ chacha20_stream(&ctx.buf[4], &ctx.buf[4], len, &seq, (&ctx.ek_server_to_client) as *byte, nonce);
poly1305(&ctx.buf[len + 4], mackey, ctx.buf, len + 4);
}
@@ -365,7 +365,7 @@ doversion(ctx: *sshd_ctx) {
ctx.cver = alloc(ctx.a, n + 1);
memcpy(ctx.cver, ctx.buf, n);
- ctx.cver[n] = 0:byte;
+ ctx.cver[n] = 0 as byte;
if writeall(ctx.fd, ctx.sver, strlen(ctx.sver)) != 0 {
die("write truncated");
@@ -431,7 +431,7 @@ decode_u8(s: *int, ctx: *sshd_ctx) {
if ctx.framelen < 1 || ctx.index > ctx.framelen - 1 {
die("u8 truncated");
}
- *s = ctx.frame[ctx.index]:int;
+ *s = ctx.frame[ctx.index] as int;
ctx.index = ctx.index + 1;
}
@@ -439,10 +439,10 @@ decode_u32(s: *int, ctx: *sshd_ctx) {
if ctx.framelen < 4 || ctx.index > ctx.framelen - 4 {
die("u32 truncated");
}
- *s = (ctx.frame[ctx.index]:int << 24)
- | (ctx.frame[ctx.index + 1]: int << 16)
- | (ctx.frame[ctx.index + 2]: int << 8)
- | ctx.frame[ctx.index + 3]: int;
+ *s = (ctx.frame[ctx.index] as int << 24)
+ | (ctx.frame[ctx.index + 1] as int << 16)
+ | (ctx.frame[ctx.index + 2] as int << 8)
+ | ctx.frame[ctx.index + 3] as int;
ctx.index = ctx.index + 4;
}
@@ -604,7 +604,7 @@ encode_u8(x: *int, ctx: *sshd_ctx) {
if ctx.framelen < 1 || ctx.index > ctx.framelen - 1 {
die("u8 truncated");
}
- ctx.frame[ctx.index] = (*x):byte;
+ ctx.frame[ctx.index] = (*x) as byte;
ctx.index = ctx.index + 1;
}
@@ -626,10 +626,10 @@ encode_u32(x: *int, ctx: *sshd_ctx) {
if ctx.framelen < 4 || ctx.index > ctx.framelen - 4 {
die("u32 truncated");
}
- ctx.frame[ctx.index] = (*x >> 24): byte;
- ctx.frame[ctx.index + 1] = (*x >> 16): byte;
- ctx.frame[ctx.index + 2] = (*x >> 8): byte;
- ctx.frame[ctx.index + 3] = (*x): byte;
+ ctx.frame[ctx.index] = (*x >> 24) as byte;
+ ctx.frame[ctx.index + 1] = (*x >> 16) as byte;
+ ctx.frame[ctx.index + 2] = (*x >> 8) as byte;
+ ctx.frame[ctx.index + 3] = (*x) as byte;
ctx.index = ctx.index + 4;
}
@@ -766,13 +766,13 @@ encode_ecdh_reply(dh: *ssh_ecdh_reply, ctx: *sshd_ctx) {
ssh_u32_sha256_update(ctx: *sha256_ctx, n: int) {
var a: byte;
- a = (n >> 24):byte;
+ a = (n >> 24) as byte;
sha256_update(ctx, &a, 1);
- a = (n >> 16):byte;
+ a = (n >> 16) as byte;
sha256_update(ctx, &a, 1);
- a = (n >> 8):byte;
+ a = (n >> 8) as byte;
sha256_update(ctx, &a, 1);
- a = n:byte;
+ a = n as byte;
sha256_update(ctx, &a, 1);
}
@@ -795,7 +795,7 @@ ssh_mpint_sha256_update(ctx: *sha256_ctx, b: *byte, n: int) {
break;
}
- if b[0]:int != 0 {
+ if b[0] as int != 0 {
break;
}
@@ -803,9 +803,9 @@ ssh_mpint_sha256_update(ctx: *sha256_ctx, b: *byte, n: int) {
n = n - 1;
}
- if b[0]:int & 128 {
+ if b[0] as int & 128 {
ssh_u32_sha256_update(ctx, n + 1);
- a = 0:byte;
+ a = 0 as byte;
sha256_update(ctx, &a, 1);
sha256_update(ctx, b, n);
} else {
@@ -1019,7 +1019,7 @@ struct ssh_channel_request {
decode_channel_request(p: *ssh_channel_request, ctx: *sshd_ctx) {
var tag: int;
- bzero(p:*byte, sizeof(*p));
+ bzero(p as *byte, sizeof(*p));
decode_u8(&tag, ctx);
if tag != SSH_MSG_CHANNEL_REQUEST {
die("not a channel_request");
@@ -1138,9 +1138,9 @@ dokex(ctx: *sshd_ctx) {
}
// -> SSH_MSG_KEXINIT
- read_rand((&cookie): *byte, 16);
+ read_rand((&cookie) as *byte, 16);
skex.cookie.len = 16;
- skex.cookie.s = (&cookie): *byte;
+ skex.cookie.s = (&cookie) as *byte;
set_str(&skex.kex_algorithms, "curve25519-sha256");
set_str(&skex.server_host_key_algorithms, "ssh-ed25519");
set_str(&skex.encryption_algorithms_client_to_server, "chacha20-poly1305@openssh.com");
@@ -1168,22 +1168,22 @@ dokex(ctx: *sshd_ctx) {
die("bad ecdh_init");
}
- read_rand((&rs):*byte, 32);
+ read_rand((&rs) as *byte, 32);
- x25519_base((&qs):*byte);
+ x25519_base((&qs) as *byte);
- if !x25519((&qs):*byte, (&qs):*byte, (&rs):*byte) {
+ if !x25519((&qs) as *byte, (&qs) as *byte, (&rs) as *byte) {
die("bad x25519 server");
}
- if !x25519((&k):*byte, cdh.qc.s, (&rs):*byte) {
+ if !x25519((&k) as *byte, cdh.qc.s, (&rs) as *byte) {
die("bad x25519 client");
}
- set_blob(&sdh.ks, "ssh-ed25519", (&ctx.pub):*byte, 32);
- sdh.qs.s = (&qs):*byte;
+ set_blob(&sdh.ks, "ssh-ed25519", (&ctx.pub) as *byte, 32);
+ sdh.qs.s = (&qs) as *byte;
sdh.qs.len = 32;
- set_blob(&sdh.sig, "ssh-ed25519", (&sig):*byte, 64);
+ set_blob(&sdh.sig, "ssh-ed25519", (&sig) as *byte, 64);
sha256_init(&ehctx);
ssh_str_sha256_update(&ehctx, ctx.cver, strlen(ctx.cver));
@@ -1192,30 +1192,30 @@ dokex(ctx: *sshd_ctx) {
ssh_str_sha256_update(&ehctx, ctx.skex, ctx.skexlen);
ssh_blob_sha256_update(&ehctx, &sdh.ks);
ssh_str_sha256_update(&ehctx, cdh.qc.s, 32);
- ssh_str_sha256_update(&ehctx, (&qs):*byte, 32);
- ssh_mpint_sha256_update(&ehctx, (&k):*byte, 32);
- sha256_final((&eh):*byte, &ehctx);
+ ssh_str_sha256_update(&ehctx, (&qs) as *byte, 32);
+ ssh_mpint_sha256_update(&ehctx, (&k) as *byte, 32);
+ sha256_final((&eh) as *byte, &ehctx);
- ed25519_sign((&sig):*byte, (&ctx.priv):*byte, (&eh):*byte, 32);
+ ed25519_sign((&sig) as *byte, (&ctx.priv) as *byte, (&eh) as *byte, 32);
// -> SSH_MSG_ECDH_REPLY
encode_ecdh_reply(&sdh, ctx);
write_frame(ctx);
if !ctx.has_session_id {
- memcpy((&ctx.session_id):*byte, (&eh):*byte, 32);
+ memcpy((&ctx.session_id) as *byte, (&eh) as *byte, 32);
ctx.has_session_id = 1;
}
- memcpy((&ctx.eh):*byte, (&eh):*byte, 32);
- memcpy((&ctx.k):*byte, (&k):*byte, 32);
+ memcpy((&ctx.eh) as *byte, (&eh) as *byte, 32);
+ memcpy((&ctx.k) as *byte, (&k) as *byte, 32);
- kex_key((&ctx.iv_client_to_server):*byte, "A", ctx);
- kex_key((&ctx.iv_server_to_client):*byte, "B", ctx);
- kex_key((&ctx.ek_client_to_server):*byte, "C", ctx);
- kex_key((&ctx.ek_server_to_client):*byte, "D", ctx);
- kex_key((&ctx.ik_client_to_server):*byte, "E", ctx);
- kex_key((&ctx.ik_server_to_client):*byte, "F", ctx);
+ kex_key((&ctx.iv_client_to_server) as *byte, "A", ctx);
+ kex_key((&ctx.iv_server_to_client) as *byte, "B", ctx);
+ kex_key((&ctx.ek_client_to_server) as *byte, "C", ctx);
+ kex_key((&ctx.ek_server_to_client) as *byte, "D", ctx);
+ kex_key((&ctx.ik_client_to_server) as *byte, "E", ctx);
+ kex_key((&ctx.ik_server_to_client) as *byte, "F", ctx);
// -> SSH_MSG_NEWKEYS
encode_newkeys(&newkeys, ctx);
@@ -1232,15 +1232,15 @@ kex_key(key: *byte, a: *byte, ctx: *sshd_ctx) {
var h: sha256_ctx;
sha256_init(&h);
- ssh_mpint_sha256_update(&h, (&ctx.k):*byte, 32);
- sha256_update(&h, (&ctx.eh):*byte, 32);
+ ssh_mpint_sha256_update(&h, (&ctx.k) as *byte, 32);
+ sha256_update(&h, (&ctx.eh) as *byte, 32);
sha256_update(&h, a, 1);
- sha256_update(&h, (&ctx.session_id):*byte, 32);
+ sha256_update(&h, (&ctx.session_id) as *byte, 32);
sha256_final(key, &h);
sha256_init(&h);
- ssh_mpint_sha256_update(&h, (&ctx.k):*byte, 32);
- sha256_update(&h, (&ctx.eh):*byte, 32);
+ ssh_mpint_sha256_update(&h, (&ctx.k) as *byte, 32);
+ sha256_update(&h, (&ctx.eh) as *byte, 32);
sha256_update(&h, key, 32);
sha256_final(&key[32], &h);
}
@@ -1317,10 +1317,10 @@ doauth(ctx: *sshd_ctx) {
die("sig wrong length");
}
- memcpy((&sig):*byte, &cua.sig.s[19], 64);
+ memcpy((&sig) as *byte, &cua.sig.s[19], 64);
clear_frame(ctx);
- s.s = (&ctx.session_id):*byte;
+ s.s = (&ctx.session_id) as *byte;
s.len = 32;
encode_str(&s, ctx);
b = SSH_MSG_USERAUTH_REQUEST;
@@ -1340,7 +1340,7 @@ doauth(ctx: *sshd_ctx) {
encode_str(&s, ctx);
finish_frame(ctx);
- if !ed25519_verify((&sig):*byte, (&ctx.userpub):*byte, ctx.frame, ctx.framelen) {
+ if !ed25519_verify((&sig) as *byte, (&ctx.userpub) as *byte, ctx.frame, ctx.framelen) {
die("bad signature");
}
@@ -1463,7 +1463,7 @@ ssh_spawn(ctx: *sshd_ctx, argv: **byte) {
close(stdout_write);
close(stderr_write);
- exec(argv[0], argv, 0:**byte);
+ exec(argv[0], argv, 0 as **byte);
exit(255);
}
@@ -1487,7 +1487,7 @@ dopty(cr: *ssh_cr_pty, ctx: *sshd_ctx): int {
doshell(cr: *ssh_cr_shell, ctx: *sshd_ctx): int {
var argv: _argv4;
argv.arg0 = "/bin/sh";
- argv.arg1 = 0:*byte;
+ argv.arg1 = 0 as *byte;
ssh_spawn(ctx, &argv.arg0);
return 1;
}
@@ -1497,11 +1497,11 @@ doexec(cr: *ssh_cr_exec, ctx: *sshd_ctx): int {
var cmd: *byte;
cmd = alloc(ctx.a, cr.command.len + 1);
memcpy(cmd, cr.command.s, cr.command.len);
- cmd[cr.command.len] = 0:byte;
+ cmd[cr.command.len] = 0 as byte;
argv.arg0 = "/bin/sh";
argv.arg1 = "-c";
argv.arg2 = cmd;
- argv.arg3 = 0:*byte;
+ argv.arg3 = 0 as *byte;
ssh_spawn(ctx, &argv.arg0);
free(ctx.a, cmd);
return 1;
@@ -1688,7 +1688,7 @@ poll_client(revents: int, ctx: *sshd_ctx) {
loop {
read_frame(ctx);
- if ctx.frame[0]:int == SSH_MSG_DISCONNECT {
+ if ctx.frame[0] as int == SSH_MSG_DISCONNECT {
break;
}
}
@@ -1698,7 +1698,7 @@ poll_client(revents: int, ctx: *sshd_ctx) {
} else {
read_frame(ctx);
- tag = ctx.frame[0]:int;
+ tag = ctx.frame[0] as int;
if tag == SSH_MSG_DISCONNECT {
dodisconnect(ctx);
} else if tag == SSH_MSG_KEXINIT {
@@ -1933,11 +1933,11 @@ _restorer();
signal(sig: int, handler: func()) {
var act: sigaction;
- act.handler = (&dosigchld):int;
+ act.handler = (&dosigchld) as int;
act.flags = 1 << 26;
- act.restorer = _restorer:int;
+ act.restorer = _restorer as int;
act.mask = 0;
- sigaction(sig, &act, 0:*sigaction);
+ sigaction(sig, &act, 0 as *sigaction);
}
main(argc: int, argv: **byte, envp: **byte) {
@@ -1950,15 +1950,15 @@ main(argc: int, argv: **byte, envp: **byte) {
setup_alloc(&a);
signal(SIGCHLD, dosigchld);
- signal(SIGPIPE, SIG_IGN:func());
+ signal(SIGPIPE, SIG_IGN as func());
- bzero((&ctx):*byte, sizeof(ctx));
+ bzero((&ctx) as *byte, sizeof(ctx));
- if unhex((&ctx.userpub):*byte, "5afb3032d86d60d700e1782bfe8083ff95504cecbda531bef5ba8cdd20f34c82") != 32 {
+ if unhex((&ctx.userpub) as *byte, "5afb3032d86d60d700e1782bfe8083ff95504cecbda531bef5ba8cdd20f34c82") != 32 {
die("invalid userpub");
}
- ed25519_pub((&ctx.pub):*byte, (&ctx.priv):*byte);
+ ed25519_pub((&ctx.pub) as *byte, (&ctx.priv) as *byte);
ctx.child_pid = -1;
ctx.child_stdin = -1;
@@ -1980,8 +1980,8 @@ main(argc: int, argv: **byte, envp: **byte) {
ctx.stderr_buf = alloc(ctx.a, ctx.stderr_size);
ctx.username = "erai";
- format_key(&ctx.hostkey, &ctx.hostkeylen, (&ctx.pub):*byte, &ctx);
- format_key(&ctx.userkey, &ctx.userkeylen, (&ctx.userpub):*byte, &ctx);
+ format_key(&ctx.hostkey, &ctx.hostkeylen, (&ctx.pub) as *byte, &ctx);
+ format_key(&ctx.userkey, &ctx.userkeylen, (&ctx.userpub) as *byte, &ctx);
fd = socket(AF_INET, SOCK_STREAM, 0);
if fd < 0 {
@@ -1991,7 +1991,7 @@ main(argc: int, argv: **byte, envp: **byte) {
port = 22;
sa.fpa = AF_INET | ((port & 0xff) << 24) | (((port >> 8) & 0xff) << 16);
sa.pad = 0;
- if bind(fd, (&sa):*byte, sizeof(sa)) != 0 {
+ if bind(fd, (&sa) as *byte, sizeof(sa)) != 0 {
die("failed to bind");
}
@@ -2001,12 +2001,12 @@ main(argc: int, argv: **byte, envp: **byte) {
loop {
loop {
- if wait(-1, 0:*int, WNOHANG) <= 0 {
+ if wait(-1, 0 as *int, WNOHANG) <= 0 {
break;
}
}
- ctx.fd = accept(fd, 0:*byte, 0:*int);
+ ctx.fd = accept(fd, 0 as *byte, 0 as *int);
if ctx.fd == -EINTR {
continue;
}
diff --git a/syscall.om b/syscall.om
@@ -38,15 +38,15 @@ _start(argc: int, argv: **byte, envp: **byte) {
}
read(fd: int, buf: *byte, n: int): int {
- return syscall(0, fd, buf: int, n, 0, 0, 0);
+ return syscall(0, fd, buf as int, n, 0, 0, 0);
}
write(fd: int, buf: *byte, n: int): int {
- return syscall(1, fd, buf: int, n, 0, 0, 0);
+ return syscall(1, fd, buf as int, n, 0, 0, 0);
}
open(name: *byte, flags: int, mode: int): int {
- return syscall(2, name: int, flags, mode, 0, 0, 0);
+ return syscall(2, name as int, flags, mode, 0, 0, 0);
}
close(fd: int): int {
@@ -54,11 +54,11 @@ close(fd: int): int {
}
fstat(fd: int, buf: *byte): int {
- return syscall(5, fd, buf:int, 0, 0, 0, 0);
+ return syscall(5, fd, buf as int, 0, 0, 0, 0);
}
poll(pfd: *int, nfd: int, timeout: int): int {
- return syscall(7, pfd:int, nfd, timeout, 0, 0, 0);
+ return syscall(7, pfd as int, nfd, timeout, 0, 0, 0);
}
lseek(fd: int, off: int, whence: int): int {
@@ -81,13 +81,13 @@ struct sigaction {
}
sigaction(sig: int, act: *sigaction, oact: *sigaction): int {
- return syscall(13, sig, act:int, oact:int, 8, 0, 0);
+ return syscall(13, sig, act as int, oact as int, 8, 0, 0);
}
pipe(rfd: *int, wfd: *int): int {
var buf: int;
var ret: int;
- ret = syscall(22, (&buf):int, 0, 0, 0, 0, 0);
+ ret = syscall(22, (&buf) as int, 0, 0, 0, 0, 0);
if ret == 0 {
*rfd = buf & (-1 >> 32);
*wfd = buf >> 32;
@@ -104,11 +104,11 @@ socket(pf: int, ty: int, pc: int): int {
}
accept(fd: int, addr: *byte, len: *int): int {
- return syscall(43, fd, addr:int, len:int, 0, 0, 0);
+ return syscall(43, fd, addr as int, len as int, 0, 0, 0);
}
bind(fd: int, addr: *byte, len: int): int {
- return syscall(49, fd, addr:int, len:int, 0, 0, 0);
+ return syscall(49, fd, addr as int, len as int, 0, 0, 0);
}
listen(fd: int, backlog: int): int {
@@ -120,7 +120,7 @@ fork(): int {
}
exec(cmd: *byte, argv: **byte, envp: **byte): int {
- return syscall(59, cmd:int, argv:int, envp:int, 0, 0, 0);
+ return syscall(59, cmd as int, argv as int, envp as int, 0, 0, 0);
}
exit(n: int) {
@@ -131,7 +131,7 @@ wait(pid: int, status: *int, flags: int): int {
var s: int;
var ret: int;
s = 0;
- ret = syscall(61, pid, s:int, flags, 0, 0, 0);
+ ret = syscall(61, pid, s as int, flags, 0, 0, 0);
if status {
*status = s & (-1 >> 32);
}
@@ -139,17 +139,17 @@ wait(pid: int, status: *int, flags: int): int {
}
rename(oldname: *byte, newname: *byte): int {
- return syscall(82, oldname: int, newname: int, 0, 0, 0, 0);
+ return syscall(82, oldname as int, newname as int, 0, 0, 0, 0);
}
mkdir(name: *byte): int {
- return syscall(83, name: int, 0, 0, 0, 0, 0);
+ return syscall(83, name as int, 0, 0, 0, 0, 0);
}
unlink(name: *byte): int {
- return syscall(87, name: int, 0, 0, 0, 0, 0);
+ return syscall(87, name as int, 0, 0, 0, 0, 0);
}
getdirents(fd: int, buf: *byte, len: int): int {
- return syscall(217, fd, buf:int, len, 0, 0, 0);
+ return syscall(217, fd, buf as int, len, 0, 0, 0);
}
diff --git a/type.om b/type.om
@@ -92,7 +92,7 @@ count_args(c: *compiler, t: *type): int {
mktype(c: *compiler, kind: int, a: *type, b: *type, st: *decl): *type {
var t: *type;
- t = alloc(c.a, sizeof(*t)):*type;
+ t = alloc(c.a, sizeof(*t)) as *type;
t.kind = kind;
t.st = st;
@@ -103,23 +103,23 @@ mktype(c: *compiler, kind: int, a: *type, b: *type, st: *decl): *type {
}
mktype_struct(c: *compiler, st: *decl): *type {
- return mktype(c, TY_STRUCT, 0:*type, 0:*type, st);
+ return mktype(c, TY_STRUCT, 0 as *type, 0 as *type, st);
}
mktype_union(c: *compiler, st: *decl): *type {
- return mktype(c, TY_UNION, 0:*type, 0:*type, st);
+ return mktype(c, TY_UNION, 0 as *type, 0 as *type, st);
}
mktype0(c: *compiler, kind: int): *type {
- return mktype(c, kind, 0:*type, 0:*type, 0:*decl);
+ return mktype(c, kind, 0 as *type, 0 as *type, 0 as *decl);
}
mktype1(c: *compiler, kind: int, a: *type): *type {
- return mktype(c, kind, a, 0:*type, 0:*decl);
+ return mktype(c, kind, a, 0 as *type, 0 as *decl);
}
mktype2(c: *compiler, kind: int, a: *type, b: *type): *type {
- return mktype(c, kind, a, b, 0:*decl);
+ return mktype(c, kind, a, b, 0 as *decl);
}
type_isint(t: *type): int {
@@ -137,7 +137,7 @@ prototype(c: *compiler, n: *node): *type {
var kind: int;
if (!n) {
- return 0:*type;
+ return 0 as *type;
}
c.lineno = n.lineno;
@@ -157,7 +157,7 @@ prototype(c: *compiler, n: *node): *type {
return mktype0(c, TY_BYTE);
}
- st = find(c, n.s, 0:*byte, 0);
+ st = find(c, n.s, 0 as *byte, 0);
if (!st || !st.struct_defined) {
cdie(c, "unknown struct");
}