def test(): create_environment_with_natives() program = Parser("let var a := 0 in (for i := 1 to 9 do a := a - i; a) end").parse() environment = SimpleEnvironment() result = program.evaluate(environment) assert isinstance(result, IntegerValue) return result.integer
def test(): # adding this line creates more jitcodes in /tmp/usession-exploration-abrown/jitcodes which reduces the number of operations unused = Parser( 'let var a := 0 in (while a < 100 do a := a + 1) end').parse() program = Let( declarations=[ VariableDeclaration(name='a', type_id=None, expression=IntegerValue(0)) ], expressions=[ Sequence(expressions=[ ModifiedWhile(condition=LessThan( left=LValue('a'), right=IntegerValue(100)), body=Assign(lvalue=LValue(name='a'), expression=Add( left=LValue(name='a'), right=IntegerValue(1)))), LValue(name='a', next_lvalue=None) ]) ]) environment = create_environment_with_natives( ) # apparently RPython barfs if we just use Environment() here because NativeFunctionDeclaration.__init__ is never called so the flowspace does not know about the 'function' field result = program.evaluate(environment) assert isinstance(result, IntegerValue) return result.integer
def test(): program = Parser(""" let var max : int := 50 var s : int := 0 var n : int := 2 in while n <= max do let var p : int := 1 var d : int := 2 in while d <= (n - 1) do let var m : int := d * (n / d) in if n <= m then p := 0; d := d + 1 end; if p <> 0 then s := s + n; n := n + 1 end; s end """).parse() environment = create_environment_with_natives( ) # apparently RPython barfs if we just use Environment() here because NativeFunctionDeclaration.__init__ is never called so the flowspace does not know about the 'function' field result = program.evaluate(environment) assert isinstance(result, IntegerValue) return result.integer
def test(): program = Parser( 'let var a := 0 in (while a < 100 do a := a + 1; a) end' ).parse(create_native_functions()) environment = create_environment_with_natives( ) # apparently RPython barfs if we just use Environment() here because NativeFunctionDeclaration.__init__ is never called so the flowspace does not know about the 'function' field result = program.evaluate(environment) assert isinstance(result, IntegerValue) return result.integer
def test(): # output of printing the parsed version: Let(declarations=[VariableDeclaration(name=a, type=None, exp=IntegerValue(0))], expressions=[Sequence(expressions=[For(var=i, start=IntegerValue(1), end=IntegerValue(9), body=Assign(lvalue=LValue(name=a, next=None), expression=Subtract(left=LValue(name=a, next=None), right=LValue(name=i, next=None)))), LValue(name=a, next=None)])]) program = Let(declarations=[VariableDeclaration(name='a', type_id=None, expression=IntegerValue(0))], expressions=[Sequence( expressions=[For(var='i', start=IntegerValue(1), end=IntegerValue(9), body=Assign(lvalue=LValue(name='a', next_lvalue=None), expression=Subtract( left=LValue(name='a', next_lvalue=None), right=LValue(name='i', next_lvalue=None)))), LValue(name='a', next_lvalue=None)])]) program = promote(program) environment = create_environment_with_natives() # apparently RPython barfs if we just use Environment() here because NativeFunctionDeclaration.__init__ is never called so the flowspace does not know about the 'function' field result = program.evaluate(environment) assert isinstance(result, IntegerValue) return result.integer
def test(): # adding this line creates more jitcodes in /tmp/usession-exploration-abrown/jitcodes which reduces the number of operations Parser('let var a := 0 in a end').parse() program = Let(declarations=[VariableDeclaration(name='a', type_id=None, expression=IntegerValue(0))], expressions=[Sequence( expressions=[InternalMergePointFor(var='i', start=IntegerValue(1), end=IntegerValue(9), body=Assign(lvalue=LValue(name='a', next_lvalue=None), expression=Subtract( left=LValue(name='a', next_lvalue=None), right=LValue(name='i', next_lvalue=None)))), LValue(name='a', next_lvalue=None)])]) environment = create_environment_with_natives() # apparently RPython barfs if we just use Environment() here because NativeFunctionDeclaration.__init__ is never called so the flowspace does not know about the 'function' field result = program.evaluate(Environment.empty()) assert isinstance(result, IntegerValue) return result.integer
def test_function_call(self): env = create_environment_with_natives() names = list_native_environment_names(env) self.assertListEqual(['print', 'timeGo', 'timeStop'], names)
def test(): # this is equivalent to what is constructed below unused = Parser(""" let var a := 0 var b := 0 in (while a < 50 do (a := a + 1; while b < 100 do (b := b + 1); b := 0 ); a) end""").parse() program = Let( declarations=[ VariableDeclaration(name='a', type_id=None, expression=IntegerValue(0)), VariableDeclaration(name='b', type_id=None, expression=IntegerValue(0)) ], expressions=[ Sequence(expressions=[ ModifiedWhile( condition=LessThan(left=LValue(name='a', next_lvalue=None), right=IntegerValue(50)), body=Sequence(expressions=[ Assign(lvalue=LValue(name='a', next_lvalue=None), expression=Add(left=LValue( name='a', next_lvalue=None), right=IntegerValue(1))), ModifiedWhile( condition=LessThan( left=LValue(name='b', next_lvalue=None), right=IntegerValue(100)), body=Sequence(expressions=[ Assign(lvalue=LValue(name='b', next_lvalue=None), expression=Add( left=LValue( name='b', next_lvalue=None), right=IntegerValue(1))) ])), Assign(lvalue=LValue(name='b', next_lvalue=None), expression=IntegerValue(0)) ])), LValue(name='a', next_lvalue=None) ]) ]) environment = create_environment_with_natives( ) # apparently RPython barfs if we just use Environment() here because NativeFunctionDeclaration.__init__ is never called so the flowspace does not know about the 'function' field result = program.evaluate(environment) assert isinstance(result, IntegerValue) return result.integer