[pypy-svn] r66147 - pypy/branch/pyjitpl5/pypy/jit/tl
antocuni at codespeak.net
antocuni at codespeak.net
Tue Jul 7 12:07:53 CEST 2009
Author: antocuni
Date: Tue Jul 7 12:07:52 2009
New Revision: 66147
Added:
pypy/branch/pyjitpl5/pypy/jit/tl/add_10.tla.py (contents, props changed)
pypy/branch/pyjitpl5/pypy/jit/tl/targettla.py (contents, props changed)
pypy/branch/pyjitpl5/pypy/jit/tl/tla_assembler.py (contents, props changed)
Modified:
pypy/branch/pyjitpl5/pypy/jit/tl/tla.py
Log:
add a target, an assembler and an example program
Added: pypy/branch/pyjitpl5/pypy/jit/tl/add_10.tla.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/add_10.tla.py Tue Jul 7 12:07:52 2009
@@ -0,0 +1,7 @@
+from pypy.jit.tl import tla
+
+code = [
+ tla.CONST_INT, 10,
+ tla.ADD,
+ tla.RETURN
+ ]
Added: pypy/branch/pyjitpl5/pypy/jit/tl/targettla.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/targettla.py Tue Jul 7 12:07:52 2009
@@ -0,0 +1,36 @@
+import py
+py.magic.autopath()
+from pypy.jit.tl import tla
+
+
+def entry_point(args):
+ """Main entry point of the stand-alone executable:
+ takes a list of strings and returns the exit code.
+ """
+ if len(args) < 3:
+ print "Usage: %s filename x" % (args[0],)
+ return 2
+ filename = args[1]
+ x = int(args[2])
+ w_x = tla.W_IntObject(x)
+ bytecode = load_bytecode(filename)
+ w_res = tla.run(bytecode, w_x)
+ print w_res.getrepr()
+ return 0
+
+def load_bytecode(filename):
+ from pypy.rlib.streamio import open_file_as_stream
+ f = open_file_as_stream(filename)
+ bytecode = f.readall()
+ f.close()
+ return bytecode
+
+def target(driver, args):
+ return entry_point, None
+
+# ____________________________________________________________
+
+
+if __name__ == '__main__':
+ import sys
+ sys.exit(entry_point(sys.argv))
Modified: pypy/branch/pyjitpl5/pypy/jit/tl/tla.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/tla.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/tla.py Tue Jul 7 12:07:52 2009
@@ -4,10 +4,16 @@
class W_Object:
+ def getrepr(self):
+ """
+ Return an RPython string which represent the object
+ """
+ raise NotImplementedError
+
def is_true(self):
raise NotImplementedError
- def add(self):
+ def add(self, w_other):
raise NotImplementedError
@@ -17,6 +23,9 @@
def __init__(self, intvalue):
self.intvalue = intvalue
+ def getrepr(self):
+ return str(self.intvalue)
+
def is_true(self):
return self.intvalue != 0
@@ -39,6 +48,9 @@
def __init__(self, strvalue):
self.strvalue = strvalue
+ def getrepr(self):
+ return self.strvalue
+
def is_true(self):
return len(self.strvalue) != 0
Added: pypy/branch/pyjitpl5/pypy/jit/tl/tla_assembler.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/tla_assembler.py Tue Jul 7 12:07:52 2009
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+import sys
+import py
+py.magic.autopath()
+from pypy.jit.tl.test.test_tla import assemble
+
+def usage():
+ print >> sys.stderr, 'Usage: tla_assembler.py filename.tla.py'
+ sys.exit(1)
+
+def main():
+ if len(sys.argv) != 2:
+ usage()
+
+ filename = sys.argv[1]
+ if not filename.endswith('.tla.py'):
+ usage()
+
+ outname = filename[:-len('.py')]
+ mydict = {}
+ execfile(filename, mydict)
+ bytecode = assemble(mydict['code'])
+ f = open(outname, 'w')
+ f.write(bytecode)
+ f.close()
+ print '%s successfully assembled' % outname
+
+if __name__ == '__main__':
+ main()
More information about the Pypy-commit
mailing list