-Subproject commit 9250ae0ec3f65a9be684a5dfb66ca13c7916883f
+Subproject commit 0ba7b3b15cbdfab20b35b8a84dcebded0501c054
-Subproject commit 0bd98c85e182ecb27324be5298629feef0e05042
+Subproject commit 1884860fc01b25f295cd7c5e7ddc304a1a69e730
} Clean;
ANN static void clean_array_sub(Clean *a, Array_Sub b);
-ANN static void clean_type_list(Clean *a, Type_List b);
+ANN static void clean_tmplarg_list(Clean *a, TmplArg_List b);
ANN static void clean_tmpl(Clean *a, Tmpl *b);
ANN static void clean_range(Clean *a, Range *b);
ANN static void clean_type_decl(Clean *a, Type_Decl *b);
ANN Value find_value(const Type, const Symbol);
ANN m_bool isa(const Type, const Type) __attribute__((pure));
ANN m_bool isres(const Env, const Tag);
-ANN Type array_type(const Env, const Type, const m_uint);
+ANN Type array_type(const Env, const Type, const m_uint, const loc_t);
ANN Type find_common_anc(const Type, const Type) __attribute__((pure));
ANN Type array_base(Type) __attribute__((pure));
ANN Symbol array_sym(const Env env, const Type src,
ANN Type str2type(const Gwion, const m_str, const loc_t);
// those functions return a mp_alloced string
-ANEW ANN m_str tl2str(const Gwion, const Type_List, const loc_t);
+ANEW ANN m_str tl2str(const Gwion, const TmplArg_List, const loc_t);
ANEW ANN m_str type2str(const Gwion, const Type, const loc_t);
ANN static inline Type_Decl *type2td(const Gwion gwion, const Type t,
#define __TEMPLATE
ANN m_bool template_push_types(const Env, const Tmpl *);
ANN m_bool template_push(const Env env, const Type t);
-ANN Tmpl *mk_tmpl(const Env, const Tmpl *, const Type_List);
+ANN Tmpl *mk_tmpl(const Env, const Tmpl *, const TmplArg_List);
/*
//! returns the Tmpl of a class or enum def
ANN static inline Tmpl* get_tmpl(const Type t) {
ANN Func find_template_match(const Env env, const Value value,
Exp_Call *const exp);
ANN Func find_func_match(const Env env, const Func up, Exp_Call *const exp);
-ANN2(1,2) m_bool check_tmpl(const Env env, const Type_List tl, const Specialized_List sl, const loc_t pos, const bool is_spread);
+ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t pos, const bool is_spread);
#endif
};
ANN Type tmpl_exists(const Env env, struct tmpl_info *const info);
-ANN bool tmpl_global(const Env env, Type_List tl);
+ANN bool tmpl_global(const Env env, TmplArg_List tl);
#endif
-Subproject commit 3597b6e30bcbfb85a1fa65346ecf78b3c2231f61
+Subproject commit 04994e9dbc6acf0ff93c78c772a73ce4aab56b0e
#define clean_id_list(a, b) do {} while(0)
#define clean_specialized_list(a, b) do {} while(0)
-ANN static void clean_type_list(Clean *a, Type_List b) {
+ANN static void clean_tmplarg_list(Clean *a, TmplArg_List b) {
for(uint32_t i = 0; i < b->len; i++) {
TmplArg arg = *mp_vector_at(b, TmplArg, i);
if(arg.type == tmplarg_td)
ANN static void clean_tmpl(Clean *a, Tmpl *b) {
if (!b->call) clean_specialized_list(a, b->list);
- else clean_type_list(a, b->call);
+ else clean_tmplarg_list(a, b->call);
}
ANN static void clean_range(Clean *a, Range *b) {
ANN static void clean_type_decl(Clean *a, Type_Decl *b) {
if (b->array) clean_array_sub(a, b->array);
- if (b->types) clean_type_list(a, b->types);
+ if (b->types) clean_tmplarg_list(a, b->types);
if (b->fptr) clean_fptr_def(a, b->fptr);
if (b->next) clean_type_decl(a, b->next);
}
}
ANN static void clean_idx(Clean *a, struct EachIdx_ *b) {
- if (b->v) value_remref(b->v, a->gwion);
+ if (b->var.value) value_remref(b->var.value, a->gwion);
}
ANN static void clean_stmt_each(Clean *a, Stmt_Each b) {
++a->scope;
clean_exp(a, b->exp);
clean_stmt(a, b->body);
- if (b->v) mp_free(a->gwion->mp, Value, b->v);
+ if (b->var.value) mp_free(a->gwion->mp, Value, b->var.value);
if (b->idx) clean_idx(a, b->idx);
--a->scope;
}
return GW_OK;
}
-ANEW ANN static ArrayInfo *new_arrayinfo(const Emitter emit, const Type t) {
+ANEW ANN static ArrayInfo *new_arrayinfo(const Emitter emit, const Type t, const loc_t loc) {
const Type base = array_base(t);
ArrayInfo *info = mp_calloc(emit->gwion->mp, ArrayInfo);
vector_init(&info->type);
info->depth = get_depth(t);
for (long i = 1; i < info->depth; ++i)
- vector_add(&info->type, (vtype)array_type(emit->env, base, i));
+ vector_add(&info->type, (vtype)array_type(emit->env, base, i, loc));
vector_add(&info->type, (vtype)t);
info->base = base;
return info;
static ArrayInfo *emit_array_extend_inner(const Emitter emit, const Type t,
const Exp e, const uint is_ref) {
CHECK_BO(extend_indices(emit, e, get_depth(t)));
- ArrayInfo * info = new_arrayinfo(emit, t);
+ ArrayInfo * info = new_arrayinfo(emit, t, t->info->cdef->base.tag.loc);
const Instr alloc = emit_add_instr(emit, ArrayAlloc);
alloc->m_val = (m_uint)info;
if (!is_ref) CHECK_BO(arrayinfo_ctor(emit, info));
Capture_List caps = sporker.captures;
for (uint32_t i = 0; i < caps->len; i++) {
Capture *cap = mp_vector_at(caps, Capture, i);
- const Value v = cap->orig;
+ const Value v = cap->var.value;
struct Exp_ exp = {
.d = { .prim = {
- .d = { .var = cap->tag.sym },
+ .d = { .var = cap->var.tag.sym },
.value = v,
.prim_type = ae_prim_id
}},
? */emit_local(emit, emit->gwion->type[et_int])
/*: emit_local(emit, stmt->idx->v->type)*/;
- const m_uint val_offset = emit_localn(emit, stmt->v->type); // localn ?
+ const m_uint val_offset = emit_localn(emit, stmt->var.value->type); // localn ?
emit_regtomem(emit, arr_offset, 0);
emit_memsetimm(emit, key_offset, -1);
- stmt->v->from->offset = val_offset;
+ stmt->var.value->from->offset = val_offset;
//value_addref(stmt->v);
-_nspc_add_value(emit->env->curr, stmt->tag.sym, stmt->v);
- emit_debug(emit, stmt->v);
+_nspc_add_value(emit->env->curr, stmt->tag.sym, stmt->var.value);
+ emit_debug(emit, stmt->var.value);
if (stmt->idx) {
- stmt->idx->v->from->offset = key_offset;
-_nspc_add_value(emit->env->curr, stmt->idx->tag.sym, stmt->idx->v);
+ stmt->idx->var.value->from->offset = key_offset;
+_nspc_add_value(emit->env->curr, stmt->idx->var.tag.sym, stmt->idx->var.value);
//value_addref(stmt->idx->v);
- emit_debug(emit, stmt->idx->v);
+ emit_debug(emit, stmt->idx->var.value);
}
struct Looper loop = {.exp = stmt->exp,
.stmt = stmt->body,
if (stmt->idx) {
emit_memsetimm(emit, emit_local(emit, emit->gwion->type[et_int]), 0);
emit_memsetimm(emit, offset, -1);
- stmt->idx->v->from->offset = offset;
+ stmt->idx->var.value->from->offset = offset;
}
CHECK_BB(emit_exp_pop_next(emit, stmt->cond));
emit_regmove(emit, -SZ_INT);
f->code->native_func = (m_uint)func_ptr;
f->code->ret_type = f->def->base->ret_type;
if(f->def->base->tmpl) {
- const Type_List tl = f->def->base->tmpl->call;
+ const TmplArg_List tl = f->def->base->tmpl->call;
if(!tl) return;
const Specialized *spec = mp_vector_at(f->def->base->tmpl->list, Specialized, f->def->base->tmpl->list->len - 1);
if(!strcmp(s_name(spec->tag.sym), "...")) {
return insert_symbol(name);
}
-ANN Type array_type(const Env env, const Type src, const m_uint depth) {
+ANN Type array_type(const Env env, const Type src, const m_uint depth, const loc_t loc) {
if(!depth) return src;
const Symbol sym = array_sym(env, src, depth);
const Type type = nspc_lookup_type1(src->info->value->from->owner, sym);
if (type) return type;
const size_t tdepth = depth + src->array_depth;
- const Type base = tdepth > 1 ? array_type(env, src, tdepth - 1) : src;
- struct TemplateScan ts = {.t = base, /*.td=td*/ };
+ const Type base = tdepth > 1 ? array_type(env, src, tdepth - 1, loc) : src;
+ const Type_Decl td = { .tag = MK_TAG(insert_symbol(src->name), loc) };
+ struct TemplateScan ts = {.t = base, .td=&td };
struct Op_Import opi = {.op = insert_symbol("class"),
.lhs = env->gwion->type[et_array],
.data = (uintptr_t)&ts};
Tmpl *tmpl = ck.sl ? new_tmpl(gwi->gwion->mp, ck.sl) : NULL;
if (tmpl) CHECK_BO(template_push_types(gwi->gwion->env, tmpl));
DECL_OO(const Type, base, = known_type(gwi->gwion->env, td));
- const Type_List tl = td->types;
+ const TmplArg_List tl = td->types;
if (tflag(base, tflag_ntmpl)) td->types = NULL;
const Type p = !td->types ? known_type(gwi->gwion->env, td) : NULL;
td->types = tl;
}
ANN static Type_Decl *_str2td(const Gwion gwion, struct td_checker *tdc);
-ANN bool str2tl(const Gwion gwion, struct td_checker *tdc, Type_List *tl) {
+ANN bool str2tl(const Gwion gwion, struct td_checker *tdc, TmplArg_List *tl) {
// we probably need smth better
if(isalpha(*tdc->str)) {
TmplArg targ = {
return true;
}
-ANN static Type_List td_tmpl(const Gwion gwion, struct td_checker *tdc) {
+ANN static TmplArg_List td_tmpl(const Gwion gwion, struct td_checker *tdc) {
if (*tdc->str != ':') return NULL; // GW_PASS
++tdc->str;
if (*tdc->str != '[') {
GWION_ERR(tdc->pos, "invalid character");
- return (Type_List)GW_ERROR;
+ return (TmplArg_List)GW_ERROR;
}
++tdc->str;
- Type_List tl = new_mp_vector(gwion->mp, TmplArg, 0);
+ TmplArg_List tl = new_mp_vector(gwion->mp, TmplArg, 0);
if (!str2tl(gwion, tdc, &tl)) {
- free_type_list(gwion->mp, tl);
- return (Type_List)GW_ERROR;
+ free_tmplarg_list(gwion->mp, tl);
+ return (TmplArg_List)GW_ERROR;
}
if (tdc->str[0] != ']') {
- free_type_list(gwion->mp, tl);
+ free_tmplarg_list(gwion->mp, tl);
GWION_ERR(tdc->pos, "unfinished template");
- return (Type_List)GW_ERROR;
+ return (TmplArg_List)GW_ERROR;
}
++tdc->str;
return tl;
const m_str base = tdc->str;
tdc->str++;
Type_Decl *const ret_td = _str2td(gwion, tdc);
- const Type_List tl = td_tmpl(gwion, tdc);
- if (tl == (Type_List)GW_ERROR) {
+ const TmplArg_List tl = td_tmpl(gwion, tdc);
+ if (tl == (TmplArg_List)GW_ERROR) {
free_type_decl(gwion->mp, ret_td);
return NULL;
}
tdc->str++;
Arg_List args = fptr_args(gwion, tdc);
if (args == (Arg_List)GW_ERROR) {
- if(tl) free_type_list(gwion->mp, tl);
+ if(tl) free_tmplarg_list(gwion->mp, tl);
free_type_decl(gwion->mp, ret_td);
return NULL;
}
if(tdc->str[0] != ')' || tdc->str[1] != ')') {
- if(tl) free_type_list(gwion->mp, tl);
+ if(tl) free_tmplarg_list(gwion->mp, tl);
if(args) free_arg_list(gwion->mp, args);
return NULL;
}
tdc->str += 2;
struct AC ac = {.str = tdc->str, .pos = tdc->pos};
if(ac_run(gwion, &ac) < 0 ) {
- if(tl) free_type_list(gwion->mp, tl);
+ if(tl) free_tmplarg_list(gwion->mp, tl);
if(args) free_arg_list(gwion->mp, args);
return NULL;
}
return td;
}
DECL_OO(const Symbol, sym, = __str2sym(gwion, tdc));
- Type_List tl = td_tmpl(gwion, tdc);
+ TmplArg_List tl = td_tmpl(gwion, tdc);
struct AC ac = {.str = tdc->str, .pos = tdc->pos};
CHECK_BO(ac_run(gwion, &ac));
tdc->str = ac.str;
- if (tl == (Type_List)GW_ERROR) return NULL;
+ if (tl == (TmplArg_List)GW_ERROR) return NULL;
const uint option = get_n(tdc, '?');
Type_Decl *next = NULL;
if (*tdc->str == '.') {
++tdc->str;
if (!(next = _str2td(gwion, tdc))) {
- if (tl) free_type_list(gwion->mp, tl);
+ if (tl) free_tmplarg_list(gwion->mp, tl);
if (ac.base) free_exp(gwion->mp, ac.base);
return NULL;
}
}
struct td_info {
- Type_List tl;
+ TmplArg_List tl;
Gwfmt *fmt;
};
ANN static m_bool td_info_run(const Env env, struct td_info *info) {
const Gwion gwion = env->gwion;
- Type_List tl = info->tl;
+ TmplArg_List tl = info->tl;
for(uint32_t i = 0; i < tl->len; i++) {
if (i) text_add(&info->fmt->ls->text, ",");
TmplArg *targ = mp_vector_at(tl, TmplArg, i);
return text.str;
}
-ANEW ANN m_str tl2str(const Gwion gwion, const Type_List tl,
+ANEW ANN m_str tl2str(const Gwion gwion, const TmplArg_List tl,
const loc_t pos NUSED) {
struct GwfmtState ls = {.minimize=true, .ppa = gwion->ppa};
text_init(&ls.text, gwion->mp);
const Instr loop = (Instr)vector_at(&emit->code->instr, pc);
loop->m_val = emit_code_size(emit);
const Instr end = emit_add_instr(emit, ArrayInit);
- const Type t = array_type(emit->env, base, i + 1);
- end->m_val = (m_uint)array_type(emit->env, base, i + 1);
+ const Type t = array_type(emit->env, base, i + 1, base->info->cdef->base.tag.loc);
+ end->m_val = (m_uint)array_type(emit->env, base, i + 1, base->info->cdef->base.tag.loc);
end->m_val2 = t->actual_size ?: t->size;
}
}
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);
+ return array_type(env, array_base(t), t->array_depth - array->depth, array->exp->pos);
const Exp curr = take_exp(array->exp, t->array_depth);
struct Array_Sub_ next = {curr->next, array_base(t),
DECL_OO(const Type, t, = array_base_simple(base));
if(!tflag(base, tflag_ref)) {
const m_uint depth = base->array_depth - 1;
- return depth ? array_type(env, t, depth) : t;
+ return depth ? array_type(env, t, depth, exp->pos) : t;
}
const Type inner = (Type)vector_front(&base->info->tuple->contains);
const Type refbase = array_base_simple(inner);
const m_uint depth = inner->array_depth - 1;
- return depth ? array_type(env, refbase, depth) : refbase;
+ return depth ? array_type(env, refbase, depth, exp->pos) : refbase;
}
// rewrite me
}
ANN Type upvalue_type(const Env env, Capture *cap) {
- const Value v = nspc_lookup_value1(env->curr, cap->tag.sym);
- if(!v) ERR_O(cap->tag.loc, _("non existing value")); // did_you_mean
+ const Value v = nspc_lookup_value1(env->curr, cap->var.tag.sym);
+ if(!v) ERR_O(cap->var.tag.loc, _("non existing value")); // did_you_mean
if(cap->is_ref && not_upvalue(env, v))
- ERR_O(cap->tag.loc, _("can't take ref of a scoped value"));
- cap->orig = v;
+ ERR_O(cap->var.tag.loc, _("can't take ref of a scoped value"));
+ cap->var.value = v;
const Type base_type = !tflag(v->type, tflag_ref) ? v->type : (Type)vector_front(&v->type->info->tuple->contains);
- return !cap->is_ref ? base_type : ref_type(env->gwion, base_type, cap->tag.loc);
+ return !cap->is_ref ? base_type : ref_type(env->gwion, base_type, cap->var.tag.loc);
}
ANN void free_captures(const VM_Shred shred, m_bit *const caps) {
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->tag.sym;
- e->d.prim.value = cap->orig;
- e->type = cap->orig->type;
+ e->d.prim.d.var = cap->var.tag.sym;
+ e->d.prim.value = cap->var.value;
+ e->type = cap->var.value->type;
exp_setvar(e, cap->is_ref);
CHECK_BB(emit_exp(emit, e));
if(!cap->is_ref && tflag(cap->temp->type, tflag_compound))
ANN static void _fptr_tmpl_push(const Env env, const Func f) {
const Tmpl *tmpl = f->def->base->tmpl;
if (!tmpl) return;
- Type_List tl = tmpl->call;
+ TmplArg_List tl = tmpl->call;
if (!tl) return;
Specialized_List sl = tmpl->list;
for(uint32_t i = 0; i < sl->len; i++) {
// here move to arguments
for(uint32_t i = 0; i < l->def->captures->len; i++) {
Capture *cap = mp_vector_at(l->def->captures, Capture, i);
- const Value v = nspc_lookup_value1(env->curr, cap->tag.sym);
- if(!v) ERR_B(cap->tag.loc, _("unknown value in capture"));
+ const Value v = nspc_lookup_value1(env->curr, cap->var.tag.sym);
+ if(!v) ERR_B(cap->var.tag.loc, _("unknown value in capture"));
DECL_OB(const Type, t, = upvalue_type(env, cap));
- cap->temp = new_value(env, t, s_name(cap->tag.sym), cap->tag.loc);
- cap->orig = v;
+ cap->temp = new_value(env, t, s_name(cap->var.tag.sym), cap->var.tag.loc);
+ cap->var.value = v;
}
}
#include "traverse.h"
#include "gwi.h"
-ANN static bool is_base(const Env env, const Type_List tl) {
+ANN static bool is_base(const Env env, const TmplArg_List tl) {
for(uint32_t i = 0; i < tl->len; i++) {
// can call with const happen?
TmplArg arg = *mp_vector_at(tl, TmplArg, i);
Func_Base *const fbase = new_func_base(env->gwion->mp, cpy_type_decl(env->gwion->mp, base->td), info.name, args, ae_flag_none, base->tag.loc);
fbase->tmpl = cpy_tmpl(env->gwion->mp, base->tmpl);
if(!is_base(env, ts->td->types))
- fbase->tmpl->call = cpy_type_list(env->gwion->mp, ts->td->types);
+ fbase->tmpl->call = cpy_tmplarg_list(env->gwion->mp, ts->td->types);
const Fptr_Def fdef = new_fptr_def(env->gwion->mp, cpy_func_base(env->gwion->mp, fbase));
fdef->base->tag.sym = info.name;
struct EnvSet es = {.env = env,
static OP_EMIT(opem_dict_each) {
Looper *loop = (Looper *)data;
HMapInfo *const hinfo = (HMapInfo*)loop->exp->type->nspc->class_data;
- if(loop->idx && !loop->init) loop->idx->v->from->offset = emit_localn(emit, hinfo->key);
+ if(loop->idx && !loop->init) loop->idx->var.value->from->offset = emit_localn(emit, hinfo->key);
const Instr instr = emit_add_instr(emit, !loop->idx ? DictEach : DictEachIdx);
instr->m_val2 = loop->offset;
- if(loop->idx) instr->m_val = loop->idx->v->from->offset;
+ if(loop->idx) instr->m_val = loop->idx->var.value->from->offset;
if(loop->n)instr->m_val2 += SZ_INT;
const Instr go = emit_add_instr(emit, BranchNeqInt);
if(!loop->n) loop->instr = go;
const Class_Def cdef = cpy_class_def(env->gwion->mp, env->gwion->type[et_dict]->info->cdef);
cdef->base.ext = type2td(env->gwion, env->gwion->type[et_dict], ts->td->tag.loc);
cdef->base.tag.sym = info.name;
- cdef->base.tmpl->call = cpy_type_list(env->gwion->mp, info.td->types);
+ cdef->base.tmpl->call = cpy_tmplarg_list(env->gwion->mp, info.td->types);
const bool is_global = tmpl_global(env, ts->td->types);
const m_uint scope = is_global ? env_push_global(env) : env->scope->depth;
v->d.func_ref->def->d.dl_func_ptr = NULL; // why
const Func_Def def = cpy_func_def(env->gwion->mp, v->d.func_ref->def);
if (vflag(v, vflag_builtin)) v->d.func_ref->def->d.dl_func_ptr = xfun;
- def->base->tmpl->call = cpy_type_list(env->gwion->mp, fbase->base->tmpl->call);
+ def->base->tmpl->call = cpy_tmplarg_list(env->gwion->mp, fbase->base->tmpl->call);
CHECK_BO(traverse_dot_tmpl(emit, def, v));
if (vflag(v, vflag_builtin)) builtin_func(emit->gwion, def->base->func, xfun);
return def;
const Exp exp = (Exp)data;
const Range *range = exp->d.prim.d.range;
const Exp e = range->start ?: range->end;
- return array_type(env, e->type, 1);
+ return array_type(env, e->type, 1, e->pos);
}
static OP_EMIT(opem_int_range) {
return sym;
}
-ANN static m_bool template_match(Specialized_List sl, Type_List tl) {
+ANN static m_bool template_match(Specialized_List sl, TmplArg_List tl) {
// uint32_t i = 0;
// while ((call = call->next)) i++;
//&& (base = base->next))
return _tmpl_exists(env, info->name);
}
-ANN bool tmpl_global(const Env env, Type_List tl) {
+ANN bool tmpl_global(const Env env, TmplArg_List tl) {
for(uint32_t i = 0; i < tl->len; i++) {
TmplArg arg = *mp_vector_at(tl, TmplArg, i);
if(unlikely(arg.type == tmplarg_exp)) continue;
for(uint32_t i = 0; i < unary->captures->len; i++) {
Capture *const cap = mp_vector_at(unary->captures, Capture, i);
DECL_OO(const Type, t, = upvalue_type(env, cap));
- cap->temp = new_value(env, t, s_name(cap->tag.sym), cap->tag.loc);
+ cap->temp = new_value(env, t, s_name(cap->var.tag.sym), cap->var.tag.loc);
cap->temp->from->offset = offset;
offset += cap->temp->type->size;
}
if(unary->captures) {
for(uint32_t i = 0; i < unary->captures->len; i++) {
Capture *const cap = mp_vector_at(unary->captures, Capture, i);
- valid_value(env, cap->tag.sym, cap->temp);
+ valid_value(env, cap->var.tag.sym, cap->temp);
}
}
const Func f = env->func;
do
if (check_collection(env, type, e, loc) < 0) err = true;
while ((e = e->next));
- if (!err) return array_type(env, array_base_simple(type), type->array_depth + 1);
+ if (!err) return array_type(env, array_base_simple(type), type->array_depth + 1, loc);
env_set_error(env, true);
return NULL;
}
// get the type of the function
// without the mangling
-ANN static inline Type type_list_base_func(const Type type) {
+ANN static inline Type tmplarg_list_base_func(const Type type) {
const Nspc owner = type->info->value->from->owner;
const Symbol xid = type->info->func->def->base->tag.sym;
return nspc_lookup_type0(owner, xid);
}
-ANN static inline Type type_list_base(const Gwion gwion, const Type type) {
- return !(is_func(gwion, type)) ? type : type_list_base_func(type);
+ANN static inline Type tmplarg_list_base(const Gwion gwion, const Type type) {
+ return !(is_func(gwion, type)) ? type : tmplarg_list_base_func(type);
}
ANN static Type_Decl* mk_td(const Env env, Type_Decl *td,
- const Type type, const loc_t pos) {
- const Type base = type_list_base(env->gwion, type);
+ const Type type, const loc_t loc) {
+ const Type base = tmplarg_list_base(env->gwion, type);
const Type t = !td->array ?
- base : array_type(env, base, td->array->depth);
- return type2td(env->gwion, t, pos);
+ base : array_type(env, base, td->array->depth, loc);
+ return type2td(env->gwion, t, loc);
}
ANN static Type tmplarg_match(const Env env, const Symbol xid, const Symbol tgt, const Type t) {
return func->def->base->ret_type;
}
-ANN static Type_List check_template_args(const Env env, Exp_Call *exp,
+ANN static TmplArg_List check_template_args(const Env env, Exp_Call *exp,
const Tmpl *tm, const Func_Def fdef) {
Specialized_List sl = tm->list;
const bool spread = is_spread_tmpl(fdef->base->tmpl);
const uint32_t len = sl->len - spread;
- Type_List tl = new_mp_vector(env->gwion->mp, TmplArg, len);
+ TmplArg_List tl = new_mp_vector(env->gwion->mp, TmplArg, len);
m_uint args_number = 0;
// infer template types from args
// should not work with const generic
template_arg = template_arg->next;
}
}
- if (args_number < len) //TODO: free type_list
+ if (args_number < len) //TODO: free tmplarg_list
ERR_O(exp->func->pos, _("not able to infer types for template call."))
if(spread) {
value->d.func_ref ? value->d.func_ref->def : t->info->func->def;
Tmpl *tm = fdef->base->tmpl;
if (tm->call) return check_predefined(env, exp, value, tm, fdef);
- DECL_OO(const Type_List, tl, = check_template_args(env, exp, tm, fdef));
+ DECL_OO(const TmplArg_List, tl, = check_template_args(env, exp, tm, fdef));
Tmpl tmpl = {.call = tl};
((Exp_Call *)exp)->tmpl = &tmpl;
DECL_OO(const Func, func, = get_template_func(env, exp, value));
return NULL;
}
Arg arg = { .var = MK_VAR(
- type2td(env->gwion, t, cap->tag.loc),
- (Var_Decl){ .tag = MK_TAG(cap->tag.sym, cap->tag.loc) }
+ type2td(env->gwion, t, cap->var.tag.loc),
+ (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->tag.sym, cap->tag.loc);
+ const 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;
}
return false;
}
-ANN static bool tl_match(const Env env, const Type_List tl0, const Type_List tl1) {
+ANN static bool tl_match(const Env env, const TmplArg_List tl0, const TmplArg_List tl1) {
if (tl0->len != tl1->len) return false;
for(uint32_t i = 0; i < tl0->len; i++) {
TmplArg targ0 = *mp_vector_at(tl0, TmplArg, i);
}
ANN static void check_idx(const Env env, const Type base, struct EachIdx_ *const idx) {
- idx->v = new_value(env, base, s_name(idx->tag.sym), idx->tag.loc);
- valid_value(env, idx->tag.sym, idx->v);
- SET_FLAG(idx->v, const);
+ idx->var.value = new_value(env, base, s_name(idx->var.tag.sym), idx->var.tag.loc);
+ valid_value(env, idx->var.tag.sym, idx->var.value);
+ SET_FLAG(idx->var.value, const);
}
/** sets for the key expression value
.lhs = exp->type,
.op = insert_symbol("@each_idx"),
.data = (m_uint)exp,
- .pos = idx->tag.loc
+ .pos = idx->var.tag.loc
};
DECL_OB(const Type, t, = op_check(env, &opi));
check_idx(env, t, idx);
if (stmt->idx)
CHECK_BB(check_each_idx(env, stmt->exp, stmt->idx));
DECL_OB(const Type, ret, = check_each_val(env, stmt->exp));
- stmt->v = new_value(env, ret, s_name(stmt->tag.sym), stmt->tag.loc);
- valid_value(env, stmt->tag.sym, stmt->v);
+ stmt->var.value = new_value(env, ret, s_name(stmt->tag.sym), stmt->tag.loc);
+ valid_value(env, stmt->tag.sym, stmt->var.value);
return check_conts(env, stmt_self(stmt), stmt->body);
}
uint32_t offset = fdef->stack_depth;
for(uint32_t i = 0; i < fdef->captures->len; i++) {
Capture *cap = mp_vector_at(fdef->captures, Capture, i);
- valid_value(env, cap->tag.sym, cap->temp);
+ valid_value(env, cap->var.tag.sym, cap->temp);
cap->temp->from->offset = offset;
offset += cap->temp->type->size;
}
const Value v;
Exp_Call *const e;
const m_str tmpl_name;
- const Type_List types;
+ const TmplArg_List types;
};
ANN static inline Value template_get_ready(const Env env, const Value v,
CHECK_BO(template_push_types(env, &tmpl));
Func_Base *const fbase = cpy_func_base(env->gwion->mp, base->base);
fbase->tag.sym = sym;
- fbase->tmpl->call = cpy_type_list(env->gwion->mp, ra->types);
+ fbase->tmpl->call = cpy_tmplarg_list(env->gwion->mp, ra->types);
const Fptr_Def fptr = new_fptr_def(env->gwion->mp, fbase);
const Func m_func = ensure_fptr(env, ra, fptr);
if (m_func)
DECL_OO(const Value, value, = template_get_ready(env, ra->v, "template", i));
if (value->d.func_ref->def->builtin) set_vflag(value, vflag_builtin);
const Func_Def fdef = cpy_func_def(env->gwion->mp, value->d.func_ref->def);
- fdef->base->tmpl->call = cpy_type_list(env->gwion->mp, ra->types);
+ fdef->base->tmpl->call = cpy_tmplarg_list(env->gwion->mp, ra->types);
fdef->vt_index = i;
if(is_spread_tmpl(value->d.func_ref->def->base->tmpl)) {
ANN static Func find_tmpl(const Env env, const Value v, Exp_Call *const exp,
const m_str tmpl_name) {
- const Type_List types = exp->tmpl->call;
+ const TmplArg_List types = exp->tmpl->call;
const Func former = env->func;
const m_uint scope = env->scope->depth;
struct EnvSet es = {.env = env,
ANN static Func _find_template_match(const Env env, const Value v,
Exp_Call *const exp) {
DECL_OO(const Func, f, = __find_template_match(env, v, exp));
- Type_List tl = exp->tmpl->call;
+ TmplArg_List tl = exp->tmpl->call;
Specialized_List sl = f->def->base->tmpl->list;
for(uint32_t i = 0; i < tl->len; i++) {
Specialized * spec = mp_vector_at(sl, Specialized, i);
const Type base = array_base_simple(t);
return !base->info->parent
? t->info->parent
- : array_type(env, base->info->parent, depth);
+ : array_type(env, base->info->parent, depth, t->info->cdef->base.tag.loc);
}
ANN static Type op_check_inner(const Env env, struct OpChecker *ock,
return true;
}
-ANN static void op_tmpl_set(const Gwion gwion, Type_List tl,
+ANN static void op_tmpl_set(const Gwion gwion, TmplArg_List tl,
const Type t, const loc_t pos, const uint32_t idx) {
TmplArg arg = {.type = tmplarg_td, .d = { .td = type2td(gwion, t, pos)}};
mp_vector_set(tl, TmplArg, idx, arg);
if (nspc_lookup_value1(env->curr, stmt->tag.sym))
ERR_B(stmt_self(stmt)->pos, _("foreach value '%s' is already defined"),
s_name(stmt->tag.sym))
- if (stmt->idx && nspc_lookup_value1(env->curr, stmt->idx->tag.sym))
- ERR_B(stmt->idx->tag.loc, _("foreach index '%s' is already defined"),
- s_name(stmt->idx->tag.sym))
+ if (stmt->idx && nspc_lookup_value1(env->curr, stmt->idx->var.tag.sym))
+ ERR_B(stmt->idx->var.tag.loc, _("foreach index '%s' is already defined"),
+ s_name(stmt->idx->var.tag.sym))
return GW_OK;
}
scan1_stmt(env, stmt->body) < 0) ? 1 : -1)
describe_ret_nspc(each, Stmt_Each,, !(stmt_each_defined(env, stmt) < 0 || scan1_exp(env, stmt->exp) < 0 ||
scan1_stmt(env, stmt->body) < 0) ? 1 : -1)
-describe_ret_nspc(loop, Stmt_Loop,, !( (!stmt->idx ? GW_OK : shadow_var(env, stmt->idx->tag)) < 0 ||
+describe_ret_nspc(loop, Stmt_Loop,, !( (!stmt->idx ? GW_OK : shadow_var(env, stmt->idx->var.tag)) < 0 ||
scan1_exp(env, stmt->cond) < 0 ||
scan1_stmt(env, stmt->body) < 0) ? 1 : -1)
ANN static m_bool scan1_class_tmpl(const Env env, const Class_Def c) {
Specialized_List sl = c->base.tmpl->list;
- Type_List tl = c->base.tmpl->call;
+ TmplArg_List tl = c->base.tmpl->call;
env_push_type(env, c->base.type);
m_bool ret = GW_OK;
// check len
if (c->body) {
const m_uint scope = env_push_type(env, t);
const Tmpl *tmpl = cdef->base.tmpl;
- if(tmpl && tmpl->call && tmpl->call != (Type_List)1 && tmpl->list)
+ if(tmpl && tmpl->call && tmpl->call != (TmplArg_List)1 && tmpl->list)
template_push_types(env, tmpl);
const m_bool ret = scan2_class_body(env, c);
- if(tmpl && tmpl->call && tmpl->call != (Type_List)1 && tmpl->list)
+ if(tmpl && tmpl->call && tmpl->call != (TmplArg_List)1 && tmpl->list)
nspc_pop_type(env->gwion->mp, env->curr);
env_pop(env, scope);
return ret;
}
ANN static inline int actual(const Tmpl *tmpl) {
- return tmpl->call && tmpl->call != (Type_List)1 && tmpl->list;
+ return tmpl->call && tmpl->call != (TmplArg_List)1 && tmpl->list;
}
ANN static inline m_bool tmpl_push(const Env env, const Tmpl *tmpl) {
ANN static m_bool _push_types(const Env env, const Nspc nspc,
const Tmpl *tmpl) {
Specialized_List sl = tmpl->list;
- Type_List tl = tmpl->call;
+ TmplArg_List tl = tmpl->call;
Specialized *spec = mp_vector_at(sl, Specialized, sl->len - 1);
const uint32_t len = strcmp(s_name(spec->tag.sym), "...") ? sl->len : sl->len-1;
POP_RET(GW_ERROR);
}
-ANN Tmpl *mk_tmpl(const Env env, const Tmpl *tm, const Type_List types) {
+ANN Tmpl *mk_tmpl(const Env env, const Tmpl *tm, const TmplArg_List types) {
Tmpl *tmpl = new_tmpl(env->gwion->mp, tm->list);
- tmpl->call = cpy_type_list(env->gwion->mp, types);
+ tmpl->call = cpy_tmplarg_list(env->gwion->mp, types);
return tmpl;
}
return !strcmp(s_name(spec->tag.sym), "...");
}
-ANN2(1,2) m_bool check_tmpl(const Env env, const Type_List tl, const Specialized_List sl, const loc_t pos, const bool is_spread) {
+ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t pos, const bool is_spread) {
if (!sl || sl->len > tl->len || (tl->len != sl->len && !is_spread))
ERR_B(pos, "invalid template type number");
for (uint32_t i = 0; i < sl->len; i++) {
return ret;
}
struct TemplateScan ts = {.t = t, .td = td};
- Type_List tl = td->types;
+ TmplArg_List tl = td->types;
Specialized_List sl = tmpl
? tmpl->list : NULL;
const bool is_spread = is_spread_tmpl(tmpl);
env->context = ctx;
env->name = name;
if (!td->array) return ret;
- return array_type(env, ret, td->array->depth);
+ return array_type(env, ret, td->array->depth, td->tag.loc);
}
return !t->array_depth ? _scan_type(env, t, td) : t;
}
ANN static Type _option(const Env env, Type_Decl *td, const uint8_t n) {
const Array_Sub array = td->array;
td->array = NULL;
- Type_List tl = new_mp_vector(env->gwion->mp, TmplArg, 1);
+ TmplArg_List tl = new_mp_vector(env->gwion->mp, TmplArg, 1);
TmplArg arg = { .type = tmplarg_td, .d = { .td = td } };
mp_vector_set(tl, TmplArg, 0, arg);
Type_Decl tmp = { .tag = MK_TAG(insert_symbol("Option"), td->tag.loc), .types = tl };
}
ANN static Type _ref(const Env env, Type_Decl *td) {
- Type_List tl = new_mp_vector(env->gwion->mp, TmplArg, 1);
+ TmplArg_List tl = new_mp_vector(env->gwion->mp, TmplArg, 1);
TmplArg arg = { .type = tmplarg_td, .d = { .td = td } };
mp_vector_set(tl, TmplArg, 0, arg);
Type_Decl tmp = {.tag = MK_TAG(insert_symbol("Ref"), td->tag.loc), .types = tl};
DECL_OO(const Type, t, = !td->ref ? type : ref(env, td));
DECL_OO(const Type, ret, = !td->option ? t : option(env, td));
const Array_Sub array = last->array;
- return !array ? ret : array_type(env, ret, array->depth);
+ return !array ? ret : array_type(env, ret, array->depth, td->tag.loc);
}
ANN static inline void *type_unknown(const Env env, const Type_Decl *td) {