Browse Source

Merge branch 'master' of https://github.com/vladfolts/oberonjs

Vladislav Folts 11 years ago
parent
commit
eaf8d6cf4e
6 changed files with 57 additions and 5 deletions
  1. 2 0
      src/cast.js
  2. 6 3
      src/context.js
  3. 17 0
      test/expected/modules.js
  4. 11 0
      test/input/modules.ob
  5. 12 0
      test/input/run/modules.ob
  6. 9 2
      test/test_unit.js

+ 2 - 0
src/cast.js

@@ -28,6 +28,8 @@ function areTypesMatch(t1, t2){
         return true;
     if (Type.isInt(t1) && Type.isInt(t2))
         return true;
+    if (t1 instanceof ArrayType && t2 instanceof ArrayType)
+        return t1.length() === t2.length() && areTypesMatch(t1.elementsType(), t2.elementsType());
     if (t1 instanceof PointerType && t2 instanceof PointerType)
         return areTypesMatch(t1.baseType(), t2.baseType());
     if (t1 instanceof ProcedureType && t2 instanceof ProcedureType)

+ 6 - 3
src/context.js

@@ -1671,12 +1671,15 @@ exports.RecordDecl = ChainedContext.extend({
         var type = this.__type;
         var baseType = type.baseType();
         var gen = this.codeGenerator();
-        gen.write((baseType ? baseType.name() + ".extend" : this.rtl().extendId()) + "(");
+        var qualifiedBase = baseType ? this.qualifyScope(baseType.scope()) + baseType.name() : undefined; 
+        gen.write((baseType ? qualifiedBase + ".extend" 
+						    : this.rtl().extendId())
+			   + "(");
         gen.openScope();
         gen.write("init: function " + this.__type.cons() + "()");
         gen.openScope();
         if (baseType)
-            gen.write(baseType.name() + ".prototype.init.call(this);\n");
+            gen.write(qualifiedBase + ".prototype.init.call(this);\n");
         var ownFields = type.ownFields();
         for(var f in ownFields)
             gen.write("this." + f + " = " + ownFields[f].initializer(this) + ";\n");
@@ -1894,4 +1897,4 @@ exports.Context = Class.extend({
     }
 });
 
-exports.Chained = ChainedContext;
+exports.Chained = ChainedContext;

+ 17 - 0
test/expected/modules.js

@@ -101,9 +101,17 @@ return {
 }
 }();
 var m2 = function (m1){
+var T = m1.T.extend({
+	init: function T(){
+		m1.T.prototype.init.call(this);
+		this.i2 = 0;
+	}
+});
 var r = new m1.T();
+var r2 = new T();
 var pb = null;
 var ptr = null;
+var ptr2 = null;
 var ptrA = null;
 
 function p(i/*INTEGER*/){
@@ -114,6 +122,9 @@ function ref(i/*VAR INTEGER*/){
 ptr = new m1.T();
 pb = ptr;
 RTL$.typeGuard(pb, m1.T).i = 123;
+ptr2 = new T();
+ptr2.i = 1;
+ptr2.i2 = 2;
 ptrA = m1.makeTPA();
 m1.p();
 p(m1.i());
@@ -121,7 +132,13 @@ p(m1.ci);
 ref(RTL$.makeRef(m1.pr2(), "i"));
 }(m1);
 var m3 = function (m1, m2){
+var T = m2.T.extend({
+	init: function T(){
+		m2.T.prototype.init.call(this);
+	}
+});
 var r = new m2.T();
+var r2 = new T();
 var a = RTL$.makeArray(3, function(){return new m2.Base();});
 var ptr = null;
 var pb = null;

+ 11 - 0
test/input/modules.ob

@@ -36,10 +36,14 @@ END m1.
 MODULE m2;
 IMPORT m1;
 
+TYPE
+	T = RECORD(m1.T) i2: INTEGER END;
 VAR 
 	r: m1.T;
+	r2: T;
 	pb: POINTER TO m1.Base;
 	ptr: m1.TP;
+	ptr2: POINTER TO T;
 	ptrA: m1.TPA;
 
 PROCEDURE p(i: INTEGER);
@@ -53,6 +57,10 @@ BEGIN
 	pb := ptr;
 	pb(m1.TP).i := 123;
 
+	NEW(ptr2);
+	ptr2.i := 1;
+	ptr2.i2 := 2;
+
 	ptrA := m1.makeTPA();
 
 	m1.p();
@@ -63,8 +71,11 @@ END m2.
 
 MODULE m3;
 IMPORT m1 := m2, m2 := m1;
+TYPE
+	T = RECORD(m2.T) END;
 VAR 
     r: m2.T;
+	r2: T;
     a: ARRAY 3 OF m2.Base;
     ptr: m2.TP;
     pb: POINTER TO m2.Base;

+ 12 - 0
test/input/run/modules.ob

@@ -0,0 +1,12 @@
+MODULE m1;
+TYPE T1* = RECORD END;
+END m1.
+
+MODULE m2;
+IMPORT m1;
+TYPE T2* = RECORD(m1.T1) END;
+
+VAR v: T2;
+
+BEGIN
+END m2.

+ 9 - 2
test/test_unit.js

@@ -753,14 +753,18 @@ var testSuite = {
                 + "v3: PROCEDURE(i: INTEGER): ProcType1; v4: PROCEDURE(b: BOOLEAN): ProcType1;"
                 + "v5: PROCEDURE(p: ProcType1); v6: PROCEDURE(p: ProcType2);"
                 + "v7: ProcType3; v8: ProcType4; v8VAR: ProcType4VAR; v9: ProcType5; v10: ProcType6; v11: ProcType7;"
+                + "vProcCharArray: PROCEDURE (a: ARRAY OF CHAR);"
             + "PROCEDURE p1(): ProcType1; RETURN p1 END p1;"
+            + "PROCEDURE procCharArray(a: ARRAY OF CHAR); END procCharArray;"
+            + "PROCEDURE procIntArray(a: ARRAY OF INTEGER); END procIntArray;"
             ),
     pass("v1 := v2",
          "v5 := v6",
          "v7 := v8",
          "v7 := v9",
          "v8 := v9",
-         "v1 := p1"),
+         "v1 := p1",
+         "vProcCharArray := procCharArray"),
     fail(["p1 := v1", "cannot assign to procedure"],
          ["v3 := v1",
           "type mismatch: 'v3' is 'PROCEDURE(INTEGER): ProcType1' and cannot be assigned to 'ProcType1' expression"],
@@ -769,7 +773,10 @@ var testSuite = {
          ["v10 := NEW",
           "standard procedure NEW cannot be referenced"],
          ["v10 := v11", "type mismatch: 'v10' is 'ProcType6' and cannot be assigned to 'ProcType7' expression" ],
-         ["v8 := v8VAR", "type mismatch: 'v8' is 'ProcType4' and cannot be assigned to 'ProcType4VAR' expression" ])
+         ["v8 := v8VAR", "type mismatch: 'v8' is 'ProcType4' and cannot be assigned to 'ProcType4VAR' expression" ],
+         ["vProcCharArray := procIntArray",
+          "type mismatch: 'vProcCharArray' is 'PROCEDURE(ARRAY OF CHAR)' and cannot be assigned to 'PROCEDURE(ARRAY OF INTEGER)' expression"]
+         )
     ),
 "string assignment": testWithContext(
     context(Grammar.statement,