-Subproject commit 1292b905b96915cdce6627bcfce3490f415c37fa
+Subproject commit f5b426bcc8570dabb40dcccc8f5b5ba3236b002e
-Subproject commit a1d3a1680d6f680199f6793f599629847a8f9759
+Subproject commit b6a9fa7512897dc1420549c511561b94f722d34c
uint16_t weight;
ae_flag flag;
enum tflag tflag;
+ bool error;
};
REF_FUNC(Type, type)
struct Vector_ unroll_v;
Instr instr;
// };
- struct EachIdx_ *idx;
+ Var_Decl *idx;
bool init;
};
#endif
--a->scope;
}
-ANN static void clean_idx(Clean *a, struct EachIdx_ *b) {
- 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);
+ // use clean var_decl?
if (b->var.value) mp_free(a->gwion->mp, Value, b->var.value);
- if (b->idx) clean_idx(a, b->idx);
+ if (b->idx.value) clean_var_decl(a, &b->idx);
--a->scope;
}
++a->scope;
clean_exp(a, b->cond);
clean_stmt(a, b->body);
+ if(b->idx.value) clean_var_decl(a, &b->idx);
--a->scope;
}
if(isa(v->type, gwion->type[et_class])) {
const Type t = (Type)v->d.ptr;
type_addref(t);
- mk_class(gwion->env, t, (loc_t) {});
+ mk_class(gwion->env, t, t->info->value->from->loc);
nspc_add_type(gwion->env->curr, insert_symbol(gwion->st, v->name), t);
} else
valid_value(gwion->env, insert_symbol(gwion->st, v->name), v);
return ret;
}
-static pos_t pos = { 1 , 1 };
-void gwion_set_default_pos(const pos_t _pos) {
- pos = _pos;
-}
ANN static inline bool _check(struct Gwion_ *gwion, struct Compiler *c) {
struct AstGetter_ arg = {c->name, c->file, gwion->st, .ppa = gwion->ppa};
- CHECK_B((c->ast = parse_pos(&arg, pos)));
+ CHECK_B((c->ast = parse(&arg)));
gwion->env->name = c->name;
return passes(gwion, c);
}
static const f_instr allocword[4] = {AllocWord, AllocWord2, AllocWord3,
RegPushMem4};
-ANN static bool emit_class_def(const Emitter, const Class_Def);
+ANN static bool emit_class_def(const Emitter, const Class_Def);
ANN static bool emit_cdef(const Emitter, const Type);
ANN static bool ensure_emit(const Emitter emit, const Type t) {
const Type t = decl->type;
const bool emit_addr = exp_getvar(exp_self(decl));
if(GET_FLAG(decl->var.vd.value, late) || GET_FLAG(decl->var.td, late)) {
- if(!emit_addr)
- decl_expand(emit, t);
+ if(!emit_addr) decl_expand(emit, t);
return true;
}
if(!decl->args && !tflag(t, tflag_ctor) && emit_addr)
emit_memsetimm(emit, key_offset, -1);
stmt->var.value->from->offset = val_offset;
//value_addref(stmt->v);
-_nspc_add_value(emit->env->curr, stmt->tag.sym, stmt->var.value);
+ _nspc_add_value(emit->env->curr, stmt->var.tag.sym, stmt->var.value);
emit_debug(emit, stmt->var.value);
- if (stmt->idx) {
- stmt->idx->var.value->from->offset = key_offset;
-_nspc_add_value(emit->env->curr, stmt->idx->var.tag.sym, stmt->idx->var.value);
+ if (stmt->idx.tag.sym) {
+ stmt->idx.value->from->offset = key_offset;
+_nspc_add_value(emit->env->curr, stmt->idx.tag.sym, stmt->var.value);
//value_addref(stmt->idx->v);
- emit_debug(emit, stmt->idx->var.value);
+ emit_debug(emit, stmt->idx.value);
}
struct Looper loop = {.exp = stmt->exp,
.stmt = stmt->body,
.n = n,
.roll = each_op,
.unroll = each_op,
- .idx = stmt->idx,
+ .idx = stmt->idx.tag.sym ? &stmt->idx : NULL,
.init = false
};
if (n) {
m_uint end_pc = 0;
const bool ret = _emit_stmt_each(emit, stmt, &end_pc);
emit_pop_stack(emit, end_pc);
-nspc_pop_value(emit->gwion->mp, emit->env->curr);
+ nspc_pop_value(emit->gwion->mp, emit->env->curr);
emit->status.unroll = 0;
return ret;
}
emit->status.unroll = 0;
}
const m_uint offset = emit_local(emit, emit->gwion->type[et_int]);
- if (stmt->idx) {
+ if (stmt->idx.tag.sym) {
emit_memsetimm(emit, emit_local(emit, emit->gwion->type[et_int]), 0);
emit_memsetimm(emit, offset, -1);
- stmt->idx->var.value->from->offset = offset;
+ stmt->idx.value->from->offset = offset;
}
CHECK_B(emit_exp_pop_next(emit, stmt->cond));
emit_regmove(emit, -SZ_INT);
- emit_regtomem(emit, offset + !!stmt->idx * SZ_INT, 0);
+ emit_regtomem(emit, offset + !!stmt->idx.tag.sym * SZ_INT, 0);
*index = emit_code_size(emit);
struct Looper loop = {.exp = stmt->cond,
.stmt = stmt->body,
.offset = offset,
.n = n,
.roll =
- !stmt->idx ? stmt_loop_roll : stmt_loop_roll_idx};
+ !stmt->idx.tag.sym ? stmt_loop_roll : stmt_loop_roll_idx};
CHECK_B(looper_run(emit, &loop));
const Instr _goto = emit_add_instr(emit, Goto);
_goto->m_val = *index;
}
ANN static bool section_fdef(const Gwi gwi, const Func_Def fdef) {
- Section section = MK_SECTION(func, func_def, fdef);
+ Section section = MK_SECTION(func, func_def, fdef, gwi->loc);
gwi_body(gwi, §ion);
return true;
}
}
ANN static bool section_fptr(const Gwi gwi, const Fptr_Def fdef) {
- Section section = MK_SECTION(fptr, fptr_def, fdef);
+ Section section = MK_SECTION(fptr, fptr_def, fdef, gwi->loc);
gwi_body(gwi, §ion);
return true;
}
gwi->gwfmt = &gwfmter;
const bool ret = f(gwi);
fprintf(stdout, "%s", ls.text.str);
+ free_mstr(gwi->gwion->mp, ls.text.str);
return ret;
}
ANN static bool gwi_item_tmpl(const Gwi gwi) {
Stmt_List slist = new_mp_vector(gwi->gwion->mp, Stmt, 1);
mp_vector_set(slist, Stmt, 0, MK_STMT_EXP(gwi->loc, gwi->ck->exp));
- Section section = MK_SECTION(stmt, stmt_list, slist);
+ Section section = MK_SECTION(stmt, stmt_list, slist, gwi->loc);
gwi_body(gwi, §ion);
mp_free2(gwi->gwion->mp, sizeof(ImportCK), gwi->ck);
gwi->ck = NULL;
free_prim_def(gwi->gwion->mp, pdef);
return ret;
}
- Section section = MK_SECTION(primitive, prim_def, pdef);
+ Section section = MK_SECTION(primitive, prim_def, pdef, gwi->loc);
gwi_body(gwi, §ion);
return true;
}
= ts->t != t_array ? ts->t : known_type(env, mp_vector_at(ts->td->types, TmplArg, 0)->d.td));
if (base->size == 0) {
gwerr_basic("Can't use type of size 0 as array base", NULL, NULL,
- "/dev/null", (loc_t) {}, 0);
+ env->context->name, ts->td->tag.loc, 0);
env_set_error(env, true);
return env->gwion->type[et_error];
}
if (tflag(base, tflag_ref)) {
- gwerr_basic("Can't use ref types as array base", NULL, NULL, "/dev/null",
- (loc_t) {}, 0);
+ gwerr_basic("Can't use ref types as array base", NULL, NULL,
+ env->context->name, ts->td->tag.loc, 0);
env_set_error(env, true);
return env->gwion->type[et_error];
}
const Type type = nspc_lookup_type1(base->info->value->from->owner, sym);
if (type) return type;
const Class_Def cdef = cpy_class_def(env->gwion->mp, c);
- cdef->base.ext = type2td(env->gwion, t_array, (loc_t){});
+ cdef->base.ext = type2td(env->gwion, t_array, t_array->info->value->from->loc);
cdef->base.tag.sym = sym;
cdef->base.tmpl->call = new_mp_vector(env->gwion->mp, TmplArg, 1);
- TmplArg arg = {.type = tmplarg_td, .d = {.td = type2td(env->gwion, base, (loc_t){})} };
+ TmplArg arg = {.type = tmplarg_td, .d = {.td = type2td(env->gwion, base, base->info->value->from->loc)} };
mp_vector_set(cdef->base.tmpl->call, TmplArg, 0, arg);
const Context ctx = env->context;
env->context = base->info->value->from->ctx;
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->var.value->from->offset = emit_localn(emit, hinfo->key);
- const Instr instr = emit_add_instr(emit, !loop->idx ? DictEach : DictEachIdx);
+ if(loop->idx && !loop->init) loop->idx->value->from->offset = emit_localn(emit, hinfo->key);
+ const Instr instr = emit_add_instr(emit, !loop->idx->tag.sym ? DictEach : DictEachIdx);
instr->m_val2 = loop->offset;
- if(loop->idx) instr->m_val = loop->idx->var.value->from->offset;
+ if(loop->idx) instr->m_val = loop->idx->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;
do {
if(curr->type) continue;
if(curr->poison) continue;
- if(!(curr->type = check_exp_func[curr->exp_type](env, &curr->d))) {
+ if(!(curr->type = check_exp_func[curr->exp_type](env, &curr->d)) || curr->type->error) {
POISON_NODE(ok, env, curr);
continue;
}
return true;
}
-ANN static void check_idx(const Env env, const Type base, struct EachIdx_ *const idx) {
- idx->var.value = new_value(env, base, idx->var.tag);
- valid_value(env, idx->var.tag.sym, idx->var.value);
- SET_FLAG(idx->var.value, const);
+ANN static void check_idx(const Env env, const Type base, Var_Decl *const idx) {
+ idx->value = new_value(env, base, idx->tag);
+ valid_value(env, idx->tag.sym, idx->value);
+ SET_FLAG(idx->value, const);
}
/** sets for the key expression value
with eg type *int* for an array or the *Key* type of a Dict **/
-ANN static bool check_each_idx(const Env env, Exp* exp, struct EachIdx_ *const idx) {
+ANN static bool check_each_idx(const Env env, Exp* exp, Var_Decl *const idx) {
struct Op_Import opi = {
.lhs = exp->type,
.op = insert_symbol("@each_idx"),
.data = (m_uint)exp,
- .loc = idx->var.tag.loc
+ .loc = idx->tag.loc
};
DECL_B(const Type, t, = op_check(env, &opi));
check_idx(env, t, idx);
ANN static bool do_stmt_each(const Env env, const Stmt_Each stmt) {
CHECK_B(check_exp(env, stmt->exp));
- if (stmt->idx)
- CHECK_B(check_each_idx(env, stmt->exp, stmt->idx));
+ if (stmt->idx.tag.sym)
+ CHECK_B(check_each_idx(env, stmt->exp, &stmt->idx));
DECL_B(const Type, ret, = check_each_val(env, stmt->exp));
- stmt->var.value = new_value(env, ret, stmt->tag);
- valid_value(env, stmt->tag.sym, stmt->var.value);
+ stmt->var.value = new_value(env, ret, stmt->var.tag);
+ valid_value(env, stmt->var.tag.sym, stmt->var.value);
return check_conts(env, stmt_self(stmt), stmt->body);
}
ANN static bool do_stmt_repeat(const Env env, const Stmt_Loop stmt) {
- if (stmt->idx) check_idx(env, env->gwion->type[et_int], stmt->idx);
+ if (stmt->idx.tag.sym) check_idx(env, env->gwion->type[et_int], &stmt->idx);
return check_conts(env, stmt_self(stmt), stmt->body);
}
}
ANN bool check_fptr_def(const Env env, const Fptr_Def fptr) {
+if(fptr->cdef->base.type->error) return false;
if(GET_FLAG(fptr->cdef, global)) env_push_global(env);
const bool ret = check_class_def(env, fptr->cdef);
if(GET_FLAG(fptr->cdef, global)) env_pop(env, 0);
for(uint32_t i = 0; i < tmpl->list->len; i++) {
const TmplArg targ = *mp_vector_at(tmpl->call, TmplArg, i);
if(likely(targ.type == tmplarg_td)) continue;
- if(!check_exp(env, targ.d.exp))
+ if(!check_exp(env, targ.d.exp)) {
POISON_NODE(ok, env, targ.d.exp);
+ continue;
+ }
const Specialized spec = *mp_vector_at(tmpl->list, Specialized, i);
const Value v = new_value(env, targ.d.exp->type, MK_TAG(spec.tag.sym, targ.d.exp->loc));
valuefrom(env, v->from);
if(global) SET_FLAG(cpy->base, global);
const bool ret = traverse_func_def(env, cpy);
nspc_pop_type(env->gwion->mp, env->curr);
- Section section = MK_SECTION(func, func_def, cpy);
+ Section section = MK_SECTION(func, func_def, cpy, t->info->value->from->loc);
if(!env->context->extend)
env->context->extend = new_mp_vector(env->gwion->mp, Section, 0);
mp_vector_add(env->gwion->mp, &env->context->extend, Section, section);
? std_code(env, fb, max)
: new_code(env, fb, max);
const Func_Def fdef = new_func_def(env->gwion->mp, base, code);
- Section section = MK_SECTION(func, func_def, fdef);
+ Section section = MK_SECTION(func, func_def, fdef, fb->tag.loc);
mp_vector_add(env->gwion->mp, acc, Section, section);
return fdef;
}
insert_symbol("func"), args, ae_flag_static | ae_flag_private, loc);
const Func_Def fdef = new_func_def(env->gwion->mp, fbase, NULL);
Ast body = new_mp_vector(env->gwion->mp, Section, 1);
- mp_vector_set(body, Section, 0, MK_SECTION(func, func_def, fdef));
+ mp_vector_set(body, Section, 0, MK_SECTION(func, func_def, fdef, loc));
Type_Decl* td = new_type_decl(env->gwion->mp, insert_symbol(env->gwion->type[et_closure]->name), loc);
const Class_Def cdef = new_class_def(env->gwion->mp, ae_flag_final, fptr->base->tag, td, body);
if(global) SET_FLAG(cdef, global);
ANN static inline bool stmt_each_defined(const restrict Env env,
const Stmt_Each stmt) {
bool ok = true;
- if (nspc_lookup_value1(env->curr, stmt->tag.sym))
+ if (nspc_lookup_value1(env->curr, stmt->var.tag.sym))
ERR_OK_NODE(ok, stmt_self(stmt), stmt_self(stmt)->loc, _("foreach value '%s' is already defined"),
- s_name(stmt->tag.sym));
- if (stmt->idx && nspc_lookup_value1(env->curr, stmt->idx->var.tag.sym))
- ERR_OK_NODE(ok, stmt_self(stmt), stmt->idx->var.tag.loc, _("foreach index '%s' is already defined"),
- s_name(stmt->idx->var.tag.sym));
+ s_name(stmt->var.tag.sym));
+ if (stmt->idx.tag.sym && nspc_lookup_value1(env->curr, stmt->idx.tag.sym))
+ ERR_OK_NODE(ok, stmt_self(stmt), stmt->idx.tag.loc, _("foreach index '%s' is already defined"),
+ s_name(stmt->idx.tag.sym));
return ok;
}
!scan1_stmt(env, stmt->body)) ? true : false)
describe_ret_nspc(each, Stmt_Each,, !(!stmt_each_defined(env, stmt) || !scan1_exp(env, stmt->exp) ||
!scan1_stmt(env, stmt->body)) ? true : false)
-describe_ret_nspc(loop, Stmt_Loop,, !( (!stmt->idx ? true : !shadow_var(env, stmt->idx->var.tag)) ||
+describe_ret_nspc(loop, Stmt_Loop,, !( (!stmt->idx.tag.sym ? true : !shadow_var(env, stmt->idx.tag)) ||
!scan1_exp(env, stmt->cond) ||
!scan1_stmt(env, stmt->body)) ? true : false)
ERR_OK(ok, um->vd.tag.loc, _("'%s' already declared in union"), s_name(um->vd.tag.sym));
const Type t = known_type(env, um->td);
if(t) {
- if(tflag(t, tflag_ref))
+ if(tflag(t, tflag_ref)) {
ERR_OK(ok, um->vd.tag.loc, _("can't declare ref type in union"));
+ continue;
+ }
const Value v = new_value(env, t, um->vd.tag);
tuple_contains(env, v);
valuefrom(env, v->from);
Symbol sym = insert_symbol("@ctor");
Func_Base *fb = new_func_base(mp, td, sym, NULL, ae_flag_none, cdef->base.tag.loc);
Func_Def fdef = new_func_def(mp, fb, ctor);
- mp_vector_set(body, Section, 0, MK_SECTION(func, func_def, fdef));
+ mp_vector_set(body, Section, 0, MK_SECTION(func, func_def, fdef, cdef->base.tag.loc));
free_mp_vector(mp, Section, base);
cdef->body = body;
}
// return
-env_body(env, cdef, scan1_section);
+// check for previous errors?
+cdef->base.type->error = !env_body(env, cdef, scan1_section);
return true;
}
}
ANN bool scan2_fptr_def(const Env env NUSED, const Fptr_Def fptr) {
+ if(fptr->cdef->base.type->error) return false;
if(GET_FLAG(fptr->cdef, global)) env_push_global(env);
const bool ret = scan2_class_def(env, fptr->cdef);
const Func_Def fdef = mp_vector_at(fptr->cdef->base.type->info->cdef->body, struct Section_ , 0)->d.func_def;
const Value overload) {
const m_str name = s_name(f->base->tag.sym);
const Func func = scan_new_func(env, f, name);
- const Value value = func_value(env, func, overload);
+ DECL_B(const Value, value, = func_value(env, func, overload));
set_fflag(func, fflag_tmpl);
set_vflag(value, vflag_valid);
set_tflag(value->type,
ANN2(1, 2, 4)
static Value func_create(const Env env, const Func_Def f, const Value overload,
const m_str name) {
- const Func func = scan_new_func(env, f, name);
+ DECL_B(const Func, func, = scan_new_func(env, f, name));
nspc_add_func(env->curr, insert_symbol(func->name), func);
- const Value v = func_value(env, func, overload);
+ DECL_B(const Value, v, = func_value(env, func, overload));
scan2_func_def_flag(env, f);
nspc_add_value(env->curr, insert_symbol(func->name), v);
return v;
free_mp_vector(env->gwion->mp, Section , ast);
}
fclose(f);
- mp_vector_add(env->gwion->mp, &env->context->extend, Section, MK_SECTION(stmt, stmt_list, NULL));
+ mp_vector_add(env->gwion->mp, &env->context->extend, Section, MK_SECTION(stmt, stmt_list, NULL, spread->tag.loc));
return true;
}
const Stmt stmt = *mp_vector_at(list, Stmt, j);
if(stmt.stmt_type == ae_stmt_spread) {
if(acc) {
- mp_vector_add(env->gwion->mp, &new_body, Section, MK_SECTION(stmt, stmt_list, acc));
+ mp_vector_add(env->gwion->mp, &new_body, Section, MK_SECTION(stmt, stmt_list, acc, stmt.loc));
acc = NULL;
}
const Ast extend = env->context->extend;
}
}
if(acc) {
- mp_vector_add(env->gwion->mp, &new_body, Section, MK_SECTION(stmt, stmt_list, acc));
+ mp_vector_add(env->gwion->mp, &new_body, Section, MK_SECTION(stmt, stmt_list, acc, section.loc));
}
}
}
#include "operator.h"
#include "instr.h"
#include "import.h"
+#include "gwfmt.h"
ANN static Type _option(const Env env, Type_Decl *td, const uint8_t n) {
const Array_Sub array = td->array;
}
ANN static inline void *type_unknown(const Env env, const Type_Decl *td) {
+ struct GwfmtState ls = {};
+ text_init(&ls.text, env->gwion->mp);
+ Gwfmt gwfmter = {.mp = env->gwion->mp, .ls = &ls, .st = env->gwion->st };
+ gwfmt_type_decl(&gwfmter, td);
env_err(env, td->tag.loc, _("unknown type '%s'"), s_name(td->tag.sym));
+ free_mstr(env->gwion->mp, ls.text.str);
return NULL;
}