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
Instance Method Details
#aprintln ⇒ Object
385
386
387
|
# File 'lib/bitescript/bytecode.rb', line 385
def aprintln
println
end
|
#label(id = nil) ⇒ Object
375
376
377
378
379
380
381
382
383
|
# File 'lib/bitescript/bytecode.rb', line 375
def label(id = nil)
if id
lbl = sym_to_label(id)
lbl.set!
lbl
else
return SmartLabel.new(method_visitor)
end
end
|
#labels ⇒ Object
363
364
365
|
# File 'lib/bitescript/bytecode.rb', line 363
def labels
@labels ||= {}
end
|
#line(num) ⇒ Object
400
401
402
403
404
405
|
# File 'lib/bitescript/bytecode.rb', line 400
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
389
390
391
392
393
|
# File 'lib/bitescript/bytecode.rb', line 389
def println(type = JObject)
getstatic JSystem, "out", JPrintStream
swap
invokevirtual JPrintStream, "println", [JVoid::TYPE, type]
end
|
#push_int(num) ⇒ Object
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
# File 'lib/bitescript/bytecode.rb', line 407
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
320
321
322
323
|
# File 'lib/bitescript/bytecode.rb', line 320
def start
method_visitor.visit_code
@start_label.set!
end
|
#stop ⇒ Object
325
326
327
328
329
330
331
332
|
# File 'lib/bitescript/bytecode.rb', line 325
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
395
396
397
398
|
# File 'lib/bitescript/bytecode.rb', line 395
def swap2
dup2_x2
pop2
end
|
#sym_to_label(id) ⇒ Object
367
368
369
370
371
372
373
|
# File 'lib/bitescript/bytecode.rb', line 367
def sym_to_label(id)
lbl = labels[id]
unless lbl
lbl = labels[id] = label
end
lbl
end
|
#trycatch(from, to, target, type) ⇒ Object
334
335
336
337
338
339
340
|
# File 'lib/bitescript/bytecode.rb', line 334
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
|