Newer
Older
NewLang / src / main.py
# SPDX-License-Identifier: LGPL-2.1-only
# Copyright 2022 Jookia <contact@jookia.org>

import os
import sys

from src import port
from src import log
from src import oldparse
from src import interp


def main():
    args = sys.argv
    log_level = os.getenv("NEWLANG_LOG_LEVEL")
    if len(args) != 2:
        print("Usage: main.py FILENAME")
        return 1
    log.set_default_log_level(log_level)
    ast = oldparse.parse_file(args[1])
    if not ast:
        return 1
    interp.run_ast(ast)
    return 0


def unexpected_exit():
    input("Unexpected exit. Press any key to continue.")


def wait_main():
    port.atexit_register_one(unexpected_exit)
    code = main()
    port.atexit_unregister()
    input("Exited with code %s. Press any key to continue." % (code))
    sys.exit(code)