uint16_t ref_count; // could be an unsigned short
};
-#define HAS_OBJ struct VM_Object_ obj;
-#define INIT_OO(a, b) { (a)->obj.ref_count = 1; (a)->obj.free= (void(*)(void*,void*))b; }
-ANN static inline void rem_ref(struct VM_Object_* a, void* ptr, void *gwion) {
+#define HAS_OBJ struct VM_Object_* obj;
+#define INIT_OO(mp, a, b) { (a)->obj = mp_alloc(mp, VM_Object); (a)->obj->ref_count = 1; (a)->obj->free= (void(*)(void*,void*))b; }
+ANN static inline void rem_ref(MemPool mp, struct VM_Object_* a, void* ptr, void *gwion) {
if(--a->ref_count)
return;
a->free(ptr, gwion);
+ mp_free(mp, VM_Object, a);
}
-#define ADD_REF(a) { ++(a)->obj.ref_count; }
-#define REM_REF(a, b) { rem_ref(&(a)->obj, (a), (b)); }
+#define ADD_REF(a) { ++(a)->obj->ref_count; }
+#define REM_REF(a, b) { rem_ref(((Gwion)(b))->mp, (a)->obj, (a), (b)); }
#endif
context->nspc = new_nspc(p, str);
context->tree = ast;
context->name = str;
- INIT_OO(context, free_context);
+ INIT_OO(p, context, free_context);
return context;
}
a->info->value = new_scope(p);
a->info->type = new_scope(p);
a->info->func = new_scope(p);
- INIT_OO(a, free_nspc);
+ INIT_OO(p, a, free_nspc);
return a;
}
type->parent = parent;
if(type->parent)
type->size = parent->size;
- INIT_OO(type, free_type);
+ INIT_OO(p, type, free_type);
return type;
}
const Value a = mp_alloc(p, Value);
a->type = type;
a->name = name;
- INIT_OO(a, free_value);
+ INIT_OO(p, a, free_value);
return a;
}
Func func = mp_alloc(p, Func);
func->name = name;
func->def = def;
- INIT_OO(func, free_func);
+ INIT_OO(p, func, free_func);
return func;
}
#include "object.h"
#include "driver.h"
#include "shreduler_private.h"
+#include "env.h" // unwind
+#include "gwion.h" // unwind
#include "instr.h" // unwind
ANN void shreduler_set_loop(const Shreduler s, const m_bool loop) {
code->name = strdup(name);
code->stack_depth = stack_depth;
code->flag = flag;
- INIT_OO(code, free_vm_code)
+ INIT_OO(p, code, free_vm_code)
return code;
}