Skip to content

Commit

Permalink
🔥 update to no pos
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Jan 30, 2024
1 parent 81093b9 commit 9bc9b6d
Show file tree
Hide file tree
Showing 25 changed files with 212 additions and 212 deletions.
2 changes: 1 addition & 1 deletion ast
46 changes: 23 additions & 23 deletions src/emit/emit.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ ANN static m_bool _emit_symbol(const Emitter emit, const Symbol *data) {

ANN static m_bool emit_symbol(const Emitter emit, const Exp_Primary *prim) {
if (!prim->value) // assume it's an operator
ERR_B(exp_self(prim)->pos, "missing value for operator");
ERR_B(exp_self(prim)->loc, "missing value for operator");
return _emit_symbol(emit, &prim->d.var);
}

Expand Down Expand Up @@ -615,7 +615,7 @@ ANN static m_bool emit_prim_range(const Emitter emit, Range **data) {
assert(e);
struct Op_Import opi = {.op = sym,
.lhs = e->type,
.loc = e->pos,
.loc = e->loc,
.data = (uintptr_t)prim_exp(data)};
CHECK_BB(op_emit(emit, &opi));
emit_local_exp(emit, prim_exp(data));
Expand All @@ -630,7 +630,7 @@ 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->pos);
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;
e->next = NULL;
Expand Down Expand Up @@ -706,7 +706,7 @@ ANN static m_bool emit_exp_slice(const Emitter emit, const Exp_Slice *range) {
struct Op_Import opi = {.op = sym,
.lhs = e->type,
.rhs = range->base->type,
.loc = e->pos,
.loc = e->loc,
.data = (uintptr_t)exp_self(range)};
CHECK_BB(op_emit(emit, &opi));
emit_local_exp(emit, exp_self(range));
Expand Down Expand Up @@ -1128,7 +1128,7 @@ ANN static m_bool emit_decl(const Emitter emit, Exp_Decl *const decl) {
ANN /*static */ m_bool emit_exp_decl(const Emitter emit, Exp_Decl *const decl) {
const Type t = decl->type;
if(decl->args && !strncmp(decl->args->type->name, "partial:", 8))
ERR_B(decl->args->pos, "unresolved partial");
ERR_B(decl->args->loc, "unresolved partial");
CHECK_BB(ensure_emit(emit, t));
const m_bool global = GET_FLAG(decl->var.td, global);
const m_uint scope =
Expand Down Expand Up @@ -1326,7 +1326,7 @@ ANN static m_bool _emit_exp_call(const Emitter emit, const Exp_Call *call) {
struct Op_Import opi = {.op = insert_symbol("call_type"),
.rhs = t,
.data = (uintptr_t)call,
.loc = exp_self(call)->pos};
.loc = exp_self(call)->loc};
CHECK_BB(op_emit(emit, &opi));
}
const Func f = t->info->func;
Expand Down Expand Up @@ -1390,7 +1390,7 @@ ANN static m_bool emit_exp_binary(const Emitter emit, const Exp_Binary *bin) {
struct Op_Import opi = {.op = bin->op,
.lhs = lhs->type,
.rhs = rhs->type,
.loc = exp_self(bin)->pos,
.loc = exp_self(bin)->loc,
.data = (uintptr_t)bin};
return op_emit(emit, &opi);
}
Expand Down Expand Up @@ -1524,23 +1524,23 @@ static m_bool me_cmp(MemoizeEmitter *me, const Arg *arg) {
struct Exp_ lhs = {
.exp_type = ae_exp_primary,
.type = arg->type,
.pos = arg->var.td->tag.loc,
.loc = arg->var.td->tag.loc,
.d = {
.prim = { .prim_type = ae_prim_id }
}
};
struct Exp_ rhs = {
.exp_type = ae_exp_primary,
.type = me->emit->gwion->type[et_bool],
.pos = arg->var.td->tag.loc,
.loc = arg->var.td->tag.loc,
.d = {
.prim = { .prim_type = ae_prim_id }
}
};
struct Exp_ bin = {
.exp_type = ae_exp_binary,
.type = arg->type,
.pos = arg->var.td->tag.loc,
.loc = arg->var.td->tag.loc,
.d = {
.exp_binary = {
.lhs = &lhs,
Expand Down Expand Up @@ -1690,7 +1690,7 @@ ANN static m_bool spork_prepare_func(const Emitter emit,
if(!f->code && f != emit->env->func)
CHECK_BB(emit_ensure_func(emit, f));
push_spork_code(emit, sp->is_spork ? SPORK_FUNC_PREFIX : FORK_CODE_PREFIX,
sp->exp->pos);
sp->exp->loc);
return emit_exp_call1(emit, f, f->def->base->ret_type->size, false);
}

Expand Down Expand Up @@ -1736,7 +1736,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) {
.code = unary->unary_type == unary_code ? unary->code : NULL,
.type = exp_self(unary)->type,
.captures = unary->captures,
.loc = exp_self(unary)->pos,
.loc = exp_self(unary)->loc,
.is_spork = (unary->op == insert_symbol("spork")),
.emit_var = exp_getvar(exp_self(unary))};
CHECK_OB((sporker.vm_code = spork_prepare(emit, &sporker)));
Expand Down Expand Up @@ -1804,13 +1804,13 @@ ANN static m_bool emit_exp_unary(const Emitter emit, const Exp_Unary *unary) {
ANN static m_bool emit_implicit_cast(const Emitter emit,
const restrict Exp from,
const restrict Type to) {
const struct Implicit imp = { .e=from, .t=to, . loc = from->pos};
const struct Implicit imp = { .e=from, .t=to, . loc = from->loc};
// no pos
struct Op_Import opi = {.op = insert_symbol("@implicit"),
.lhs = from->type,
.rhs = to,
.data = (m_uint)&imp,
.loc = from->pos
.loc = from->loc
};
return op_emit(emit, &opi);
}
Expand All @@ -1830,7 +1830,7 @@ ANN2(1,2) static Instr _flow(const Emitter emit, const Exp e, Instr *const instr
struct Op_Import opi = {
.op = insert_symbol(b ? "@conditional" : "@unconditional"),
.rhs = e->type,
.loc = e->pos,
.loc = e->loc,
.data = (uintptr_t)e};
CHECK_BO(op_emit(emit, &opi));
return (Instr)vector_back(&emit->code->instr);
Expand Down Expand Up @@ -1949,9 +1949,9 @@ DECL_EXP_FUNC(emit, m_bool, Emitter)
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->pos.first.line) {
if (emit->info->debug && emit->status.line < e->loc.first.line) {
const Instr instr = emit_add_instr(emit, DebugLine);
instr->m_val = emit->status.line = e->pos.first.line;
instr->m_val = emit->status.line = e->loc.first.line;
}
CHECK_BB(emit_exp_func[exp->exp_type](emit, &exp->d));
if (exp->cast_to) CHECK_BB(emit_implicit_cast(emit, exp, exp->cast_to));
Expand All @@ -1960,7 +1960,7 @@ ANN2(1) /*static */ m_bool emit_exp(const Emitter emit, /* const */ Exp e) {
e->exp_type == ae_exp_decl && GET_FLAG(e->d.exp_decl.var.td, late) &&
exp_getuse(e) && !exp_getvar(e) &&
GET_FLAG(e->d.exp_decl.var.vd.value, late))
emit_fast_except(emit, e->d.exp_decl.var.vd.value->from, e->pos);
emit_fast_except(emit, e->d.exp_decl.var.vd.value->from, e->loc);
} while ((exp = exp->next));
return GW_OK;
}
Expand Down Expand Up @@ -2428,12 +2428,12 @@ ANN static m_bool emit_case_head(const Emitter emit, const Exp base,
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, .pos = e->pos };
struct 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,
.data = (uintptr_t)&ebin.d.exp_binary,
.loc = e->pos};
.loc = e->loc};
CHECK_BB(op_emit(emit, &opi));
const Instr instr = emit_add_instr(emit, BranchEqInt);
vector_add(v, (vtype)instr);
Expand Down Expand Up @@ -2503,12 +2503,12 @@ ANN static Symbol case_op(const Emitter emit, const Exp base, const Exp e,
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}, .pos = e->pos };
struct Exp_ ebin = {.d = {.exp_binary = bin}, .loc = e->loc };
struct Op_Import opi = {.op = insert_symbol("?="),
.lhs = base->type,
.rhs = e->type,
.data = (uintptr_t)&ebin.d.exp_binary,
.loc = e->pos};
.loc = e->loc};
CHECK_BO(op_emit(emit, &opi));
const Instr instr = emit_add_instr(emit, BranchEqInt);
vector_add(vec, (vtype)instr);
Expand Down Expand Up @@ -2633,7 +2633,7 @@ ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot *member) {
.lhs = member->base->type,
.rhs = exp_self(member)->type,
.data = (uintptr_t)member,
.loc = exp_self(member)->pos};
.loc = exp_self(member)->loc};
return op_emit(emit, &opi);
}

