@@ -26,10 +26,10 @@ using namespace std::literals::string_literals;
2626 */
2727
2828int glob_func_cnt, undef_func_cnt, glob_var_cnt, const_cnt;
29- std::vector<SymDef*> glob_func, glob_vars;
29+ std::vector<SymDef*> glob_func, glob_vars, glob_get_methods ;
3030std::set<std::string> prohibited_var_names;
3131
32- SymDef* predefine_builtin_func ( std::string name, TypeExpr* func_type ) {
32+ SymDef* define_builtin_func_impl ( const std::string& name, SymValAsmFunc* func_val ) {
3333 if (name.back () == ' _' ) {
3434 prohibited_var_names.insert (name);
3535 }
@@ -42,30 +42,40 @@ SymDef* predefine_builtin_func(std::string name, TypeExpr* func_type) {
4242 std::cerr << " fatal: global function `" << name << " ` already defined" << std::endl;
4343 std::exit (1 );
4444 }
45+ func_val->flags |= SymValFunc::flagBuiltinFunction;
46+ def->value = func_val;
47+ #ifdef TOLK_DEBUG
48+ dynamic_cast <SymValAsmFunc*>(def->value )->name = name;
49+ #endif
4550 return def;
4651}
4752
48- template <typename T>
49- SymDef* define_builtin_func (std::string name, TypeExpr* func_type, const T& func, bool impure = false ) {
50- SymDef* def = predefine_builtin_func (name, func_type);
51- def->value = new SymValAsmFunc{func_type, func, impure};
52- return def;
53+ SymDef* define_builtin_func (const std::string& name, TypeExpr* func_type, const simple_compile_func_t & func, bool impure = false ) {
54+ return define_builtin_func_impl (name, new SymValAsmFunc{func_type, func, !impure});
55+ }
56+
57+ SymDef* define_builtin_func (const std::string& name, TypeExpr* func_type, const compile_func_t & func, bool impure = false ) {
58+ return define_builtin_func_impl (name, new SymValAsmFunc{func_type, func, !impure});
59+ }
60+
61+ SymDef* define_builtin_func (const std::string& name, TypeExpr* func_type, const AsmOp& macro, bool impure = false ) {
62+ return define_builtin_func_impl (name, new SymValAsmFunc{func_type, make_simple_compile (macro), !impure});
5363}
5464
55- template <typename T>
56- SymDef* define_builtin_func (std::string name, TypeExpr* func_type, const T& func, std::initializer_list<int > arg_order,
65+ SymDef* define_builtin_func (const std::string& name, TypeExpr* func_type, const simple_compile_func_t & func, std::initializer_list<int > arg_order,
5766 std::initializer_list<int > ret_order = {}, bool impure = false ) {
58- SymDef* def = predefine_builtin_func (name, func_type);
59- def->value = new SymValAsmFunc{func_type, func, arg_order, ret_order, impure};
60- return def;
67+ return define_builtin_func_impl (name, new SymValAsmFunc{func_type, func, arg_order, ret_order, !impure});
6168}
6269
63- SymDef* define_builtin_func (std::string name, TypeExpr* func_type, const AsmOp& macro,
70+ SymDef* define_builtin_func (const std::string& name, TypeExpr* func_type, const compile_func_t & func, std::initializer_list<int > arg_order,
71+ std::initializer_list<int > ret_order = {}, bool impure = false ) {
72+ return define_builtin_func_impl (name, new SymValAsmFunc{func_type, func, arg_order, ret_order, !impure});
73+ }
74+
75+ SymDef* define_builtin_func (const std::string& name, TypeExpr* func_type, const AsmOp& macro,
6476 std::initializer_list<int > arg_order, std::initializer_list<int > ret_order = {},
6577 bool impure = false ) {
66- SymDef* def = predefine_builtin_func (name, func_type);
67- def->value = new SymValAsmFunc{func_type, make_simple_compile (macro), arg_order, ret_order, impure};
68- return def;
78+ return define_builtin_func_impl (name, new SymValAsmFunc{func_type, make_simple_compile (macro), arg_order, ret_order, !impure});
6979}
7080
7181SymDef* force_autoapply (SymDef* def) {
@@ -262,7 +272,7 @@ int emulate_lshift(int a, int b) {
262272 }
263273 int t = ((b & VarDescr::_NonZero) ? VarDescr::_Even : 0 );
264274 t |= b & VarDescr::_Finite;
265- return emulate_mul (a, VarDescr::_Int | VarDescr::_Pos | VarDescr::_NonZero | VarDescr::_Even | t);
275+ return emulate_mul (a, VarDescr::_Int | VarDescr::_Pos | VarDescr::_NonZero | t);
266276}
267277
268278int emulate_div (int a, int b) {
@@ -308,7 +318,7 @@ int emulate_rshift(int a, int b) {
308318 }
309319 int t = ((b & VarDescr::_NonZero) ? VarDescr::_Even : 0 );
310320 t |= b & VarDescr::_Finite;
311- return emulate_div (a, VarDescr::_Int | VarDescr::_Pos | VarDescr::_NonZero | VarDescr::_Even | t);
321+ return emulate_div (a, VarDescr::_Int | VarDescr::_Pos | VarDescr::_NonZero | t);
312322}
313323
314324int emulate_mod (int a, int b, int round_mode = -1 ) {
@@ -1128,9 +1138,9 @@ void define_builtins() {
11281138 auto Int3 = TypeExpr::new_tensor ({Int, Int, Int});
11291139 auto TupleInt = TypeExpr::new_tensor ({Tuple, Int});
11301140 auto SliceInt = TypeExpr::new_tensor ({Slice, Int});
1131- auto X = TypeExpr::new_var ();
1132- auto Y = TypeExpr::new_var ();
1133- auto Z = TypeExpr::new_var ();
1141+ auto X = TypeExpr::new_var (0 );
1142+ auto Y = TypeExpr::new_var (1 );
1143+ auto Z = TypeExpr::new_var (2 );
11341144 auto XY = TypeExpr::new_tensor ({X, Y});
11351145 auto arith_bin_op = TypeExpr::new_map (Int2, Int);
11361146 auto arith_un_op = TypeExpr::new_map (Int, Int);
0 commit comments