JSON-Lang/compile.py

28 lines
818 B
Python

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
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))
result = evaluate(subst_all(BUILTIN_SUBSTITUTIONS, expr))
if isinstance(result, ReplHole):
print(result.render())
else:
print(result.codegen())
case _:
raise Exception('TODO')
if __name__ == '__main__':
main()