def invoke_method(self, argv, suppress_default): self = jit.promote(self) if len(argv) < self.arity: raise Error(u"expected at least %d arguments, got %d" % (self.arity, len(argv))) if self.arity == 1: method = self.get_method(jit.promote(argv[0].__class__.interface)) elif self.arity == 2: method = self.get_method(jit.promote(argv[0].__class__.interface), jit.promote(argv[1].__class__.interface)) elif self.arity == 3: method = self.get_method(jit.promote(argv[0].__class__.interface), jit.promote(argv[1].__class__.interface), jit.promote(argv[2].__class__.interface)) elif self.arity == 4: method = self.get_method(jit.promote(argv[0].__class__.interface), jit.promote(argv[1].__class__.interface), jit.promote(argv[2].__class__.interface), jit.promote(argv[3].__class__.interface)) else: vec = [] for i in range(self.arity): vec.append(argv[i].__class__.interface) method = self.methods.get(List(vec), None) if method is None: vec = [] for i in range(self.arity): vec.append(argv[i].__class__.interface) if self.default is None or suppress_default: names = [] for i in range(self.arity): names.append(vec[i].name) raise Error(u"no method for [" + u' '.join(names) + u"]") return self.default.call(argv) return method.call(argv)
def multimethod(self, *spec): vec = List(list(cls.interface for cls in spec)) def _impl_(fn): self.methods[vec] = Builtin(fn) return fn return _impl_
def next(self): key, value = self.iterator.next() return List([key, value])
def _(a, b): return List(a.contents + b.contents)
def _(a, b): return List([a, Float(float(b.value))])
def _(a, b): return List([Float(float(a.value)), b])
def get_method(self, *interfaces): return self.methods.get(List(list(interfaces)), None)
def _(a, b): return List([Integer(int(a.flag)), Integer(int(b.flag))])