Browse Source

Merge branch 'release'

Vladislav Folts 11 years ago
parent
commit
b230c38d0f
6 changed files with 44 additions and 6 deletions
  1. 2 1
      src/context.js
  2. 18 3
      src/module.js
  3. 2 2
      src/procedure.js
  4. 5 0
      test/expected/js_var.js
  5. 8 0
      test/input/js_var.ob
  6. 9 0
      test/test_unit.js

+ 2 - 1
src/context.js

@@ -1528,7 +1528,8 @@ exports.StatementProcedureCall = ProcedureCall.extend({
     endParse: function(){
         ProcedureCall.prototype.endParse.call(this);
         var e = this.callExpression();
-        if  (e.type())
+        var type = e.type();
+        if  (type && !(type instanceof Module.AnyType ))
             throw new Errors.Error("procedure returning a result cannot be used as a statement");
         this.parent().codeGenerator().write(e.code());
     }

+ 18 - 3
src/module.js

@@ -6,19 +6,29 @@ var Procedure = require("procedure.js");
 var Symbol = require("symbol.js");
 var Type = require("type.js");
 
+var AnyTypeProc = Type.Procedure.extend({
+    init: function AnyTypeProc(){
+        Type.Procedure.prototype.init.call("PROCEDURE: JS.var");
+    },
+    result: function(){return any;}
+});
+
+var anyProc = new AnyTypeProc();
+
 var AnyType = Type.Basic.extend({
     init: function AnyType(){
-        Type.Basic.prototype.init.call(this, "ANY");
+        Type.Basic.prototype.init.call(this, "JS.var");
     },
     findSymbol: function(){return this;},
     callGenerator: function(context, id){
-        return new Procedure.CallGenerator(context, id);
+        return new Procedure.CallGenerator(context, id, anyProc);
     }
 });
 
 var any = new AnyType();
 
 var doProcId = "do$";
+var varTypeId = "var$";
 
 var doProcSymbol = (function(){
     var description = "JS predefined procedure 'do'";
@@ -62,6 +72,10 @@ var doProcSymbol = (function(){
     return new Symbol.Symbol(doProcId, new ProcType());
 })();
 
+var varTypeSymbol = function(){
+    return new Symbol.Symbol(varTypeId, new Type.TypeId(any));
+}();
+
 var JSModule = Type.Module.extend({
     init: function Module$JSModule(){
         Type.Module.prototype.init.call(this);
@@ -70,7 +84,8 @@ var JSModule = Type.Module.extend({
     findSymbol: function(id){
         return new Symbol.Found(
             id == doProcId ? doProcSymbol
-                           : new Symbol.Symbol(id, any));
+          : id == varTypeId ? varTypeSymbol
+          : new Symbol.Symbol(id, any));
     }
 });
 

+ 2 - 2
src/procedure.js

@@ -42,7 +42,7 @@ var ProcCallGenerator = Class.extend({
         var pos = this.__argumentsCount++;
         var isVarArg = false;
         var convert;
-        if (this.__type){
+        if (this.__type.args){
             var expectedArguments = this.__type.args();
             if (pos >= expectedArguments.length )
                 // ignore, handle error after parsing all arguments
@@ -61,7 +61,7 @@ var ProcCallGenerator = Class.extend({
         this.writeCode(prefix + code);
     },
     end: function(){
-        if (this.__type)
+        if (this.__type.args)
             this.checkArgumentsCount(this.__argumentsCount);
         return this.callExpression();
     },

+ 5 - 0
test/expected/js_var.js

@@ -0,0 +1,5 @@
+var m = function (JS){
+var v = undefined;
+v = JS.Date();
+JS.console.info(v);
+}(this);

+ 8 - 0
test/input/js_var.ob

@@ -0,0 +1,8 @@
+MODULE m;
+IMPORT JS;
+VAR 
+	v: JS.var;
+BEGIN
+	v := JS.Date();
+	JS.console.info(v);
+END m.

+ 9 - 0
test/test_unit.js

@@ -1305,6 +1305,15 @@ var testSuite = {
           "string is expected as an argument of JS predefined procedure 'do', got ARRAY 10 OF CHAR"]
           )
     ),
+"JS.var": testWithGrammar(
+    Grammar.module,
+    pass("MODULE m; IMPORT JS; VAR v: JS.var; END m.",
+         "MODULE m; IMPORT JS; VAR v: JS.var; BEGIN v := JS.f(); END m.",
+         "MODULE m; IMPORT JS; VAR v: JS.var; BEGIN v := JS.f1(); JS.f2(v); END m."
+         ),
+    fail(["MODULE m; IMPORT JS; VAR v: JS.var; i: INTEGER; BEGIN i := v; END m.",
+          "type mismatch: 'i' is 'INTEGER' and cannot be assigned to 'JS.var' expression"])
+    ),
 "import unknown module": testWithGrammar(
     Grammar.module,
     pass(),