Browse files

Cardinal restart

git-svn-id: https://svn.parrot.org/parrot/trunk/languages/cardinal@25103 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent c6d82d3 commit 5bb360e5374f146916fecd86733dc049ccc13edb @tewk tewk committed Jan 21, 2008
Showing with 364 additions and 7,462 deletions.
  1. +0 −26 HISTORY
  2. +0 −4 MAINTAINER
  3. +126 −0 Makefile
  4. +0 −30 Parrot_gen/Test.pm
  5. +0 −3 README
  6. +0 −4 TODO
  7. +35 −353 cardinal.pir
  8. +65 −123 config/makefiles/root.in
  9. +0 −74 rit
  10. +0 −8 runtime/cardinallib.pir
  11. +0 −51 runtime/parts/rubyclass.pir
  12. +0 −100 src/AST2OST.pir
  13. +0 −1,740 src/ASTGrammar.tg
  14. +0 −145 src/CardinalBuiltins.pir
  15. +0 −84 src/CardinalGrammar.pir
  16. +0 −74 src/OST2PIR.pir
  17. +0 −913 src/OSTGrammar.tg
  18. +0 −367 src/PAST.pir
  19. +0 −129 src/PGE2AST.pir
  20. +0 −272 src/PIRGrammar.tg
  21. +0 −496 src/POST.pir
  22. +0 −191 src/builtins/assign.pir
  23. +0 −135 src/builtins/cmp.pir
  24. +0 −63 src/builtins/io.pir
  25. +0 −47 src/builtins/ranges.pir
  26. +31 −0 src/builtins/say.pir
  27. +0 −103 src/cardinal_optok.pg
  28. +0 −491 src/cardinal_rules.pg
  29. +58 −0 src/parser/actions.pm
  30. +41 −0 src/parser/grammar.pg
  31. +0 −32 src/pmc/rubybignum.pmc
  32. +0 −38 src/pmc/rubyclass.pmc
  33. +0 −32 src/pmc/rubycomplex.pmc
  34. +0 −33 src/pmc/rubyfixnum.pmc
  35. +0 −58 src/pmc/rubyfloat.pmc
  36. +0 −56 src/pmc/rubyhash.pmc
  37. +0 −33 src/pmc/rubyinteger.pmc
  38. +0 −81 src/pmc/rubyobject.pmc
  39. +0 −46 src/pmc/rubyrange.pmc
  40. +0 −73 src/pmc/rubystring.pmc
  41. +0 −97 src/preamble
  42. +5 −0 t/00-sanity.t
  43. +0 −63 t/00_arithmetic.t
  44. +0 −46 t/00_assignment.t
  45. +0 −35 t/00_command_calls.t
  46. +0 −95 t/00_conditionals.t
  47. +0 −48 t/00_if_unless.t
  48. +0 −44 t/00_initial.t
  49. +0 −21 t/00_rescue.t
  50. +0 −34 t/00_while_until.t
  51. +0 −123 t/array.t
  52. +0 −25 t/begin_end_block.t
  53. +0 −36 t/begin_end_blocks.t
  54. +0 −34 t/class.t
  55. +0 −33 t/comments.t
  56. +0 −30 t/for.t
  57. +0 −34 t/function_calls.t
  58. +3 −3 t/harness
  59. +0 −26 t/loop_example.t
  60. +0 −43 t/module.t
  61. +0 −44 t/primes.t
  62. +0 −40 tools/gen_runtime.pl
