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
378
379
380
|
# File 'lib/bitescript/bytecode.rb', line 378
def aprintln
println
end
|
#label(id = nil) ⇒ Object
364
365
366
367
368
369
370
371
372
373
374
375
376
|
# File 'lib/bitescript/bytecode.rb', line 364
def label(id = nil)
if id
label = labels[id]
if label
raise "Duplicate label '#{id}'"
end
label = labels[id] = SmartLabel.new(method_visitor)
label.set!
label
else
return SmartLabel.new(method_visitor)
end
end
|
#labels ⇒ Object
356
357
358
|
# File 'lib/bitescript/bytecode.rb', line 356
def labels
@labels ||= {}
end
|
#line(num) ⇒ Object
393
394
395
396
397
398
|
# File 'lib/bitescript/bytecode.rb', line 393
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
382
383
384
385
386
|
# File 'lib/bitescript/bytecode.rb', line 382
def println(type = JObject)
getstatic JSystem, "out", JPrintStream
swap
invokevirtual JPrintStream, "println", [JVoid::TYPE, type]
end
|
#push_int(num) ⇒ Object
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
427
|
# File 'lib/bitescript/bytecode.rb', line 400
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
388
389
390
391
|
# File 'lib/bitescript/bytecode.rb', line 388
def swap2
dup2_x2
pop2
end
|
#sym_to_label(id) ⇒ Object
360
361
362
|
# File 'lib/bitescript/bytecode.rb', line 360
def sym_to_label(id)
lbl = labels[id] or raise "Unknown label '#{id}'"
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
|