ref: 3608567e7519780572651f0fee607b0c1746925b
parent: 9f9ce59cef3042e64a0a90ac370dbdaf1c7be7b1
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Apr 23 17:13:53 EDT 2025
fn: add "raw" argument To avoid mixing shifted and unshifted bytecode, add an extra parameter. This removes the need for "special" handling during boot image load and allows correct processing of #fn(...) forms in REPL.
--- a/boot/sl.boot
+++ b/boot/sl.boot
@@ -199,7 +199,7 @@
n bcode:stack compile-arglist emit tcall.l call.l
builtin->instruction cadr length= λ inlineable? compile-let compile-builtin-call tcall call) compile-app 16)
compile-arglist #fn("n3202101>282524228261:" #(#fn(for-each)
- #fn("n170AFq054471AK62:" #(compile-in
+ #fn("n170AFq054471AK62:" #(compile-in
egin #fn("n483H3?0700182715064:83=H3>070018283<64:7001q83<5447202352474018283=64:" #(compile-in
void emit pop compile-begin) compile-begin 9)
compile-builtin-call #fn("n7I202186850>3?;514227385q538<3I07483=8<52J=075858<52@30q4858=26CL086El23:07702862:770858663:8=29C708;60:8=2:C708;60:8=2;C]086El23:07702<62:86r2l23:07702=62:770858663:8=2>Cm086El23:07585K62:86Kl23:07702?62:86r2l23:07702@62:770858663:8=2ACL086El23:07702B62:770858663:8=2CCL086El23:07585K62:770858663:8=2DCN086El23<07702E2F63:770858663:8=2GCX086r2L23;07585r262:770823702H@402G8663:8=2ICb086r2l23:07702J62:r286L23?07708586r3~63:7585r262:7708562:" #(#0#
--- a/src/compiler.sl
+++ b/src/compiler.sl
@@ -765,7 +765,8 @@
(values (fn (encode-byte-code (bcode:code g))
(const-to-idx-vec g)
name
- (- (bcode:spmax g) (length args)))
+ (- (bcode:spmax g) (length args))
+ T)
(bcode:cenv g)))))
;; disassembler
--- a/src/sl.c
+++ b/src/sl.c
@@ -954,7 +954,7 @@
{
if(nargs == 1 && issym(args[0]))
return fn_builtin_builtin(args, nargs);
- if(nargs < 1 || nargs > 5)
+ if(nargs < 1 || nargs > 6)
argcount(nargs, 1);
sl_fn *fn = alloc_words(sizeof(sl_fn)/sizeof(sl_v));
sl_v fv = tagptr(fn, TAG_FN);
@@ -964,7 +964,9 @@
fn->name = sl_lambda;
u8int *data = nil;
usize sz = 0;
- bool envset = false, valsset = false, nameset = false, maxstackset = false, bcodeset = false;
+ bool envset = false, valsset = false;
+ bool nameset = false, maxstackset = false;
+ bool bcodeset = false, raw = false;
for(int i = 0; nargs > i; i++){
sl_v v = args[i];
if(!envset && (v == sl_nil || (valsset && isvec(v)))){
@@ -973,6 +975,8 @@
}else if(!valsset && isvec(v)){
valsset = true;
fn->vals = v;
+ }else if(v == sl_t){
+ raw = true;
}else if(!nameset && issym(v)){
if(sl_unlikely(isgensym(v)))
bthrow(lerrorf(sl_errarg, "name cannot be a gensym"));
@@ -989,11 +993,6 @@
cv_pin(arr);
data = cv_data(arr);
sz = cv_len(arr);
- if(slg.loading){
- // read syntax, shifted 48 for compact text representation
- for(usize j = 0; j < sz; j++)
- data[j] -= 48;
- }
fn->bcode = v;
}else{
bthrow(lerrorf(sl_errarg, "unexpected argument type"));
@@ -1003,6 +1002,11 @@
bthrow(lerrorf(sl_errarg, "no code"));
if(!maxstackset)
bthrow(lerrorf(sl_errarg, "no max stack"));
+ if(!raw){
+ // read syntax, shifted 48 for compact text representation
+ for(usize j = 0; j < sz; j++)
+ data[j] -= 48;
+ }
return fv;
}
@@ -1472,7 +1476,6 @@
int
sl_load_system_image(sl_v sys_image_io)
{
- slg.loading = true;
PUSH(sys_image_io);
usize osp = sl.sp - sl.stack;
SL_TRY{
@@ -1506,6 +1509,5 @@
return -1;
}
sl.sp = sl.stack + osp - 1;
- slg.loading = false;
return 0;
}
--- a/src/sl.h
+++ b/src/sl.h
@@ -434,7 +434,6 @@
// gensym names available at a time, mostly for compare()
char gsname[2][16];
int gsnameno;
- bool loading;
bool exiting;
bool grew;
int ngchandles;