const m_bool is_var;
};
-typedef struct M_Vector_ * M_Vector;
+typedef struct M_Vector_ {
+ m_bit* ptr;
+} * M_Vector;
+#define ARRAY_OFFSET SZ_INT * 4
+#define ARRAY_PTR(array) (array->ptr + ARRAY_OFFSET)
+#define ARRAY_LEN(array) *(m_uint*)(array->ptr)
+#define ARRAY_SIZE(array) *(m_uint*)(array->ptr + SZ_INT)
+#define ARRAY_CAP(array) *(m_uint*)(array->ptr + SZ_INT*2)
+
typedef struct ArrayInfo_ {
m_int depth;
struct Vector_ type;
uint is_obj;
} ArrayInfo;
-ANN m_uint m_vector_size(const M_Vector);
+ANN static inline m_uint m_vector_size(const M_Vector v) {
+ return ARRAY_LEN(v);
+}
+
+ANN static inline void m_vector_get(const M_Vector v, const m_uint i, void* c) {
+ const m_uint size = ARRAY_SIZE(v);
+ memcpy(c, ARRAY_PTR(v) + i * size, size);
+}
+
+ANN static inline m_bit* m_vector_addr(const M_Vector v, const m_uint i) {
+ return &*(m_bit*)(ARRAY_PTR(v) + i * ARRAY_SIZE(v));
+}
+
ANN void m_vector_set(const M_Vector, const m_uint, const void*);
-ANN void m_vector_get(const M_Vector, const m_uint, void*);
ANN void m_vector_add(const M_Vector, const void*);
-ANN m_bit* m_vector_addr(const M_Vector, const m_uint);
ANN void m_vector_rem(const M_Vector, const m_uint);
ANEW M_Vector new_m_vector(MemPool, const m_uint size, const m_uint len);
ANN void free_m_vector(MemPool, M_Vector);
eBranchNeqFloat,
eArrayAppend,
eAutoLoop,
- eAutoLoopPtr,
- eAutoLoopCount,
eArrayTop,
eArrayAccess,
eArrayGet,
#define BranchNeqFloat (f_instr)eBranchNeqFloat
#define ArrayAppend (f_instr)eArrayAppend
#define AutoLoop (f_instr)eAutoLoop
-#define AutoLoopPtr (f_instr)eAutoLoopPtr
-#define AutoLoopCount (f_instr)eAutoLoopCount
#define ArrayTop (f_instr)eArrayTop
#define ArrayAccess (f_instr)eArrayAccess
#define ArrayGet (f_instr)eArrayGet
BranchNeqFloat
ArrayAppend
AutoLoop
-AutoLoopPtr
-AutoLoopCount
ArrayTop
ArrayAccess
ArrayGet
ANN static Instr emit_struct_decl(const Emitter emit, const Value v, const m_bool emit_addr) {
emit_add_instr(emit, RegPushMem);
const Instr instr = emit_kind(emit, v->type->size, emit_addr, structmember);
- if(!emit_addr)
- regpush(emit, v->type->size - SZ_INT);
+ if(!emit_addr) {
+ const m_int sz = v->type->size - SZ_INT;
+ if(sz)
+ regpush(emit, v->type->size - SZ_INT);
+ }
return instr;
}
}
ANN static m_bool _emit_stmt_each(const Emitter emit, const Stmt_Each stmt, m_uint *end_pc) {
+ CHECK_BB(emit_exp(emit, stmt->exp))
+ const m_uint _offset = emit_local(emit, emit->gwion->type[et_int]);//array?
+ const Instr tomem = emit_add_instr(emit, Reg2Mem);
+ tomem->m_val = _offset + SZ_INT;
+ tomem->m_val2 = -SZ_INT;
+ regpop(emit, SZ_INT);
const Instr s1 = emit_add_instr(emit, MemSetImm);
Instr cpy = emit_add_instr(emit, MemSetImm);
emit_local(emit, emit->gwion->type[et_int]);
emit_local(emit, emit->gwion->type[et_int]);
stmt->v->from->offset = offset + SZ_INT;
const m_uint ini_pc = emit_code_size(emit);
- const Instr loop = emit_add_instr(emit, AutoLoopPtr);
+ const Instr loop = emit_add_instr(emit, AutoLoop);
const Instr end = emit_add_instr(emit, BranchEqInt);
const m_bool ret = scoped_stmt(emit, stmt->body, 1);
*end_pc = emit_code_size(emit);
}
ANN static m_bool emit_stmt_each(const Emitter emit, const Stmt_Each stmt) {
- CHECK_BB(emit_exp(emit, stmt->exp))
emit_push_stack(emit);
m_uint end_pc = 0;
const m_bool ret = _emit_stmt_each(emit, stmt, &end_pc);
emit_pop_stack(emit, end_pc);
- regpop(emit, SZ_INT);
return ret;
}
#include "gwi.h"
#include "emit.h"
-struct M_Vector_ {
- m_bit* ptr;
-};
-#define ARRAY_OFFSET SZ_INT * 4
-#define ARRAY_PTR(array) (array->ptr + ARRAY_OFFSET)
-#define ARRAY_LEN(array) *(m_uint*)(array->ptr)
-#define ARRAY_SIZE(array) *(m_uint*)(array->ptr + SZ_INT)
-#define ARRAY_CAP(array) *(m_uint*)(array->ptr + SZ_INT*2)
-
-ANN m_uint m_vector_size(const M_Vector v) {
- return ARRAY_LEN(v);
-}
-
M_Vector new_m_vector(MemPool p, const m_uint size, const m_uint len) {
const M_Vector array = mp_calloc(p, M_Vector);
const size_t sz = (ARRAY_OFFSET*SZ_INT) + (len*size);
return a;
}
-ANN void m_vector_get(const M_Vector v, const m_uint i, void* c) {
- const m_uint size = ARRAY_SIZE(v);
- memcpy(c, ARRAY_PTR(v) + i * size, size);
-}
-
ANN void m_vector_add(const M_Vector v, const void* data) {
const m_uint size = ARRAY_SIZE(v);
if(++ARRAY_LEN(v) >= ARRAY_CAP(v)) {
struct_addref(shred->info->vm->gwion, array_base(o->type_ref), shred->mem + SZ_INT*2);
}
-ANN m_bit* m_vector_addr(const M_Vector v, const m_uint i) {
- return &*(m_bit*)(ARRAY_PTR(v) + i * ARRAY_SIZE(v));
-}
-
static MFUN(vm_vector_size) {
*(m_uint*)RETURN = ARRAY_LEN(ARRAY(o));
}
&®move, &®tomem, &®tomemother, &&overflow, &&funcusrend, &&funcmemberend,
&&sporkini, &&forkini, &&sporkfunc, &&sporkmemberfptr, &&sporkexp, &&sporkend,
&&brancheqint, &&branchneint, &&brancheqfloat, &&branchnefloat,
- &&arrayappend, &&autoloop, &&autoloopptr, &&autoloopcount, &&arraytop, &&arrayaccess, &&arrayget, &&arrayaddr, &&arrayvalid,
+ &&arrayappend, &&autoloop, &&arraytop, &&arrayaccess, &&arrayget, &&arrayaddr, &&arrayvalid,
&&newobj, &&addref, &&addrefaddr, &&structaddref, &&structaddrefaddr, &&objassign, &&assign, &&remref,
&&except, &&allocmemberaddr, &&dotmember, &&dotfloat, &&dotother, &&dotaddr,
&&unioncheck, &&unionint, &&unionfloat, &&unionother, &&unionaddr,
m_vector_add(ARRAY(*(M_Object*)(reg-SZ_INT)), reg);
DISPATCH()
autoloop:
- m_vector_get(ARRAY(*(M_Object*)(reg-SZ_INT)), *(m_uint*)(mem + VAL), mem + VAL + SZ_INT);
- goto autoloopcount;
-autoloopptr:
- *(m_bit**)(mem + VAL + SZ_INT) = m_vector_addr(ARRAY(*(M_Object*)(reg-SZ_INT)), *(m_uint*)(mem + VAL));
-autoloopcount:
- *(m_uint*)reg = m_vector_size(ARRAY(*(M_Object*)(reg-SZ_INT))) - (*(m_uint*)(mem + VAL))++;
+ *(m_bit**)(mem + VAL + SZ_INT) = m_vector_addr(ARRAY(*(M_Object*)(mem+VAL-SZ_INT)), *(m_uint*)(mem + VAL));
+ *(m_uint*)reg = m_vector_size(ARRAY(*(M_Object*)(mem+VAL-SZ_INT))) - (*(m_uint*)(mem + VAL))++;
reg += SZ_INT;
DISPATCH()
arraytop: