Example #1
0
 def interpret(self, env, cont):
     from pycket.interpreter import return_value_direct
     # default implementation for simple AST forms
     assert self.simple
     # interpret should only be called from interpret_one, therefore it's
     # safe to not use the Label implementation of return_value here
     return return_value_direct(self.interpret_simple(env), env, cont)
Example #2
0
 def interpret(self, env, cont):
     from pycket.interpreter import return_value_direct
     # default implementation for simple AST forms
     assert self.simple
     # interpret should only be called from interpret_one, therefore it's
     # safe to not use the Label implementation of return_value here
     return return_value_direct(self.interpret_simple(env), env, cont)
Example #3
0
class AST(object):
    __metaclass__ = Visitable

    _attrs_ = ["should_enter", "surrounding_lambda", "_stringrepr"]
    _immutable_fields_ = ["should_enter", "surrounding_lambda"]
    _settled_ = True

    should_enter = False  # default value
    _stringrepr = None  # default value
    surrounding_lambda = None

    simple = False
    ispure = False

    def defined_vars(self, defs):
        pass

    def interpret(self, env, cont):
        from pycket.interpreter import return_value_direct
        from pycket.prims.control import convert_runtime_exception
        from pycket.error import SchemeException
        # default implementation for simple AST forms
        assert self.simple
        # interpret should only be called from interpret_one, therefore it's
        # safe to not use the Label implementation of return_value here
        try:
            val = self.interpret_simple(env)
        except SchemeException, exn:
            return convert_runtime_exception(exn, env, cont)
        return return_value_direct(val, env, cont)
Example #4
0
 def func_result_handling(*args):
     from pycket.interpreter import (return_multi_vals,
                                     return_value_direct)
     from pycket             import values
     env = args[-2]
     cont = args[-1]
     args = args[:-2]
     result = func_arg_unwrap(*args)
     if result is None:
         result = values.w_void
     if isinstance(result, values.Values):
         return return_multi_vals(result, env, cont)
     else:
         return return_value_direct(result, env, cont)
Example #5
0
 def func_result_handling(*args):
     from pycket.interpreter import (return_multi_vals,
                                     return_value_direct)
     from pycket             import values
     env = args[-2]
     cont = args[-1]
     args = args[:-2]
     result = func_arg_unwrap(*args)
     if result is None:
         result = values.w_void
     if isinstance(result, values.Values):
         return return_multi_vals(result, env, cont)
     else:
         return return_value_direct(result, env, cont)
Example #6
0
def _make_result_handling_func(func_arg_unwrap, simple):
    if simple:
        def func_result_handling(*args):
            from pycket.interpreter   import return_multi_vals, return_value_direct
            from pycket.prims.control import convert_runtime_exception
            from pycket               import values
            env = args[-2]
            cont = args[-1]
            args = args[:-2]
            try:
                result = func_arg_unwrap(*args)
            except SchemeException, exn:
                return convert_runtime_exception(exn, env, cont)
            if result is None:
                result = values.w_void
            if isinstance(result, values.Values):
                return return_multi_vals(result, env, cont)
            else:
                return return_value_direct(result, env, cont)
        return func_result_handling
Example #7
0
def _make_result_handling_func(func_arg_unwrap, simple):
    if simple:

        def func_result_handling(*args):
            from pycket.interpreter import return_multi_vals, return_value_direct
            from pycket.prims.control import convert_runtime_exception, convert_os_error
            from pycket import values
            env = args[-2]
            cont = args[-1]
            args = args[:-2]
            try:
                result = func_arg_unwrap(*args)
            except SchemeException, exn:
                return convert_runtime_exception(exn, env, cont)
            except OSError, exn:
                return convert_os_error(exn, env, cont)
            if result is None:
                result = values.w_void
            if isinstance(result, values.Values):
                return return_multi_vals(result, env, cont)
            else:
                return return_value_direct(result, env, cont)
Example #8
0
File: AST.py Project: pycket/pycket
    def interpret(self, env, cont):
        from pycket.interpreter import return_value_direct
        from pycket.prims.control import convert_runtime_exception, convert_os_error
        from pycket.error import SchemeException
        # default implementation for simple AST forms
        assert self.simple
        # interpret should only be called from interpret_one, therefore it's
        # safe to not use the Label implementation of return_value here
        try:
            val = self.interpret_simple(env)
        except SchemeException, exn:
            return convert_runtime_exception(exn, env, cont)
        except OSError, exn:
            return convert_os_error(exn, env, cont)
        return return_value_direct(val, env, cont)

    def interpret_simple(self, env):
        raise NotImplementedError("abstract base class")

    def set_surrounding_lambda(self, lam):
        from pycket.interpreter import Lambda
        assert isinstance(lam, Lambda)
        self.surrounding_lambda = lam
        for child in self.direct_children():
            child.set_surrounding_lambda(lam)

    def set_should_enter(self):
        """ Set the should_enter field and returns whether or not the field was
        already set. This looks potentially dangerous: the field is marked
        immutable above. It works however, because should_enter MUST only be