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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user