コード例 #1
0
ファイル: function.py プロジェクト: evfredericksen/janlang
 def call(self, context: execution_context.ExecutionContext, arg_ast, kwarg_ast):
     args = [arg.execute(context) for arg in arg_ast]
     kwargs = {k: v.execute(context) for k, v in kwarg_ast.items()}
     result = None
     context.add_scope()
     if isinstance(self.action, list):
         for i, param in enumerate(self.parameters):
            context.declare(param.name, 'parameter')
            context.assign(param.name, args[i])
         for statement in self.action:
             try:
                 statement.execute(context)
             except Return as e:
                 result = e.value
                 break
     else:
         result = self.action(context, *args, **kwargs)
     context.remove_scope()
     return result
コード例 #2
0
ファイル: interpreter.py プロジェクト: evfredericksen/janlang
 def add_native_functions(self,
                          context: execution_context.ExecutionContext):
     for name, native_fn in native_functions.FUNCTIONS.items():
         fn = function.Function(name, [], [], native_fn)
         context.declare(name, 'native_function')
         context.assign(name, fn)