44from rpython .jit .codewriter .policy import JitPolicy
55from rpython .rlib .jit import JitHookInterface , Counters
66from rpython .annotator .policy import AnnotatorPolicy
7- from pixie .vm .code import wrap_fn
7+ from pixie .vm .code import wrap_fn , NativeFn , intern_var
88from pixie .vm .stacklet import with_stacklets
99import pixie .vm .stacklet as stacklet
1010from pixie .vm .object import RuntimeException , WrappedException
1111from rpython .translator .platform import platform
12-
12+ from pixie . vm . primitives import nil
1313import sys
1414
1515
@@ -23,65 +23,58 @@ class Policy(JitPolicy, AnnotatorPolicy):
2323 def __init__ (self ):
2424 JitPolicy .__init__ (self , DebugIFace ())
2525
26- #def event(pol, bookkeeper, what, x):
27- # pass
28-
2926def jitpolicy (driver ):
3027 return JitPolicy (jithookiface = DebugIFace ())
3128
3229
33- @wrap_fn
34- def repl ():
35- from pixie .vm .keyword import keyword
36- import pixie .vm .rt as rt
37- from pixie .vm .string import String
30+ PROGRAM_ARGUMENTS = intern_var (u"pixie.stdlib" , u"program-arguments" )
31+ PROGRAM_ARGUMENTS .set_root (nil )
32+
33+
34+ class ReplFn (NativeFn ):
35+ def __init__ (self , args ):
36+ self ._argv = args
37+
38+ def inner_invoke (self , args ):
39+ from pixie .vm .keyword import keyword
40+ import pixie .vm .rt as rt
41+ from pixie .vm .string import String
42+ import pixie .vm .persistent_vector as vector
3843
39- with with_ns (u"user" ):
40- NS_VAR .deref ().include_stdlib ()
44+ with with_ns (u"user" ):
45+ NS_VAR .deref ().include_stdlib ()
4146
42- rdr = MetaDataReader (PromptReader ())
43- with with_ns (u"user" ):
44- while True :
45- try :
46- val = read (rdr , False )
47- if val is eof :
47+ acc = vector .EMPTY
48+ for x in self ._argv :
49+ acc = rt .conj (acc , rt .wrap (x ))
50+
51+ PROGRAM_ARGUMENTS .set_root (acc )
52+
53+
54+ rdr = MetaDataReader (PromptReader ())
55+ with with_ns (u"user" ):
56+ while True :
57+ try :
58+ val = read (rdr , False )
59+ if val is eof :
60+ break
61+ val = interpret (compile (val ))
62+ except WrappedException as ex :
63+ print "Error: " , ex ._ex .__repr__ ()
64+ rdr .reset_line ()
65+ continue
66+ if val is keyword (u"exit-repl" ):
4867 break
49- val = interpret (compile (val ))
50- except WrappedException as ex :
51- print "Error: " , ex ._ex .__repr__ ()
52- rdr .reset_line ()
53- continue
54- if val is keyword (u"exit-repl" ):
55- break
56- val = rt .str (val )
57- assert isinstance (val , String ), "str should always return a string"
58- print val ._str
59-
60- def entry_point (foo = None ):
68+ val = rt .str (val )
69+ assert isinstance (val , String ), "str should always return a string"
70+ print val ._str
71+
72+ def entry_point (args ):
6173 print "Pixie 0.1 - Interactive REPL"
6274 print "(" + platform .name + ", " + platform .cc + ")"
6375 print "----------------------------"
64- #try:
65- # code = argv[1]
66- #except IndexError:
67- # print "must provide a program"
68- # return 1
69- # rdr = StreamReader(sys.stdin)
70- # while True:
71- # #val = read(rdr, True)
72- # #if val is eof:
73- # # break
74- # val = read(StringReader(raw_input("user>")), True)
75- # print interpret(compile(val))
76- # interpret(compile(read(StringReader("""
77- # (do (def foo (fn [h v] (h 42)))
78- # ((create-stacklet foo) 0))
79- # """), True)))
80- #rt.load_file(String(u"pixie/stdlib.lisp"))
81-
82-
83-
84- with_stacklets (repl )
76+
77+ with_stacklets (ReplFn (args ))
8578
8679 return 0
8780
@@ -91,7 +84,6 @@ def entry_point(foo=None):
9184from rpython .jit .metainterp import warmspot
9285
9386def run_child (glob , loc ):
94- import sys , pdb
9587 interp = loc ['interp' ]
9688 graph = loc ['graph' ]
9789 interp .malloc_check = False
@@ -153,6 +145,4 @@ def target(*args):
153145print rpython .config .translationoption .get_combined_translation_config ()
154146
155147if __name__ == "__main__" :
156- #run_debug(sys.argv)
157- #with_stacklets(bootstrap)
158- entry_point ()
148+ entry_point (sys .argv )
0 commit comments