Esempio n. 1
0
def main(args):
    """Main entry point allowing external calls

    Args:
      args ([str]): command line parameter list
    """
    args = parse_args(args)
    setup_logging(args.loglevel)
    if args.file:
        try:
            ast = load_file(args.file)
            vm = VM(ast)
            vm.run()
        except InnerPactorRuntimeError as e:
            print(f"Runtime error in {args.file} at [{e.line}:{e.column}]")
            with open(args.file) as f:
                line = f.readline()
                for _ in range(1, e.line):
                    line = f.readline()
            print("> " + line[:-1])
            print("> " + e.error_arrow)
            print("> " + e.message)
        except SyntaxException as e:
            print(f"Syntax Error: {e.message}")
            print(f"{e.error_arrow}")
        except Exception as e:
            print(f"Error: {e}")

        if (args.stack):
            print(vm.stack)
    else:
        repl()
Esempio n. 2
0
    def __run_script(self, script):
        ast = load_script(script)
        vm = VM(ast)
        vm.run()

        return vm