diff --git a/src/compiler/boot.dst b/src/compiler/boot.dst index 550a1107..79b1c244 100644 --- a/src/compiler/boot.dst +++ b/src/compiler/boot.dst @@ -246,7 +246,7 @@ value." :let (tuple 'let verb (doone (+ i 2))) :when (tuple 'if verb (doone (+ i 2))) (error ("unexpected loop predicate: " verb))) - (switch + (switch verb :range (do (def [start end _inc] (ast.unwrap1 object)) @@ -293,7 +293,7 @@ value." (def $accum (gensym "accum")) (tuple 'do (tuple 'def $accum @[]) - (tuple 'loop head + (tuple 'loop head (tuple array.push $accum (tuple.prepend body 'do))) $accum)) @@ -734,7 +734,7 @@ in the same manner, and so on. Useful for expressing pipelines of data." "Get the number of occurences of each value in a indexed structure." [ind] (def freqs @{}) - (loop + (loop [x :in ind] (def n (get freqs x)) (put freqs x (if n (+ 1 n) 1))) @@ -1016,8 +1016,9 @@ onvalue." } :in st] (file.write stdout " in") (when c (file.write stdout " cfunction")) - (when name (file.write stdout (string " " name))) - (when func (file.write stdout (string " " func))) + (if name + (file.write stdout (string " " name)) + (when func (file.write stdout (string " " func)))) (when pc (file.write stdout (string " (pc=" pc ")"))) (when tail (file.write stdout " (tailcall)")) (file.write stdout "\n")))) @@ -1060,7 +1061,7 @@ environment is needed, use run-context." (def last (get parts (- (length parts) 1))) (def normname (string.replace-all "." "/" path)) (array.push - (map (fn [x] + (map (fn [x] (def y (string.replace "??" last x)) (string.replace "?" normname y)) paths) @@ -1104,7 +1105,7 @@ returned from compiling and running the file." (put cache path newenv) (put loading path true) (def f (find-mod path)) - (if f + (if f (do # Normal dst module (defn chunks [buf] (file.read f 1024 buf)) @@ -1115,7 +1116,7 @@ returned from compiling and running the file." (file.close f) (put loading path nil) newenv) - (do + (do # Try native module (def n (find-native path)) (if (not n) diff --git a/src/compiler/compile.c b/src/compiler/compile.c index c7f09657..a24c43d9 100644 --- a/src/compiler/compile.c +++ b/src/compiler/compile.c @@ -983,6 +983,7 @@ DstCompileResult dst_compile(Dst source, DstTable *env, int flags) { if (c.result.status == DST_COMPILE_OK) { DstFuncDef *def = dstc_pop_funcdef(&c); + def->name = dst_cstring("[thunk]"); c.result.funcdef = def; } diff --git a/src/compiler/stl.c b/src/compiler/stl.c index 1eecb9f7..22ad97e4 100644 --- a/src/compiler/stl.c +++ b/src/compiler/stl.c @@ -60,6 +60,7 @@ static const DstReg cfuns[] = { /* Utility for inline assembly */ static DstFunction *dst_quick_asm( + const char *name, int32_t arity, int varargs, int32_t slots, @@ -71,6 +72,7 @@ static DstFunction *dst_quick_asm( def->slotcount = slots; def->bytecode = malloc(bytecode_size); def->bytecode_length = bytecode_size / sizeof(uint32_t); + def->name = dst_cstring(name); if (!def->bytecode) { DST_OUT_OF_MEMORY; } @@ -105,11 +107,11 @@ DstTable *dst_stl_env(int flags) { /* Load main functions */ dst_env_cfuns(env, cfuns); - dst_env_def(env, "debug", dst_wrap_function(dst_quick_asm(0, 0, 1, debug_asm, sizeof(debug_asm)))); - dst_env_def(env, "error", dst_wrap_function(dst_quick_asm(1, 0, 1, error_asm, sizeof(error_asm)))); - dst_env_def(env, "apply1", dst_wrap_function(dst_quick_asm(2, 0, 2, apply_asm, sizeof(apply_asm)))); - dst_env_def(env, "yield", dst_wrap_function(dst_quick_asm(1, 0, 2, yield_asm, sizeof(yield_asm)))); - dst_env_def(env, "resume", dst_wrap_function(dst_quick_asm(2, 0, 2, resume_asm, sizeof(resume_asm)))); + dst_env_def(env, "debug", dst_wrap_function(dst_quick_asm("debug", 0, 0, 1, debug_asm, sizeof(debug_asm)))); + dst_env_def(env, "error", dst_wrap_function(dst_quick_asm("error", 1, 0, 1, error_asm, sizeof(error_asm)))); + dst_env_def(env, "apply1", dst_wrap_function(dst_quick_asm("apply1", 2, 0, 2, apply_asm, sizeof(apply_asm)))); + dst_env_def(env, "yield", dst_wrap_function(dst_quick_asm("yield", 1, 0, 2, yield_asm, sizeof(yield_asm)))); + dst_env_def(env, "resume", dst_wrap_function(dst_quick_asm("resume", 2, 0, 2, resume_asm, sizeof(resume_asm)))); dst_env_def(env, "VERSION", dst_cstringv(DST_VERSION));