ae_flag flag;
};
-extern Type t_void, t_int, t_bool, t_float, t_dur, t_time, t_now, t_complex, t_polar, t_vec3, t_vec4,
+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;
ANN m_uint get_depth(const Type type);
typedef enum {
- et_void, et_int, et_bool, et_float, et_dur, et_time, et_now, et_complex, et_polar, et_vec3, et_vec4,
+ 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_function, et_fptr, et_varloop, et_vararg, et_lambda, et_class, et_union, et_undefined, et_auto, et_tuple,
MAX_TYPE
return op_emit_bool(emit, &opi);
}
-ANN static m_bool is_special(const Type t) {
- if(isa(t, t_complex) > 0 || isa(t, t_polar) > 0 ||
- isa(t, t_vec3) > 0 || isa(t, t_vec4) > 0 ||
+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)
return GW_OK;
return GW_ERROR;
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(f->value_ref->owner_class) > 0) ||
+ } 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))
push_func_code(emit, f);
const Exp base = member->base;
base->emit_var = 1;
CHECK_BB(emit_exp(emit, base, 0))
- const m_bool is_complex = !strcmp((isa(base->type, t_complex) > 0 ? "re" : "phase") ,
+ const m_bool is_complex = !strcmp((isa(base->type, emit->gwion->type[et_complex]) > 0 ? "re" : "phase") ,
s_name(member->xid));
if(is_complex && exp_self(member)->emit_var)
return GW_OK;
ANN static m_bool emit_exp_dot_special(const Emitter emit, const Exp_Dot* member) {
const Type t = member->t_base;
- if(isa(t, t_complex) > 0 || isa(t, t_polar) > 0)
+ if(isa(t, emit->gwion->type[et_complex]) > 0 || isa(t, emit->gwion->type[et_polar]) > 0)
return emit_complex_member(emit, member);
- else if(isa(t, t_vec3) > 0 || isa(t, t_vec4) > 0)
+ else if(isa(t, emit->gwion->type[et_vec3]) > 0 || isa(t, emit->gwion->type[et_vec4]) > 0)
return emit_VecMember(emit, member);
return emit_vararg(emit, member);
}
emit_add_instr(emit, RegPushImm);
return GW_OK;
}
- if(is_special(member->t_base) > 0)
+ 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) ||
gwion->env->gwion = gwion;
gwion->vm->bbq->si = new_soundinfo(gwion->mp);
gwion->data = new_gwiondata(gwion->mp);
- gwion->type = xmalloc(MAX_TYPE * sizeof(struct Type_));
+ gwion->type = (Type*)xmalloc(MAX_TYPE * sizeof(struct Type_));
pass_default(gwion);
arg->si = gwion->vm->bbq->si;
const m_bool ret = arg_parse(gwion, arg);
#include "operator.h"
#include "import.h"
+#include "gwi.h"
+
#define describe(name, op) \
static INSTR(Complex##name) {\
POP_REG(shred, SZ_COMPLEX); \
polar_def2_r(Div, /, -)
GWION_IMPORT(complex) {
- GWI_BB(gwi_class_ini(gwi, t_complex, NULL, NULL))
+ GWI_BB(gwi_class_ini(gwi, gwi->gwion->type[et_complex], NULL, NULL))
gwi_item_ini(gwi, "float", "re");
GWI_BB(gwi_item_end(gwi, ae_flag_member, NULL))
gwi_item_ini(gwi, "float", "im");
GWI_BB(gwi_item_end(gwi, ae_flag_member, NULL))
GWI_BB(gwi_class_end(gwi))
- GWI_BB(gwi_class_ini(gwi, t_polar, NULL, NULL))
+ GWI_BB(gwi_class_ini(gwi, gwi->gwion->type[et_polar], NULL, NULL))
GWI_BB(gwi_item_ini(gwi, "float", "mod"))
GWI_BB(gwi_item_end(gwi, ae_flag_member, NULL))
GWI_BB(gwi_item_ini(gwi, "float", "phase"))
#include "engine.h"
#include "parser.h"
#include "lang_private.h"
+#include "specialid.h"
static FREEARG(freearg_gack) {
free_vector(((Gwion)gwion)->mp, (Vector)instr->m_val2);
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))
- GWI_OB((t_int = gwi_mk_type(gwi, "int", SZ_INT, NULL)))
- GWI_BB(gwi_add_type(gwi, t_int))
- GWI_OB((t_float = gwi_mk_type(gwi, "float", SZ_FLOAT, NULL)))
- GWI_BB(gwi_add_type(gwi, t_float))
- GWI_OB((t_dur = gwi_mk_type(gwi, "dur", SZ_FLOAT, NULL)))
+ 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);
+ GWI_BB(gwi_set_global_type(gwi, t_float, et_float))
+ const Type t_dur = gwi_mk_type(gwi, "dur", SZ_FLOAT, NULL);
GWI_BB(gwi_add_type(gwi, t_dur))
- GWI_OB((t_time = gwi_mk_type(gwi, "time", SZ_FLOAT, NULL)))
+ const Type t_time = gwi_mk_type(gwi, "time", SZ_FLOAT, NULL);
GWI_BB(gwi_add_type(gwi, t_time))
- GWI_OB((t_now = gwi_mk_type(gwi, "@now", SZ_FLOAT, t_time)))
+ const Type t_now = gwi_mk_type(gwi, "@now", SZ_FLOAT, t_time);
GWI_BB(gwi_add_type(gwi, t_now))
- GWI_OB((t_complex = gwi_mk_type(gwi, "complex", SZ_COMPLEX , NULL)))
- GWI_OB((t_polar = gwi_mk_type(gwi, "polar", SZ_COMPLEX , NULL)))
- GWI_OB((t_vec3 = gwi_mk_type(gwi, "Vec3", SZ_VEC3, NULL)))
- GWI_OB((t_vec4 = gwi_mk_type(gwi, "Vec4", SZ_VEC4, NULL)))
+ struct SpecialId_ spid = { .type=t_now, .exec=RegPushNow, .is_const=1 };
+ gwi_specialid(gwi, "now", &spid);
+ gwi_reserve(gwi, "now");
+ const Type t_complex = gwi_mk_type(gwi, "complex", SZ_COMPLEX , NULL);
+ gwi->gwion->type[et_complex] = t_complex;
+ const Type t_polar = gwi_mk_type(gwi, "polar", SZ_COMPLEX , NULL);
+ gwi->gwion->type[et_polar] = t_polar;
+ const Type t_vec3 = gwi_mk_type(gwi, "Vec3", SZ_VEC3, NULL);
+ gwi->gwion->type[et_vec3] = t_vec3;
+ 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)))
GWI_BB(gwi_class_ini(gwi, t_union, NULL, NULL))
}
static OP_CHECK(opck_eventwait) {
- return t_int;
+ return env->gwion->type[et_int];
}
static INSTR(EventWait) {
gw_out("%p", NULL);
}
-ANN static void print_prim(const Type type, const m_bit* stack) {
- if(isa(type, t_bool) > 0)
+ANN static void print_prim(const Gwion gwion, const Type type, const m_bit* stack) {
+ if(isa(type, gwion->type[et_bool]) > 0)
print_bool(*(m_int*)stack);
- else if(isa(type, t_int) > 0)
+ else if(isa(type, gwion->type[et_int]) > 0)
print_int(*(m_int*)stack);
- else if(isa(type, t_complex) > 0)
+ else if(isa(type, gwion->type[et_complex]) > 0)
print_complex(*(m_complex*)stack);
- else if(isa(type, t_polar) > 0)
+ else if(isa(type, gwion->type[et_polar]) > 0)
print_polar(*(m_complex*)stack);
- else if(isa(type, t_vec3) > 0)
+ else if(isa(type, gwion->type[et_vec3]) > 0)
print_vec(stack, 3);
- else if(isa(type, t_vec4) > 0)
+ else if(isa(type, gwion->type[et_vec4]) > 0)
print_vec(stack, 4);
else
print_float(*(m_float*)stack);
else if(isa(type, gwion->type[et_void]) > 0)
print_string1("void");
else
- print_prim(type, (reg-offset));
+ print_prim(gwion, type, (reg-offset));
offset -= type->size;
}
gw_out("\n");
gwi->gwion->env->class_def->nspc->info->offset =
udef->o + udef->s;
const Type t = udef->xid ? udef->value->type :
- udef->type_xid ? udef->type : t_int;
+ udef->type_xid ? udef->type : gwi->gwion->type[et_int];
free_union_def(gwi->gwion->mp, udef);
gwi->union_data.list = NULL;
gwi->union_data.xid = NULL;
OP_CHECK(opck_unary_meta2) {
const Exp_Unary* unary = (Exp_Unary*)data;
exp_self(unary)->meta = ae_meta_value;
- return t_int;
+ return env->gwion->type[et_int];
}
OP_CHECK(opck_unary) {
GWI_BB(gwi_enum_ini(gwi, "bool"))
GWI_BB(gwi_enum_add(gwi, "false", 0))
GWI_BB(gwi_enum_add(gwi, "true", 1))
- t_bool = gwi_enum_end(gwi);
+ const Type t_bool = gwi_enum_end(gwi);
+ gwi->gwion->type[et_bool] = t_bool;
GWI_BB(gwi_oper_ini(gwi, NULL, "int", "bool"))
GWI_BB(gwi_oper_end(gwi, "!", IntNot))
-// GWI_BB(gwi_item_ini(gwi, "bool", "maybe"))
-// GWI_BB(gwi_item_end(gwi, 0, NULL))
gwi_reserve(gwi, "maybe");
struct SpecialId_ spid = { .type=t_bool, .exec=RegPushMaybe, .is_const=1 };
gwi_specialid(gwi, "maybe", &spid);
gwi_item_end(gwi, ae_flag_const, hour);
gwi_item_ini(gwi, "time", "t_zero");
gwi_item_end(gwi, ae_flag_const, t_zero);
- gwi_item_ini(gwi, "@now", "now");
- gwi_item_end(gwi, ae_flag_const, NULL);
- gwi_reserve(gwi, "now");
- struct SpecialId_ spid = { .type=t_now, .exec=RegPushNow, .is_const=1 };
- gwi_specialid(gwi, "now", &spid);
+// gwi_item_ini(gwi, "@now", "now");
+// gwi_item_end(gwi, ae_flag_const, NULL);
return GW_OK;
}
/*
static OP_CHECK(opck_implicit_i2f) {
struct Implicit* imp = (struct Implicit*)data;
- imp->e->cast_to = t_float;
- return t_float;
+ return imp->e->cast_to = env->gwion->type[et_float];
}
// can't it be just declared?
#include "operator.h"
#include "import.h"
#include "driver.h"
+#include "gwi.h"
INSTR(VecCpy) {
POP_REG(shred, instr->m_val2);
}
GWION_IMPORT(vec3) {
- GWI_BB(gwi_class_ini(gwi, t_vec3, NULL, NULL))
+ GWI_BB(gwi_class_ini(gwi, gwi->gwion->type[et_vec3], NULL, NULL))
vecx_base(gwi);
gwi_func_ini(gwi, "void", "set", vec3_set);
gwi_func_arg(gwi, "float", "x");
}
GWION_IMPORT(vec4) {
- CHECK_BB(gwi_class_ini(gwi, t_vec4, NULL, NULL))
+ CHECK_BB(gwi_class_ini(gwi, gwi->gwion->type[et_vec4], NULL, NULL))
vecx_base(gwi);
gwi_item_ini(gwi, "float", "w");
gwi_item_end(gwi, ae_flag_member, NULL);
return depth;
}
-Type t_int, t_bool, t_float, t_dur, t_time, t_now, t_complex, t_polar, t_vec3, t_vec4,
+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 check_exp_array_subscripts(Env env, Exp exp) {
CHECK_OB(check_exp(env, exp))
- do if(isa(exp->type, t_int) < 0)
+ do if(isa(exp->type, env->gwion->type[et_int]) < 0)
ERR_B(exp->pos, _("incompatible array subscript type '%s' ..."), exp->type->name)
while((exp = exp->next));
return GW_OK;
const Type common = find_common_anc(e->type, type);
if(common)
return GW_OK;
- else if(!(isa(e->type, t_int) > 0 && isa(type, t_float) > 0))
+ else if(!(isa(e->type, env->gwion->type[et_int]) > 0 && isa(type, env->gwion->type[et_float]) > 0))
ERR_B(e->pos, _("array init [...] contains incompatible types ..."))
set_cast(env, type, e);
return GW_OK;
CHECK_OB(check_exp(env, e))
do {
const Type t = e->type;
- if(isa(t, t_float) < 0) {
- if(isa(t, t_int) > 0)
- set_cast(env, t_float, e);
+ if(isa(t, env->gwion->type[et_float]) < 0) {
+ if(isa(t, env->gwion->type[et_int]) > 0)
+ set_cast(env, env->gwion->type[et_float], e);
else
ERR_B(e->pos, _("invalid type '%s' in %s value #%d...\n"
" (must be of type 'int' or 'float')"), t->name, s, count)
m_uint n;
};
-ANN static void vec_info(const ae_prim_t t, struct VecInfo* v) {
+ANN static void vec_info(const Env env, const ae_prim_t t, struct VecInfo* v) {
if(t == ae_primary_complex) {
v->s = "complex";
- v->t = t_complex;
+ v->t = env->gwion->type[et_complex];
v->n = 2;
} else if(t == ae_primary_vec) {
- v->t = v->n == 4 ? t_vec4 : t_vec3;
+ v->t = env->gwion->type[v->n == 4 ? et_vec4 : et_vec3];
v->n = 4;
v->s = "vector";
} else {
v->s = "polar";
- v->t = t_polar;
+ v->t = env->gwion->type[et_polar];
v->n = 2;
}
}
const Vec * vec = &primary->d.vec;
const ae_prim_t t = primary->primary_type;
struct VecInfo info = { .n=vec->dim };
- vec_info(t, &info);
+ vec_info(env, t, &info);
if(vec->dim > info.n)
ERR_O(vec->exp->pos, _("extraneous component of %s value..."), info.s)
CHECK_BO(vec_value(env, vec->exp, info.s))
ANN static Type prim_##name(const Env env NUSED, const Exp_Primary * primary NUSED) {\
return type; \
}
-describe_prim_xxx(num, t_int)
-describe_prim_xxx(float, t_float)
+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)
}
static inline m_bool index_is_int(const Env env, Exp e, m_uint *depth) {
- do if(isa(e->type, t_int) < 0)
+ do if(isa(e->type, env->gwion->type[et_int]) < 0)
ERR_B(e->pos, _("array index %i must be of type 'int', not '%s'"),
*depth, e->type->name)
while(++(*depth) && (e = e->next));
if(e->next)
ERR_B(e->pos, _("conditional must be a single expression"))
const Type t = e->type;
- if(isa(t, t_int) > 0)
+ if(isa(t, env->gwion->type[et_int]) > 0)
return GW_OK;
- if(isa(t, t_float) > 0) {
- e->cast_to = t_int;
+ if(isa(t, env->gwion->type[et_float]) > 0) {
+ e->cast_to = env->gwion->type[et_int];
e->nspc = env->curr;
return GW_OK;
}
s_name(edef->xid), v->type->name)
CHECK_BB(scan0_defined(env, edef->xid, edef->pos))
}
- const Type t = type_copy(env->gwion->mp, t_int);
+ const Type t = type_copy(env->gwion->mp, env->gwion->type[et_int]);
t->xid = ++env->scope->type_xid;
t->name = edef->xid ? s_name(edef->xid) : "int";
- t->e->parent = t_int;
+ t->e->parent = env->gwion->type[et_int];
const Nspc nspc = GET_FLAG(edef, global) ? env->global_nspc : env->curr;
t->e->owner = nspc;
edef->t = t;
add_type(env, nspc, t);
mk_class(env, t);
}
- scan0_implicit_similar(env, t_int, t);
+ scan0_implicit_similar(env, env->gwion->type[et_int], t);
return GW_OK;
}
#include "oo.h"
#include "vm.h"
#include "env.h"
+#include "type.h"
#include "gwion.h"
#include "operator.h"
#include "object.h"
#include "import.h"
#include "emit.h"
#include "specialid.h"
+#include "gwi.h"
static ID_EMIT(spidem) {
}
GWION_IMPORT(spid_test) {
- struct SpecialId_ spid = { .type=t_int, .em=spidem, .is_const = 1 };
+ struct SpecialId_ spid = { .type=gwi->gwion->type[et_int], .em=spidem, .is_const = 1 };
gwi_specialid(gwi, "testid", &spid);
return GW_OK;
}