Permalink
Browse files

[cardinal]

* Indexed variable access works
* array creation works


git-svn-id: https://svn.parrot.org/parrot/trunk/languages/cardinal@27829 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
tene committed May 26, 2008
1 parent c27492c commit 3e448bd71927e3f5b5142fe1a25db30749e0a79d
Showing with 32 additions and 15 deletions.
  1. +3 −3 cardinal.pir
  2. +13 −10 src/parser/actions.pm
  3. +4 −2 src/parser/grammar.pg
  4. +12 −0 t/04-indexed.t
View
@@ -75,9 +75,6 @@ to the cardinal compiler.
.sub 'main' :main
.param pmc args_str
- $P0 = compreg 'cardinal'
- $P1 = $P0.'command_line'(args_str)
-
## create ARGS global.
.local pmc args, iter
args = new 'CardinalArray'
@@ -90,6 +87,9 @@ to the cardinal compiler.
args_end:
set_hll_global 'ARGS', args
+ $P0 = compreg 'cardinal'
+ $P1 = $P0.'command_line'(args_str)
+
.include 'iterator.pasm'
$P0 = get_hll_global ['cardinal'], '@?END_BLOCKS'
iter = new 'Iterator', $P0
View
@@ -209,6 +209,13 @@ method local_variable($/) {
}
+method constant_variable($/) {
+ my @a;
+ my $past := PAST::Var.new( :name(~$/), :scope('package'), :node($/), :viviself('Undef'), :namespace( @a ) );
+ make $past;
+}
+
+
method if_stmt($/) {
my $cond := +$<expr> - 1;
my $comp := $( $<comp_stmt>[$cond] );
@@ -447,20 +454,16 @@ method pcomp_stmt($/) {
}
method array($/) {
- my $past;
- ## XXX the "new" method should be invoked on the "Array" class (use get_class)
- ## but that doesn't work yet.
- my $getclass := PAST::Op.new( :inline(' %r = new "CardinalArray"'), :node($/) );
+ my $list;
if $<args> {
- $past := $( $<args>[0] );
- $past.unshift( $getclass );
- $past.name('new');
- $past.pasttype('callmethod');
+ $list := $( $<args>[0] );
+ $list.name('list');
}
else {
- $past := PAST::Op.new( $getclass, :name('new'), :pasttype('callmethod'), :node($/) );
+ $list := PAST::Op.new( :name('list'), :node($/) );
}
- make $past;
+
+ make $list;
}
method ahash($/) {
View
@@ -104,8 +104,8 @@ token lhs {
| <member_variable> {*} #= member_variable
}
-rule indexed_variable {
- <primary> '[' <args>? ']'
+token indexed_variable {
+ <primary=variable> '[' <args>? ']'
{*}
}
@@ -164,6 +164,7 @@ token varname {
[ <global> {*} #= global
| <instance_variable> {*} #= instance_variable
| <local_variable> {*} #= local_variable
+ | <constant_variable> {*} #= constant_variable
]
}
@@ -184,6 +185,7 @@ proto 'infix:=' is precedence('1') is pasttype('copy') is lvalue(1) { ... }
token basic_primary {
| <literal> {*} #= literal
+ | <indexed_variable> {*} #= indexed_variable
| <command> {*} #= command
| <not_command> {*} #= command
| <variable> {*} #= variable
View
@@ -0,0 +1,12 @@
+puts "1..4"
+
+a = [ 'ok ', 1 ]
+
+puts a[0], a[1]
+
+a = [ 'ok ', 2, 3, 4 ]
+b = 1
+
+puts a[0], a[b]
+puts a[0], a[a[1]]
+puts a[0], a[a[a[1]]]

0 comments on commit 3e448bd

Please sign in to comment.