w6a,w6l: char-literals for ELF/archive magic bytes (Wave-1)

byte-id-neutral: every magic-decimal sub is value-equivalent to its
ASCII char-literal. 0x7F (ELF byte-0), ELFCLASS64=2, NUL sentinels,
and hex/itoa radix arithmetic kept decimal (no char identity).
Regenerated w6a/w6l main.combined.ww (the only two embedders).
This commit is contained in:
2026-06-02 20:41:51 +09:00
parent 5987e389b9
commit 2131ae0dee
6 changed files with 152 additions and 152 deletions

View File

@@ -3328,7 +3328,7 @@ fn nextline(a: *asm_) (*u8, u64) = {
if (a.pos >= a.srclen) { return nil, 0u64; };
let start: u64 = a.pos;
for (a.pos < a.srclen) {
if (a.src[a.pos] == 10u8) { a.pos = a.pos; a.pos += 0u64; } // no-op; explicit break via condition
if (a.src[a.pos] == '\n') { a.pos = a.pos; a.pos += 0u64; } // no-op; explicit break via condition
else { a.pos += 1u64; continue; };
// hit newline
let n: u64 = a.pos - start;
@@ -3352,7 +3352,7 @@ fn nextline(a: *asm_) (*u8, u64) = {
fn skipws(p: *u8, off: u64, n: u64) u64 = {
let i: u64 = off;
for (i < n) {
if (p[i] != 32u8) { if (p[i] != 9u8) { return i; }; };
if (p[i] != ' ') { if (p[i] != '\t') { return i; }; };
i += 1u64;
};
return i;
@@ -3372,7 +3372,7 @@ fn parseoperand(a: *asm_, p: *u8, offin: u64, n: u64, out: *aoperand) u64 = {
let c0: u8 = p[off];
// $NUM
if (c0 == 36u8) { // '$'
if (c0 == '$') {
off += 1u64;
let v: i64;
let used: u64;
@@ -3383,11 +3383,11 @@ fn parseoperand(a: *asm_, p: *u8, offin: u64, n: u64, out: *aoperand) u64 = {
};
// (REG)
if (c0 == 40u8) { // '('
if (c0 == '(') {
off += 1u64;
let rstart: u64 = off;
for (off < n) {
if (p[off] == 41u8) { off = off; off += 0u64; } // no-op marker
if (p[off] == ')') { off = off; off += 0u64; } // no-op marker
else { off += 1u64; continue; };
let rn: u64 = off - rstart;
let r: i32 = reglookup(p + rstart, rn);
@@ -3405,19 +3405,19 @@ fn parseoperand(a: *asm_, p: *u8, offin: u64, n: u64, out: *aoperand) u64 = {
let cur: u64 = off;
let isnum: bool = false;
if (cur < n) {
if (p[cur] == 45u8) { isnum = true; }
else { if (p[cur] >= 48u8) { if (p[cur] <= 57u8) { isnum = true; }; }; };
if (p[cur] == '-') { isnum = true; }
else { if (p[cur] >= '0') { if (p[cur] <= '9') { isnum = true; }; }; };
};
if (isnum) {
let v: i64;
let used: u64;
v, used = parsenum(p + off, n - off);
let after: u64 = off + used;
if (after < n) { if (p[after] == 40u8) { // '('
if (after < n) { if (p[after] == '(') {
let rstart: u64 = after + 1u64;
let cur2: u64 = rstart;
for (cur2 < n) {
if (p[cur2] == 41u8) { cur2 = cur2; cur2 += 0u64; }
if (p[cur2] == ')') { cur2 = cur2; cur2 += 0u64; }
else { cur2 += 1u64; continue; };
let rn: u64 = cur2 - rstart;
let r: i32 = reglookup(p + rstart, rn);
@@ -3446,7 +3446,7 @@ fn parseoperand(a: *asm_, p: *u8, offin: u64, n: u64, out: *aoperand) u64 = {
// by DATAR to address bytes within a previously-defined
// .data slot (e.g. `DATAR s+8(SB),...`).
let symdisp: i64 = 0i64;
if (off < n) { if (p[off] == 43u8) { // '+'
if (off < n) { if (p[off] == '+') {
off += 1u64;
let v: i64;
let used: u64;
@@ -3455,11 +3455,11 @@ fn parseoperand(a: *asm_, p: *u8, offin: u64, n: u64, out: *aoperand) u64 = {
off += used;
};};
// IDENT(SB) — external
if (off < n) { if (p[off] == 40u8) { // '('
if (off < n) { if (p[off] == '(') {
let rstart: u64 = off + 1u64;
let cur2: u64 = rstart;
for (cur2 < n) {
if (p[cur2] == 41u8) { cur2 = cur2; cur2 += 0u64; }
if (p[cur2] == ')') { cur2 = cur2; cur2 += 0u64; }
else { cur2 += 1u64; continue; };
let rn: u64 = cur2 - rstart;
let r: i32 = reglookup(p + rstart, rn);
@@ -3525,7 +3525,7 @@ export fn parse(a: *asm_) i32 = {
// blank or //-comment
if (i >= n) { a.line += 1; continue; };
if (i + 1u64 < n) {
if (line[i] == 47u8) { if (line[i + 1u64] == 47u8) {
if (line[i] == '/') { if (line[i + 1u64] == '/') {
a.line += 1; continue;
};};
};
@@ -3534,7 +3534,7 @@ export fn parse(a: *asm_) i32 = {
// Only if the identifier is followed by ':'. Otherwise, fall
// through to mnemonic parsing so e.g. `TEXT foo,$0` (which
// also starts with an idchar in column 0) gets parsed.
if (line[0u64] != 9u8) {
if (line[0u64] != '\t') {
if (isidstart(line[i]: i32)) {
let q: u64 = i;
let scanid: bool = true;
@@ -3543,7 +3543,7 @@ export fn parse(a: *asm_) i32 = {
else { if (isidcont(line[q]: i32)) { q += 1u64; }
else { scanid = false; }; };
};
if (q < n) { if (line[q] == 58u8) { // ':'
if (q < n) { if (line[q] == ':') {
let nm: str = dupstr(line + i, q - i);
// Pending label gets a NOP prog so addresses pin.
if (pending.len > 0) {
@@ -3563,8 +3563,8 @@ export fn parse(a: *asm_) i32 = {
let scan: bool = true;
for (scan) {
if (m >= n) { scan = false; }
else { if (line[m] == 32u8) { scan = false; }
else { if (line[m] == 9u8) { scan = false; }
else { if (line[m] == ' ') { scan = false; }
else { if (line[m] == '\t') { scan = false; }
else { m += 1u64; }; }; };
};
let mlen: u64 = m - mstart;
@@ -3590,7 +3590,7 @@ export fn parse(a: *asm_) i32 = {
let scant: bool = true;
for (scant) {
if (q >= n) { scant = false; }
else { if (line[q] == 44u8) { commapos = q; scant = false; }
else { if (line[q] == ',') { commapos = q; scant = false; }
else { q += 1u64; }; };
};
let toop: *aoperand = pr.to;
@@ -3599,7 +3599,7 @@ export fn parse(a: *asm_) i32 = {
if (commapos < n) {
let p2: u64 = commapos + 1u64;
p2 = skipws(line, p2, n);
if (p2 < n) { if (line[p2] == 36u8) { p2 += 1u64; }; };
if (p2 < n) { if (line[p2] == '$') { p2 += 1u64; }; };
let v: i64;
let used: u64;
v, used = parsenum(line + p2, n - p2);
@@ -3618,7 +3618,7 @@ export fn parse(a: *asm_) i32 = {
let scand: bool = true;
for (scand) {
if (q >= n) { scand = false; }
else { if (line[q] == 40u8) { lparen = q; scand = false; }
else { if (line[q] == '(') { lparen = q; scand = false; }
else { q += 1u64; }; };
};
let toop: *aoperand = pr.to;
@@ -3629,41 +3629,41 @@ export fn parse(a: *asm_) i32 = {
let scand2: bool = true;
for (scand2) {
if (p2 >= n) { scand2 = false; }
else { if (line[p2] == 41u8) { p2 += 1u64; scand2 = false; }
else { if (line[p2] == ')') { p2 += 1u64; scand2 = false; }
else { p2 += 1u64; }; };
};
// Skip ws / ',' / tab between `)` and the `"`.
let scand3: bool = true;
for (scand3) {
if (p2 >= n) { scand3 = false; }
else { if (line[p2] == 32u8) { p2 += 1u64; }
else { if (line[p2] == 44u8) { p2 += 1u64; }
else { if (line[p2] == 9u8) { p2 += 1u64; }
else { if (line[p2] == ' ') { p2 += 1u64; }
else { if (line[p2] == ',') { p2 += 1u64; }
else { if (line[p2] == '\t') { p2 += 1u64; }
else { scand3 = false; }; }; }; };
};
if (p2 >= n) { perr(a, "DATA missing payload"); a.line += 1; continue; };
if (line[p2] != 34u8) { perr(a, "DATA expects \"...\""); a.line += 1; continue; };
if (line[p2] != '"') { perr(a, "DATA expects \"...\""); a.line += 1; continue; };
p2 += 1u64; // past opening "
// Parse escape sequence into a fresh growable buffer.
let cap: u64 = 32u64;
let blen: u64 = 0u64;
let dbuf: []u8 = alloc([], cap)!;
for (p2 < n) {
if (line[p2] == 34u8) { p2 = p2; p2 += 0u64; p2 = n + 1u64; }
if (line[p2] == '"') { p2 = p2; p2 += 0u64; p2 = n + 1u64; }
else {
let ch: u8 = line[p2];
p2 += 1u64;
if (ch == 92u8) { // '\'
if (ch == '\\') {
if (p2 < n) {
let e: u8 = line[p2];
p2 += 1u64;
if (e == 110u8) { ch = 10u8; } // 'n'
else { if (e == 116u8) { ch = 9u8; }
else { if (e == 114u8) { ch = 13u8; }
else { if (e == 92u8) { ch = 92u8; }
else { if (e == 34u8) { ch = 34u8; }
else { if (e == 48u8) { ch = 0u8; }
else { if (e == 120u8) { // 'x'
if (e == 'n') { ch = '\n'; }
else { if (e == 't') { ch = '\t'; }
else { if (e == 'r') { ch = '\r'; }
else { if (e == '\\') { ch = '\\'; }
else { if (e == '"') { ch = '"'; }
else { if (e == '0') { ch = '\0'; }
else { if (e == 'x') {
if (p2 + 1u64 < n) {
let hi: u8 = line[p2];
let lo: u8 = line[p2 + 1u64];
@@ -3702,7 +3702,7 @@ export fn parse(a: *asm_) i32 = {
let comma: i64 = -1i64;
let q: u64 = r0;
for (q < n) {
if (line[q] == 44u8) {
if (line[q] == ',') {
if (comma < 0i64) { comma = q: i64; };
};
q += 1u64;