};
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));
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;
+}