1
0
mirror of https://github.com/janet-lang/janet synced 2025-12-03 07:08:09 +00:00

Add quick asm for adding apply and error to the stl.

This commit is contained in:
bakpakin
2018-01-21 16:41:15 -05:00
parent 911b0b15e8
commit 42a88de9e7
5 changed files with 37 additions and 25 deletions

View File

@@ -243,3 +243,17 @@ DstFunction *dst_function(DstFuncDef *def, DstFunction *parent) {
}
return func;
}
/* Utility for inline assembly */
DstFunction *dst_quick_asm(int32_t arity, int varargs, int32_t slots, const uint32_t *bytecode, size_t bytecode_size) {
DstFuncDef *def = dst_funcdef_alloc();
def->arity = arity;
def->flags = varargs ? DST_FUNCDEF_FLAG_VARARG : 0;
def->slotcount = slots;
def->bytecode = malloc(bytecode_size);
if (!def->bytecode) {
DST_OUT_OF_MEMORY;
}
memcpy(def->bytecode, bytecode, bytecode_size);
return dst_function(def, NULL);
}

View File

@@ -23,6 +23,7 @@
#include <dst/dst.h>
#include <dst/dststl.h>
#include <dst/dstasm.h>
#include <dst/dstopcodes.h>
int dst_stl_exit(DstArgs args) {
int32_t exitcode = 0;
@@ -274,12 +275,24 @@ static const DstReg cfuns[] = {
};
DstTable *dst_stl_env() {
static uint32_t error_asm[] = {
DOP_ERROR
};
static uint32_t apply_asm[] = {
DOP_PUSH_ARRAY | (1 << 8),
DOP_TAILCALL
};
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))));
/* Allow references to the environment */
dst_env_def(env, "_env", ret);