浏览代码

js -> eberon transition

Vladislav Folts 10 年之前
父节点
当前提交
e030f3467f
共有 6 个文件被更改,包括 31 次插入24 次删除
  1. 二进制
      bin/compiled.zip
  2. 1 20
      src/context.js
  3. 1 1
      src/eberon/eberon_context.js
  4. 26 1
      src/ob/ContextExpression.ob
  5. 1 1
      src/ob/Designator.ob
  6. 2 1
      src/oberon/oberon_context.js

二进制
bin/compiled.zip


+ 1 - 20
src/context.js

@@ -442,24 +442,6 @@ exports.ArrayDimensions = ChainedContext.extend({
     }
 });
 
-function designatorAsExpression(d){
-    var info = d.info();
-
-    if (info instanceof Type.ProcedureId){
-        var proc = info.type;
-        if (proc instanceof Procedure.Std)
-            throw new Errors.Error(proc.description() + " cannot be referenced");
-        var scope = d.scope();
-        if (scope instanceof Scope.Procedure)
-            throw new Errors.Error("local procedure '" + d.code() + "' cannot be referenced");
-    }
-
-    var value;
-    if (info instanceof Type.Const)
-        value = info.value;
-    return Expression.make(d.code(), d.type(), d, value);
-}
-
 exports.Set = ChainedContext.extend({
     init: function SetContext(context){
         ChainedContext.prototype.init.call(this, context);
@@ -788,7 +770,7 @@ exports.For = ChainedContext.extend({
             if (type != basicTypes.integer)
                 throw new Errors.Error("'INTEGER' expression expected as 'BY' parameter, got '" + type.description() + "'");
             var value = e.constValue();
-            if ( value === undefined )
+            if (!value)
                 throw new Errors.Error("constant expression expected as 'BY' parameter");
             this.__by = value.value;
         }
@@ -1258,7 +1240,6 @@ exports.assertProcStatementResult = assertProcStatementResult;
 exports.beginCallMsg = beginCallMsg;
 exports.endCallMsg = endCallMsg;
 exports.Chained = ChainedContext;
-exports.designatorAsExpression = designatorAsExpression;
 exports.endParametersMsg = endParametersMsg;
 exports.makeProcCall = makeProcCall;
 exports.HandleSymbolAsType = HandleSymbolAsType;

+ 1 - 1
src/eberon/eberon_context.js

@@ -460,7 +460,7 @@ var ExpressionProcedureCall = Context.Chained.extend({
             e = new Expression.Type(d.code(), d.type(), undefined, e.constValue(), e.maxPrecedence());
         }
         else
-            e = Context.designatorAsExpression(d);
+            e = ContextExpression.designatorAsExpression(d);
         parent.handleExpression(e);
     }
 });

+ 26 - 1
src/ob/ContextExpression.ob

@@ -1,6 +1,8 @@
 MODULE ContextExpression;
 IMPORT 
-    Cast, Chars, CodeGenerator, ConstValue, Context, ContextHierarchy, Errors, Expression, JS, LanguageContext, Operator, Record, String, TypeId, Types;
+    Cast, Chars, CodeGenerator, ConstValue, Context, ContextHierarchy, 
+    Designator, Errors, Expression, JS, LanguageContext, Operator, 
+    Procedure, Record, Scope, String, TypeId, Types;
 TYPE
     ExpressionHandler = RECORD(ContextHierarchy.Node)
         PROCEDURE handleExpression(e: Expression.PType);
@@ -930,6 +932,29 @@ PROCEDURE NumericOrSetOpTypeCheck.check(t: Types.PType): BOOLEAN;
     RETURN SUPER(t) OR (t = Types.basic.set);
 END;
 
+PROCEDURE designatorAsExpression*(d: Designator.PType): Expression.PType;
+VAR
+    value: ConstValue.PType;
+BEGIN
+    info <- d.info();
+
+    IF info IS Types.PProcedureId THEN
+        proc <- info.type;
+        IF proc^ IS Procedure.Std THEN
+            Errors.raise(proc.description() + " cannot be referenced");
+        END;
+        scope <- d.scope();
+        IF scope^ IS Scope.Procedure THEN
+            Errors.raise("local procedure '" + d.code() + "' cannot be referenced");
+        END;
+    END;
+
+    IF info IS Types.PConst THEN
+        value := info.value;
+    END;
+    RETURN Expression.make(d.code(), d.type(), d, value);
+END;
+
 BEGIN
     NEW(relationOps);
 END ContextExpression.

+ 1 - 1
src/ob/Designator.ob

@@ -9,7 +9,7 @@ TYPE
         PROCEDURE lval*(): STRING;
         PROCEDURE type*(): Types.PType;
         PROCEDURE info*(): Types.PId;
-        PROCEDURE scope(): ScopeBase.PType;
+        PROCEDURE scope*(): ScopeBase.PType;
 
         mCode: STRING;
         mLval: STRING;

+ 2 - 1
src/oberon/oberon_context.js

@@ -2,6 +2,7 @@
 
 var CodeGenerator = require("js/CodeGenerator.js");
 var Context = require("context.js");
+var ContextExpression = require("js/ContextExpression.js");
 var Errors = require("js/Errors.js");
 var Expression = require("js/Expression.js");
 var op = require("js/Operator.js");
@@ -89,7 +90,7 @@ var ExpressionProcedureCall = ProcedureCall.extend({
     endParse: function(){
         var e = this.__hasActualParameters 
               ? this.callExpression()
-              : Context.designatorAsExpression(this.attributes.designator); 
+              : ContextExpression.designatorAsExpression(this.attributes.designator); 
         this.parent().handleExpression(e);
     }
 });