mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 00:10:27 +00:00
Remove transfer as a compiler special. Eventually
rely on function inlining for efficiency.
This commit is contained in:
parent
26c8145893
commit
aa68ef49f1
@ -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}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user