};
ANN void free_dottmpl(struct dottmpl_*);
ANN m_bool traverse_dot_tmpl(const Emitter emit, const struct dottmpl_ *dt);
+
+INSTR(SetFunc);
+INSTR(SetRecurs);
+INSTR(SetCtor);
// optimizations
#ifdef OPTIMIZE
INSTR(PutArgsInMem);
+++ /dev/null
-#ifndef __MODIFY_INSTR
-#define __MODIFY_INSTR
-typedef void (*instr_modifier)(m_bit *bytecode, m_bit *reg);
-
-ANN void emit_mod_recurs(const Emitter);
-ANN void emit_mod_func(const Emitter, const Func);
-ANN void emit_mod_ctor(const Emitter, const Type);
-#endif
eDotStatic3,
eDotFunc,
eDotStaticFunc,
- ePushStaticCode,
eGcIni,
eGcAdd,
eGcEnd,
#define DotStatic3 (f_instr)eDotStatic3
#define DotFunc (f_instr)eDotFunc
#define DotStaticFunc (f_instr)eDotStaticFunc
-#define PushStaticCode (f_instr)ePushStaticCode
#define GcIni (f_instr)eGcIni
#define GcAdd (f_instr)eGcAdd
#define GcEnd (f_instr)eGcEnd
DotStatic3
DotFunc
DotStaticFunc
-PushStaticCode
GcIni
GcAdd
GcEnd
#include "parser.h"
#include "specialid.h"
#include "vararg.h"
-#include "modify_instr.h"
#undef insert_symbol
#define insert_symbol(a) insert_symbol(emit->gwion->st, (a))
if(t->nspc->pre_ctor) {
const Instr set_code = regseti(emit, (m_uint)t->nspc->pre_ctor);
set_code->m_val2 = SZ_INT;
- } else
- emit_mod_ctor(emit, t);
+ } else {
+ const Instr instr = emit_add_instr(emit, SetCtor);
+ instr->m_val = (m_uint)t;
+ }
const m_uint offset = emit_code_offset(emit);
const Instr regset = regseti(emit, offset);
regset->m_val2 = SZ_INT *2;
else { // recursive function. (maybe should be used only for global funcs)
const Instr back = (Instr) vector_size(&emit->code->instr) ?
(Instr)vector_back(&emit->code->instr) : emit_add_instr(emit, RegPushImm);
- back->opcode = ePushStaticCode;
+ back->opcode = eOP_MAX;
+ back->execute = SetRecurs;
back->m_val = 0;
}
} else if(emit->env->func != f && !f->value_ref->from->owner_class && !f->code && !is_fptr(emit->gwion, f->value_ref->type)) {
instr->m_val = val;
instr->m_val2 = val2;
} else if(f != emit->env->func && !f->code && !is_fptr(emit->gwion, f->value_ref->type)){
- /* not yet emitted static func */
+ // not yet emitted static func
+/*
if(f->value_ref->from->owner_class) {
const Instr instr = vector_size(&emit->code->instr) ?
(Instr)vector_back(&emit->code->instr) : emit_add_instr(emit, PushStaticCode);
assert(instr->opcode == ePushStaticCode);
instr->opcode = eRegPushImm;
- } else
- emit_mod_func(emit, f);
+ } else*/
+ const Instr instr = emit_add_instr(emit, SetFunc);
+ instr->m_val = (m_uint)f;
+// emit_mod_func(emit, f);
}
const m_uint offset = emit_code_offset(emit);
regseti(emit, offset);
+++ /dev/null
-#include "gwion_util.h"
-#include "gwion_ast.h"
-#include "gwion_env.h"
-#include "vm.h"
-#include "gwion.h"
-#include "instr.h"
-#include "emit.h"
-
-// should be in vm.h
-#define VAL (*(m_uint*)(byte + SZ_INT))
-#define FVAL (*(m_float*)(byte + SZ_INT))
-#define VAL2 (*(m_uint*)(byte + SZ_INT*2))
-/*
-ANN static void set_recurs(m_bit *byte, m_bit **reg) {
- *(m_bit*)byte = eRegPushImm;
- VAL = (*(m_uint*)(*reg-SZ_INT) = );
- VAL2 = -SZ_INT;
-// copy from vm_code
-}
-*/
-
-ANN static void set_func(m_bit *byte, m_bit **reg) {
- *(m_bit*)byte = eRegSetImm;
- VAL = (*(m_uint*)(*reg-SZ_INT) = (m_uint)((Func)VAL)->code);
- VAL2 = -SZ_INT;
-// copy from vm_code
-}
-
-ANN static void set_ctor(m_bit *byte, m_bit *reg) {
- *(m_bit*)byte = eRegSetImm;
- VAL = (*(m_uint*)(reg+SZ_INT) = (m_uint)((Type)VAL)->nspc->pre_ctor);
- VAL2 = SZ_INT;
-}
-
-ANN void emit_mod_recurs(const Emitter emit) {
- const Instr instr = vector_size(&emit->code->instr) ?
- (Instr)vector_back(&emit->code->instr) : emit_add_instr(emit, RegPushImm);
- instr->opcode = ePushStaticCode;
- instr->m_val = 0;
-}
-
-ANN void emit_mod_func(const Emitter emit, const Func f) {
- const Instr instr = emit_add_instr(emit, PushStaticCode);
- instr->m_val = (m_uint)f;
- instr->m_val2 = (m_uint)set_func;
-}
-
-ANN void emit_mod_ctor(const Emitter emit, const Type t) {
- const Instr instr = emit_add_instr(emit, PushStaticCode);
- instr->m_val = (m_uint)t;
- instr->m_val2 = (m_uint)set_ctor;
-}
} while((t = t->e->parent));
Except(shred, "MissigTmplException[internal]");
}
+
+#define VAL (*(m_uint*)(byte + SZ_INT))
+#define FVAL (*(m_float*)(byte + SZ_INT))
+#define VAL2 (*(m_uint*)(byte + SZ_INT*2))
+
+INSTR(SetFunc) {
+ const Func f = (Func)instr->m_val;
+ m_bit *byte = shred->code->bytecode + (shred->pc -1)* SZ_INT*3;
+ *(m_bit*)byte = eRegPushImm;
+ VAL = *(m_uint*)(shred->reg) = (m_uint)f->code;
+ shred->reg += SZ_INT;
+}
+
+INSTR(SetRecurs) {
+ m_bit *byte = shred->code->bytecode + (shred->pc -1)* SZ_INT*3;
+ *(m_bit*)byte = eRegPushImm;
+ VAL = *(m_uint*)(shred->reg) = (m_uint)shred->code;
+ shred->reg += SZ_INT;
+}
+
+INSTR(SetCtor) {
+ const Type t = (Type)instr->m_val;
+ m_bit *byte = shred->code->bytecode + (shred->pc -1)* SZ_INT*3;
+ *(m_bit*)byte = eRegSetImm;
+ VAL = *(m_uint*)(shred->reg + SZ_INT) = (m_uint)t->nspc->pre_ctor;
+ VAL2 = SZ_INT;
+}
+
ANN static void emit_member_func(const Emitter emit, const Exp_Dot* member) {
const Func f = exp_self(member)->info->type->e->d.func;
+ if(f->def->base->tmpl)
+ emit_add_instr(emit, DotTmplVal);
+else
if(is_class(emit->gwion, member->t_base) || GET_FLAG(member->base->info->type, force)) {
- const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : PushStaticCode);
- func_i->m_val = (m_uint)f->code;
+ const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : SetFunc);
+ func_i->m_val = (m_uint)f->code ?: (m_uint)f;
return;
}
- if(f->def->base->tmpl)
- emit_add_instr(emit, DotTmplVal);
+// if(f->def->base->tmpl)
+// emit_add_instr(emit, DotTmplVal);
else {
if(GET_FLAG(member->t_base, struct)) {
if(!GET_FLAG(f->def, static)) {
exp_setvar(member->base, 1);
emit_exp(emit, member->base);
}
- const Instr instr = emit_add_instr(emit, f->code ? RegPushImm : PushStaticCode);
- instr->m_val = (m_uint)f->code;
+ const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : SetFunc);
+ func_i->m_val = (m_uint)f->code ?: (m_uint)f;
return;
}
const Instr instr = emit_add_instr(emit, GET_FLAG(f, member) ? DotFunc : DotStaticFunc);
ANN static Instr handle_instr(const Emitter emit, const M_Operator* mo) {
if(mo->func) {
- const Instr push = emit_add_instr(emit, mo->func->code ? RegPushImm : PushStaticCode);
+ const Instr push = emit_add_instr(emit, mo->func->code ? RegPushImm : SetFunc);
push->m_val = ((m_uint)mo->func->code ?:(m_uint)mo->func);
const Instr instr = emit_exp_call1(emit, mo->func);
if(mo->func->def->base->xid == insert_symbol(emit->gwion->st, "@conditionnal"))
#include "map_private.h"
#include "gack.h"
#include "array.h"
-#include "modify_instr.h"
static inline uint64_t splitmix64_stateless(uint64_t index) {
uint64_t z = (index + UINT64_C(0x9E3779B97F4A7C15));
&&newobj, &&addref, &&addrefaddr, &&objassign, &&assign, &&remref,
&&setobj, &&except, &&allocmemberaddr, &&dotmember, &&dotfloat, &&dotother, &&dotaddr,
&&staticint, &&staticfloat, &&staticother,
- &&dotfunc, &&dotstaticfunc, &&pushstaticcode,
+ &&dotfunc, &&dotstaticfunc,
&&gcini, &&gcadd, &&gcend,
&&gacktype, &&gackend, &&gack, &&noop, &&eoc, &&other, &®pushimm
};
*(VM_Code*)(reg-SZ_INT) = ((Func)vector_at(a.obj->vtable, VAL))->code;
PRAGMA_POP()
DISPATCH()
-pushstaticcode: // TODO: use external instr
- ((instr_modifier)VAL2)(byte, reg);
- DISPATCH()
gcini:
vector_add(&shred->gc, 0);
DISPATCH();
m_bit *ptr = _mp_malloc(p, sz * BYTECODE_SZ);
for(m_uint i= 0; i < sz; ++i) {
const Instr instr = (Instr)vector_at(v, i);
- if(instr->opcode == ePushStaticCode && !instr->m_val) {
- instr->opcode = eRegPushImm;
- instr->m_val = (m_uint)code;
- }
if(instr->opcode < eOP_MAX)
memcpy(ptr + i*BYTECODE_SZ, instr, BYTECODE_SZ);
else {