m_bit* d; // d(ata)
m_uint o, i, s; // o(ffset), i(ndex), s(ize)
};
-
+void free_vararg(struct Vararg_* arg);
#endif
#include "import.h"
#include "vararg.h"
+void free_vararg(struct Vararg_* arg) {
+ xfree(arg->d);
+ xfree(arg->k);
+ mp_free(Vararg, arg);
+}
+
INSTR(VarargTop) { GWDEBUG_EXE
struct Vararg_* arg = *(struct Vararg_**)MEM(instr->m_val);
if(arg->d)
else {
shred->pc = instr->m_val2 + 1;
mp_free(Vararg, arg);
- return;
}
}
POP_REG(shred, instr->m_val)
arg->d = (m_bit*)xmalloc(instr->m_val);
memcpy(arg->d, shred->reg, instr->m_val);
- } else {
- if(*(m_uint*)instr->ptr)
- POP_REG(shred, SZ_INT)
- arg->d = NULL;
- }
+ } else if(*(m_uint*)instr->ptr)
+ POP_REG(shred, SZ_INT)
const Vector kinds = (Vector)instr->m_val2;
if(kinds) {
- arg->s = vector_size(kinds);
- if(arg->s) {
+ if((arg->s = vector_size(kinds))) {
arg->k = (m_uint*)xcalloc(arg->s, SZ_INT);
memcpy(arg->k, kinds->ptr + OFFSET, arg->s * SZ_INT);
}
- } else {
- arg->s = 0;
- arg->k = NULL;
}
- arg->o = 0;
- arg->i = 0;
*(struct Vararg_**)REG(0) = arg;
PUSH_REG(shred, SZ_INT);
}
arg->o += arg->k[arg->i];
if(++arg->i < arg->s)
shred->pc = instr->m_val2;
- else {
- free(arg->d);
- free(arg->k);
- mp_free(Vararg, arg);
- }
+ else
+ free_vararg(arg);
}
INSTR(VarargMember) { GWDEBUG_EXE
ret = err_msg(f->td->xid->pos, "...in function '%s'", s_name(f->name));
if(variadic)
REM_REF(variadic)
- if(GET_FLAG(f, builtin)) {
- if(GET_FLAG(func, member) && GET_FLAG(func, ref))
- f->stack_depth += SZ_INT;
+ if(GET_FLAG(f, builtin))
func->code->stack_depth = f->stack_depth;
- }
else if(GET_FLAG(f, op))
operator_func(func);
nspc_pop_value(env->curr);
ANN static m_bool scan2_func_def_builtin(const Func func, const m_str name) { GWDEBUG_EXE
SET_FLAG(func, builtin);
+ if(GET_FLAG(func->def, variadic))
+ func->def->stack_depth += SZ_INT;
func->code = new_vm_code(NULL, func->def->stack_depth,
GET_FLAG(func, member), name);
SET_FLAG(func->code, builtin);
#include "import.h"
#include "vararg.h"
+static MFUN(m_test) {
+ printf("%p\n", *(M_Object*)MEM(0));
+}
+
static MFUN(m_variadic) {
M_Object str_obj = *(M_Object*)MEM(SZ_INT);
if(!str_obj)return;
arg->i++;
str++;
}
- POP_REG(shred, SZ_INT);
+ free_vararg(arg);
}
GWION_IMPORT(variadic test) {
CHECK_BB(gwi_func_ini(gwi, "void", "member", m_variadic))
CHECK_BB(gwi_func_arg(gwi, "string", "format"))
CHECK_BB(gwi_func_end(gwi, ae_flag_variadic))
+ CHECK_BB(gwi_func_ini(gwi, "void", "test", m_test))
+ CHECK_BB(gwi_func_end(gwi, 0))
CHECK_BB(gwi_class_end(gwi))
return 1;
}
Variadic v;
"iiii" => string format;
<<<v, " ", format $ Object>>>;
-//v.member(format);
v.member(format, 1,2,3,4);
-//v.member(1,2,3,4);
-//v.member(1,2,3,4);
+v.member(format, 1,2,3,4);
+v.test();
+v.member(format, 1,2,3,4);
+v.member(format, 1,2,3,4);
+v.test();
+v.member(format, 1,2,3,4);
+v.member(format, 1,2,3,4);
+v.test();