We're supposed to be able to do this somehow. I think I've seen it somewhere, but I can't find what I think I remember. Mostly I want to see how the compiler interprets code.
Along with decompiling, is there a way to watch what it's doing as it compiles? I think seeing what's it's trying to do and where might be easier than trying to understand some of its error messages. And, decompiling a program can undo all the shorthand and cleverness to elucidate what's actually happening.
I'm not sure why you would want to do it. Also, the compilation result is backend dependent, and you did not specify a backend. Anyway, with the --target=
parameter, you can get intermediate results. The most useful are:
$ perl6 --target=parse -e 'say "foo"'
- statementlist: say "foo"
- statement: 1 matches
- EXPR: say "foo"
- args: "foo"
- arglist: "foo"
- EXPR: "foo"
- value: "foo"
- quote: "foo"
- nibble: foo
- longname: say
- name: say
- identifier: say
- morename: isa NQPArray
- colonpair: isa NQPArray
--target=parse
shows the immediate result of the parse.
$ perl6 --target=ast -e 'say "foo"'
- QAST::CompUnit :W<?> :UNIT<?>
[pre_deserialize]
- QAST::Stmt
- QAST::Stmt
- QAST::Op(loadbytecode)
- QAST::VM
[jvm]
- QAST::SVal(ModuleLoader.class)
[moar]
- QAST::SVal(ModuleLoader.moarvm)
- QAST::Op(callmethod load_module)
*snip*
--target=ast
shows the Abstract Syntax Trees.
$ perl6 --target=mast -e 'say "foo"'
MAST::Frame name<<unit-outer>>, cuuid<2>
Local types: 0<obj>, 1<obj>, 2<obj>, 3<obj>,
Outer: <none>
Instructions:
[0] MAST::Op getcode
MAST::Local index<3>
MAST::Frame name<<unit>>, cuuid<1>
[1] MAST::Op capturelex
MAST::Local index<3>
[2] MAST::Op getcode
MAST::Local index<1>
MAST::Frame name<<unit>>, cuuid<1>
[3] MAST::Op takeclosure
*snip*
And --target=mast
shows the actual byte code that is being generated, in this case for the MoarVM backend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With