22from pixie .vm .code import BaseCode , PolymorphicFn , wrap_fn , as_var , defprotocol , extend
33from types import MethodType
44from pixie .vm .primitives import true , false , nil
5- from pixie .vm .numbers import Integer , zero_int , _add
5+ import pixie .vm .numbers as numbers
66import rpython .rlib .jit as jit
77import rpython .rlib .rstacklet as rstacklet
88
1616
1717defprotocol ("pixie.stdlib" , "IPersistentCollection" , ["-conj" ])
1818
19+ defprotocol ("pixie.stdlib" , "IObject" , ["-hash" , "-eq" , "-str" , "-repr" ])
20+
21+ def default_str (x ):
22+ from pixie .vm .string import String
23+
24+ return String ("<inst " + x .type ()._name + ">" )
25+
26+ _str .set_default_fn (wrap_fn (default_str ))
27+ _repr .set_default_fn (wrap_fn (default_str ))
28+
1929#_first = PolymorphicFn("-first")
2030#_next = PolymorphicFn("-next")
2131
@@ -51,7 +61,7 @@ def _seq(_):
5161
5262@extend (_count , nil ._type )
5363def _count (_ ):
54- return zero_int
64+ return numbers . zero_int
5565
5666
5767_count_driver = jit .JitDriver (name = "pixie.stdlib.count" ,
@@ -63,7 +73,7 @@ def count(x):
6373 while True :
6474 _count_driver .jit_merge_point (tp = rt .type (x ))
6575 if ICounted .satisfies (rt .type (x )):
66- return rt ._add (Integer (acc ), rt ._count (x ))
76+ return rt ._add (numbers . Integer (acc ), rt ._count (x ))
6777 acc += 1
6878 x = rt .next (rt .seq (x ))
6979
@@ -81,5 +91,10 @@ def nth(a, b):
8191 return rt ._nth (a , b )
8292
8393
94+ @as_var ("str" )
95+ def str (a ):
96+ return rt ._str (a )
8497
8598import pixie .vm .rt as rt
99+
100+
0 commit comments