2
0
Эх сурвалжийг харах

Merge pull request #32 from vladfolts/release

merge from release
vladfolts 11 жил өмнө
parent
commit
6a11844edd

BIN
doc/Oberon07.Report.pdf


+ 20 - 58
src/procedure.js

@@ -188,17 +188,22 @@ var TwoArgToOperatorProcCallGenerator = ExpCallGenerator.extend({
     }
 });
 
-function setBitImpl(name, op){
+function setBitImpl(name, bitOp){
     var args = [new Arg(Type.basic.set, true),
                 new Arg(Type.basic.integer, false)];
     function operator(x, y){
         var value = y.constValue();
-        if (value === undefined || value < 0 || value > 31)
-            throw new Errors.Error("constant (0..31) expected as second argument of " + name);
-        var comment = "bit: " + (y.isTerm() ? value : Code.adjustPrecedence(y, precedence.shift));
-        value = 1 << value;
-        var valueCode = value + "/*" + comment + "*/";
-        return op(Code.adjustPrecedence(x, precedence.assignment), valueCode);
+        var valueCode;
+        if (value === undefined)
+            valueCode = op.lsl(new Code.Expression("1"), y).code();
+        else {
+            if (value < 0 || value > 31)
+                throw new Errors.Error("value (0..31) expected as a second argument of " + name + ", got " + value);
+            var comment = "bit: " + (y.isTerm() ? value : Code.adjustPrecedence(y, precedence.shift));
+            value = 1 << value;
+            valueCode = value + "/*" + comment + "*/";
+        }
+        return bitOp(Code.adjustPrecedence(x, precedence.assignment), valueCode);
     }
     var proc = new Std(
         name,
@@ -220,10 +225,13 @@ function incImpl(name, unary, op){
             return unary + x.code();
 
         var value = y.constValue();
+        var valueCode;
         if (value === undefined)
-            throw new Errors.Error("constant expected as second argument of " + name);
-        var comment = y.isTerm() ? "" : "/*" + y.code() + "*/";
-        var valueCode = value + comment;
+            valueCode = y.code();
+        else {
+            var comment = y.isTerm() ? "" : "/*" + y.code() + "*/";
+            valueCode = value + comment;
+        }
         return op(x.code(), valueCode);
     }
     var CallGenerator = TwoArgToOperatorProcCallGenerator.extend({
@@ -270,25 +278,6 @@ function bitShiftImpl(name, op){
     return symbol;
 }
 
-function longShort(name){
-    var CallGenerator = ExpCallGenerator.extend({
-        init: function LongShortCallGenerator(context, id, type){
-            ExpCallGenerator.prototype.init.call(this, context, id, type);
-        },
-        callExpression: function(){return this.args()[0];}
-    });
-    var args = [new Arg(Type.basic.real, false)];
-    var proc = new Std(
-        name,
-        args,
-        Type.basic.real,
-        function(context, id, type){
-            return new CallGenerator(context, id, type);
-        });
-    var symbol = new Symbol.Symbol(name, proc);
-    return symbol;
-}
-
 function checkVariableArgumentsCount(min, max, actual){
     if (actual < min)
         throw new Errors.Error("at least " + min + " argument expected, got " + actual);
@@ -393,13 +382,10 @@ exports.predefined = [
             init: function AssertProcCallGenerator(context, id, type){
                 ProcCallGenerator.prototype.init.call(this, context, id, type);
             },
-            prolog: function(){return this.context().rtl().assertId() + "(";},
-            checkArgumentsCount: function(count){
-                checkVariableArgumentsCount(1, 2, count);
-            }
+            prolog: function(){return this.context().rtl().assertId() + "(";}
         });
 
-        var args = [new Arg(Type.basic.bool), new Arg(Type.basic.integer)];
+        var args = [new Arg(Type.basic.bool)];
         var proc = new Std(
             "ASSERT",
             args,
@@ -481,8 +467,6 @@ exports.predefined = [
         var symbol = new Symbol.Symbol("FLT", proc);
         return symbol;
     }(),
-    longShort("LONG"),
-    longShort("SHORT"),
     bitShiftImpl("LSL", op.lsl),
     bitShiftImpl("ASR", op.asr),
     bitShiftImpl("ROR", op.ror),
@@ -555,28 +539,6 @@ exports.predefined = [
         var symbol = new Symbol.Symbol(name, type);
         return symbol;
     }(),
-    function(){
-        var CallGenerator = ExpCallGenerator.extend({
-            init: function CopyProcCallGenerator(context, id, type){
-                ExpCallGenerator.prototype.init.call(this, context, id, type);
-            },
-            callExpression: function(){
-                var args = this.args();
-                return new Code.Expression(op.assign(args[1], args[0], this.context()));
-            }
-        });
-        var name = "COPY";
-        var type = new Std(
-            name,
-            [new Arg(undefined, false),
-             new Arg(new Type.Array("ARRAY OF CHAR", undefined, Type.basic.ch), true)],
-            undefined,
-            function(context, id, type){
-                return new CallGenerator(context, id, type);
-            });
-        var symbol = new Symbol.Symbol(name, type);
-        return symbol;
-    }(),
     function(){
         var args = [new Arg(Type.basic.real, true),
                     new Arg(Type.basic.integer, false)];

+ 0 - 1
src/scope.js

@@ -12,7 +12,6 @@ var stdSymbols = function(){
         var type = Type.basic[t];
         symbols[type.name()] = new Symbol.Symbol(type.name(), new Type.TypeId(type));
     }
-    symbols["LONGREAL"] = new Symbol.Symbol("LONGREAL", new Type.TypeId(Type.basic.real));
     
     var predefined = Procedure.predefined;
     for(var i = 0; i < predefined.length; ++i){

+ 0 - 1
test/expected/assert.js

@@ -7,5 +7,4 @@ var RTL$ = {
 };
 var m = function (){
 RTL$.assert(true);
-RTL$.assert(true, 123);
 }();

+ 2 - 0
test/expected/inc_dec.js

@@ -6,9 +6,11 @@ i += 2;
 i += 15/*3 * 5 | 0*/;
 i += 10/*ic*/;
 i += -2147483648/*2147483647 + 1 | 0*/;
+i += i + 1 | 0;
 --i;
 i -= 2;
 i -= 15/*3 * 5 | 0*/;
 i -= 10/*ic*/;
 i -= -2/*4294967295 * 2 | 0*/;
+i -= i * 2 | 0;
 }();

+ 0 - 8
test/expected/long_short.js

@@ -1,8 +0,0 @@
-var m = function (){
-var r = 0;
-var lr = 0;
-r = lr;
-lr = r;
-r = 1.23;
-lr = 1.23;
-}();

+ 2 - 0
test/expected/set.js

@@ -97,8 +97,10 @@ s1 = ~s2;
 s2 |= 8/*bit: 3*/;
 s1 |= 512/*bit: ((ci * 2 | 0) + 3 | 0)*/;
 s1 |= 2/*bit: (cb ? 1 : 0)*/;
+s2 |= 1 << i1;
 aSet[0] |= 8/*bit: 3*/;
 s2 &= ~(8/*bit: 3*/);
 s2 &= ~(1/*bit: (!cb ? 1 : 0)*/);
+s2 &= ~(1 << i1);
 aSet[0] &= ~(8/*bit: 3*/);
 }();

+ 0 - 1
test/input/assert.ob

@@ -2,5 +2,4 @@ MODULE m;
 
 BEGIN
     ASSERT(TRUE);
-    ASSERT(TRUE, 123)
 END m.

+ 1 - 1
test/input/blur.ob

@@ -16,7 +16,7 @@ MODULE Blur;
 
   VAR
     a, b:  Plane;
-    time: LONGREAL;
+    time: REAL;
 
   PROCEDURE Blur2DArray*;
   VAR

+ 0 - 13
test/input/copy.ob

@@ -1,13 +0,0 @@
-MODULE m;
-
-CONST
-	s1 = 22X;
-	s2 = "ABC";
-VAR
-	ac3: ARRAY 3 OF CHAR;
-
-BEGIN
-    COPY(s1, ac3);
-    COPY(s2, ac3);
-    COPY(ac3, ac3);
-END m.

+ 2 - 0
test/input/inc_dec.ob

@@ -9,10 +9,12 @@ BEGIN
 	INC(i, 3 * 5);
 	INC(i, ic);
 	INC(i, 07FFFFFFFH + 1 );
+	INC(i, i + 1);
 
 	DEC(i);
 	DEC(i, 2);
 	DEC(i, 3 * 5);
 	DEC(i, ic);
 	DEC(i, 0FFFFFFFFH * 2);
+	DEC(i, i * 2);
 END m.

+ 0 - 10
test/input/long_short.ob

@@ -1,10 +0,0 @@
-MODULE m;
-
-VAR r: REAL; lr: LONGREAL;
-
-BEGIN
-    r := SHORT(lr);
-    lr := LONG(r);
-    r := SHORT(1.23);
-    lr := LONG(1.23);
-END m.

+ 2 - 0
test/input/set.ob

@@ -57,9 +57,11 @@ BEGIN
 	INCL(s2, 3);
 	INCL(s1, ci * 2 + 3);
 	INCL(s1, ORD(cb));
+	INCL(s2, i1);
 	INCL(aSet[0], 3);
 
 	EXCL(s2, 3);
 	EXCL(s2, ORD(~cb));
+	EXCL(s2, i1);
 	EXCL(aSet[0], 3);
 END m.

+ 12 - 36
test/test_unit.js

@@ -556,20 +556,6 @@ var testSuite = {
          ["i := FLT(i, i)", "1 argument(s) expected, got 2"]
          )
     ),
-"LONG": testWithContext(
-    context(Grammar.statement, "VAR i: INTEGER; r: REAL; lr: LONGREAL;"),
-    pass("lr := LONG(r)"),
-    fail(["lr := LONG(i)", "type mismatch for argument 1: 'INTEGER' cannot be converted to 'REAL'"],
-         ["lr := LONG(r, r)", "1 argument(s) expected, got 2"]
-         )
-    ),
-"SHORT": testWithContext(
-    context(Grammar.statement, "VAR i: INTEGER; r: REAL; lr: LONGREAL;"),
-    pass("r := SHORT(lr)"),
-    fail(["r := SHORT(i)", "type mismatch for argument 1: 'INTEGER' cannot be converted to 'REAL'"],
-         ["r := SHORT(lr, lr)", "1 argument(s) expected, got 2"]
-         )
-    ),
 "LSL": testWithContext(
     context(Grammar.statement,
             "VAR i: INTEGER; r: REAL; c: CHAR;"),
@@ -628,9 +614,9 @@ var testSuite = {
 "INC": testWithContext(
     context(Grammar.statement, "VAR i: INTEGER;"),
     pass("INC(i)",
-         "INC(i, 3)"),
+         "INC(i, 3)",
+         "INC(i, i)"),
     fail(["INC(i + i)", "expression cannot be used as VAR parameter"],
-         ["INC(i, i)", "constant expected as second argument of INC"],
          ["INC()", "at least 1 argument expected, got 0"],
          ["INC(i, 1, 2)", "at most 2 arguments expected, got 3"]
          )
@@ -638,23 +624,13 @@ var testSuite = {
 "DEC": testWithContext(
     context(Grammar.statement, "VAR i: INTEGER;"),
     pass("DEC(i)",
-         "DEC(i, 3)"),
+         "DEC(i, 3)",
+         "DEC(i, i)"),
     fail(["DEC(i + i)", "expression cannot be used as VAR parameter"],
-         ["DEC(i, i)", "constant expected as second argument of DEC"],
          ["DEC()", "at least 1 argument expected, got 0"],
          ["DEC(i, 1, 2)", "at most 2 arguments expected, got 3"]
          )
 ),
-"COPY": testWithContext(
-    context(Grammar.statement, "VAR ac3: ARRAY 3 OF CHAR; ac4: ARRAY 4 OF CHAR;"),
-    pass("COPY(\"abc\", ac3)",
-         "COPY(ac3, ac3)"
-        ),
-    fail(["COPY(ac3, \"abc\")", "expression cannot be used as VAR parameter"],
-         ["COPY(\"abcd\", ac3)", "3-character ARRAY is too small for 4-character string"],
-         ["COPY(ac3, ac4)", "type mismatch: 'ac4' is 'ARRAY 4 OF CHAR' and cannot be assigned to 'ARRAY 3 OF CHAR' expression"]
-         )
-),
 "PACK": testWithContext(
     context(Grammar.statement, "VAR r: REAL; i: INTEGER;"),
     pass("PACK(r, i)",
@@ -945,12 +921,12 @@ var testSuite = {
     context(Grammar.statement,
             "VAR set1, set2: SET; b: BOOLEAN; i: INTEGER;"),
     pass("INCL(set1, 0)",
-         "EXCL(set1, 3)"),
+         "EXCL(set1, 3)",
+         "INCL(set1, i)",
+         "EXCL(set1, i)"),
     fail(["INCL({}, i)", "expression cannot be used as VAR parameter"],
-         ["INCL(set1, i)", "constant (0..31) expected as second argument of INCL"],
-         ["EXCL(set1, i)", "constant (0..31) expected as second argument of EXCL"],
-         ["INCL(set1, 32)", "constant (0..31) expected as second argument of INCL"],
-         ["EXCL(set1, -1)", "constant (0..31) expected as second argument of EXCL"]
+         ["INCL(set1, 32)", "value (0..31) expected as a second argument of INCL, got 32"],
+         ["EXCL(set1, -1)", "value (0..31) expected as a second argument of EXCL, got -1"]
         )
     ),
 "procedure body": testWithGrammar(
@@ -1293,9 +1269,9 @@ var testSuite = {
     ),
 "assert": testWithGrammar(
     Grammar.statement,
-    pass("ASSERT(TRUE)",
-         "ASSERT(TRUE, 123)"),
-    fail(["ASSERT()", "at least 1 argument expected, got 0"],
+    pass("ASSERT(TRUE)"),
+    fail(["ASSERT()", "1 argument(s) expected, got 0"],
+         ["ASSERT(TRUE, 123)", "1 argument(s) expected, got 2"],
          ["ASSERT(123, TRUE)", "type mismatch for argument 1: 'INTEGER' cannot be converted to 'BOOLEAN'"])
     ),
 "export": testWithGrammar(