Advertisement
Guest User

Untitled

a guest
Oct 31st, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1.     def test_simple(self):
  2.         """
  3.        We build a list of AST nodes: some are one-arg native functions and some are zero-arg native functions. RPython
  4.        seems unable to determine which one it is virtually dispatching to:
  5.  
  6.        AnnotatorError:
  7.  
  8.        signature mismatch: native_print_newline() takes no arguments (1 given)
  9.  
  10.  
  11.        Occurred processing the following simple_call:
  12.          function native_print_newline <.../src/experimental/native_functions.py, line 76> returning
  13.  
  14.          function native_print <.../src/experimental/native_functions.py, line 72> returning
  15.  
  16.            v2 = simple_call(v0, v1)
  17.  
  18.        In <FunctionGraph of (native_functions:69)OneArgFunction.call at 0x7f714ff320d0>:
  19.        Happened at file .../src/experimental/native_functions.py line 70
  20.  
  21.        ==>                 return self.function(arguments[0])
  22.  
  23.        Known variable annotations:
  24.         v0 = SomePBC(can_be_None=False, descriptions={...2...}, knowntype=function, subset_of=None)
  25.         v1 = SomeString(no_nul=True)
  26.        """
  27.  
  28.         class NativeFunction:
  29.             def __init__(self, function):
  30.                 self.function = function
  31.  
  32.             def call(self, arguments):
  33.                 raise Exception("Use descendants")
  34.  
  35.         class ZeroArgFunction(NativeFunction):
  36.             def call(self, arguments):
  37.                 return self.function()
  38.  
  39.         def native_print_newline():
  40.             print('\n')
  41.             return 1
  42.  
  43.         class OneArgFunction(NativeFunction):
  44.             def call(self, arguments):
  45.                 return self.function(arguments[0])
  46.  
  47.         def native_print(s):
  48.             print(s)
  49.             return len(s)
  50.  
  51.         def test(*args):
  52.             arguments = ['as', 'b', 'c']
  53.             assert isinstance(arguments, list)
  54.             program = [ZeroArgFunction(native_print_newline), OneArgFunction(native_print),
  55.                        ZeroArgFunction(native_print_newline)]
  56.             result = 0
  57.             for node in program:
  58.                 result = node.call(arguments)
  59.             return result
  60.  
  61.         # eventually calls something like: return LLJitMixin().meta_interp(function, arguments, listops=True, inline=True)
  62.         self.assertEqual(interpretation_mechanisms.meta_interpret(test, [41, 42, 43]), 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement