/* vararg */
INSTR(VarargIni);
+INSTR(VarargCheck);
INSTR(PopArrayClass);
ANN static m_bool emit_stmt_varloop(const Emitter emit, const Stmt_VarLoop stmt) {
CHECK_BB(variadic_state(emit, stmt, 1))
CHECK_BB(emit_exp(emit, stmt->exp))
+ const Instr check = emit_add_instr(emit, VarargCheck);
const Instr member = emit_add_instr(emit, DotMember4);
member->m_val = SZ_INT*2;
const Instr instr = emit_add_instr(emit, BranchEqInt);
emit_stmt(emit, stmt->body, 1);
CHECK_BB(emit_exp(emit, stmt->exp))
emit_vararg_end(emit, pc);
- instr->m_val = emit_code_size(emit);
CHECK_BB(variadic_state(emit, stmt, 0))
- instr->m_val = emit_code_size(emit);
+ check->m_val = instr->m_val = emit_code_size(emit);
return GW_OK;
}
isa(v->type, shred->info->vm->gwion->type[et_object]) > 0)
release(*(M_Object*)(o->data + v->from->offset), shred);
else if(GET_FLAG(v->type, struct) &&
- !GET_FLAG(v, static) && !GET_FLAG(v, pure)) {
+ !GET_FLAG(v, static) && !GET_FLAG(v, pure) && v->type->e->tuple) {
const TupleForm tf = v->type->e->tuple;
for(m_uint i = 0; i < vector_size(&tf->types); ++i) {
const m_bit *data = o->data + v->from->offset;
struct Vararg_* arg = mp_calloc(shred->info->mp, Vararg);
*(struct Vararg_**)o->data = arg;
POP_REG(shred, instr->m_val - SZ_INT)
-// if((arg->l = instr->m_val)) {
if((*(m_uint*)(o->data + SZ_INT * 2) = instr->m_val)) {
arg->d = (m_bit*)xmalloc(round2szint(instr->m_val));
const Vector kinds = (Vector)instr->m_val2;
*(M_Object*)REG(-SZ_INT) = o;
}
+INSTR(VarargCheck) {
+ const M_Object o = *(M_Object*)(shred->reg-SZ_INT);
+ struct Vararg_ *arg = *(struct Vararg_**)o->data;
+ if(arg->s)
+ return;
+ shred->reg -= SZ_INT;
+ shred->pc = instr->m_val;
+}
+
static INSTR(VarargEnd) {
const M_Object o = *(M_Object*)REG(0);
struct Vararg_* arg = *(struct Vararg_**)o->data;
const M_Object o = *(M_Object*)REG(-SZ_INT);
if(!*(m_uint*)(o->data + SZ_INT))
Except(shred, "Using Vararg outside varloop");
- if(!*(m_uint*)(o->data + SZ_INT*2))
- Except(shred, "Using Vararg cast on empty vararg");
struct Vararg_* arg = *(struct Vararg_**)o->data;
const Type t = (Type)instr->m_val;
if(isa((Type)vector_at(&arg->t, arg->i), t) < 0)
+++ /dev/null
-fun void test(...) {
- vararg.start;
-}
fun void test(...) {
<<< this, " ", __func__ >>>;
- vararg.start;
- <<< vararg $ int >>>;
- vararg.end;
+ varloop vararg {
+ <<< vararg $ int >>>;
+ }
}
test @=> iptr;
fun void test(...){
- vararg.start;
- vararg.end;
+ varloop vararg {
+ }
}
test();
-fun void test(int i, float f, ...){ vararg.start; vararg.end; }
+fun void test(int i, float f, ...){
+ varloop vararg {
+ }
+}
test(1, 2.3, 1);
fun void test(...) {
var Object o;
- vararg.start;
- vararg $ Object @=> o;
- vararg.end;
+ varloop vararg {
+ vararg $ Object @=> o;
+ }
}