-Subproject commit 23c2894a2dd6b0f0b3531f7995a3395020fc45bb
+Subproject commit 1c3afd609f38c79cdfa58346c8dbc6112bedcca4
-Subproject commit 379c80d6914e8e204739d49f97c45cfe386b749f
+Subproject commit a1d3a1680d6f680199f6793f599629847a8f9759
ANN Type check_array_access(const Env env, const Array_Sub array);
ANN m_bool emit_array_access(const Emitter emit,
struct ArrayAccessInfo *const info);
-ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, const Exp args);
+ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, Exp* args);
#endif
ANN static void clean_exp_if(Clean *a, Exp_If *b);
ANN static void clean_exp_dot(Clean *a, Exp_Dot *b);
ANN static void clean_exp_lambda(Clean *a, Exp_Lambda *b);
-ANN static void clean_exp(Clean *a, Exp b);
+ANN static void clean_exp(Clean *a, Exp* b);
ANN static void clean_stmt_exp(Clean *a, Stmt_Exp b);
ANN static void clean_stmt_for(Clean *a, Stmt_For b);
ANN static void clean_stmt_each(Clean *a, Stmt_Each b);
#ifndef __CONSTANT
#define __CONSTANT
-ANN m_bool constant_int(const Exp e);
-ANN m_bool constant_float(const Exp e);
+ANN m_bool constant_int(Exp* e);
+ANN m_bool constant_float(Exp* e);
#endif
Instr emit_add_instr(const Emitter, const f_instr)
__attribute__((returns_nonnull));
ANN Code * emit_class_code(const Emitter, const m_str);
-ANN m_bool emit_array_extend(const Emitter, const Type, const Exp);
+ANN m_bool emit_array_extend(const Emitter, const Type, Exp*);
ANN void emit_class_finish(const Emitter, const Nspc);
ANN2(1, 2)
m_bool emit_instantiate_object(const Emitter, const Type, const Array_Sub,
ANN m_uint emit_local(const Emitter emit, const Type t);
ANN m_uint emit_localn(const Emitter emit, const Type t);
ANN void* emit_localx(const Emitter emit, const Type t);
-ANN m_uint emit_local_exp(const Emitter emit, const Exp);
+ANN m_uint emit_local_exp(const Emitter emit, Exp*);
ANN m_bool emit_exp_spork(const Emitter, const Exp_Unary *);
-ANN m_bool emit_exp(const Emitter, const Exp);
+ANN m_bool emit_exp(const Emitter, Exp*);
ANN void emit_object_addref(const Emitter emit, const m_int size,
const bool emit_var);
union {
ID_List tmpl;
Specialized_List sl;
- Exp exp;
+ Exp* exp;
};
union {
Symbol xid; // union name
ANN void gwi_body(const Gwi, const Section*);
-ANN Exp make_exp(const Gwi gwi, const m_str type, const m_str name);
+ANN Exp* make_exp(const Gwi gwi, const m_str type, const m_str name);
ANN void gwi_reset(const Gwi gwi);
ANN VM * gwi_vm(const Gwi);
typedef Instr (*f_looper)(const Emitter, const Looper *);
struct Looper {
- const Exp exp;
+ Exp* exp;
Stmt *const stmt;
/*const */ m_uint offset;
const m_uint n;
struct Vector_ vec;
};
-ANN static inline void match_map(struct Match_ *const match, Exp e) {
+ANN static inline void match_map(struct Match_ *const match, Exp* e) {
const Vector cond = &match->cond;
vector_init(cond);
- Exp next;
+ Exp* next;
do {
next = e->next;
e->next = NULL;
const Vector cond = &match->cond;
const vtype sz = vector_size(cond);
for (m_uint i = 0; i < sz - 1; ++i) {
- const Exp e = (Exp)vector_at(cond, i), next = (Exp)vector_at(cond, i + 1);
+ Exp* e = (Exp*)vector_at(cond, i);
+ Exp* next = (Exp*)vector_at(cond, i + 1);
e->next = next;
}
vector_release(cond);
};
struct Implicit {
- Exp e;
+ Exp* e;
Type t;
loc_t loc;
};
*(uintptr_t *)opi->ret = opi->data;
}
-ANN static inline void set_decl_ref(const Exp e) {
+ANN static inline void set_decl_ref(Exp* e) {
if (e->exp_type == ae_exp_decl)
SET_FLAG(e->d.exp_decl.var.vd.value, late);
}
#define HANDLE_EXP_FUNC(prefix, type, Arg) \
DECL_EXP_FUNC(prefix, type, Arg) \
- ANN type prefix##_exp(const Arg arg, Exp exp) { \
+ ANN type prefix##_exp(const Arg arg, Exp* exp) { \
do CHECK_BB(prefix##_exp_func[exp->exp_type](arg, &exp->d)); \
while ((exp = exp->next)); \
return GW_OK; \
}
-ANN m_bool scan1_exp(const Env, Exp);
-ANN m_bool scan2_exp(const Env, Exp);
+ANN m_bool scan1_exp(const Env, Exp*);
+ANN m_bool scan2_exp(const Env, Exp*);
#define describe_stmt_func(prefix, name, type, prolog, exp) \
ANN static m_bool prefix##_stmt_##name(const Env env, const type stmt) { \
scanx_fdef(const Env, void *, const Func_Def, const _exp_func);
ANN m_bool check_subscripts(const Env, const Array_Sub, const m_bool is_decl);
-ANN m_bool check_implicit(const Env env, const Exp e, const Type t);
+ANN m_bool check_implicit(const Env env, Exp* e, const Type t);
ANN m_bool ensure_traverse(const Env env, const Type t);
ANN m_bool check_traverse_fdef(const Env env, const Func_Def fdef);
if (env->func) env->func->inline_mult += mult;
}
-ANN static inline bool is_hole(const Env env, const Exp exp) {
+ANN static inline bool is_hole(const Env env, Exp* exp) {
const Symbol hole = insert_symbol("_");
if (exp->exp_type == ae_exp_primary) {
if (exp->d.prim.prim_type == ae_prim_id) {
return false;
}
-static inline bool exp_is_zero(const Exp exp) {
+static inline bool exp_is_zero(Exp* exp) {
return exp->exp_type == ae_exp_primary &&
exp->d.prim.prim_type == ae_prim_num &&
!exp->d.prim.d.gwint.num;
ANN m_bool abstract_array(const Env env, const Array_Sub array);
-ANN static inline bool is_static_call(const Gwion gwion, const Exp e) {
+ANN static inline bool is_static_call(const Gwion gwion, Exp* e) {
if (e->exp_type != ae_exp_dot) return true;
const Exp_Dot *member = &e->d.exp_dot;
if(unlikely(!strcmp(s_name(member->xid), "new"))) return true;
ANN Type partial_type(const Env, Exp_Call *const);
ANN void print_signature(const Func f);
-ANN static inline bool func_match_inner(const Env env, const Exp e,
+ANN static inline bool func_match_inner(const Env env, Exp* e,
const Type t, const bool implicit,
const bool specific) {
if (specific ? e->type == t : isa(e->type, t) > 0) // match
return !implicit ? false : check_implicit(env, e, t) > 0;
}
-ANN static inline bool is_typed_hole(const Env env, const Exp exp) {
+ANN static inline bool is_typed_hole(const Env env, Exp* exp) {
return exp->exp_type == ae_exp_cast && is_hole(env, exp->d.exp_cast.exp);
}
#endif
ANN m_bool traverse_enum_def(const Env, const Enum_Def);
ANN m_bool traverse_fptr_def(const Env, const Fptr_Def);
ANN m_bool traverse_type_def(const Env env, const Type_Def);
-ANN m_bool traverse_exp(const Env, const Exp);
+ANN m_bool traverse_exp(const Env, Exp*);
ANN m_bool scan0_ast(const Env, Ast*);
ANN m_bool scan1_ast(const Env, Ast*);
ANN m_bool scan2_ast(const Env, Ast*);
ANN m_bool check_ast(const Env, Ast*);
-ANN m_bool scan1_exp(const Env, const Exp);
-ANN m_bool scan2_exp(const Env, const Exp);
-ANN Type check_exp(const Env, const Exp);
+ANN m_bool scan1_exp(const Env, Exp*);
+ANN m_bool scan2_exp(const Env, Exp*);
+ANN Type check_exp(const Env, Exp*);
ANN m_bool scan0_func_def(const Env, const Func_Def);
ANN m_bool scan1_func_def(const Env, const Func_Def);
-Subproject commit a8194c5a7b1b874d1475cb5af245770327605f9b
+Subproject commit 88b079e8a888a883141170147c3c8e792360c8e1
}
DECL_EXP_FUNC(clean, void, Clean *)
-ANN static void clean_exp(Clean *a, Exp b) {
+ANN static void clean_exp(Clean *a, Exp* b) {
clean_exp_func[b->exp_type](a, &b->d);
if (b->next) clean_exp(a, b->next);
}
return _frame_pop(emit);
}
-ANN /*static */ m_bool emit_exp(const Emitter emit, Exp exp);
+ANN /*static */ m_bool emit_exp(const Emitter emit, Exp* exp);
ANN static m_bool emit_stmt_list(const Emitter emit, Stmt_List list);
ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot *member);
return l;
}
-ANN m_uint emit_local_exp(const Emitter emit, const Exp e) {
+ANN m_uint emit_local_exp(const Emitter emit, Exp* e) {
Local *const l = emit_localx(emit, e->type);
if(e->ref) e->ref->data = l;
return l->offset;
}
-ANN m_uint emit_local_exp2(const Emitter emit, const Exp e) {
+ANN m_uint emit_local_exp2(const Emitter emit, Exp* e) {
Local *const l = emit_localx(emit, e->type);
e->data = l;
return l->offset;
ANN2(1, 2)
static ArrayInfo *emit_array_extend_inner(const Emitter emit, const Type t,
- const Exp e, const uint is_ref);
+ Exp* e, const uint is_ref);
ANN static m_bool emit_pre_ctor(const Emitter emit, const Type type) {
if (type->info->parent) {
CHECK_BB(emit_pre_ctor(emit, type->info->parent));
}
ANN2(1)
-static m_bool extend_indices(const Emitter emit, Exp e, const m_uint depth) {
+static m_bool extend_indices(const Emitter emit, Exp* e, const m_uint depth) {
if (e) CHECK_BB(emit_exp(emit, e));
m_uint count = 0;
while (e) {
ANN2(1, 2)
static ArrayInfo *emit_array_extend_inner(const Emitter emit, const Type t,
- const Exp e, const uint is_ref) {
+ Exp* e, const uint is_ref) {
CHECK_BO(extend_indices(emit, e, get_depth(t)));
ArrayInfo * info = new_arrayinfo(emit, t, t->info->cdef->base.tag.loc);
const Instr alloc = emit_add_instr(emit, ArrayAlloc);
return code;
}
-ANN static inline m_uint exp_size(const Exp e) {
+ANN static inline m_uint exp_size(Exp* e) {
if (exp_getvar(e)) return SZ_INT;
const Type type = e->cast_to ?: e->type;
return type->size;
}
ANN2(1)
-static void emit_exp_addref1(const Emitter emit, const Exp exp, m_int size) {
+static void emit_exp_addref1(const Emitter emit, Exp* exp, m_int size) {
const Type t = exp->cast_to ?: exp->type;
if (tflag(t, tflag_compound))
emit_compound_addref(emit, exp->type, size, exp_getvar(exp));
}
/*ANN2(1)
-static void emit_exp_addref(const Emitter emit, Exp exp,
+static void emit_exp_addref(const Emitter emit, Exp* exp,
m_int size) {
do {
emit_exp_addref1(emit, exp, size);
} while ((exp = exp->next));
}*/
-ANN static inline m_bool emit_exp1(const Emitter emit, const Exp e) {
- const Exp next = e->next;
+ANN static inline m_bool emit_exp1(const Emitter emit, Exp* e) {
+ Exp* next = e->next;
e->next = NULL;
const m_bool ret = emit_exp(emit, e);
e->next = next;
return ret;
}
-ANN static m_bool emit_prim_array_exp(const Emitter emit, const Type t, Exp e) {
+ANN static m_bool emit_prim_array_exp(const Emitter emit, const Type t, Exp* e) {
do {
CHECK_BB(emit_exp1(emit, e));
emit_exp_addref1(emit, e, -t->size);
}
ANN static m_bool emit_prim_array(const Emitter emit, const Array_Sub *data) {
- Exp e = (*data)->exp;
+ Exp* e = (*data)->exp;
const Type type = (*data)->type;
const Type base = array_base_simple(type);
if(!base->actual_size) CHECK_BB(emit_exp(emit, e));
return GW_OK;
}
-ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp e);
+ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp* e);
ANN static m_bool emit_range(const Emitter emit, Range *range) {
if (range->start)
ANN static m_bool emit_prim_range(const Emitter emit, Range **data) {
Range *range = *data;
CHECK_BB(emit_range(emit, range));
- const Exp e = range->start ?: range->end;
+ Exp* e = range->start ?: range->end;
const Symbol sym = insert_symbol("[:]");
assert(e);
struct Op_Import opi = {.op = sym,
return x == 1 ? 2 : 1<<(64-__builtin_clzl(x));
}
-ANN static m_bool emit_prim_dict(const Emitter emit, Exp *data) {
- Exp e = *data;
+ANN static m_bool emit_prim_dict(const Emitter emit, Exp* *data) {
+ Exp* e = *data;
const Type key = e->type;
const Type val = e->next->type;
const Type t = dict_type(emit->gwion, key, val, e->loc);
const Instr init = emit_add_instr(emit, dict_ctor_alt);
- const Exp next = e->next;
+ Exp* next = e->next;
e->next = NULL;
- struct Exp_ func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }};
- struct Exp_ call = { .exp_type = ae_exp_call, .d = { .exp_call = { .func = &func, .args = e}}};
+ Exp func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }};
+ Exp call = { .exp_type = ae_exp_call, .d = { .exp_call = { .func = &func, .args = e}}};
CHECK_BB(traverse_exp(emit->env, &call));
e->next = next;
m_uint count = 0;
do {
- const Exp next = e->next;
- const Exp nnext = next->next;
+ Exp* next = e->next;
+ Exp* nnext = next->next;
next->next = NULL;
e->next = NULL;
CHECK_BB(emit_exp(emit, e));
}
ANN static m_bool emit_exp_array(const Emitter emit, const Exp_Array *array) {
- const Exp e = exp_self(array);
+ Exp* e = exp_self(array);
exp_setvar(array->base, get_emit_var(emit, array->base->type, exp_getvar(e)));
CHECK_BB(emit_exp(emit, array->base));
struct ArrayAccessInfo info = {
CHECK_BB(emit_exp(emit, range->base));
CHECK_BB(emit_range(emit, range->range));
const Symbol sym = insert_symbol("[:]");
- const Exp e = range->range->start ?: range->range->end;
+ Exp* e = range->range->start ?: range->range->end;
assert(e);
struct Op_Import opi = {.op = sym,
.lhs = e->type,
#define emit_prim_nil (void *)dummy_func
-ANN static inline void interp_size(const Emitter emit, const Exp e) {
+ANN static inline void interp_size(const Emitter emit, Exp* e) {
const Type t = !tflag(e->type, tflag_ref) || safe_tflag(e->cast_to, tflag_ref) ?
e->type : (Type)vector_front(&e->type->info->tuple->contains);
emit_regsetimm(emit, t->size, SZ_INT);
}
-ANN static void emit_gack_type(const Emitter emit, const Exp e) {
+ANN static void emit_gack_type(const Emitter emit, Exp* e) {
if (e->exp_type == ae_exp_cast ||
(e->exp_type == ae_exp_primary && e->d.prim.prim_type == ae_prim_str))
return;
emit_add_instr(emit, GackType);
}
-ANN /*static*/ m_bool emit_interp(const Emitter emit, const Exp exp) {
+ANN /*static*/ m_bool emit_interp(const Emitter emit, Exp* exp) {
emit_pushimm(emit, 0);
//emit_local(emit, emit->gwion->type[et_int]);
- Exp e = exp, next = NULL;
+ Exp* e = exp;
+ Exp* next = NULL;
do {
next = e->next;
e->next = NULL;
return GW_OK;
}
-ANN static m_bool emit_prim_hack(const Emitter emit, const Exp *exp) {
+ANN static m_bool emit_prim_hack(const Emitter emit, Exp* *exp) {
CHECK_BB(emit_interp(emit, *exp));
if (!(emit->env->func &&
emit->env->func->def->base->tag.sym == insert_symbol("@gack")))
return GW_OK;
}
-ANN static m_bool emit_prim_interp(const Emitter emit, const Exp *exp) {
- const Exp e = *exp;
+ANN static m_bool emit_prim_interp(const Emitter emit, Exp* *exp) {
+ Exp* e = *exp;
CHECK_BB(emit_interp(emit, e));
const Instr instr = emit_add_instr(emit, GackEnd);
instr->m_val = 1;
// see take exp
-Exp nth_exp(Exp e, uint32_t n) {
+Exp* nth_exp(Exp* e, uint32_t n) {
for(uint32_t i = 0; i < n; i++)
e = e->next;
return e;
}
}
-ANN static inline void pop_exp(const Emitter emit, Exp e);
+ANN static inline void pop_exp(const Emitter emit, Exp* e);
ANN static inline void scoped_ini(const Emitter emit) {
++emit->env->scope->depth;
return f->weight < threshold;
}
-ANN static inline bool member_inlinable(const Emitter emit, const Func f, const Exp e) {
+ANN static inline bool member_inlinable(const Emitter emit, const Func f, Exp* e) {
if (f!= emit->env->func)return false;
const Type owner_class = f->value_ref->from->owner_class;
if (!owner_class) return true;
}
ANN static m_bool emit_new_struct(const Emitter emit,const Exp_Call *call) {
- const Exp self = exp_self(call);
+ Exp* self = exp_self(call);
const Type t = self->type;
const m_int offset = self->ref ? emit->code->frame->curr_offset - t->size: emit_local(emit, t);
const Instr back = self->ref ? (Instr)vector_pop(&emit->code->instr) : NULL;
ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call *exp_call) {
CHECK_BB(_emit_exp_call(emit, exp_call));
- const Exp e = exp_self(exp_call);
+ Exp* e = exp_self(exp_call);
if (exp_getvar(e)) {
const m_uint size = e->type->size;
emit_regmove(emit, -size);
return GW_OK;
}
-ANN static m_uint get_type_size(const Exp e) {
+ANN static m_uint get_type_size(Exp* e) {
if(tflag(e->type, tflag_ref)&& !safe_tflag(e->cast_to, tflag_ref)) {
const Type base =(Type)vector_front(&e->type->info->tuple->contains);
return base->size;
return e->type->size;
}
-ANN static m_uint pop_exp_size(Exp e) {
+ANN static m_uint pop_exp_size(Exp* e) {
const bool emit_addr = exp_getvar(e);
m_uint size = 0;
do size += !emit_addr ? get_type_size(e) : SZ_INT;
return size;
}
-ANN static inline void pop_exp(const Emitter emit, Exp e) {
+ANN static inline void pop_exp(const Emitter emit, Exp* e) {
const m_uint size = pop_exp_size(e);
if (size) emit_regmove(emit, -size);
}
-ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp e) {
+ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp* e) {
CHECK_BB(emit_exp(emit, e));
if (e->next) pop_exp(emit, e->next);
return GW_OK;
}
ANN static m_bool emit_exp_binary(const Emitter emit, const Exp_Binary *bin) {
- const Exp lhs = bin->lhs;
- const Exp rhs = bin->rhs;
+ Exp* lhs = bin->lhs;
+ Exp* rhs = bin->rhs;
CHECK_BB(emit_exp_pop_next(emit, lhs));
CHECK_BB(emit_exp_pop_next(emit, rhs));
struct Op_Import opi = {.op = bin->op,
static m_bool me_cmp(MemoizeEmitter *me, const Arg *arg) {
const Emitter emit = me->emit;
const Symbol sym = insert_symbol("?=");
- struct Exp_ lhs = {
+ Exp lhs = {
.exp_type = ae_exp_primary,
.type = arg->type,
.loc = arg->var.td->tag.loc,
.prim = { .prim_type = ae_prim_id }
}
};
- struct Exp_ rhs = {
+ Exp rhs = {
.exp_type = ae_exp_primary,
.type = me->emit->gwion->type[et_bool],
.loc = arg->var.td->tag.loc,
.prim = { .prim_type = ae_prim_id }
}
};
- struct Exp_ bin = {
+ Exp bin = {
.exp_type = ae_exp_binary,
.type = arg->type,
.loc = arg->var.td->tag.loc,
struct Sporker {
const Stmt_List code;
- const Exp exp;
+ Exp* exp;
VM_Code vm_code;
const Type type;
const Capture_List captures;
// uint32_t offset = 0;
m_uint offset = 0;
if(emit->env->class_def && sporker.code) {
- struct Exp_ exp = {
+ Exp exp = {
.d = { .prim = {
.d = { .var = insert_symbol("this") },
.prim_type = ae_prim_id
for (uint32_t i = 0; i < caps->len; i++) {
Capture *cap = mp_vector_at(caps, Capture, i);
const Value v = cap->var.value;
- struct Exp_ exp = {
+ Exp exp = {
.d = { .prim = {
.d = { .var = cap->var.tag.sym },
.value = v,
return op_emit(emit, &opi);
}
-ANN static m_bool emit_implicit_cast(const Emitter emit,
- const restrict Exp from,
- const restrict Type to) {
+ANN static m_bool emit_implicit_cast(const Emitter emit,
+ Exp* from, const Type to) {
const struct Implicit imp = { .e=from, .t=to, . loc = from->loc};
// no pos
struct Op_Import opi = {.op = insert_symbol("@implicit"),
return op_emit(emit, &opi);
}
-ANN2(1,2) static Instr _flow(const Emitter emit, const Exp e, Instr *const instr, /*const */bool b) {
+ANN2(1,2) static Instr _flow(const Emitter emit, Exp* e, Instr *const instr, /*const */bool b) {
CHECK_BO(emit_exp_pop_next(emit, e));
{
const Instr ex = (Instr)vector_back(&emit->code->instr);
}
ANN static m_bool emit_exp_if(const Emitter emit, const Exp_If *exp_if) {
- const Exp e = exp_if->if_exp ?: exp_if->cond;
+ Exp* e = exp_if->if_exp ?: exp_if->cond;
Instr instr;
struct M_Vector_ v = {};
const m_uint reg = emit_local(emit, emit->gwion->type[et_bool]);
DECL_EXP_FUNC(emit, m_bool, Emitter)
-ANN2(1) /*static */ m_bool emit_exp(const Emitter emit, /* const */ Exp e) {
- Exp exp = e;
+ANN2(1) /*static */ m_bool emit_exp(const Emitter emit, /* const */ Exp* e) {
+ Exp* exp = e;
do {
if (emit->info->debug && emit->status.line < e->loc.first.line) {
const Instr instr = emit_add_instr(emit, DebugLine);
return exp->val ? emit_exp(emit, exp->val) : GW_OK;
}
-ANN static m_bool emit_case_head(const Emitter emit, const Exp base,
- const Exp e, const Symbol op, const Vector v) {
+ANN static m_bool emit_case_head(const Emitter emit, Exp* base,
+ Exp* e, const Symbol op, const Vector v) {
CHECK_BB(emit_exp1(emit, base));
CHECK_BB(emit_exp1(emit, e));
const Exp_Binary bin = {.lhs = base, .rhs = e, .op = op};
- struct Exp_ ebin = { .d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc };
+ Exp ebin = { .d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc };
struct Op_Import opi = {.op = op,
.lhs = base->type,
.rhs = e->type,
return GW_OK;
}
-ANN static m_bool case_value(const Emitter emit, const Exp base, const Exp e) {
+ANN static m_bool case_value(const Emitter emit, Exp* base, Exp* e) {
const Value v = e->d.prim.value;
v->from->offset = emit_local(emit, base->type);
emit_regtomem4(emit, v->from->offset, base->type->size);
return GW_OK;
}
-ANN Symbol case_basic_op(const Env env, const Type base, const Exp e);
+ANN Symbol case_basic_op(const Env env, const Type base, Exp* e);
#define CASE_PASS (Symbol)1
-ANN static Symbol case_op(const Emitter emit, const Exp base, const Exp e,
+ANN static Symbol case_op(const Emitter emit, Exp* base, Exp* e,
const Vector vec, const uint n) {
if (e->exp_type == ae_exp_primary) {
if (e->d.prim.prim_type == ae_prim_id) {
}
} else if (tflag(base->type, tflag_union) &&
e->exp_type == ae_exp_call) {
- const Exp func = e->d.exp_call.func;
+ Exp* func = e->d.exp_call.func;
if (func->d.prim.prim_type == ae_prim_id) {
const Map map = &base->type->nspc->info->value->map;
for (m_uint i = 0; i < map_size(map); ++i) {
emit_regmove(emit, SZ_INT);
CHECK_BO(emit_exp(emit, e));
const Exp_Binary bin = {.lhs = base, .rhs = e, .op = insert_symbol("?=")};
- struct Exp_ ebin = {.d = {.exp_binary = bin}, .loc = e->loc };
+ Exp ebin = {.d = {.exp_binary = bin}, .loc = e->loc };
struct Op_Import opi = {.op = insert_symbol("?="),
.lhs = base->type,
.rhs = e->type,
ANN static m_bool _emit_stmt_match_case(const Emitter emit,
const struct Stmt_Match_ *stmt,
const Vector v) {
- Exp e = stmt->cond;
+ Exp* e = stmt->cond;
const Vector cond = &emit->env->scope->match->cond;
for (m_uint i = 0; i < vector_size(cond) && e; e = e->next, ++i) {
- const Exp base = (Exp)vector_at(cond, i);
+ Exp* base = (Exp*)vector_at(cond, i);
const Symbol op = case_op(emit, base, e, v, 0);
if (op != CASE_PASS) CHECK_BB(emit_case_head(emit, base, e, op, v));
}
struct AC {
m_str str;
- Exp base;
- Exp exp;
+ Exp* base;
+ Exp* exp;
loc_t loc;
m_uint depth;
};
text_add(text, t->name);
}
-ANN Exp td2exp(const MemPool mp, const Type_Decl *td) {
- Exp base = new_prim_id(mp, td->tag.sym, td->tag.loc);
+ANN Exp* td2exp(const MemPool mp, const Type_Decl *td) {
+ Exp* base = new_prim_id(mp, td->tag.sym, td->tag.loc);
Type_Decl *next = td->next;
while(next) {
base = new_exp_dot(mp, base, next->tag.sym, td->tag.loc);
if(t)
td_fullname(env, &info->fmt->ls->text, t);
else {
- const Exp exp = td2exp(gwion->mp, targ->d.td);
+ Exp* exp = td2exp(gwion->mp, targ->d.td);
if(traverse_exp(env, exp) > 0) {
if(is_class(gwion, exp->type)) {
td_fullname(env, &info->fmt->ls->text, exp->type);
} else GWION_ERR_B(targ->d.td->tag.loc, "invalid template argument");
}
} else {
- Exp exp = targ->d.exp;
+ Exp* exp = targ->d.exp;
if(check_exp(env, targ->d.exp)) {
if(!is_class(gwion, exp->type))
gwfmt_exp(info->fmt, exp);
GWION_ERR_B(ac->loc, "malformed array [][...]")
}
-ANN static void ac_add_exp(struct AC *ac, const Exp exp) {
+ANN static void ac_add_exp(struct AC *ac, Exp* exp) {
if (ac->exp)
ac->exp = (ac->exp->next = exp);
else
if (str != ac->str) {
CHECK_BB(ac_num(gwion, ac, num));
CHECK_BB(ac_exp(gwion, ac));
- const Exp exp = new_prim_int(gwion->mp, num, ac->loc);
+ Exp* exp = new_prim_int(gwion->mp, num, ac->loc);
// set type: otherwise could fail at emit time
exp->type = gwion->type[et_int];
ac_add_exp(ac, exp);
static OP_CHECK(opck_bit_access) {
Array_Sub array = data;
- const Exp e = array->exp;
+ Exp* e = array->exp;
if(e->next) ERR_N(e->next->loc, "too many expressions for bit access");
if(is_prim_int(e)) {
m_int idx = e->d.prim.d.gwint.num;
#include "gwi.h"
// move me
-ANN Exp make_exp(const Gwi gwi, const m_str type, const m_str name) {
+ANN Exp* make_exp(const Gwi gwi, const m_str type, const m_str name) {
DECL_OO(Type_Decl *, td, = gwi_str2td(gwi, type));
struct Var_Decl_ vd;
if(gwi_str2var(gwi, &vd, name) < 0) {
return get_depth(base) == get_depth(more);
}
-ANN static Type check_array_shift(const Env env, const Exp a, const Exp b,
+ANN static Type check_array_shift(const Env env, Exp* a, Exp* b,
const m_str str, const loc_t loc) {
/* if(a->type == env->gwion->type[et_error] &&
b->type->array_depth > 1)
}
parent = parent->info->parent;
}
- struct Exp_ e = { .type = l, .loc = cast->exp->loc };
+ Exp e = { .type = l, .loc = cast->exp->loc };
CHECK_BN(check_implicit(env, &e, r));
return t;
}
}
static OP_CHECK(opck_array_slice) {
- const Exp e = (Exp)data;
+ Exp* e = (Exp*)data;
exp_setmeta(exp_self(e), 1);
return e->d.exp_slice.base->type;
}
static OP_CHECK(opck_array) {
const Array_Sub array = (Array_Sub)data;
const Type t_int = env->gwion->type[et_int];
- Exp e = array->exp;
+ Exp* e = array->exp;
do CHECK_BN(check_implicit(env, e, t_int));
while ((e = e->next));
const Type t = get_array_type(array->type);
if (t->array_depth >= array->depth)
return array_type(env, array_base(t), t->array_depth - array->depth, array->exp->loc);
- const Exp curr = take_exp(array->exp, t->array_depth);
+ Exp* curr = take_exp(array->exp, t->array_depth);
struct Array_Sub_ next = {curr->next, array_base(t),
array->depth - t->array_depth};
return vars[1];
}
-ANN static inline Exp emit_n_exp(const Emitter emit,
+ANN static inline Exp* emit_n_exp(const Emitter emit,
struct ArrayAccessInfo *const info) {
- const Exp e = take_exp(info->array.exp, info->array.depth);
- const Exp next = e->next;
+ Exp* e = take_exp(info->array.exp, info->array.depth);
+ Exp* next = e->next;
e->next = NULL;
struct Array_Sub_ partial = {info->array.exp, info->array.type,
info->array.depth};
struct Array_Sub_ next = {info->array.exp, array_base(t),
info->array.depth - t->array_depth};
info->array = partial;
- const Exp exp = emit_n_exp(emit, info);
+ Exp* exp = emit_n_exp(emit, info);
next.exp = exp;
info->array = next;
return exp ? emit_array_access(emit, info) : GW_ERROR;
}
-ANN static inline Type foreach_type(const Env env, const Exp exp) {
+ANN static inline Type foreach_type(const Env env, Exp* exp) {
const Type et = exp->type;
DECL_OO(Type, base, = typedef_base(et));
DECL_OO(const Type, t, = array_base_simple(base));
// rewrite me
static OP_CHECK(opck_array_each_val) {
- const Exp exp = (const Exp) data;
+ Exp* exp = (Exp*) data;
DECL_ON(const Type, base, = foreach_type(env, exp));
CHECK_BN(ensure_traverse(env, base));
return ref_type(env->gwion, base, exp->loc);
}
}
-ANN static bool last_is_zero(Exp e) {
+ANN static bool last_is_zero(Exp* e) {
while(e->next) e = e->next;
return exp_is_zero(e);
}
-ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, const Exp args) {
+ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, Exp* args) {
if (!last_is_zero(td->array->exp)) {
if (!args)
ERR_B(td->tag.loc, "declaration of abstract type arrays needs lambda");
#include "gack.h"
#include "tmp_resolve.h"
-ANN static Exp uncurry(const Env env, const Exp_Binary *bin) {
+ANN static Exp* uncurry(const Env env, const Exp_Binary *bin) {
const Stmt* stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code, Stmt, 0);
- const Exp ecall = stmt->d.stmt_exp.val;
+ Exp* ecall = stmt->d.stmt_exp.val;
const Exp_Call *call = &ecall->d.exp_call;
- Exp args = call->args;
- Exp lhs = bin->lhs;
- Exp base = NULL, tmp = NULL;
+ Exp* args = call->args;
+ Exp* lhs = bin->lhs;
+ Exp* base = NULL;
+ Exp *tmp = NULL;
while(args) {
if(args->exp_type != ae_exp_primary || args->d.prim.prim_type != ae_prim_id || *s_name(args->d.prim.d.var) != '@') {
- const Exp next = args->next;
+ Exp* next = args->next;
args->next = NULL;
if(tmp) tmp = (tmp->next = cpy_exp(env->gwion->mp, args));
else base = (tmp = cpy_exp(env->gwion->mp, args));
free_exp(env->gwion->mp, base);
return NULL;
}
- const Exp next = lhs->next;
+ Exp* next = lhs->next;
lhs->next = NULL;
if(tmp) tmp = (tmp->next = cpy_exp(env->gwion->mp, lhs));
else base = (tmp = cpy_exp(env->gwion->mp, lhs));
return NULL;
}
-ANN static Type mk_call(const Env env, const Exp e, const Exp func, const Exp args) {
+ANN static Type mk_call(const Env env, Exp* e, Exp* func, Exp* args) {
Exp_Call call = {.func = func, .args = args };
e->exp_type = ae_exp_call;
e->d.exp_call = call;
if(!strncmp(bin->rhs->type->name, "partial:", 8)) {
const Stmt* stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code, Stmt, 0);
const Exp_Call *call = &stmt->d.stmt_exp.val->d.exp_call;
- DECL_ON(const Exp, args, = uncurry(env, bin));
+ DECL_ON(Exp*, args, = uncurry(env, bin));
return mk_call(env, exp_self(bin), call->func, args);
}
return mk_call(env, exp_self(bin), bin->rhs, bin->lhs);
const Capture_List captures = fdef->captures;
if(captures) {
uint32_t offset = 0;
- Exp e = new_prim_id(emit->gwion->mp, fdef->base->tag.sym, fdef->base->tag.loc); // free me
+ Exp* e = new_prim_id(emit->gwion->mp, fdef->base->tag.sym, fdef->base->tag.loc); // free me
for(uint32_t i = 0; i < captures->len; i++) {
Capture *const cap = mp_vector_at(captures, Capture, i);
e->d.prim.d.var = cap->var.tag.sym;
struct FptrInfo {
Func lhs;
const Func rhs;
- const Exp exp;
+ Exp* exp;
};
ANN static void _fptr_tmpl_push(const Env env, const Func f) {
env_set_error(env, true);
}
}
-static m_bool op_call_narg(const Env env, Exp arg, const loc_t loc) {
+static m_bool op_call_narg(const Env env, Exp* arg, const loc_t loc) {
m_uint narg = 0;
while (arg) {
narg++;
ANN Type check_op_call(const Env env, Exp_Call *const exp) {
CHECK_BO(op_call_narg(env, exp->args, exp->func->loc));
- const Exp base = exp_self(exp);
- const Exp op_exp = exp->func;
+ Exp* base = exp_self(exp);
+ Exp* op_exp = exp->func;
base->exp_type = ae_exp_binary;
Exp_Binary *bin = &base->d.exp_binary;
bin->lhs = exp->args;
const Symbol rhs_sym = insert_symbol("@rhs");
const Arg *arg0 = (Arg*)(func->def->base->args->ptr);
const Arg *arg1 = (Arg*)(func->def->base->args->ptr + sizeof(Arg));
- struct Exp_ _lhs = {
+ Exp _lhs = {
.d = {.prim = {.d = {.var = lhs_sym}, .prim_type = ae_prim_id}},
.exp_type = ae_exp_primary,
.type = arg0->type,
.loc = arg0->var.td->tag.loc};
- struct Exp_ _rhs = {
+ Exp _rhs = {
.d = {.prim = {.d = {.var = rhs_sym}, .prim_type = ae_prim_id}},
.exp_type = ae_exp_primary,
.type = arg1->type,
.loc = arg1->var.td->tag.loc};
- struct Exp_ self = {.loc = impl->e->loc};
+ Exp self = {.loc = impl->e->loc};
self.d.exp_binary.lhs = &_lhs;
self.d.exp_binary.rhs = &_rhs;
self.d.exp_binary.op = impl->e->d.prim.d.var;
}
free_mp_vector(env->gwion->mp, struct ScopeEffect, eff);
}
- const Exp lhs =
+ Exp* lhs =
new_prim_id(env->gwion->mp, larg0->var.vd.tag.sym, impl->e->loc);
- const Exp rhs =
+ Exp* rhs =
new_prim_id(env->gwion->mp, larg1->var.vd.tag.sym, impl->e->loc);
- const Exp bin = new_exp_binary(env->gwion->mp, lhs, impl->e->d.prim.d.var,
+ Exp* bin = new_exp_binary(env->gwion->mp, lhs, impl->e->d.prim.d.var,
rhs, impl->e->loc);
Stmt_List code = new_mp_vector(env->gwion->mp, Stmt, 1);
mp_vector_set(code, Stmt, 0, MK_STMT(ae_stmt_return, impl->e->loc,
type_get_member(env->gwion, t, v);
}
-ANN static inline void check_deep_equal_exp(const Env env, const Exp e, const Vector v) {
+ANN static inline void check_deep_equal_exp(const Env env, Exp* e, const Vector v) {
vector_init(v);
compound_get_member(env, e->type, v);
if(tflag(e->type, tflag_struct))
for(m_uint i = 0; i < lsz; i++) {
const Value lval = (Value)vector_at(l, i),
rval = (Value)vector_at(r, i);
- struct Exp_ lexp = MK_DOT(env, bin->lhs, lval),
+ Exp lexp = MK_DOT(env, bin->lhs, lval),
rexp = MK_DOT(env, bin->rhs, rval),
temp = MK_BIN(lexp, rexp, bin);
if(!check_exp(env, &temp))
}
struct DeepEmit {
- Exp exp;
+ Exp* exp;
Value val;
- Exp tmp;
+ Exp* tmp;
struct Vector_ vec;
};
for(m_uint i = 0; i < vector_size(&ds->lhs->vec); i++) {
const Value lhs = (Value)vector_at(&ds->lhs->vec, i),
rhs = (Value)vector_at(&ds->rhs->vec, i);
- struct Exp_ lexp = MK_DOT(emit, ds->lhs->tmp, lhs);
- struct Exp_ rexp = MK_DOT(emit, ds->rhs->tmp, rhs);
- struct Exp_ temp = MK_BIN(lexp, rexp, ds->bin);
+ Exp lexp = MK_DOT(emit, ds->lhs->tmp, lhs);
+ Exp rexp = MK_DOT(emit, ds->rhs->tmp, rhs);
+ Exp temp = MK_BIN(lexp, rexp, ds->bin);
temp.type=emit->gwion->type[et_bool];
if(emit_exp(emit, &temp) < 0) return false;
vector_add(&ds->acc, (m_uint)emit_add_instr(emit, BranchEqInt));
}
static OP_CHECK(opck_dict_remove_toop) {
- const Exp e = (Exp)data;
+ Exp* e = (Exp*)data;
const Exp_Call *call = &e->d.exp_call;
- const Exp func = call->func;
- const Exp args = call->args;
+ Exp* func = call->func;
+ Exp* args = call->args;
e->exp_type = ae_exp_binary;
CHECK_OO(check_exp(env, e->d.exp_binary.rhs = cpy_exp(env->gwion->mp, func->d.exp_dot.base)));
CHECK_OO(check_exp(env, e->d.exp_binary.lhs = args));
}
ANN static m_bool emit_dict_iter(const Emitter emit, const HMapInfo *hinfo,
- const struct Op_Import *opi, const Exp call, const Exp exp) {
+ const struct Op_Import *opi, Exp* call, Exp* exp) {
emit_pushimm(emit, -1); // room for tombstone
CHECK_BB(emit_exp(emit, call));
const m_uint pc = emit_code_size(emit);
const HMapInfo *hinfo = (HMapInfo*)array->type->nspc->class_data;
const Type key = *(Type*)array->type->nspc->class_data;
- struct Exp_ func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }};
+ Exp func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }};
- struct Exp_ call = {
+ Exp call = {
.exp_type = ae_exp_call,
.d = {
.exp_call = {
}
}
};
-struct Exp_ lhs = { .exp_type = ae_exp_primary, .type = key, .d = { .prim = { .prim_type = ae_prim_id } }};
-struct Exp_ rhs = { .exp_type = ae_exp_primary, .type = key, .d = { .prim = { .prim_type = ae_prim_id } }};
-struct Exp_ bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }};
+Exp lhs = { .exp_type = ae_exp_primary, .type = key, .d = { .prim = { .prim_type = ae_prim_id } }};
+Exp rhs = { .exp_type = ae_exp_primary, .type = key, .d = { .prim = { .prim_type = ae_prim_id } }};
+Exp bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }};
struct Op_Import opi = {
.lhs = key,
.rhs = key,
static OP_EMIT(opem_dict_remove) {
Exp_Binary *bin = (Exp_Binary*)data;
const Env env = emit->env;
- struct Exp_ func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }};
+ Exp func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }};
- struct Exp_ call = {
+ Exp call = {
.exp_type = ae_exp_call,
.d = {
.exp_call = {
const Type t = bin->rhs->type;
HMapInfo *const hinfo = (HMapInfo*)t->nspc->class_data;
- struct Exp_ lhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }};
- struct Exp_ rhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }};
- struct Exp_ _bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }};
+ Exp lhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }};
+ Exp rhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }};
+ Exp _bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }};
struct Op_Import opi = {
.lhs = hinfo->key,
.rhs = hinfo->key,
static OP_EMIT(opem_dict_access) {
struct ArrayAccessInfo *const info = (struct ArrayAccessInfo *const)data;
const Array_Sub array = &info->array;
- const Exp enext = array->exp->next;
+ Exp* enext = array->exp->next;
array->exp->next = NULL;
const m_bool ret = _opem_dict_access(emit, data);
array->exp->next = enext;
const Array_Sub array = (Array_Sub)data;
HMapInfo *const hinfo = (HMapInfo*)array->type->nspc->class_data;
- struct Exp_ func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }};
+ Exp func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }};
- struct Exp_ call = {
+ Exp call = {
.exp_type = ae_exp_call,
.d = {
.exp_call = {
}
}
};
-struct Exp_ lhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }};
-struct Exp_ rhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }};
-struct Exp_ bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }};
+Exp lhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }};
+Exp rhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }};
+Exp bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }};
struct Op_Import opi = {
.lhs = hinfo->key,
.rhs = hinfo->key,
}
static OP_CHECK(opck_dict_each_key) {
- const Exp exp = (const Exp)data;
+ Exp* exp = (Exp*)data;
HMapInfo *const hinfo = (HMapInfo*)exp->type->nspc->class_data;
return hinfo->key;
}
static OP_CHECK(opck_dict_each_val) {
- const Exp exp = (const Exp)data;
+ Exp* exp = (Exp*)data;
HMapInfo *const hinfo = (HMapInfo*)exp->type->nspc->class_data;
return hinfo->val;
}
static OP_CHECK(opck_class_call) {
const Exp_Binary *bin = (Exp_Binary *)data;
Exp_Call call = {.func = bin->rhs, .args = bin->lhs};
- Exp e = exp_self(bin);
+ Exp* e = exp_self(bin);
e->exp_type = ae_exp_call;
memcpy(&e->d.exp_call, &call, sizeof(Exp_Call));
return check_exp_call1(env, &e->d.exp_call) ?: env->gwion->type[et_error];
}
static ID_CHECK(opck_super) {
- const Exp self = exp_self(prim);
+ Exp* self = exp_self(prim);
if(!env->func || is_ctor(env->func->def))
ERR_O(self->loc, "can't use 'super' outside of constructor");
const Type parent = env->class_def->info->parent;
static ID_EMIT(opem_super) {
const Env env = emit->env;
- const Exp self = exp_self(prim);
+ Exp* self = exp_self(prim);
if(!self->is_call)
ERR_B(self->loc, "can only use 'super' as a function call");
emit_regpushmem(emit, 0, SZ_INT, false);
static OP_CHECK(opck_object_instance) {
Exp_Binary *bin = (Exp_Binary*)data;
- Exp rhs = bin->rhs;
+ Exp* rhs = bin->rhs;
if (rhs->exp_type != ae_exp_decl)
return NULL;
if (rhs->d.exp_decl.var.td->array)
return NULL;
- Exp lhs = bin->lhs;
- Exp e = exp_self(bin);
+ Exp* lhs = bin->lhs;
+ Exp* e = exp_self(bin);
Exp_Decl *const decl = &e->d.exp_decl;
e->exp_type = ae_exp_decl;
decl->var.td = cpy_type_decl(env->gwion->mp, rhs->d.exp_decl.var.td);
}
ANN static void emit_member_func(const Emitter emit, const Exp_Dot *member) {
- const Exp self = exp_self(member);
+ Exp* self = exp_self(member);
const Func f = self->type->info->func;
if(is_new(f->def)) {
return NULL;
}
-ANN static m_bool member_access(const Env env, const Exp exp, const Value value) {
+ANN static m_bool member_access(const Env env, Exp* exp, const Value value) {
if (!env->class_def || isa(env->class_def, value->from->owner_class) < 0) {
if (GET_FLAG(value, private)) {
gwerr_basic("invalid variable access", "is private", NULL, env->name,
OP_CHECK(opck_object_dot) {
Exp_Dot *const member = (Exp_Dot *)data;
- Exp self = exp_self(member);
+ Exp* self = exp_self(member);
const m_str str = s_name(member->xid);
const m_bool base_static = is_class(env->gwion, member->base->type);
const Type the_base =
}
if(f) {
// TODO: add call exp
- struct Exp_ call = { .exp_type=ae_exp_call,
+ Exp call = { .exp_type=ae_exp_call,
.d={.exp_call={.args=imp->e}}, .pos=imp->e->loc, .type=f->value_ref->type };
struct Op_Import opi = { .op=insert_symbol("@func_check"),
.rhs=f->value_ref->type, .pos=imp->e->loc, .data=(uintptr_t)&call };
CHECK_BN(check_subscripts(env, array, 1));
}
if(unary->ctor.exp) {
- const Exp self = exp_self(unary);
- const Exp args = cpy_exp(env->gwion->mp, unary->ctor.exp);
- const Exp base = new_exp_unary2(env->gwion->mp, unary->op, unary->ctor.td, unary->ctor.exp, self->loc);
+ Exp* self = exp_self(unary);
+ Exp* args = cpy_exp(env->gwion->mp, unary->ctor.exp);
+ Exp* base = new_exp_unary2(env->gwion->mp, unary->op, unary->ctor.td, unary->ctor.exp, self->loc);
base->type = t;
- const Exp func = new_exp_dot(env->gwion->mp, base, insert_symbol("new"), self->loc);
+ Exp* func = new_exp_dot(env->gwion->mp, base, insert_symbol("new"), self->loc);
self->d.exp_call.func = func;
self->d.exp_call.args = args;
self->d.exp_call.tmpl = NULL;
}
static OP_CHECK(opck_int_range) {
- const Exp exp = (Exp)data;
+ Exp* exp = (Exp*)data;
const Range *range = exp->d.prim.d.range;
- const Exp e = range->start ?: range->end;
+ Exp* e = range->start ?: range->end;
return array_type(env, e->type, 1, e->loc);
}
static OP_EMIT(opem_int_range) {
- const Exp exp = (Exp)data;
+ Exp* exp = (Exp*)data;
const Instr instr = emit_add_instr(emit, IntRange);
instr->m_val = (m_uint)exp->type;
return GW_OK;
const m_float f = cast->exp->d.prim.d.fnum;
free_type_decl(env->gwion->mp, cast->td);
free_exp(env->gwion->mp, cast->exp);
- Exp e = exp_self(cast);
+ Exp* e = exp_self(cast);
e->exp_type = ae_exp_primary;
e->d.prim.prim_type = ae_prim_num;
e->d.prim.d.gwint.num = f;
return env->gwion->type[et_int];
}
/*
-ANN static void tofloat(Exp e, const m_int i) {
+ANN static void tofloat(Exp* e, const m_int i) {
e->exp_type = ae_exp_primary;
e->d.prim.prim_type = ae_prim_float;
e->d.prim.d.fnum = i;
const m_int i = cast->exp->d.prim.d.gwint.num;
free_type_decl(env->gwion->mp, cast->td);
free_exp(env->gwion->mp, cast->exp);
- Exp e = exp_self(cast);
+ Exp* e = exp_self(cast);
e->exp_type = ae_exp_primary;
e->d.prim.prim_type = ae_prim_float;
e->d.prim.d.fnum = i;
return gwi_oper_end(gwi, "<=", float_le);
}
-static inline int is_now(const Env env, const Exp exp) {
+static inline int is_now(const Env env, Exp* exp) {
return exp->exp_type == ae_exp_primary &&
exp->d.prim.prim_type == ae_prim_id &&
exp->d.prim.d.var == insert_symbol("now");
return str2type(gwion, c, loc);
}
-static m_bool ref_access(const Env env, const Exp e) {
+static m_bool ref_access(const Env env, Exp* e) {
const m_str access = exp_access(e);
if (!access) return GW_OK;
env_err(env, e->loc, _("operand is %s"), access);
const struct Implicit *imp = (struct Implicit *)data;
const Env env = emit->env;
const Type base = (Type)vector_front(&imp->t->info->tuple->contains);
- struct Exp_ cast = {.type=base, .d={.exp_cast={.exp=imp->e}}};
+ Exp cast = {.type=base, .d={.exp_cast={.exp=imp->e}}};
struct Op_Import opi = {.op = insert_symbol("$"),
.lhs = imp->e->type,
.rhs = base,
static OP_CHECK(opck_sift) {
Exp_Binary *bin = (Exp_Binary*)data;
- const Exp lhs = bin->lhs;
+ Exp* lhs = bin->lhs;
Stmt* stmt = mp_vector_at(lhs->d.exp_unary.code, Stmt, 0);
Stmt* fst = mp_vector_at(stmt->d.stmt_flow.body->d.stmt_code.stmt_list, Stmt, 0);
const Symbol chuck = insert_symbol(env->gwion->st, "=>");
- Exp next = new_exp_binary(env->gwion->mp, fst->d.stmt_exp.val, chuck, bin->rhs, bin->rhs->loc);
+ Exp* next = new_exp_binary(env->gwion->mp, fst->d.stmt_exp.val, chuck, bin->rhs, bin->rhs->loc);
CHECK_BN(traverse_exp(env, next)); // how do we free it?
fst->d.stmt_exp.val = next;
- const Exp exp = exp_self(bin);
+ Exp* exp = exp_self(bin);
exp->exp_type = lhs->exp_type;
exp->d.exp_unary.code = lhs->d.exp_unary.code;
exp->type = lhs->type;
if(bin->lhs->exp_type == ae_exp_decl)
ERR_N(bin->lhs->loc, _("can't use declaration to start sift `|>` operator"));
const Symbol chuck = insert_symbol(env->gwion->st, "=>");
- Exp exp = exp_self(data);
+ Exp* exp = exp_self(data);
- Exp func = cpy_exp(mp, exp);
- const Exp dot = new_exp_dot(mp, func->d.exp_binary.lhs, insert_symbol(env->gwion->st, "last"), func->loc);
- const Exp call = new_exp_call(mp, dot, NULL, func->loc);
+ Exp* func = cpy_exp(mp, exp);
+ Exp* dot = new_exp_dot(mp, func->d.exp_binary.lhs, insert_symbol(env->gwion->st, "last"), func->loc);
+ Exp* call = new_exp_call(mp, dot, NULL, func->loc);
func->d.exp_binary.lhs = call;
func->d.exp_binary.op = chuck;
CHECK_BN(traverse_exp(env, func));
Stmt one = { .d = { .stmt_exp = { .val = func }}, .stmt_type = ae_stmt_exp, .loc = func->loc };
- Exp samp = new_prim_id(mp, insert_symbol(env->gwion->st, "samp"), func->loc);
- Exp _now = new_prim_id(mp, insert_symbol(env->gwion->st, "now"), func->loc);
- Exp time = new_exp_binary(mp, samp, chuck, _now, func->loc);
+ Exp* samp = new_prim_id(mp, insert_symbol(env->gwion->st, "samp"), func->loc);
+ Exp* _now = new_prim_id(mp, insert_symbol(env->gwion->st, "now"), func->loc);
+ Exp* time = new_exp_binary(mp, samp, chuck, _now, func->loc);
CHECK_BN(traverse_exp(env, time));
Stmt two = { .d = { .stmt_exp = { .val = time }}, .stmt_type = ae_stmt_exp, .loc = func->loc };
mp_vector_set(slist, Stmt, 1, two);
Stmt* stmt = new_stmt_code(mp, slist, func->loc);
- const Exp cond = new_prim_id(mp, insert_symbol(env->gwion->st, "true"), func->loc);
+ Exp* cond = new_prim_id(mp, insert_symbol(env->gwion->st, "true"), func->loc);
check_exp(env, cond);
const Stmt_List code = new_mp_vector(mp, Stmt, 1);
describe_string_logical(eq, (!strcmp(STRING(lhs), STRING(rhs))))
describe_string_logical(neq, (strcmp(STRING(lhs), STRING(rhs))))
- static inline uint is_const_str(const Exp exp) {
+ static inline uint is_const_str(Exp* exp) {
return exp->exp_type == ae_exp_primary &&
exp->d.prim.prim_type == ae_prim_str;
}
const int ret = __exp__; \
free_exp(env->gwion->mp, bin->lhs); \
free_exp(env->gwion->mp, bin->rhs); \
- const Exp e = exp_self(bin); \
+ Exp* e = exp_self(bin); \
e->exp_type = ae_exp_primary; \
e->d.prim.prim_type = ae_prim_num; \
e->d.prim.d.gwint.num = ret; \
static OP_CHECK(opck_string_access) {
const Array_Sub array = (Array_Sub)data;
- const Exp exp = array->exp;
+ Exp* exp = array->exp;
if(!exp->next)
return env->gwion->type[et_char];
struct Array_Sub_ next = { exp->next, env->gwion->type[et_char], array->depth - 1 };
static OP_EMIT(opem_string_access) {
struct ArrayAccessInfo *info = (struct ArrayAccessInfo*)data;
- const Exp exp = info->array.exp;
- const Exp next = exp->next;
+ Exp* exp = info->array.exp;
+ Exp* next = exp->next;
CHECK_BB(emit_exp(emit, exp));
exp->next = next;
emit_add_instr(emit, !info->is_var ? string_at : string_at_set);
}
static OP_CHECK(opck_union_is) {
- const Exp e = (Exp)data;
+ Exp* e = (Exp*)data;
const Exp_Call *call = &e->d.exp_call;
- const Exp exp = call->args;
+ Exp* exp = call->args;
if(!exp)
ERR_N(e->loc, "Union.is() takes one argument of form id");
if (exp->exp_type != ae_exp_primary || exp->d.prim.prim_type != ae_prim_id)
for (m_uint i = 0; i < map_size(map); ++i) {
const Value v = (Value)VVAL(map, i);
if (!strcmp(s_name(exp->d.prim.d.var), v->name)) {
- const Exp exp_func = call->func;
- const Exp exp_args = call->args;
+ Exp* exp_func = call->func;
+ Exp* exp_args = call->args;
e->exp_type = ae_exp_binary;
e->d.exp_binary.lhs = cpy_exp(env->gwion->mp, exp_func);
e->d.exp_binary.lhs->d.exp_dot.xid =
#undef insert_symbol
static OP_CHECK(opck_union_new) {
Exp_Call *call = (Exp_Call *)data;
- const Exp name = call->args;
+ Exp* name = call->args;
if (!name)
ERR_N(call->func->loc, "Union constructor takes one or two arguments, "
"'id' and 'value'");
if (name->exp_type != ae_exp_primary || name->d.prim.prim_type != ae_prim_id)
ERR_N(call->func->loc, "Union constructor first argument me be an identifier");
- const Exp val = name->next;
+ Exp* val = name->next;
const Type base = call->func->d.exp_dot.base->type;
const Map map = &base->nspc->info->value->map;
name->d.prim.d.gwint.num = i;
name->type = env->gwion->type[et_int];
if(!val && v->type == env->gwion->type[et_none]) {
- const Exp e = new_prim_int(env->gwion->mp, SZ_INT, name->loc);
+ Exp* e = new_prim_int(env->gwion->mp, SZ_INT, name->loc);
e->next = name;
e->type = env->gwion->type[et_int];
name->next = new_prim_int(env->gwion->mp, 0, name->loc);
ERR_N(val->loc, "Invalid type '%s' for '%s', should be '%s'", t->name,
v->name, v->type->name);
}
- const Exp e = new_prim_int(env->gwion->mp, t->size + SZ_INT, val->loc);
+ Exp* e = new_prim_int(env->gwion->mp, t->size + SZ_INT, val->loc);
e->next = name;
e->type = env->gwion->type[et_int];
call->args = e;
ANN m_bool check_stmt_list(const Env env, Stmt_List list);
ANN m_bool check_class_def(const Env env, const Class_Def class_def);
-ANN static Type check_internal(const Env env, const Symbol sym, const Exp e,
+ANN static Type check_internal(const Env env, const Symbol sym, Exp* e,
const Type t) {
struct Implicit imp = {.e = e, .t = t, .loc = e->loc};
struct Op_Import opi = {.op = sym,
return op_check(env, &opi);
}
-ANN m_bool check_implicit(const Env env, const Exp e, const Type t) {
+ANN m_bool check_implicit(const Env env, Exp* e, const Type t) {
if (e->type == t) return GW_OK;
if (isa(e->type, t) > 0) return GW_OK;
const Symbol sym = insert_symbol("@implicit");
const m_bool is_decl) {
CHECK_OB(check_exp(env, array->exp));
m_uint depth = 0;
- Exp e = array->exp;
+ Exp* e = array->exp;
do {
if (is_decl) {
if(check_implicit(env, e, env->gwion->type[et_int]) < 0)
if (decl->var.td->array && decl->var.td->array->exp)
CHECK_OO(check_exp(env, decl->var.td->array->exp));
if (decl->args) {
- const Exp e = new_exp_unary2(env->gwion->mp, insert_symbol("new"), cpy_type_decl(env->gwion->mp, decl->var.td), decl->args, decl->var.td->tag.loc);
+ Exp* e = new_exp_unary2(env->gwion->mp, insert_symbol("new"), cpy_type_decl(env->gwion->mp, decl->var.td), decl->args, decl->var.td->tag.loc);
CHECK_OO(check_exp(env, e));
decl->args = e;
e->ref = exp_self(decl);
return ret > 0 ? decl->var.vd.value->type : NULL;
}
-ANN static m_bool check_collection(const Env env, Type type, const Exp e,
+ANN static m_bool check_collection(const Env env, Type type, Exp* e,
const loc_t loc) {
const Type common = find_common_anc(e->type, type);
if (common) return GW_OK;
return GW_ERROR;
}
-ANN static inline Type prim_array_match(const Env env, Exp e) {
+ANN static inline Type prim_array_match(const Env env, Exp* e) {
const Type type = e->type;
bool err = false;
const loc_t loc = e->loc;
ANN static Type check_prim_array(const Env env, const Array_Sub *data) {
const Array_Sub array = *data;
- const Exp e = array->exp;
+ Exp* e = array->exp;
if (!e)
ERR_O(prim_pos(data), _("must provide values/expressions for array [...]"))
CHECK_OO(check_exp(env, e));
Range *range = *data;
CHECK_BO(check_range(env, range));
env_weight(env, 1);
- const Exp e = range->start ?: range->end;
+ Exp* e = range->start ?: range->end;
assert(e);
const Symbol sym = insert_symbol("[:]");
struct Op_Import opi = {.op = sym,
return op_check(env, &opi);
}
-ANN static Type check_prim_dict(const Env env, Exp *data) {
- const Exp base = *data;
+ANN static Type check_prim_dict(const Env env, Exp* *data) {
+ Exp* base = *data;
CHECK_OO(check_exp(env, base));
const Type key = base->type;
const Type val = base->next->type;
bool err = false;
const loc_t loc = base->loc;
- Exp e = base;
+ Exp* e = base;
env_weight(env, 1);
do {
if (check_collection(env, key, e, loc) < 0) err = true;
}
ANN static Type prim_owned(const Env env, const Symbol *data) {
- const Exp exp = exp_self(prim_exp(data));
+ Exp* exp = exp_self(prim_exp(data));
const Value v = exp->d.prim.value;
if(is_class(env->gwion, v->type) && env->class_def == v->type->info->base_type) // write it better
return v->type->info->base_type;
// if(v->from->owner_class && is_func(env->gwion, v->from->owner_class))
// return v->type;
const m_str name = !GET_FLAG(v, static) ? "this" : v->from->owner_class->name;
- const Exp base =
+ Exp* base =
new_prim_id(env->gwion->mp, insert_symbol(name), prim_pos(data));
exp_setuse(base, 1);
exp->exp_type = ae_exp_dot;
return env->gwion->type[et_void];
}
-ANN static Type check_prim_interp(const Env env, const Exp *exp) {
+ANN static Type check_prim_interp(const Env env, Exp* *exp) {
CHECK_OO(check_exp(env, *exp));
env_weight(env, 1);
return env->gwion->type[et_string];
}
-ANN static Type check_prim_hack(const Env env, const Exp *data) {
+ANN static Type check_prim_hack(const Env env, Exp* *data) {
if (env->func) unset_fflag(env->func, fflag_pure);
CHECK_OO(check_prim_interp(env, data));
env_weight(env, 1);
CHECK_BO(check_range(env, range->range));
env_weight(env, 1);
const Symbol sym = insert_symbol("[:]");
- const Exp e = range->range->start ?: range->range->end;
+ Exp* e = range->range->start ?: range->range->end;
assert(e);
struct Op_Import opi = {.op = sym,
.lhs = e->type,
}
ANN2(1, 2)
-static Func find_func_match_actual(const Env env, const Func f, const Exp exp,
+static Func find_func_match_actual(const Env env, const Func f, Exp* exp,
const bool implicit, const bool specific) {
Func func = f;
do {
- Exp e = exp;
+ Exp* e = exp;
Arg_List args = func->def->base->args;
m_uint i = 0;
const m_uint args_len = mp_vector_len(args);
ANN static Type check_exp_call(const Env env, Exp_Call *exp);
ANN static Func call2ufcs(const Env env, Exp_Call *call, const Value v) {
- const Exp this = call->func->d.exp_dot.base;
+ Exp* this = call->func->d.exp_dot.base;
this->next = call->args;
call->args = this;
call->func->type = v->type;
ANN Func find_func_match(const Env env, const Func up, Exp_Call *const call) {
Func func;
- const Exp exp = call->args;
- const Exp args =
+ Exp* exp = call->args;
+ Exp* args =
(exp && isa(exp->type, env->gwion->type[et_void]) < 0) ? exp : NULL;
if ((func = find_func_match_actual(env, up, args, false, true)) ||
(func = find_func_match_actual(env, up, args, true, true)) ||
return GW_OK;
}
-#define next_arg(type) \
- ANN static inline type next_arg_##type(const type e) { \
- const type next = e->next; \
- if (next) gw_err(", "); \
- return next; \
- }
-next_arg(Exp)
-//next_arg(Arg_List);
+ANN static inline Exp* next_arg_exp(const Exp *e) {
+ Exp* next = e->next;
+ if (next) gw_err(", ");
+ return next;
+}
-ANN static void print_current_args(Exp e) {
+ANN static void print_current_args(Exp* e) {
gw_err(_("and not\n "));
do gw_err(" {G}%s{0}", e->type ? e->type->name : "<Unknown>");
- while ((e = next_arg_Exp(e)));
+ while ((e = next_arg_exp(e)));
gw_err("\n");
}
ANN2(1)
-static void function_alternative(const Env env, const Type t, const Exp args,
+static void function_alternative(const Env env, const Type t, Exp* args,
const loc_t loc) {
if (env->context && env->context->error) // needed for ufcs
return;
Specialized *spec = mp_vector_at(sl, Specialized, i);
Arg_List args = fdef->base->args;
const uint32_t args_len = mp_vector_len(args);
- Exp template_arg = exp->args;
+ Exp* template_arg = exp->args;
uint32_t count = 0;
while (count < args_len && template_arg) {
Arg *arg = mp_vector_at(args, Arg, count);
ERR_O(exp->func->loc, _("not able to infer types for template call."))
if(spread) {
- Exp e = exp->args;
+ Exp* e = exp->args;
if(fdef->base->args)
for(uint32_t i = 0; i < fdef->base->args->len && e; i++) e = e->next;
while(e) {
ANN Type upvalue_type(const Env env, Capture *cap);
ANN static m_bool lambda_args_ref(const Env env, Exp_Call *const call) {
- Exp e = call->args;
+ Exp* e = call->args;
CHECK_OB(check_exp(env, e));
do if(tflag(e->type, tflag_ref) && !safe_tflag(exp_self(e)->cast_to, tflag_ref))
exp_setvar(e, true);
return GW_OK;
}
-ANN2(1) static m_bool lambda_append_args(const Env env, Exp_Call *const call, const Exp add) {
+ANN2(1) static m_bool lambda_append_args(const Env env, Exp_Call *const call, Exp* add) {
if(!add) return GW_ERROR;
if (call->args) {
- Exp e = call->args;
+ Exp* e = call->args;
while(e->next) e = e->next;
e->next = add;
} else call->args = add;
return traverse_exp(env, add);
}
-ANN static Exp check_lambda_captures(const Env env, const Func_Def fdef) {
+ANN static Exp* check_lambda_captures(const Env env, const Func_Def fdef) {
if(!fdef->base->args)
fdef->base->args = new_mp_vector(env->gwion->mp, Arg, 0);
- Exp args = NULL, tmp;
+ Exp* args = NULL;
+ Exp* tmp;
for(uint32_t i = 0; i < fdef->captures->len; i++) {
Capture *const cap = mp_vector_at(fdef->captures, Capture, i);
const Type t = upvalue_type(env, cap);
(Var_Decl){ .tag = MK_TAG(cap->var.tag.sym, cap->var.tag.loc) }
)};
mp_vector_add(env->gwion->mp, &fdef->base->args, Arg, arg);
- const Exp exp = new_prim_id(env->gwion->mp, cap->var.tag.sym, cap->var.tag.loc);
+ Exp* exp = new_prim_id(env->gwion->mp, cap->var.tag.sym, cap->var.tag.loc);
if(args) tmp = tmp->next = exp;
else args = tmp = exp;
}
const Func_Def fdef = exp->func->d.exp_lambda.def;
const bool captures = !!fdef->captures;
if (exp->args) CHECK_BO(lambda_args_ref(env, exp));
- const Exp _args = !captures ? NULL : check_lambda_captures(env, fdef);
+ Exp* _args = !captures ? NULL : check_lambda_captures(env, fdef);
if(captures) CHECK_BO(lambda_append_args(env, exp, _args));
Exp_Lambda *l = &exp->func->d.exp_lambda;
Arg_List args = l->def->base->args;
- Exp e = exp->args;
+ Exp* e = exp->args;
for(uint32_t i = 0; i < (args ? args->len : 0); i++) {
if(!e)
ERR_O(exp_self(exp)->loc, _("argument number does not match for lambda"))
if (exp->args) CHECK_OB(check_exp(env, exp->args));
return call2ufcs(env, exp, t->info->func->value_ref) ? GW_OK : GW_ERROR;
}
- const Exp e = exp_self(exp);
+ Exp* e = exp_self(exp);
struct Op_Import opi = {.op = insert_symbol("@func_check"),
.rhs = t,
.loc = e->loc,
return op_check(env, &opi);
}
-ANN static inline bool is_super(const Exp func) {
+ANN static inline bool is_super(Exp* func) {
return func->exp_type == ae_exp_primary &&
func->d.prim.prim_type == ae_prim_id &&
!strcmp(s_name(func->d.prim.d.var), "super");
return check_lambda_call(env, exp);
if (exp->args) {
CHECK_OO(check_exp(env, exp->args));
- Exp e = exp->args;
+ Exp* e = exp->args;
do exp_setuse(e, true);
while((e = e->next));
}
? NULL : partial_type(env, exp);
}
-ANN static Type check_static(const Env env, const Exp e) {
+ANN static Type check_static(const Env env, Exp* e) {
const Type t = e->type;
if(unlikely(!is_func(env->gwion, t)) ||
!t->info->func ||
if(_ret) return _ret;
if(isa(exp->func->type, env->gwion->type[et_closure]) > 0) {
if(exp->func->exp_type == ae_exp_dot && t->info->value->from->owner_class) {
- const Exp args = exp->args;
- const Exp this_arg = cpy_exp(env->gwion->mp, exp->func->d.exp_dot.base);
+ Exp* args = exp->args;
+ Exp* this_arg = cpy_exp(env->gwion->mp, exp->func->d.exp_dot.base);
this_arg->next = args;
exp->args = this_arg;
const Type t = _check_exp_call1(env, exp);
bin->rhs->exp_type == ae_exp_unary && bin->rhs->d.exp_unary.unary_type == unary_td &&
!bin->rhs->d.exp_unary.ctor.td->array &&
!bin->rhs->d.exp_unary.ctor.exp) {
- Exp lhs = bin->lhs;
- Exp rhs = bin->rhs;
- Exp e = exp_self(bin);
+ Exp* lhs = bin->lhs;
+ Exp* rhs = bin->rhs;
+ Exp* e = exp_self(bin);
Exp_Unary *const unary = &e->d.exp_unary;
e->exp_type = ae_exp_unary;
unary->unary_type = unary_td;
return GW_ERROR;
}
-ANN2(1) static inline bool is_partial(const Env env, Exp exp) {
+ANN2(1) static inline bool is_partial(const Env env, Exp* exp) {
while (exp) {
if (is_hole(env, exp) || is_typed_hole(env, exp))
return true;
return ret;
}
-ANN static Type _flow(const Env env, const Exp e, const m_bool b) {
+ANN static Type _flow(const Env env, Exp* e, const m_bool b) {
DECL_OO(const Type, type, = check_exp(env, e));
struct Op_Import opi = {
.op = insert_symbol(b ? "@conditional" : "@unconditional"),
ANN static Type check_exp_if(const Env env, Exp_If *const exp_if) {
if (!exp_if->if_exp) {
- const Exp e = exp_if->if_exp = cpy_exp(env->gwion->mp, exp_if->cond);
+ Exp* e = exp_if->if_exp = cpy_exp(env->gwion->mp, exp_if->cond);
scan1_exp(env, e);
scan2_exp(env, e);
}
env->gwion->mp, type2td(env->gwion, tdef->type, tdef->tag.loc),
insert_symbol("@implicit"), args, ae_flag_none, tdef->tag.loc);
set_fbflag(fb, fbflag_op);
- const Exp helper = new_prim_id(env->gwion->mp, insert_symbol("@predicate"),
+ Exp* helper = new_prim_id(env->gwion->mp, insert_symbol("@predicate"),
tdef->when->loc);
- const Exp when = tdef->when;
+ Exp* when = tdef->when;
tdef->when = NULL;
when->next = helper;
Stmt_List code = new_mp_vector(env->gwion->mp, Stmt, 2);
}
// we handle the return after, so that we don't get *cant' use implicit
// casting while defining it*
- const Exp ret_id = new_prim_id(env->gwion->mp, insert_symbol("self"), when->loc);
+ Exp* ret_id = new_prim_id(env->gwion->mp, insert_symbol("self"), when->loc);
ret_id->d.prim.value = new_value(env, tdef->type, "self", tdef->tag.loc);
Stmt ret = {
.stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = ret_id }},
DECL_EXP_FUNC(check, Type, Env)
-ANN Type check_exp(const Env env, const Exp exp) {
- Exp curr = exp;
+ANN Type check_exp(const Env env, Exp* exp) {
+ Exp* curr = exp;
if (!exp->type) {
env_weight(env, 1);
do {
/** sets for the key expression value
with eg type *int* for an array or the *Key* type of a Dict **/
-ANN static m_bool check_each_idx(const Env env, const Exp exp, struct EachIdx_ *const idx) {
+ANN static m_bool check_each_idx(const Env env, Exp* exp, struct EachIdx_ *const idx) {
struct Op_Import opi = {
.lhs = exp->type,
.op = insert_symbol("@each_idx"),
/** return the base type for the foreach expression
eg the base type of an array or the *Val* type of a Dict **/
-ANN static Type check_each_val(const Env env, const Exp exp) {
+ANN static Type check_each_val(const Env env, Exp* exp) {
struct Op_Import opi = {
.lhs = exp->type,
.op = insert_symbol("@each_val"),
return check_conts(env, stmt_self(stmt), stmt->body);
}
-ANN static inline m_bool repeat_type(const Env env, const Exp e) {
+ANN static inline m_bool repeat_type(const Env env, Exp* e) {
const Type t_int = env->gwion->type[et_int];
if (check_implicit(env, e, t_int) < 0) {
char explain[40 + strlen(e->type->name)];
return v;
}
-ANN Symbol case_basic_op(const Env env, const Type base, const Exp e) {
+ANN Symbol case_basic_op(const Env env, const Type base, Exp* e) {
const Symbol _op = insert_symbol("==");
struct Op_Import opi = {.op = _op,
.lhs = base,
: insert_symbol("?=");
}
-ANN static Symbol case_op(const Env env, const Type base, const Exp e) {
+ANN static Symbol case_op(const Env env, const Type base, Exp* e) {
if (e->exp_type == ae_exp_primary) {
if (e->d.prim.prim_type == ae_prim_id) {
if (e->d.prim.d.var == insert_symbol("_")) return NULL;
}
} else if (tflag(base, tflag_union) &&
e->exp_type == ae_exp_call) {
- const Exp func = e->d.exp_call.func;
+ Exp* func = e->d.exp_call.func;
if (func->d.prim.prim_type == ae_prim_id) {
const Value v = find_value(base, func->d.prim.d.var);
if (v) {
return case_basic_op(env, base, e);
}
-ANN static m_bool match_case_exp(const Env env, Exp e) {
- Exp last = e;
+ANN static m_bool match_case_exp(const Env env, Exp* e) {
+ Exp* last = e;
for (m_uint i = 0; i < vector_size(&env->scope->match->cond); e = e->next, ++i) {
if (!e) ERR_B(last->loc, _("no enough to match"))
last = e;
- const Exp base = (Exp)vector_at(&env->scope->match->cond, i);
+ Exp* base = (Exp*)vector_at(&env->scope->match->cond, i);
const Symbol op = case_op(env, base->type, e);
if (op) {
- const Exp next = e->next;
+ Exp* next = e->next;
e->next = NULL;
const Type t = check_exp(env, e);
e->next = next;
CHECK_OB(t);
Exp_Binary bin = {.lhs = cpy_exp(env->gwion->mp, base), .rhs = cpy_exp(env->gwion->mp, e), .op = op};
- struct Exp_ ebin = {.d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc };
+ Exp ebin = {.d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc };
CHECK_BB(traverse_exp(env, &ebin));
const Type ret = ebin.type;
if(ebin.exp_type == ae_exp_binary) {
env->func->memoize = strtol(stmt->data + 7, NULL, 10);
else if(stmt->pp_type == ae_pp_locale) {
const loc_t loc = stmt_self(stmt)->loc;
- const Exp id = new_prim_id(env->gwion->mp, stmt->xid, loc);
- const Exp arg = new_prim_id(env->gwion->mp, insert_symbol("_"), loc);
+ Exp* id = new_prim_id(env->gwion->mp, stmt->xid, loc);
+ Exp* arg = new_prim_id(env->gwion->mp, insert_symbol("_"), loc);
arg->next = stmt->exp;
- const Exp call = new_exp_call(env->gwion->mp, id, arg, loc);
+ Exp* call = new_exp_call(env->gwion->mp, id, arg, loc);
stmt->exp = call;
CHECK_BB(traverse_exp(env, id));
CHECK_OB(partial_type(env, &call->d.exp_call));
const Stmt* stmt = mp_vector_at(l, Stmt, i);
if (stmt->stmt_type == ae_stmt_pp) continue;
if (stmt->stmt_type == ae_stmt_exp) {
- const Exp exp = stmt->d.stmt_exp.val;
+ Exp* exp = stmt->d.stmt_exp.val;
if (!exp) continue;
if (exp->exp_type != ae_exp_decl) return true;
if (GET_FLAG(exp->d.exp_decl.var.td, late)) continue;
#include "gwion.h"
#include "traverse.h"
-ANN2(1,2) static Exp base_args(const MemPool p, const Arg_List args, Exp next, const uint32_t min) {
+ANN2(1,2) static Exp* base_args(const MemPool p, const Arg_List args, Exp* next, const uint32_t min) {
for(uint32_t i = min; i--;) {
Arg *arg = mp_vector_at(args, Arg, i);
- const Exp exp = new_prim_id(p, arg->var.vd.tag.sym, arg->var.vd.tag.loc);
+ Exp* exp = new_prim_id(p, arg->var.vd.tag.sym, arg->var.vd.tag.loc);
exp->next = next;
next = exp;
}
return next;
}
-ANN static Exp additional_args(const MemPool p, const Arg_List args, const uint32_t max) {
- Exp next = NULL;
+ANN static Exp* additional_args(const MemPool p, const Arg_List args, const uint32_t max) {
+ Exp* next = NULL;
for(uint32_t i = max; i-- > args->len;) {
Arg *arg = mp_vector_at(args, Arg, i);
- const Exp exp = cpy_exp(p, arg->exp);
+ Exp* exp = cpy_exp(p, arg->exp);
exp->next = next;
next = exp;
}
return next;
}
-ANN static Exp mk_args(const MemPool p, const Arg_List args, const uint32_t max) {
- const Exp next = additional_args(p, args, max);
+ANN static Exp* mk_args(const MemPool p, const Arg_List args, const uint32_t max) {
+ Exp* next = additional_args(p, args, max);
return base_args(p, args, next, args->len);
}
-ANN static Stmt_List code(const MemPool p, const Exp func, const Arg_List lst,
+ANN static Stmt_List code(const MemPool p, Exp* func, const Arg_List lst,
const uint32_t max, const ae_stmt_t type) {
- const Exp arg = mk_args(p, lst, max);
- const Exp call = new_exp_call(p, func, arg, func->loc);
+ Exp* arg = mk_args(p, lst, max);
+ Exp* call = new_exp_call(p, func, arg, func->loc);
Stmt_List code = new_mp_vector(p, Stmt, 1);
- mp_vector_set(code, Stmt, 0, MK_STMT(ae_stmt_return, func->loc, .stmt_exp = { .val = call}));
+ mp_vector_set(code, Stmt, 0, MK_STMT(type, func->loc, .stmt_exp = { .val = call}));
return code;
}
ANN static Stmt_List std_code(const Env env, Func_Base *base, const uint32_t max) {
const MemPool p = env->gwion->mp;
- const Exp func = new_prim_id(p, base->tag.sym, base->tag.loc);
+ Exp* func = new_prim_id(p, base->tag.sym, base->tag.loc);
return code(p, func, base->args, max, ae_stmt_return);
}
ANN static Stmt_List new_code(const Env env, Func_Base *base, const uint32_t max) {
const MemPool p = env->gwion->mp;
SymTable *st = env->gwion->st;
- const Exp dbase = new_prim_id(p, insert_symbol(st, "this"), base->tag.loc);
+ Exp* dbase = new_prim_id(p, insert_symbol(st, "this"), base->tag.loc);
const Symbol sym = insert_symbol(st, "new");
- const Exp func = new_exp_dot(p, dbase, sym, base->tag.loc);
+ Exp* func = new_exp_dot(p, dbase, sym, base->tag.loc);
return code(p, func, base->args, max, ae_stmt_exp);
}
#include "traverse.h"
#include "clean.h"
-typedef Type (*f_type)(const Env env, const Exp exp);
+typedef Type (*f_type)(const Env env, Exp* exp);
typedef struct M_Operator_ {
Type lhs, rhs, ret;
ANN static Type chuck_rewrite(const Env env, const struct Op_Import *opi, const m_str op, const size_t len) {
Exp_Binary *base = (Exp_Binary*)opi->data;
- const Exp lhs = cpy_exp(env->gwion->mp, base->lhs); // no need to copy
- const Exp call = new_exp_call(env->gwion->mp, cpy_exp(env->gwion->mp, base->rhs), NULL, lhs->loc);
+ Exp* lhs = cpy_exp(env->gwion->mp, base->lhs); // no need to copy
+ Exp* call = new_exp_call(env->gwion->mp, cpy_exp(env->gwion->mp, base->rhs), NULL, lhs->loc);
char c[len - 1];
strncpy(c, op, len - 2);
c[len - 2] = '\0';
env_set_error(env, true);
return NULL;
}
- const Exp bin = new_exp_binary(env->gwion->mp, lhs, insert_symbol(env->gwion->st, c), call, exp_self(base)->loc);
+ Exp* bin = new_exp_binary(env->gwion->mp, lhs, insert_symbol(env->gwion->st, c), call, exp_self(base)->loc);
base->lhs = bin;
base->op = insert_symbol(env->gwion->st, "=>");
const Type ret = check_exp(env, exp_self(base));
#include "parse.h"
#include "partial.h"
-ANN static Arg_List partial_arg_list(const Env env, const Arg_List base, const Exp e) {
+ANN static Arg_List partial_arg_list(const Env env, const Arg_List base, Exp* e) {
Arg_List args = new_mp_vector(env->gwion->mp, Arg, 0);
- Exp next = e;
+ Exp* next = e;
uint32_t i = 0;
while(next) {
if(is_hole(env, next) || is_typed_hole(env, next)) {
return insert_symbol(c);
}
-ANN2(1, 2) static inline Func_Base *partial_base(const Env env, const Func_Base *base, Exp earg, const loc_t loc) {
+ANN2(1, 2) static inline Func_Base *partial_base(const Env env, const Func_Base *base, Exp* earg, const loc_t loc) {
Arg_List args = earg ? partial_arg_list(env, base->args, earg) : NULL;
Func_Base *fb = new_func_base(env->gwion->mp, base->td ? cpy_type_decl(env->gwion->mp, base->td) : NULL, partial_name(env, loc.first), args, ae_flag_none, loc);
return fb;
}
-ANN static Exp partial_exp(const Env env, Arg_List args, Exp e, const uint i) {
+ANN static Exp* partial_exp(const Env env, Arg_List args, Exp* e, const uint i) {
if(is_hole(env, e) || is_typed_hole(env, e)) {
char c[256];
sprintf(c, "@%u", i);
- const Exp exp = new_prim_id(env->gwion->mp, insert_symbol(c), e->loc);
+ Exp* exp = new_prim_id(env->gwion->mp, insert_symbol(c), e->loc);
exp->type = known_type(env, mp_vector_at(args, Arg, i)->var.td);
exp->d.prim.value = new_value(env, exp->type, c, e->loc);
valid_value(env, insert_symbol(c), exp->d.prim.value);
return exp;
}
- const Exp next = e->next;
+ Exp* next = e->next;
e->next = NULL;
- const Exp exp = cpy_exp(env->gwion->mp, e);
+ Exp* exp = cpy_exp(env->gwion->mp, e);
exp->type = e->type;
e->next = next;
return exp;
}
-ANN2(1) static Exp partial_call(const Env env, Arg_List args, Exp e) {
- Exp base = NULL, arg;
+ANN2(1) static Exp* partial_call(const Env env, Arg_List args, Exp* e) {
+ Exp* base = NULL;
+ Exp* arg;
uint32_t i = 0;
while(e) {
- const Exp exp = partial_exp(env, args, e, i++);
+ Exp* exp = partial_exp(env, args, e, i++);
if(base) arg = arg->next = exp;
else arg = base = exp;
e = e->next;
}
-ANN Func find_match(const Env env, Func func, const Exp exp, const bool implicit,
+ANN Func find_match(const Env env, Func func, Exp* exp, const bool implicit,
const bool specific) {
do {
- Exp e = exp;
+ Exp* e = exp;
uint32_t i = 0;
Arg_List args = func->def->base->args;
uint32_t len = mp_vector_len(args);
const Arg *arg = mp_vector_at(args, Arg, i++);
if(!is_hole(env, e)) {
if(!is_typed_hole(env, e)) {
- const Exp next = e->next;
+ Exp* next = e->next;
e->next = NULL;
const Type ret = check_exp(env, e);
e->next = next;
return NULL;
}
-ANN Func find_match_actual(const Env env, const Func up, const Exp args) {
+ANN Func find_match_actual(const Env env, const Func up, Exp* args) {
return find_match(env, up, args, false, true) ?:
find_match(env, up, args, true, true) ?:
find_match(env, up, args, false, true) ?:
NULL;
}
-ANN static Func partial_match(const Env env, const Func up, const Exp args, const loc_t loc);
+ANN static Func partial_match(const Env env, const Func up, Exp* args, const loc_t loc);
ANN static void print_arg(Arg_List args) {
for(uint32_t i = 0; i < args->len; i++) {
gw_err("\n");
}
-ANN void ambiguity(const Env env, Func f, const Exp args, const loc_t loc) {
+ANN void ambiguity(const Env env, Func f, Exp* args, const loc_t loc) {
print_signature(f);
while(f->next) {
const Func next = partial_match(env, f->next, args, loc);
}
}
-ANN static Func partial_match(const Env env, const Func up, const Exp args, const loc_t loc) {
+ANN static Func partial_match(const Env env, const Func up, Exp* args, const loc_t loc) {
const Func f = find_match_actual(env, up, args);
if(f) {
const Type t = f->value_ref->from->owner_class;
return NULL;
}
-ANN static Stmt_List partial_code(const Env env, Arg_List args, const Exp efun, const Exp earg) {
- const Exp arg = partial_call(env, args, earg);
- const Exp exp = new_exp_call(env->gwion->mp, efun, arg, efun->loc);
+ANN static Stmt_List partial_code(const Env env, Arg_List args, Exp* efun, Exp* earg) {
+ Exp* arg = partial_call(env, args, earg);
+ Exp* exp = new_exp_call(env->gwion->mp, efun, arg, efun->loc);
Stmt_List code = new_mp_vector(env->gwion->mp, Stmt, 1);
mp_vector_set(code, Stmt, 0, MK_STMT(ae_stmt_return, efun->loc,
.stmt_exp = { .val = exp }));
return code;
}
-ANN static uint32_t count_args_exp(Exp args) {
+ANN static uint32_t count_args_exp(Exp* args) {
uint32_t i = 0;
do i++;
while ((args = args->next));
return max;
}
-ANN static Exp expand(const Env env, const Func func, const Exp e, const loc_t loc) {
+ANN static Exp* expand(const Env env, const Func func, Exp* e, const loc_t loc) {
const uint32_t i = count_args_exp(e);
const uint32_t max = count_args_func(func, i);
if(max > i) {
- Exp args = e;
+ Exp* args = e;
if(args) {
while(args->next) args = args->next;
args->next = new_prim_id(env->gwion->mp, insert_symbol("_"), loc);
if(!base) ERR_O(call->func->loc, _("can't do partial application on a literal lambda"));
const Func f = partial_match(env, base, call->args, call->func->loc);
if(!f) {
- const Exp e = expand(env, call->func->type->info->func, call->args, call->func->loc);
+ Exp* e = expand(env, call->func->type->info->func, call->args, call->func->loc);
if(e) {
call->args = e;
return partial_type(env, call);
nspc_push_value(env->gwion->mp, env->curr);
Func_Base *const fbase = partial_base(env, f->def->base, call->args, call->func->loc);
const Stmt_List code = partial_code(env, f->def->base->args, call->func, call->args);
- const Exp exp = exp_self(call);
+ Exp* exp = exp_self(call);
exp->d.exp_lambda.def = new_func_def(env->gwion->mp, fbase, code);
exp->exp_type = ae_exp_lambda;
const m_bool ret = traverse_func_def(env, exp->d.exp_lambda.def);
static OP_EMIT(opem_struct_assign) {
const Exp_Binary *bin = data;
const Type t = bin->lhs->type;
- const Exp e = exp_self(bin);
+ Exp* e = exp_self(bin);
if(tflag(t, tflag_release)) {
const f_instr exec = !tflag(t, tflag_union)
ANN static Type cdef_parent(const Env env, const Class_Def cdef) {
if (cflag(cdef, cflag_struct)) return env->gwion->type[et_compound];
if (!cdef->base.ext) return env->gwion->type[et_object];
- Exp e = cdef->base.ext->array ? cdef->base.ext->array->exp : NULL;
+ Exp* e = cdef->base.ext->array ? cdef->base.ext->array->exp : NULL;
while(e) {
if(!is_prim_int(e))
ERR_O(e->loc, "non null array type extension must be literal");
}
ANN m_bool abstract_array(const Env env, const Array_Sub array) {
- Exp e = array->exp;
+ Exp* e = array->exp;
while(e) {
if(!exp_is_zero(e))
ERR_B(e->loc, _("arrays of abstract type should use `0` size"));
ANN static m_bool scan1_exp_call(const Env env, const Exp_Call *exp_call) {
if (exp_call->tmpl) return GW_OK;
CHECK_BB(scan1_exp(env, exp_call->func));
- const Exp args = exp_call->args;
+ Exp* args = exp_call->args;
return args ? scan1_exp(env, args) : GW_OK;
}
const Exp_Call *exp_call) {
if (exp_call->tmpl) return GW_OK;
CHECK_BB(scan2_exp(env, exp_call->func));
- const Exp args = exp_call->args;
+ Exp* args = exp_call->args;
return args ? scan2_exp(env, args) : GW_OK;
}
}
#include <ctype.h>
-ANN Exp td2exp(const MemPool mp, const Type_Decl *td);
+ANN Exp* td2exp(const MemPool mp, const Type_Decl *td);
ANN void check_call(const Env env, const Tmpl *tmpl) {
for(uint32_t i = 0; i < tmpl->call->len; i++) {
Specialized *spec = i < tmpl->list->len
if(unlikely(spec->td)) {
if(targ->type == tmplarg_td) {
targ->type = tmplarg_exp;
-const Exp exp = td2exp(env->gwion->mp, targ->d.td);
+Exp* exp = td2exp(env->gwion->mp, targ->d.td);
targ->d.exp = exp;
}
const Type t = known_type(env, base);
if(t) {
arg->type = tmplarg_exp;
- Exp e = new_exp_td(env->gwion->mp, base, base->tag.loc);
+ Exp* e = new_exp_td(env->gwion->mp, base, base->tag.loc);
arg->d.exp = new_exp_dot(env->gwion->mp, e, last->tag.sym, base->tag.loc);
free_type_decl(env->gwion->mp, last);
i--;
return check_ast(env, ast);
}
-ANN m_bool traverse_exp(const Env env, const Exp exp) {
+ANN m_bool traverse_exp(const Env env, Exp* exp) {
CHECK_BB(scan1_exp(env, exp));
CHECK_BB(scan2_exp(env, exp));
return check_exp(env, exp) ? 1 : -1;