ww: implement package initialization
This commit is contained in:
@@ -544,6 +544,12 @@ fn cgfn(c: *cgen, fn_: *syntax.node) void = {
|
||||
};
|
||||
|
||||
cgfnparams(c, fn_.list);
|
||||
if (c.initdispatchsymbol.len > 0 && syntax.streq(fn_.str, "main")
|
||||
&& fn_.imported == 0 && c.sepisdep == 0) {
|
||||
emitline("\tCALL\t");
|
||||
emitbytes(c.initdispatchsymbol.ptr, c.initdispatchsymbol.len: u64);
|
||||
emitline("(SB)\n");
|
||||
};
|
||||
c.lastwasreturn = 0;
|
||||
// Iterate the fn body's statements directly rather than dispatching
|
||||
// the outermost N_BLOCK through cgstmt — cgblock now save/restores
|
||||
@@ -594,11 +600,13 @@ fn cgfn(c: *cgen, fn_: *syntax.node) void = {
|
||||
// (path-carrying `//ww:module-reset`, #57); only the root/link-entry
|
||||
// unit (wwiout==nil, #69) keeps the bare label.
|
||||
emitline("TEXT ");
|
||||
if (syntax.streq(fn_.str, "main") && fn_.imported == 0 && c.sepisdep == 0) {
|
||||
if (fn_.linksym.len > 0) {
|
||||
emitbytes(fn_.linksym.ptr, fn_.linksym.len: u64);
|
||||
} else { if (syntax.streq(fn_.str, "main") && fn_.imported == 0 && c.sepisdep == 0) {
|
||||
emitbytes(fn_.str.ptr, fn_.str.len: u64);
|
||||
} else {
|
||||
emitfnname(c, fn_.str, fn_.nmod);
|
||||
};
|
||||
}; };
|
||||
emitline(",$");
|
||||
emitint(frame: i64);
|
||||
emitline("\n");
|
||||
@@ -612,8 +620,9 @@ fn cgfn(c: *cgen, fn_: *syntax.node) void = {
|
||||
cgout_flush();
|
||||
};
|
||||
|
||||
fn cgfile(c: *cgen, file: *syntax.node) void = {
|
||||
if (file == nil) { return; };
|
||||
fn cgfile(c: *cgen, file: *syntax.node) i32 = {
|
||||
cgwritefailed = 0;
|
||||
if (file == nil) { return 0; };
|
||||
c.strlits = nil;
|
||||
c.strlitseq = 0;
|
||||
collectaliases(c, file);
|
||||
@@ -647,5 +656,7 @@ fn cgfile(c: *cgen, file: *syntax.node) void = {
|
||||
letpreintern(c, file);
|
||||
emitdatasection(c);
|
||||
emitdefconstants(c, file);
|
||||
emitinitbackings(file.list);
|
||||
emitletdataw(c, file);
|
||||
return cgwritefailed;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user