View
26 HISTORY
@@ -1,26 +0,0 @@
-During the years there were several efforts to bring Ruby to Parrot.
-
-Pat Eyler has made the first attempt.
-In 2000 he wrote a very small subset of Ruby on Parrot and called it Rabbit.
-At the time, Parrot had no object support, so he was limited to string
-and numeric 'objects' and a small set of operators that posed as methods.
-Sadly, there is no extant copy of the code.
-
-Then, around 2002, Phil Tomson created the first incarnation of Cardinal. It lived
-as a RubyForge project in http://rubyforge.org/projects/cardinal/.
-At that time Parrot was still very much a moving target
-and it was deemed by Phil Tomson to be a waste of time to put much effort
-into Cardinal.
-
-A couple of years ago cardindal was reborn for a time due to the
-efforts of Mark Sparshatt. But even then Parrot still proved to be too
-much of a moving target, so not much happened. The fruits of
-that effort are in http://rubyforge.org/projects/cardinal/.
-
-More recently Kevin Tew asked whether he could use the name Cardinal and Phil Tomson
-graciously accepted. The current incarnation of Cardinal lives in
-https://svn.perl.org/parrot/trunk/languages/cardinal and is based on PGE and TGE.
-
-Sources:
-- http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/207872
-- http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/29982
View
4 MAINTAINER
@@ -1,4 +0,0 @@
-# $Id$
-
-N: Kevin Tew
-E: kevintew@tewk.com
View
126 Makefile
@@ -0,0 +1,126 @@
+# DO NOT EDIT THIS FILE
+# Generated by Parrot::Configure::Compiler from languages/cardinal/config/makefiles/root.in
+
+## $Id$
+
+## arguments we want to run parrot with
+PARROT_ARGS =
+
+## configuration settings
+BUILD_DIR = /home/tewk/srcs/parrot2
+LOAD_EXT = .so
+O = .o
+
+## Setup some commands
+LN_S = /bin/ln -s
+PERL = /usr/bin/perl
+RM_RF = $(PERL) -MExtUtils::Command -e rm_rf
+CP = $(PERL) -MExtUtils::Command -e cp
+PARROT = ../../parrot
+CAT = $(PERL) -MExtUtils::Command -e cat
+BUILD_DYNPMC = $(PERL) $(BUILD_DIR)/tools/build/dynpmc.pl
+RECONFIGURE = $(PERL) $(BUILD_DIR)/tools/dev/reconfigure.pl
+
+## places to look for things
+PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext
+PGE_LIBRARY = $(BUILD_DIR)/runtime/parrot/library/PGE
+PERL6GRAMMAR = $(PGE_LIBRARY)/Perl6Grammar.pbc
+NQP = $(BUILD_DIR)/compilers/nqp/nqp.pbc
+PCT = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc
+
+PMC_DIR = src/pmc
+
+all: cardinal.pbc
+
+CARDINAL_GROUP = $(PMC_DIR)/cardinal_group$(LOAD_EXT)
+
+SOURCES = cardinal.pir \
+ src/gen_grammar.pir \
+ src/gen_actions.pir \
+ src/gen_builtins.pir \
+# $(CARDINAL_GROUP)
+
+BUILTINS_PIR = \
+ src/builtins/say.pir \
+
+# PMCS = cardinal
+# PMC_SOURCES = $(PMC_DIR)/cardinal.pmc
+
+# the default target
+cardinal.pbc: $(PARROT) $(SOURCES)
+ $(PARROT) $(PARROT_ARGS) -o cardinal.pbc cardinal.pir
+
+src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg
+ $(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
+ --output=src/gen_grammar.pir \
+ src/parser/grammar.pg
+
+src/gen_actions.pir: $(NQP) $(PCT) src/parser/actions.pm
+ $(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_actions.pir \
+ --target=pir src/parser/actions.pm
+
+src/gen_builtins.pir: $(BUILTINS_PIR)
+ $(CAT) $(BUILTINS_PIR) >src/gen_builtins.pir
+
+$(CARDINAL_GROUP): $(PARROT) $(PMC_SOURCES)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) generate $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) compile $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) linklibs $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) copy --destination=$(PARROT_DYNEXT) $(PMCS)
+
+# regenerate the Makefile
+Makefile: config/makefiles/root.in
+ cd $(BUILD_DIR) && $(RECONFIGURE) --step=gen::languages --languages=cardinal
+
+# This is a listing of all targets, that are meant to be called by users
+help:
+ @echo ""
+ @echo "Following targets are available for the user:"
+ @echo ""
+ @echo " all: cardinal.pbc"
+ @echo " This is the default."
+ @echo "Testing:"
+ @echo " test: Run the test suite."
+ @echo " testclean: Clean up test results."
+ @echo ""
+ @echo "Cleaning:"
+ @echo " clean: Basic cleaning up."
+ @echo " realclean: Removes also files generated by 'Configure.pl'"
+ @echo " distclean: Removes also anything built, in theory"
+ @echo ""
+ @echo "Misc:"
+ @echo " help: Print this help message."
+ @echo ""
+
+test: all
+ $(PERL) t/harness
+
+# this target has nothing to do
+testclean:
+
+CLEANUPS = \
+ cardinal.pbc \
+ src/gen_grammar.pir \
+ src/gen_actions.pir \
+ src/gen_builtins.pir \
+ $(PMC_DIR)/*.h \
+ $(PMC_DIR)/*.c \
+ $(PMC_DIR)/*.dump \
+ $(PMC_DIR)/*$(O) \
+ $(PMC_DIR)/*$(LOAD_EXT) \
+ $(PMC_DIR)/*.exp \
+ $(PMC_DIR)/*.ilk \
+ $(PMC_DIR)/*.manifest \
+ $(PMC_DIR)/*.pdb \
+ $(PMC_DIR)/*.lib \
+
+
+clean:
+ $(RM_RF) $(CLEANUPS)
+
+realclean: clean
+ $(RM_RF) Makefile
+
+distclean: realclean
+
+
View
30 Parrot_gen/Test.pm
@@ -1,30 +0,0 @@
-#!perl
-
-# Copyright (C) 2006, The Perl Foundation.
-# $Id$
-
-use strict;
-use warnings;
-use lib qw(t . lib ../lib ../../lib ../../../lib);
-use Parrot::Test tests => 1;
-
-our $counter = 1;
-
-sub language_output_is {
- my ( $lang_name, $code, $out, $description ) = @_;
- $0 =~ s/\.t//;
- open my $OUT, ">", "$0_$counter.rb";
- print $OUT "$code\n";
- close $OUT;
- $counter++;
- "ok";
-}
-
-1;
-
-# Local Variables:
-# mode: cperl
-# cperl-indent-level: 4
-# fill-column: 100
-# End:
-# vim: expandtab shiftwidth=4:
View
3 README
@@ -1,3 +0,0 @@
-Cardinal is a Implementation of the Ruby Language and Interpreter on top of Parrot.
-
-./rit provides fast access to debugging tools.
View
4 TODO
@@ -1,4 +0,0 @@
-Get test suites running from
-Rubicon - cvs -d :pserver:anonymous@cvs.ruby-lang.org:/src co rubicon
-Unit Tests for Ruby builtin classes and modules - http://groups.google.com/group/RubyTests/
-
View
388 cardinal.pir
@@ -1,379 +1,60 @@
-=head1 NAME
+=head1 TITLE
-cardinal -- A compiler for Ruby 1.8.4
+cardinal.pir - A cardinal compiler.
-=head1 SYNOPSIS
+=head2 Description
- $ ./parrot languages/cardinal/cardinal.pir script.rb
+This is the base file for the cardinal compiler.
-=head1 DESCRIPTION
+This file includes the parsing and grammar rules from
+the src/ directory, loads the relevant PGE libraries,
+and registers the compiler under the name 'cardinal'.
-Ruby is a compiler for Ruby version 1.8, running on Parrot. Its parser is
-a PGE grammar (a subclass of PGE::Grammar). The compilation is a series of
-tree transformations using TGE: from match tree to abstract syntax tree
-(AST), from AST to opcode syntax tree (OST), and finally from OST to
-bytecode (actually to PIR, at first). For more on the ideas behind the
-compiler, see:
+=head2 Functions
-=cut
-#.HLL 'Ruby', ''
-.HLL 'Ruby', 'ruby_group'
-.include 'errors.pasm'
-.include 'library/dumper.pir'
-
-.sub _main :main
- .param pmc args
-
- errorson .PARROT_ERRORS_PARAM_COUNT_FLAG
-
- load_bytecode 'PGE.pbc'
- load_bytecode 'dumper.pbc'
- load_bytecode 'PGE/Dumper.pbc'
- load_bytecode 'PGE/Text.pbc'
- load_bytecode 'Getopt/Obj.pbc'
-
- load_bytecode 'languages/cardinal/src/PAST.pir'
- load_bytecode 'languages/cardinal/src/POST.pir'
- #load_bytecode 'languages/cardinal/src/CardinalGrammar.pir'
- load_bytecode 'languages/cardinal/src/CardinalGrammar.pbc'
- load_bytecode 'languages/cardinal/src/PGE2AST.pir'
- load_bytecode 'languages/cardinal/src/AST2OST.pir'
- load_bytecode 'languages/cardinal/src/OST2PIR.pir'
-
- #needed to run compiled tests
- load_bytecode 'languages/cardinal/src/builtins_gen.pir'
- load_bytecode 'languages/cardinal/runtime/cardinallib.pbc'
-
- .local pmc _dumper
- .local pmc getopts
- .local pmc opts
- .local string arg0
- _dumper = get_root_global [ 'parrot' ], '_dumper'
- arg0 = shift args
- getopts = new 'Getopt::Obj'
- getopts.'notOptStop'(1)
- push getopts, 'target=s'
- push getopts, 'dump-optable'
- push getopts, 'dump-source|s'
- push getopts, 'dump-pge-parse|p'
- push getopts, 'dump-tge-AST|a'
- push getopts, 'dump-tge-OST|o'
- push getopts, 'dump-tge-PIR|i'
- push getopts, 'execute|e'
- push getopts, 'dump-all|x'
- push getopts, 'dump|d'
- push getopts, 'help|h'
- push getopts, 'trace|t'
- opts = getopts.'get_options'(args)
-
- $S0 = opts['dump-optable']
- if $S0 goto dump_optable
- $S0 = opts['help']
- if $S0 goto usage
-
- .local int stopafter
- .local string dump
- .local string target
- .local int istrace
-
- stopafter = 0
- dump = opts['dump']
- target = opts['target']
- $S0 = opts['trace']
- istrace = isne $S0, ''
-
- .local int dump_pge
- $S0 = opts['dump-pge-parse']
- dump_pge = isne $S0, ''
- unless $S0 goto a1
- stopafter = 1
- a1:
-
- .local int dump_ast
- $S0 = opts['dump-tge-AST']
- dump_ast = isne $S0, ''
- unless $S0 goto a2
- stopafter = 2
- a2:
-
- .local int dump_ost
- $S0 = opts['dump-tge-OST']
- dump_ost = isne $S0, ''
- unless $S0 goto a3
- stopafter = 3
- a3:
-
- .local int dump_pir
- $S0 = opts['dump-tge-PIR']
- dump_pir = isne $S0, ''
- unless $S0 goto a4
- stopafter = 4
- a4:
-
- .local int dump_src
- .local int dump_src_early
- .local int execute_debug
- $S0 = opts['dump-source']
- dump_src = isne $S0, ''
- dump_src_early = dump_src
-
- $S0 = opts['execute']
- execute_debug = isne $S0, ''
- unless execute_debug goto a5
- stopafter = 0
- a5:
-
- .local int istrace
- $S0 = opts['dump-all']
- if $S0 goto dump_all
- $S0 = dump
- unless $S0 goto after_dump_all
- dump_all:
- dump_pge = 1
- dump_ast = 1
- dump_ost = 1
- dump_pir = 1
- dump_src_early = 1
- dump_src = 1
- execute_debug = 1
- stopafter = 0
- after_dump_all:
-
- .local pmc cardinal
- .local string filename
- cardinal = compreg 'Cardinal'
-
- .local string source
-
- $I0 = elements args
- if $I0 > 0 goto file_arg
- filename = "STDIN"
-
- .local pmc stdin
- stdin = getstdin
- push stdin, 'utf8'
- # enable interactive readline if possible
- $I0 = stdin.'set_readline_interactive'(1)
-
- stmt_loop:
- .local string stmt
- stmt = stdin.'readline'('cardinal> ')
- unless stmt goto end
- bsr cardinal_irb_eval
- goto stmt_loop
-
- file_arg:
- filename = args[0]
- source = _get_source(filename)
- goto compile_it
-
- cardinal_irb_eval:
- $I0 = find_charset 'iso-8859-1' # XXX: Note 2006-04-14
- trans_charset stmt, $I0
- #$P0 = perl6(stmt, 'target' => target, 'dump' => dump)
- null $P0
- if target == 'PIR' goto dump_pir_output
- if target goto dump_object
- trace istrace
- $P0()
- trace 0
- ret
- dump_pir_output:
- print $P0
- ret
- dump_object:
- _dumper($P0, target)
- ret
-
- dump_optable:
- #$P0 = get_hll_global [ 'Cardinal'; 'Grammar'], '$optable'
- $P0 = get_root_global [ 'parrot'; 'Cardinal::Grammar'], '$optable'
- _dumper($P0, "Cardinal::Grammar::optable")
- goto end
-
- usage:
- print "usage: cardinal.pbc [--dump-optable] [--target=OUT] [file]\n"
- end
-
- compile_it:
- # Match against the source
- .local pmc match
- .local pmc start_rule
-
- unless dump_src_early goto after_src_dump_early
- print "\n\nSource dump:\n"
- print source
- after_src_dump_early:
+=over 4
- start_rule = get_root_global [ 'parrot'; 'Cardinal::Grammar'], 'program'
- match = start_rule(source, 'grammar'=> 'Cardinal::Grammar')
+=item onload()
- # Verify the match
- $I0 = match.get_bool()
- unless $I0 goto err_match_fail # if match fails stop
+Creates the cardinal compiler using a C<PCT::HLLCompiler>
+object.
- unless dump_pge goto after_pge_dump
- print "parse succeeded\n"
- print "Match tree dump:\n"
- _dumper(match, "PGE Dump")
- after_pge_dump:
- eq stopafter, 1, end
-
- # "Traverse" the parse tree
- .local pmc grammar
- grammar = new 'Cardinal::ASTGrammar'
-
- # Construct the "AST"
- .local pmc astbuilder
- astbuilder = grammar.apply(match)
- .local pmc ast
- ast = astbuilder.get('result')
- $I0 = defined ast
- unless $I0 goto err_no_ast # if AST fails stop
-
- unless dump_ast goto after_ast_dump
- print "\n\nAST tree dump:\n"
- '_dumper'(ast)
- #ast.'dump'()
- after_ast_dump:
- eq stopafter, 2, end
-
- # Compile the abstract syntax tree down to an opcode syntax tree
- .local pmc ostgrammar
- .local pmc ostbuilder
- .local pmc ost
- ostgrammar = new 'Cardinal::OSTGrammar'
- ostbuilder = ostgrammar.apply(ast)
- ost = ostbuilder.get('root')
- $I0 = defined ost
- unless $I0 goto err_no_ost # if OST fails stop
-
- unless dump_ost goto after_ost_dump
- print "\n\nOST tree dump:\n"
- '_dumper'(ost)
- #ost.'dump'()
- after_ost_dump:
- eq stopafter, 3, end
-
- # Compile the OST down to PIR
- .local pmc pirgrammar
- .local pmc pirbuilder
- .local pmc pir
- pirgrammar = new 'Cardinal::PIRGrammar'
- pirbuilder = pirgrammar.apply(ost)
- pir = pirbuilder.get('root')
- unless pir goto err_no_pir # if PIR not generated, stop
-
- unless dump_src goto after_src_dump
- print "\n\nSource dump:\n"
- print source
- after_src_dump:
-
- unless dump_pir goto after_pir_dump
- print "\n\nPIR dump:\n"
- print pir
- after_pir_dump:
- eq stopafter, 4, end
-
- # dump pir to file
- $S0 = concat filename, ".pir.out"
- _spew_file($S0, pir)
-
- # Execute
- unless execute_debug goto execute_only
- print "\n\nExecution Result:\n"
- execute_only:
- cardinal_exec(pir)
- end
-
- err_match_fail:
- print "Parse failed on "
- print filename
- print "\n"
- exit -1
-
- err_no_ast:
- print "Unable to construct AST.\n"
- exit -2
+=cut
- err_no_ost:
- print "Unable to construct OST.\n"
- exit -3
+.namespace [ 'cardinal::Compiler' ]
- err_no_pir:
- print "Unable to construct PIR.\n"
- exit -4
+.loadlib 'cardinal_group'
- end:
- exit 0
-.end
+.sub 'onload' :anon :load :init
+ load_bytecode 'PCT.pbc'
-#.HLL 'Ruby', 'ruby_group'
-.sub cardinal_exec
- .param pmc code
- .local pmc pir_compiler
- .local pmc pir_compiled
- pir_compiler = compreg "PIR"
- pir_compiled = pir_compiler(code)
- pir_compiled()
+ $P0 = get_hll_global ['PCT'], 'HLLCompiler'
+ $P1 = $P0.'new'()
+ $P1.'language'('cardinal')
+ $P1.'parsegrammar'('cardinal::Grammar')
+ $P1.'parseactions'('cardinal::Grammar::Actions')
.end
-#.HLL 'Ruby', ''
-
-# Read in the source from a file
-.sub _get_source
- .param string filename
- $S1 = _slurp_file(filename)
- .return ($S1)
+=item main(args :slurpy) :main
- err_no_file:
- print "You must supply a Ruby file to parse.\n"
- end
-.end
-
-.sub _slurp_file
- .param string filename
- .local pmc filehandle
- filehandle = open filename, "<"
- unless filehandle goto err_no_file
- $S1 = read filehandle, 65535
- close filehandle
- .return ($S1)
+Start compilation by passing any command line C<args>
+to the cardinal compiler.
- err_no_file:
- print "Unable to open file "
- print filename
- print "\n"
- end
-.end
+=cut
-.sub _spew_file
- .param string filename
- .param string contents
- .local pmc filehandle
- filehandle = open filename, ">"
- unless filehandle goto err_no_file
- print filehandle, contents
- close filehandle
- .return ($S1)
+.sub 'main' :main
+ .param pmc args
- err_no_file:
- print "Unable to open file "
- print filename
- print "\n"
- end
+ $P0 = compreg 'cardinal'
+ $P1 = $P0.'command_line'(args)
.end
-=head1 LICENSE
-
-Copyright (c) 2005 The Perl Foundation
-This is free software; you may redistribute it and/or modify
-it under the same terms as Parrot.
+.include 'src/gen_builtins.pir'
+.include 'src/gen_grammar.pir'
+.include 'src/gen_actions.pir'
-=head1 AUTHOR
-
-Kevin Tew <kevintew@tewk.com>
+=back
=cut
@@ -382,3 +63,4 @@ Kevin Tew <kevintew@tewk.com>
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
+
View
188 config/makefiles/root.in
@@ -1,131 +1,73 @@
-# $Id$
+## $Id$
-# Set up some commands
+## arguments we want to run parrot with
+PARROT_ARGS =
+
+## configuration settings
+BUILD_DIR = @build_dir@
+LOAD_EXT = @load_ext@
+O = @o@
+
+## Setup some commands
+LN_S = @lns@
PERL = @perl@
-MV = $(PERL) -MExtUtils::Command -e mv
-RM_F = @rm_f@
RM_RF = @rm_rf@
+CP = @cp@
PARROT = ../../parrot@exe@
-BUILD = $(PERL) @build_dir@/tools/build/dynpmc.pl
CAT = $(PERL) -MExtUtils::Command -e cat
-PARROT_DYNEXT = @build_dir@/runtime/parrot/dynext
-RECONFIGURE = $(PERL) @build_dir@/tools/dev/reconfigure.pl
+BUILD_DYNPMC = $(PERL) $(BUILD_DIR)/tools/build/dynpmc.pl
+RECONFIGURE = $(PERL) $(BUILD_DIR)/tools/dev/reconfigure.pl
-# Set up extensions
-O = @o@
-LOAD_EXT = @load_ext@
+## places to look for things
+PARROT_DYNEXT = $(BUILD_DIR)/runtime/parrot/dynext
+PGE_LIBRARY = $(BUILD_DIR)/runtime/parrot/library/PGE
+PERL6GRAMMAR = $(PGE_LIBRARY)/Perl6Grammar.pbc
+NQP = $(BUILD_DIR)/compilers/nqp/nqp.pbc
+PCT = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc
-# Set up directories
-BUILD_DIR = @build_dir@
-PGE_DIR = ../../compilers/pge
-TGE_DIR = ../../compilers/tge
PMC_DIR = src/pmc
-# the default target
-all: gen_tests cardinal.pbc $(PMC_DIR)/ruby_group$(LOAD_EXT)
-
-PMCS = \
- rubyclass \
- rubyobject \
- rubyinteger \
- rubyhash \
- rubybignum \
- rubycomplex \
- rubyfixnum \
- rubyfloat \
- rubystring \
- rubyrange
-
-PMC_SOURCES = \
- $(PMC_DIR)/rubyclass.pmc \
- $(PMC_DIR)/rubyobject.pmc \
- $(PMC_DIR)/rubyinteger.pmc \
- $(PMC_DIR)/rubyhash.pmc \
- $(PMC_DIR)/rubybignum.pmc \
- $(PMC_DIR)/rubycomplex.pmc \
- $(PMC_DIR)/rubyfixnum.pmc \
- $(PMC_DIR)/rubyfloat.pmc \
- $(PMC_DIR)/rubystring.pmc \
- $(PMC_DIR)/rubyrange.pmc
-
-BUILTINS_PIR = \
- src/builtins/assign.pir \
- src/builtins/cmp.pir \
- src/builtins/io.pir \
- src/builtins/ranges.pir
-
-GEN_PIR = \
- src/cardinal_grammar_gen.pir \
- src/ASTGrammar.pir \
- src/OSTGrammar.pir \
- src/PIRGrammar.pir \
- src/builtins_gen.pir
-
-GEN_PBC = \
- src/CardinalGrammar.pbc \
- src/PGE2AST.pbc \
- src/AST2OST.pbc \
- src/OST2PIR.pbc \
- src/PAST.pbc \
- src/POST.pbc
-
-# regenerate the Makefile
-Makefile: config/makefiles/root.in
- cd $(BUILD_DIR) && $(RECONFIGURE) --step=gen::languages --languages=cardinal
-
-RUNTIME_COMPONENTS = \
- runtime/parts/rubyclass.pir
+all: cardinal.pbc
-cardinal.pbc: cardinal.pir runtime/cardinallib.pbc $(GEN_PIR) $(GEN_PBC)
- $(PARROT) -o cardinal.pbc --output-pbc cardinal.pir
+CARDINAL_GROUP = $(PMC_DIR)/cardinal_group$(LOAD_EXT)
-src/PAST.pbc: src/PAST.pir
- $(PARROT) -o src/PAST.pbc --output-pbc src/PAST.pir
+SOURCES = cardinal.pir \
+ src/gen_grammar.pir \
+ src/gen_actions.pir \
+ src/gen_builtins.pir \
+# $(CARDINAL_GROUP)
-src/POST.pbc: src/POST.pir
- $(PARROT) -o src/POST.pbc --output-pbc src/POST.pir
-
-src/cardinal_grammar_gen.pir: src/cardinal_rules.pg src/cardinal_optok.pg
- $(PARROT) $(PGE_DIR)/pgc.pir --output=src/cardinal_grammar_gen.pir src/cardinal_rules.pg src/cardinal_optok.pg
-
-src/cardinal_grammar_gen.pbc: src/cardinal_grammar_gen.pir
- $(PARROT) -o src/cardinal_grammar_gen.pbc --output-pbc src/cardinal_grammar_gen.pir
-
-src/CardinalGrammar.pbc: src/CardinalGrammar.pir src/cardinal_grammar_gen.pir
- $(PARROT) -o src/CardinalGrammar.pbc --output-pbc src/CardinalGrammar.pir
-
-src/ASTGrammar.pir: src/ASTGrammar.tg
- $(PARROT) $(TGE_DIR)/tgc.pir --output=src/ASTGrammar.pir src/ASTGrammar.tg
-
-src/PGE2AST.pbc: src/PGE2AST.pir src/ASTGrammar.pir src/preamble
- $(PARROT) -o src/PGE2AST.pbc --output-pbc src/PGE2AST.pir
-
-src/OSTGrammar.pir: src/OSTGrammar.tg
- $(PARROT) $(TGE_DIR)/tgc.pir --output=src/OSTGrammar.pir src/OSTGrammar.tg
+BUILTINS_PIR = \
+ src/builtins/say.pir \
-src/AST2OST.pbc: src/AST2OST.pir src/OSTGrammar.pir src/preamble
- $(PARROT) -o src/AST2OST.pbc --output-pbc src/AST2OST.pir
+# PMCS = cardinal
+# PMC_SOURCES = $(PMC_DIR)/cardinal.pmc
-src/PIRGrammar.pir: src/PIRGrammar.tg
- $(PARROT) $(TGE_DIR)/tgc.pir --output=src/PIRGrammar.pir src/PIRGrammar.tg
+# the default target
+cardinal.pbc: $(PARROT) $(SOURCES)
+ $(PARROT) $(PARROT_ARGS) -o cardinal.pbc cardinal.pir
-src/OST2PIR.pbc: src/OST2PIR.pir src/PIRGrammar.pir src/preamble
- $(PARROT) -o src/OST2PIR.pbc --output-pbc src/OST2PIR.pir
+src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg
+ $(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
+ --output=src/gen_grammar.pir \
+ src/parser/grammar.pg
-$(PMC_DIR)/ruby_group$(LOAD_EXT): $(PARROT) $(PMC_SOURCES)
- cd $(PMC_DIR) && $(BUILD) generate $(PMCS)
- cd $(PMC_DIR) && $(BUILD) compile $(PMCS)
- cd $(PMC_DIR) && $(BUILD) linklibs $(PMCS)
- cd $(PMC_DIR) && $(BUILD) copy --destination=$(PARROT_DYNEXT) $(PMCS)
+src/gen_actions.pir: $(NQP) $(PCT) src/parser/actions.pm
+ $(PARROT) $(PARROT_ARGS) $(NQP) --output=src/gen_actions.pir \
+ --target=pir src/parser/actions.pm
-src/builtins_gen.pir: $(BUILTINS_PIR)
- $(CAT) $(BUILTINS_PIR) >src/builtins_gen.pir
+src/gen_builtins.pir: $(BUILTINS_PIR)
+ $(CAT) $(BUILTINS_PIR) >src/gen_builtins.pir
-runtime/runtime.pir: $(RUNTIME_COMPONENTS) tools/gen_runtime.pl
- $(PERL) tools/gen_runtime.pl > runtime/runtime.pir
+$(CARDINAL_GROUP): $(PARROT) $(PMC_SOURCES)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) generate $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) compile $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) linklibs $(PMCS)
+ cd $(PMC_DIR) && $(BUILD_DYNPMC) copy --destination=$(PARROT_DYNEXT) $(PMCS)
-runtime/cardinallib.pbc: $(PARROT) runtime/cardinallib.pir runtime/runtime.pir $(CLASSES)
- $(PARROT) --output=runtime/cardinallib.pbc runtime/cardinallib.pir
+# regenerate the Makefile
+Makefile: config/makefiles/root.in
+ cd $(BUILD_DIR) && $(RECONFIGURE) --step=gen::languages --languages=cardinal
# This is a listing of all targets, that are meant to be called by users
help:
@@ -147,35 +89,35 @@ help:
@echo " help: Print this help message."
@echo ""
-gen_tests:
- @$(MV) Parrot_gen Parrot
- -@t/harness > /dev/null 2>&1
- @$(MV) Parrot Parrot_gen
-
test: all
- $(PERL) -Isrc -I../../src t/harness
+ $(PERL) t/harness
+# this target has nothing to do
testclean:
- $(RM_F) "t/*.rb" "t/*.out"
CLEANUPS = \
cardinal.pbc \
- runtime/cardinallib.pbc \
- runtime/runtime.pir \
- $(GEN_PIR) \
- $(GEN_PBC) \
+ src/gen_grammar.pir \
+ src/gen_actions.pir \
+ src/gen_builtins.pir \
$(PMC_DIR)/*.h \
$(PMC_DIR)/*.c \
$(PMC_DIR)/*.dump \
$(PMC_DIR)/*$(O) \
$(PMC_DIR)/*$(LOAD_EXT) \
- t/*.out \
- t/*.rb
+ $(PMC_DIR)/*.exp \
+ $(PMC_DIR)/*.ilk \
+ $(PMC_DIR)/*.manifest \
+ $(PMC_DIR)/*.pdb \
+ $(PMC_DIR)/*.lib \
-clean:
+
+clean:
$(RM_RF) $(CLEANUPS)
realclean: clean
$(RM_RF) Makefile
distclean: realclean
+
+
View
74 rit
@@ -1,74 +0,0 @@
-#!/usr/bin/perl -w
-
-# vim: syntax=perl
-use strict;
-use warnings;
-
-my $PARROT = '../../parrot';
-my $CARDINAL = 'cardinal.pbc';
-my $CURRENT_TEST = slurp_current_test();
-my $TRACE_ARGS = "";
-my $DEBUG_FLAGS = "";
-my $POST_PROC = "";
-
-sub slurp_current_test
-{
- local $\;
- open my $FH, "<.current_test";
- <$FH>;
-}
-
-if ( @ARGV > 1 )
-{
- $CURRENT_TEST = $ARGV[1];
-}
-
-if ( @ARGV > 0 )
-{
- if ( $ARGV[0] eq "--help" )
- {
- help();
- exit;
- }
- eval($ARGV[0]);
-}
-else
-{
- debug2();
-}
-
-sub help
-{
- print <<"EOF"
-./rit command program.rb
-Commands
- trace :-> parrot -t
- execute :-> executes the
- debug executes cardinal.pbc w/ -d
- gdb executes cardinal under gdb
-EOF
-}
-
-sub trace { $TRACE_ARGS = "-t 4"; execute(); }
-sub debug { $DEBUG_FLAGS = "-d"; execute(); }
-sub debug2 { $DEBUG_FLAGS = "-a -o -i -s -e"; execute(); }
-
-sub execute
-{
- execute_cmd( "make ; $PARROT $TRACE_ARGS $CARDINAL $DEBUG_FLAGS $CURRENT_TEST $POST_PROC" );
-}
-
-sub gdb
-{
- execute_cmd( "echo 'set args $CARDINAL -d $CURRENT_TEST\n run\n set print pretty \n' > .rit_gdb_cmds");
- exec( "gdb -x .rit_gdb_cmds ../../parrot" );
-}
-
-sub execute_cmd
-{
- my ($cmd) = @_;
- print $cmd . "\n";
- print `$cmd`;
- $$;
-}
-
View
8 runtime/cardinallib.pir
@@ -1,8 +0,0 @@
-.HLL 'Ruby', 'ruby_group'
-.include 'languages/cardinal/runtime/runtime.pir'
-
-# Local Variables:
-# mode: pir
-# fill-column: 100
-# End:
-# vim: expandtab shiftwidth=4:
View
51 runtime/parts/rubyclass.pir
@@ -1,51 +0,0 @@
-.HLL 'parrot', ''
-#.HLL 'Ruby', 'ruby_group'
-
-.namespace [ 'RubyClass' ]
-
-.sub 'allocate' :method
-.end
-
-.sub 'inherited' :method
-.end
-
-.sub 'superclass' :method
-.end
-
-.sub 'to_yaml' :method
-.end
-
-.sub 'new' :method
- .param pmc args :slurpy
- $I0 = typeof self
- $P0 = new $I0
- print "13\n"
- $P0.'initialize'()
- print "14\n"
- .return ($P0)
-.end
-
-#cardinal specific
-.sub '_store_instance_var' :method
- .param string name
- .param pmc value
- print self
- print " "
- print name
- print " "
- print value
- print "\n"
- $I0 = classoffset self, name
- unless $I0 > 0 goto exists
- addattribute self, name
-exists:
- setattribute self, name, value
- .return ()
-.end
-
-
-# Local Variables:
-# mode: pir
-# fill-column: 100
-# End:
-# vim: expandtab shiftwidth=4:
View
100 src/AST2OST.pir
@@ -1,100 +0,0 @@
-.namespace [ 'Cardinal::OSTGrammar' ]
-
-.include "iterator.pasm"
-.include 'languages/cardinal/src/preamble'
-.include 'languages/cardinal/src/OSTGrammar.pir'
-
-.sub '__onload' :load
- $P0 = get_class 'Cardinal::OSTGrammar'
- if null $P0 goto error
- addattribute $P0, 'post_scope_stack'
- addattribute $P0, 'past_scope_stack'
- addattribute $P0, 'BEGIN_blocks'
- addattribute $P0, 'END_blocks'
- addattribute $P0, 'namespaces'
- .return ()
-error:
- print "Cardinal::OSTGrammar class not found\n"
- end
-.end
-
-.namespace [ 'Cardinal::OSTGrammar' ]
-.sub 'attr' :method
- .param string attrname
- .param pmc value
- .param int setvalue
- if setvalue goto set
- value = getattribute self, attrname
- unless null value goto end
- value = new .Undef
- set:
- setattribute self, attrname, value
- end:
- .return (value)
-.end
-
-.sub 'post_scope_stack' :method
- .param pmc attr :optional
- .param int has_attr :opt_flag
- .return self.'attr'('post_scope_stack', attr, has_attr)
-.end
-
-.sub 'past_scope_stack' :method
- .param pmc attr :optional
- .param int has_attr :opt_flag
- .return self.'attr'('past_scope_stack', attr, has_attr)
-.end
-
-.sub 'push_BEGIN_block' :method
- .param pmc value :optional
- .param int has_value :opt_flag
- .local pmc stack
- stack = self.'attr'('BEGIN_blocks', 0, 0)
- $I0 = defined stack
- if $I0 goto test_value
- stack = new .ResizablePMCArray
- stack = self.'attr'('BEGIN_blocks', stack, 1)
- test_value:
- unless has_value goto end
- push stack, value
- end:
- .return (stack)
-.end
-
-.sub 'push_END_block' :method
- .param pmc value :optional
- .param int has_value :opt_flag
- .local pmc stack
- stack = self.'attr'('END_blocks', 0, 0)
- $I0 = defined stack
- if $I0 goto test_value
- stack = new .ResizablePMCArray
- stack = self.'attr'('END_blocks', stack, 1)
- test_value:
- unless has_value goto end
- push stack, value
- end:
- .return (stack)
-.end
-
-.sub 'push_namespace' :method
- .param pmc value :optional
- .param int has_value :opt_flag
- .local pmc stack
- stack = self.'attr'('namespaces', 0, 0)
- $I0 = defined stack
- if $I0 goto test_value
- stack = new .ResizablePMCArray
- stack = self.'attr'('namespaces', stack, 1)
- test_value:
- unless has_value goto end
- push stack, value
- end:
- .return (stack)
-.end
-
-# Local Variables:
-# mode: pir
-# fill-column: 100
-# End:
-# vim: expandtab shiftwidth=4:
View
1,740 src/ASTGrammar.tg
@@ -1,1740 +0,0 @@
-grammar Cardinal::ASTGrammar is TGE::Grammar;
-
-transform result (ROOT) :language('PIR') {
- debug_init
-
- .local pmc past
- past = new 'Cardinal::PAST::Block'
- past.'init'('node'=>node, 'name'=>'top', 'blocktype'=>'block')
- self.'push_scope_stack'(past)
-
- .local pmc child
- $I0 = defined node['compound_statement']
- unless $I0 goto err_no_tree
- $P0 = node['compound_statement']
- child = tree.get('result', $P0, 'Cardinal::Grammar::compound_statement')
- past.'add_child'(child)
- .return (past)
-
- err_no_tree:
- print "The top-level node doesn't contain an 'compound_statement' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::body_statement) :language('PIR') {
- .local pmc child
- .local pmc result
- result = new 'Cardinal::PAST::Stmts'
- result.'init'('node'=>node)
-
- $I0 = defined node['compound_statement']
- unless $I0 goto err_no_tree
- $P0 = node['compound_statement']
- child = tree.get('result', $P0, 'Cardinal::Grammar::compound_statement')
- result.'add_child'(child)
-
- $I0 = defined node['rescue_clause']
- unless $I0 goto n1
- $P0 = node['rescue_clause']
- child = tree.get('result', $P0, 'Cardinal::Grammar::rescue_clause')
- result.'add_child'(child)
-
- n1:
- $I0 = defined node['else_clause']
- unless $I0 goto n2
- $P0 = node['else_clause']
- child = tree.get('result', $P0, 'Cardinal::Grammar::else_clause')
- result.'add_child'(child)
-
- n2:
- $I0 = defined node['rescue_clause']
- unless $I0 goto n3
- $P0 = node['rescue_clause']
- child = tree.get('result', $P0, 'Cardinal::Grammar::rescue_clause')
- result.'add_child'(child)
-
- n3:
- .return (result)
-
- err_no_tree:
- print "The body_statement node doesn't contain a 'compound_statement' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::compound_statement) :language('PIR') {
- .local pmc child
- .local pmc result
- result = new 'Cardinal::PAST::Stmts'
- result.'init'('node'=>node)
- #.kdump2(node, 'compound_statement')
-
- $I0 = defined node['statement']
- unless $I0 goto no_statement
- $P0 = node['statement']
-
- .local pmc iter
- iter = new Iterator, $P0 # setup iterator for node
- iter = 0
-
- iter_loop:
- unless iter, iter_end # while (entries) ...
- shift $P0, iter
-
- child = tree.get('result', $P0, 'Cardinal::Grammar::statement')
- result.'add_child'(child)
-
- goto iter_loop
-
- iter_end:
- .return (result)
-
- no_statement:
- .return ()
-
- err_no_tree:
- print "The statements node doesn't contain a 'statement' match.\n"
- .kdump2(node, 'statements')
- end
-}
-
-transform val (string) :language('PIR') {
- .local pmc result
- result = new 'Cardinal::PAST::Val'
- $S0 = node
- result.'init'('node'=>node, 'name'=>$S0, 'valtype'=>'String')
- .return (result)
-}
-
-transform result (Cardinal::Grammar::statement) :language('PIR') {
- #.kdump2(node, 'statement')
- .local pmc result
- .local pmc child
- .local pmc op
-
- result = new 'Cardinal::PAST::Stmt'
- result.'init'('node'=>node)
-
- # alias
- $I0 = defined node['ALIAS']
- unless $I0 goto n1
- $S0 = node['ALIAS']
-
- op = new 'Cardinal::PAST::Op'
- op.'init'('node'=>node, 'name'=>$S0)
- $I0 = defined node['function_item']
- unless $I0 goto l1
- $P0 = node['function_item']
- $P1 = $P0[0]
- $P1 = tree.'get'('val', $P1, 'string')
- $P2 = $P0[1]
- $P2 = tree.'get'('val', $P2, 'string')
- goto finish_alias
- l1:
- $I0 = defined node['GLOBAL_VARIABLE']
- unless $I0 goto err_no_tree
-
- $P0 = node['GLOBAL_VARIABLE']
- $P1 = $P0[0]
- $P1 = tree.'get'('val', $P1, 'string')
- $I0 = elements $P0
- unless $I0 == 2 goto back_reference
- $P2 = $P0[1]
- goto finish_GLOBAL_VARIABLE
- back_reference:
- $P2 = node['back_reference']
- finish_GLOBAL_VARIABLE:
- $P2 = tree.'get'('val', $P2, 'string')
-
- finish_alias:
- op.'add_child'($P1)
- op.'add_child'($P2)
- result.'add_child'(op)
- .return (result)
-
- # undef
- n1:
- $I0 = defined node['UNDEF']
- unless $I0 goto n2
- child = tree.get('result', node, 'Cardinal::Grammar::undef')
- .return (child)
-
- # begin
- n2:
- $I0 = defined node['BEGIN']
- unless $I0 goto n3
- .local pmc begin_sub
- $P0 = self.'top_scope_stack'()
- begin_sub = new 'Cardinal::PAST::Block'
- begin_sub.'init'('node'=>node, 'name'=>'begin', 'blocktype'=>'BEGIN', 'outer'=>$P0)
- $P0 = node['compound_statement']
-
- self.'push_scope_stack'(begin_sub)
- child = tree.get('result', $P0, 'Cardinal::Grammar::compound_statement')
- self.'pop_scope_stack'()
-
- begin_sub.'add_child'(child)
- .return (begin_sub)
-
- # end
- n3:
- $I0 = defined node['END']
- unless $I0 goto n4
- .local pmc begin_sub
- $P0 = self.'top_scope_stack'()
- begin_sub = new 'Cardinal::PAST::Block'
- begin_sub.'init'('node'=>node, 'name'=>'end', 'blocktype'=>'END', 'outer'=>$P0)
- $P0 = node['compound_statement']
-
- self.'push_scope_stack'(begin_sub)
- child = tree.get('result', $P0, 'Cardinal::Grammar::compound_statement')
- self.'pop_scope_stack'()
-
- begin_sub.'add_child'(child)
- .return (begin_sub)
-
- n4:
- # if | unless | while | until
- $I0 = defined node['expression']
- unless $I0 goto n6
- $P0 = node['expression']
- $P1 = $P0[0]
- child = tree.get('result', $P1, 'Cardinal::Grammar::expression')
-
- $I0 = defined node['MODIFIER']
- unless $I0 goto n5
- $P2 = node['MODIFIER']
- $S0 = $P2[0]
-
- op = new 'Cardinal::PAST::Op'
- op.'init'('node'=>node, 'name'=>$S0)
- $P1 = $P0[1]
- $P3 = tree.get('result', $P1, 'Cardinal::Grammar::expression')
-
- op.'add_child'($P3)
- unless $S0 == 'unless' goto its_a_if
- null $P4
- op.'add_child'($P4)
- its_a_if:
- op.'add_child'(child)
- result.'add_child'(op)
- .return (result)
-
- n5:
- # rescue
- $I0 = defined node['rescue']
- unless $I0 goto pass_through
-
- $I0 = defined node['statement']
- unless $I0 goto err_no_tree
- $P0 = node['statement'; 0]
- $P0 = tree.get('result', $P0, 'Cardinal::Grammar::statement')
-
- result = new 'Cardinal::PAST::Rescue_Stmt'
- result.'init'('node'=>node, 'try_stmt'=>child, 'rescue_stmt'=>$P0)
- .return (result)
-
- n6:
- $I0 = defined node['lang_statements']
- unless $I0 goto err_no_tree
- $P0 = node['lang_statements']
- $P0 = tree.get('result', $P0, 'Cardinal::Grammar::lang_statements')
- .return ($P0)
-
-
- pass_through:
- result.'add_child'(child)
- .return (result)
-
- err_no_tree:
- print "The statement node doesn't contain a 'expression' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::expression) :language('PIR') {
-
- # Ask the child node for its result
- .local pmc child
- $I0 = defined node['operator_precedence_parser']
- unless $I0 goto err_no_tree
- $P0 = node['operator_precedence_parser']
- child = tree.get('result', $P0, 'Cardinal::Grammar::operator_precedence_parser')
- .return (child)
-
- err_no_tree:
- print "The expression node doesn't contain a 'operator_precedence_parser' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::operator_precedence_parser) :language('PIR') {
- .local pmc result
- result = new 'Cardinal::PAST::Exp'
- result.'init'('node'=>node)
-
- .local pmc iter
- $P1 = node.get_hash()
- iter = new Iterator, $P1 # setup iterator for node
- iter = 0
- iter_loop:
- unless iter, iter_end # while (entries) ...
- shift $S1, iter # get the key of the iterator
- $P2 = iter[$S1]
- $S0 = 'Cardinal::Grammar::'
- $S0 .= $S1
- $P3 = tree.get('result', $P2, $S0)
- if null $P3 goto iter_loop
- result.'add_child'($P3)
- goto iter_loop
- iter_end:
-
- .return (result)
-}
-
-transform result (Cardinal::Grammar::expr) :language('PIR') {
- .local string type
- type = node["type"]
- unless node goto error_no_node
- if type == 'term:' goto transform_term
- # else
- $P1 = tree.get('op', node, 'expr')
- .return($P1)
- transform_term:
- $P1 = tree.get('term', node, 'expr')
- .return($P1)
- error_no_node:
- print "error: no node\n"
- end
-}
-
-
-transform result (Cardinal::Grammar::assignment) :language('PIR') {
- .local pmc child
- .local string assign_symbol
- .local pmc child2
-
- $I0 = defined node[0]
- unless $I0 goto other_assignment
- $S0 = node[0]
- ne_str $S0, '=', na1
- assign_symbol = 'infix:='
- goto get_left
- na1:
- print "No other assigns have been coded yet"
- end
-
- other_assignment:
- $I0 = defined node['ASSIGN_OP']
- unless $I0 goto try_command
- assign_symbol = node['ASSIGN_OP']
- ne_str assign_symbol, '-=', na2
- assign_symbol = 'infix:-='
- na2:
- goto get_left
-
- get_left:
- $I0 = defined node['left_hand_side']
- unless $I0 goto get_variable
- $P0 = node['left_hand_side']
- child = tree.get('result', $P0, 'Cardinal::Grammar::left_hand_side')
- goto get_right
-
- get_variable:
- $I0 = defined node['variable']
- unless $I0 goto err_no_left_hand_side
- $P0 = node['variable']
- child = tree.get('result', $P0, 'Cardinal::Grammar::variable')
- goto get_right
-
- get_right:
- $I0 = defined node['expression']
- unless $I0 goto err_no_tree
- $P0 = node['expression']
- child2 = tree.get('result', $P0, 'Cardinal::Grammar::expression')
- goto build_assignment
-
- try_command:
- $I0 = defined node['command_call']
- unless $I0 goto try_method_call
- $P0 = node['command_call']
- child = tree.get('result', $P0, 'Cardinal::Grammar::command_call')
- goto single_item
-
- try_method_call:
- $I0 = defined node['method_call']
- unless $I0 goto try_atom
- $P0 = node['method_call']
- child = tree.get('result', $P0, 'Cardinal::Grammar::method_call')
- goto single_item
-
- try_atom:
- $I0 = defined node['atom']
- unless $I0 goto err_no_tree
- $P0 = node['atom']
- child = tree.get('result', $P0, 'Cardinal::Grammar::atom')
- goto single_item
-
-
- build_assignment:
- .local pmc result
- result = new 'Cardinal::PAST::Op'
- result.'init'('node'=>node, 'name'=>assign_symbol)
- result.'add_child'(child)
- result.'add_child'(child2)
- .return (result)
-
- single_item:
- .return (child)
-
- err_not_past_val:
- print "Not a Identifier\n"
- end
-
- err_no_tree:
- print "The assignment node doesn't contain a 'postfix' match.\n"
- .kdump2(node, "Node")
- end
- err_no_assign_symbol:
- print "The assignment node doesn't contain a assignment symbol.\n"
- end
- err_no_left_hand_side:
- .kdump2(node, "Node")
- print "The assignment node doesn't contain a 'left_hand_side' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::command_call) :language('PIR') {
- .local pmc command
- $I0 = defined node['command']
- unless $I0 goto err_no_tree
- $P1 = node['command']
- command = tree.get('result', $P1, 'Cardinal::Grammar::command')
-
- .return (command)
-
- err_no_tree:
- print "The command_call node doesn't contain a 'command' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::method_call) :language('PIR') {
- .local pmc child
- .local pmc child2
-
- $I0 = defined node['atom']
- unless $I0 goto err_no_tree
- $P0 = node['atom']
- $S0 = node['atom']
- #child = tree.get('result', $P0, 'Cardinal::Grammar::atom')
- child = new 'Cardinal::PAST::Var'
- child.'init'('node'=>node, 'name'=> $S0, 'scope'=>'exists')
-
- $I0 = defined node['operation2']
- unless $I0 goto err_no_tree
- $P0 = node['operation2']
- child2 = tree.get('result', $P0, 'Cardinal::Grammar::operation2')
-
- .local pmc result
- result = new 'Cardinal::PAST::MethodCall'
- result.'init'('node'=>node, 'name'=>child2)
- result.'add_child'(child)
- result.'add_child'(child2)
- .return (result)
-
- err_no_tree:
- print "The method_call node doesn't contain a match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::command) :language('PIR') {
- .local pmc name
- .local pmc result
- $I0 = defined node['operation']
- unless $I0 goto try_atom
- $P0 = node['operation']
- $S0 = tree.get('result', $P0, 'Cardinal::Grammar::operation')
-
- # Check for args
- .local pmc args
- $I0 = defined node['command_args']
- if $I0 goto get_operator_args
- .return (name)
-
- try_atom:
- try_special_command_type:
- $I0 = defined node['special_command_type']
- unless $I0 goto err_no_name
- $P0 = node['special_command_type']
- $S0 = $P0
- result = new 'Cardinal::PAST::Op'
- result.'init'('node'=>node, 'name'=>$S0)
- goto get_args
-
-
- get_operator_args:
- result = new 'Cardinal::PAST::Op'
- result.'init'('node'=>node, 'name'=>$S0)
- get_args:
- $I0 = defined node['command_args']
- $P0 = node['command_args']
- args = tree.get('result', $P0, 'Cardinal::Grammar::command_args')
- if_null args, noargs
-
- .local pmc iter
- iter = new Iterator, args
- iter = 0
-
- iter_loop:
- unless iter, iter_end
- shift $P2, iter
- result.'add_child'($P2)
- goto iter_loop
- iter_end:
-
- noargs:
- .return (result)
-
- err_no_name:
- print "The command node doesn't contain a 'operation' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::command_args) :language('PIR') {
- .local pmc args
- $I0 = defined node['paren_args']
- unless $I0 goto call_args
- $P0 = node['paren_args']
- args = tree.get('result', $P0, 'Cardinal::Grammar::paren_args')
- .return (args)
-
- call_args:
- $I0 = defined node['call_args']
- unless $I0 goto err_no_tree
- $P0 = node['call_args']
- args = tree.get('result', $P0, 'Cardinal::Grammar::call_args')
- .return (args)
-
- err_no_tree:
- print "The command_args node doesn't contain an 'paren_args' or 'call_args' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::paren_args) :language('PIR') {
- .local pmc args
- $I0 = defined node['call_args']
- unless $I0 goto no_call_args
- $P0 = node['call_args']
- $P0 = $P0[0]
- args = tree.get('result', $P0, 'Cardinal::Grammar::call_args')
- .return (args)
-
- no_call_args:
- null args
- .return (args)
-}
-
-transform result (Cardinal::Grammar::call_args) :language('PIR') {
- .local pmc child
- .local pmc result
- result = new .ResizablePMCArray
-
- $I0 = defined node['call_args_positional']
- unless $I0 goto next_1
- $P0 = node['call_args_positional']
- child = tree.get('result', $P0, 'Cardinal::Grammar::call_args_positional')
- .return (child)
-
- next_1:
- goto err_no_tree
- $I0 = defined node['call_args_positional']
- unless $I0 goto err_no_tree
- $P0 = node['call_args_positional']
- child = tree.get('result', $P0, 'Cardinal::Grammar::call')
- goto add_child
-
- add_child:
- push result, child
- .return (result)
-
- err_no_tree:
- print "The call_args node doesn't contain a proper 'argument' match.\n"
- end
-
-}
-
-transform result (Cardinal::Grammar::call_args_positional) :language('PIR') {
- .local pmc result
- result = new .ResizablePMCArray
-
- $I0 = defined node['expression']
- unless $I0 goto err_no_tree
- $P0 = node['expression']
-
- .local pmc iter
- iter = new Iterator, $P0 # setup iterator for node
- iter = 0
-
- iter_loop:
- unless iter, iter_end # while (entries) ...
- shift $P2, iter
-
- .local pmc child
- child = tree.get('result', $P2, 'Cardinal::Grammar::expression')
- push result, child
-
- goto iter_loop
- iter_end:
-
- .return (result)
-
- err_no_tree:
- print "The call_args_positional node doesn't contain a proper 'expression' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::operation) :language('PIR') {
- .local pmc name
- $I0 = defined node['IDENTIFIER']
- unless $I0 goto test_constant
- $P0 = node['IDENTIFIER']
- name = tree.get('result', $P0, 'Cardinal::Grammar::IDENTIFIER')
- .return (name)
-
- test_constant:
- $I0 = defined node['CONSTANT']
- unless $I0 goto err_no_name
- $P0 = node['CONSTANT']
- name = tree.get('result', $P0, 'Cardinal::Grammar::CONSTANT')
- .return (name)
-
- err_no_name:
- print "The PGE operation node doesn't contain a 'IDENTIFIER' or a 'CONSTANT' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::operation2) :language('PIR') {
-.local pmc name
-
- $I0 = defined node['IDENTIFIER']
- unless $I0 goto test_constant
- $P0 = node['IDENTIFIER']
- name = tree.get('result', $P0, 'Cardinal::Grammar::IDENTIFIER')
- .return (name)
-
- test_constant:
- $I0 = defined node['CONSTANT']
- unless $I0 goto test_op
- $P0 = node['CONSTANT']
- name = tree.get('result', $P0, 'Cardinal::Grammar::CONSTANT')
- .return (name)
-
- test_op:
- $I0 = defined node['op']
- unless $I0 goto err_no_name
- $P0 = node['op']
- name = tree.get('result', $P0, 'Cardinal::Grammar::op')
- .return (name)
-
- err_no_name:
- print "The PGE operation2 node doesn't contain a 'IDENTIFIER', 'CONSTANT', or a 'op' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::IDENTIFIER) :language('PIR') {
- .local pmc result
-
- $S0 = node
-
- result = new 'Cardinal::PAST::Val'
- result.'init'('node'=>node, 'name'=>$S0, 'valtype'=>'identifier')
- .return (result)
-
- err_no_tree:
- print "The IDENTIFIER node doesn't contain a 'identifier' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::CONSTANT) :language('PIR') {
- $I0 = defined node[0]
- unless $I0 goto err_no_tree
- $S0 = node[0]
-
- .local pmc result
- result = new 'Cardinal::PAST::Val'
- result.'init'('node'=>node, 'name'=>$S0, 'valtype'=>'constant')
- .return (result)
-
- err_no_tree:
- print "The CONSTANT node doesn't contain a 'constant' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::op) :language('PIR') {
- $S0 = node
-
- .local pmc result
- result = new 'Cardinal::PAST::Val'
- result.'init'('node'=>node, 'name'=>$S0, 'valtype'=>'op')
- .return (result)
-
- err_no_tree:
- print "The op node doesn't contain an 'op' match.\n"
- end
-}
-
-transform result (Cardinal::Grammar::atom) :language('PIR') {
- .local pmc child
- $I0 = defined node['literal']
- unless $I0 goto try_string
- $P0 = node['literal']
- child = tree.get('result', $P0, 'Cardinal::Grammar::literal')
- goto done
-
- try_string:
- $I0 = defined node['string']
- unless $I0 goto try_variable
- $P0 = node['string']
- child = tree.get('result', $P0, 'Cardinal::Grammar::string')
- goto done
-
- try_variable:
- $I0 = defined node['variable']
- unless $I0 goto try_expression
- $P0 = node['variable']
- child = tree.get('result', $P0, 'Cardinal::Grammar::variable')
- goto done
-
- try_expression:
- $I0 = defined node['expression']
- unless $I0 goto err_no_tree
- $P0 = node['expression']
- child = tree.get('result', $P0, 'Cardinal::Grammar::expression')
- goto done
-
-done:
- .return (child)
-
-err_no_tree:
- print "The atom node doesn't contain an appropriate match.\n"
- .kdump2(node, "atom")
- end
-}
-
-transform result (Cardinal::Grammar::lang_statements) :language('PIR') {
- .local pmc child
- $I0 = defined node['begin']
- unless $I0 goto try_if_clause
- .local pmc block
- $P0 = self.'top_scope_stack'()
- block = new 'Cardinal::PAST::Block'
- block.'init'('node'=>node, 'blocktype'=>'begin', 'outer'=>$P0)
-
- $P0 = node['body_statement']
- self.'push_scope_stack'(block)
- child = tree.get('result', $P0, 'Cardinal::Grammar::body_statement')
- self.'pop_scope_stack'()
-
- block.'add_child'(child)
- .return (block)
-
- try_if_clause:
- $I0 = defined node['if_clause']
- unless $I0 goto try_while_until_statement
- $P0 = node['if_clause']
- child = tree.get('result', $P0, 'Cardinal::Grammar::if_clause')
- .return (child)
-
- try_while_until_statement:
- .local pmc test
- .local pmc body
- .local pmc result
-
- $I0 = defined node['while_until']
- unless $I0 goto try_for_statement
- $P0 = node['while_until']
- $S0 = $P0
-
- result = new 'Cardinal::PAST::WhileUntil'
- result.'init'('node'=>node, 'name'=>$S0)
-
- $I0 = defined node['expression']
- unless $I0 goto while_err_no_tree
- $P0 = node['expression']
- test = tree.get('result', $P0, 'Cardinal::Grammar::expression')
- result.add_child(test)
-
- $I0 = defined node['compound_statement']
- unless $I0 goto while_err_no_tree
- $P0 = node['compound_statement']
- body = tree.get('result', $P0, 'Cardinal::Grammar::compound_statement')
- result.add_child(body)
-
- .return (result)
-
- while_err_no_tree:
- print "while or until node inline\n"
- print "The while or until node doesn't contain an appropriate match.\n"
- .kdump2(node, "while_statement")
- end
-
-# $I0 = defined node['while_until']
-# unless $I0 goto try_for_statement
-# child = tree.get('result', node, 'Cardinal::Grammar::while_until_statement')
-# .return (child)
-
- try_for_statement:
- $I0 = defined node['for']
- unless $I0 goto try_def
-
- .local pmc var
- .local pmc test
- .local pmc body
- .local pmc result
-
- result = new 'Cardinal::PAST::For'
- result.'init'('node'=>node)
-
- $I0 = defined node['for_variable']
- unless $I0 goto for_err_no_tree
- $P0 = node['for_variable']
- var = tree.get('result', $P0, 'Cardinal::Grammar::for_variable')
- result.add_child(var)
-
- $I0 = defined node['expression']
- unless $I0 goto for_err_no_tree
- $P0 = node['expression']
- test = tree.get('result', $P0, 'Cardinal::Grammar::expression')
- result.add_child(test)
-
- $I0 = defined node['compound_statement']
- unless $I0 goto for_err_no_tree
- $P0 = node['compound_statement']
- body = tree.get('result', $P0, 'Cardinal::Grammar::compound_statement')
- result.add_child(body)
-
- .return (result)
-
- for_err_no_tree:
- print "The for node doesn't contain an appropriate match.\n"
- .kdump2(node, "while_statement")
- end
-
-# $I0 = defined node['for']
-# unless $I0 goto try_def
-# child = tree.get('result', node, 'Cardinal::Grammar::for')
-# .return (child)
-
- try_def:
- $I0 = defined node['def']
- unless $I0 goto try_class
- .local pmc function
- .local string function_name
- $P0 = node['function_name']
- function_name = tree.get('result', $P0, 'Cardinal::Grammar::function_name')
-
- $P0 = self.'top_scope_stack'()
- $S0 = $P0.'blocktype'()
- .local string function_blocktype
-
- function_blocktype = 'function'
- unless $S0 == 'class' goto is_function
- function_blocktype = 'method'
- is_function:
-
- function = new 'Cardinal::PAST::Block'
- function.'init'('node'=>node, 'name'=>function_name, 'blocktype'=>function_blocktype, 'outer'=>$P0)
- $P0 = node['function_prototype_arg_list']
-
- self.'add_to_current_block'(function_name, function)
-
- self.'push_scope_stack'(function)
-
- child = tree.get('result', $P0, 'Cardinal::Grammar::function_prototype_arg_list')
-
- if_null child, no_params
- .local pmc iter
- iter = new .Iterator, child
- iter_loop1:
- unless iter, iter_end1
- shift $P1, iter
- function.'add_child'($P1)
- goto iter_loop1
- iter_end1:
- no_params:
-
- $P0 = node['body_statement']
- child = tree.get('result', $P0, 'Cardinal::Grammar::body_statement')
- self.'pop_scope_stack'()
- function.'add_child'(child)
- .return (function)
-
- try_class:
- $I0 = defined node['class']
- unless $I0 goto try_module
-
- $P0 = self.'top_scope_stack'()
- .local pmc class_block
- class_block = new 'Cardinal::PAST::Class'
- class_block.'init'('node'=>node, 'name'=>function_name, 'blocktype'=>'class', 'outer'=>$P0)
-
- $I0 = defined node['class_path']
- unless $I0 goto err_no_tree
- $P0 = node['class_path']
- child = tree.get('result', $P0, 'Cardinal::Grammar::class_path')
- class_block.'class_path'(child)
-
-
- $I0 = defined node['superclass']
- unless $I0 goto err_no_tree
- $P0 = node['superclass']
- child = tree.get('result', $P0, 'Cardinal::Grammar::superclass')
- if_null child, class_body
- class_block.'add_child'(child)
-
- class_body:
- $P0 = node['body_statement']
- self.'push_scope_stack'(class_block)
- child = tree.get('result', $P0, 'Cardinal::Grammar::body_statement')
- self.'pop_scope_stack'()
- class_block.'add_child'(child)
- .return (class_block)
-
- try_module:
- $I0 = defined node['module']
- unless $I0 goto err_no_tree
-
- $P0 = self.'top_scope_stack'()
- .local pmc module_block
- module_block = new 'Cardinal::PAST::Module'
- module_block.'init'('node'=>node, 'name'=>function_name, 'blocktype'=>'module', 'outer'=>$P0)
-
- $I0 = defined node['class_path']
- unless $I0 goto err_no_tree
- $P0 = node['class_path']
- child = tree.get('result', $P0, 'Cardinal::Grammar::class_path')
- module_block.'add_child'(child)
-
- module_body:
- $P0 = node['body_statement']
- self.'push_scope_stack'(module_block)
- child = tree.get('result', $P0, 'Cardinal::Grammar::body_statement')
- self.'pop_scope_stack'()
- module_block.'add_child'(child)
- .return (module_block)
-
- err_no_tree:
- print "The lang_statements node doesn't contain an appropriate match.\n"
- .kdump2(node, "lang_statements")
- end
-}
-
-transform result (Cardinal::Grammar::while_until_statement) :language('PIR') {
- .local pmc test
- .local pmc body
- .local pmc result
-
- $I0 = defined node['while_until']
- unless $I0 goto err_no_tree
- $P0 = node['while_until']
- $S0 = $P0
-
- result = new 'Cardinal::PAST::WhileUntil'
- result.'init'('node'=>node, 'name'=>$S0)
-
- $I0 = defined node['expression']
- unless $I0 goto err_no_tree
- $P0 = node['expression']
- test = tree.get('result', $P0, 'Cardinal::Grammar::expression')
- result.add_child(test)
-
- $I0 = defined node['compound_statement']
- unless $I0 goto err_no_tree
- $P0 = node['compound_statement']
- body = tree.get('result', $P0, 'Cardinal::Grammar::compound_statement')
- result.add_child(body)
-
- .return (result)
-
- err_no_tree:
- print "while_until_statement\n"
- print "The while or until node doesn't contain an appropriate match.\n"
- .kdump2(node, "while_until_statement")
- end
-}
-
-transform result (Cardinal::Grammar::for_statement) :language('PIR') {
- .local pmc var
- .local pmc test
- .local pmc body
- .local pmc result
-
- result = new 'Cardinal::PAST::For'
- result.'init'('node'=>node)
-
- $I0 = defined node['for_variable']
- unless $I0 goto err_no_tree
- $P0 = node['for_variable']
- var = tree.get('result', $P0, 'Cardinal::Grammar::for_variable')
- result.add_child(var)
-
- $I0 = defined node['expression']
- unless $I0 goto err_no_tree
- $P0 = node['expression']
- test = tree.get('result', $P0, 'Cardinal::Grammar::expression')
- result.add_child(test)
-
- $I0 = defined node['compound_statement']
- unless $I0 goto err_no_tree
- $P0 = node['compound_statement']
- body = tree.get('result', $P0, 'Cardinal::Grammar::compound_statement')
- result.add_child(body)
-
- .return (result)
-
- err_no_tree:
- print "The for node doesn't contain an appropriate match.\n"
- .kdump2(node, "while_statement")
- end
-}
-
-transform result (Cardinal::Grammar::for_variable) :language('PIR') {
- .local pmc var
-
- $I0 = defined node['left_hand_side']
- unless $I0 goto err_no_tree
- $P0 = node['left_hand_side']
- var = tree.get('result', $P0, 'Cardinal::Grammar::left_hand_side')
- .return (var)
-
- $I0 = defined node['multiple_left_hand_side']
- unless $I0 goto err_no_tree
- $P0 = node['multiple_left_hand_side']
- var = tree.get('result', $P0, 'Cardinal::Grammar::multiple_left_hand_side')
-
- .return (var)
-
- err_no_tree:
- print "The for_variable node doesn't contain an appropriate match.\n"
- .kdump2(node, "for_variable")
- end
-}
-
-transform result (Cardinal::Grammar::function_name) :language('PIR') {
- .local pmc op
- .local pmc child
- $I0 = defined node['IDENTIFIER']
- unless $I0 goto n1
- $P0 = node['IDENTIFIER']
- child = tree.get('result', $P0, 'Cardinal::Grammar::IDENTIFIER')
- goto finish
- n1:
- $I0 = defined node['CONSTANT']
- unless $I0 goto n2
- $P0 = node['CONSTANT']
- child = tree.get('result', $P0, 'Cardinal::Grammar::CONSTANT')
- goto finish
- n2:
- $I0 = defined node['FID']
- unless $I0 goto n3
- $P0 = node['FID']
- child = tree.get('result', $P0, 'Cardinal::Grammar::FID')
- goto finish
- n3:
- $I0 = defined node['op']
- unless $I0 goto n4
- $P0 = node['op']
- child = tree.get('result', $P0, 'Cardinal::Grammar::op')
- goto finish
- n4:
- $I0 = defined node['reserved_words']
- unless $I0 goto err_no_tree
- $P0 = node['reserved_words']
- child = tree.get('result', $P0, 'Cardinal::Grammar::reserved_words')
- goto finish
- finish:
- $S0 = child
- .return ($S0)
-
- err_no_tree:
- print "The function_name node doesn't contain a the right component matches.\n"
- .kdump2(node, 'function_name')
- end
-}
-transform result (Cardinal::Grammar::class_path) :language('PIR') {
- .local pmc result
- .local pmc child
- result = new 'Cardinal::PAST::ClassPath'
- result.'init'('node'=>node, 'name'=>'class_path')
- $S0 = node
- result.'class_name'($S0)
-
- $I0 = defined node['starting_colons']
- unless $I0 goto atoms
- $P0 = node['starting_colons']
- result.'starting_colons'(1)
-
- atoms:
- $I0 = defined node['atom']
- unless $I0 goto get_name
- $P0 = node['atom']
-
- .local pmc iter
- iter = new .Iterator, $P0
- iter_loop:
- unless iter goto iter_end
- $P1 = shift iter
- child = tree.get('result', $P1, 'Cardinal::Grammar::atom')
- result.'add_child'(child)
- goto iter_loop
- iter_end:
-
- get_name:
- $I0 = defined node['class_name']
- unless $I0 goto err_no_tree
- $S0 = node['class_name']
- result.'add_child'($S0)
-
- .return (result)
-
- err_no_tree:
- print "The class_path node doesn't contain a the right component matches.\n"
- .kdump(node)
- end
-}
-
-transform result (Cardinal::Grammar::superclass) :language('PIR') {
- .local pmc result
- .local pmc child
- result = new 'Cardinal::PAST::Op'
- result.'init'('node'=>node, 'name'=>'superclass')
-
- $I0 = defined node['expression']
- unless $I0 goto try_error
- $P0 = node['expression'; 0]
- child = tree.get('result', $P0, 'Cardinal::Grammar::expression')
- .return (child)
-
- try_error:
- $I0 = defined node['error']
- unless $I0 goto just_return
- $P0 = node['error']
- child = tree.get('result', $P0, 'Cardinal::Grammar::error')
- .return (child)
-
- just_return:
- null $P0
- .return ($P0)
-
- err_no_tree:
- print "The superclass node doesn't contain a the right component matches.\n"
- .kdump(node)
- end
-}
-
-transform result (Cardinal::Grammar::function_prototype_arg_list) :language('PIR') {
- .local pmc child
- $I0 = defined node['function_prototype_args']
- unless $I0 goto return_empty
- $P0 = node['function_prototype_args'; 0]
- child = tree.get('result', $P0, 'Cardinal::Grammar::function_prototype_args')
- .return (child)
- return_empty:
- null $P0
- .return ($P0)
-
- err_no_tree:
- print "The function_prototype_arg_list node doesn't contain a the right component matches.\n"
- .kdump2(node, 'function_prototype_arg_list')
- end
-}
-
-transform result (Cardinal::Grammar::function_prototype_args) :language('PIR') {
- .local pmc child
- .local pmc arg_list
- arg_list = new .ResizablePMCArray
-
- $I0 = defined node['function_prototype_positional_arg_list']
- unless $I0 goto n1
- $P1 = node['function_prototype_positional_arg_list']
- child = tree.get('result', $P1, 'Cardinal::Grammar::function_prototype_positional_arg_list')
- arg_list.'append'(child)
-
- n1:
- $I0 = defined node['function_prototype_optional_arg_list']
- unless $I0 goto n2
- $P1 = node['function_prototype_optional_arg_list']
- child = tree.get('result', $P1, 'Cardinal::Grammar::function_prototype_optional_arg_list')
- arg_list.'append'(child)
-
- n2:
- $I0 = defined node['function_prototype_rest_args']
- unless $I0 goto n3
- $P1 = node['function_prototype_rest_args']
- child = tree.get('result', $P1, 'Cardinal::Grammar::function_prototype_rest_args')
- push arg_list, child
-
- n3:
- $I0 = defined node['function_prototype_block_arg']
- unless $I0 goto n4
- $P1 = node['function_prototype_block_arg']
- child = tree.get('result', $P1, 'Cardinal::Grammar::function_prototype_block_arg')
- push arg_list, child
-
- n4:
- .return (arg_list)
-
- err_no_tree:
- print "The function_prototype_args node doesn't contain a the right component matches.\n"
- .kdump2(node, 'function_prototype_args')
- end
-}
-
-transform result (Cardinal::Grammar::function_prototype_positional_arg_list) :language('PIR') {
- .local pmc child
- .local pmc arg_list
- arg_list = new .ResizablePMCArray
-
- $I0 = defined node['function_prototype_arg']
- unless $I0 goto n1
- $P0 = node['function_prototype_arg']
-
- .local pmc iter
- iter = new .Iterator, $P0
- iter_loop:
- unless iter, iter_end
- shift $P1, iter
- child = tree.get('result', $P1, 'Cardinal::Grammar::function_prototype_arg')
- push arg_list, child
- goto iter_loop
- iter_end:
-
- n1:
- .return (arg_list)
-
- err_no_tree:
- print "The function_prototype_positional_arg_list node doesn't contain a the right component matches.\n"
- .kdump2(node, 'function_prototype_positional_arg_list')
- end
-}
-
-transform result (Cardinal::Grammar::function_prototype_optional_arg_list) :language('PIR') {
- .local pmc child
- .local pmc arg_list
- arg_list = new .ResizablePMCArray
-
- $I0 = defined node['function_prototype_optional_arg']
- unless $I0 goto n1
- $P0 = node['function_prototype_optional_arg']
-
- .local pmc iter
- iter = new .Iterator, $P0
- iter_loop:
- unless iter, iter_end
- shift $P1, iter
- child = tree.get('result', $P1, 'Cardinal::Grammar::function_prototype_optional_arg')
- push arg_list, child
- goto iter_loop
- iter_end:
-
- n1:
- .return (arg_list)
-
- err_no_tree:
- print "The function_prototype_optional_arg_list node doesn't contain a the right component matches.\n"
- .kdump2(node, 'function_prototype_optional_arg_list')
- end
-}
-
-
-transform result (Cardinal::Grammar::function_prototype_arg) :language('PIR') {
- .local pmc op
- .local pmc child
- .local string type
-
- $I0 = defined node['IDENTIFIER']
- unless $I0 goto n1
- $P0 = node['IDENTIFIER']
- child = tree.get('result', $P0, 'Cardinal::Grammar::IDENTIFIER')
- type = 'normal'
- goto finish
- n1:
- $I0 = defined node['CONSTANT']
- unless $I0 goto n2
- $P0 = node['CONSTANT']
- child = tree.get('result', $P0, 'Cardinal::Grammar::CONSTANT')
- type = 'normal'
- goto finish
- n2:
- $I0 = defined node['INSTANCE_VARIABLE']
- unless $I0 goto n3
- $P0 = node['INSTANCE_VARIABLE']
- child = tree.get('result', $P0, 'Cardinal::Grammar::INSTANCE_VARIABLE')
- type = 'instance'
- goto finish
- n3:
- $I0 = defined node['GLOBAL_VARIABLE']
- unless $I0 goto n4
- $P0 = node['GLOBAL_VARIABLE']
- child = tree.get('result', $P0, 'Cardinal::Grammar::GLOBAL_VARIABLE')
- type = 'global'
- goto finish
- n4:
- $I0 = defined node['CLASS_VARIABLE']
- unless $I0 goto err_no_tree
- $P0 = node['CLASS_VARIABLE']
- child = tree.get('result', $P0, 'Cardinal::Grammar::CLASS_VARIABLE')
- type = 'class'
- goto finish
- finish:
- $S0 = child
- op = new 'Cardinal::PAST::PositionalParameter'
- op.'init'('node'=>node, 'name'=>$S0, 'scope'=>'parameter', 'type'=>type)
- self.'add_to_current_block'($S0, op)
- .return (op)
-
- err_no_tree:
- print "The function_prototype_arg node doesn't contain a the right component matches.\n"
- .kdump2(node, 'function_prototype_arg')
- end
-}
-
-transform result (Cardinal::Grammar::function_prototype_optional_arg) :language('PIR') {
- .local pmc op
- .local pmc child
- .local pmc expression
- $I0 = defined node['IDENTIFIER']
- unless $I0 goto err_no_tree
- $P0 = node['IDENTIFIER']
- child = tree.get('result', $P0, 'Cardinal::Grammar::IDENTIFIER')
- $S0 = child
- $P0 = node['expression']
- expression = tree.get('result', $P0, 'Cardinal::Grammar::expression')
- op = new 'Cardinal::PAST::OptionalParameter'
- op.'init'('node'=>node, 'name'=>$S0, 'scope'=>'parameter', 'default_value'=>expression)
- self.'add_to_current_block'($S0, op)
- .return (op)
-
- err_no_tree:
- print "The function_prototype_optional_arg node doesn't contain a the right component matches.\n"
- .kdump2(node, 'function_prototype_optional_arg')
- end
-}
-
-transform result (Cardinal::Grammar::function_prototype_rest_args) :language('PIR') {
- .local pmc op
- .local pmc child
- $I0 = defined node['IDENTIFIER']
- unless $I0 goto err_no_tree
- $P0 = node['IDENTIFIER']
- child = tree.get('result', $P0, 'Cardinal::Grammar::IDENTIFIER')
- $S0 = child
- op = new 'Cardinal::PAST::RestParameter'
- op.'init'('node'=>node, 'name'=>$S0, 'scope'=>'parameter')
- self.'add_to_current_block'($S0, op)
- .return (op)
-
- err_no_tree:
- print "The function_prototype_rest_arg_list node doesn't contain a the right component matches.\n"
- .kdump2(node, 'function_prototype_rest_arg_list')
- end
-}
-
-transform result (Cardinal::Grammar::function_prototype_block_arg) :language('PIR') {
- .local pmc op
- .local pmc child
- $I0 = defined node['IDENTIFIER']
- unless $I0 goto err_no_tree
- $P0 = node['IDENTIFIER']
- child = tree.get('result', $P0, 'Cardinal::Grammar::IDENTIFIER')
- $S0 = child
- op = new 'Cardinal::PAST::BlockParameter'
- op.'init'('node'=>node, 'name'=>$S0, 'scope'=>'parameter')
- self.'add_to_current_block'($S0, op)
- .return (op)
-
- err_no_tree:
- print "The function_prototype_block_arg node doesn't contain a the right component matches.\n"
- .kdump2(node, 'function_prototype_block_arg')
- end
-}
-
-transform result (Cardinal::Grammar::if_clause) :language('PIR') {
- .local pmc child
- .local pmc op
- op = new 'Cardinal::PAST::Op'
- op.'init'('node'=>node, 'name'=>'if')
-
- $I0 = defined node['expression']
- unless $I0 goto err_no_tree
- $P0 = node['expression']
- child = tree.get('result', $P0, 'Cardinal::Grammar::expression')
- op.'add_child'(child)
-
- $I0 = defined node['compound_statement']
- unless $I0 goto err_no_tree
- $P0 = node['compound_statement']
- child = tree.get('result', $P0, 'Cardinal::Grammar::compound_statement')
- op.'add_child'(child)
-
- $I0 = defined node['elsif_clause']
- unless $I0 goto n1
- $P0 = node['elsif_clause']
- child = tree.get('result', $P0, 'Cardinal::Grammar::elsif_clause')
- op.'add_child'(child)
-
- n1:
- $I0 = defined node['else_clause']
- unless $I0 goto n2
- $P0 = node['else_clause']
- child = tree.get('result', $P0, 'Cardinal::Grammar::else_clause')