Example #1
0
def main_run(
    source_filename: str,
    environment: Optional[MachineEnvironment] = None,
) -> None:
    with open(source_filename, "r") as source_file:
        source_text = source_file.read()
    root_block = parse(source_text)
    root_expression_stack = MachineExpressionStack([])
    if not environment:
        environment = base_environment()
    interpret(root_block, root_expression_stack, environment)
    assert not root_expression_stack, root_expression_stack
    assert "main" in environment, environment.bindings
    main_call = environment["main"]
    assert isinstance(main_call, GuestCall), main_call
    main_expression_stack = MachineExpressionStack([])
    interpret(
        main_call.definition_block,
        main_expression_stack,
        main_call.definition_environment,
    )
    if main_expression_stack.values:
        print(main_expression_stack.values)
Example #2
0
def test_parse(text: str, expected_result: SyntaxBlock) -> None:
    assert parse(text) == expected_result
Example #3
0
 def statement_loop(statement_text: str, ) -> list[MachineValue]:
     block = parse(statement_text)
     expression_stack = MachineExpressionStack([])
     interpret(block, expression_stack, environment)
     return expression_stack.values