Example #1
0
def func_dir():
    env = context.get('SL-env')
    # XXX show specials here too. Or maybe make specials a part of the environment! wee hee.
    d = env[1].copy()

    # hmm, ok, even though vars from lower on the stack will
    # "overwrite" ones from above it, it doesn't matter, because we
    # only care about the names here, not objects.
    while 1:
        env = env[0]
        if env == None: break
        d.update(env[1])
    return d.keys()
Example #2
0
    def evalForm(self, form, env):
        """
        Evaluate a form in an environment
        """
        assert context.get('SL-interp', None) is not None, "Only call evalForm from within eval!"
        if self.maxInstructions:
            self.instructions += 1
            if self.instructions > self.maxInstructions:
                raise TooManyInstructions("Your limit is %s, buddy." % self.maxInstructions)

        # XXX This code is *riddled* with isinstance. What's a better solution?

        if not isinstance(form, O.SLObject):
            raise UnevaluableError("I cannot evaluate %s." % form)

        if isinstance(form, O.Identifier):
            return E.lookup(env, form.name)

        if not isinstance(form, O.List):
            return form


        if isinstance(form, O.List):
            value = form.pyvalue
            if not value:
                raise SyntaxError("Empty call.")
            if isinstance(value[0], O.Identifier):
                name = value[0].name
                func = self.specials.get(name, None)
                if func:
                    return func(self, form, env)

            func = self.evalForm(value[0], env)
            #print "GOT THE FUNC", func, "FROM", value
            if isinstance(func, O.Macro):
                return func.callMacro(self, env, value[1:])

            # Must be a function call: LispEvaluate the
            # elements of the list
            args = [self.evalForm(x, env) for x in value[1:]]

            if isinstance(func, O.Function):
                return func.callFunc(self, O.List(args))

            # must be a python extension...
            r = context.call({'SL-env': env}, func, *args)
            return r

        raise RuntimeError("This is a bug. What the heck is %s?" % repr(form))
Example #3
0
 def __str__(self):
     if self.__sl_dict__.has_key('__str__'):
         return self.__sl_dict__['__str__'].callFunc(context.get('SL-interp')).pyvalue
     return object.__str__(self)