public
Description: a ruby-to-pyc compiler
Clone URL: git://github.com/why/unholy.git
Search Repo:
 * lib/unholy/pyasm.rb: record original Ruby line numbers in the bytecode.
why (author)
Mon May 05 19:47:25 -0700 2008
commit  6ee028c13014248abaebd0d9ef13f7127c853cc5
tree    5a57c5c8c2c7f126d8a2afac26c6789d39684120
parent  82cce7287f80b8a7309d399615ec48a81bb03480
...
4
5
6
7
8
 
 
9
10
 
11
12
13
 
14
15
16
...
91
92
93
 
94
95
96
...
100
101
102
 
 
 
103
104
105
...
233
234
235
236
 
237
238
239
240
...
274
275
276
277
 
278
279
 
280
281
282
...
341
342
343
344
 
 
 
 
 
 
 
 
345
346
347
...
4
5
6
 
 
7
8
9
 
10
11
12
 
13
14
15
16
...
91
92
93
94
95
96
97
...
101
102
103
104
105
106
107
108
109
...
237
238
239
 
240
241
242
243
244
...
278
279
280
 
281
282
 
283
284
285
286
...
345
346
347
 
348
349
350
351
352
353
354
355
356
357
358
0
@@ -4,13 +4,13 @@
0
   }
0
 
0
   attr_accessor :argc, :nlocals, :stacksize, :flags, :consts, :bytecode,
0
- :filename, :lineno, :name, :symbols, :stacknow, :varsyms, :jumps, :labels
0
- def initialize(fname, name = "<module>")
0
+ :filename, :lineno, :name, :symbols, :stacknow, :varsyms, :jumps, :labels, :lines
0
+ def initialize(fname, name = "<module>", lineno = 0)
0
     @argc, @nlocals, @stacksize, @flags, @filename, @lineno, @name, @stack, @nopop =
0
- 0, 0, 1, 0x40, fname, 1, name, [], 0
0
+ 0, 0, 1, 0x40, fname, lineno, name, [], 0
0
     @consts = [-1, nil]
0
     @symbols = [:Kernel]
0
- @bytecode, @varsyms, @labels, @jumps = [], [], {}, {}
0
+ @bytecode, @varsyms, @labels, @lines, @jumps = [], [], {}, [], {}
0
   end
0
 
0
   def add_const(obj)
0
@@ -91,6 +91,7 @@
0
     stack_push Object.new, bc(0x7c, n, 0x0)
0
   end
0
   def store_fast(n)
0
+ dump_stack
0
     bc 0x7d, n, 0x0
0
   end
0
   def call_func(arity)
0
@@ -100,6 +101,9 @@
0
   def make_func(arity)
0
     bc 0x84, arity, 0x0
0
   end
0
+ def line n
0
+ @lines << [n, @bytecode.flatten.length]
0
+ end
0
   def label l
0
     @nopop -= 1 if @nopop > 0
0
     @labels[l] = @bytecode.flatten.length
0
@@ -233,7 +237,7 @@
0
     bytes = @bytecode.slice! idx..-1
0
     bytes.shift unless receiver
0
 
0
- asm = Pyasm.new(@filename, id.to_s)
0
+ asm = Pyasm.new(@filename, id.to_s, @lines.last[0])
0
     asm.load_iseq iseq
0
     if type == :class
0
       load_const(id.to_s)
0
0
@@ -274,9 +278,9 @@
0
     iseq.last.each do |inst|
0
       case inst
0
       when Integer # line no
0
- nil
0
+ line inst
0
       when Symbol
0
- self.label inst
0
+ label inst
0
       when Array
0
         # p inst
0
         inst[0] = :message if inst[0] == :send
0
@@ -341,7 +345,14 @@
0
     f << @filename.to_pickle
0
     f << @name.to_pickle
0
     f << 1.to_plong
0
- f << "".to_pickle
0
+
0
+ lnotab = ""
0
+ lastn, lastpos = @lines[0]
0
+ @lines[1..-1].each do |n, pos|
0
+ lnotab << [pos - lastpos, n - lastn].pack("cc")
0
+ lastn, lastpos = n, pos
0
+ end
0
+ f << lnotab.to_pickle
0
     f
0
   end
0
 
...
1
2
3
 
 
 
...
1
2
3
4
5
6
0
@@ -1,4 +1,7 @@
0
 def puts(*args):
0
   for x in args: print x
0
   if not args: print
0
+
0
+class BasicObject:
0
+ pass

Comments

    No one has commented yet.