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 m_bool is_fptr(const struct Gwion_*, const Type t);
+ANN m_bool is_class(const struct Gwion_*, const Type t);
ANN m_uint get_depth(const Type type);
typedef enum {
const Value v = prim->value;
if(v->from->owner_class)
return emit_symbol_owned(emit, prim);
- if(isa(v->type, emit->gwion->type[et_class]) > 0) {
+ if(is_class(emit->gwion, v->type)) {
regpushi(emit, (m_uint)actual_type(emit->gwion, v->type));
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, emit->gwion->type[et_class]) < 0) {
+ if(!is_class(emit->gwion, v->type)) {
const Instr instr = emit_kind(emit, size, emit_var, dotstatic);
instr->m_val = (m_uint)(v->from->owner->info->class_data + v->from->offset);
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, emit->gwion->type[et_class]) > 0 || GET_FLAG(member->base->type, force)) {
+ if(is_class(emit->gwion, member->t_base) || 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(emit->gwion, member->t_base), member->xid);
- if(isa(member->t_base, emit->gwion->type[et_class]) < 0 && (GET_FLAG(value, member) ||
+ if(!is_class(emit->gwion, member->t_base) && (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))
for(m_uint i = 0; i <= v->from->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, env->gwion->type[et_class]) < 0)
+ if(!is_class(env->gwion, info->lhs->value_ref->type))
CHECK_OO((info->lhs = nspc_lookup_func1(nspc, sym)))
else {
DECL_OO(const Type, t, = nspc_lookup_type1(nspc, info->lhs->def->base->xid))
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, env->gwion->type[et_class]) > 0)
+ if(!v || is_class(env->gwion, v->type))
return GW_OK;
env_err(env, pos,
_("'%s' already declared as variable of type '%s'."), s_name(s), v->type->name);
ANN m_bool is_fptr(const struct Gwion_* gwion, const Type t) {
return isa(actual_type(gwion, t), gwion->type[et_fptr]) > 0;
}
+ANN inline m_bool is_class(const struct Gwion_* gwion, const Type t) {
+ return isa(t, gwion->type[et_class]) > 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;
+ return is_class(gwion, t) ? t->e->d.base_type : t;
}
!(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->from->owner_class)
&& isa(t, gwion->type[et_object]) < 0)
_mp_free(gwion->mp, t->size, a->d.ptr);
- if(isa(t, gwion->type[et_class]) > 0/* || isa(a->type, t_function) > 0*/)
+ if(is_class(gwion, t))
REM_REF(t, gwion)
mp_free(gwion->mp, ValueFrom, a->from);
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))
+// TODO: check me
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]))
+ if(!t || (is_class(env->gwion, td->exp->type) && 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)"), env->gwion->type[et_class]->name, td->exp->type->name);
m_uint 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, env->gwion->type[et_class]) > 0) {
+ if(is_class(env->gwion, decl->type)) {
do {
list->self->value->type = env->gwion->type[et_auto];
} while((list = list->next));
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, env->gwion->type[et_class]) > 0;
+ const m_bool base_static = is_class(env->gwion, member->t_base);
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,