Module: BiteScript::Bytecode
Overview
Bytecode is a simple adapter around an ASM MethodVisitor that makes it look like JVM assembly code. Included classes must just provide a method_visitor accessor
Defined Under Namespace
Classes: SmartLabel
Constant Summary
collapse
- JObject =
java.lang.Object
- JSystem =
java.lang.System
- JPrintStream =
java.io.PrintStream
- JVoid =
java.lang.Void
- JInteger =
java.lang.Integer
- JFloat =
java.lang.Float
- JLong =
java.lang.Long
- JDobule =
java.lang.Double
- OpcodeStackDeltas =
{}
- OpcodeInstructions =
{}
Instance Method Summary
collapse
Methods included from Signature
ci, class_id, classname, path, sig, signature, tipath, type_insn_path
Instance Method Details
#aprintln ⇒ Object
377
378
379
|
# File 'lib/bitescript/bytecode.rb', line 377
def aprintln
println
end
|
#label(id = nil) ⇒ Object
367
368
369
370
371
372
373
374
375
|
# File 'lib/bitescript/bytecode.rb', line 367
def label(id = nil)
if id
lbl = sym_to_label(id)
lbl.set!
lbl
else
return SmartLabel.new(method_visitor)
end
end
|
#labels ⇒ Object
355
356
357
|
# File 'lib/bitescript/bytecode.rb', line 355
def labels
@labels ||= {}
end
|
#line(num) ⇒ Object
392
393
394
395
396
397
|
# File 'lib/bitescript/bytecode.rb', line 392
def line(num)
if num && num != @line_num
method_visitor.visit_line_number(num, label.set!.label)
end
@line_num = num
end
|
#println(type = JObject) ⇒ Object
#push_int(num) ⇒ Object
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
# File 'lib/bitescript/bytecode.rb', line 399
def push_int(num)
if (num <= Java::java.lang.Byte::MAX_VALUE && num >= Java::java.lang.Byte::MIN_VALUE)
case num
when -1
iconst_m1
when 0
iconst_0
when 1
iconst_1
when 2
iconst_2
when 3
iconst_3
when 4
iconst_4
when 5
iconst_5
else
bipush(num)
end
elsif (num <= Java::java.lang.Short::MAX_VALUE && num >= Java::java.lang.Short::MIN_VALUE)
sipush(num)
elsif (num <= Java::java.lang.Integer::MAX_VALUE && num >= Java::java.lang.Integer::MIN_VALUE)
ldc_int(num)
else
ldc_long(num)
end
end
|
#start ⇒ Object
312
313
314
315
|
# File 'lib/bitescript/bytecode.rb', line 312
def start
method_visitor.visit_code
@start_label.set!
end
|
#stop ⇒ Object
317
318
319
320
321
322
323
324
|
# File 'lib/bitescript/bytecode.rb', line 317
def stop
@end_label.set!
@locals.each do |name, locals|
local_debug_info(name, locals[-1], @end_label)
end
method_visitor.visit_maxs(1,1)
method_visitor.visit_end
end
|
#swap2 ⇒ Object
387
388
389
390
|
# File 'lib/bitescript/bytecode.rb', line 387
def swap2
dup2_x2
pop2
end
|
#sym_to_label(id) ⇒ Object
359
360
361
362
363
364
365
|
# File 'lib/bitescript/bytecode.rb', line 359
def sym_to_label(id)
lbl = labels[id]
unless lbl
lbl = labels[id] = label
end
lbl
end
|
#trycatch(from, to, target, type) ⇒ Object
326
327
328
329
330
331
332
|
# File 'lib/bitescript/bytecode.rb', line 326
def trycatch(from, to, target, type)
from = sym_to_label(from) if Symbol === from
to = sym_to_label(to) if Symbol === to
target = sym_to_label(target) if Symbol === target
method_visitor.visit_try_catch_block(from.label, to.label, target.label, type ? path(type) : nil)
end
|