ANN void instantiate_object(const VM_Shred, const Type);
ANN void free_object(MemPool p, const M_Object);
ANEW M_Object new_object(MemPool, const VM_Shred, const Type);
-ANEW M_Object new_M_UGen(MemPool);
+ANEW M_Object new_M_UGen(const struct Gwion_*);
ANN ANEW M_Object new_array(MemPool, const Type t, const m_uint length);
ANEW M_Object new_string(MemPool, const VM_Shred, const m_str);
-ANEW M_Object new_string2(MemPool, const VM_Shred, const m_str);
+ANEW M_Object new_string2(const struct Gwion_*, const VM_Shred, const m_str);
ANEW M_Object gwion_new_string(const struct Gwion_*, const m_str);
ANEW M_Object new_shred(const VM_Shred, const m_bool);
ANN void fork_launch(const VM*, const M_Object, const m_uint);
#define __OPERATOR
#define OP_ANY_TYPE (Type)1
-#define ERR_N(a, b, ...) { env_err(env, (a), (b), ## __VA_ARGS__); return t_null; }
+#define ERR_N(a, b, ...) { env_err(env, (a), (b), ## __VA_ARGS__); return env->gwion->type[et_null]; }
typedef Type (*opck)(const Env, void*, m_bool*);
typedef struct Instr_* (*opem)(const Emitter, void*);
ae_flag flag;
};
-extern Type
- t_null, t_object, t_shred, t_fork, t_event, t_ugen, t_string, t_ptr, t_array, t_gack,
- t_function, t_fptr, t_varloop, t_vararg, t_lambda, t_class, t_union, t_undefined, t_auto, t_tuple;
-
ANN2(1,3) ANEW Type new_type(MemPool, const m_uint xid, const m_str name, const Type);
ANEW ANN Type type_copy(MemPool, const Type type);
ANN m_str get_type_name(const Env, const m_str, const m_uint);
ANN m_bool type_ref(Type) __attribute__((pure));
__attribute__((returns_nonnull))
ANN Type template_parent(const Env, const Type type);
-static inline Type actual_type(const Type t) {
- return isa(t, t_class) > 0 ? t->e->d.base_type : t;
-}
+ANN Type actual_type(const struct Gwion_* gwion, const Type t);
ANN static inline m_uint env_push_type(const Env env, const Type type) { return env_push(env, type, type->nspc); }
-ANN static inline m_bool is_fptr(const Type t) {
- return isa(actual_type(t), t_fptr) > 0;
-}
+ANN m_bool is_fptr(const struct Gwion_*, const Type t);
ANN m_uint get_depth(const Type type);
typedef enum {
et_void, et_int, et_bool, et_float, et_complex, et_polar, et_vec3, et_vec4,
- et_null, et_object, et_shred, et_fork, et_event, et_ugen, et_string, et_ptr, et_array, zt_gack,
+ et_null, et_object, et_shred, et_fork, et_event, et_ugen, et_string, et_ptr, et_array, et_gack,
et_function, et_fptr, et_varloop, et_vararg, et_lambda, et_class, et_union, et_undefined, et_auto, et_tuple,
MAX_TYPE
} type_enum;
#define TICK(a) __attribute__((hot)) ANN inline void a(const UGen u)
-ANN void ugen_ini(MemPool p, const UGen, const uint, const uint);
-ANN void ugen_gen(MemPool p, const UGen, const f_tick, void*, const m_bool);
+ANN void ugen_ini(const struct Gwion_*, const UGen, const uint, const uint);
+ANN void ugen_gen(const struct Gwion_*, const UGen, const f_tick, void*, const m_bool);
ANN void ugen_connect(const UGen lhs, const UGen rhs);
ANN void ugen_disconnect(const UGen lhs, const UGen rhs);
#endif
info->base = base;
const Instr alloc = emit_add_instr(emit, ArrayAlloc);
alloc->m_val = (m_uint)info;
- if(isa(base, t_object) > 0 && !GET_FLAG(base, abstract)) {
+ if(isa(base, emit->gwion->type[et_object]) > 0 && !GET_FLAG(base, abstract)) {
emit_pre_constructor_array(emit, base);
info->is_obj = 1;
}
const m_uint size = v->type->size;
const Instr instr = emit_kind(emit, size, exp_self(prim)->emit_var, regpushimm);
if(!exp_self(prim)->emit_var && size == SZ_INT) {
- if(isa(v->type, t_object) > 0) {
+ if(isa(v->type, emit->gwion->type[et_object]) > 0) {
instr->opcode = eRegPushImm;
instr->m_val = (m_uint)v->d.ptr;
} else if(v->d.ptr)
const Value v = prim->value;
if(v->owner_class)
return emit_symbol_owned(emit, prim);
- if(isa(v->type, t_class) > 0) {
- regpushi(emit, (m_uint)actual_type(v->type));
+ if(isa(v->type, emit->gwion->type[et_class]) > 0) {
+ regpushi(emit, (m_uint)actual_type(emit->gwion, v->type));
return GW_OK;
}
if(GET_FLAG(v, builtin) || GET_FLAG(v, union) || GET_FLAG(v, enum))
const m_uint size = v->type->size;
const Instr instr = emit_kind(emit, size, exp_self(prim)->emit_var, !GET_FLAG(v, global) ? regpushmem : regpushbase);
instr->m_val = v->offset;
- if(isa(v->type, t_function) > 0 && isa(v->type, t_fptr) < 0)
+ if(isa(v->type, emit->gwion->type[et_function]) > 0 && !is_fptr(emit->gwion, v->type))
instr->m_val = exp_self(prim)->type->e->d.func->value_ref->offset;
return GW_OK;
}
}
ANN static inline m_bool tuple_index(const Emitter emit, struct ArrayAccessInfo *const info) {
- assert(isa(info->array.type, t_tuple) > 0);
+ assert(isa(info->array.type, emit->gwion->type[et_tuple]) > 0);
const m_uint idx = info->array.exp->d.exp_primary.d.num;
emit_except(emit, info->array.type);
tuple_access(emit, info->array.exp->d.exp_primary.d.num, info->array.depth ? 0 : info->is_var);
const Value v = prim->value;
const Symbol sym = insert_symbol(c);
if(!v->d.ptr)
- v->d.ptr = (m_uint*)new_string2(emit->gwion->mp, NULL, s_name(sym));
+ v->d.ptr = (m_uint*)new_string2(emit->gwion, NULL, s_name(sym));
regpushi(emit, (m_uint)v->d.ptr);
emit_add_instr(emit, RegAddRef);
return GW_OK;
ANN static m_bool emit_dot_static_data(const Emitter emit, const Value v, const uint emit_var) {
const m_uint size = v->type->size;
- if(isa(v->type, t_class) < 0) {
+ if(isa(v->type, emit->gwion->type[et_class]) < 0) {
const Instr instr = emit_kind(emit, size, emit_var, dotstatic);
instr->m_val = (m_uint)(v->owner->info->class_data + v->offset);
instr->m_val2 = size;
ANN static m_bool emit_exp_decl_static(const Emitter emit, const Var_Decl var_decl, const uint is_ref, const uint emit_addr) {
const Value value = var_decl->value;
- if(isa(value->type, t_object) > 0 && !is_ref)
+ if(isa(value->type, emit->gwion->type[et_object]) > 0 && !is_ref)
CHECK_BB(decl_static(emit, var_decl, 0))
return emit_dot_static_data(emit, value, emit_addr);
}
const Type type = v->type;
const Array_Sub array = var_decl->array;
const m_bool is_array = array && array->exp;
- const m_bool is_obj = isa(type, t_object) > 0;
- const uint emit_addr = ((is_ref && !array) || isa(type, t_object) < 0) ?
+ const m_bool is_obj = isa(type, emit->gwion->type[et_object]) > 0;
+ const uint emit_addr = ((is_ref && !array) || isa(type, emit->gwion->type[et_object]) < 0) ?
emit_var : 1;
if(is_obj && (is_array || !is_ref)/* && !GET_FLAG(var_decl->value, ref)*/)
CHECK_BB(emit_instantiate_object(emit, type, array, is_ref))
const Type type = v->type;
const Array_Sub array = var_decl->array;
const m_bool is_array = array && array->exp;
- const m_bool is_obj = isa(type, t_object) > 0;
- const uint emit_addr = ((is_ref && !array) || isa(type, t_object) < 0) ?
+ const m_bool is_obj = isa(type, emit->gwion->type[et_object]) > 0;
+ const uint emit_addr = ((is_ref && !array) || isa(type, emit->gwion->type[et_object]) < 0) ?
emit_var : 1;
if(is_obj && (is_array || !is_ref))
CHECK_BB(emit_instantiate_object(emit, type, array, is_ref))
if(is_obj && (is_array || !is_ref)) {
const Instr assign = emit_add_instr(emit, Assign);
assign->m_val = emit_var;
- if(isa(type, t_fork) < 0) { // beware fork
+// TODO: (test type)watch me: am I needed ?
+ if(isa(type, emit->gwion->type[et_fork]) < 0) { // beware fork
const Instr instr = emit_add_instr(emit, RegAddRef);
instr->m_val = emit_var;
}
ANN static m_bool is_special(const Emitter emit, const Type t) {
if(isa(t, emit->gwion->type[et_complex]) > 0 || isa(t, emit->gwion->type[et_polar]) > 0 ||
isa(t, emit->gwion->type[et_vec3]) > 0 || isa(t, emit->gwion->type[et_vec4]) > 0 ||
- isa(t, t_vararg) > 0)
+ isa(t, emit->gwion->type[et_vararg]) > 0)
return GW_OK;
return GW_ERROR;
}
ANN static Instr get_prelude(const Emitter emit, const Func f) {
Instr instr;
- const Type t = actual_type(f->value_ref->type);
- if(isa(t, t_fptr) < 0)
+ const Type t = actual_type(emit->gwion, f->value_ref->type);
+ if(!is_fptr(emit->gwion, t))
instr = emit_add_instr(emit, !GET_FLAG(f, builtin) ? FuncUsr : SetCode);
else {
emit_except(emit, t);
ANN Instr emit_exp_call1(const Emitter emit, const Func f) {
if(!f->code || (GET_FLAG(f, ref) && !GET_FLAG(f, builtin))) {
- if(GET_FLAG(f, template) && !is_fptr(f->value_ref->type)) {
+ if(GET_FLAG(f, template) && !is_fptr(emit->gwion, f->value_ref->type)) {
if(emit->env->func != f)
CHECK_BO(emit_template_code(emit, f))
else {
back->opcode = ePushStaticCode;
back->m_val = 0;
}
- } else if(emit->env->func != f && !f->value_ref->owner_class && !f->code && !is_fptr(f->value_ref->type)) {
+ } else if(emit->env->func != f && !f->value_ref->owner_class && !f->code && !is_fptr(emit->gwion, f->value_ref->type)) {
const Instr back = !GET_FLAG(f->def, op) ? emit_add_instr(emit, PushStaticCode) : (Instr)vector_back(&emit->code->instr);
back->m_val = (m_uint)f;
}
} else if((f->value_ref->owner_class && is_special(emit, f->value_ref->owner_class) > 0) ||
!f->value_ref->owner_class || (GET_FLAG(f, template) &&
- isa(f->value_ref->type, t_fptr) < 0))
+ !is_fptr(emit->gwion, f->value_ref->type)))
push_func_code(emit, f);
else if(vector_size(&emit->code->instr)) {
const Instr back = (Instr)vector_back(&emit->code->instr);
back->m_val = f->vt_index;
}
if(vector_size(&emit->code->instr) && GET_FLAG(f, member) &&
- is_fptr(f->value_ref->type)) {
+ is_fptr(emit->gwion, f->value_ref->type)) {
const Instr back = (Instr)vector_back(&emit->code->instr);
m_bit exec = back->opcode;
m_uint val = back->m_val;
const Instr spork = emit_add_instr(emit, is_spork ? SporkExp : ForkEnd);
spork->m_val = emit->code->stack_depth;
} else {
- if(GET_FLAG(f, member) && is_fptr(f->value_ref->type)) {
+ if(GET_FLAG(f, member) && is_fptr(emit->gwion, f->value_ref->type)) {
const m_uint depth = f->def->stack_depth;
regpop(emit, depth -SZ_INT);
const Instr spork = emit_add_instr(emit, SporkMemberFptr);
}
ANN static m_bool emit_exp_typeof(const Emitter emit, const Exp_Typeof *exp) {
- regpushi(emit, (m_uint)actual_type(exp->exp->type));
+ regpushi(emit, (m_uint)actual_type(emit->gwion, exp->exp->type));
return GW_OK;
}
ANN2(1) static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool ref) {
do {
CHECK_BB(exp_func[exp->exp_type](emit, &exp->d))
- if(ref && isa(exp->type, t_object) > 0 && isa(exp->type, t_shred) < 0 ) { // beware fork
+ if(ref && isa(exp->type, emit->gwion->type[et_object]) > 0 && isa(exp->type, emit->gwion->type[et_shred]) < 0 ) { // beware fork
const Instr instr = emit_add_instr(emit, RegAddRef);
instr->m_val = exp->emit_var;
}
if(exp->cast_to)
CHECK_BB(emit_implicit_cast(emit, exp, exp->cast_to))
- if(emit->env->func && isa(exp->type, t_lambda) < 0 && isa(exp->type, t_function) > 0 &&
+ if(emit->env->func && isa(exp->type, emit->gwion->type[et_lambda]) < 0 &&
+ isa(exp->type, emit->gwion->type[et_function]) > 0 &&
!GET_FLAG(exp->type->e->d.func->value_ref->d.func_ref, pure))
UNSET_FLAG(emit->env->func, pure);
} while((exp = exp->next));
if(stmt->val->exp_type == ae_exp_call && emit->env->func == stmt->val->d.exp_call.m_func)
return optimize_taill_call(emit, &stmt->val->d.exp_call);
CHECK_BB(emit_exp_pop_next(emit, stmt->val, 0))
- if(isa(stmt->val->type, t_object) > 0 && isa(stmt->val->type , t_shred) < 0) // beware shred
+ if(isa(stmt->val->type, emit->gwion->type[et_object]) > 0 && isa(stmt->val->type , emit->gwion->type[et_shred]) < 0) // beware shred
emit_add_instr(emit, RegAddRef);
}
vector_add(&emit->code->stack_return, (vtype)emit_add_instr(emit, Goto));
ANN static m_bool case_value(const Emitter emit, const Exp base, const Exp e) {
const Value v = e->d.exp_primary.value;
- v->offset = emit_local(emit, base->type->size, isa(base->type, t_object) > 0);
+ v->offset = emit_local(emit, base->type->size, isa(base->type, emit->gwion->type[et_object]) > 0);
CHECK_BB(emit_exp(emit, base, 1))
regpop(emit, base->type->size);
const Instr instr = emit_add_instr(emit, Reg2Mem4);
else {
const m_uint size = v->type->size;
const Instr instr = emit_kind(emit, size, emit_addr, regpushimm);
- instr->m_val = (isa(v->type, t_object) > 0 ?
+ instr->m_val = (isa(v->type, emit->gwion->type[et_object]) > 0 ?
(m_uint)&v->d.ptr : (m_uint)v->d.ptr);
instr->m_val2 = size;
}
ANN static m_bool emit_member_func(const Emitter emit, const Exp_Dot* member) {
const Func f = exp_self(member)->type->e->d.func;
- if(isa(member->t_base, t_class) > 0 || GET_FLAG(member->base->type, force)) {
+ if(isa(member->t_base, emit->gwion->type[et_class]) > 0 || GET_FLAG(member->base->type, force)) {
const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : PushStaticCode);
if(f->code)
func_i->m_val = (m_uint)(f->code ?: (VM_Code)f);
}
if(is_special(emit, member->t_base) > 0)
return emit_exp_dot_special(emit, member);
- const Value value = find_value(actual_type(member->t_base), member->xid);
- if(isa(member->t_base, t_class) < 0 && (GET_FLAG(value, member) ||
-(isa(exp_self(member)->type, t_function) > 0 && isa(exp_self(member)->type, t_fptr) < 0))
+ const Value value = find_value(actual_type(emit->gwion, member->t_base), member->xid);
+ if(isa(member->t_base, emit->gwion->type[et_class]) < 0 && (GET_FLAG(value, member) ||
+(isa(exp_self(member)->type, emit->gwion->type[et_function]) > 0 && !is_fptr(emit->gwion, exp_self(member)->type)))
) {
CHECK_BB(emit_exp(emit, member->base, 0))
// emit_except(emit, member->t_base);
emit_add_instr(emit, GWOP_EXCEPT);
}
- if(isa(exp_self(member)->type, t_function) > 0 && isa(exp_self(member)->type, t_fptr) < 0)
+ if(isa(exp_self(member)->type, emit->gwion->type[et_function]) > 0 && !is_fptr(emit->gwion, exp_self(member)->type))
return emit_member_func(emit, member);
return (GET_FLAG(value, member) ? emit_member : emit_dot_static_import_data) (emit, value, exp_self(member)->emit_var);
}
do {
const Value value = a->var_decl->value;
const m_uint size = value->type->size;
- const m_bool obj = isa(value->type, t_object) > 0;
+ const m_bool obj = isa(value->type, emit->gwion->type[et_object]) > 0;
emit->code->stack_depth += size;
value->offset = emit_local(emit, size, obj);
} while((a = a->next));
#include "import.h"
#include "traverse.h"
#include "parse.h"
+#include "gwi.h"
struct M_Vector_ {
m_bit* ptr;
o->type_ref : o->type_ref->e->parent;
const Type base = array_base(t);
struct M_Vector_* a = ARRAY(o);
- if(t->array_depth > 1 || isa(base, t_object) > 0)
+ if(t->array_depth > 1 || isa(base, shred->info->vm->gwion->type[et_object]) > 0)
for(m_uint i = 0; i < ARRAY_LEN(a); ++i)
release(*(M_Object*)(ARRAY_PTR(a) + i * SZ_INT), shred);
free_m_vector(shred->info->mp, a);
const M_Vector v = ARRAY(o);
if(index < 0 || (m_uint)index >= ARRAY_LEN(v))
return;
- if(isa(o->type_ref, t_object) > 0) {
+ if(isa(o->type_ref, shred->info->vm->gwion->type[et_object]) > 0) {
M_Object obj;
m_vector_get(v, (vtype)index, &obj);
release(obj,shred);
static OP_CHECK(opck_array_at) {
ARRAY_OPCK
- if(opck_const_rhs(env, data, mut) == t_null)
- return t_null;
+ if(opck_const_rhs(env, data, mut) == env->gwion->type[et_null])
+ return env->gwion->type[et_null];
if(bin->lhs->type->array_depth != bin->rhs->type->array_depth)
ERR_N(exp_self(bin)->pos, _("array depths do not match."))
if(bin->rhs->exp_type == ae_exp_decl) {
r = r->e->parent;
if(l->array_depth == r->array_depth || isa(l->e->d.base_type, r->e->d.base_type) > 0)
return l;
- return t_null;
+ return env->gwion->type[et_null];
}
static FREEARG(freearg_array) {
}
GWION_IMPORT(array) {
- t_array = gwi_mk_type(gwi, "@Array", SZ_INT, t_object);
+ const Type t_array = gwi_mk_type(gwi, "@Array", SZ_INT, gwi->gwion->type[et_object]);
+ gwi->gwion->type[et_array] = t_array;
GWI_BB(gwi_class_ini(gwi, t_array, NULL, array_dtor))
GWI_BB(gwi_item_ini(gwi, "int", "@array"))
mk_class_instr(lt, r, l, && l != r)
ANN static m_bool import_core_libs(const Gwi gwi) {
- GWI_OB((t_class = gwi_mk_type(gwi, "Class", SZ_INT, NULL)))
+ const Type t_class = gwi_mk_type(gwi, "Class", SZ_INT, NULL);
+ gwi->gwion->type[et_class] = t_class;
GWI_BB(gwi_add_type(gwi, t_class))
- GWI_OB((t_undefined = gwi_mk_type(gwi, "@Undefined", SZ_INT, NULL))) // size = SZ_INT to enable declarations
- GWI_BB(gwi_add_type(gwi, t_undefined))
- GWI_OB((t_auto = gwi_mk_type(gwi, "auto", SZ_INT, NULL))) // size = SZ_INT to enable declarations
- GWI_BB(gwi_add_type(gwi, t_auto))
+ const Type t_undefined = gwi_mk_type(gwi, "@Undefined", SZ_INT, NULL);
+ GWI_BB(gwi_set_global_type(gwi, t_undefined, et_undefined))
+ const Type t_auto = gwi_mk_type(gwi, "auto", SZ_INT, NULL);
+ GWI_BB(gwi_set_global_type(gwi, t_auto, et_auto))
SET_FLAG(t_class, abstract);
const Type t_void = gwi_mk_type(gwi, "void", 0, NULL);
GWI_BB(gwi_set_global_type(gwi, t_void, et_void))
- GWI_OB((t_null = gwi_mk_type(gwi, "@null", SZ_INT, NULL)))
- GWI_BB(gwi_add_type(gwi, t_null))
- GWI_OB((t_function = gwi_mk_type(gwi, "@function", SZ_INT, NULL)))
- GWI_BB(gwi_add_type(gwi, t_function))
- GWI_OB((t_fptr = gwi_mk_type(gwi, "@func_ptr", SZ_INT, t_function)))
- GWI_BB(gwi_add_type(gwi, t_fptr))
- GWI_OB((t_lambda = gwi_mk_type(gwi, "@lambda", SZ_INT, t_function)))
- GWI_BB(gwi_add_type(gwi, t_lambda))
- GWI_OB((t_gack = gwi_mk_type(gwi, "@Gack", SZ_INT, NULL)))
- GWI_BB(gwi_add_type(gwi, t_gack))
+ const Type t_null = gwi_mk_type(gwi, "@null", SZ_INT, NULL);
+ GWI_BB(gwi_set_global_type(gwi, t_null, et_null))
+ const Type t_function = gwi_mk_type(gwi, "@function", SZ_INT, NULL);
+ GWI_BB(gwi_set_global_type(gwi, t_function, et_function))
+ const Type t_fptr = gwi_mk_type(gwi, "@func_ptr", SZ_INT, t_function);
+ GWI_BB(gwi_set_global_type(gwi, t_fptr, et_fptr))
+ const Type t_lambda = gwi_mk_type(gwi, "@lambda", SZ_INT, t_function);
+ GWI_BB(gwi_set_global_type(gwi, t_lambda, et_lambda))
+ const Type t_gack = gwi_mk_type(gwi, "@Gack", SZ_INT, NULL);
+ GWI_BB(gwi_set_global_type(gwi, t_gack, et_gack))
const Type t_int = gwi_mk_type(gwi, "int", SZ_INT, NULL);
GWI_BB(gwi_set_global_type(gwi, t_int, et_int))
const Type t_float = gwi_mk_type(gwi, "float", SZ_FLOAT, NULL);
const Type t_vec4 = gwi_mk_type(gwi, "Vec4", SZ_VEC4, NULL);
gwi->gwion->type[et_vec4] = t_vec4;
GWI_BB(import_object(gwi))
- GWI_OB((t_union = gwi_mk_type(gwi, "@Union", SZ_INT, t_object)))
+ const Type t_union = gwi_mk_type(gwi, "@Union", SZ_INT, gwi->gwion->type[et_object]);
+ gwi->gwion->type[et_union] = t_union;
GWI_BB(gwi_class_ini(gwi, t_union, NULL, NULL))
GWI_BB(gwi_class_end(gwi))
GWI_BB(import_tuple(gwi))
#include "object.h"
#include "operator.h"
#include "import.h"
+#include "gwi.h"
static CTOR(event_ctor) {
EV_SHREDS(o) = new_vector(shred->info->mp);
}
GWION_IMPORT(event) {
- t_event = gwi_mk_type(gwi, "Event", SZ_INT, t_object );
+ const Type t_event = gwi_mk_type(gwi, "Event", SZ_INT, gwi->gwion->type[et_object]);
+ gwi->gwion->type[et_event] = t_event;
GWI_BB(gwi_class_ini(gwi, t_event, event_ctor, event_dtor))
GWI_BB(gwi_item_ini(gwi, "int", "@shreds"))
GWI_BB(gwi_item_end(gwi, ae_flag_member, NULL))
e->exp_type = ae_exp_call;
memcpy(&e->d.exp_call, &call, sizeof(Exp_Call));
++*mut;
- return check_exp_call1(env, &e->d.exp_call) ?: t_null;
+ return check_exp_call1(env, &e->d.exp_call) ?: env->gwion->type[et_null];
}
static inline void fptr_instr(const Emitter emit, const Func f, const m_uint i) {
if(bin->rhs->type->e->d.func->def->base->tmpl)
fptr_instr(emit, bin->lhs->type->e->d.func, 2);
const Instr instr = emit_add_instr(emit, int_r_assign);
- if(isa(bin->lhs->type, t_fptr) < 0 && GET_FLAG(bin->rhs->type->e->d.func, member)) {
+ if(!is_fptr(emit->gwion, bin->lhs->type) && GET_FLAG(bin->rhs->type->e->d.func, member)) {
const Instr pop = emit_add_instr(emit, LambdaAssign);
pop->m_val = SZ_INT;
}
t1 = info->rhs->def->base->tmpl->list;
nspc_push_type(env->gwion->mp, env->curr);
while(t0) {
- nspc_add_type(env->curr, t0->xid, t_undefined);
- nspc_add_type(env->curr, t1->xid, t_undefined);
+ nspc_add_type(env->curr, t0->xid, env->gwion->type[et_undefined]);
+ nspc_add_type(env->curr, t1->xid, env->gwion->type[et_undefined]);
t0 = t0->next;
t1 = t1->next;
}
for(m_uint i = 0; i <= v->offset && !type; ++i) {
const Symbol sym = (!info->lhs->def->base->tmpl || i != 0) ?
func_symbol(env, nspc->name, c, stmpl, i) : info->lhs->def->base->xid;
- if(isa(info->lhs->value_ref->type, t_class) < 0)
+ if(isa(info->lhs->value_ref->type, env->gwion->type[et_class]) < 0)
CHECK_OO((info->lhs = nspc_lookup_func1(nspc, sym)))
else {
DECL_OO(const Type, t, = nspc_lookup_type1(nspc, info->lhs->def->base->xid))
- info->lhs = actual_type(t)->e->d.func;
+ info->lhs = actual_type(env->gwion, t)->e->d.func;
}
Func_Base *base[2] = { info->lhs->def->base, info->rhs->def->base };
if(fptr_tmpl_push(env, info) > 0) {
if(fptr_rettype(env, info) > 0 &&
fptr_arity(info) && fptr_args(env, base) > 0)
- type = actual_type(info->lhs->value_ref->type) ?: info->lhs->value_ref->type;
+ type = actual_type(env->gwion, info->lhs->value_ref->type) ?: info->lhs->value_ref->type;
if(info->rhs->def->base->tmpl)
nspc_pop_type(env->gwion->mp, env->curr);
}
}
ANN static m_bool fptr_do(const Env env, struct FptrInfo *info) {
- if(isa(info->exp->type, t_lambda) < 0) {
+ if(isa(info->exp->type, env->gwion->type[et_lambda]) < 0) {
m_bool nonnull = GET_FLAG(info->exp->type, nonnull);
CHECK_BB(fptr_check(env, info))
DECL_OB(const Type, t, = fptr_type(env, info))
ERR_O(exp_self(unary)->pos, _("forks must be stored in a value:\n"
"fork xxx @=> Fork f"))
if(unary->exp && unary->exp->exp_type == ae_exp_call)
- return unary->op == insert_symbol("spork") ? t_shred : t_fork;
+ return env->gwion->type[unary->op == insert_symbol("spork") ? et_shred : et_fork];
else if(unary->code) {
++env->scope->depth;
nspc_push_value(env->gwion->mp, env->curr);
nspc_pop_value(env->gwion->mp, env->curr);
--env->scope->depth;
CHECK_BO(ret)
- return unary->op == insert_symbol("spork") ? t_shred : t_fork;
+ return env->gwion->type[unary->op == insert_symbol("spork") ? et_shred : et_fork];
} else
ERR_O(exp_self(unary)->pos, _("only function calls can be sporked..."))
return NULL;
#include "gwion.h"
#include "gack.h"
-static void print_type(const Type type) {
- const m_bool is_func = isa(type, t_function) > 0 && isa(type, t_fptr) < 0;
+static void print_type(const Gwion gwion, const Type type) {
+ const m_bool is_func = isa(type, gwion->type[et_function]) > 0 && !is_fptr(gwion, type);
gw_out("(%s) ", is_func ? "@function" : type->name);
if(GET_FLAG(type, typedef)) {
gw_out(" aka ");
- print_type(type->e->parent);
+ print_type(gwion, type->e->parent);
}
}
print_string1(obj ? STRING(obj) : "(null string)");
}
-ANN2(1) static inline void print_object(const Type type, const M_Object obj) {
- if(isa(type, t_string) > 0)
+ANN2(1) static inline void print_object(const Gwion gwion, const Type type, const M_Object obj) {
+ if(isa(type, gwion->type[et_string]) > 0)
print_string(obj);
else
gw_out("%p", (void*)obj);
}
-ANN static inline void print_func(const Type type, const m_bit* stack) {
- if(isa(type, t_fptr) > 0 && type->e->d.func->def->base->tmpl) {
+ANN static inline void print_func(const Gwion gwion,const Type type, const m_bit* stack) {
+ if(is_fptr(gwion, type) > 0 && type->e->d.func->def->base->tmpl) {
const Func f = *(Func*)stack;
gw_out("%s", f ? f->name : "(nil)");
return;
}
if(type->e->d.func) {
- const VM_Code code = isa(type, t_fptr) > 0 ?
+ const VM_Code code = is_fptr(gwion, type) ?
*(VM_Code*)stack : type->e->d.func->code;
gw_out("%s %s %p", type->name, (void*)code ? code->name : NULL, code);
} else // uncalled lambda
for(m_uint i = size + 1; --i;) {
const Type type = (Type)vector_at(v, size - i);
if(size == 1)
- print_type(type);
- if(isa(type, t_object) > 0)
- print_object(type, *(M_Object*)(reg-offset));
- else if(isa(type, t_function) > 0)
- print_func(type, (reg-offset));
- else if(type == t_class)
- print_type(type);
- else if(isa(type, t_class) > 0)
- print_type(type->e->d.base_type);
+ print_type(gwion, type);
+ if(isa(type, gwion->type[et_object]) > 0)
+ print_object(gwion, type, *(M_Object*)(reg-offset));
+ else if(isa(type, gwion->type[et_function]) > 0)
+ print_func(gwion, type, (reg-offset));
+ else if(type == gwion->type[et_class])
+ print_type(gwion, type);
+ else if(isa(type, gwion->type[et_class]) > 0)
+ print_type(gwion, type->e->d.base_type);
else if(isa(type, gwion->type[et_void]) > 0)
print_string1("void");
else
ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, const restrict m_str name) {
DECL_OB(const Exp, exp, = make_exp(gwi, type, name))
DECL_OB(const Type, t, = known_type(gwi->gwion->env, exp->d.exp_decl.td))
- if(isa(t, t_object) > 0)
+ if(isa(t, gwi->gwion->type[et_object]) > 0)
SET_FLAG(exp->d.exp_decl.td, ref);
gwi->union_data.list = new_decl_list(gwi->gwion->mp, exp, gwi->union_data.list);
return GW_OK;
#include "import.h"
#include "ugen.h"
#include "func.h"
+#include "gwi.h"
static DTOR(basic_dtor) {
free(UGEN(o)->module.gen.data);
}
static CTOR(gain_ctor) {
- ugen_ini(shred->info->mp, UGEN(o), 1, 1);
- ugen_gen(shred->info->mp, UGEN(o), gain_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
+ ugen_ini(shred->info->vm->gwion, UGEN(o), 1, 1);
+ ugen_gen(shred->info->vm->gwion, UGEN(o), gain_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
UGEN(o)->module.gen.tick = gain_tick;
*(m_float*)UGEN(o)->module.gen.data = 1;
}
}
static GWION_IMPORT(gain) {
- const Type t_gain = gwi_mk_type(gwi, "Gain", SZ_INT, t_ugen);
+ const Type t_gain = gwi_mk_type(gwi, "Gain", SZ_INT, gwi->gwion->type[et_ugen]);
GWI_BB(gwi_class_ini(gwi, t_gain, gain_ctor, basic_dtor))
gwi_func_ini(gwi, "float", "gain", gain_get_gain);
GWI_BB(gwi_func_end(gwi, 0))
}
static CTOR(impulse_ctor) {
- ugen_ini(shred->info->mp, UGEN(o), 0, 1);
- ugen_gen(shred->info->mp, UGEN(o), impulse_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
+ ugen_ini(shred->info->vm->gwion, UGEN(o), 0, 1);
+ ugen_gen(shred->info->vm->gwion, UGEN(o), impulse_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
*(m_float*)UGEN(o)->module.gen.data = 0;
}
}
static GWION_IMPORT(impulse) {
- const Type t_impulse = gwi_mk_type(gwi, "Impulse", SZ_INT, t_ugen);
+ const Type t_impulse = gwi_mk_type(gwi, "Impulse", SZ_INT, gwi->gwion->type[et_ugen]);
GWI_BB(gwi_class_ini(gwi, t_impulse, impulse_ctor, basic_dtor))
gwi_func_ini(gwi, "float", "next", impulse_get_next);
GWI_BB(gwi_func_end(gwi, 0))
}
static CTOR(fullrect_ctor) {
- ugen_ini(shred->info->mp, UGEN(o), 1, 1);
- ugen_gen(shred->info->mp, UGEN(o), fullrect_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
+ ugen_ini(shred->info->vm->gwion, UGEN(o), 1, 1);
+ ugen_gen(shred->info->vm->gwion, UGEN(o), fullrect_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
*(m_float*)UGEN(o)->module.gen.data = 1;
}
static GWION_IMPORT(fullrect) {
- const Type t_fullrect = gwi_mk_type(gwi, "FullRect", SZ_INT, t_ugen);
+ const Type t_fullrect = gwi_mk_type(gwi, "FullRect", SZ_INT, gwi->gwion->type[et_ugen]);
GWI_BB(gwi_class_ini(gwi, t_fullrect, fullrect_ctor, basic_dtor))
return gwi_class_end(gwi);
}
}
static CTOR(halfrect_ctor) {
- ugen_ini(shred->info->mp, UGEN(o), 1, 1);
- ugen_gen(shred->info->mp, UGEN(o), halfrect_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
+ ugen_ini(shred->info->vm->gwion, UGEN(o), 1, 1);
+ ugen_gen(shred->info->vm->gwion, UGEN(o), halfrect_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
*(m_float*)UGEN(o)->module.gen.data = 1;
}
static GWION_IMPORT(halfrect) {
- const Type t_halfrect = gwi_mk_type(gwi, "HalfRect", SZ_INT, t_ugen);
+ const Type t_halfrect = gwi_mk_type(gwi, "HalfRect", SZ_INT, gwi->gwion->type[et_ugen]);
GWI_BB(gwi_class_ini(gwi, t_halfrect, halfrect_ctor, basic_dtor))
return gwi_class_end(gwi);
}
}
static CTOR(step_ctor) {
- ugen_ini(shred->info->mp, UGEN(o), 0, 1);
- ugen_gen(shred->info->mp, UGEN(o), step_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
+ ugen_ini(shred->info->vm->gwion, UGEN(o), 0, 1);
+ ugen_gen(shred->info->vm->gwion, UGEN(o), step_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
*(m_float*)UGEN(o)->module.gen.data = 0;
}
}
static GWION_IMPORT(step) {
- const Type t_step = gwi_mk_type(gwi, "Step", SZ_INT, t_ugen);
+ const Type t_step = gwi_mk_type(gwi, "Step", SZ_INT, gwi->gwion->type[et_ugen]);
GWI_BB(gwi_class_ini(gwi, t_step, step_ctor, basic_dtor))
gwi_func_ini(gwi, "float", "next", step_get_next);
GWI_BB(gwi_func_end(gwi, 0))
}
static CTOR(zerox_ctor) {
- ugen_ini(shred->info->mp, UGEN(o), 1, 1);
- ugen_gen(shred->info->mp, UGEN(o), zerox_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
+ ugen_ini(shred->info->vm->gwion, UGEN(o), 1, 1);
+ ugen_gen(shred->info->vm->gwion, UGEN(o), zerox_tick, (m_float*)xmalloc(SZ_FLOAT), 0);
*(m_float*)UGEN(o)->module.gen.data = 1;
}
static GWION_IMPORT(zerox) {
- const Type t_zerox = gwi_mk_type(gwi, "ZeroX", SZ_INT, t_ugen);
+ const Type t_zerox = gwi_mk_type(gwi, "ZeroX", SZ_INT, gwi->gwion->type[et_ugen]);
GWI_BB(gwi_class_ini(gwi, t_zerox, zerox_ctor, basic_dtor))
return gwi_class_end(gwi);
}
}
M_Object new_string(MemPool p, const VM_Shred shred, const m_str str) {
- const M_Object o = new_object(p, shred, t_string);
+ const M_Object o = new_object(p, shred, shred->info->vm->gwion->type[et_string]);
STRING(o) = s_name(insert_symbol(shred->info->vm->gwion->st, str));
return o;
}
-M_Object new_string2(MemPool p, const VM_Shred shred, const m_str str) {
- const M_Object o = new_object(p, shred, t_string);
+M_Object new_string2(const struct Gwion_ *gwion, const VM_Shred shred, const m_str str) {
+ const M_Object o = new_object(gwion->mp, shred, gwion->type[et_string]);
STRING(o) = str;
return o;
}
Value v;
while(scope_iter(&iter, &v) > 0) {
if(!GET_FLAG(v, static) && !GET_FLAG(v, pure) &&
- isa(v->type, t_object) > 0)
+ isa(v->type, shred->info->vm->gwion->type[et_object]) > 0)
release(*(M_Object*)(o->data + v->offset), shred);
}
if(GET_FLAG(t, dtor) && t->nspc->dtor) {
static inline Type check_nonnull(const Env env, const Type l, const Type r,
const m_str action, const loc_t pos) {
if(GET_FLAG(r, nonnull)) {
- if(isa(l, t_null) > 0)
+ if(isa(l, env->gwion->type[et_null]) > 0)
ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name);
if(isa(l, r) < 0)
ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name);
}
if(nonnull_check(l, r))
ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name);
- if(l != t_null && isa(l, r) < 0)
+ if(l != env->gwion->type[et_null] && isa(l, r) < 0)
ERR_N(pos, _("can't %s '%s' to '%s'"), action, l->name, r->name);
return r;
}
const Exp_Binary* bin = (Exp_Binary*)data;
const Type l = bin->lhs->type;
const Type r = bin->rhs->type;
- if(opck_rassign(env, data, mut) == t_null)
- return t_null;
- if(check_nonnull(env, l, r, "assign", exp_self(bin)->pos) == t_null)
- return t_null;
+ if(opck_rassign(env, data, mut) == env->gwion->type[et_null])
+ return env->gwion->type[et_null];
+ if(check_nonnull(env, l, r, "assign", exp_self(bin)->pos) == env->gwion->type[et_null])
+ return env->gwion->type[et_null];
if(bin->rhs->exp_type == ae_exp_decl) {
SET_FLAG(bin->rhs->d.exp_decl.td, ref);
SET_FLAG(bin->rhs->d.exp_decl.list->self->value, ref);
const Exp_Cast* cast = (Exp_Cast*)data;
const Type l = cast->exp->type;
const Type r = exp_self(cast)->type;
- if(check_nonnull(env, l, r, "cast", exp_self(cast)->pos) == t_null)
- return t_null;
+ if(check_nonnull(env, l, r, "cast", exp_self(cast)->pos) == env->gwion->type[et_null])
+ return env->gwion->type[et_null];
return get_force_type(env, r);
}
const struct Implicit* imp = (struct Implicit*)data;
const Type l = imp->e->type;
const Type r = imp->t;
- if(check_nonnull(env, l, r, "implicitly cast", imp->pos) == t_null)
- return t_null;
+ if(check_nonnull(env, l, r, "implicitly cast", imp->pos) == env->gwion->type[et_null])
+ return env->gwion->type[et_null];
imp->e->cast_to = r;
return imp->t;
}
}
GWION_IMPORT(object) {
- t_object = gwi_mk_type(gwi, "Object", SZ_INT, NULL);
+ const Type t_object = gwi_mk_type(gwi, "Object", SZ_INT, NULL);
+ gwi->gwion->type[et_object] = t_object;
GWI_BB(gwi_class_ini(gwi, t_object, NULL, NULL))
GWI_BB(gwi_class_end(gwi))
GWI_BB(gwi_oper_cond(gwi, "Object", BranchEqInt, BranchNeqInt))
OP_CHECK(opck_basic_cast) {
const Exp_Cast* cast = (Exp_Cast*)data;
return isa(cast->exp->type, exp_self(cast)->type) > 0 ?
- exp_self(cast)->type : t_null;
+ exp_self(cast)->type : env->gwion->type[et_null];
}
OP_CHECK(opck_usr_implicit) {
OP_CHECK(opck_rassign) {
const Exp_Binary* bin = (Exp_Binary*)data;
- if(opck_const_rhs(env, data, mut) == t_null)
- return t_null;
+ if(opck_const_rhs(env, data, mut) == env->gwion->type[et_null])
+ return env->gwion->type[et_null];
bin->rhs->emit_var = 1;
return bin->rhs->type;
}
const Exp_Unary* unary = (Exp_Unary*)data;
SET_FLAG(unary->td, ref);
DECL_OO(const Type, t, = known_type(env, unary->td))
- if(isa(t, t_object) < 0 && isa(t, t_function) < 0)
+ if(isa(t, env->gwion->type[et_object]) < 0 && isa(t, env->gwion->type[et_function]) < 0)
ERR_O(exp_self(unary)->pos, _("primitive types cannot be used as reference (@)...\n"))
if(type_ref(t))
ERR_N(td_pos(unary->td), _("can't use 'new' on ref type '%s'\n"), t->name)
}
*/
static OP_CHECK(opck_implicit_f2i) {
- return t_null;
+ return env->gwion->type[et_null];
}
static OP_CHECK(opck_implicit_i2f) {
#include "import.h"
#include "emit.h"
#include "traverse.h"
+#include "gwi.h"
static OP_CHECK(opck_ptr_assign) {
const Exp_Binary* bin = (Exp_Binary*)data;
do if(!strcmp(t->name, get_type_name(env, bin->rhs->type->name, 1)))
return bin->lhs->type;
while((t = t->e->parent));
- return t_null;
+ return env->gwion->type[et_null];
}
static INSTR(instr_ptr_assign) {
}
static INSTR(Cast2Ptr) {
- const M_Object o = new_object(shred->info->mp, shred, t_ptr);
+ const M_Object o = new_object(shred->info->mp, shred, shred->info->vm->gwion->type[et_ptr]);
*(m_uint**)o->data = *(m_uint**)REG(-SZ_INT);
*(M_Object*)REG(-SZ_INT) = o;
}
GWION_IMPORT(ptr) {
const m_str list[] = { "A" };
- t_ptr = gwi_mk_type(gwi, "Ptr", SZ_INT, t_object);
+ const Type t_ptr = gwi_mk_type(gwi, "Ptr", SZ_INT, gwi->gwion->type[et_object]);
+ gwi->gwion->type[et_ptr] = t_ptr;
GWI_BB(gwi_tmpl_ini(gwi, 1, list))
GWI_BB(gwi_class_ini(gwi, t_ptr, NULL, NULL))
GWI_BB(gwi_tmpl_end(gwi))
#include "import.h"
#include "emit.h"
#include "specialid.h"
+#include "gwi.h"
static m_int o_fork_thread, o_shred_cancel, o_fork_done, o_fork_ev, o_fork_retsize, o_fork_retval,
o_fork_orig;
}
M_Object new_shred(const VM_Shred shred, m_bool is_spork) {
- const M_Object obj = new_object(shred->info->mp, NULL, is_spork ? t_shred : t_fork);
+ const M_Object obj = new_object(shred->info->mp, NULL,
+ shred->info->vm->gwion->type[is_spork ? et_shred :et_fork]);
ME(obj) = shred;
if(!is_spork) {
- *(M_Object*)(obj->data + o_fork_ev) = new_object(shred->info->mp, NULL, t_event);
+ *(M_Object*)(obj->data + o_fork_ev) = new_object(shred->info->mp, NULL, shred->info->vm->gwion->type[et_event]);
EV_SHREDS(*(M_Object*)(obj->data + o_fork_ev)) = new_vector(shred->info->mp);
}
return obj;
#include "nspc.h"
GWION_IMPORT(shred) {
- GWI_OB((t_shred = gwi_mk_type(gwi, "Shred", SZ_INT, t_object)))
+ const Type t_shred = gwi_mk_type(gwi, "Shred", SZ_INT, gwi->gwion->type[et_object]);
+ gwi->gwion->type[et_shred] = t_shred;
GWI_BB(gwi_class_ini(gwi, t_shred, NULL, shred_dtor))
gwi_item_ini(gwi, "int", "@me");
SET_FLAG((t_shred), abstract);
- GWI_OB((t_fork = gwi_mk_type(gwi, "Fork", SZ_INT, t_shred)))
+ const Type t_fork = gwi_mk_type(gwi, "Fork", SZ_INT, t_shred);
+ gwi->gwion->type[et_fork] = t_fork;
GWI_BB(gwi_class_ini(gwi, t_fork, NULL, fork_dtor))
gwi_item_ini(gwi, "int", "@thread");
GWI_BB((o_fork_thread = gwi_item_end(gwi, ae_flag_const, NULL)))
#include "emit.h"
#include "specialid.h"
#include "func.h"
+#include "gwi.h"
ANN static void push_string(const VM_Shred shred, const M_Object obj, const m_str c) {
STRING(obj) = s_name(insert_symbol(shred->info->vm->gwion->st, c));
}
GWION_IMPORT(string) {
- t_string = gwi_mk_type(gwi, "string", SZ_INT, t_object);
+ const Type t_string = gwi_mk_type(gwi, "string", SZ_INT, gwi->gwion->type[et_object]);
GWI_BB(gwi_class_ini(gwi, t_string, string_ctor, NULL))
-
+ gwi->gwion->type[et_string] = t_string;
gwi_item_ini(gwi, "int", "@data");
GWI_BB(gwi_item_end(gwi, ae_flag_const, NULL))
GWI_BB(gwi_class_end(gwi))
static INSTR(TupleUnpack) {
const M_Object o = *(M_Object*)(shred->reg - SZ_INT);
struct UnpackInfo_ *info = (struct UnpackInfo_*)instr->m_val;
- memcpy(shred->mem + info->mem_offset, o->data + t_tuple->nspc->info->offset + info->obj_offset, info->size);
+ memcpy(shred->mem + info->mem_offset, o->data + shred->info->vm->gwion->type[et_tuple]->nspc->info->offset + info->obj_offset, info->size);
}
INSTR(TupleMember) {
emit_unpack_instr(emit, te);
}
-static m_bool tuple_match(const Type lhs, const Type rhs) {
+static m_bool tuple_match(const Env env, const Type lhs, const Type rhs) {
DECL_OB(const Vector, lv, = &lhs->e->tuple->types)
DECL_OB(const Vector, rv, = &rhs->e->tuple->types)
for(m_uint i = 0; i < vector_size(rv); i++) {
DECL_OB(const Type, l, = (Type)vector_at(lv, i))
const Type r = (Type)vector_at(rv, i);
- if(r != t_undefined)
+ if(r != env->gwion->type[et_undefined])
CHECK_BB(isa(l, r))
}
return GW_OK;
static OP_CHECK(opck_at_object_tuple) {
const Exp_Binary *bin = (Exp_Binary*)data;
- if(opck_rassign(env, data, mut) == t_null)
- return t_null;
- if(tuple_match(bin->lhs->type, bin->rhs->type) < 0)
- return t_null;
+ if(opck_rassign(env, data, mut) == env->gwion->type[et_null])
+ return env->gwion->type[et_null];
+ if(tuple_match(env, bin->lhs->type, bin->rhs->type) < 0)
+ return env->gwion->type[et_null];
bin->rhs->emit_var = 1;
return bin->rhs->type;
}
static OP_CHECK(opck_at_tuple_object) {
const Exp_Binary *bin = (Exp_Binary*)data;
- if(opck_rassign(env, data, mut) == t_null)
- return t_null;
+ if(opck_rassign(env, data, mut) == env->gwion->type[et_null])
+ return env->gwion->type[et_null];
if(!bin->rhs->type->e->tuple)
return bin->rhs->type;
- if(tuple_match(bin->rhs->type, bin->lhs->type) < 0)
- return t_null;
+ if(tuple_match(env, bin->rhs->type, bin->lhs->type) < 0)
+ return env->gwion->type[et_null];
bin->rhs->emit_var = 1;
return bin->rhs->type;
}
static OP_CHECK(opck_cast_tuple) {
const Exp_Cast *cast = (Exp_Cast*)data;
- CHECK_BO(tuple_match(exp_self(cast)->type, cast->exp->type))
+ CHECK_BO(tuple_match(env, exp_self(cast)->type, cast->exp->type))
return exp_self(cast)->type;
}
static OP_CHECK(opck_impl_tuple) {
struct Implicit *imp = (struct Implicit*)data;
- CHECK_BO(tuple_match(imp->e->type, imp->t))
+ CHECK_BO(tuple_match(env, imp->e->type, imp->t))
return imp->t;
}
INSTR(TupleCtor) {
const Type t = (Type)instr->m_val;
const M_Object o = new_object(shred->info->vm->gwion->mp, shred, t);
- const size_t sz = t_tuple->nspc->info->offset;
- memcpy(o->data + t_tuple->nspc->info->offset,
+ const size_t sz = shred->info->vm->gwion->type[et_tuple]->nspc->info->offset;
+ memcpy(o->data + shred->info->vm->gwion->type[et_tuple]->nspc->info->offset,
shred->reg - (t->nspc->info->offset - sz), (t->nspc->info->offset - sz));
shred->reg -= (t->nspc->info->offset - sz - SZ_INT);
*(M_Object*)(shred->reg - SZ_INT) = o;
ANN static Symbol tuple_sym(const Env env, const Vector v) {
GwText text = { .mp=env->gwion->mp };
- text_add(&text, t_tuple->name);
+ text_add(&text, env->gwion->type[et_tuple]->name);
text_add(&text, "<~");
for(m_uint i = 0; i < vector_size(v); ++i) {
const Type t = (Type)vector_at(v, i);
}
Section * section = new_section_stmt_list(env->gwion->mp, base);
Class_Body body = new_class_body(env->gwion->mp, section, NULL);
- const ID_List ilist = new_id_list(env->gwion->mp, insert_symbol(t_tuple->name),
+ const ID_List ilist = new_id_list(env->gwion->mp, insert_symbol(env->gwion->type[et_tuple]->name),
loc_cpy(env->gwion->mp, pos));
Type_Decl *td = new_type_decl(env->gwion->mp, ilist);
Class_Def cdef = new_class_def(env->gwion->mp, ae_flag_template,
}
GWION_IMPORT(tuple) {
- GWI_OB((t_tuple = gwi_mk_type(gwi, "Tuple", SZ_INT, t_object)))
+ const Type t_tuple = gwi_mk_type(gwi, "Tuple", SZ_INT, gwi->gwion->type[et_object]);
+ gwi->gwion->type[et_tuple] = t_tuple;
GWI_BB(gwi_class_ini(gwi, t_tuple, NULL, NULL))
GWI_BB(gwi_class_end(gwi))
SET_FLAG(t_tuple, abstract | ae_flag_template);
#include "gwi.h"
#include "ugen.h"
#include "driver.h"
+#include "gwi.h"
ANN static inline void ugop_add (const UGen u, const m_float f) { u->in += f; }
ANN static inline void ugop_sub (const UGen u, const m_float f) { u->in -= f; }
return u;
}
-ANEW M_Object new_M_UGen(MemPool p) {
- const M_Object o = new_object(p, NULL, t_ugen);
- UGEN(o) = new_UGen(p);
+ANEW M_Object new_M_UGen(const struct Gwion_ *gwion) {
+ const M_Object o = new_object(gwion->mp, NULL, gwion->type[et_ugen]);
+ UGEN(o) = new_UGen(gwion->mp);
return o;
}
-ANN static void assign_channel(MemPool p, const UGen u) {
+ANN static void assign_channel(const struct Gwion_ *gwion, const UGen u) {
u->multi = 1;
u->compute = gen_compute_multi;
u->connect.multi->channel = (M_Object*)xmalloc(u->connect.multi->n_chan * SZ_INT);
for(uint i = u->connect.multi->n_chan + 1; --i;) {
const uint j = i - 1;
- const M_Object chan = new_M_UGen(p);
- ugen_ini(p, UGEN(chan), u->connect.multi->n_in > j, u->connect.multi->n_out > j);
+ const M_Object chan = new_M_UGen(gwion);
+ ugen_ini(gwion, UGEN(chan), u->connect.multi->n_in > j, u->connect.multi->n_out > j);
UGEN(chan)->module.ref = u;
UGEN(chan)->compute = compute_chan;
u->connect.multi->channel[j] = chan;
}
}
-ANN void ugen_gen(MemPool p, const UGen u, const f_tick tick, void* data, const m_bool trig) {
+ANN void ugen_gen(const struct Gwion_ *gwion, const UGen u, const f_tick tick, void* data, const m_bool trig) {
u->module.gen.tick = tick;
u->module.gen.data = data;
if(trig) {
- u->module.gen.trig = new_UGen(p);
+ u->module.gen.trig = new_UGen(gwion->mp);
u->module.gen.trig->compute = compute_mono;
- ugen_ini(p, u->module.gen.trig, 1, 1);
+ ugen_ini(gwion, u->module.gen.trig, 1, 1);
u->compute = (u->compute == gen_compute_mono ? gen_compute_monotrig : gen_compute_multitrig);
}
}
-ANN void ugen_ini(MemPool p, const UGen u, const uint in, const uint out) {
+ANN void ugen_ini(const struct Gwion_ *gwion, const UGen u, const uint in, const uint out) {
const uint chan = in > out ? in : out;
if(chan == 1) {
- u->connect.net = mp_calloc(p, ugen_net);
+ u->connect.net = mp_calloc(gwion->mp, ugen_net);
vector_init(&u->connect.net->from);
vector_init(&u->connect.net->to);
} else {
- u->connect.multi = mp_calloc(p, ugen_multi);
+ u->connect.multi = mp_calloc(gwion->mp, ugen_multi);
u->connect.multi->n_in = in;
u->connect.multi->n_out = out;
u->connect.multi->n_chan = chan;
- assign_channel(p, u);
+ assign_channel(gwion, u);
}
}
ANN static m_int add_ugen(const Gwi gwi, struct ugen_importer* imp) {
VM* vm = gwi_vm(gwi);
- const M_Object o = new_M_UGen(gwi->gwion->mp);
+ const M_Object o = new_M_UGen(gwi->gwion);
const UGen u = imp->ugen = UGEN(o);
- ugen_ini(vm->gwion->mp, u, imp->nchan, imp->nchan);
- ugen_gen(vm->gwion->mp, u, imp->tick, (void*)imp->vm, 0);
+ ugen_ini(vm->gwion, u, imp->nchan, imp->nchan);
+ ugen_gen(vm->gwion, u, imp->tick, (void*)imp->vm, 0);
vector_add(&vm->ugen, (vtype)u);
CHECK_BB(gwi_item_ini(gwi, "UGen", imp->name))
return gwi_item_end(gwi, ae_flag_const, o);
struct ugen_importer adc = { vm, adc_tick, NULL, "adc", vm->bbq->si->in };
add_ugen(gwi, &adc);
ugen_connect(dac.ugen, hole.ugen);
- SET_FLAG(t_ugen, abstract);
+ SET_FLAG(gwi->gwion->type[et_ugen], abstract);
return GW_OK;
}
}
GWION_IMPORT(ugen) {
- t_ugen = gwi_mk_type(gwi, "UGen", SZ_INT, t_object);
+ const Type t_ugen = gwi_mk_type(gwi, "UGen", SZ_INT, gwi->gwion->type[et_object]);
+ gwi->gwion->type[et_ugen] = t_ugen;
GWI_BB(gwi_class_ini(gwi, t_ugen, ugen_ctor, ugen_dtor))
GWI_BB(gwi_item_ini(gwi, "int", "@ugen"))
GWI_BB(gwi_item_end(gwi, ae_flag_member, NULL))
#include "gwion.h"
#include "operator.h"
#include "import.h"
+#include "gwi.h"
void free_vararg(MemPool p, struct Vararg_* arg) {
xfree(arg->d);
}
GWION_IMPORT(vararg) {
- GWI_OB((t_vararg = gwi_mk_type(gwi, "@Vararg", SZ_INT, t_object)))
+ const Type t_vararg = gwi_mk_type(gwi, "@Vararg", SZ_INT, gwi->gwion->type[et_object]);
const Type t_varobj = gwi_mk_type(gwi, "VarObject", SZ_INT, t_vararg);
SET_FLAG(t_varobj, abstract);
- t_varloop = gwi_mk_type(gwi, "@VarLoop", SZ_INT, NULL);
+ const Type t_varloop = gwi_mk_type(gwi, "@VarLoop", SZ_INT, NULL);
GWI_BB(gwi_add_type(gwi, t_varobj))
- GWI_BB(gwi_add_type(gwi, t_varloop))
+ GWI_BB(gwi_set_global_type(gwi, t_varloop, et_varloop))
GWI_BB(gwi_class_ini(gwi, t_vararg, NULL, NULL))
+ gwi->gwion->type[et_vararg] = t_vararg;
GWI_BB(gwi_union_ini(gwi, NULL))
GWI_BB(gwi_union_add(gwi, "@VarLoop", "start"))
GWI_BB(gwi_union_add(gwi, "@VarLoop", "end"))
}
ANN void env_add_type(const Env env, const Type type) {
- const Type v_type = type_copy(env->gwion->mp, t_class);
+ const Type v_type = type_copy(env->gwion->mp, env->gwion->type[et_class]);
v_type->e->d.base_type = type;
SET_FLAG(type, builtin);
const Symbol sym = insert_symbol(type->name);
ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos) {
const Value v = nspc_lookup_value0(env->curr, s);
- if(!v || isa(v->type, t_class) > 0)
+ if(!v || isa(v->type, env->gwion->type[et_class]) > 0)
return GW_OK;
env_err(env, pos,
_("'%s' already declared as variable of type '%s'."), s_name(s), v->type->name);
if(!a->is_union) {
while(scope_iter(&iter, &v) > 0) {
if(v) {
- if(isa(v->type, t_object) > 0)
+ if(isa(v->type, gwion->type[et_object]) > 0)
nspc_release_object(a, v, gwion);
REM_REF(v, gwion);
}
a->e->d.base_type = type->e->d.base_type;
a->array_depth = type->array_depth;
a->e->def = type->e->def;
- if(t_function && isa(type, t_function) > 0) {
- if(a->e->tuple) {
- free_tupleform(p, a->e->tuple);
- a->e->tuple = NULL;
- }
- }
return a;
}
const Type type = nspc_lookup_type1(base->e->owner, sym);
if(type)
return type;
- const Type t = new_type(env->gwion->mp, t_array->xid, base->name, t_array);
+ const Type t = new_type(env->gwion->mp, env->gwion->type[et_array]->xid, base->name, env->gwion->type[et_array]);
t->name = s_name(sym);
t->size = SZ_INT;
t->array_depth = depth + base->array_depth;
t->e->d.base_type = base;
- t->nspc = t_array->nspc;
+ t->nspc = env->gwion->type[et_array]->nspc;
ADD_REF(t->nspc);
SET_FLAG(t, checked);
t->e->owner = base->e->owner;
return depth;
}
-Type
- t_null, t_object, t_shred, t_fork, t_event, t_ugen, t_string, t_ptr, t_array, t_gack,
- t_function, t_fptr, t_varloop, t_vararg, t_lambda, t_class, t_union, t_undefined, t_auto, t_tuple;
+ANN m_bool is_fptr(const struct Gwion_* gwion, const Type t) {
+ return isa(actual_type(gwion, t), gwion->type[et_fptr]) > 0;
+}
+
+ANN Type actual_type(const struct Gwion_* gwion, const Type t) {
+ return isa(t, gwion->type[et_class]) > 0 ? t->e->d.base_type : t;
+}
const Type t = a->type;
if(!GET_FLAG(a, func) && a->d.ptr && !GET_FLAG(a, union) &&
!(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->owner_class)
- && isa(t, t_object) < 0)
+ && isa(t, gwion->type[et_object]) < 0)
_mp_free(gwion->mp, t->size, a->d.ptr);
- if(isa(t, t_class) > 0/* || isa(a->type, t_function) > 0*/)
+ if(isa(t, gwion->type[et_class]) > 0/* || isa(a->type, t_function) > 0*/)
REM_REF(t, gwion)
mp_free(gwion->mp, Value, a);
}
CHECK_BO(scan1_exp(env, td->exp))
CHECK_BO(scan2_exp(env, td->exp))
CHECK_OO(check_exp(env, td->exp))
- const Type t = actual_type(td->exp->type);
- if(!t || (isa(td->exp->type, t_class) < 0 && t == t_class))
+ const Type t = actual_type(env->gwion, td->exp->type);
+ if(!t || (isa(td->exp->type, env->gwion->type[et_class]) < 0 && t == env->gwion->type[et_class]))
ERR_O(td->exp->pos, _("Expression must be of type '%s', not '%s'\n"
- "maybe you meant typeof(Expression)"), t_class->name, td->exp->type->name);
+ "maybe you meant typeof(Expression)"), env->gwion->type[et_class]->name, td->exp->type->name);
m_uint depth;
td->xid = str2list(env, t->name, &depth);
if(depth) {
clear_decl(env, decl);
CHECK_BO(scan1_exp(env, exp_self(decl)))
CHECK_BO(scan2_exp(env, exp_self(decl)))
- if(isa(decl->type, t_class) > 0) {
+ if(isa(decl->type, env->gwion->type[et_class]) > 0) {
do {
- list->self->value->type = t_auto;
+ list->self->value->type = env->gwion->type[et_auto];
} while((list = list->next));
- ((Exp_Decl*)decl)->type = t_auto;
+ ((Exp_Decl*)decl)->type = env->gwion->type[et_auto];
}
- if(decl->type == t_auto)
+ if(decl->type == env->gwion->type[et_auto])
ERR_O(td_pos(decl->td), _("can't infer type."));
}
if(!decl->type)
if(env->class_def) {
if(GET_FLAG(decl->td, member)) {
decl_member(env, v);
- if(isa(env->class_def, t_object) > 0)
+ if(isa(env->class_def, env->gwion->type[et_object]) > 0)
tuple_info(env, decl->td, var);
} else if(GET_FLAG(decl->td, static))
decl_static(env, v);
}
else if(global || (env->func && GET_FLAG(env->func->def, global)))
SET_FLAG(v, abstract);
- if(isa(decl->type, t_fptr) > 0)
+ if(is_fptr(env->gwion, decl->type))
CHECK_BO(check_fptr_decl(env, var))
SET_FLAG(v, checked | ae_flag_used);
nspc_add_value(env->curr, var->xid, v);
const Value v = nspc_lookup_value0(env->global_nspc, sym);
if(v)
return v;
- const Value value = new_value(env->gwion->mp, t_string, s_name(sym));
+ const Value value = new_value(env->gwion->mp, env->gwion->type[et_string], s_name(sym));
nspc_add_value_front(env->global_nspc, sym, value);
return value;
}
sprintf(c, "%s:string", str);
prim->value = prim_str_value(env, insert_symbol(c));
}
- return t_string;
+ return env->gwion->type[et_string];// prim->value
}
ANN static Type prim_id(const Env env, Exp_Primary* primary) {
if(env->func)
UNSET_FLAG(env->func, pure);
CHECK_OO((check_exp(env, primary->d.exp)))
- return t_gack;
+ return env->gwion->type[et_gack];
}
ANN static Type prim_tuple(const Env env, const Exp_Primary * primary) {
describe_prim_xxx(num, env->gwion->type[et_int])
describe_prim_xxx(float, env->gwion->type[et_float])
describe_prim_xxx(nil, env->gwion->type[et_void])
-describe_prim_xxx(unpack, t_tuple)
+describe_prim_xxx(unpack, env->gwion->type[et_tuple])
typedef Type (*_type_func)(const Env, const void*);
static const _type_func prim_func[] = {
if(idx >= vector_size(v))
ERR_O(exp->pos, _("tuple subscripts too big"))
const Type type = (Type)vector_at(v, idx);
- if(type == t_undefined)
+ if(type == env->gwion->type[et_undefined])
ERR_O(exp->pos, _("tuple subscripts is undefined at index %lu"), idx)
if(!exp->next)
return type;
}
if(t->array_depth >= depth)
return array_type(env, array_base(array->type), t->array_depth - depth);
- return (isa(t, t_tuple) < 0 ? partial_depth : tuple_depth)(env, array);
+ return (isa(t, env->gwion->type[et_tuple]) < 0 ? partial_depth : tuple_depth)(env, array);
}
static inline m_bool index_is_int(const Env env, Exp e, m_uint *depth) {
e->type->array_depth == t->array_depth &&
array_base(e->type) == array_base(t);
if(!match) {
- if(e->type == t_lambda && isa(t, t_fptr) > 0) {
+ if(e->type == env->gwion->type[et_lambda] && is_fptr(env->gwion, t)) {
const Type owner = nspc_lookup_type1(t->e->owner->parent,
insert_symbol(t->e->owner->name));
return check_lambda(env, owner, &e->d.exp_lambda, t->e->d.func->def);
CHECK_OO(func->next);
return find_func_match_actual(env, func->next, args, implicit, specific);
}
- if(e1->type == t_undefined ||
- (func->def->base->tmpl && is_fptr(func->value_ref->type) > 0)) {
+ if(e1->type == env->gwion->type[et_undefined] ||
+ (func->def->base->tmpl && is_fptr(env->gwion, func->value_ref->type) > 0)) {
if(SAFE_FLAG(func->value_ref->owner_class, template))
CHECK_BO(template_push_types(env, func->value_ref->owner_class->e->def->base.tmpl))
e1->type = known_type(env, e1->td);
const Value v = decl->value;
if(arg_list->td && !arg_list->td->xid)
arg_list->type = v->type = check_td(env, arg_list->td);
- if(isa(v->type, t_object) > 0 || isa(v->type, t_function) > 0)
+ if(isa(v->type, env->gwion->type[et_object]) > 0 || isa(v->type, env->gwion->type[et_function]) > 0)
UNSET_FLAG(env->func, pure);
CHECK_BB(already_defined(env, decl->xid, decl->pos))
SET_FLAG(v, checked);
Func m_func = NULL, former = env->func;
DECL_OO(const m_str, tmpl_name, = tl2str(env, types))
const m_uint scope = env_push(env, v->owner_class, v->owner);
- if(is_fptr(v->type)) {
+ if(is_fptr(env->gwion, v->type)) {
const Symbol sym = func_symbol(env, v->owner->name, v->name, tmpl_name, 0);
const Value value = nspc_lookup_value1(v->owner, sym);
Func_Def base = v->d.func_ref ? v->d.func_ref->def : exp->func->type->e->d.func->def;
if(template_push_types(env, fbase->tmpl) > 0) {
const Fptr_Def fptr = new_fptr_def(env->gwion->mp, fbase, base->flag);
if(value) {
- fptr->type = actual_type(value->type);
+ fptr->type = actual_type(env->gwion, value->type);
fptr->value = value;
}
if(traverse_fptr_def(env, fptr) > 0 &&
m_func = find_func_match(env, fbase->func, exp->args);
nspc_pop_type(env->gwion->mp, env->curr);
if(!value && m_func)
- nspc_add_type_front(v->owner, sym, actual_type(m_func->value_ref->type));
+ nspc_add_type_front(v->owner, sym, actual_type(env->gwion, m_func->value_ref->type));
}
free_fptr_def(env->gwion->mp, fptr); // ???? related
}
ANN static m_bool check_exp_call1_check(const Env env, const Exp exp) {
CHECK_OB(check_exp(env, exp))
- if(isa(exp->type, t_function) < 0)
+ if(isa(exp->type, env->gwion->type[et_function]) < 0)
ERR_B(exp->pos, _("function call using a non-function value"))
return GW_OK;
}
ANN Type check_exp_call1(const Env env, const Exp_Call *exp) {
CHECK_BO(check_exp_call1_check(env, exp->func))
- if(exp->func->type == t_lambda)
+ if(exp->func->type == env->gwion->type[et_lambda])
return check_lambda_call(env, exp);
if(GET_FLAG(exp->func->type->e->d.func, ref)) {
const Value value = exp->func->type->e->d.func->value_ref;
bin->rhs->exp_type == ae_exp_decl)
bin->lhs->d.exp_unary.fork_ok = 1;
CHECK_OO(check_exp(env, bin->lhs))
- if(bin->rhs->exp_type == ae_exp_decl && bin->rhs->d.exp_decl.type == t_auto)
+ if(bin->rhs->exp_type == ae_exp_decl && bin->rhs->d.exp_decl.type == env->gwion->type[et_auto])
bin->rhs->type = bin->rhs->d.exp_decl.type = bin->lhs->type;
CHECK_OO(check_exp(env, bin->rhs))
struct Op_Import opi = { .op=bin->op, .lhs=bin->lhs->type,
struct Op_Import opi = { .op=post->op, .lhs=check_exp(env, post->exp), .data=(uintptr_t)post, .pos=exp_self(post)->pos };
CHECK_OO(opi.lhs)
const Type t = op_check(env, &opi);
- if(t && isa(t, t_object) < 0)
+ if(t && isa(t, env->gwion->type[et_object]) < 0)
exp_self(post)->meta = ae_meta_value;
return t;
}
ANN static Type check_exp_call(const Env env, Exp_Call* exp) {
if(exp->tmpl) {
CHECK_OO(check_exp(env, exp->func))
- const Type t = actual_type(!GET_FLAG(exp->func->type, nonnull) ?
+ const Type t = actual_type(env->gwion, !GET_FLAG(exp->func->type, nonnull) ?
exp->func->type : exp->func->type->e->parent);
const Value v = nspc_lookup_value1(t->e->owner, insert_symbol(t->name));
if(!GET_FLAG(v, func) && !GET_FLAG(exp->func->type, func) )
ANN static Type check_exp_dot(const Env env, Exp_Dot* member) {
const m_str str = s_name(member->xid);
CHECK_OO((member->t_base = check_exp(env, member->base)))
- const m_bool base_static = isa(member->t_base, t_class) > 0;
+ const m_bool base_static = isa(member->t_base, env->gwion->type[et_class]) > 0;
const Type the_base = base_static ? member->t_base->e->d.base_type : member->t_base;
if(!the_base->nspc)
ERR_O(member->base->pos,
ANN m_bool check_type_def(const Env env, const Type_Def tdef) {
return tdef->type->e->def ? check_class_def(env, tdef->type->e->def) : GW_OK;
}
-ANN static Type check_exp_lambda(const Env env NUSED,
- const Exp_If* exp_if NUSED) { return t_lambda; }
+ANN static Type check_exp_lambda(const Env env,
+ const Exp_If* exp_if NUSED) { return env->gwion->type[et_lambda]; }
ANN static Type check_exp_typeof(const Env env, const Exp_Typeof *exp) {
DECL_OO(const Type, t, = check_exp(env, exp->exp))
do {
next = curr->next;
CHECK_OO((curr->type = exp_func[curr->exp_type](env, &curr->d)))
- if(isa(curr->type, t_varloop) > 0 && (prev || next))
+ if(isa(curr->type, env->gwion->type[et_varloop]) > 0 && (prev || next))
ERR_O(exp->pos, _("Varloop must be the only expression"))
- if(env->func && isa(curr->type, t_lambda) < 0 && isa(curr->type, t_function) > 0 &&
+ if(env->func && isa(curr->type, env->gwion->type[et_lambda]) < 0 && isa(curr->type, env->gwion->type[et_function]) > 0 &&
!GET_FLAG(curr->type->e->d.func, pure))
UNSET_FLAG(env->func, pure);
} while((prev = curr) && (curr = next));
const m_uint depth = t->array_depth - 1;
if(GET_FLAG(t, typedef))
t = t->e->parent;
- if(!ptr || isa(t, t_array) < 0)
+ if(!ptr || isa(t, env->gwion->type[et_array]) < 0)
ERR_B(stmt_self(stmt)->pos, _("type '%s' is not array.\n"
" This is not allowed in auto loop"), stmt->exp->type->name)
if(stmt->is_ptr) {
ERR_B(stmt_self(stmt)->pos, _("'return' statement found outside function definition"))
DECL_OB(const Type, ret_type, = stmt->val ? check_exp(env, stmt->val) : env->gwion->type[et_void])
if(!env->func->def->base->ret_type) {
- assert(isa(env->func->value_ref->type, t_lambda) > 0);
+ assert(isa(env->func->value_ref->type, env->gwion->type[et_lambda]) > 0);
env->func->def->base->ret_type = ret_type;
return GW_OK;
}
Decl_List l = udef->l;
do {
CHECK_OB(check_exp(env, l->self))
- if(isa(l->self->type, t_object) > 0) {
+ if(isa(l->self->type, env->gwion->type[et_object]) > 0) {
Var_Decl_List list = l->self->d.exp_decl.list;
do SET_FLAG(list->self->value, pure);
while((list = list->next));
vector_init(&env->curr->info->vtable);
if(parent) {
const Value v = find_value(parent, fdef->base->xid);
- if(v && isa(v->type, t_function) > 0) {
+ if(v && isa(v->type, env->gwion->type[et_function]) > 0) {
const m_bool match = parent_match_actual(env, fdef, v->d.func_ref);
if(match)
return match;
const Func func = fdef->base->func;
if(env->class_def && env->class_def->e->parent) {
const Value override = find_value(env->class_def->e->parent, fdef->base->xid);
- if(override && override->owner_class && isa(override->type, t_function) < 0)
+ if(override && override->owner_class && isa(override->type, env->gwion->type[et_function]) < 0)
ERR_B(fdef->pos,
_("function name '%s' conflicts with previously defined value...\n"
" from super class '%s'..."),
}
ANN static Value set_variadic(const Env env) {
- const Value variadic = new_value(env->gwion->mp, t_vararg, "vararg");
+ const Value variadic = new_value(env->gwion->mp, env->gwion->type[et_vararg], "vararg");
SET_FLAG(variadic, checked);
nspc_add_value(env->curr, insert_symbol("vararg"), variadic);
return variadic;
return GW_OK;
const Type type = cdef->base.type;
SET_FLAG(type, check);
- if(type->e->parent == t_undefined) {
+ if(type->e->parent == env->gwion->type[et_undefined]) {
type->e->parent = check_td(env, cdef->base.ext);
return traverse_cdef(env, cdef);
}
if(cdef->base.ext)
CHECK_BB(scanx_parent(cdef->base.type, check_class_parent, env))
else if(!type->e->parent)
- type->e->parent = t_object;
+ type->e->parent = env->gwion->type[et_object];
inherit(type);
if(cdef->body)
CHECK_BB(env_body(env, cdef, check_section))
struct OpChecker ock = { env, &nspc->info->op_map, &opi2, 0 };
const Type ret = op_check_inner(&ock);
if(ret) {
- if(ret == t_null)
+ if(ret == env->gwion->type[et_null])
break;
if(!ock.mut)
set_nspc(&ock, nspc);
ANN static Value mk_class(const Env env, const Type base) {
const Symbol sym = insert_symbol(base->name);
- const Type t = type_copy(env->gwion->mp, t_class);
+ const Type t = type_copy(env->gwion->mp, env->gwion->type[et_class]);
const Value v = new_value(env->gwion->mp, t, s_name(sym));
t->e->d.base_type = base;
v->owner = base->e->owner;
CHECK_OB(known_type(env, fptr->base->td))
CHECK_BB(scan0_defined(env, fptr->base->xid, td_pos(fptr->base->td)));
const m_str name = s_name(fptr->base->xid);
- const Type t = new_type(env->gwion->mp, t_fptr->xid, name, t_fptr);
+ const Type t = new_type(env->gwion->mp, env->gwion->type[et_fptr]->xid, name, env->gwion->type[et_fptr]);
t->e->owner = !(!env->class_def && GET_FLAG(fptr->base->td, global)) ?
env->curr : env->global_nspc;
t->nspc = new_nspc(env->gwion->mp, name);
CHECK_BB(env_access(env, tdef->ext->flag, td_pos(tdef->ext)))
DECL_OB(const Type, base, = tdef->tmpl ? find_type(env, tdef->ext->xid) : known_type(env, tdef->ext))
CHECK_BB(scan0_defined(env, tdef->xid, td_pos(tdef->ext)))
- if(isa(base, t_function) < 0) {
+ if(isa(base, env->gwion->type[et_function]) < 0) {
if(!tdef->ext->types && (!tdef->ext->array || !tdef->ext->array->exp))
typedef_simple(env, tdef, base);
else
ANN static Type union_type(const Env env, const Nspc nspc, const Symbol s, const m_bool add) {
const m_str name = s_name(s);
- const Type t = type_copy(env->gwion->mp, t_union);
+ const Type t = type_copy(env->gwion->mp, env->gwion->type[et_union]);
t->xid = ++env->scope->type_xid;
t->name = name;
t->nspc = new_nspc(env->gwion->mp, name);
t->nspc->parent = nspc;
t->nspc->is_union = 1;
t->e->owner = nspc;
- t->e->parent = t_union;
+ t->e->parent = env->gwion->type[et_union];
if(add) {
add_type(env, nspc, t);
mk_class(env, t);
}
ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) {
- const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, s_name(cdef->base.xid), t_object);
+ const Type t = new_type(env->gwion->mp, ++env->scope->type_xid, s_name(cdef->base.xid), env->gwion->type[et_object]);
t->e->owner = env->curr;
t->nspc = new_nspc(env->gwion->mp, t->name);
// t->nspc->parent = GET_FLAG(cdef, global) ? env_nspc(env) : env->curr;
DECL_OO(const Type, type, = known_type(env, td))
{
const Type t = get_type(type);
- if(isa(t, t_object) > 0)
+ if(isa(t, env->gwion->type[et_object]) > 0)
CHECK_BO(type_recursive(env, td, t))
}
if(type->size)
CHECK_BB(isres(env, var->xid, exp_self(decl)->pos))
Type t = decl->type;
const Value former = nspc_lookup_value0(env->curr, var->xid);
- if(former && t != t_auto)
+ if(former && t != env->gwion->type[et_auto])
ERR_B(var->pos, _("variable %s has already been defined in the same scope..."),
s_name(var->xid))
if(var->array) {
ANN m_bool scan1_type_def(const Env env, const Type_Def tdef) {
if(!tdef->type->e->def)return GW_OK;
-// return tdef->type->e->def ? scan1_cdef(env, tdef->type->e->def) : GW_OK;
- return isa(tdef->type, t_fptr) < 0 ? scan1_cdef(env, tdef->type->e->def) : GW_OK;
+ return !is_fptr(env->gwion, tdef->type) ? scan1_cdef(env, tdef->type->e->def) : GW_OK;
}
ANN m_bool scan1_union_def_action(const Env env, const Union_Def udef,
if(cdef->base.type == t)
ERR_B(pos, _("recursive (%s <= %s) class declaration."), cdef->base.type->name, t->name);
} while((t = t->e->parent));
- if(isa(parent, t_object) < 0)
+ if(isa(parent, env->gwion->type[et_object]) < 0)
ERR_B(pos, _("cannot extend primitive type '%s'"), parent->name)
if(parent->e->def && !GET_FLAG(parent, scan1))
CHECK_BB(scanx_parent(parent, scan1_cdef, env))
#include "instr.h"
#include "import.h"
+#include "tuple.h"
ANN static m_bool scan2_stmt(const Env, const Stmt);
ANN static m_bool scan2_stmt_list(const Env, Stmt_List);
ANN m_bool scan2_type_def(const Env env, const Type_Def tdef) {
if(!tdef->type->e->def) return GW_OK;
- return isa(tdef->type, t_fptr) < 0 ? scan2_class_def(env, tdef->type->e->def) : GW_OK;
+ return !is_fptr(env->gwion, tdef->type) ? scan2_class_def(env, tdef->type->e->def) : GW_OK;
}
ANN static inline Value prim_value(const Env env, const Symbol s) {
ANN static m_bool scan2_func_def_overload(const Env env, const Func_Def f, const Value overload) {
const m_bool base = tmpl_base(f->base->tmpl);
const m_bool tmpl = GET_FLAG(overload, template);
- if(isa(overload->type, t_function) < 0 || isa(overload->type, t_fptr) > 0) {
- if(isa(actual_type(overload->type), t_function) < 0)
+ if(isa(overload->type, env->gwion->type[et_function]) < 0 || is_fptr(env->gwion, overload->type)) {
+ if(isa(actual_type(env->gwion, overload->type), env->gwion->type[et_function]) < 0)
ERR_B(f->pos, _("function name '%s' is already used by another value"), overload->name)
}
if((!tmpl && base) || (tmpl && !base && !GET_FLAG(f, template)))
}
ANN static Type func_type(const Env env, const Func func) {
- const Type t = type_copy(env->gwion->mp, func->def->base->td ? t_function : t_lambda);
+ const Type t = type_copy(env->gwion->mp, env->gwion->type[func->def->base->td ? et_function : et_lambda]);
t->name = func->name;
t->e->owner = env->curr;
if(GET_FLAG(func, member))
t->size += SZ_INT;
t->e->d.func = func;
+ if(t->e->tuple)
+ free_tupleform(env->gwion->mp, t->e->tuple);
+ t->e->tuple = NULL;
return t;
}
ANN m_bool scanx_cdef(const Env env, void* opt, const Class_Def cdef,
const _exp_func f_cdef, const _exp_func f_union) {
const Type t = get_type(cdef->base.type);
- if(t->e->parent != t_union)
+ if(t->e->parent != env->gwion->type[et_union])
return f_cdef(opt, t->e->def);
CHECK_BB(template_push_types(env, t->e->def->base.tmpl))
const m_bool ret = f_union(opt, t->e->def->union_def);
if(GET_FLAG(t, ref))
return t;
if(!type->types) {
- if(t != t_tuple)
+ if(t != env->gwion->type[et_tuple])
ERR_O(t->e->def->pos,
_("you must provide template types for type '%s'"), t->name)
return t;
if(a->base.type)
return a->base.type;
a->base.tmpl = mk_tmpl(env, t, t->e->def->base.tmpl, type->types);
- if(t->e->parent != t_union) {
+ if(t->e->parent != env->gwion->type[et_union]) {
CHECK_BO(scan0_class_def(env, a))
nspc_add_type_front(env->curr, a->base.xid, a->base.type);
} else {
} else
return scan_tuple(env, type);
} else if(type->types) { // TODO: clean me
- if(isa(t, t_function) > 0 && t->e->d.func->def->base->tmpl) {
+ if(isa(t, env->gwion->type[et_function]) > 0 && t->e->d.func->def->base->tmpl) {
DECL_OO(const m_str, tl_name, = tl2str(env, type->types))
const Symbol sym = func_symbol(env, t->e->owner->name, t->e->d.func->name, tl_name, 0);
free_mstr(env->gwion->mp, tl_name);
if(GET_FLAG(td, nonnull)) {
if(isa(ret, env->gwion->type[et_void]) > 0)
ERR_O(td_pos(td), _("void types can't be nonnull."))
- if(isa(ret, t_object) < 0 && isa(ret, t_function) < 0)
+ if(isa(ret, env->gwion->type[et_object]) < 0 && isa(ret, env->gwion->type[et_function]) < 0)
return ret;
return type_nonnull(env, ret);
}
ANN Type known_type(const Env env, const Type_Decl* td) {
if(!td->xid)
- return t_undefined;
+ return env->gwion->type[et_undefined];
return type_decl_resolve(env, td) ?:type_unknown(env, td->xid);
}
reg += SZ_INT;
DISPATCH()
pushstr:
- *(M_Object*)reg = new_string2(vm->gwion->mp, shred, (m_str)VAL);
+ *(M_Object*)reg = new_string2(vm->gwion, shred, (m_str)VAL);
reg += SZ_INT;
DISPATCH();
gcini:
#include "gwion.h"
#include "operator.h"
#include "import.h"
+#include "gwi.h"
MFUN(test_mfun){}
GWION_IMPORT(array_test) {
Type t_invalid_var_name;
- CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, t_object)))
+ CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, gwi->gwion->type[et_object])))
CHECK_BB(gwi_class_ini(gwi, t_invalid_var_name, NULL, NULL))
CHECK_BB(gwi_item_ini(gwi, "int[]", "int_array"))
CHECK_BB(gwi_item_end(gwi, 0, NULL)) // import array var
#include "gwion.h"
#include "operator.h"
#include "import.h"
+#include "gwi.h"
MFUN(test_mfun){}
GWION_IMPORT(begin_class) {
Type t_invalid_var_name;
- CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, t_object)))
+ CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, gwi->gwion->type[et_object])))
CHECK_BB(gwi_class_ini(gwi, t_invalid_var_name, NULL, NULL))
CHECK_BB(gwi_class_ini(gwi, t_invalid_var_name, NULL, NULL))
return GW_OK;
#include "operator.h"
#include "import.h"
#include "func.h"
+#include "gwi.h"
struct ret_info {
Instr instr;
CHECK_BB(gwi_fptr_ini(gwi, "Vec4", "PtrType"))
CHECK_OB(gwi_fptr_end(gwi, 0))
- const Type t_callback = gwi_mk_type(gwi, "Callback", SZ_INT, t_object);
+ const Type t_callback = gwi_mk_type(gwi, "Callback", SZ_INT, gwi->gwion->type[et_object]);
CHECK_BB(gwi_class_ini(gwi, t_callback, NULL, NULL))
CHECK_BB(gwi_func_ini(gwi, "int", "callback", cb_func))
CHECK_BB(gwi_func_arg(gwi, "PtrType", "func"))
#include "gwion.h"
#include "operator.h"
#include "import.h"
+#include "gwi.h"
static m_int o_map_key;
static m_int o_map_value;
Type t_class_template;
const m_str list[2] = { "A", "B" };
gwi_tmpl_ini(gwi, 2, list);
- CHECK_OB((t_class_template = gwi_mk_type(gwi, "ClassTemplate", SZ_INT, t_object)))
+ CHECK_OB((t_class_template = gwi_mk_type(gwi, "ClassTemplate", SZ_INT, gwi->gwion->type[et_object])))
CHECK_BB(gwi_class_ini(gwi, t_class_template, class_template_ctor, NULL))
gwi_tmpl_end(gwi);
CHECK_BB(gwi_item_ini(gwi, "A[]", "key"))
GWION_IMPORT(coverage) {
Type t_coverage;
- CHECK_OB((t_coverage = gwi_mk_type(gwi, "Coverage", SZ_INT, t_object)))
+ CHECK_OB((t_coverage = gwi_mk_type(gwi, "Coverage", SZ_INT, gwi->gwion->type[et_object])))
CHECK_BB(gwi_class_ini(gwi, t_coverage, NULL, NULL))
CHECK_BB(gwi_func_ini(gwi, "int", "i", coverage_int))
CHECK_BB(gwi_func_end(gwi, ae_flag_static))
GWION_IMPORT(global_var_test) {
// ALLOC_PTR(i, m_uint, 1);
- const M_Object obj = new_object(gwi->gwion->mp, NULL, t_string);
+ 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"));
CHECK_BB(gwi_item_ini(gwi,"string", "i"))
CHECK_BB(gwi_item_end(gwi, 0, obj))
#include "gwi.h"
GWION_IMPORT(static_string_test) {
- const M_Object obj = new_object(gwi->gwion->mp, NULL, t_string);
+ 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 static string"));
CHECK_BB(gwi_item_ini(gwi, "string", "self"))
CHECK_BB(gwi_item_end(gwi, ae_flag_global, obj))
#include "operator.h"
#include "import.h"
#include "vararg.h"
+#include "gwi.h"
static MFUN(m_test) {
printf("%p\n", *(M_Object*)MEM(0));
}
GWION_IMPORT(variadic test) {
- const Type t_variadic = gwi_mk_type(gwi, "Variadic", SZ_INT, t_object);
+ const Type t_variadic = gwi_mk_type(gwi, "Variadic", SZ_INT, gwi->gwion->type[et_object]);
CHECK_BB(gwi_class_ini(gwi, t_variadic, NULL, NULL))
CHECK_BB(gwi_func_ini(gwi, "void", "member", m_variadic))
CHECK_BB(gwi_func_arg(gwi, "string", "format"))