git @ Cat's Eye Technologies Yolk / 2d9017e
Make compilable under RPython. Chris Pressey 10 years ago
5 changed file(s) with 58 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
0 *.pyc
1 yolk-c
0 syntax: glob
1
2 *.pyc
3 yolk-c
0 #!/bin/sh
1
2 if [ `which rpython`X = X ]; then
3 echo 'RPython not found. Not building. Use CPython instead.'
4 else
5 rpython src/yolk.py
6 fi
0 (tail (quote (cons head head)))
2727 self.sexprs = sexprs
2828
2929 def __str__(self):
30 return "(%s)" % ' '.join([str(s) for s in self.sexprs])
30 return "(%s)" % ' '.join([s.__str__() for s in self.sexprs])
3131
3232 def head(self):
3333 return self.sexprs[0]
107107 return eval(full, prog.tail().tail().tail().tail().head(), arg)
108108 if prog.head().is_atom('self'):
109109 return eval(full, full, eval(full, prog.tail().head(), arg))
110 return Atom('head').head()
110 raise ValueError("Cannot evaluate %r" % prog)
111 # return Atom('head').head() # too clever for rpython
111112
112113
113114 def run(ptext, atext):
115116 return eval(p, p, Parser(atext).sexpr())
116117
117118
118 if __name__ == '__main__':
119 def main():
119120 import sys
120121 with open(sys.argv[1], 'r') as f:
121122 inp = sys.stdin.read()
123124 inp = 'ifeq'
124125 result = run(f.read(), inp)
125126 print result
127
128
129 def target(*args):
130 import os
131
132 def rpython_load(filename):
133 fd = os.open(filename, os.O_RDONLY, 0644)
134 text = ''
135 chunk = os.read(fd, 1024)
136 text += chunk
137 while len(chunk) == 1024:
138 chunk = os.read(fd, 1024)
139 text += chunk
140 os.close(fd)
141 return text
142
143 def rpython_input():
144 accum = ''
145 done = False
146 while not done:
147 s = os.read(1, 1)
148 if not s:
149 done = True
150 accum += s
151 return accum
152
153 def rpython_main(argv):
154 inp = rpython_input()
155 if not inp:
156 inp = 'ifeq'
157 program = rpython_load(argv[1])
158 result = run(program, inp)
159 print result.__str__()
160 return 0
161
162 return rpython_main, None
163
164
165 if __name__ == '__main__':
166 main()