ANN m_int gwi_item_ini(const Gwi gwi, const m_str type, const m_str name);
ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, union value_data);
-#define gwi_item_end(a, b, c) gwi_item_end(a, (const ae_flag)(b), (m_uint*const)c)
+#define gwi_item_end(a, b, c) gwi_item_end(a, (const ae_flag)(b), c)
ANN void ck_clean_item(MemPool, ImportCK*);
#endif
if(vflag(v, vflag_direct)) {
const m_uint size = v->type->size;
const Instr instr = emit_kind(emit, size, exp_getvar(prim_exp(data)), dotstatic);
- instr->m_val = (m_uint)v->d.ptr;
+ instr->m_val = (m_uint)&v->d.ptr;
} else {
const m_uint size = v->type->size;
const Instr instr = emit_kind(emit, size, exp_getvar(prim_exp(data)), regpushimm);
- if((!exp_getvar(prim_exp(data)) && size == SZ_INT)) {
- if(isa(v->type, emit->gwion->type[et_object]) > 0 || vflag(v, vflag_enum))
- instr->m_val = (m_uint)v->d.ptr;
- else if(v->d.ptr)
- instr->m_val = *(m_uint*)v->d.ptr;
- } else {
- assert(v->d.ptr); // instr->m_val = v->d.ptr;
- memcpy(&instr->m_val, v->d.ptr, v->type->size);
- }
+ if(v->type->size == SZ_FLOAT)
+ instr->f = v->d.fnum;
+ else
+ instr->m_val = v->d.num;
instr->m_val2 = size;
}
return GW_OK;
const Instr instr = emit_add_instr(emit, Reg2Reg);
instr->m_val = -SZ_INT;
}
-/*
- const size_t missing_depth = type->array_depth - (array ? array->depth : 0) - (decl->td->array ? decl->td->array->depth : 0);
- if(missing_depth) {
- const Instr push = emit_add_instr(emit, Reg2Reg);
- push->m_val = -(missing_depth) * SZ_INT;
- }
-*/
} else if(struct_ctor(v))
emit_struct_decl_finish(emit, v->type, emit_addr);
return GW_OK;
if(is_obj && (is_array || !is_ref))
CHECK_BB(emit_instantiate_decl(emit, type, decl->td, array, is_ref))
const Instr instr = emit_kind(emit, v->type->size, !struct_ctor(v) ? emit_addr : 1, dotstatic);
- v->d.ptr = mp_calloc2(emit->gwion->mp, v->type->size);
- if(isa(type, emit->gwion->type[et_union]) < 0)
- set_vflag(v, vflag_direct);// mpalloc
- instr->m_val = (m_uint)v->d.ptr;
+ if(type->size > SZ_INT) //{
+ v->d.ptr = mp_calloc2(emit->gwion->mp, v->type->size);
+ instr->m_val = (m_uint)&v->d.ptr;
+ set_vflag(v, vflag_direct);// mpalloc
instr->m_val2 = v->type->size;
if(is_obj && (is_array || !is_ref || emit_addr)) {
const Instr assign = emit_add_instr(emit, Assign);
assign->m_val = emit_var;
-/*
- const size_t missing_depth = type->array_depth - (array ? array->depth : 0) - (decl->td->array ? decl->td->array->depth : 0);
- if(missing_depth) {
- const Instr push = emit_add_instr(emit, Reg2Reg);
- push->m_val = -(missing_depth) * SZ_INT;
- }
-*/
(void)emit_object_addref(emit, -SZ_INT, emit_var);
} else if(struct_ctor(v))
emit_struct_decl_finish(emit, v->type, emit_addr);
#include "vm.h"
#include "gwion.h"
+#define MAX(a, b) (a >= b ? a : b)
ANN void free_value(Value a, Gwion gwion) {
const Type t = a->type;
-if(!vflag(a, vflag_enum)) {
- if(!vflag(a, vflag_func) && a->d.ptr && !vflag(a, vflag_direct) &&
- !(vflag(a, vflag_builtin) && a->from->owner_class)
- && isa(t, gwion->type[et_object]) < 0)
- _mp_free(gwion->mp, t->size, a->d.ptr);
- else if(vflag(a, vflag_freeme))
- xfree(a->d.ptr);
-}
- if(is_class(gwion, t))
+ if(t->size > SZ_INT && !vflag(a, vflag_func) && a->d.ptr)
+ _mp_free(gwion->mp, t->size, a->d.ptr);
+ else if(is_class(gwion, t))
type_remref(t, gwion);
mp_free(gwion->mp, ValueFrom, a->from);
mp_free(gwion->mp, Value, a);
GWION_IMPORT(values) {
VM* vm = gwi_vm(gwi);
- ALLOC_PTR(gwi->gwion->mp, d_zero, m_float, 0.0);
- ALLOC_PTR(gwi->gwion->mp, sr, m_float, (m_float)vm->bbq->si->sr);
- ALLOC_PTR(gwi->gwion->mp, samp, m_float, 1.0);
- ALLOC_PTR(gwi->gwion->mp, ms, m_float, (m_float)(*sr / 1000.));
- ALLOC_PTR(gwi->gwion->mp, second, m_float, (m_float)*sr);
- ALLOC_PTR(gwi->gwion->mp, minute, m_float, (m_float)(*sr * 60.0));
- ALLOC_PTR(gwi->gwion->mp, hour, m_float, (m_float)(*minute * 60.0));
- ALLOC_PTR(gwi->gwion->mp, t_zero, m_float, 0.0);
- ALLOC_PTR(gwi->gwion->mp, pi, m_float, (m_float)M_PI);
+ const m_float sr = vm->bbq->si->sr;
gwi_item_ini(gwi, "float", "samplerate");
gwi_item_end(gwi, ae_flag_const, sr);
gwi_item_ini(gwi, "float", "pi");
- gwi_item_end(gwi, ae_flag_const, pi);
+ gwi_item_end(gwi, ae_flag_const, (m_float)M_PI);
gwi_item_ini(gwi, "dur", "d_zero");
- gwi_item_end(gwi, ae_flag_const, d_zero);
+ gwi_item_end(gwi, ae_flag_const, (m_float)0.0);
gwi_item_ini(gwi, "dur", "samp");
- gwi_item_end(gwi, ae_flag_const, samp);
+ gwi_item_end(gwi, ae_flag_const, (m_float)1.0);
gwi_item_ini(gwi, "dur", "ms");
- gwi_item_end(gwi, ae_flag_const, ms);
+ gwi_item_end(gwi, ae_flag_const, (m_float)(sr/1000.0));
gwi_item_ini(gwi, "dur", "second");
- gwi_item_end(gwi, ae_flag_const, second);
+ gwi_item_end(gwi, ae_flag_const, sr);
gwi_item_ini(gwi, "dur", "minute");
- gwi_item_end(gwi, ae_flag_const, minute);
+ gwi_item_end(gwi, ae_flag_const, (m_float)(sr*60.0));
gwi_item_ini(gwi, "dur", "hour");
- gwi_item_end(gwi, ae_flag_const, hour);
+ gwi_item_end(gwi, ae_flag_const, (m_float)(sr*60*60));
gwi_item_ini(gwi, "time", "t_zero");
- gwi_item_end(gwi, ae_flag_const, t_zero);
+ gwi_item_end(gwi, ae_flag_const, (m_float)0.0);
return GW_OK;
}
static MFUN(string_rtrim) {
const m_str str = STRING(o);
- m_uint len = strlen(str) - 1;
- while(str[len] == ' ')
- len--;
- char c[len + 2];
- strncpy(c, str, len + 1);
- c[len + 1] = '\0';
- *(M_Object*)RETURN = new_string(shred->info->vm->gwion->mp, shred, c);
+ const size_t sz = strlen(str);
+ if(sz) {
+ m_uint len = strlen(str) - 1;
+ while(str[len] == ' ')
+ len--;
+ char c[len + 2];
+ strncpy(c, str, len + 1);
+ c[len + 1] = '\0';
+ *(M_Object*)RETURN = new_string(shred->info->vm->gwion->mp, shred, c);
+ } else {
+ ++o->ref;
+ *(M_Object*)RETURN = o;
+ }
}
static MFUN(string_trim) {
GWION_IMPORT(global_var_test) {
-// ALLOC_PTR(i, m_uint, 1);
const M_Object obj = new_object(gwi->gwion->mp, NULL, gwi->gwion->type[et_string]);
STRING(obj) = s_name(insert_symbol(gwi->gwion->st, "test"));
GWI_BB(gwi_item_ini(gwi,"string", "i"))
GWI_BB(gwi_item_end(gwi, 0, obj))
- ALLOC_PTR(gwi->gwion->mp, cf, m_float, 2.1);
GWI_BB(gwi_item_ini(gwi,"float", "f"))
- GWI_BB(gwi_item_end(gwi, 0, cf))
+ GWI_BB(gwi_item_end(gwi, 0, (m_float)2.1))
return GW_OK;
}