def test_modulo_big_numbers() -> str: code: str = generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(10000000000000000000000000000), IntNumberValue(0), 'DIV'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(456988946138451327846351276843512), IntNumberValue(454562), 'MOD'), visitor=interpreter) + 'PUT\n' return code
def test_divide_big_numbers() -> str: code: str = generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(10000000000000000000000000000), IntNumberValue(2), 'DIV'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(10000000000000000000000000000), IntNumberValue(0), 'DIV'), visitor=interpreter) + 'PUT\n' return code
def test_single_val_expr(): code: str = '' code = code + generate_code_for_expression(ExpressionHavingOneValue( IntNumberValue(111)), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingOneValue( IdentifierValue(VariableIdentifier('d'))), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingOneValue( IdentifierValue(VariableIdentifier('c'))), visitor=interpreter) + 'PUT\n' return code
def test_divide_ones() -> str: code = generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('one')), IdentifierValue(VariableIdentifier('one')), 'DIV'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('one')), IdentifierValue(VariableIdentifier('m_one')), 'DIV'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('m_one')), IdentifierValue(VariableIdentifier('one')), 'DIV'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('m_one')), IdentifierValue(VariableIdentifier('m_one')), 'DIV'), visitor=interpreter) + 'PUT\n' return code
def test_sub(): code: str = '' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('d')), IntNumberValue(-60), 'MINUS'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(-4), IdentifierValue(VariableIdentifier('c')), 'MINUS'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('d')), IdentifierValue(VariableIdentifier('c')), 'MINUS'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(-60), IntNumberValue(66), 'MINUS'), visitor=interpreter) + 'PUT\n' return code
def test_add(): code: str = '' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('d')), IntNumberValue(-60), 'PLUS'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(-4), IdentifierValue(VariableIdentifier('c')), 'PLUS'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('d')), IdentifierValue(VariableIdentifier('c')), 'PLUS'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(60), IntNumberValue(-66), 'PLUS'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue( ArrayElementByIntNumberIdentifier('arr', IntNumberValue(-14))), IdentifierValue( ArrayElementByIntNumberIdentifier('arr', IntNumberValue(-15))), 'PLUS'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(ArrayElementByVariableIdentifier('arr', 'e')), IdentifierValue(ArrayElementByVariableIdentifier('arr', 'f')), 'PLUS'), visitor=interpreter) + 'PUT\n' return code
def test_modulo_number_values() -> str: code: str = generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(76), IntNumberValue(10), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(7), IntNumberValue(10), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(25), IntNumberValue(10), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(25), IntNumberValue(5), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(10000000000000000000000000000), IntNumberValue(0), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(0), IntNumberValue(784), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(24), IntNumberValue(7), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(24), IntNumberValue(-7), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(-24), IntNumberValue(7), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(-24), IntNumberValue(-7), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IntNumberValue(7894), IntNumberValue(-215), 'MOD'), visitor=interpreter) + 'PUT\n' return code
def init() -> str: expr1 = ExpressionHavingOneValue(IntNumberValue(10)) expr2 = ExpressionHavingOneValue(IntNumberValue(20)) expr3 = ExpressionHavingOneValue(IntNumberValue(-15)) expr4 = ExpressionHavingOneValue(IntNumberValue(-14)) code: str = generate_numbers_naive(interpreter.constants) code = code + generate_code_for_expression( expr1, interpreter) + f'STORE {decl_arrays["arr"][0] + 5 }\n' # arr[-15]=10 code = code + generate_code_for_expression( expr2, interpreter) + f'STORE {decl_arrays["arr"][0] + 6 }\n' # arr[-14]=20 code = code + generate_code_for_expression( expr3, interpreter) + f'STORE {decl_vars["e"]}\n' # e = -15 code = code + generate_code_for_expression( expr4, interpreter) + f'STORE {decl_vars["f"]}\n' # f = -14 code = code + generate_code_for_expression( expr1, interpreter) + f'STORE {decl_vars["g"]}\n' # g = 10 code = code + generate_numbers({ 24: decl_vars['tw_four'], 248974361532: decl_vars['big_1'], -879461521222224: decl_vars['big_2'], -24: decl_vars['m_tw_four'], -7: decl_vars['m_seven'], 7: decl_vars['seven'], 1: decl_vars['one'], -1: decl_vars['m_one'], 0: decl_vars['zero'], 5: decl_vars['five'], -5: decl_vars['m_five'], 28: decl_vars['tw_eight'], -28: decl_vars['m_tw_eight'], 100: decl_vars['hundred'], -100: decl_vars['m_hundred'], }) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('tw_four'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('m_tw_four'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('m_seven'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('seven'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('one'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('m_one'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('zero'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('five'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('m_five'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('tw_eight'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('m_tw_eight'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('hundred'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('m_hundred'))), interpreter) code = code + generate_code_for_write_command( WriteCommand( IdentifierValue( ArrayElementByIntNumberIdentifier( 'arr', IntNumberValue(-15)))), interpreter) code = code + generate_code_for_write_command( WriteCommand( IdentifierValue( ArrayElementByIntNumberIdentifier( 'arr', IntNumberValue(-14)))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('e'))), interpreter) code = code + generate_code_for_write_command( WriteCommand(IdentifierValue(VariableIdentifier('f'))), interpreter) code = code + generate_code_for_write_command( WriteCommand( IdentifierValue(ArrayElementByVariableIdentifier('arr', 'e'))), interpreter) code = code + generate_code_for_write_command( WriteCommand( IdentifierValue(ArrayElementByVariableIdentifier('arr', 'f'))), interpreter) return code
def test_modulo_variables() -> str: code: str = generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(ArrayElementByVariableIdentifier('arr', 'f')), IdentifierValue(ArrayElementByVariableIdentifier('arr', 'e')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('tw_four')), IdentifierValue(VariableIdentifier('seven')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('tw_four')), IdentifierValue(VariableIdentifier('m_seven')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('m_tw_four')), IdentifierValue(VariableIdentifier('seven')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('m_tw_four')), IdentifierValue(VariableIdentifier('m_seven')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('one')), IdentifierValue(VariableIdentifier('one')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('one')), IdentifierValue(VariableIdentifier('zero')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('zero')), IdentifierValue(VariableIdentifier('one')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('zero')), IdentifierValue(VariableIdentifier('zero')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('tw_eight')), IdentifierValue(VariableIdentifier('five')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('tw_eight')), IdentifierValue(VariableIdentifier('m_five')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('m_tw_eight')), IdentifierValue(VariableIdentifier('five')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('m_tw_eight')), IdentifierValue(VariableIdentifier('m_five')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('hundred')), IdentifierValue(VariableIdentifier('tw_eight')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('hundred')), IdentifierValue(VariableIdentifier('m_tw_eight')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('m_hundred')), IdentifierValue(VariableIdentifier('tw_eight')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('m_hundred')), IdentifierValue(VariableIdentifier('m_tw_eight')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('tw_eight')), IdentifierValue(VariableIdentifier('m_seven')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('tw_eight')), IdentifierValue(VariableIdentifier('seven')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('tw_eight')), IdentifierValue(VariableIdentifier('hundred')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('tw_eight')), IdentifierValue(VariableIdentifier('m_hundred')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('m_tw_eight')), IdentifierValue(VariableIdentifier('hundred')), 'MOD'), visitor=interpreter) + 'PUT\n' code = code + generate_code_for_expression(ExpressionHavingTwoValues( IdentifierValue(VariableIdentifier('m_tw_eight')), IdentifierValue(VariableIdentifier('m_hundred')), 'MOD'), visitor=interpreter) + 'PUT\n' return code
def visit_expression_having_two_values(self, expression: 'ExpressionHavingTwoValues'): self.generated_code.append( generate_code_for_expression(expression, self))
def visit_expression_having_one_value(self, expression: 'ExpressionHavingOneValue'): self.generated_code.append( generate_code_for_expression(expression, self))