From: fennecdjay Date: Wed, 31 Jan 2024 20:30:32 +0000 (+0100) Subject: :fire: few fixes X-Git-Tag: nightly~108 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=6ecdb4525895276cf389afd806ca232d71e99a73;p=gwion.git :fire: few fixes --- diff --git a/const-generic.gw b/const-generic.gw deleted file mode 100644 index 451f7af9..00000000 --- a/const-generic.gw +++ /dev/null @@ -1,22 +0,0 @@ -#!enum Enum { -#! bar, -#! foo -#!} -#!class C:[const int N] { -#!class C:[const Enum N] { -#! N :=> var auto n; -#! <<< "N:${N} n:${n}" >>>; -#!} - -fun void foo:[T, const float N]() { -#! <<< __func__ >>>; - <<< N >>>; -#! <<< "heyo">>>; -} -#!const int i; -#!new C:[Enum.foo]; -#!new C:[2]; -#!r -#!foo:[int, Enum.foo](); -foo:[int, .2](); -#!foo:[int, 2](); diff --git a/include/opcode.h b/include/opcode.h index d0704e44..537955ef 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -150,6 +150,7 @@ enum { eReg2Mem, eReg2Mem4, e_staticmemcpy_, + e_staticmemset_, eOverflow, eFuncUsrEnd, eFuncUsrEnd2, @@ -370,6 +371,7 @@ enum { #define Reg2Mem (f_instr)eReg2Mem #define Reg2Mem4 (f_instr)eReg2Mem4 #define _staticmemcpy_ (f_instr)e_staticmemcpy_ +#define _staticmemset_ (f_instr)e_staticmemset_ #define Overflow (f_instr)eOverflow #define FuncUsrEnd (f_instr)eFuncUsrEnd #define FuncUsrEnd2 (f_instr)eFuncUsrEnd2 @@ -1119,6 +1121,10 @@ ANN static inline void dump_opcodes(const VM_Code code) { gw_out("{Y}┃{0}{-}% 4lu{0}: _staticmemcpy_", j); gw_out("\n"); break; + case e_staticmemset_: + gw_out("{Y}┃{0}{-}% 4lu{0}: _staticmemset_", j); + gw_out("\n"); + break; case eOverflow: gw_out("{Y}┃{0}{-}% 4lu{0}: Overflow ", j); gw_out("\n"); diff --git a/opcode.txt b/opcode.txt index 4bd9f83b..ba0271d8 100644 --- a/opcode.txt +++ b/opcode.txt @@ -147,6 +147,7 @@ RegMove~i Reg2Mem~u~i Reg2Mem4~u~u _staticmemcpy_ +_staticmemset_ Overflow FuncUsrEnd FuncUsrEnd2 diff --git a/src/emit/emit.c b/src/emit/emit.c index 49986981..296df6bb 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -111,9 +111,9 @@ ANN static inline void frame_push(Frame *frame) { vector_add(&frame->defer, (vtype)NULL); } -static const f_instr allocmember[] = {RegPushImm, RegPushImm2, RegPushImm3, +static const f_instr allocmember[4] = {RegPushImm, RegPushImm2, _staticmemset_, DotMemberMem4}; -static const f_instr allocword[] = {AllocWord, AllocWord2, AllocWord3, +static const f_instr allocword[4] = {AllocWord, AllocWord2, AllocWord3, RegPushMem4}; ANN static m_bool emit_class_def(const Emitter, const Class_Def); @@ -1023,9 +1023,13 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, if (GET_FLAG(v, late)) // ref or emit_var ? emit_memsetimm(emit, v->from->offset, 0); } - if(!(safe_tflag(emit->env->class_def, tflag_struct) && !emit->env->scope->depth)) - emit_kind(emit, v->from->offset, v->type->size, !struct_ctor(v) ? emit_addr : true, + if(!(safe_tflag(emit->env->class_def, tflag_struct) && !emit->env->scope->depth)) { + const Instr instr = emit_kind(emit, v->from->offset, v->type->size, !struct_ctor(v) ? emit_addr : true, exec); + // we want to push a zero + if(vflag(v, vflag_member) && !emit_addr) + instr->m_val = 0; + } else emit_struct_decl(emit, v, !struct_ctor(v) ? emit_addr : 1); if (is_obj && !is_ref && !exp_self(decl)->ref) { if (!emit_var) diff --git a/src/vm/vm.c b/src/vm/vm.c index ae3009f5..5550543a 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -408,7 +408,7 @@ _Pragma(STRINGIFY(COMPILER diagnostic ignored UNINITIALIZED) #define IVAL (*(m_int *)(byte + SZ_INT)) #define FVAL (*(m_float *)(byte + SZ_INT)) #define VAL2 (*(m_uint *)(byte + SZ_INT + SZ_INT)) -#define IVAL2 (*(m_int *)(byte + SZ_INT + SZ_INT)) +#define IVAL2 (*(m_int *)(byte + SZ_INT + SZ_INT)) #define SVAL (*(uint16_t *)(byte + SZ_INT + SZ_INT)) #define SVAL2 (*(uint16_t *)(byte + SZ_INT + SZ_INT + sizeof(uint16_t))) @@ -454,7 +454,7 @@ vm_prepare(const VM *vm, m_bit *prepare_code) { // lgtm [cpp/use-of-goto] &&fimul, &&fidiv, &&fiand, &&fior, &&fieq, &&fine, &&figt, &&fige, &&filt, &&file, &&firassign, &&firadd, &&firsub, &&firmul, &&firdiv, &&itof, &&ftoi, &&timeadv, &&recurs, &&setcode, &®move, - &®tomem, &®tomemother, &&staticmemcpy, + &®tomem, &®tomemother, &&staticmemcpy, &&staticmemset, &&overflow, &&funcusrend, &&funcusrend2, &&funcmemberend, &&sporkini, &&forkini, &&sporkfunc, &&sporkexp, &&sporkcode, @@ -942,6 +942,10 @@ vm_prepare(const VM *vm, m_bit *prepare_code) { // lgtm [cpp/use-of-goto] staticmemcpy: memcpy((void*)VAL, reg, VAL2); DISPATCH() + staticmemset: + memset(reg, VAL2, VAL); + reg += VAL; + DISPATCH() overflow: if (overflow_(mem + VAL2, shred)) { handle(shred, "StackOverflow"); @@ -1144,9 +1148,9 @@ DISPATCH(); reg += SZ_INT; DISPATCH() dotmembermem2: - *(m_float *)(reg + SZ_INT) = + *(m_float *)reg = *(m_float *)((*(M_Object *)(mem + VAL2))->data + VAL); - reg += SZ_INT - SZ_FLOAT; + reg += SZ_FLOAT; DISPATCH() // dotmembermem3: dotmembermem4: @@ -1338,7 +1342,7 @@ static void *_dispatch[] = { &&_fimul, &&_fidiv, &&_fiand, &&_fior, &&_fieq, &&_fine, &&_figt, &&_fige, &&_filt, &&_file, &&_firassign, &&_firadd, &&_firsub, &&_firmul, &&_firdiv, &&_itof, &&_ftoi, &&_timeadv, &&_recurs, &&_setcode, &&_regmove, - &&_regtomem, &&_regtomemother, &&_staticmemcpy, + &&_regtomem, &&_regtomemother, &&_staticmemcpy, &&_staticmemset, &&_overflow, &&_funcusrend, &&_funcusrend2, &&_funcmemberend, &&_sporkini, &&_forkini, &&_sporkfunc, &&_sporkexp, &&_sporkcode, &&_forkend, @@ -1540,6 +1544,7 @@ return; PREPARE(regtomem); PREPARE(regtomemother); PREPARE(staticmemcpy); + PREPARE(staticmemset); PREPARE(overflow); PREPARE(funcusrend); PREPARE(funcusrend2);