forked from pixie-lang/pixie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget.py
More file actions
157 lines (121 loc) · 4.61 KB
/
target.py
File metadata and controls
157 lines (121 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from pixie.vm.compiler import compile, with_ns, NS_VAR
from pixie.vm.reader import StringReader, read, eof, PromptReader, MetaDataReader
from pixie.vm.interpreter import interpret
from rpython.jit.codewriter.policy import JitPolicy
from rpython.rlib.jit import JitHookInterface, Counters
from rpython.annotator.policy import AnnotatorPolicy
from pixie.vm.code import wrap_fn
from pixie.vm.stacklet import with_stacklets
import pixie.vm.stacklet as stacklet
from pixie.vm.object import RuntimeException, WrappedException
from rpython.translator.platform import platform
import sys
class DebugIFace(JitHookInterface):
def on_abort(self, reason, jitdriver, greenkey, greenkey_repr, logops, operations):
print "Aborted Trace, reason: ", Counters.counter_names[reason], logops, greenkey_repr
import sys, pdb
class Policy(JitPolicy, AnnotatorPolicy):
def __init__(self):
JitPolicy.__init__(self, DebugIFace())
#def event(pol, bookkeeper, what, x):
# pass
def jitpolicy(driver):
return JitPolicy(jithookiface=DebugIFace())
@wrap_fn
def repl():
from pixie.vm.keyword import keyword
import pixie.vm.rt as rt
from pixie.vm.string import String
with with_ns(u"user"):
NS_VAR.deref().include_stdlib()
rdr = MetaDataReader(PromptReader())
with with_ns(u"user"):
while True:
try:
val = read(rdr, False)
if val is eof:
break
val = interpret(compile(val))
except WrappedException as ex:
print "Error: ", ex._ex.__repr__()
continue
if val is keyword(u"exit-repl"):
break
val = rt.str(val)
assert isinstance(val, String), "str should always return a string"
print val._str
def entry_point(foo=None):
print "Pixie 0.1 - Interactive REPL"
print "(" + platform.name + ", " + platform.cc + ")"
print "----------------------------"
#try:
# code = argv[1]
#except IndexError:
# print "must provide a program"
# return 1
# rdr = StreamReader(sys.stdin)
# while True:
# #val = read(rdr, True)
# #if val is eof:
# # break
# val = read(StringReader(raw_input("user>")), True)
# print interpret(compile(val))
# interpret(compile(read(StringReader("""
# (do (def foo (fn [h v] (h 42)))
# ((create-stacklet foo) 0))
# """), True)))
#rt.load_file(String(u"pixie/stdlib.lisp"))
with_stacklets(repl)
return 0
from rpython.rtyper.lltypesystem import lltype
from rpython.jit.metainterp import warmspot
def run_child(glob, loc):
import sys, pdb
interp = loc['interp']
graph = loc['graph']
interp.malloc_check = False
def returns_null(T, *args, **kwds):
return lltype.nullptr(T)
interp.heap.malloc_nonmovable = returns_null # XXX
from rpython.jit.backend.llgraph.runner import LLGraphCPU
#LLtypeCPU.supports_floats = False # for now
apply_jit(interp, graph, LLGraphCPU)
def apply_jit(interp, graph, CPUClass):
print 'warmspot.jittify_and_run() started...'
policy = Policy()
warmspot.jittify_and_run(interp, graph, [], policy=policy,
listops=True, CPUClass=CPUClass,
backendopt=True, inline=True)
def run_debug(argv):
from rpython.rtyper.test.test_llinterp import get_interpreter
# first annotate and rtype
try:
interp, graph = get_interpreter(entry_point, [], backendopt=False,
#config=config,
#type_system=config.translation.type_system,
policy=Policy())
except Exception, e:
print '%s: %s' % (e.__class__, e)
pdb.post_mortem(sys.exc_info()[2])
raise
# parent process loop: spawn a child, wait for the child to finish,
# print a message, and restart
#unixcheckpoint.restartable_point(auto='run')
from rpython.jit.codewriter.codewriter import CodeWriter
CodeWriter.debug = True
run_child(globals(), locals())
import pixie.vm.rt as rt
rt.init()
stacklet.global_state = stacklet.GlobalState()
def target(*args):
import pixie.vm.rt as rt
driver = args[0]
driver.exe_name = "pixie-vm"
rt.__config__ = args[0].config
return entry_point, None
import rpython.config.translationoption
print rpython.config.translationoption.get_combined_translation_config()
if __name__ == "__main__":
#run_debug(sys.argv)
#with_stacklets(bootstrap)
entry_point()