diff --git a/src/compiler/compile_specials.c b/src/compiler/compile_specials.c index 14343b7a..d84c64b2 100644 --- a/src/compiler/compile_specials.c +++ b/src/compiler/compile_specials.c @@ -301,34 +301,6 @@ DstSlot dstc_do(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) { return ret; } -DstSlot dstc_transfer(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) { - DstCompiler *c = opts.compiler; - DstFopts subopts = dstc_fopts_default(c);; - DstSlot dest, fib, val; - int32_t destindex, fibindex, valindex; - if (argn > 2) { - dstc_cerror(c, ast, "expected no more than 2 arguments"); - return dstc_cslot(dst_wrap_nil()); - } - dest = dstc_gettarget(opts); - fib = (argn > 0) ? dstc_value(subopts, argv[0]) : dstc_cslot(dst_wrap_nil()); - val = (argn > 1) ? dstc_value(subopts, argv[1]) : dstc_cslot(dst_wrap_nil()); - destindex = dstc_preread(c, ast, 0xFF, 1, dest); - fibindex = dstc_preread(c, ast, 0xFF, 2, fib); - valindex = dstc_preread(c, ast, 0xFF, 3, val); - dstc_emit(c, ast, - (valindex << 24) | - (fibindex << 16) | - (destindex << 8) | - DOP_TRANSFER); - dstc_postread(c, dest, destindex); - dstc_postread(c, fib, fibindex); - dstc_postread(c, val, valindex); - dstc_freeslot(c, fib); - dstc_freeslot(c, val); - return dest; -} - /* * :whiletop * ... @@ -528,7 +500,6 @@ static const DstSpecial dstc_specials[] = { {"fn", dstc_fn}, {"if", dstc_if}, {"quote", dstc_quote}, - {"transfer", dstc_transfer}, {"var", dstc_var}, {"varset!", dstc_varset}, {"while", dstc_while} diff --git a/src/core/bytecode.c b/src/core/bytecode.c index 512a9e2b..d7dc4052 100644 --- a/src/core/bytecode.c +++ b/src/core/bytecode.c @@ -251,6 +251,7 @@ DstFunction *dst_quick_asm(int32_t arity, int varargs, int32_t slots, const uint def->flags = varargs ? DST_FUNCDEF_FLAG_VARARG : 0; def->slotcount = slots; def->bytecode = malloc(bytecode_size); + def->bytecode_length = bytecode_size / sizeof(uint32_t); if (!def->bytecode) { DST_OUT_OF_MEMORY; } diff --git a/src/core/stl.c b/src/core/stl.c index 8eb50814..a0249610 100644 --- a/src/core/stl.c +++ b/src/core/stl.c @@ -300,14 +300,27 @@ DstTable *dst_stl_env() { DOP_TAILCALL }; + static uint32_t yield_asm[] = { + DOP_LOAD_NIL | (1 << 8), + DOP_TRANSFER | (1 << 16), + DOP_RETURN + }; + + static uint32_t transfer_asm[] = { + DOP_TRANSFER | (1 << 24), + DOP_RETURN + }; + DstTable *env = dst_table(0); Dst ret = dst_wrap_table(env); /* Load main functions */ dst_env_cfuns(env, cfuns); - dst_env_def(env, "error", dst_wrap_function(dst_quick_asm(1, 0, 1, error_asm, sizeof(uint32_t)))); - dst_env_def(env, "apply", dst_wrap_function(dst_quick_asm(2, 0, 2, apply_asm, 2 * sizeof(uint32_t)))); + dst_env_def(env, "error", dst_wrap_function(dst_quick_asm(1, 0, 1, error_asm, sizeof(error_asm)))); + dst_env_def(env, "apply", 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, "transfer", dst_wrap_function(dst_quick_asm(2, 0, 2, transfer_asm, sizeof(transfer_asm)))); /* Allow references to the environment */ dst_env_def(env, "_env", ret);