Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def test_simple(self):
- """
- We build a list of AST nodes: some are one-arg native functions and some are zero-arg native functions. RPython
- seems unable to determine which one it is virtually dispatching to:
- AnnotatorError:
- signature mismatch: native_print_newline() takes no arguments (1 given)
- Occurred processing the following simple_call:
- function native_print_newline <.../src/experimental/native_functions.py, line 76> returning
- function native_print <.../src/experimental/native_functions.py, line 72> returning
- v2 = simple_call(v0, v1)
- In <FunctionGraph of (native_functions:69)OneArgFunction.call at 0x7f714ff320d0>:
- Happened at file .../src/experimental/native_functions.py line 70
- ==> return self.function(arguments[0])
- Known variable annotations:
- v0 = SomePBC(can_be_None=False, descriptions={...2...}, knowntype=function, subset_of=None)
- v1 = SomeString(no_nul=True)
- """
- class NativeFunction:
- def __init__(self, function):
- self.function = function
- def call(self, arguments):
- raise Exception("Use descendants")
- class ZeroArgFunction(NativeFunction):
- def call(self, arguments):
- return self.function()
- def native_print_newline():
- print('\n')
- return 1
- class OneArgFunction(NativeFunction):
- def call(self, arguments):
- return self.function(arguments[0])
- def native_print(s):
- print(s)
- return len(s)
- def test(*args):
- arguments = ['as', 'b', 'c']
- assert isinstance(arguments, list)
- program = [ZeroArgFunction(native_print_newline), OneArgFunction(native_print),
- ZeroArgFunction(native_print_newline)]
- result = 0
- for node in program:
- result = node.call(arguments)
- return result
- # eventually calls something like: return LLJitMixin().meta_interp(function, arguments, listops=True, inline=True)
- self.assertEqual(interpretation_mechanisms.meta_interpret(test, [41, 42, 43]), 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement