-Subproject commit 511f61502bebcfc02df1e651d9d742b74072e4ed
+Subproject commit a95e4eac0089fcbb55cd477987f5dcd40116eb6f
else if(GET_FLAG(a, protect)) \
SET_FLAG(b, protect);
-typedef m_bool (*_exp_func)(const void*, const void*);
-static inline m_bool dummy_func(const void*a NUSED,
- const void*b NUSED) { return 1; }
-
-#define DECL_PRIM_FUNC(prefix) \
-static const _exp_func prim_func[] = { \
- (_exp_func)prefix##__primary_id, (_exp_func)prefix##__primary_num, \
- (_exp_func)prefix##__primary_float, (_exp_func)prefix##__primary_str, \
- (_exp_func)prefix##__primary_array, (_exp_func)prefix##__primary_hack, \
- (_exp_func)prefix##__primary_complex, (_exp_func)prefix##__primary_polar, \
- (_exp_func)prefix##__primary_vec, (_exp_func)prefix##__primary_tuple, \
- (_exp_func)prefix##__primary_unpack, (_exp_func)prefix##__primary_char, \
- (_exp_func)prefix##__primary_nil \
-}
-
-#define DECL_EXP_FUNC(prefix) \
-static const _exp_func exp_func[] = { \
- (_exp_func)prefix##_exp_decl, (_exp_func)prefix##_exp_binary, (_exp_func)prefix##_exp_unary, \
- (_exp_func)prefix##_exp_primary, (_exp_func)prefix##_exp_cast, (_exp_func)prefix##_exp_post, \
- (_exp_func)prefix##_exp_call, (_exp_func)prefix##_exp_array, (_exp_func)prefix##_exp_if, \
- (_exp_func)prefix##_exp_dot, (_exp_func)prefix##_exp_lambda, (_exp_func)prefix##_exp_typeof \
-};
-
-#define DECL_STMT_FUNC(prefix) \
-static const _exp_func stmt_func[] = { \
- (_exp_func)prefix##__stmt_exp, (_exp_func)prefix##__stmt_while, \
- (_exp_func)prefix##__stmt_until, (_exp_func)prefix##__stmt_for, \
- (_exp_func)prefix##__stmt_auto, (_exp_func)prefix##__stmt_loop, \
- (_exp_func)prefix##__stmt_if, (_exp_func)prefix##__stmt_code, \
- (_exp_func)prefix##__stmt_break, (_exp_func)prefix##__stmt_continue, \
- (_exp_func)prefix##__stmt_return, (_exp_func)prefix##__stmt_match, \
- (_exp_func)prefix##__stmt_jump, \
-};
-
-#define DECL_SECTION_FUNC(prefix) \
-static const _exp_func section_func[] = { \
- (_exp_func)prefix##_stmt_list, (_exp_func)prefix##_func_def, (_exp_func)prefix##_class_def, \
- (_exp_func)prefix##_enum_def, (_exp_func)prefix##_union_def, \
- (_exp_func)prefix##_fptr_def, (_exp_func)prefix##_type_def \
-}; \
-ANN static inline m_bool prefix##_section(const void* a, /* const */ Section* section) { \
- void* d = §ion->d.stmt_list; \
- return section_func[section->section_type](a, *(void**)d); \
+#define HANDLE_SECTION_FUNC(prefix, type, Arg) \
+DECL_SECTION_FUNC(prefix, type, Arg) \
+ANN static inline type prefix##_section(const Arg a, /* const */ Section* section) { \
+ void* d = §ion->d.stmt_list; \
+ return section_func[section->section_type](a, *(void**)d); \
}
-#define HANDLE_EXP_FUNC(prefix, type, ret) \
-DECL_EXP_FUNC(prefix) \
-ANN type prefix##_exp(const Env env, Exp exp) { \
- do CHECK_BB(exp_func[exp->exp_type](env, &exp->d)) \
- while((exp = exp->next)); \
- return ret; \
+#define HANDLE_EXP_FUNC(prefix, type, Arg) \
+DECL_EXP_FUNC(prefix, type, Arg) \
+ANN type prefix##_exp(const Arg arg, Exp exp) { \
+ do CHECK_BB(exp_func[exp->exp_type](arg, &exp->d)) \
+ while((exp = exp->next)); \
+ return GW_OK; \
}
ANN m_bool scan1_exp(const Env, Exp);
ANN m_bool scan2_exp(const Env, Exp);
ANN void union_pop(const Env, const Union_Def, const m_uint);
ANN m_bool check_stmt(const Env env, const Stmt stmt);
+typedef m_bool (*_exp_func)(const void*, const void*);
ANN m_bool scanx_body(const Env env, const Class_Def cdef, const _exp_func f, void* data);
static inline ANN m_bool env_body(const Env env, const Class_Def cdef, const _exp_func f) {
return scanx_body(env, cdef, f, env);
return code;
}
-ANN static m_bool prim_array(const Emitter emit, const Exp_Primary * primary) {
+ANN static m_bool emit_prim_array(const Emitter emit, const Exp_Primary * primary) {
const Array_Sub array = primary->d.array;
Exp e = array->exp;
CHECK_BB(emit_exp(emit, e, 0))
return _emit_indexes(emit, &info);
}
-ANN static m_bool prim_vec(const Emitter emit, const Exp_Primary * primary) {
+ANN static m_bool emit_prim_vec(const Emitter emit, const Exp_Primary * primary) {
const Vec * vec = &primary->d.vec;
const ae_prim_t t = primary->primary_type;
CHECK_BB(emit_exp(emit, vec->exp, 0));
return GW_OK;
}
-ANN static m_bool prim_id(const Emitter emit, const Exp_Primary* prim) {
+ANN static m_bool emit_prim_id(const Emitter emit, const Exp_Primary* prim) {
struct SpecialId_ * spid = specialid_get(emit->gwion, prim->d.var);
if(spid)
return specialid_instr(emit, spid, prim) ? GW_OK : GW_ERROR;
return emit_symbol(emit, prim);
}
-ANN static m_bool prim_tuple(const Emitter emit, const Exp_Primary * primary) {
+ANN static m_bool emit_prim_tuple(const Emitter emit, const Exp_Primary * primary) {
CHECK_BB(emit_exp(emit, primary->d.tuple.exp, 1))
const Instr instr = emit_add_instr(emit, TupleCtor);
instr->m_val = (m_uint)exp_self(primary)->type;
return GW_OK;
}
-ANN static m_bool prim_num(const Emitter emit, const Exp_Primary * primary) {
+ANN static m_bool emit_prim_num(const Emitter emit, const Exp_Primary * primary) {
regpushi(emit, primary->d.num);
return GW_OK;
}
-ANN static m_bool prim_float(const Emitter emit, const Exp_Primary* primary) {
+ANN static m_bool emit_prim_float(const Emitter emit, const Exp_Primary* primary) {
const Instr instr = emit_add_instr(emit, RegPushImm2);
instr->f = primary->d.fnum;
return GW_OK;
}
-ANN static m_bool prim_char(const Emitter emit, const Exp_Primary* prim) {
+ANN static m_bool emit_prim_char(const Emitter emit, const Exp_Primary* prim) {
DECL_BB(const m_int, c, = str2char(emit, prim->d.chr, exp_self(prim)->pos))
regpushi(emit, c);
return GW_OK;
}
-ANN static m_bool prim_str(const Emitter emit, const Exp_Primary* prim) {
+ANN static m_bool emit_prim_str(const Emitter emit, const Exp_Primary* prim) {
char c[strlen(prim->d.str) + 1];
if(strlen(prim->d.str)) {
strcpy(c, prim->d.str);
return GW_OK;
}
-ANN static m_bool prim_gack(const Emitter emit, const Exp_Primary* primary) {
+ANN static m_bool emit_prim_hack(const Emitter emit, const Exp_Primary* primary) {
const Exp exp = primary->d.exp;
Exp e = exp, next = NULL;
do {
return GW_OK;
}
-ANN static m_bool prim_unpack(const Emitter emit NUSED, const Exp_Primary* primary) {
+ANN static m_bool emit_prim_unpack(const Emitter emit NUSED, const Exp_Primary* primary) {
if(exp_self(primary)->meta == ae_meta_var)
return GW_OK;
ERR_B(exp_self(primary)->pos, _("unused Tuple unpack"))
}
-static const _exp_func prim_func[] = {
- (_exp_func)prim_id, (_exp_func)prim_num, (_exp_func)prim_float, (_exp_func)prim_str,
- (_exp_func)prim_array, (_exp_func)prim_gack, (_exp_func)prim_vec, (_exp_func)prim_vec,
- (_exp_func)prim_vec, (_exp_func)prim_tuple, (_exp_func)prim_unpack,
- (_exp_func)prim_char, (_exp_func)dummy_func,
-};
+#define emit_prim_complex emit_prim_vec
+#define emit_prim_polar emit_prim_vec
+#define emit_prim_nil (void*)dummy_func
-ANN static m_bool emit_exp_primary(const Emitter emit, const Exp_Primary* prim) {
+DECL_PRIM_FUNC(emit, m_bool , Emitter);
+ANN static m_bool emit_exp_primary(const Emitter emit, Exp_Primary *const prim) {
return prim_func[prim->primary_type](emit, prim);
}
return GW_OK;
}
-DECL_EXP_FUNC(emit)
+DECL_EXP_FUNC(emit, m_bool, Emitter)
ANN2(1) static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool ref) {
do {
return ret;
}
-static const _exp_func stmt_func[] = {
- (_exp_func)emit_stmt_exp, (_exp_func)emit_stmt_flow, (_exp_func)emit_stmt_flow,
- (_exp_func)emit_stmt_for, (_exp_func)emit_stmt_auto, (_exp_func)emit_stmt_loop,
- (_exp_func)emit_stmt_if, (_exp_func)emit_stmt_code, (_exp_func)emit_stmt_break,
- (_exp_func)emit_stmt_continue, (_exp_func)emit_stmt_return, (_exp_func)emit_stmt_match,
- (_exp_func)emit_stmt_jump,
-};
+#define emit_stmt_while emit_stmt_flow
+#define emit_stmt_until emit_stmt_flow
+DECL_STMT_FUNC(emit, m_bool , Emitter)
ANN static m_bool emit_stmt(const Emitter emit, const Stmt stmt, const m_bool pop) {
CHECK_BB(stmt_func[stmt->stmt_type](emit, &stmt->d))
}
#define emit_fptr_def dummy_func
-DECL_SECTION_FUNC(emit)
+HANDLE_SECTION_FUNC(emit, m_bool, Emitter)
ANN Code* emit_class_code(const Emitter emit, const m_str name) {
const m_uint len = strlen(name) + 7;
STRING(o) = "";
}
-ANN Type prim_str(const Env, Exp_Primary *const);
+ANN Type check_prim_str(const Env, Exp_Primary *const);
ID_CHECK(check_funcpp) {
((Exp_Primary*)prim)->primary_type = ae_primary_str;
((Exp_Primary*)prim)->d.str = env->func ? env->func->name : env->class_def ?
env->class_def->name : env->name;
- return prim_str(env, (Exp_Primary * const)prim);
+ return check_prim_str(env, (Exp_Primary * const)prim);
}
static GACK(gack_string) {
return array_type(env, type->array_depth ? array_base(type) : type, type->array_depth + 1);
}
-ANN static Type prim_array(const Env env, const Exp_Primary* primary) {
+ANN static Type check_prim_array(const Env env, const Exp_Primary* primary) {
const Array_Sub array = primary->d.array;
const Exp e = array->exp;
if(!e)
return value;
}
-ANN Type prim_str(const Env env, Exp_Primary *const prim) {
+ANN Type check_prim_str(const Env env, Exp_Primary *const prim) {
if(!prim->value) {
const m_str str = prim->d.str;
char c[strlen(str) + 8];
return env->gwion->type[et_string];// prim->value
}
-ANN static Type prim_id(const Env env, Exp_Primary* primary) {
+ANN static Type check_prim_id(const Env env, Exp_Primary* primary) {
struct SpecialId_ * spid = specialid_get(env->gwion, primary->d.var);
if(spid)
return specialid_type(env, spid, primary);
}
}
-ANN static Type prim_vec(const Env env, const Exp_Primary* primary) {
+ANN static Type check_prim_vec(const Env env, const Exp_Primary* primary) {
const Vec * vec = &primary->d.vec;
const ae_prim_t t = primary->primary_type;
struct VecInfo info = { .n=vec->dim };
return info.t;
}
-ANN static Type prim_gack(const Env env, const Exp_Primary * primary) {
+ANN static Type check_prim_hack(const Env env, const Exp_Primary * primary) {
if(env->func)
UNSET_FLAG(env->func, pure);
CHECK_OO((check_exp(env, primary->d.exp)))
return env->gwion->type[et_gack];
}
-ANN static Type prim_tuple(const Env env, const Exp_Primary * primary) {
+ANN static Type check_prim_tuple(const Env env, const Exp_Primary * primary) {
CHECK_OO(check_exp(env, primary->d.tuple.exp))
struct Vector_ v;
vector_init(&v);
}
#define describe_prim_xxx(name, type) \
-ANN static Type prim_##name(const Env env NUSED, const Exp_Primary * primary NUSED) {\
+ANN static Type check##_prim_##name(const Env env NUSED, const Exp_Primary * primary NUSED) {\
return type; \
}
describe_prim_xxx(num, env->gwion->type[et_int])
describe_prim_xxx(nil, env->gwion->type[et_void])
describe_prim_xxx(unpack, env->gwion->type[et_tuple])
-typedef Type (*_type_func)(const Env, const void*);
-static const _type_func prim_func[] = {
- (_type_func)prim_id, (_type_func)prim_num, (_type_func)prim_float, (_type_func)prim_str,
- (_type_func)prim_array, (_type_func)prim_gack, (_type_func)prim_vec, (_type_func)prim_vec,
- (_type_func)prim_vec, (_type_func)prim_tuple, (_type_func)prim_unpack,
- (_type_func)prim_num, (_type_func)prim_nil,
-};
+#define check_prim_complex check_prim_vec
+#define check_prim_polar check_prim_vec
+#define check_prim_char check_prim_num
+DECL_PRIM_FUNC(check, Type, Env);
-ANN static Type check_exp_primary(const Env env, const Exp_Primary* primary) {
+ANN static Type check_exp_primary(const Env env, Exp_Primary *primary) {
return exp_self(primary)->type = prim_func[primary->primary_type](env, primary);
}
return v->type;
}
-static const _type_func exp_func[] = {
- (_type_func)check_exp_decl, (_type_func)check_exp_binary, (_type_func)check_exp_unary,
- (_type_func)check_exp_primary, (_type_func)check_exp_cast, (_type_func)check_exp_post,
- (_type_func)check_exp_call, (_type_func)check_exp_array, (_type_func)check_exp_if,
- (_type_func)check_exp_dot, (_type_func)check_exp_lambda, (_type_func)check_exp_typeof
-};
+DECL_EXP_FUNC(check, Type, Env)
ANN static inline Type check_exp(const Env env, const Exp exp) {
Exp curr = exp, next = NULL, prev = NULL;
RET_NSPC(_check_stmt_match(env, stmt))
}
-static const _exp_func stmt_func[] = {
- (_exp_func)check_stmt_exp, (_exp_func)check_stmt_flow, (_exp_func)check_stmt_flow,
- (_exp_func)check_stmt_for, (_exp_func)check_stmt_auto, (_exp_func)check_stmt_loop,
- (_exp_func)check_stmt_if, (_exp_func)check_stmt_code, (_exp_func)check_stmt_break,
- (_exp_func)check_stmt_continue, (_exp_func)check_stmt_return, (_exp_func)check_stmt_match,
- (_exp_func)check_stmt_jump,
-};
+#define check_stmt_while check_stmt_flow
+#define check_stmt_until check_stmt_flow
+DECL_STMT_FUNC(check, m_bool , Env)
ANN m_bool check_stmt(const Env env, const Stmt stmt) {
return stmt_func[stmt->stmt_type](env, &stmt->d);
}
#define check_fptr_def dummy_func
-DECL_SECTION_FUNC(check)
+HANDLE_SECTION_FUNC(check, m_bool, Env)
ANN static m_bool check_parent(const Env env, const Class_Def cdef) {
const Type parent = cdef->base.type->e->parent;
}
#define scan1_exp_lambda dummy_func
-HANDLE_EXP_FUNC(scan1, m_bool, 1)
+HANDLE_EXP_FUNC(scan1, m_bool, Env)
ANN static inline m_bool _scan1_stmt_match_case(const restrict Env env, const Stmt_Match stmt) {
CHECK_BB(scan1_exp(env, stmt->cond))
return ret;
}
-static const _exp_func stmt_func[] = {
- (_exp_func)scan1_stmt_exp, (_exp_func)scan1_stmt_flow, (_exp_func)scan1_stmt_flow,
- (_exp_func)scan1_stmt_for, (_exp_func)scan1_stmt_auto, (_exp_func)scan1_stmt_loop,
- (_exp_func)scan1_stmt_if, (_exp_func)scan1_stmt_code, (_exp_func)dummy_func,
- (_exp_func)dummy_func, (_exp_func)scan1_stmt_exp, (_exp_func)scan1_stmt_match,
- (_exp_func)dummy_func
-};
+#define scan1_stmt_while scan1_stmt_flow
+#define scan1_stmt_until scan1_stmt_flow
+#define scan1_stmt_continue (void*)dummy_func
+#define scan1_stmt_break (void*)dummy_func
+#define scan1_stmt_jump (void*)dummy_func
+#define scan1_stmt_return scan1_stmt_exp
+DECL_STMT_FUNC(scan1, m_bool, Env)
ANN static inline m_bool scan1_stmt(const Env env, const Stmt stmt) {
return stmt_func[stmt->stmt_type](env, &stmt->d);
return ret;
}
-DECL_SECTION_FUNC(scan1)
+HANDLE_SECTION_FUNC(scan1, m_bool, Env)
ANN static Type scan1_get_parent(const Env env, const Type_Def tdef) {
const Type parent = known_type(env, tdef->ext);
}
#define scan2_exp_lambda dummy_func
-HANDLE_EXP_FUNC(scan2, m_bool, 1)
+HANDLE_EXP_FUNC(scan2, m_bool, Env)
#define scan2_stmt_func(name, type, prolog, exp) describe_stmt_func(scan2, name, type, prolog, exp)
scan2_stmt_func(flow, Stmt_Flow,, !(scan2_exp(env, stmt->cond) < 0 ||
return ret;
}
-static const _exp_func stmt_func[] = {
- (_exp_func)scan2_stmt_exp, (_exp_func)scan2_stmt_flow, (_exp_func)scan2_stmt_flow,
- (_exp_func)scan2_stmt_for, (_exp_func)scan2_stmt_auto, (_exp_func)scan2_stmt_loop,
- (_exp_func)scan2_stmt_if, (_exp_func)scan2_stmt_code, (_exp_func)dummy_func,
- (_exp_func)dummy_func, (_exp_func)scan2_stmt_exp, (_exp_func)scan2_stmt_match,
- (_exp_func)scan2_stmt_jump
-};
+
+#define scan2_stmt_while scan2_stmt_flow
+#define scan2_stmt_until scan2_stmt_flow
+#define scan2_stmt_continue (void*)dummy_func
+#define scan2_stmt_break (void*)dummy_func
+#define scan2_stmt_return scan2_stmt_exp
+
+DECL_STMT_FUNC(scan2, m_bool, Env)
ANN static m_bool scan2_stmt(const Env env, const Stmt stmt) {
return stmt_func[stmt->stmt_type](env, &stmt->d);
}
#define scan2_enum_def dummy_func
-DECL_SECTION_FUNC(scan2)
+HANDLE_SECTION_FUNC(scan2, m_bool, Env)
ANN static m_bool scan2_parent(const Env env, const Class_Def cdef) {
const Type parent = cdef->base.type->e->parent;