from emis_funky_funktions import * from typing import Collection, Sequence, TypeAlias from ir import BUILTIN_SUBSTITUTIONS, Expression, ReplHole, subst_all from genir import json_to_ir, PatternParseProblem, BranchTypesDiffer, UndefinedVariable from types_ import BUILTINS_CONTEXT, UnificationError from silly_thing import evaluate from opt import optimize_to_fixpoint, all_optimizations import json from dataclasses import dataclass from operator import add def main(): import sys match sys.argv: case [_, file]: # TODO handle this expr, ty, substs = unwrap_r(json_to_ir(json.loads(open(sys.argv[1]).read()), BUILTINS_CONTEXT)) expr_with_builtins = subst_all(BUILTIN_SUBSTITUTIONS, expr) expr_with_optimization = optimize_to_fixpoint(all_optimizations, expr_with_builtins) result = evaluate(expr_with_optimization) if isinstance(result, ReplHole): print(result.render()) else: print(result.codegen()) case _: raise Exception('TODO') if __name__ == '__main__': main()