2024-03-15 13:34:54 +00:00
|
|
|
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
|
2024-03-17 02:02:22 +00:00
|
|
|
from opt import optimize_to_fixpoint, all_optimizations
|
2024-03-15 13:34:54 +00:00
|
|
|
|
|
|
|
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))
|
2024-03-17 02:02:22 +00:00
|
|
|
expr_with_builtins = subst_all(BUILTIN_SUBSTITUTIONS, expr)
|
|
|
|
expr_with_optimization = optimize_to_fixpoint(all_optimizations, expr_with_builtins)
|
|
|
|
result = evaluate(expr_with_optimization)
|
2024-03-15 13:34:54 +00:00
|
|
|
if isinstance(result, ReplHole):
|
|
|
|
print(result.render())
|
|
|
|
else:
|
|
|
|
print(result.codegen())
|
|
|
|
case _:
|
|
|
|
raise Exception('TODO')
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|