-Subproject commit 260f256586cbd65f0e5c74484dbe71d26b6db62e
+Subproject commit 11f86a1a1aad81ff6dba21605398007898e2fb3f
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 bool is_func(const struct Gwion_ *, const Type t);
+ANN bool is_fptr(const struct Gwion_ *, const Type t);
+ANN bool is_class(const struct Gwion_ *, const Type t);
ANN __attribute__((returns_nonnull)) static inline Type _class_base(Type t) {
return t->info->base_type;
}
// emit_exp_addref(emit, exp_call->args, -exp_totalsize(exp_call->args));
}
const Type t = actual_type(emit->gwion, exp_call->func->type);
- if (isa(t, emit->gwion->type[et_function]) > 0 &&
+ if (is_func(emit->gwion, t) &&
fbflag(t->info->func->def->base, fbflag_variadic))
emit_func_arg_vararg(emit, exp_call);
return GW_OK;
ANN static inline Func is_inlinable(const Emitter emit,
const Exp_Call *exp_call) {
const Type ftype = exp_call->func->type;
- if (isa(ftype, emit->gwion->type[et_function]) < 0 ||
+ if (!is_func(emit->gwion, ftype)||
is_fptr(emit->gwion, ftype) || !ftype->info->func->code ||
ftype->info->func->code->builtin)
return false;
CHECK_BB(prepare_call(emit, exp_call));
else
CHECK_BB(emit_func_args(emit, exp_call));
- if (isa(t, emit->gwion->type[et_function]) > 0)
+ if (is_func(emit->gwion, t))
CHECK_BB(emit_exp_call1(emit, t->info->func,
is_static_call(emit, exp_call->func)));
else {
regpop(emit, exp_self(exp_call)->type->size);
const Instr instr = emit_add_instr(emit, Reg2RegAddr);
instr->m_val = -SZ_INT;
- } else if (isa(exp_call->func->type, emit->gwion->type[et_function]) < 0 &&
+ } else if (!is_func(emit->gwion, exp_call->func->type) &&
tflag(e->type, tflag_struct))
regpop(emit, SZ_INT);
return GW_OK;
return depth;
}
-ANN m_bool is_fptr(const struct Gwion_ *gwion, const Type t) {
+ANN bool is_func(const struct Gwion_ *gwion, const Type t) {
+ return isa(actual_type(gwion, t), gwion->type[et_function]) > 0;
+}
+ANN 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) {
+ANN inline bool is_class(const struct Gwion_ *gwion, const Type t) {
return isa(t, gwion->type[et_class]) > 0;
}
if (!is_class(env->gwion, info->lhs->value_ref->type)) {
if (!(info->lhs = nspc_lookup_func1(nspc, sym))) {
const Value v = nspc_lookup_value1(nspc, insert_symbol(c));
- if (isa(v->type, env->gwion->type[et_function]) < 0) return NULL;
+ if (!is_func(env->gwion, v->type)) return NULL;
info->lhs = v->type->info->func;
}
} else {
const Value value = get_value(env, member, the_base);
if (!value) {
const Value v = nspc_lookup_value1(env->curr, member->xid);
- if (v && isa(v->type, env->gwion->type[et_function]) > 0) return v->type;
+ if (v && is_func(env->gwion, v->type)) return v->type;
env_err(env, exp_self(member)->pos, _("class '%s' has no member '%s'"),
the_base->name, str);
if (member->base->type->nspc) did_you_mean_type(the_base, str);
}
if (!is_class(emit->gwion, member->base->type) &&
(vflag(value, vflag_member) ||
- (isa(exp_self(member)->type, emit->gwion->type[et_function]) > 0 &&
+ (is_func(emit->gwion, exp_self(member)->type) &&
!is_fptr(emit->gwion, exp_self(member)->type)))) {
if (!tflag(t_base, tflag_struct) && vflag(value, vflag_member))
CHECK_BB(emit_exp(emit, member->base));
}
- if (isa(exp_self(member)->type, emit->gwion->type[et_function]) > 0 &&
+ if (is_func(emit->gwion, exp_self(member)->type) &&
!is_fptr(emit->gwion, exp_self(member)->type))
emit_member_func(emit, member);
else if (vflag(value, vflag_member)) {
const Exp_Dot *member = (Exp_Dot *)data;
const Map map = &member->base->type->nspc->info->value->map;
CHECK_BB(emit_exp(emit, member->base));
- if (isa(exp_self(member)->type, emit->gwion->type[et_function]) > 0) {
+ if (is_func(emit->gwion, exp_self(member)->type)) {
const Instr instr = emit_add_instr(emit, RegPushImm);
const Func f =
(Func)vector_front(&member->base->type->info->parent->nspc->vtable);
ANN Func ufcs(const Env env, const Func up, Exp_Call *const call) {
const Value v = nspc_lookup_value1(env->curr, up->def->base->xid);
- if (v && isa(v->type, env->gwion->type[et_function]) > 0 &&
- !vflag(v, vflag_member))
+ if (v && is_func(env->gwion, v->type) && !vflag(v, vflag_member))
return call2ufcs(env, call, v);
return NULL;
}
ERR_B(exp->func->pos, _("Can't call late function pointer at declaration "
"site. did you meant to use `@=>`?"))
const Type t = actual_type(env->gwion, exp->func->type);
- if (isa(t, env->gwion->type[et_function]) > 0 &&
+ if (is_func(env->gwion , t) &&
exp->func->exp_type == ae_exp_dot && !t->info->value->from->owner_class) {
if (exp->args) CHECK_OB(check_exp(env, exp->args));
return call2ufcs(env, exp, t->info->func->value_ref) ? GW_OK : GW_ERROR;
DECL_BO(const m_bool, ret, = func_check(env, exp));
if (!ret) return exp_self(exp)->type;
const Type t = actual_type(env->gwion, exp->func->type);
- if (isa(t, env->gwion->type[et_function]) < 0) { // use func flag?
+ if (!is_func(env->gwion, t)) { // use func flag?
struct Op_Import opi = {.op = insert_symbol("@ctor"),
.rhs = actual_type(env->gwion, exp->func->type),
.data = (uintptr_t)exp,
DECL_BO(const m_bool, ret, = func_check(env, exp));
if (!ret) return exp_self(exp)->type;
const Type t = actual_type(env->gwion, exp->func->type);
- if (isa(t, env->gwion->type[et_function]) < 0)
+ if (!is_func(env->gwion, t))
return check_exp_call1(env, exp);
if (exp->args) CHECK_OO(check_exp(env, exp->args));
if (!t->info->func->def->base->tmpl)
ANN static Type check_exp_td(const Env env, Type_Decl **td) {
DECL_OO(const Type, t, = known_type(env, *td));
- if (isa(t, env->gwion->type[et_function]) > 0 && !is_fptr(env->gwion, t))
+ if (is_func(env->gwion, t) && !is_fptr(env->gwion, t))
return type_class(env->gwion, t);
return t;
}
do {
CHECK_OO((curr->type = check_exp_func[curr->exp_type](env, &curr->d)));
if (env->func && isa(curr->type, env->gwion->type[et_lambda]) < 0 &&
- isa(curr->type, env->gwion->type[et_function]) > 0 &&
+ is_func(env->gwion, curr->type) &&
!safe_fflag(curr->type->info->func, fflag_pure))
unset_fflag(env->func, fflag_pure);
} while ((curr = curr->next));
if (!env->curr->vtable.ptr) vector_init(&env->curr->vtable);
if (parent) {
const Value v = find_value(parent, fdef->base->xid);
- if (v && isa(v->type, env->gwion->type[et_function]) > 0) {
+ if (v && is_func(env->gwion, v->type)) {
const m_bool match = parent_match_actual(env, fdef, v->d.func_ref);
if (match) return match;
}
const Value override =
find_value(env->class_def->info->parent, fdef->base->xid);
if (override && override->from->owner_class &&
- isa(override->type, env->gwion->type[et_function]) < 0)
+ !is_func(env->gwion, override->type))
ERR_B(fdef->base->pos,
_("function name '%s' conflicts with previously defined value...\n"
" from super class '%s'..."),
const Func_Def request) {
const Value v = nspc_lookup_value0(t->nspc, request->base->xid);
if (v) {
- if (isa(v->type, env->gwion->type[et_function]) < 0 ||
+ if (!is_func(env->gwion, v->type) ||
is_fptr(env->gwion, v->type)) {
gwerr_basic("is not a function", NULL, NULL, v->from->filename,
v->from->loc, 0);
context_global(env);
env_push_global(env);
}
- if (isa(base, env->gwion->type[et_function]) < 0) {
+ if (!is_func(env->gwion, base)) {
if (!tdef->ext->types && (!tdef->ext->array || !tdef->ext->array->exp))
typedef_simple(env, tdef, base);
else
const Func_Def fdef) {
const Value v = nspc_lookup_value1(env->curr, fdef->base->xid);
if (!v) return GW_OK;
- if (isa(actual_type(env->gwion, v->type), env->gwion->type[et_function]) > 0)
+ if (is_func(env->gwion, actual_type(env->gwion, v->type)))
return GW_OK;
if ((!env->class_def || !GET_FLAG(env->class_def, final)) &&
!nspc_lookup_value0(env->curr, fdef->base->xid))
ANN static m_bool scan2_func_def_overload(const Env env, const Func_Def f,
const Value overload) {
const m_bool fptr = is_fptr(env->gwion, overload->type);
- if (isa(overload->type, env->gwion->type[et_function]) < 0 ||
+ if (!is_func(env->gwion, overload->type) ||
is_fptr(env->gwion, overload->type)) {
if (!fbflag(f->base, fbflag_internal))
ERR_B(f->base->pos,
}
static ANN Type maybe_func(const Env env, const Type t, const Type_Decl *td) {
- if (isa(t, env->gwion->type[et_function]) > 0 &&
+ if (is_func(env->gwion, t) &&
t->info->func->def->base->tmpl)
return scan_func(env, t, td);
ERR_O(td->pos,
}
ANN Type _scan_type(const Env env, const Type t, Type_Decl *td) {
- if (tflag(t, tflag_tmpl) && isa(t, env->gwion->type[et_function]) < 0) {
+ if (tflag(t, tflag_tmpl) && !is_func(env->gwion, t)) {
if (tflag(t, tflag_ntmpl) && !td->types) return t;
struct TemplateScan ts = {.t = t, .td = td};
Type_List tl = td->types;