Skip to content

Instantly share code, notes, and snippets.

@usev6
Last active April 20, 2018 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usev6/cedc5c44dccf8df39f06b4e179e50fab to your computer and use it in GitHub Desktop.
Save usev6/cedc5c44dccf8df39f06b4e179e50fab to your computer and use it in GitHub Desktop.
Java bytecode snippets
Output string with 'printfh' (nqp)
$il.append($ALOAD_1);
$il.append(JAST::Instruction.new( :op('invokestatic'), $TYPE_OPS, "getstderr", $TYPE_SMO, $TYPE_TC ));
$il.append(JAST::Instruction.new( :op('ldc'), "DEBUG_20\n" ));
$il.append($ALOAD_1);
$il.append(JAST::Instruction.new( :op('invokestatic'), $TYPE_OPS, "printfh", 'Long', $TYPE_SMO, $TYPE_STR, $TYPE_TC ));
$il.append($POP2);
Output string with 'println' (java)
$il.append(JAST::Instruction.new( :op('getstatic'), 'java/lang/System', 'err', 'Ljava/io/PrintStream;', 'Void' ));
$il.append(JAST::Instruction.new( :op('ldc'), "DEBUG_30" ));
$il.append(JAST::Instruction.new( :op('invokevirtual'), 'java/io/PrintStream', 'println', 'Void', $TYPE_STR ));
Output long with 'println' (java)
$il.append(JAST::Instruction.new( :op('getstatic'), 'java/lang/System', 'err', 'Ljava/io/PrintStream;', 'Void' ));
$il.append(JAST::PushIVal.new( :value($desired) ));
$il.append(JAST::Instruction.new( :op('invokevirtual'), 'java/io/PrintStream', 'println', 'Void', 'Long' ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment