From: fennecdjay Date: Thu, 24 Oct 2019 15:57:39 +0000 (+0200) Subject: :art: split import => oper X-Git-Tag: nightly~2116^2~29 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=1b21a3d3d06ee085c8b82110b4ad2192c308d5c7;p=gwion.git :art: split import => oper --- diff --git a/include/import.h b/include/import.h index 863b0e10..6a648a95 100644 --- a/include/import.h +++ b/include/import.h @@ -42,9 +42,7 @@ ANN2(1,2)m_int gwi_class_ini(const Gwi gwi, const Type type, const f_xtor pre_ct ANN m_int gwi_class_ext(const Gwi gwi, Type_Decl* td); ANN m_int gwi_class_end(const Gwi gwi); -ANN m_int gwi_item_ini(const Gwi gwi, const m_str type, const m_str name); -ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, const m_uint* addr); -#define gwi_item_end(a, b, c) gwi_item_end(a, (const ae_flag)(b), (const m_uint*)c) +#include "import/item.h" ANN m_int gwi_fptr_ini(const Gwi gwi, const m_str __restrict__ type, const __restrict__ m_str name); ANN Type gwi_fptr_end(const Gwi gwi, const ae_flag flag); diff --git a/include/import/item.h b/include/import/item.h new file mode 100644 index 00000000..05dbc2a2 --- /dev/null +++ b/include/import/item.h @@ -0,0 +1,8 @@ +#ifndef __IMPORT_ITEM +#define __IMPORT_ITEM + +ANN m_int gwi_item_ini(const Gwi gwi, const m_str type, const m_str name); +ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, const m_uint* addr); +#define gwi_item_end(a, b, c) gwi_item_end(a, (const ae_flag)(b), (const m_uint*)c) + +#endif diff --git a/include/import/oper.h b/include/import/oper.h new file mode 100644 index 00000000..b2322c40 --- /dev/null +++ b/include/import/oper.h @@ -0,0 +1,10 @@ +#ifndef __IMPORT_OPER +#define __IMPORT_OPER + +ANN2(1) m_int gwi_oper_ini(const Gwi gwi, const m_str l, const m_str r, const m_str t); +ANN m_int gwi_oper_add(const Gwi gwi, const opck); +ANN m_int gwi_oper_emi(const Gwi gwi, const opem); +ANN2(1) m_int gwi_oper_end(const Gwi gwi, const m_str op, const f_instr f); +ANN m_int gwi_oper_cond(const Gwi, const m_str, const f_instr, const f_instr); + +#endif diff --git a/src/import/oper.c b/src/import/oper.c new file mode 100644 index 00000000..043c8754 --- /dev/null +++ b/src/import/oper.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include "gwion_util.h" +#include "gwion_ast.h" +#include "oo.h" +#include "vm.h" +#include "env.h" +#include "type.h" +#include "value.h" +#include "traverse.h" +#include "instr.h" +#include "object.h" +#include "emit.h" +#include "func.h" +#include "nspc.h" +#include "gwion.h" +#include "operator.h" +#include "import.h" +#include "gwi.h" +#include "mpool.h" +#include "specialid.h" + +ANN2(1,3) static Type _get_type(const Env env, const m_str str, const loc_t pos) { + m_uint depth = 0; + const ID_List list = (str && str != (m_str)OP_ANY_TYPE) ? str2list(env, str, &depth, pos) : NULL; + const Type t = (str == (m_str) OP_ANY_TYPE) ? OP_ANY_TYPE : list ? find_type(env, list) : NULL; + if(list) + free_id_list(env->gwion->mp, list); + return t ? (depth ? array_type(env, t, depth) : t) : NULL; +} + +ANN2(1,3) static inline Type get_type(const Env env, const m_str str, const loc_t pos) { + return str ? _get_type(env, str, pos) : NULL; +} + +ANN2(1,2) static int import_op(const Gwi gwi, const DL_Oper* op, + const f_instr f) { + const Env env = gwi->gwion->env; + const Type lhs = get_type(env, op->lhs, gwi->loc), + rhs = get_type(env, op->rhs, gwi->loc), + ret = _get_type(env, op->ret, gwi->loc); + const struct Op_Import opi = { lhs, rhs, ret, + op->ck, op->em, (uintptr_t)f, gwi->loc, op->op }; + return add_op(gwi->gwion, &opi); +} + + +ANN2(1) m_int gwi_oper_ini(const Gwi gwi, const restrict m_str l, + const restrict m_str r, const restrict m_str t) { + gwi->oper.ret = t; + gwi->oper.rhs = r; + gwi->oper.lhs = l; + return GW_OK; +} + +ANN m_int gwi_oper_add(const Gwi gwi, Type (*ck)(Env, void*, m_bool*)) { + gwi->oper.ck = ck; + return GW_OK; +} + +ANN m_int gwi_oper_emi(const Gwi gwi, const opem em) { + gwi->oper.em = em; + return GW_OK; +} + +ANN m_int gwi_oper_end(const Gwi gwi, const m_str op, const f_instr f) { + gwi->oper.op = insert_symbol(gwi->gwion->st, op); + const m_bool ret = import_op(gwi, &gwi->oper, f); + gwi->oper.ck = NULL; + gwi->oper.em = NULL; + return ret; +} + +ANN m_int gwi_oper_cond(const Gwi gwi, const m_str type, + const f_instr f1, const f_instr f2) { + GWI_BB(gwi_oper_ini(gwi, NULL, type, "int")) + GWI_BB(gwi_oper_end(gwi, "@conditionnal", f1)) + GWI_BB(gwi_oper_end(gwi, "@unconditionnal", f2)) + return GW_OK; +} diff --git a/src/lib/import.c b/src/lib/import.c index 89a89fc4..f0b07352 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -568,65 +568,6 @@ ANN m_int gwi_func_end(const Gwi gwi, const ae_flag flag) { return GW_ERROR; } -ANN2(1,3) static Type _get_type(const Env env, const m_str str, const loc_t pos) { - m_uint depth = 0; - const ID_List list = (str && str != (m_str)OP_ANY_TYPE) ? str2list(env, str, &depth, pos) : NULL; - const Type t = (str == (m_str) OP_ANY_TYPE) ? OP_ANY_TYPE : list ? find_type(env, list) : NULL; - if(list) - free_id_list(env->gwion->mp, list); - return t ? (depth ? array_type(env, t, depth) : t) : NULL; -} - -ANN2(1,3) static inline Type get_type(const Env env, const m_str str, const loc_t pos) { - return str ? _get_type(env, str, pos) : NULL; -} - -ANN2(1,2) static int import_op(const Gwi gwi, const DL_Oper* op, - const f_instr f) { - const Env env = gwi->gwion->env; - const Type lhs = get_type(env, op->lhs, gwi->loc), - rhs = get_type(env, op->rhs, gwi->loc), - ret = _get_type(env, op->ret, gwi->loc); - const struct Op_Import opi = { lhs, rhs, ret, - op->ck, op->em, (uintptr_t)f, gwi->loc, op->op }; - return add_op(gwi->gwion, &opi); -} - - -ANN2(1) m_int gwi_oper_ini(const Gwi gwi, const restrict m_str l, - const restrict m_str r, const restrict m_str t) { - gwi->oper.ret = t; - gwi->oper.rhs = r; - gwi->oper.lhs = l; - return GW_OK; -} - -ANN m_int gwi_oper_add(const Gwi gwi, Type (*ck)(Env, void*, m_bool*)) { - gwi->oper.ck = ck; - return GW_OK; -} - -ANN m_int gwi_oper_emi(const Gwi gwi, const opem em) { - gwi->oper.em = em; - return GW_OK; -} - -ANN m_int gwi_oper_end(const Gwi gwi, const m_str op, const f_instr f) { - gwi->oper.op = insert_symbol(gwi->gwion->st, op); - const m_bool ret = import_op(gwi, &gwi->oper, f); - gwi->oper.ck = NULL; - gwi->oper.em = NULL; - return ret; -} - -ANN m_int gwi_oper_cond(const Gwi gwi, const m_str type, - const f_instr f1, const f_instr f2) { - GWI_BB(gwi_oper_ini(gwi, NULL, type, "int")) - GWI_BB(gwi_oper_end(gwi, "@conditionnal", f1)) - GWI_BB(gwi_oper_end(gwi, "@unconditionnal", f2)) - return GW_OK; -} - ANN m_int gwi_fptr_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name) { dl_func_init(&gwi->func, type, name, 0); return GW_OK;