|
1 | 1 | # gen_dispatch_stubs.py |
2 | 2 | import os |
| 3 | +import sys |
3 | 4 |
|
4 | 5 | type_tags = [ |
5 | 6 | "none", "int", "float", "string", "bool", "double", "long", "long_long", "long_double", |
|
37 | 38 | "land": "and", "lor": "or" |
38 | 39 | } |
39 | 40 |
|
| 41 | +# OpTable map to Struct names |
| 42 | +op_struct_map = { |
| 43 | + "add": "Add", "sub": "Sub", "mul": "Mul", "div": "Div", "mod": "Mod", |
| 44 | + "eq": "Eq", "ne": "Ne", "gt": "Gt", "ge": "Ge", "lt": "Lt", "le": "Le", |
| 45 | + "band": "BitAnd", "bor": "BitOr", "bxor": "BitXor", |
| 46 | + "shl": "ShiftLeft", "shr": "ShiftRight", |
| 47 | + "land": "LogicalAnd", "lor": "LogicalOr" |
| 48 | +} |
| 49 | + |
| 50 | +if len(sys.argv) > 1 and sys.argv[1] == 'declarations': |
| 51 | + print("// Generated declarations for OpTable specializations") |
| 52 | + for opname, opstruct_name in op_struct_map.items(): |
| 53 | + print(f"template<> const std::array<std::array<BinaryOpFunc, TypeTagCount>, TypeTagCount> OpTable<{opstruct_name}>::table;") |
| 54 | + sys.exit(0) |
| 55 | + |
40 | 56 | print("#include \"pythonic/pythonicDispatchForwardDecls.hpp\"") |
41 | 57 | print("#include \"pythonic/pythonicVars.hpp\"") |
42 | 58 | print("#include \"pythonic/pythonicError.hpp\"") |
@@ -810,16 +826,8 @@ def print_cast(operand, varname, t, ctype): |
810 | 826 |
|
811 | 827 | print("}") |
812 | 828 |
|
813 | | -# OpTable map to Struct names |
814 | | -op_struct_map = { |
815 | | - "add": "Add", "sub": "Sub", "mul": "Mul", "div": "Div", "mod": "Mod", |
816 | | - "eq": "Eq", "ne": "Ne", "gt": "Gt", "ge": "Ge", "lt": "Lt", "le": "Le", |
817 | | - "band": "BitAnd", "bor": "BitOr", "bxor": "BitXor", |
818 | | - "shl": "ShiftLeft", "shr": "ShiftRight", |
819 | | - "land": "LogicalAnd", "lor": "LogicalOr" |
820 | | -} |
821 | | - |
822 | 829 | # Generate OpTable initializations |
| 830 | + |
823 | 831 | for opname, opstruct_name in op_struct_map.items(): |
824 | 832 | actual_op_func = ops[opname] # e.g. "add" |
825 | 833 | print(f"\n// OpTable initialization for {opstruct_name}") |
|
0 commit comments