ww+wcc: emit and lex // MODULE: <name> directive in combined.ww
This commit is contained in:
@@ -25,6 +25,7 @@ type lex = struct {
|
||||
col: i32,
|
||||
a: *arena,
|
||||
errs: i32,
|
||||
module: str, // current module from `// MODULE: foo` directive; "" if none
|
||||
};
|
||||
|
||||
export fn lexinit(l: *lex, a: *arena, file: str, src: *u8, len: u64) void = {
|
||||
@@ -36,6 +37,10 @@ export fn lexinit(l: *lex, a: *arena, file: str, src: *u8, len: u64) void = {
|
||||
l.col = 1;
|
||||
l.a = a;
|
||||
l.errs = 0;
|
||||
let empty: str;
|
||||
empty.ptr = nil;
|
||||
empty.len = 0;
|
||||
l.module = empty;
|
||||
};
|
||||
|
||||
// srcb — byte at offset; helper that lifts the cast out of indexing.
|
||||
@@ -113,6 +118,32 @@ fn skipws(l: *lex) bool = {
|
||||
if (c == 47) { // '/'
|
||||
let c2: i32 = lpeek(l, 1u64);
|
||||
if (c2 == 47) {
|
||||
lget(l); lget(l); // consume '//'
|
||||
// Driver injects `// MODULE: foo` before each
|
||||
// source file's contents; capture so cgen can
|
||||
// mangle private symbols by module.
|
||||
if (lpeek(l, 0u64) == 32) { // ' '
|
||||
if (lpeek(l, 1u64) == 77) { // 'M'
|
||||
if (lpeek(l, 2u64) == 79) { // 'O'
|
||||
if (lpeek(l, 3u64) == 68) { // 'D'
|
||||
if (lpeek(l, 4u64) == 85) { // 'U'
|
||||
if (lpeek(l, 5u64) == 76) { // 'L'
|
||||
if (lpeek(l, 6u64) == 69) { // 'E'
|
||||
if (lpeek(l, 7u64) == 58) { // ':'
|
||||
if (lpeek(l, 8u64) == 32) { // ' '
|
||||
let i: i32 = 0;
|
||||
for (i < 9) { lget(l); i += 1; };
|
||||
let start: u64 = l.lpos;
|
||||
for (true) {
|
||||
let cx: i32 = lpeek(l, 0u64);
|
||||
if (cx < 0) { break; };
|
||||
if (cx == 10) { break; };
|
||||
if (cx == 13) { break; };
|
||||
lget(l);
|
||||
};
|
||||
let n: u64 = l.lpos - start;
|
||||
l.module = astrndup(l.a, l.src + start, n);
|
||||
};};};};};};};};};
|
||||
for (true) {
|
||||
let cx: i32 = lpeek(l, 0u64);
|
||||
if (cx < 0) { return false; };
|
||||
|
||||
Reference in New Issue
Block a user