def test_interpret_block() -> None: term = init_term_block(SyntaxNumber(int32(2))) expression_stack = MachineExpressionStack( [MachineNumber(int32(10))] ) frame_stack = init_test_frame_stack( init_term_block(term), expression_stack ) interpret_term(frame_stack) assert len(frame_stack) == 2 assert ( frame_stack.frames[0] == init_test_frame_stack( init_term_block(term), MachineExpressionStack( [MachineNumber(int32(10))] ), term_index=1, ).frames[0] ) assert frame_stack.frames[1] == MachineFrame( instruction_pointer=MachineInstructionPointer( block=term, statement_index=0, term_index=0 ), environment=test_environment().extend(), expression_stack=MachineExpressionStack( [MachineNumber(int32(10))] ), )
def interpret_statement(frame_stack: MachineFrameStack, ) -> None: statement = frame_stack.current.statement term_index = frame_stack.current.term_index if term_index == 0: interpret_statement_enter(frame_stack) if term_index < len(statement.terms): interpret_term(frame_stack) else: interpret_statement_exit(frame_stack) next_statement(frame_stack)
def test_interpret_number() -> None: term = SyntaxNumber(int32(100)) frame_stack = init_test_frame_stack( init_term_block(term), MachineExpressionStack([]) ) interpret_term(frame_stack) assert frame_stack == init_test_frame_stack( init_term_block(term), MachineExpressionStack([MachineNumber(int32(100))]), term_index=1, )
def test_interpret_comment() -> None: term = SyntaxComment("something") expression_stack = MachineExpressionStack( [MachineNumber(int32(10))] ) frame_stack = init_test_frame_stack( init_term_block(term), expression_stack ) interpret_term(frame_stack) assert frame_stack == init_test_frame_stack( init_term_block(term), MachineExpressionStack([MachineNumber(int32(10))]), term_index=1, )
def test_interpret_identifier_call() -> None: term = SyntaxIdentifier(sqrt.name) expression_stack = MachineExpressionStack( [MachineNumber(int32(16))] ) frame_stack = init_test_frame_stack( init_term_block(term), expression_stack ) interpret_term(frame_stack) assert frame_stack == init_test_frame_stack( init_term_block(term), MachineExpressionStack([MachineNumber(int32(4))]), term_index=1, )
def test_interpret_identifier_value() -> None: term = SyntaxIdentifier(PI.name) expression_stack = MachineExpressionStack([]) frame_stack = init_test_frame_stack( init_term_block(term), expression_stack ) interpret_term(frame_stack) assert frame_stack == init_test_frame_stack( init_term_block(term), MachineExpressionStack( [cast(MachineValue, PI.value_or_call)] ), term_index=1, )