浏览代码

js -> eberon transition

Vladislav Folts 10 年之前
父节点
当前提交
8941eef429
共有 4 个文件被更改,包括 53 次插入48 次删除
  1. 二进制
      bin/compiled.zip
  2. 52 1
      src/eberon/EberonContextDesignator.ob
  3. 0 46
      src/eberon/eberon_context.js
  4. 1 1
      src/eberon/eberon_grammar.js

二进制
bin/compiled.zip


+ 52 - 1
src/eberon/EberonContextDesignator.ob

@@ -42,7 +42,14 @@ TYPE
     SelfAsPointer = RECORD(Types.Id)
     END;
 
-    OperatorNewMsg* = RECORD(ContextHierarchy.Message)
+    OperatorNew* = RECORD(ContextDesignator.QIdentHandler)
+        PROCEDURE handleExpression(e: Expression.PType);
+
+        info: TypeId.PType;
+        call: Procedure.PCallGenerator;
+    END;
+
+    OperatorNewMsg = RECORD(ContextHierarchy.Message)
         PROCEDURE OperatorNewMsg(e: Expression.PType);
 
         expression: Expression.PType;
@@ -362,6 +369,50 @@ PROCEDURE SelfAsPointer.idType(): STRING;
     RETURN "SELF(POINTER)";
 END;
 
+PROCEDURE OperatorNew.handleQIdent(q: ContextHierarchy.QIdent);
+BEGIN
+    found <- ContextHierarchy.getQIdSymbolAndScope(SELF.root()^, q);
+    s <- found.symbol();
+    info <- s.info();
+
+    IF ~(info IS TypeId.PType) THEN
+        Errors.raise("record type is expected in operator NEW, got '" + info.idType() + "'");
+    ELSE
+        type <- info.type();
+        IF ~(type IS Types.PRecord) THEN
+            Errors.raise("record type is expected in operator NEW, got '" + type.description() + "'");
+        END;
+        SELF.info := info;        
+    END;
+END;
+
+PROCEDURE OperatorNew.handleExpression(e: Expression.PType);
+BEGIN
+    SELF.call.handleArgument(e);
+END;    
+
+PROCEDURE OperatorNew.handleMessage(VAR msg: ContextHierarchy.Message): Object.PType;
+VAR
+    result: Object.PType;
+BEGIN
+    IF msg IS ContextDesignator.BeginCallMsg THEN
+        SELF.call := EberonConstructor.makeConstructorCall(
+            SELF.info, 
+            ContextHierarchy.makeLanguageContext(SELF(POINTER)), 
+            TRUE);
+    ELSIF msg IS ContextDesignator.EndCallMsg THEN
+    ELSE
+        result := SUPER(msg);
+    END;
+    RETURN result;
+END;
+
+PROCEDURE OperatorNew.endParse(): BOOLEAN;
+BEGIN
+    void <- SELF.handleMessage(NEW OperatorNewMsg(SELF.call.end())^);
+    RETURN TRUE;
+END;
+
 PROCEDURE OperatorNewMsg.OperatorNewMsg(e: Expression.PType)
     | expression(e);
 END;

+ 0 - 46
src/eberon/eberon_context.js

@@ -52,51 +52,6 @@ var ChainedContext = ContextHierarchy.Node;
 ChainedContext.extend = Class.extend;
 ChainedContext.prototype.init = ContextHierarchy.Node;
 
-function makeContextCall(context, call){
-    return call(ContextHierarchy.makeLanguageContext(context));
-    }
-
-var OperatorNew = ChainedContext.extend({
-    init: function EberonContext$OperatorNew(parent){
-        ChainedContext.prototype.init.call(this, parent);
-        this.__info = undefined;
-        this.__call = undefined;
-    },
-    handleQIdent: function(q){
-        var found = ContextHierarchy.getQIdSymbolAndScope(this.root(), q);
-        var s = found.symbol();
-        var info = s.info();
-
-        if (!(info instanceof TypeId.Type))
-            throw new Errors.Error("record type is expected in operator NEW, got '" + info.idType() + "'");
-
-        var type = info.type();
-        if (!(type instanceof Type.Record))
-            throw new Errors.Error("record type is expected in operator NEW, got '" + type.description() + "'");
-        
-        this.__info = info;        
-    },
-    handleExpression: function(e){
-        this.__call.handleArgument(e);
-    },
-    handleMessage: function(msg){
-        if (msg instanceof ContextDesignator.BeginCallMsg){
-            this.__call = makeContextCall(
-                this,
-                function(cx){ return EberonConstructor.makeConstructorCall(this.__info, cx, true); }.bind(this)
-                );
-            return;
-        }
-        if (msg instanceof ContextDesignator.EndCallMsg)
-            return;
-
-        return ChainedContext.prototype.handleMessage.call(this, msg);
-    },
-    endParse: function(){
-        this.handleMessage(new EberonContextDesignator.OperatorNewMsg(this.__call.end()));
-    }
-});
-
 var ExpressionProcedureCall = ChainedContext.extend({
     init: function EberonContext$init(context){
         ChainedContext.prototype.init.call(this, context);
@@ -392,6 +347,5 @@ exports.ModuleDeclaration = ModuleDeclaration;
 exports.AssignmentOrProcedureCall = AssignmentOrProcedureCall;
 exports.MapDecl = MapDecl;
 exports.Repeat = Repeat;
-exports.OperatorNew = OperatorNew;
 exports.VariableDeclaration = VariableDeclaration;
 exports.While = While;

+ 1 - 1
src/eberon/eberon_grammar.js

@@ -63,7 +63,7 @@ function makeIdentdef(ident){
 
 function makeDesignator(ident, qualident, selector, actualParameters){
     var self = and("SELF", optional(and("(", "POINTER", ")")));
-    var operatorNew = and("NEW", context(and(qualident, actualParameters), EbContext.OperatorNew));
+    var operatorNew = and("NEW", context(and(qualident, actualParameters), EberonContextDesignator.OperatorNew));
     var designator = context(
         and(or(self, "SUPER", operatorNew, qualident), 
             repeat(or(selector, actualParameters))), EberonContextDesignator.Type);