def _add_marshall_handlers(tp, write, read): from pixie.vm.libs.pxic.util import add_marshall_handlers add_marshall_handlers(tp, write, read) return nil
def denominator(self): return self._denominator def type(self): return Ratio._type @wrap_fn def ratio_write(obj): assert isinstance(obj, Ratio) return rt.vector(rt.wrap(obj.numerator()), rt.wrap(obj.denominator())) @wrap_fn def ratio_read(obj): return Ratio(rt.nth(obj, rt.wrap(0)).int_val(), rt.nth(obj, rt.wrap(1)).int_val()) add_marshall_handlers(Ratio._type, ratio_write, ratio_read) IMath = as_var("IMath")(Protocol(u"IMath")) _add = as_var("-add")(DoublePolymorphicFn(u"-add", IMath)) _sub = as_var("-sub")(DoublePolymorphicFn(u"-sub", IMath)) _mul = as_var("-mul")(DoublePolymorphicFn(u"-mul", IMath)) _div = as_var("-div")(DoublePolymorphicFn(u"-div", IMath)) _quot = as_var("-quot")(DoublePolymorphicFn(u"-quot", IMath)) _rem = as_var("-rem")(DoublePolymorphicFn(u"-rem", IMath)) _lt = as_var("-lt")(DoublePolymorphicFn(u"-lt", IMath)) _gt = as_var("-gt")(DoublePolymorphicFn(u"-gt", IMath)) _lte = as_var("-lte")(DoublePolymorphicFn(u"-lte", IMath)) _gte = as_var("-gte")(DoublePolymorphicFn(u"-gte", IMath)) _num_eq = as_var("-num-eq")(DoublePolymorphicFn(u"-num-eq", IMath)) _num_eq.set_default_fn(wrap_fn(lambda a, b: false))
def char_val(self): return self._char_val @wrap_fn def write_char(obj): assert isinstance(obj, Character) return rt.wrap(obj._char_val) @wrap_fn def read_char(obj): return Character(obj.int_val()) add_marshall_handlers(Character._type, write_char, read_char) @extend(proto._str, Character) def _str(self): assert isinstance(self, Character) return rt.wrap(u"" + unichr(self.char_val())) @extend(proto._repr, Character) def _repr(self): assert isinstance(self, Character) cv = self.char_val() if cv < 128: return rt.wrap(u"\\" + unicode(chr(cv))) hexv = rt.name(rt.bit_str(rt.wrap(self.char_val()), rt.wrap(4)))
@wrap_fn def ratio_write(obj): assert isinstance(obj, Ratio) return rt.vector(rt.wrap(obj.numerator()), rt.wrap(obj.denominator())) @wrap_fn def ratio_read(obj): return Ratio( rt.nth(obj, rt.wrap(0)).int_val(), rt.nth(obj, rt.wrap(1)).int_val()) add_marshall_handlers(Ratio._type, ratio_write, ratio_read) IMath = as_var("IMath")(Protocol(u"IMath")) _add = as_var("-add")(DoublePolymorphicFn(u"-add", IMath)) _sub = as_var("-sub")(DoublePolymorphicFn(u"-sub", IMath)) _mul = as_var("-mul")(DoublePolymorphicFn(u"-mul", IMath)) _div = as_var("-div")(DoublePolymorphicFn(u"-div", IMath)) _quot = as_var("-quot")(DoublePolymorphicFn(u"-quot", IMath)) _rem = as_var("-rem")(DoublePolymorphicFn(u"-rem", IMath)) _lt = as_var("-lt")(DoublePolymorphicFn(u"-lt", IMath)) _gt = as_var("-gt")(DoublePolymorphicFn(u"-gt", IMath)) _lte = as_var("-lte")(DoublePolymorphicFn(u"-lte", IMath)) _gte = as_var("-gte")(DoublePolymorphicFn(u"-gte", IMath)) _num_eq = as_var("-num-eq")(DoublePolymorphicFn(u"-num-eq", IMath)) _num_eq.set_default_fn(wrap_fn(lambda a, b: false))
assert isinstance(i, int) self._char_val = i def char_val(self): return self._char_val @wrap_fn def write_char(obj): assert isinstance(obj, Character) return rt.wrap(obj._char_val) @wrap_fn def read_char(obj): return Character(obj.int_val()) add_marshall_handlers(Character._type, write_char, read_char) @extend(proto._str, Character) def _str(self): assert isinstance(self, Character) return rt.wrap(u"" + unichr(self.char_val())) @extend(proto._repr, Character) def _repr(self): assert isinstance(self, Character) cv = self.char_val() if cv < 128: return rt.wrap(u"\\"+unicode(chr(cv))) hexv = rt.name(rt.bit_str(rt.wrap(self.char_val()), rt.wrap(4))) return rt.wrap(u"\\u" + u"0" * (4 - len(hexv)) + hexv)