Revision: 4144
          http://vexi.svn.sourceforge.net/vexi/?rev=4144&view=rev
Author:   mkpg2
Date:     2011-05-18 17:14:47 +0000 (Wed, 18 May 2011)

Log Message:
-----------
Development. Implement, but leave disabled for now, the new object 
initialisation syntax.

Modified Paths:
--------------
    trunk/org.vexi-library.js/src/main/java/org/ibex/js/parse/Parser.java
    
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/TestGeneral.java

Added Paths:
-----------
    trunk/org.vexi-library.js/src/test/java/test/js/exec/general/object_init.js

Modified: trunk/org.vexi-library.js/src/main/java/org/ibex/js/parse/Parser.java
===================================================================
--- trunk/org.vexi-library.js/src/main/java/org/ibex/js/parse/Parser.java       
2011-05-18 16:24:59 UTC (rev 4143)
+++ trunk/org.vexi-library.js/src/main/java/org/ibex/js/parse/Parser.java       
2011-05-18 17:14:47 UTC (rev 4144)
@@ -305,6 +305,38 @@
         }
     }
 
+    private void parseObjectInit(Function b) throws IOException{
+        while(true) {
+            if (peekToken() != NAME && peekToken() != STRING)
+                throw pe("expected NAME or STRING");
+            getToken();
+            b.add(parserLine, LITERAL, string(string));                        
  // grab the key
+            consume(COLON);
+            startExpr(b, NO_COMMA);                                      // 
grab the value
+            b.add(parserLine, PUT);                                      // 
put the value into the object
+            b.add(parserLine, POP);                                      // 
discard the remaining value
+            if (peekToken() == RC) break;
+            consume(COMMA);
+            if (peekToken() == RC) break;                                // we 
permit {,,} -- I'm not sure if ECMA does
+        }
+    }
+    
+    private int parseArrayInit(Function b) throws IOException{
+        int i = 0;
+        while(true) {                                               // iterate 
over the initialization values
+            b.add(parserLine, LITERAL, integer(i++));           // push the 
index in the array to place it into
+            if (peekToken() == COMMA || peekToken() == RB)
+                b.add(parserLine, LITERAL, null);                   // for 
stuff like [1,,2,]
+            else
+                startExpr(b, NO_COMMA);                             // push 
the value onto the stack
+            b.add(parserLine, PUT);                                 // put it 
into the array
+            b.add(parserLine, POP);                                 // discard 
the value remaining on the stack
+            if (peekToken() == RB) break;
+            consume(COMMA);
+        }
+        return i;
+    }    
+    
     /**
      *  Parse the largest possible expression containing no operators
      *  of precedence below <tt>minPrecedence</tt> and append the
@@ -344,17 +376,7 @@
             int size0 = b.size;
             int i = 0;
             if (peekToken() != RB)
-                while(true) {                                               // 
iterate over the initialization values
-                    b.add(parserLine, LITERAL, integer(i++));           // 
push the index in the array to place it into
-                    if (peekToken() == COMMA || peekToken() == RB)
-                        b.add(parserLine, LITERAL, null);                   // 
for stuff like [1,,2,]
-                    else
-                        startExpr(b, NO_COMMA);                             // 
push the value onto the stack
-                    b.add(parserLine, PUT);                                 // 
put it into the array
-                    b.add(parserLine, POP);                                 // 
discard the value remaining on the stack
-                    if (peekToken() == RB) break;
-                    consume(COMMA);
-                }
+                i = parseArrayInit(b);
             b.set(size0 - 1, integer(i));                               // 
back at the ARRAY instruction, write the size of the array
             consume(RB);
             break;
@@ -416,20 +438,8 @@
         }
         case LC: { // object constructor
             b.add(parserLine, OBJECT, null);                                   
  // put an object on the stack
-            if (peekToken() != RC)
-                while(true) {
-                    if (peekToken() != NAME && peekToken() != STRING)
-                        throw pe("expected NAME or STRING");
-                    getToken();
-                    b.add(parserLine, LITERAL, string(string));                
          // grab the key
-                    consume(COLON);
-                    startExpr(b, NO_COMMA);                                    
  // grab the value
-                    b.add(parserLine, PUT);                                    
  // put the value into the object
-                    b.add(parserLine, POP);                                    
  // discard the remaining value
-                    if (peekToken() == RC) break;
-                    consume(COMMA);
-                    if (peekToken() == RC) break;                              
  // we permit {,,} -- I'm not sure if ECMA does
-                }
+            if (peekToken() != RC) 
+                parseObjectInit(b);
             consume(RC);
             break;
         }
@@ -805,6 +815,14 @@
                     consume(ASSIGN);
                     startExpr(b, NO_COMMA);
                     b.add(parserLine, SCOPEPUT, scopeKey(var)); // assign it
+                    
+//// DISABLED for now. Object Initialisation Syntax               
+//                    if(peekToken()==LC){
+//                        consume(LC);
+//                        parseObjectInit(b);
+//                        consume(RC);
+//                    }
+                    
                     b.add(parserLine, POP);                      // clean the 
stack
                 }else if(tok == CONST){
                        throw pe("const not assigned to");

Modified: 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/TestGeneral.java
===================================================================
--- 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/TestGeneral.java   
    2011-05-18 16:24:59 UTC (rev 4143)
+++ 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/TestGeneral.java   
    2011-05-18 17:14:47 UTC (rev 4144)
@@ -16,7 +16,7 @@
     public static void main(String[] args) throws Throwable {
        try{
                JSTestSuite jts = new JSTestSuite(TestGeneral.class);
-               JSTestCase t = jts.createTestCase(jts.getResourceDirs(), 
"multiline_string.js");
+               JSTestCase t = jts.createTestCase(jts.getResourceDirs(), 
"object_init.js");
                //t.printByteCode();
                t.runBare();
        }catch(Throwable t){

Added: 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/object_init.js
===================================================================
--- trunk/org.vexi-library.js/src/test/java/test/js/exec/general/object_init.js 
                        (rev 0)
+++ trunk/org.vexi-library.js/src/test/java/test/js/exec/general/object_init.js 
2011-05-18 17:14:47 UTC (rev 4144)
@@ -0,0 +1,15 @@
+
+sys.import("shared");
+const Object = sys.js.Object;
+const Array = sys.js.Array;
+
+var foo =              { a: 1, b: 2 };
+var bar = new Object() { a: 1, b: 2 };
+assertObjEquals(foo, bar);
+
+
+//// REMARK, not possible to to for array initialisation,   
+//// since a[b] has a meaning already (i.e. get from object)
+//var boo =             [3];
+//var hoo = new Array() [3];
+//assertObjEquals(boo, hoo);


Property changes on: 
trunk/org.vexi-library.js/src/test/java/test/js/exec/general/object_init.js
___________________________________________________________________
Added: svn:mime-type
   + text/plain


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to