Expand Down
4 changes: 2 additions & 2 deletions src/import/import_prim.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ static OP_EMIT(opem_bit_exp) {
static OP_CHECK(opck_bit_access) {
Array_Sub array = data;
const Exp e = array->exp;
if(e->next) ERR_N(e->next->pos, "too many expressions for bit access");
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;
if(idx < 0 || idx >= (m_int)array->type->size * CHAR_BIT)
ERR_N(e->pos, "bit access out of bound");
ERR_N(e->loc, "bit access out of bound");
}
return env->gwion->type[et_bool];
}
Expand Down
22 changes: 11 additions & 11 deletions src/lib/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ static OP_CHECK(opck_array_at) {
const Exp_Binary *bin = (Exp_Binary *)data;
CHECK_NN(opck_const_rhs(env, data));
if (bin->lhs->type != env->gwion->type[et_error]) {
ARRAY_OPCK(bin->lhs, bin->rhs, exp_self(bin)->pos)
ARRAY_OPCK(bin->lhs, bin->rhs, exp_self(bin)->loc)
if (bin->lhs->type->array_depth != bin->rhs->type->array_depth)
ERR_N(exp_self(bin)->pos, _("array depths do not match."));
ERR_N(exp_self(bin)->loc, _("array depths do not match."));
}
if (bin->rhs->exp_type == ae_exp_decl) {
Type_Decl *td = bin->rhs->d.exp_decl.var.td;
if (td->array && td->array->exp)
ERR_N(exp_self(bin)->pos,
ERR_N(exp_self(bin)->loc,
_("do not provide array for 'xxx => declaration'."));
SET_FLAG(bin->rhs->d.exp_decl.var.vd.value, late);
}
Expand Down Expand Up @@ -174,12 +174,12 @@ ANN static Type check_array_shift(const Env env, const Exp a, const Exp b,

static OP_CHECK(opck_array_sl) {
const Exp_Binary *bin = (Exp_Binary *)data;
return check_array_shift(env, bin->lhs, bin->rhs, "<<", exp_self(bin)->pos);
return check_array_shift(env, bin->lhs, bin->rhs, "<<", exp_self(bin)->loc);
}

static OP_CHECK(opck_array_sr) {
const Exp_Binary *bin = (Exp_Binary *)data;
return check_array_shift(env, bin->rhs, bin->lhs, ">>", exp_self(bin)->pos);
return check_array_shift(env, bin->rhs, bin->lhs, ">>", exp_self(bin)->loc);
}

ANN static inline m_bool emit_array_shift(const Emitter emit,
Expand Down Expand Up @@ -268,7 +268,7 @@ static OP_CHECK(opck_array_cast) {
}
parent = parent->info->parent;
}
struct Exp_ e = { .type = l, .pos = cast->exp->pos };
struct Exp_ e = { .type = l, .loc = cast->exp->loc };
CHECK_BN(check_implicit(env, &e, r));
return t;
}
Expand Down Expand Up @@ -382,7 +382,7 @@ static OP_CHECK(opck_array) {
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->pos);
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);

struct Array_Sub_ next = {curr->next, array_base(t),
Expand Down Expand Up @@ -887,20 +887,20 @@ ANN static inline Type foreach_type(const Env env, const Exp exp) {
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, exp->pos) : t;
return depth ? array_type(env, t, depth, exp->loc) : 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, exp->pos) : refbase;
return depth ? array_type(env, refbase, depth, exp->loc) : refbase;
}

// rewrite me
static OP_CHECK(opck_array_each_val) {
const Exp exp = (const Exp) data;
DECL_ON(const Type, base, = foreach_type(env, exp));
CHECK_BN(ensure_traverse(env, base));
return ref_type(env->gwion, base, exp->pos);
return ref_type(env->gwion, base, exp->loc);
}

static OP_EMIT(opem_array_each) {
Expand Down Expand Up @@ -1197,7 +1197,7 @@ ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, const Exp ar
} else {
if(args)
gwerr_warn("array is empty", "no need to provide a lambda",
NULL, env->name, td->array->exp->pos);
NULL, env->name, td->array->exp->loc);
}
return GW_OK;
}
Loading

0 comments on commit 9bc9b6d

Please sign in to comment.