Browse Source

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

Conflicts:
	src/context.js
Vladislav Folts 11 years ago
parent
commit
8d1e3aa98e

+ 7 - 4
src/context.js

@@ -271,6 +271,11 @@ exports.Identdef = ChainedContext.extend({
     }
     }
 });
 });
 
 
+function castCode(type, context){
+    var baseType = type instanceof Type.Pointer ? Type.pointerBase(type) : type;
+    return context.qualifyScope(Type.recordScope(baseType)) + Type.recordConstructor(baseType);
+}
+
 exports.Designator = ChainedContext.extend({
 exports.Designator = ChainedContext.extend({
     init: function Context$Designator(context){
     init: function Context$Designator(context){
         ChainedContext.prototype.init.call(this, context);
         ChainedContext.prototype.init.call(this, context);
@@ -383,9 +388,7 @@ exports.Designator = ChainedContext.extend({
 
 
         checkTypeCast(this.__currentType, type, "invalid type cast");
         checkTypeCast(this.__currentType, type, "invalid type cast");
 
 
-        var baseType = type instanceof Type.Pointer ? Type.pointerBase(type) : type;
-        var castName = this.qualifyScope(Type.recordScope(baseType)) + Type.recordConstructor(baseType);
-        var code = this.rtl().typeGuard(this.__code, castName);
+        var code = this.rtl().typeGuard(this.__code, castCode(type, this));
         this.__code = code;
         this.__code = code;
 
 
         this.__currentType = type;
         this.__currentType = type;
@@ -1143,7 +1146,7 @@ exports.Expression = ChainedContext.extend({
 
 
             checkTypeCast(leftType, rightType, "invalid type test");
             checkTypeCast(leftType, rightType, "invalid type test");
 
 
-            code = leftCode + " instanceof " + rightCode;
+            code = leftCode + " instanceof " + castCode(rightType, this);
         }
         }
         else {
         else {
             leftExpression = promoteTypeInExpression(leftExpression, rightType);
             leftExpression = promoteTypeInExpression(leftExpression, rightType);

+ 1 - 1
src/procedure.js

@@ -566,7 +566,7 @@ exports.predefined = [
                    "; " +
                    "; " +
                    op.divInplace(x, op.pow2(y));
                    op.divInplace(x, op.pow2(y));
         }
         }
-        var name = "UNPACK";
+        var name = "UNPK";
         var proc = new Std(
         var proc = new Std(
             name,
             name,
             args,
             args,

+ 1 - 0
test/expected/is.js

@@ -39,6 +39,7 @@ pd2 = new Derived2();
 pb = pd2;
 pb = pd2;
 pd1 = pd2;
 pd1 = pd2;
 b = pb instanceof Derived1;
 b = pb instanceof Derived1;
+b = pb instanceof Derived1;
 b = pb instanceof Derived2;
 b = pb instanceof Derived2;
 b = pd1 instanceof Derived2;
 b = pd1 instanceof Derived2;
 }();
 }();

+ 0 - 0
test/expected/pack_unpack.js → test/expected/pack_unpk.js


+ 2 - 0
test/input/is.ob

@@ -3,6 +3,7 @@ MODULE m;
 TYPE
 TYPE
 	Base = RECORD END;
 	Base = RECORD END;
 	Derived1 = RECORD(Base) field1: INTEGER END;
 	Derived1 = RECORD(Base) field1: INTEGER END;
+	PDerived1 = POINTER TO Derived1;
 	Derived2 = RECORD(Derived1) field2: INTEGER END;
 	Derived2 = RECORD(Derived1) field2: INTEGER END;
 VAR
 VAR
 	pb: POINTER TO Base;
 	pb: POINTER TO Base;
@@ -14,6 +15,7 @@ BEGIN
     pb := pd2;
     pb := pd2;
     pd1 := pd2;
     pd1 := pd2;
     b := pb^ IS Derived1;
     b := pb^ IS Derived1;
+    b := pb IS PDerived1;
     b := pb^ IS Derived2;
     b := pb^ IS Derived2;
     b := pd1^ IS Derived2
     b := pd1^ IS Derived2
 END m.
 END m.

+ 2 - 2
test/input/pack_unpack.ob → test/input/pack_unpk.ob

@@ -5,10 +5,10 @@ VAR i: INTEGER; r: REAL;
 PROCEDURE p(VAR r: REAL; VAR i: INTEGER);
 PROCEDURE p(VAR r: REAL; VAR i: INTEGER);
 BEGIN
 BEGIN
     PACK(r, i);
     PACK(r, i);
-    UNPACK(r, i);
+    UNPK(r, i);
 END p;
 END p;
 
 
 BEGIN
 BEGIN
     PACK(r, i);
     PACK(r, i);
-    UNPACK(r, i);
+    UNPK(r, i);
 END m.
 END m.

+ 1 - 1
test/input/run/pack_unpack.ob → test/input/run/pack_unpk.ob

@@ -9,7 +9,7 @@ BEGIN
     ASSERT(r = 1.23 * FLT(LSL(1, i)));
     ASSERT(r = 1.23 * FLT(LSL(1, i)));
 
 
     i := 0;
     i := 0;
-    UNPACK(r, i);
+    UNPK(r, i);
     ASSERT(r = 1.23);
     ASSERT(r = 1.23);
     ASSERT(i = 7);
     ASSERT(i = 7);
 END m.
 END m.

+ 5 - 5
test/test_unit.js

@@ -435,12 +435,12 @@ return {
          "PACK(r, 3)"),
          "PACK(r, 3)"),
     fail(["PACK(r, r)", "type mismatch for argument 2: 'REAL' cannot be converted to 'INTEGER'"])
     fail(["PACK(r, r)", "type mismatch for argument 2: 'REAL' cannot be converted to 'INTEGER'"])
 ),
 ),
-"UNPACK": testWithContext(
+"UNPK": testWithContext(
     context(grammar.statement, "VAR r: REAL; i: INTEGER;"),
     context(grammar.statement, "VAR r: REAL; i: INTEGER;"),
-    pass("UNPACK(r, i)"),
-    fail(["UNPACK(r, r)", "type mismatch for argument 2: 'REAL' cannot be converted to 'INTEGER'"],
-         ["UNPACK(r, 3)", "expression cannot be used as VAR parameter"],
-         ["UNPACK(123.456, i)", "expression cannot be used as VAR parameter"]
+    pass("UNPK(r, i)"),
+    fail(["UNPK(r, r)", "type mismatch for argument 2: 'REAL' cannot be converted to 'INTEGER'"],
+         ["UNPK(r, 3)", "expression cannot be used as VAR parameter"],
+         ["UNPK(123.456, i)", "expression cannot be used as VAR parameter"]
          )
          )
 ),
 ),
 "standard procedure cannot be referenced" : testWithContext(
 "standard procedure cannot be referenced" : testWithContext(