コード例 #1
0
    def execute(self, token):
        jitdriver.jit_merge_point(phrases=self.phrases, token=token, vm=self)

        stack = self.stack

        if isinstance(token, Literal):
            stack.push(token._l)
        elif isinstance(token, Reference):
            # XXX Probably not the best type for this.
            stack.push(Str(token._r))
        elif isinstance(token, Word):
            self.run_phrase(token._w)
        elif isinstance(token, Instruction):
            i = token._i

            if False:
                pass
            elif i == NEWE:
                stack.push(E(self))
            elif i == DROP:
                stack.pop()
            elif i == DUP:
                stack.push(stack.peek())
            elif i == OVER:
                x = stack.pop()
                y = stack.peek()
                stack.push(x)
                stack.push(y)
            elif i == SWAP:
                x = stack.pop()
                y = stack.pop()
                stack.push(x)
                stack.push(y)
            elif i == ROT:
                z = stack.pop()
                y = stack.pop()
                x = stack.pop()
                stack.push(y)
                stack.push(z)
                stack.push(x)
            elif i == LIST:
                stack.push(List([]))
            elif i == CALL:
                args = stack.pop()
                name = stack.pop()
                target = stack.pop()
                result = self.pass_message(target, name, args)
                stack.push(result)
            elif i == SEND:
                args = stack.pop()
                name = stack.pop()
                target = stack.pop()

                promise = Promise(target, name, args)
                self.promises.append(promise)

                stack.push(promise)
            elif i == ESCAPE:
                target = stack.pop()
                ejector = Ejector(stack)
                stack.push(ejector)

                t = unwrap_str(target)
                with ejector:
                    self.run_phrase(t)
            elif i == EJECT:
                value = stack.pop()
                ejector = stack.pop()

                # Raise an exception to unwind the stack.
                ejector.eject(value)
            elif i == MAKE_METHOD:
                name = stack.pop()
                code = stack.pop()
                stack.push(List([name, code]))
            elif i == OBJECT:
                methods = stack.pop()

                obj = UserObject(self, methods)

                stack.push(obj)
            elif i == APPEND:
                obj = stack.pop()
                l = stack.peek()
                # Check the type.
                if isinstance(l, List):
                    l.push(obj)
                else:
                    raise TypeError("Couldn't push into non-List %s" % l)
            elif i == IF:
                otherwise = stack.pop()
                consequent = stack.pop()
                whether = unwrap_bool(stack.pop())

                if whether:
                    word = consequent
                else:
                    word = otherwise

                self.run_phrase(word._s)
            elif i == PRINT:
                print stack.pop().repr()
            elif i == STACK:
                print "Stack:", stack.repr()
            else:
                print "Unknown instruction", i
        else:
            print "Can't handle", token
コード例 #2
0
ファイル: eons.py プロジェクト: MostAwesomeDude/secret
    def execute(self, token):
        jitdriver.jit_merge_point(phrases=self.phrases, token=token, vm=self)

        stack = self.stack

        if isinstance(token, Literal):
            stack.push(token._l)
        elif isinstance(token, Reference):
            # XXX Probably not the best type for this.
            stack.push(Str(token._r))
        elif isinstance(token, Word):
            self.run_phrase(token._w)
        elif isinstance(token, Instruction):
            i = token._i

            if False:
                pass
            elif i == NEWE:
                stack.push(E(self))
            elif i == DROP:
                stack.pop()
            elif i == DUP:
                stack.push(stack.peek())
            elif i == OVER:
                x = stack.pop()
                y = stack.peek()
                stack.push(x)
                stack.push(y)
            elif i == SWAP:
                x = stack.pop()
                y = stack.pop()
                stack.push(x)
                stack.push(y)
            elif i == ROT:
                z = stack.pop()
                y = stack.pop()
                x = stack.pop()
                stack.push(y)
                stack.push(z)
                stack.push(x)
            elif i == LIST:
                stack.push(List([]))
            elif i == CALL:
                args = stack.pop()
                name = stack.pop()
                target = stack.pop()
                result = self.pass_message(target, name, args)
                stack.push(result)
            elif i == SEND:
                args = stack.pop()
                name = stack.pop()
                target = stack.pop()

                promise = Promise(target, name, args)
                self.promises.append(promise)

                stack.push(promise)
            elif i == ESCAPE:
                target = stack.pop()
                ejector = Ejector(stack)
                stack.push(ejector)

                t = unwrap_str(target)
                with ejector:
                    self.run_phrase(t)
            elif i == EJECT:
                value = stack.pop()
                ejector = stack.pop()

                # Raise an exception to unwind the stack.
                ejector.eject(value)
            elif i == MAKE_METHOD:
                name = stack.pop()
                code = stack.pop()
                stack.push(List([name, code]))
            elif i == OBJECT:
                methods = stack.pop()

                obj = UserObject(self, methods)

                stack.push(obj)
            elif i == APPEND:
                obj = stack.pop()
                l = stack.peek()
                # Check the type.
                if isinstance(l, List):
                    l.push(obj)
                else:
                    raise TypeError("Couldn't push into non-List %s" % l)
            elif i == IF:
                otherwise = stack.pop()
                consequent = stack.pop()
                whether = unwrap_bool(stack.pop())

                if whether:
                    word = consequent
                else:
                    word = otherwise

                self.run_phrase(word._s)
            elif i == PRINT:
                print stack.pop().repr()
            elif i == STACK:
                print "Stack:", stack.repr()
            else:
                print "Unknown instruction", i
        else:
            print "Can't handle", token
コード例 #3
0
 def pass_message(self, target, message, args):
     m = unwrap_str(message)
     a = unwrap_list(args)
     print "~ Passing to %s: %s, %s" % (target.repr(), message.repr(),
                                        args.repr())
     return target.call(m, a)
コード例 #4
0
ファイル: eons.py プロジェクト: MostAwesomeDude/secret
 def pass_message(self, target, message, args):
     m = unwrap_str(message)
     a = unwrap_list(args)
     print "~ Passing to %s: %s, %s" % (target.repr(), message.repr(),
             args.repr())
     return target.call(m, a)