develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35014 - in trunk/languages/ecmascript: config/makefiles src/builtin src/parser t/js_pt t/sanity_pt

From:
tewk
Date:
January 5, 2009 22:39
Subject:
[svn:parrot] r35014 - in trunk/languages/ecmascript: config/makefiles src/builtin src/parser t/js_pt t/sanity_pt
Message ID:
20090106063938.5D817CB9F9@x12.develooper.com
Author: tewk
Date: Mon Jan  5 22:39:35 2009
New Revision: 35014

Added:
   trunk/languages/ecmascript/t/js_pt/00-template.t
   trunk/languages/ecmascript/t/js_pt/09-array.t
   trunk/languages/ecmascript/t/js_pt/09-array_literals.t
   trunk/languages/ecmascript/t/js_pt/11-global_object.t
   trunk/languages/ecmascript/t/js_pt/12-regex.t
Modified:
   trunk/languages/ecmascript/config/makefiles/root.in
   trunk/languages/ecmascript/src/builtin/builtins.pir
   trunk/languages/ecmascript/src/parser/actions.pm
   trunk/languages/ecmascript/src/parser/grammar.pg
   trunk/languages/ecmascript/t/sanity_pt/05-objects.t

Log:
[js] trying to generate code for object literals


Modified: trunk/languages/ecmascript/config/makefiles/root.in
==============================================================================
--- trunk/languages/ecmascript/config/makefiles/root.in	(original)
+++ trunk/languages/ecmascript/config/makefiles/root.in	Mon Jan  5 22:39:35 2009
@@ -137,6 +137,9 @@
 
 testclean:
 	$(RM_F) "t/*.js" "t/*.out"
+	$(RM_F) "t/sanity_pt/*.js" "t/sanity_pt/*.out"
+	$(RM_F) "t/js_pt/*.js" "t/js_pt/*.out"
+
 
 CLEANUPS = \
   js.pbc \

Modified: trunk/languages/ecmascript/src/builtin/builtins.pir
==============================================================================
--- trunk/languages/ecmascript/src/builtin/builtins.pir	(original)
+++ trunk/languages/ecmascript/src/builtin/builtins.pir	Mon Jan  5 22:39:35 2009
@@ -48,11 +48,11 @@
 .end
 
 
-.sub 'Array'
-    .param pmc args :slurpy
-    $P0 = new 'Array'
-    .return ($P0)
-.end
+#.sub 'Array'
+#    .param pmc args :slurpy
+#    $P0 = new 'Array'
+#    .return ($P0)
+#.end
 
 .sub __load :init :anon
     newclass $P0, ['ECMAScript';'Object']

