Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RAST::Root is RAST::Node {
- has str $!magic;
- has int $!major_version;
- has int $!minor_version;
- has int $!format_type;
- has %!misc;
- has str $!label;
- has str $!path;
- has str $!absolute_path;
- has int $!first_lineno;
- has str $!type;
- has @!locals;
- has @!args;
- has @!catch_table;
- has @!bytecode;
- method BUILD(:@bytecode!, :$label!, :$path!, :$absolute_path!, :$type!) {
- @!bytecode := @bytecode;
- $!magic := "YARVInstructionSequence/SimpleDataFormat";
- $!major_version := 1;
- $!minor_version := 2;
- $!format_type := 1;
- %!misc := nqp::hash();
- $!label := $label;
- $!path := $path;
- $!absolute_path := $absolute_path;
- $!first_lineno := 1;
- $!type := $type;
- @!locals := [];
- @!args := [];
- @!catch_table := [];
- }
- method push_bytecode($bytecode) {
- nqp::push(@!bytecode, $bytecode);
- }
- method push_local($local) {
- nqp::push(@!locals, $local);
- }
- method push_arg($arg) {
- nqp::push(@!args, $arg);
- }
- method push_catch($catch) {
- nqp::push(@!catch_table, $catch);
- }
- method set_arity($arg_count) {
- @!args = [$arg_count];
- }
- method dump() {
- my @dumped = << '$magic' $major_version $minor_version $format_type >>;
- nqp::push(@dumped, dump_misc());
- nqp::push(@dumped, "'$!label'");
- nqp::push(@dumped, "'$!path'");
- if $!absolute_path ne '' {
- nqp::push(@dumped, "'$!absolute_path'");
- }
- else {
- nqp::push(@dumped, "nil");
- }
- nqp::push(@dumped, $!first_lineno);
- nqp::push(@dumped, "\:$!type");
- my @locals;
- for @!locals {
- nqp::push(@locals, $_.dump());
- }
- nqp::push(@dumped, @locals);
- if @!args.elems == 1 {
- nqp::push(@dumped, @!args[0]);
- }
- else
- {
- my @args;
- for @!args {
- nqp::push(@args, $_);
- }
- nqp::push(@dumped, @args);
- }
- my @catch_table;
- for @!catch_table {
- nqp::push(@catch_table, $_.dump());
- }
- nqp::push(@dumped, @catch_table);
- my @bytecode;
- for @!bytecode {
- nqp::push(@bytecode, $_.dump());
- }
- nqp::push(@dumped, @bytecode);
- return '[' ~ @dumped.join(', ') ~ ']';
- }
- method dump_misc() {
- "\{ arg_size: $!argsize, " ~
- " local_size: $!local_size, " ~
- " stack_max: $!stack_max\}"
- }
- }
- =begin ValidRASTRootNode
- This is a empty compiled program from ruby, this is our goal output for a blank nqp file
- [
- "YARVInstructionSequence/SimpleDataFormat",
- 1,
- 2,
- 1,
- {arg_size: 0, local_size: 1, stack_max: 1},
- "<main>",
- "/path/to/file.nqp".
- nil,
- 1,
- :top,
- [],
- 0,
- [],
- [
- 2,
- [
- :putnil
- ],
- [
- :leave
- ]
- ]
- ]
- =end ValidRASTRootNode
- # vim: syn=perl6 ts=3 sts=3
Advertisement
Add Comment
Please, Sign In to add comment