String comparison and emit:
fn streq_mem(a: i64, b: i64) i64 {
if (len(a) != len(b)) { return 0; }
for (0..len(a)) |i| {
if (a[i] != b[i]) { return 0; }
}
return 1;
}
var out_pos: i64 = 0;
fn emit_byte(b: i64) i64 {
store8(100000 + out_pos, b);
out_pos += 1;
return 0;
}
fn emit_s(s: i64) i64 {
for (0..len(s)) |i| {
emit_byte(s[i]);
}
return 0;
}
fn emit_num(n: i64) i64 {
if (n < 0) { emit_byte('-'); emit_num(0 - n); return 0; }
if (n > 9) { emit_num(n / 10); }
emit_byte('0' + n % 10);
return 0;
}
streq_mem uses a[i] slice indexing, len(a) for length, and for loops. No manual address arithmetic. emit_s iterates with for instead of while with a counter. emit_num uses '0' + n % 10 -- character literal and modulo, both earning their keep.
### The expression compiler