void a(const Type t NUSED, m_bit *const VALUE NUSED, \
const VM_Shred shred NUSED)
#define OP_CHECK(a) ANN Type a(const Env env NUSED, void *data NUSED)
-#define OP_EMIT(a) ANN m_bool a(const Emitter emit NUSED, void *data NUSED)
+#define OP_EMIT(a) ANN bool a(const Emitter emit NUSED, void *data NUSED)
#ifdef GWION_BUILTIN
#define GWI_BB(a) \
{ \
m_str ret;
Symbol sym;
Type (*ck)(Env, void *); // oper
- m_bool (*em)(Emitter, void *); // oper should be opem
+ //bool (*em)(Emitter, void *); // oper should be opem
+ opem em;
m_str lhs; // oper
m_str rhs; // oper
struct Vector_ effect;
} while (0)
typedef Type (*opck)(const Env, void *);
-typedef m_bool (*opem)(const Emitter, void *);
+typedef bool (*opem)(const Emitter, void *);
struct Op_Func {
opck ck;
const Type_Decl *td;
};
-ANN void op_cpy(const Env env, const struct Op_Import *opi);
-ANN bool add_op(const Gwion gwion, const struct Op_Import *);
+ANN void op_cpy(const Env env, const struct Op_Import *opi);
+ANN bool add_op(const Gwion gwion, const struct Op_Import *);
ANN void* op_get(const Env env, struct Op_Import *opi);
-ANN Type op_check(const Env, struct Op_Import *);
-ANN m_bool op_emit(const Emitter, const struct Op_Import *);
-ANN bool operator_set_func(const struct Op_Import *);
-ANN void free_op_map(Map map, struct Gwion_ *gwion);
-ANN void free_op_tmpl(Vector v, struct Gwion_ *gwion);
+ANN Type op_check(const Env, struct Op_Import *);
+ANN bool op_emit(const Emitter, const struct Op_Import *);
+ANN bool operator_set_func(const struct Op_Import *);
+ANN void free_op_map(Map map, struct Gwion_ *gwion);
+ANN void free_op_tmpl(Vector v, struct Gwion_ *gwion);
ANN void operator_suspend(const Nspc, struct Op_Import *);
ANN static inline void operator_resume(struct Op_Import *opi) {
-Subproject commit 4d02ebd70bed8624438d5ebae1feabccedaa735d
+Subproject commit 3df21f0b68d5bf2aa606119f7405f841feea3780
m_uint i;
for(i = vector_size(v) + 1; --i;) {
Stmt* s = (Stmt*)vector_at(v, i - 1);
- if(s) CHECK_b(emit_stmt(emit, s));
+ if(s) CHECK_B(emit_stmt(emit, s));
}
VLEN(v) = i;
return true;
for (m_uint i = vector_size(v) + 1; --i;) {
Stmt* s = (Stmt*)vector_at(v, i - 1);
if (!s) break;
- CHECK_b(emit_stmt(emit, s));
+ CHECK_B(emit_stmt(emit, s));
}
return true;
}
const Instr instr = emit_add_instr(emit, ArrayStruct);
instr->m_val = type->size;
}
- CHECK_b(emit_pre_ctor(emit, type));
+ CHECK_B(emit_pre_ctor(emit, type));
if (!tflag(type, tflag_struct))
emit_add_instr(emit, ArrayBottom);
else
ANN2(1)
static bool extend_indices(const Emitter emit, Exp* e, const m_uint depth) {
- if (e) CHECK_b(emit_exp(emit, e));
+ if (e) CHECK_B(emit_exp(emit, e));
m_uint count = 0;
while (e) {
++count;
const Type base = info->base;
if (tflag(base, tflag_compound) &&
!GET_FLAG(base, abstract)) {
- CHECK_b(emit_pre_constructor_array(emit, base));
+ CHECK_B(emit_pre_constructor_array(emit, base));
info->is_obj = 1;
}
return true;
const Instr instr = emit_add_instr(emit, ObjectInstantiate);
instr->m_val2 = (m_uint)type;
} // maybe we should instantiate the first actual type
- CHECK_b(emit_pre_ctor(emit, type));
+ CHECK_B(emit_pre_ctor(emit, type));
}
return true;
}
ANN static bool emit_prim_array_exp(const Emitter emit, const Type t, Exp* e) {
do {
- CHECK_b(emit_exp1(emit, e));
+ CHECK_B(emit_exp1(emit, e));
emit_exp_addref1(emit, e, -t->size);
emit_regmove(emit, - t->size + t->actual_size);
} while((e = e->next));
Exp* e = (*data)->exp;
const Type type = (*data)->type;
const Type base = array_base_simple(type);
- if(!base->actual_size) CHECK_b(emit_exp(emit, e));
- else CHECK_b(emit_prim_array_exp(emit, base, e));
+ if(!base->actual_size) CHECK_B(emit_exp(emit, e));
+ else CHECK_B(emit_prim_array_exp(emit, base, e));
m_uint count = 0;
do ++count;
while ((e = e->next));
ANN static bool emit_range(const Emitter emit, Range *range) {
if (range->start)
- CHECK_b(emit_exp_pop_next(emit, range->start));
+ CHECK_B(emit_exp_pop_next(emit, range->start));
else emit_pushimm(emit, 0);
if (range->end)
- CHECK_b(emit_exp_pop_next(emit, range->end));
+ CHECK_B(emit_exp_pop_next(emit, range->end));
else emit_pushimm(emit, -1);
return true;
}
ANN static bool emit_prim_range(const Emitter emit, Range **data) {
Range *range = *data;
- CHECK_b(emit_range(emit, range));
+ CHECK_B(emit_range(emit, range));
Exp* e = range->start ?: range->end;
const Symbol sym = insert_symbol("[:]");
assert(e);
.lhs = e->type,
.loc = e->loc,
.data = (uintptr_t)prim_exp(data)};
- if(op_emit(emit, &opi) < 0) return false;
+ CHECK_B(op_emit(emit, &opi));
emit_local_exp(emit, prim_exp(data));
return true;
}
e->next = NULL;
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_b(traverse_exp(emit->env, &call));
+ CHECK_B(traverse_exp(emit->env, &call));
e->next = next;
m_uint count = 0;
do {
}
e->next = next;
CHECK_B(emit_exp(emit, &func));
- CHECK_b(emit_exp_call1(emit, func.type->info->func,
+ CHECK_B(emit_exp_call1(emit, func.type->info->func,
func.type->info->func->def->base->ret_type->size, true));
count++;
} while((e = e->next->next));
.lhs = info->array.exp->type,
.rhs = info->array.type,
.data = (uintptr_t)info};
- return op_emit(emit, &opi) > 0;
+ return op_emit(emit, &opi);
}
ANN static bool emit_exp_array(const Emitter emit, const Exp_Array *array) {
.rhs = range->base->type,
.loc = e->loc,
.data = (uintptr_t)exp_self(range)};
- if(op_emit(emit, &opi) < 0) return false;
+ CHECK_B(op_emit(emit, &opi));
emit_local_exp(emit, exp_self(range));
return true;
}
ANN static bool emit_prim_char(const Emitter emit, const m_str *str) {
char c;
- CHECK_b(str2char(emit, *str, &c, prim_pos(str)));
+ CHECK_B(str2char(emit, *str, &c, prim_pos(str)));
emit_pushimm(emit, c);
return true;
}
ANN bool emit_ensure_func(const Emitter emit, const Func f) {
const ValueFrom *from = f->value_ref->from;
if(from->owner_class)
- CHECK_b(ensure_emit(emit, from->owner_class));
+ CHECK_B(ensure_emit(emit, from->owner_class));
if(f->code) return true;
const m_uint scope = emit_push(emit, from->owner_class, from->owner);
const bool ret = emit_func_def(emit, f->def);
if(emit->locale->def->d.code) {
const Stmt* stmt = mp_vector_at((emit->locale->def->d.code), Stmt, 0);
const Func f = stmt->d.stmt_exp.val->d.exp_call.func->type->info->func;
- CHECK_b(emit_ensure_func(emit, f));
+ CHECK_B(emit_ensure_func(emit, f));
}
- CHECK_b(emit_ensure_func(emit, emit->locale));
+ CHECK_B(emit_ensure_func(emit, emit->locale));
comptime_ini(emit, "locale");
const M_Object string = new_string(emit->gwion, s_name(*id));
emit_pushimm(emit, (m_uint)string);
emit_pushimm(emit, (m_uint)emit->locale->code);
- CHECK_b(emit_exp_call1(emit, emit->locale, SZ_FLOAT, true));
+ CHECK_B(emit_exp_call1(emit, emit->locale, SZ_FLOAT, true));
m_float ret;
comptime_end(emit, SZ_FLOAT, &ret);
if(ret == -1.0)
ANN static bool _decl_static(const Emitter emit, const Exp_Decl *decl,
const Var_Decl *var_decl, const uint is_ref) {
const Value v = var_decl->value;
- if(!decl->args) CHECK_b(emit_instantiate_decl(emit, v->type, decl->var.td, is_ref));
+ if(!decl->args) CHECK_B(emit_instantiate_decl(emit, v->type, decl->var.td, is_ref));
else CHECK_B(emit_exp(emit, decl->args));
CHECK_B(emit_dot_static_data(emit, v, 1));
emit_add_instr(emit, Assign);
const bool is_obj = isa(type, emit->gwion->type[et_object]) > 0;
const bool emit_addr = (!is_obj || is_ref) ? emit_var : true;
if (is_obj && !is_ref && !exp_self(decl)->ref) {
- if(!decl->args) CHECK_b(emit_instantiate_decl(emit, type, decl->var.td, is_ref));
+ if(!decl->args) CHECK_B(emit_instantiate_decl(emit, type, decl->var.td, is_ref));
else CHECK_B(emit_exp(emit, decl->args));
}
f_instr *exec = (f_instr *)allocmember;
const bool is_obj = isa(type, emit->gwion->type[et_object]) > 0;
const bool emit_addr = (!is_obj || is_ref) ? emit_var : true;
if (is_obj && !is_ref) {
- if(!decl->args) CHECK_b(emit_instantiate_decl(emit, type, decl->var.td, is_ref));
+ if(!decl->args) CHECK_B(emit_instantiate_decl(emit, type, decl->var.td, is_ref));
else CHECK_B(emit_exp(emit, decl->args));
}
if (type->size > SZ_INT)
struct Op_Import opi = {.lhs = t->info->base_type,
.op = insert_symbol("@implicit"),
.rhs = t};
- if(op_emit(emit, &opi) < 0) return false;
+ CHECK_B(op_emit(emit, &opi));
}
set_late(decl, vd);
if (!decl->args && !exp_getvar(exp_self(decl)) && GET_FLAG(array_base_simple(v->type), abstract) && !GET_FLAG(decl->var.td, late) &&
const Type t = decl->type;
if(decl->args && !strncmp(decl->args->type->name, "partial:", 8))
ERR_B(decl->args->loc, "unresolved partial");
- CHECK_b(ensure_emit(emit, t));
+ CHECK_B(ensure_emit(emit, t));
const bool global = GET_FLAG(decl->var.td, global);
const m_uint scope =
!global ? emit->env->scope->depth : emit_push_global(emit);
else emit_regpushmem(emit, offset, t->size, true);
if(tflag(t, tflag_ctor)) emit_ext_ctor(emit, t);
emit_add_instr(emit, NoOp);
- CHECK_b(emit_exp_call1(emit, call->func->type->info->func, t->size, is_static_call(emit->gwion, call->func))); // is a ctor, is_static is true
+ CHECK_B(emit_exp_call1(emit, call->func->type->info->func, t->size, is_static_call(emit->gwion, call->func))); // is a ctor, is_static is true
return true;
}
.rhs = t,
.data = (uintptr_t)call,
.loc = exp_self(call)->loc};
- if(op_emit(emit, &opi) < 0) return false;
+ CHECK_B(op_emit(emit, &opi));
}
const Func f = t->info->func;
if(unlikely(is_new_struct(f, exp_self(call)->type)))
if (f != emit->env->func || (f && f->value_ref->from->owner_class))
CHECK_B(prepare_call(emit, call));
else CHECK_B(emit_func_args(emit, call));
- CHECK_b(emit_exp_call1(emit, f, exp_self(call)->type->size, is_static_call(emit->gwion, call->func)));
+ CHECK_B(emit_exp_call1(emit, f, exp_self(call)->type->size, is_static_call(emit->gwion, call->func)));
}
return true;
}
.rhs = rhs->type,
.loc = exp_self(bin)->loc,
.data = (uintptr_t)bin};
- return op_emit(emit, &opi) > 0;
+ return op_emit(emit, &opi);
}
ANN static bool emit_exp_cast(const Emitter emit, const Exp_Cast *cast) {
struct Op_Import opi = {.op = post->op,
.lhs = post->exp->type,
.data = (uintptr_t)post}; // no pos ?
- return op_emit(emit, &opi) > 0;
+ return op_emit(emit, &opi);
}
ANN static inline bool traverse_emit_func_def(const Emitter emit,
const Func_Def fdef) {
- if (!fdef->base->ret_type) CHECK_b(traverse_func_def(emit->env, fdef));
+ if (!fdef->base->ret_type) CHECK_B(traverse_func_def(emit->env, fdef));
return emit_func_def(emit, fdef);
}
.func = (_envset_func)emit_cdef,
.scope = scope,
.flag = tflag_emit};
- CHECK_b(envset_pushv(&es, v));
+ CHECK_B(envset_pushv(&es, v));
(void)emit_push(emit, v->from->owner_class, v->from->owner);
const bool ret = traverse_emit_func_def(emit, fdef);
emit_pop(emit, scope);
.func = (_envset_func)emit_cdef,
.scope = scope,
.flag = tflag_emit};
- CHECK_b(envset_pushv(&es, v));
+ CHECK_B(envset_pushv(&es, v));
(void)emit_push(emit, v->from->owner_class, v->from->owner);
const bool ret = emit_func_def(emit, f->def);
envset_pop(&es, v->from->owner_class);
.rhs = arg->type,
.loc = me->fdef->base->tag.loc,
.data = (uintptr_t)&bin.d};
- if(op_emit(emit, &opi) < 0) return false;
+ CHECK_B(op_emit(emit, &opi));
const Instr instr = emit_add_instr(emit, BranchEqInt);
vector_add(&me->branch, (vtype)instr);
return true;
emit->status = (EmitterStatus){};
if(unlikely(fflag(f, fflag_fptr))) emit_fptr_call(emit, f);
else if (unlikely(!f->code && emit->env->func != f)) {
- if (fflag(f, fflag_tmpl)) CHECK_b(emit_template_code(emit, f));
+ if (fflag(f, fflag_tmpl)) CHECK_B(emit_template_code(emit, f));
else //if(is_new(f->def))//if(tflag(f->value_ref->type, tflag_ftmpl))
{
const Type t = f->value_ref->from->owner_class;
if(t && (!emit->env->curr || isa(t, emit->env->class_def) < 0))
//!is_new(f->def) || f->value_ref->from->owner_class->array_depth)
//if(f->value_ref->from->owner_class->array_depth)
-CHECK_b(emit_ensure_func(emit, f));
+CHECK_B(emit_ensure_func(emit, f));
}
} else if(is_static)
push_func_code(emit, f);
const Type t = actual_type(emit->gwion, sp->exp->d.exp_call.func->type);
const Func f = t->info->func;
if(!f->code && f != emit->env->func)
- CHECK_b(emit_ensure_func(emit, f));
+ CHECK_B(emit_ensure_func(emit, f));
push_spork_code(emit, sp->is_spork ? SPORK_FUNC_PREFIX : FORK_CODE_PREFIX,
sp->exp->loc);
return emit_exp_call1(emit, f, f->def->base->ret_type->size, false);
.type = emit->env->class_def,
.exp_type = ae_exp_primary
};
- CHECK_b(emit_exp(emit, &exp));
+ CHECK_B(emit_exp(emit, &exp));
offset += SZ_INT;
}
if(sporker.captures) {
};
if(cap->is_ref) exp_setvar(&exp, true);
offset += exp_size(&exp);
- CHECK_b(emit_exp(emit, &exp));
+ CHECK_B(emit_exp(emit, &exp));
// emit_exp_addref(emit, &exp, -exp_size(&exp));
}
}
ANN static bool emit_exp_unary(const Emitter emit, const Exp_Unary *unary) {
const Type t = exp_self(unary)->type;
const Type base = actual_type(emit->gwion, t);
- CHECK_b(ensure_emit(emit, base));
+ CHECK_B(ensure_emit(emit, base));
// no pos ?
struct Op_Import opi = {.op = unary->op, .data = (uintptr_t)unary};
if (unary->unary_type == unary_exp && unary->op != insert_symbol("spork") &&
CHECK_B(emit_exp_pop_next(emit, unary->exp));
opi.rhs = unary->exp->type;
}
- return op_emit(emit, &opi) > 0;
+ return op_emit(emit, &opi);
}
ANN static bool emit_implicit_cast(const Emitter emit,
.data = (m_uint)&imp,
.loc = from->loc
};
- return op_emit(emit, &opi) > 0;
+ return op_emit(emit, &opi);
}
ANN2(1,2) static Instr _flow(const Emitter emit, Exp* e, Instr *const instr, /*const */bool b) {
.rhs = e->type,
.loc = e->loc,
.data = (uintptr_t)e};
- if(op_emit(emit, &opi) < 0) return false;
+ CHECK_B(op_emit(emit, &opi));
return (Instr)vector_back(&emit->code->instr);
}
#define emit_flow(emit, b) _flow(emit, b, NULL, true)
.func = (_envset_func)emit_cdef,
.scope = emit->env->scope->depth,
.flag = tflag_emit};
- CHECK_b(envset_pushv(&es, lambda->def->base->func->value_ref));
+ CHECK_B(envset_pushv(&es, lambda->def->base->func->value_ref));
const bool ret = emit_lambda(emit, lambda);
envset_pop(&es, lambda->owner);
return ret;
.op = insert_symbol("@each"),
.data = (m_uint)loop
};
- if(op_emit(emit, &opi) < 0) return false;
+ CHECK_B(op_emit(emit, &opi));
return loop->instr;
}
.op = insert_symbol("@each_init"),
.data = (m_uint)&loop
};
- if(op_emit(emit, &opi) < 0) return false;
+ CHECK_B(op_emit(emit, &opi));
}
const m_uint ini_pc = emit_code_size(emit);
CHECK_B(looper_run(emit, &loop));
.rhs = e->type,
.data = (uintptr_t)&ebin.d.exp_binary,
.loc = e->loc};
- if(op_emit(emit, &opi) < 0) return false;
+ CHECK_B(op_emit(emit, &opi));
const Instr instr = emit_add_instr(emit, BranchEqInt);
vector_add(v, (vtype)instr);
return true;
.rhs = e->type,
.data = (uintptr_t)&ebin.d.exp_binary,
.loc = e->loc};
- if(op_emit(emit, &opi) < 0) return false;
+ CHECK_B(op_emit(emit, &opi));
const Instr instr = emit_add_instr(emit, BranchEqInt);
vector_add(vec, (vtype)instr);
return CASE_PASS;
.rhs = exp_self(member)->type,
.data = (uintptr_t)member,
.loc = exp_self(member)->loc};
- return op_emit(emit, &opi) > 0;
+ return op_emit(emit, &opi);
}
ANN static inline void emit_func_def_init(const Emitter emit, const Func func) {
ANN static bool cdef_parent(const Emitter emit, const Class_Def cdef) {
const bool tmpl = !!cdef->base.tmpl;
- if (tmpl) CHECK_b(template_push_types(emit->env, cdef->base.tmpl));
+ if (tmpl) CHECK_B(template_push_types(emit->env, cdef->base.tmpl));
const bool ret = emit_parent(emit, cdef);
if (tmpl) nspc_pop_type(emit->gwion->mp, emit->env->curr);
return ret;
const Class_Def c = t->info->cdef;
if (c->base.ext && t->info->parent->info->cdef &&
!tflag(t->info->parent, tflag_emit)) // ?????
- CHECK_b(cdef_parent(emit, c));
+ CHECK_B(cdef_parent(emit, c));
if (c->base.tmpl) CHECK_B(emit_class_tmpl(emit, c->base.tmpl, c->base.type->nspc));
if (c->body)
return scanx_body(emit->env, c, (_envset_func)emit_section_b, emit);
static OP_EMIT(opem_bit_access) {
struct ArrayAccessInfo *const info = (struct ArrayAccessInfo *)data;
if(!is_prim_int(info->array.exp)) {
- CHECK_b(emit_exp(emit, info->array.exp));
+ CHECK_B(emit_exp(emit, info->array.exp));
const Instr check = emit_add_instr(emit, bit_check);
check->m_val = info->array.type->actual_size * CHAR_BIT;
if(!info->is_var) {
instr->m_val = (offset / CHAR_BIT);
}
}
- return GW_OK;
+ return true;
}
static OP_EMIT(opem_bit_exp) {
bool *var = data;
var[1] = var[0];
- return GW_OK;
+ return true;
}
static OP_CHECK(opck_bit_access) {
? bin->lhs->type
: bin->rhs->type;
instr->m_val = t->actual_size;
- return GW_OK;
+ return true;
}
static INSTR(bitcast) {
const Instr instr = emit_add_instr(emit, bitcast);
instr->m_val = -SZ_INT + t->actual_size;
instr->m_val2 = SZ_INT - t->actual_size;
- return GW_OK;
+ return true;
}
ANN2(1,2,3,5) static void prim_op(const Env env, const Type t, const m_str op, const opck ck, const opem em){
prim_op(env, t, "$", opck_prim_cast, opem_bitcast);
prim_implicit(env, t);
} else if(size == SZ_INT) {
- prim_op(env, t, ":=>", opck_rassign, (opem)dummy_func);
- prim_op(env, t, "$", NULL, (opem)dummy_func);
+ prim_op(env, t, ":=>", opck_rassign, (opem)bdummy_func);
+ prim_op(env, t, "$", NULL, (opem)bdummy_func);
prim_implicit(env, t);
} // else provide function to get slices
CHECK_O(mk_gack(env->gwion->mp, t, gack_prim));
static OP_EMIT(opem_array_sr) {
const Exp_Binary *bin = (Exp_Binary *)data;
if (shift_match(bin->lhs->type, bin->rhs->type))
- return emit_array_shift(emit, ArrayConcatRight) ? GW_OK : GW_ERROR;
+ return emit_array_shift(emit, ArrayConcatRight);
emit_regmove(emit, -SZ_INT);
if (tflag(bin->lhs->type, tflag_compound))
emit_compound_addref(emit, bin->lhs->type, -SZ_INT - bin->lhs->type->size, false);
(void)emit_add_instr(emit, ArrayAppendFront);
- return GW_OK;
+ return true;
}
static OP_EMIT(opem_array_sl) {
const Exp_Binary *bin = (Exp_Binary *)data;
if (shift_match(bin->rhs->type, bin->lhs->type))
- return emit_array_shift(emit, ArrayConcatLeft) ? GW_OK : GW_ERROR;
+ return emit_array_shift(emit, ArrayConcatLeft);
if (tflag(bin->rhs->type, tflag_compound))
emit_compound_addref(emit, bin->rhs->type, -bin->rhs->type->size, false);
emit_regmove(emit, -bin->rhs->type->size);
emit_add_instr(emit, ArrayAppend);
- return GW_OK;
+ return true;
}
// check me. use common ancestor maybe
const m_uint ret_offset = emit_local(emit, t);
emit_regtomem(emit, ret_offset, -SZ_INT);
}
- return GW_OK;
+ return true;
}
static OP_CHECK(opck_array_slice) {
static OP_EMIT(opem_array_slice) {
emit_add_instr(emit, ArraySlice);
- return GW_OK;
+ return true;
}
static FREEARG(freearg_array) {
return check_array_access(env, &next) ?: env->gwion->type[et_error];
}
-ANN static inline m_bool array_do(const Emitter emit, const Array_Sub array,
+ANN static inline bool array_do(const Emitter emit, const Array_Sub array,
const bool is_var) {
- CHECK_b(emit_exp(emit, array->exp));
+ CHECK_B(emit_exp(emit, array->exp));
const m_uint depth = array->depth;
const m_uint offset = is_var ? SZ_INT : array->type->size;
emit_regmove(emit, -(depth+1) * SZ_INT + offset);
}
assert(access);
access->udata.two = is_var;
- return GW_OK;
+ return true;
}
ANN bool get_emit_var(const Emitter emit, const Type t, bool is_var) {
struct Op_Import opi = {.op = insert_symbol("@array_init"),
.lhs = t,
.data = (uintptr_t)vars};
- if(op_emit(emit, &opi) != GW_OK)
+ if(!op_emit(emit, &opi))
return false;
return vars[1];
}
struct Array_Sub_ partial = {info->array.exp, info->array.type,
info->array.depth};
const bool is_var = get_emit_var(emit, array_base(info->array.type), info->is_var);
- const m_bool ret = array_do(emit, &partial, is_var);
- e->next = next;
- return ret > 0 ? next : NULL;
+ const bool ret = array_do(emit, &partial, is_var);
+ e->next = next;
+ return ret ? next : NULL;
}
ANN static Type emit_get_array_type(const Emitter emit, const Type t) {
next.exp = exp;
info->array = next;
if(exp)
- return emit_array_access(emit, info) ? GW_OK : GW_ERROR;
- return GW_ERROR;
+ return emit_array_access(emit, info);
+ return false;
}
static m_bit map_byte[BYTECODE_SZ * 5];
Looper *loop = (Looper *)data;
const Instr instr = emit_add_instr(emit, AutoUnrollInit);
instr->m_val = loop->offset;
- return GW_OK;
+ return true;
}
instr->m_val2 = loop->offset + SZ_INT*2;
vector_add(&loop->unroll_v, (m_uint)instr);
}
- return GW_OK;
+ return true;
}
ANN static void prepare_run(m_bit *const byte, const f_instr ini,
*(M_Object*)REG(-SZ_INT) = o;
}
-ANN static m_bool emit_fptr_assign(const Emitter emit, const Type lhs, const Type rhs) {
+ANN static bool emit_fptr_assign(const Emitter emit, const Type lhs, const Type rhs) {
const Instr instr = emit_add_instr(emit, fptr_assign);
if(rhs->info->cdef && get_tmpl(rhs))
instr->m_val = SZ_INT * 2;
e->d.prim.value = cap->var.value;
e->type = cap->var.value->type;
exp_setvar(e, cap->is_ref);
- CHECK_b(emit_exp(emit, e));
+ CHECK_B(emit_exp(emit, e));
if(!cap->is_ref && tflag(cap->temp->type, tflag_compound))
emit_compound_addref(emit, cap->temp->type, cap->temp->type->size, 0);
offset += cap->temp->type->size;
instr->m_val2 = (m_uint)fdef;
}
}
- return GW_OK;
+ return true;
}
static OP_EMIT(opem_fptr_assign) {
static OP_EMIT(opem_op_impl) {
struct Implicit *impl = (struct Implicit *)data;
if(!impl->e->type->info->func->code)
- CHECK_b(emit_ensure_func(emit, impl->e->type->info->func));
+ CHECK_B(emit_ensure_func(emit, impl->e->type->info->func));
emit_pushimm(emit, (m_uint)impl->e->type->info->func->code);
return emit_fptr_assign(emit, impl->e->type, impl->t);
}
ANN bool tmpl_fptr(const Env env, const Fptr_Def fptr, const Func_Def fdef) {
fptr->cdef->base.type->nspc->offset += SZ_INT * 3;
env_push_type(env, fptr->cdef->base.type);
- CHECK_b(traverse_func_def(env, fdef));
+ CHECK_B(traverse_func_def(env, fdef));
builtin_func(env->gwion, fdef->base->func, fptr_ctor);
set_tflag(fdef->base->func->value_ref->type, tflag_ftmpl);
env_pop(env, 0);
const bool ret = deep_emit(emit, &ds);
deep_emits_release(emit, &ds);
emit_pop_scope(emit);
- return ret ? GW_OK: GW_ERROR;
+ return ret;
}
GWION_IMPORT(deep_equal) {
return e->type = env->gwion->type[et_void];
}
-ANN static m_bool emit_dict_iter(const Emitter emit, const HMapInfo *hinfo,
+ANN static bool emit_dict_iter(const Emitter emit, const HMapInfo *hinfo,
const struct Op_Import *opi, Exp* call, Exp* exp) {
emit_pushimm(emit, -1); // room for tombstone
- CHECK_b(emit_exp(emit, call));
+ CHECK_B(emit_exp(emit, call));
const m_uint pc = emit_code_size(emit);
const Instr iter = emit_add_instr(emit, hmap_iter);
iter->m_val = hinfo->key->size + SZ_INT;
- CHECK_b(emit_exp(emit, exp));
+ CHECK_B(emit_exp(emit, exp));
op_emit(emit, opi);
const Instr ok = emit_add_instr(emit, BranchNeqInt);
emit_add_instr(emit, hmap_iter_inc);
top->m_val = pc;
ok->m_val = emit_code_size(emit);
emit_regmove(emit, -SZ_INT);
- return GW_OK;
+ return true;
}
static OP_EMIT(_opem_dict_access) {
const m_uint grow_pc = emit_code_size(emit);
emit_add_instr(emit, hmap_grow_dec);
const Instr endgrow = emit_add_instr(emit, BranchNeqInt);
- CHECK_b(emit_exp(emit, call.d.exp_call.func));
- CHECK_b(emit_exp_call1(emit, call.d.exp_call.func->type->info->func,
+ CHECK_B(emit_exp(emit, call.d.exp_call.func));
+ CHECK_B(emit_exp_call1(emit, call.d.exp_call.func->type->info->func,
call.d.exp_call.func->type->info->func->def->base->ret_type->size, true));
emit_add_instr(emit, hmap_find);
const Instr regrow = emit_add_instr(emit, BranchEqInt);
regrow->m_val = grow_pc;
nogrow->m_val = emit_code_size(emit);
endgrow->m_val = emit_code_size(emit);
- CHECK_b(emit_exp(emit, &call));
- CHECK_b(emit_exp(emit, array->exp));
+ CHECK_B(emit_exp(emit, &call));
+ CHECK_B(emit_exp(emit, array->exp));
const m_uint top_pc = emit_code_size(emit);
const Instr idx = emit_add_instr(emit, hmap_iter_set_ini);
idx->m_val = key->size;
const Instr iter = emit_add_instr(emit, hmap_iter_set);
iter->m_val = key->size;
const Instr fast = emit_add_instr(emit, BranchNeqInt);
- CHECK_b(emit_exp(emit, array->exp));
+ CHECK_B(emit_exp(emit, array->exp));
op_emit(emit, &opi);
const Instr ok = emit_add_instr(emit, BranchNeqInt);
const Instr iseq = emit_add_instr(emit, hmap_addr);
iseq->m_val = key->size;
fast->m_val = emit_code_size(emit);
- return GW_OK;
+ return true;
}
- CHECK_BB(emit_dict_iter(emit, hinfo, &opi, &call, array->exp));
+ CHECK_B(emit_dict_iter(emit, hinfo, &opi, &call, array->exp));
const Instr pushval = emit_add_instr(emit, hmap_val);
pushval->m_val2 = key->size;
- return GW_OK;
+ return true;
}
static OP_EMIT(opem_dict_remove) {
};
CHECK_B(traverse_exp(env, &call));
- CHECK_BB(emit_dict_iter(emit, hinfo, &opi, &call, bin->lhs));
+ CHECK_B(emit_dict_iter(emit, hinfo, &opi, &call, bin->lhs));
const Instr pushval = emit_add_instr(emit, hmap_remove);
pushval->m_val2 = hinfo->key->size;
- return GW_OK;
+ return true;
}
ANN static bool emit_next_access(const Emitter emit, struct ArrayAccessInfo *const info) {
const Array_Sub array = &info->array;
Exp* enext = array->exp->next;
array->exp->next = NULL;
- const m_bool ret = _opem_dict_access(emit, data);
+ const bool ret = _opem_dict_access(emit, data);
array->exp->next = enext;
- CHECK_BB(ret);
- return !enext ? GW_OK : (emit_next_access(emit, info) ? GW_OK : GW_ERROR);
+ CHECK_B(ret);
+ return !enext ? GW_OK : emit_next_access(emit, info);
}
static OP_CHECK(opck_dict_access) {
if(!loop->n) loop->instr = go;
else vector_add(&loop->unroll_v, (m_uint)go);
loop->init = true;
- return GW_OK;
+ return true;
}
static INSTR(DictEachInit) {
const Looper *loop = (Looper *)data;
const Instr instr = emit_add_instr(emit, DictEachInit);
instr->m_val = loop->offset;
- return GW_OK;
+ return true;
}
static OP_CHECK(opck_dict_each_key) {
struct Implicit *imp = (struct Implicit*)data;
const Type t = actual_type(emit->gwion, imp->e->type);
emit_pushimm(emit, map_size(&t->nspc->info->value->map));
- return GW_OK;
+ return true;
}
static OP_CHECK(opck_implicit_class) {
struct Op_Import opi = {.lhs = t,
.op = insert_symbol(emit->gwion->st, "@implicit"),
.rhs = imp->t};
- CHECK_BB(op_emit(emit, &opi));
+ CHECK_B(op_emit(emit, &opi));
emit_regmove(emit, -SZ_INT);
const Instr cpy = emit_add_instr(emit, Reg2RegOther); // kind
cpy->m_val = cpy->m_val2 = imp->t->size;
}
- return GW_OK;
+ return true;
}
GWION_IMPORT(gack) {
Exp_Binary *bin = (Exp_Binary *)data;
const Instr instr = emit_add_instr(emit, UsrUGenTick);
instr->m_val = !!bin->lhs->type->info->func->value_ref->from->owner_class;
- return GW_OK;
+ return true;
}
static GWION_IMPORT(usrugen) {
(void)emit_add_instr(emit, ObjectAssign);
else
(void)emit_add_instr(emit, Assign);
- return GW_OK;
+ return true;
}
static OP_CHECK(opck_object_cast) {
OP_CHECK(opck_object_dot) {
Exp_Dot *const member = (Exp_Dot *)data;
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 =
+ const m_str str = s_name(member->xid);
+ const bool base_static = is_class(env->gwion, member->base->type);
+ const Type the_base =
base_static ? _class_base(member->base->type) : member->base->type;
const Value value = get_value(env, member, the_base);
if (!value) {
const Value value = find_value(t_base, member->xid);
if (is_class(emit->gwion, value->type)) {
emit_pushimm(emit, (m_uint)value->type);
- return GW_OK;
+ return true;
}
if (tflag(t_base, tflag_struct) && !GET_FLAG(value, static)) {
exp_setvar(member->base, true);
- CHECK_b(emit_exp(emit, member->base));
+ CHECK_B(emit_exp(emit, member->base));
}
if (!is_class(emit->gwion, member->base->type) &&
(vflag(value, vflag_member) ||
(is_func(emit->gwion, exp_self(member)->type)))) {
if (!tflag(t_base, tflag_struct))
- CHECK_b(emit_exp(emit, member->base));
+ CHECK_B(emit_exp(emit, member->base));
}
if (is_func(emit->gwion, exp_self(member)->type) &&
!fflag(exp_self(member)->type->info->func, fflag_fptr))
!exp_getvar(exp_self(member)) &&
(GET_FLAG(value, static) || GET_FLAG(value, late)))
emit_fast_except(emit, value->from, exp_self(member)->loc);
- return GW_OK;
+ return true;
}
-ANN static m_bool scantmpl_class_def(const Env env, struct tmpl_info *info) {
+ANN static bool scantmpl_class_def(const Env env, struct tmpl_info *info) {
const Class_Def c = info->base->info->cdef;
const Class_Def cdef = new_class_def(
env->gwion->mp, c->flag, MK_TAG(info->name,c->base.tag.loc),
set_tflag(info->ret, tflag_cdef);
} else
free_class_def(env->gwion->mp, cdef);
- return ret ? GW_OK : GW_ERROR;
+ return ret;
}
-ANN static m_bool scantmpl_union_def(const Env env, struct tmpl_info *info) {
+ANN static bool scantmpl_union_def(const Env env, struct tmpl_info *info) {
const Union_Def u = info->base->info->udef;
const Union_Def udef = new_union_def(
env->gwion->mp, cpy_variable_list(env->gwion->mp, u->l), u->tag.loc);
set_tflag(info->ret, tflag_udef);
} else
free_union_def(env->gwion->mp, udef);
- return ret ? GW_OK : GW_ERROR;
+ return ret;
}
ANN static Type _scan_class(const Env env, struct tmpl_info *info) {
if (info->base->info->parent != env->gwion->type[et_union])
- CHECK_BO(scantmpl_class_def(env, info));
+ CHECK_O(scantmpl_class_def(env, info));
else
- CHECK_BO(scantmpl_union_def(env, info));
+ CHECK_O(scantmpl_union_def(env, info));
return info->ret;
}
const Instr back = (Instr)vector_back(v);
if (back->opcode == eGWOP_EXCEPT) {
back->opcode = eIntNot;
- return GW_OK;
+ return true;
} else if (back->opcode == eOP_MAX && back->execute == fast_except) {
back->opcode = eIntNot;
- return GW_OK;
+ return true;
}
const Instr instr = emit_add_instr(emit, RegSetImm);
instr->m_val2 = -SZ_INT;
- return GW_OK;
+ return true;
}
static OP_EMIT(opem_uncond_object) {
}
}
emit_add_instr(emit, BranchNeqInt);
- return GW_OK;
+ return true;
}
static OP_EMIT(opem_cond_object) {
}
}
emit_add_instr(emit, BranchEqInt);
- return GW_OK;
+ return true;
}
GWION_IMPORT(object_op) {
OP_EMIT(opem_new) {
const Exp_Unary *unary = (Exp_Unary *)data;
if(!tflag(exp_self(unary)->type, tflag_struct))
- CHECK_b(emit_instantiate_object(emit, exp_self(unary)->type,
+ CHECK_B(emit_instantiate_object(emit, exp_self(unary)->type,
unary->ctor.td->array, 0));
if(!unary->ctor.exp)
emit_local_exp(emit, exp_self(unary));
- return GW_OK;
+ return true;
}
instr->opcode = e##type##_##name##_imm; \
instr->val = bin->rhs->d.prim.d.member; \
} \
- return GW_OK; \
+ return true; \
}
#define BINARY_INT_EMIT(name) BINARY_OP_EMIT(name, int, gwint.num, m_val)
Exp* exp = (Exp*)data;
const Instr instr = emit_add_instr(emit, IntRange);
instr->m_val = (m_uint)exp->type;
- return GW_OK;
+ return true;
}
#define UNARY_FOLD(ntype, name, TYPE, OP, func, ctype, exptype, member) \
return str2type(gwion, c, loc);
}
-static m_bool ref_access(const Env env, Exp* e) {
+static bool ref_access(const Env env, Exp* e) {
const m_str access = exp_access(e);
- if (!access) return GW_OK;
+ if (!access) return true;
env_err(env, e->loc, _("operand is %s"), access);
- return GW_ERROR;
+ return false;
}
static OP_CHECK(opck_ref_implicit_similar) {
const struct Implicit *imp = (struct Implicit *)data;
- CHECK_BN(ref_access(env, imp->e));
+ CHECK_ON(ref_access(env, imp->e));
exp_setvar(imp->e, 1);
return imp->t;
}
.lhs = base,
.rhs = imp->t,
.data = (m_uint)imp};
- CHECK_BB(op_emit(emit, &opi));
+ CHECK_B(op_emit(emit, &opi));
emit_regmove(emit, -imp->e->type->size);
exp_setvar(imp->e, true);
imp->e->cast_to = NULL;
- return emit_exp(emit, imp->e) > 0 ? GW_OK : GW_ERROR;
+ return emit_exp(emit, imp->e);
}
static OP_CHECK(opck_implicit_ref) {
const struct Implicit *imp = (struct Implicit *)data;
- CHECK_BN(ref_access(env, imp->e));
+ CHECK_ON(ref_access(env, imp->e));
exp_setvar(imp->e, 1);
imp->e->cast_to = imp->t;
return imp->t;
static OP_CHECK(opck_ref_contract_similar) {
const struct Implicit *imp = (struct Implicit *)data;
- CHECK_BN(ref_access(env, imp->e));
+ CHECK_ON(ref_access(env, imp->e));
const Type base = (Type)vector_front(&imp->t->info->tuple->contains);
struct Op_Import opi = {.op = insert_symbol("@implicit"),
.lhs = imp->e->type,
.lhs = imp->e->type,
.rhs = base,
.data = (m_uint)&cast};
- CHECK_BB(op_emit(emit, &opi));
+ CHECK_B(op_emit(emit, &opi));
emit_regmove(emit, -imp->e->type->size);
exp_setvar(imp->e, true);
imp->e->cast_to = NULL;
- return emit_exp(emit, imp->e) > 0 ? GW_OK : GW_ERROR;
+ return emit_exp(emit, imp->e);
}
ANN static void base2ref(Env env, const Type lhs, const Type rhs) {
struct ArrayAccessInfo *info = (struct ArrayAccessInfo*)data;
Exp* exp = info->array.exp;
Exp* next = exp->next;
- CHECK_b(emit_exp(emit, exp));
+ CHECK_B(emit_exp(emit, exp));
exp->next = next;
emit_add_instr(emit, !info->is_var ? string_at : string_at_set);
- return GW_OK;
+ return true;
}
GWION_IMPORT(string) {
static OP_EMIT(opem_none) {
emit_regmove(emit, -SZ_INT);
- return GW_OK;
+ return true;
}
static INSTR(UnionIndex) {
const Exp_Dot *member = (Exp_Dot *)data;
const Map map = &member->base->type->nspc->info->value->map;
exp_setvar(member->base, true);
- CHECK_b(emit_exp(emit, member->base));
+ CHECK_B(emit_exp(emit, member->base));
if (is_func(emit->gwion, exp_self(member)->type)) { // is_callable? can only be a func
emit_pushimm(emit, (m_uint)exp_self(member)->type->info->func->code);
- return GW_OK;
+ return true;
}
if (!strcmp(s_name(member->xid), "index")) {
//emit_add_instr(emit, DotMember);
emit_add_instr(emit, UnionIndex);
- return GW_OK;
+ return true;
}
for (m_uint i = 0; i < map_size(map); ++i) {
if (VKEY(map, i) == (m_uint)member->xid) {
const Value v = (Value)VVAL(map, i);
const uint emit_addr = exp_getvar(exp_self(member));
emit_unionmember(emit, i, v->type->size, emit_addr);
- return GW_OK;
+ return true;
}
}
- return GW_ERROR;
+ return false;
}
ANN void union_release(const VM_Shred shred, const Type t, const m_bit *data) {
GWI_BB(gwi_class_end(gwi))
const struct Op_Func opfunc0 = {.ck = opck_union_is};
- CHECK_b(add_op_func_check(gwi->gwion->env, t_union, &opfunc0, 0));
+ CHECK_B(add_op_func_check(gwi->gwion->env, t_union, &opfunc0, 0));
const struct Op_Func opfunc1 = {.ck = opck_union_new};
- CHECK_b(add_op_func_check(gwi->gwion->env, t_union, &opfunc1, 1));
+ CHECK_B(add_op_func_check(gwi->gwion->env, t_union, &opfunc1, 1));
GWI_BB(gwi_oper_ini(gwi, "union", (m_str)OP_ANY_TYPE, NULL))
GWI_BB(gwi_oper_emi(gwi, opem_union_dot))
static OP_EMIT(opem_spork) {
const Exp_Unary *unary = (Exp_Unary *)data;
- return emit_exp_spork(emit, unary) ? GW_OK : GW_ERROR;
+ return emit_exp_spork(emit, unary);
}
static FREEARG(freearg_xork) { vmcode_remref((VM_Code)instr->m_val, gwion); }
return true;
}
-ANN m_bool op_emit(const Emitter emit, const struct Op_Import *opi) {
+ANN bool op_emit(const Emitter emit, const struct Op_Import *opi) {
for (int i = 0; i < 2; ++i) {
Nspc nspc = emit->env->curr;
do {
!i ? operator_find2(v, l, r) : operator_find(v, l, r);
if (mo) {
if (mo->em) {
- const m_bool ret = mo->em(emit, (void *)opi->data);
+ const bool ret = mo->em(emit, (void *)opi->data);
if (ret) return ret;
} else if (mo->func || mo->instr)
- return handle_instr(emit, mo) ? GW_OK : GW_ERROR;
+ return handle_instr(emit, mo);
}
} while (r && (r = op_parent(emit->env, r)));
} while (l && (l = op_parent(emit->env, l)));
} while ((nspc = nspc->parent));
}
- return GW_ERROR;
+ return false;
}
#define CONVERT(t) t != from ? t : to