From: Jérémie Astor Date: Thu, 11 Feb 2021 18:43:16 +0000 (+0100) Subject: :art: Use vmcode_callback X-Git-Tag: nightly~970 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=ea77c3939ecc9c4f0d20e7638386d747185c6208;p=gwion.git :art: Use vmcode_callback --- diff --git a/include/vm.h b/include/vm.h index 9da8493c..502a1c20 100644 --- a/include/vm.h +++ b/include/vm.h @@ -73,6 +73,7 @@ struct VM_Shred_ { }; REF_FUNC(VM_Code, vmcode) ANN2(1,5) ANEW VM_Code new_vmcode(MemPool p, const Vector instr, const m_uint stack_depth, const int builtin, const m_str name); +ANN ANEW VM_Code vmcode_callback(MemPool p, const VM_Code code); ANN VM_Shred shreduler_get(const Shreduler s) __attribute__((hot)); ANN void shreduler_remove(const Shreduler s, const VM_Shred out, const m_bool erase)__attribute__((hot)); diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index e30fbe00..11ea745b 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -151,3 +151,16 @@ VM_Code new_vmcode(MemPool p, const Vector instr, const m_uint stack_depth, code->ref = 1; return code; } + +// TODO: handle native code +// TODO: do not re-create if code exists +VM_Code vmcode_callback(MemPool mp, VM_Code base) { + char name[strlen(base->name) + 11]; + sprintf(name, "%s(callback)", base->name); + const Instr instr = (Instr)vector_back(base->instr); + instr->opcode = eEOC; + VM_Code code = new_vmcode(mp, base->instr, base->stack_depth, base->builtin, name); + code->callback = 1; + instr->opcode = eFuncReturn; + return code; +}