Modified: trunk/languages/ecmascript/src/parser/actions.pm
==============================================================================
--- trunk/languages/ecmascript/src/parser/actions.pm	(original)
+++ trunk/languages/ecmascript/src/parser/actions.pm	Mon Jan  5 22:39:35 2009
@@ -679,9 +679,13 @@
 }
 
 method object_literal($/) {
-    my $past := PAST::Op.new( :pasttype('call'), :node($/) );
-    $past.name('Object');
+    my $past := PAST::Stmts.new( :node($/) );
+    
+    my $type := PAST::Var.new( :name('JSObject'), :scope('package'), :node($/) );
+    my $obj := PAST::Op.new( :pasttype('callmethod'), :name("new"), :node($/), $type);
+
     for $<property> {
+        $($_).unshift($obj);
         $past.push( $($_) );
     }
     make $past;
@@ -702,17 +706,19 @@
     ## XXX my $key  := PAST::Val.new( $prop, :returns('String'), :node($/) );
     my $val  := $( $<assignment_expression> );
 
-    $val.named($key);
-    make $val;
+    my $past := PAST::Op.new( :pasttype('callmethod'), :name('Set'), $key, $val, :node($/) );
+
+    make $past;
 }
 
 
 method property_name($/, $key) {
     ## XXX
     my $propname := $( $/{$key} );
-    my $past := PAST::Op.new( :inline('    $S0 = %0'), :node($/) );
-    $past.push($propname);
-    make $past;
+    #my $past := PAST::Op.new( :inline('    $S0 = %0'), :node($/) );
+    #$past.push($propname);
+    #make $past;
+    make $propname;
 }
 
 method array_literal($/) {

Modified: trunk/languages/ecmascript/src/parser/grammar.pg
==============================================================================
--- trunk/languages/ecmascript/src/parser/grammar.pg	(original)
+++ trunk/languages/ecmascript/src/parser/grammar.pg	Mon Jan  5 22:39:35 2009
@@ -345,7 +345,7 @@
 token null { 'null' {*} }
 
 rule object_literal {
-    '{' [ <property> [',' <property> ]* ]? '}'
+    '{' [ <property> [',' <property> ]* [',']? ]?  '}'
     {*}
 }
 

Added: trunk/languages/ecmascript/t/js_pt/00-template.t
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/t/js_pt/00-template.t	Mon Jan  5 22:39:35 2009
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+# Copyright (C) 2008, The Perl Foundation.
+# $Id: 10-version.t 34398 2008-12-26 19:40:48Z bernhard $
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 2;
+
+language_output_is( 'JS', <<'CODE', <<'OUT', '' );
+CODE
+OUT
+
+language_output_is( 'JS', <<'CODE', <<'OUT', '', todo => 'todoed');
+CODE
+FAILED
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/languages/ecmascript/t/js_pt/09-array.t
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/t/js_pt/09-array.t	Mon Jan  5 22:39:35 2009
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+# Copyright (C) 2008, The Perl Foundation.
+# $Id: 10-version.t 34398 2008-12-26 19:40:48Z bernhard $
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 1;
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'new array into var', todo => 'NOTIMPLEMENTED');
+var a = new Array();
+print a.length
+CODE
+0
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/languages/ecmascript/t/js_pt/09-array_literals.t
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/t/js_pt/09-array_literals.t	Mon Jan  5 22:39:35 2009
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+# Copyright (C) 2008, The Perl Foundation.
+# $Id: 10-version.t 34398 2008-12-26 19:40:48Z bernhard $
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 1;
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'array literal of strings', todo => 'NOTIMPLEMENTED' );
+var digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
+print(digits);
+CODE
+0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/languages/ecmascript/t/js_pt/11-global_object.t
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/t/js_pt/11-global_object.t	Mon Jan  5 22:39:35 2009
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+# Copyright (C) 2008, The Perl Foundation.
+# $Id: 10-version.t 34398 2008-12-26 19:40:48Z bernhard $
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 1;
+
+language_output_is( 'JS', <<'CODE', <<'OUT', '', todo => 'NOTIMPLEMENTED' );
+print(this);
+CODE
+[object global]
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/languages/ecmascript/t/js_pt/12-regex.t
==============================================================================
--- (empty file)
+++ trunk/languages/ecmascript/t/js_pt/12-regex.t	Mon Jan  5 22:39:35 2009
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+# Copyright (C) 2008, The Perl Foundation.
+# $Id: 10-version.t 34398 2008-12-26 19:40:48Z bernhard $
+
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Parrot::Test tests => 1;
+
+language_output_is( 'JS', <<'CODE', <<'OUT', 'print a simple regex', todo => 'NOTIMPLEMENTED');
+print( /a/ );
+CODE
+/a/
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Modified: trunk/languages/ecmascript/t/sanity_pt/05-objects.t
==============================================================================
--- trunk/languages/ecmascript/t/sanity_pt/05-objects.t	(original)
+++ trunk/languages/ecmascript/t/sanity_pt/05-objects.t	Mon Jan  5 22:39:35 2009
@@ -7,7 +7,7 @@
 use FindBin;
 use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
 
-use Parrot::Test tests => 3;
+use Parrot::Test tests => 4;
 
 language_output_is( 'JS', <<'CODE', <<'OUT', 'empty object', todo => 'toString broken' );
 var a = {};
@@ -33,6 +33,12 @@
 [object Object]
 OUT
 
+language_output_is( 'JS', <<'CODE', <<'OUT', 'objects with array members', todo => 'NOTIMPLEMENTED');
+var deriv = {X: [], Y: [] };
+CODE
+OUT
+
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About