Skip to content
This repository
Browse code

simplify support for new in stage 1:

No new literal-string
No new with variables or string const
No functions called new
  • Loading branch information...
commit e3559598c41e090b6b5a54496445f72e6288a0d5 1 parent 77eebb7
NotFound authored May 27, 2012
2  t/medium/02assignto.t
@@ -9,7 +9,7 @@ function main()
9 9
     using Test.More.is;
10 10
     plan (2);
11 11
 
12  
-    var a= new "FixedStringArray";
  12
+    var a= new [ "FixedStringArray" ];
13 13
     a=: 42;
14 14
     is (a instanceof "FixedStringArray", 1, "type unchanged");
15 15
     int i= a;
2  t/medium/04do.t
@@ -8,7 +8,7 @@ function main()
8 8
 {
9 9
     plan(1);
10 10
 
11  
-    var c = new "Integer";
  11
+    var c = new [ "Integer" ];
12 12
     c =: 4;
13 13
     int i = 0;
14 14
     do {
2  winxed.winxed
@@ -125,7 +125,7 @@ function driver_main(var argv)
125 125
         return;
126 126
     }
127 127
 
128  
-    var env = new "Env";
  128
+    var env = new [ "Env" ];
129 129
     // Path for stage pbc files
130 130
     string winxedpath = env["WINXED_PATH"];
131 131
 
91  winxedst1.winxed
@@ -5845,7 +5845,7 @@ class NewExpr : NewBaseExpr
5845 5845
     {
5846 5846
         self.Expr(owner, start);
5847 5847
 
5848  
-        if (! (firstvalue.isstring() || firstvalue.isidentifier()))
  5848
+        if (!firstvalue.isidentifier())
5849 5849
             SyntaxError("Unimplemented", firstvalue);
5850 5850
         self.value = firstvalue;
5851 5851
         var t = tk.get();
@@ -5858,17 +5858,6 @@ class NewExpr : NewBaseExpr
5858 5858
     function optimize()
5859 5859
     {
5860 5860
         var value = self.value;
5861  
-        if (value.isidentifier()) {
5862  
-            // The identifier can be a string constant, check for that case
5863  
-            // and obtain the string value.
5864  
-            var desc = self.owner.getvar(value.getidentifier());
5865  
-            if (desc != null && desc.isconst()) {
5866  
-                value = desc.getvalue();
5867  
-                if (! (value instanceof StringLiteral))
5868  
-                    SyntaxError("Constant value must evaluate to a string", value);
5869  
-                self.value = value.strval;
5870  
-            }
5871  
-        }
5872 5861
         self.optimize_initializer();
5873 5862
         return self;
5874 5863
     }
@@ -5880,10 +5869,6 @@ class NewExpr : NewBaseExpr
5880 5869
         var value = self.value;
5881 5870
         int numinits = self.numargs();
5882 5871
 
5883  
-        const int BYNAME = 0, BYIDENT = 1;
5884  
-        int type = value.isstring() ? BYNAME :
5885  
-                value.isidentifier() ? BYIDENT : -1;
5886  
-
5887 5872
         string reginit = "";
5888 5873
         string regnew = result;
5889 5874
         string constructor;
@@ -5891,20 +5876,7 @@ class NewExpr : NewBaseExpr
5891 5876
           case -1:
5892 5877
           case 0:
5893 5878
             break;
5894  
-          case 1:
5895  
-            if (type == BYIDENT) {
5896  
-                if (! is_init)
5897  
-                    regnew = self.tempreg(REGvar);
5898  
-            }
5899  
-            else {
5900  
-                var initval = initializer.getfreearg(0);
5901  
-                reginit = initval.emit_get(e);
5902  
-                reginit = ", " + reginit;
5903  
-            }
5904  
-            break;
5905 5879
           default:
5906  
-            if (type != BYIDENT)
5907  
-                SyntaxError("Multiple init arguments not allowed here", self);
5908 5880
             if (! is_init)
5909 5881
                 regnew = self.tempreg(REGvar);
5910 5882
         }
@@ -5912,49 +5884,23 @@ class NewExpr : NewBaseExpr
5912 5884
         if (regnew == "")
5913 5885
             regnew = self.tempreg(REGvar);
5914 5886
 
5915  
-        switch (type) {
5916  
-          case BYNAME:
5917  
-            // By name, usually a pmc.
5918  
-            string name = value.rawstring();
5919  
-            var aux = get_class(name);
5920  
-            if (aux == null)
5921  
-                warn_class_unknown(e, name , value);
5922  
-
5923  
-            // Avoid using root_new here for a now.
5924  
-            //e.say("root_new ", regnew, ", ['parrot'; ", value, " ]", reginit);
5925  
-            e.say(INDENT, "new ", regnew, ", [ ", value, " ]", reginit);
5926  
-            if (numinits > 1) {
5927  
-                e.say(regnew, ".'", value, "'()");
5928  
-            }
5929  
-            break;
5930  
-          case BYIDENT:
5931  
-            var id = self.owner.getvar(value);
5932  
-            if (id == null) {
5933  
-                var cl = self.owner.checkclass(value);
5934  
-                if (cl != null) {
5935  
-                    var key = cl.getpath();
5936  
-                    key.emit_new(e, self, regnew, reginit);
5937  
-                }
5938  
-                else {
5939  
-                    id = self.scopesearch( [value], SEARCH_CLASS);
5940  
-                    if (id != null)
5941  
-                        e.say(INDENT, "new ", regnew, ", ", id.getclasskey(), reginit);
5942  
-                    else {
5943  
-                        warn_class_unknown(e, value.getidentifier(), value);
5944  
-                        e.say(INDENT, "new ", regnew, ", ['", value, "']", reginit);
5945  
-                    }
5946  
-                }
5947  
-                constructor = value;
5948  
-            }
  5887
+        var cl = self.owner.checkclass(value);
  5888
+        if (cl != null) {
  5889
+            var key = cl.getpath();
  5890
+            key.emit_new(e, self, regnew, reginit);
  5891
+        }
  5892
+        else {
  5893
+            var id = self.scopesearch( [value], SEARCH_CLASS);
  5894
+            if (id != null)
  5895
+                e.say(INDENT, "new ", regnew, ", ", id.getclasskey(), reginit);
5949 5896
             else {
5950  
-                //say("new with var");
5951  
-                e.say(INDENT, "new ", regnew, ", ", id.getreg(), "", reginit);
  5897
+                warn_class_unknown(e, value.getidentifier(), value);
  5898
+                e.say(INDENT, "new ", regnew, ", ['", value, "']", reginit);
5952 5899
             }
5953  
-            break;
5954  
-          default:
5955  
-            InternalError("Unexpected type in new");
5956 5900
         }
5957  
-        if (numinits > 1 || (numinits >= 0 && type == BYIDENT)) {
  5901
+        constructor = value;
  5902
+
  5903
+        if (numinits >= 0) {
5958 5904
             self.emit_constructor(e, regnew, constructor);
5959 5905
             if (! is_init)
5960 5906
                 e.emitset(result, regnew);
@@ -6050,16 +5996,11 @@ function parseNew(var tk, var owner, var start)
6050 5996
     var t = tk.get();
6051 5997
 
6052 5998
     switch {
6053  
-      case t.isop("("):
6054  
-        // Not a new operator, but a call to a function called new.
6055  
-        return new CallExpr(tk, owner, start,
6056  
-                new StringLiteral(owner, start));
6057 5999
       case t.isop("["):
6058 6000
         // Class specifier is a key
6059 6001
         return new NewIndexedExpr(tk, owner, start);
6060 6002
       case t.isidentifier():
6061  
-        // Special case here. It can be an id, a qualified id or
6062  
-        // a const string
  6003
+        // Special case here. It can be an id or a qualified id 
6063 6004
         var t2 = tk.get();
6064 6005
         tk.unget(t2);
6065 6006
         if (t2.isop(".")) {

0 notes on commit e355959

Please sign in to comment.
Something went wrong with that request. Please try again.