Skip to content

Commit 5999381

Browse files
committed
added and, or, and support for commandline args, also removed cruft in target.py
1 parent e1022f0 commit 5999381

2 files changed

Lines changed: 59 additions & 55 deletions

File tree

pixie/stdlib.lisp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(def reset! -reset!)
44

55
(def load-paths (atom ["./"]))
6+
(def program-arguments [])
67

78

89
(def map (fn ^{:doc "map - creates a transducer that applies f to every input element" :added "0.1"}
@@ -457,3 +458,16 @@
457458
nil
458459
(do ~@body
459460
(recur (inc ~b))))))))
461+
462+
463+
(defmacro and
464+
([x] x)
465+
([x y] `(if ~x ~y nil))
466+
([x y & more] `(if ~x (and ~y ~@more))))
467+
468+
(defmacro or
469+
([x] x)
470+
([x y] `(let [r# ~x]
471+
(if r# r# ~y)))
472+
([x y & more] `(let [r# ~x]
473+
(if r# r# (or ~y ~@more)))))

target.py

Lines changed: 45 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from rpython.jit.codewriter.policy import JitPolicy
55
from rpython.rlib.jit import JitHookInterface, Counters
66
from rpython.annotator.policy import AnnotatorPolicy
7-
from pixie.vm.code import wrap_fn
7+
from pixie.vm.code import wrap_fn, NativeFn, intern_var
88
from pixie.vm.stacklet import with_stacklets
99
import pixie.vm.stacklet as stacklet
1010
from pixie.vm.object import RuntimeException, WrappedException
1111
from rpython.translator.platform import platform
12-
12+
from pixie.vm.primitives import nil
1313
import 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-
2926
def 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):
9184
from rpython.jit.metainterp import warmspot
9285

9386
def 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):
153145
print rpython.config.translationoption.get_combined_translation_config()
154146

155147
if __name__ == "__main__":
156-
#run_debug(sys.argv)
157-
#with_stacklets(bootstrap)
158-
entry_point()
148+
entry_point(sys.argv)

0 commit comments

Comments
 (0)