def callAtom(self, atom, arguments, namedArgsMap): """ This method is used to reuse atoms without having to rebuild them. """ # Promote the atom, on the basis that atoms are generally reused. atom = promote(atom) # Log the atom to the JIT log. Don't do this if the atom's not # promoted; it'll be slow. jit_debug(atom.repr) try: return self.recvNamed(atom, arguments, namedArgsMap) except Refused as r: addTrail(r, self, atom, arguments) raise except UserException as ue: addTrail(ue, self, atom, arguments) raise except MemoryError: ue = userError(u"Memory corruption or exhausted heap") addTrail(ue, self, atom, arguments) raise ue except StackOverflow: check_stack_overflow() ue = userError(u"Stack overflow") addTrail(ue, self, atom, arguments) raise ue
def run(self): jit_debug(self.code.profileName) # print ">" * 10 pc = 0 while pc < self.code.instSize(): instruction = self.code.inst(promote(pc)) try: pc = self.runInstruction(instruction, pc) except Ejecting as e: pc = self.unwindEjector(e) except UserException as ue: pc = self.unwindEx(ue) # If there is a final handler, drop it; it may cause exceptions to # propagate or perform some additional stack unwinding. if self.env.handlerDepth: finalHandler = self.env.popHandler() # Return value ignored here. finalHandler.drop(self, pc, pc) # print "<" * 10 return 0
def callAtom(self, atom, arguments, namedArgsMap=None, span=None): """ This method is used to reuse atoms without having to rebuild them. This is the correct method to call if you have an atom. """ # Promote the atom, on the basis that atoms are generally reused. atom = promote(atom) # Log the atom to the JIT log. Don't do this if the atom's not # promoted; it'll be slow. jit_debug(atom.repr) if namedArgsMap is None or namedArgsMap.isEmpty(): namedArgsMap = MIRANDA_MAP else: from typhon.objects.collections.maps import ConstMap namedArgsMap = ConstMap(namedArgsMap._or(MIRANDA_ARGS)) try: return self.recvNamed(atom, arguments, namedArgsMap) except Refused as r: r.addTrail(self, atom, arguments, span) raise except UserException as ue: ue.addTrail(self, atom, arguments, span) raise except MemoryError: ue = userError(u"Memory corruption or exhausted heap") ue.addTrail(self, atom, arguments, span) raise ue except StackOverflow: check_stack_overflow() ue = userError(u"Stack overflow") ue.addTrail(self, atom, arguments, span) raise ue
def callAtom(self, atom, arguments, namedArgsMap): """ This method is used to reuse atoms without having to rebuild them. """ from typhon.objects.collections.maps import EMPTY_MAP # Promote the atom, on the basis that atoms are generally reused. atom = promote(atom) # Log the atom to the JIT log. Don't do this if the atom's not # promoted; it'll be slow. jit_debug(atom.repr) try: return self.recvNamed(atom, arguments, namedArgsMap) except Refused as r: # This block of method implementations is Typhon's Miranda # protocol. ~ C. if atom is _CONFORMTO_1: # Welcome to _conformTo/1. # to _conformTo(_): return self return self if atom is _GETALLEGEDINTERFACE_0: # Welcome to _getAllegedInterface/0. interface = self.optInterface() if interface is None: from typhon.objects.interfaces import ComputedInterface interface = ComputedInterface(self) return interface if atom is _PRINTON_1: # Welcome to _printOn/1. from typhon.objects.constants import NullObject self.printOn(arguments[0]) return NullObject if atom is _RESPONDSTO_2: from typhon.objects.constants import wrapBool from typhon.objects.data import unwrapInt, unwrapStr verb = unwrapStr(arguments[0]) arity = unwrapInt(arguments[1]) atom = getAtom(verb, arity) result = (atom in self.respondingAtoms() or atom in mirandaAtoms) return wrapBool(result) if atom is _SEALEDDISPATCH_1: # to _sealedDispatch(_): return null from typhon.objects.constants import NullObject return NullObject if atom is _UNCALL_0: from typhon.objects.constants import NullObject return NullObject if atom is _WHENMORERESOLVED_1: # Welcome to _whenMoreResolved. # This method's implementation, in Monte, should be: # to _whenMoreResolved(callback): callback<-(self) from typhon.vats import currentVat vat = currentVat.get() vat.sendOnly(arguments[0], RUN_1, [self], EMPTY_MAP) from typhon.objects.constants import NullObject return NullObject addTrail(r, self, atom, arguments) raise except UserException as ue: addTrail(ue, self, atom, arguments) raise except MemoryError: ue = userError(u"Memory corruption or exhausted heap") addTrail(ue, self, atom, arguments) raise ue except StackOverflow: check_stack_overflow() ue = userError(u"Stack overflow") addTrail(ue, self, atom, arguments) raise ue