Browse Source

js -> eberon transition

Vladislav Folts 10 năm trước cách đây
mục cha
commit
f9e3a4a580

BIN
bin/compiled.zip


+ 1 - 1
build.py

@@ -130,7 +130,7 @@ def recompile(bin):
     sources = ['ContextAssignment.ob', 'ContextCase.ob', 'ContextConst.ob', 
                'ContextIdentdef.ob', 'ContextLoop.ob', 'ContextModule.ob', 'ContextProcedure.ob', 
                'ContextVar.ob', 'EberonSymbols.ob', 'EberonCast.ob', 
-               'EberonContextProcedure.ob', 'EberonContextType.ob', 'EberonOperator.ob', 'EberonScope.ob',
+               'EberonContextExpression.ob', 'EberonContextType.ob', 'EberonOperator.ob', 'EberonScope.ob',
                'OberonContext.ob', 'OberonContextType.ob', 'OberonContextVar.ob',
                'OberonSymbols.ob', 'Lexer.ob', 'Module.ob']
     

+ 4 - 4
src/eberon/EberonContextDesignator.ob

@@ -56,10 +56,10 @@ TYPE
     END;
 
     PromoteTypeMsg* = RECORD(ContextHierarchy.Message)
-        PROCEDURE PromoteTypeMsg(info: Types.PId; type: Types.PType);
+        PROCEDURE PromoteTypeMsg(info: EberonTypePromotion.PVariable; type: Types.PType);
 
-        info: Types.PId;
-        type: Types.PType;
+        info-: EberonTypePromotion.PVariable;
+        type-: Types.PType;
     END;
 
     TransferPromotedTypesMsg* = RECORD(ContextHierarchy.Message)
@@ -369,7 +369,7 @@ PROCEDURE OperatorNewMsg.OperatorNewMsg(e: Expression.PType)
     | expression(e);
 END;
 
-PROCEDURE PromoteTypeMsg.PromoteTypeMsg(info: Types.PId; type: Types.PType)
+PROCEDURE PromoteTypeMsg.PromoteTypeMsg(info: EberonTypePromotion.PVariable; type: Types.PType)
     | info(info),
       type(type);
 END;

+ 87 - 0
src/eberon/EberonContextExpression.ob

@@ -0,0 +1,87 @@
+MODULE EberonContextExpression;
+IMPORT
+    ContextExpression, ContextHierarchy, 
+    EberonContextDesignator, EberonContextProcedure, EberonTypePromotion, 
+    Object;
+TYPE
+    Term* = RECORD(ContextExpression.Term)
+        PROCEDURE getCurrentPromotion(): EberonTypePromotion.PMaybe;
+        PROCEDURE handleLogicalAnd();
+
+        typePromotion: EberonTypePromotion.PCombined;
+        currentPromotion: EberonTypePromotion.PMaybe;
+        andHandled: BOOLEAN;
+    END;
+
+    Factor* = RECORD(ContextExpression.Factor)
+    END;
+
+    BeginTypePromotionAndMsg* = RECORD(ContextHierarchy.Message)
+        result: EberonTypePromotion.PCombined;
+    END;
+
+    CurrentTypePromotionMsg = RECORD(ContextHierarchy.Message)
+        result: EberonTypePromotion.PMaybe;
+    END;
+
+PROCEDURE Term.handleMessage(VAR msg: ContextHierarchy.Message): Object.PType;
+VAR
+    result: Object.PType;
+BEGIN
+    IF msg IS EberonContextDesignator.PromoteTypeMsg THEN
+        promoted <- msg.info;
+        p <- SELF.getCurrentPromotion();
+        IF p # NIL THEN
+            p.promote(promoted, msg.type);
+        END;
+    ELSIF msg IS EberonContextProcedure.BeginTypePromotionOrMsg THEN
+        p <- SELF.getCurrentPromotion();
+        IF p # NIL THEN
+            msg.result := p.makeOr();
+        END;
+    ELSIF msg IS CurrentTypePromotionMsg THEN
+        msg.result := SELF.getCurrentPromotion();
+    ELSE
+        result := SUPER(msg);
+    END;
+    RETURN result;
+END;
+
+PROCEDURE Term.handleLogicalAnd();
+BEGIN
+    IF SELF.typePromotion # NIL THEN
+        SELF.currentPromotion := SELF.typePromotion.next();
+    ELSE
+        SELF.andHandled := TRUE;
+    END;
+END;
+
+PROCEDURE Term.getCurrentPromotion(): EberonTypePromotion.PMaybe;
+BEGIN
+    IF SELF.currentPromotion = NIL THEN
+        msg <- NEW BeginTypePromotionAndMsg();
+        void <- SELF.parent().handleMessage(msg^);
+        SELF.typePromotion := msg.result;
+        IF SELF.typePromotion # NIL THEN
+            IF SELF.andHandled THEN
+                unused <- SELF.typePromotion.next();
+            END;
+            SELF.currentPromotion := SELF.typePromotion.next();
+        END;
+    END;
+    RETURN SELF.currentPromotion;
+END;
+
+PROCEDURE Factor.handleLogicalNot();
+BEGIN
+    SUPER();
+
+    msg <- NEW CurrentTypePromotionMsg();
+    void <- SELF.handleMessage(msg^);
+    p <- msg.result;
+    IF p # NIL THEN
+        p.invert();
+    END;
+END;
+
+END EberonContextExpression.

+ 1 - 1
src/eberon/EberonContextProcedure.ob

@@ -42,7 +42,7 @@ TYPE
     END;
 
     BeginTypePromotionOrMsg* = RECORD(ContextHierarchy.Message)
-        result: EberonTypePromotion.PCombined;
+        result*: EberonTypePromotion.PCombined;
     END;
 
 PROCEDURE superMethodCallGenerator(cx: LanguageContext.PType; type: Procedure.Type): Procedure.PCallGenerator;

+ 6 - 6
src/eberon/EberonTypePromotion.ob

@@ -6,7 +6,7 @@ TYPE
         PROCEDURE type(): Types.PType;
         PROCEDURE setType(type: Types.PType);
     END;
-    PVariable = POINTER TO Variable;
+    PVariable* = POINTER TO Variable;
 
     Type = RECORD
         PROCEDURE and();
@@ -26,13 +26,13 @@ TYPE
     END;
 
     Operation = PROCEDURE(p: Type);
-    PMaybe = POINTER TO Maybe;
+    PMaybe* = POINTER TO Maybe;
 
     Combined* = RECORD(Type)
         PROCEDURE Combined(op, invertedOp: Operation; inverted: BOOLEAN);
 
         PROCEDURE clear*();
-        PROCEDURE next(): PMaybe;
+        PROCEDURE next*(): PMaybe;
 
         op, invertedOp: Operation;
         inverted: BOOLEAN;
@@ -53,9 +53,9 @@ TYPE
     Maybe = RECORD
         PROCEDURE Maybe(handler: PCombined);
 
-        PROCEDURE promote(v: PVariable; type: Types.PType);
-        PROCEDURE invert();
-        PROCEDURE makeOr(): PCombined;
+        PROCEDURE promote*(v: PVariable; type: Types.PType);
+        PROCEDURE invert*();
+        PROCEDURE makeOr*(): PCombined;
         PROCEDURE makeAnd(): PCombined;
 
         inverted: BOOLEAN;

+ 2 - 66
src/eberon/eberon_context.js

@@ -19,6 +19,7 @@ var ContextVar = require("js/ContextVar.js");
 var EberonConstructor = require("js/EberonConstructor.js");
 var EberonContext = require("js/EberonContext.js");
 var EberonContextDesignator = require("js/EberonContextDesignator.js");
+var EberonContextExpression = require("js/EberonContextExpression.js");
 var EberonContextProcedure = require("js/EberonContextProcedure.js");
 var EberonContextType = require("js/EberonContextType.js");
 var EberonDynamicArray = require("js/EberonDynamicArray.js");
@@ -314,21 +315,6 @@ var BaseInit = ChainedContext.extend({
     }
 });
 
-var Factor = Class.extend.call(ContextExpression.Factor, {
-    init: function EberonContext$Factor(context){
-        ContextExpression.Factor.call(this, context);
-    },
-    handleLogicalNot: function(){
-        ContextExpression.Factor.prototype.handleLogicalNot.call(this);
-        var p = this.getCurrentPromotion();
-        if (p)
-            p.invert();
-    },
-    getCurrentPromotion: function(){
-        return this.parent().getCurrentPromotion();
-    }
-});
-
 var AddOperator = Class.extend.call(ContextExpression.AddOperator, {
     init: function EberonContext$AddOperator(context){
         ContextExpression.AddOperator.call(this, context);
@@ -407,54 +393,6 @@ var RelationOps = Class.extend.call(ContextExpression.RelationOps, {
     }
 });
 
-function BeginTypePromotionAndMsg(){
-    this.result = undefined;
-}
-
-var Term = Class.extend.call(ContextExpression.Term, {
-    init: function EberonContext$Term(context){
-        ContextExpression.Term.call(this, context);
-        this.__typePromotion = undefined;
-        this.__currentPromotion = undefined;
-        this.__andHandled = false;
-    },
-    handleMessage: function(msg){
-        if (msg instanceof EberonContextDesignator.PromoteTypeMsg) {
-            var promoted = msg.info;
-            var p = this.getCurrentPromotion();
-            if (p)
-                p.promote(promoted, msg.type);
-            return;
-        }
-        if (msg instanceof EberonContextProcedure.BeginTypePromotionOrMsg){
-            var cp = this.getCurrentPromotion();
-            if (cp)
-                msg.result = cp.makeOr();
-            return;
-        }
-        return ContextExpression.Term.prototype.handleMessage.call(this, msg);
-    },
-    handleLogicalAnd: function(){
-        if (this.__typePromotion)
-            this.__currentPromotion = this.__typePromotion.next();
-        else
-            this.__andHandled = true;
-    },
-    getCurrentPromotion: function(){
-        if (!this.__currentPromotion){
-            var msg = new BeginTypePromotionAndMsg();
-            this.parent().handleMessage(msg);
-            this.__typePromotion = msg.result;
-            if (this.__typePromotion){
-                if (this.__andHandled)
-                    this.__typePromotion.next();
-                this.__currentPromotion = this.__typePromotion.next();
-            }
-        }
-        return this.__currentPromotion;
-    }
-});
-
 var SimpleExpression = Class.extend.call(ContextExpression.SimpleExpression, {
     init: function EberonContext$SimpleExpression(context){
         ContextExpression.SimpleExpression.call(this, context);
@@ -469,7 +407,7 @@ var SimpleExpression = Class.extend.call(ContextExpression.SimpleExpression, {
             this.__orHandled = true;
     },
     handleMessage: function(msg){
-        if (msg instanceof BeginTypePromotionAndMsg){
+        if (msg instanceof EberonContextExpression.BeginTypePromotionAndMsg){
             var p = this.__getCurrentPromotion();
             if (p)
                 msg.result = p.makeAnd();
@@ -898,13 +836,11 @@ exports.If = If;
 exports.ModuleDeclaration = ModuleDeclaration;
 exports.MulOperator = MulOperator;
 exports.AssignmentOrProcedureCall = AssignmentOrProcedureCall;
-exports.Factor = Factor;
 exports.MapDecl = MapDecl;
 exports.Repeat = Repeat;
 exports.SimpleExpression = SimpleExpression;
 exports.InPlaceVariableInit = InPlaceVariableInit;
 exports.InPlaceVariableInitFor = InPlaceVariableInitFor;
 exports.OperatorNew = OperatorNew;
-exports.Term = Term;
 exports.VariableDeclaration = VariableDeclaration;
 exports.While = While;

+ 3 - 2
src/eberon/eberon_grammar.js

@@ -6,6 +6,7 @@ var CodeGenerator = require("js/CodeGenerator.js");
 var ContextType = require("js/ContextType.js");
 var EbContext = require("eberon/eberon_context.js");
 var EberonContextDesignator = require("js/EberonContextDesignator.js");
+var EberonContextExpression = require("js/EberonContextExpression.js");
 var EberonContextProcedure = require("js/EberonContextProcedure.js");
 var EberonContextType = require("js/EberonContextType.js");
 var Grammar = require("grammar.js");
@@ -146,10 +147,10 @@ exports.language = {
             recordDecl:         EberonContextType.Record,
             variableDeclaration: EbContext.VariableDeclaration,
             ArrayDecl:          EbContext.ArrayDecl,
-            Factor:             EbContext.Factor,
+            Factor:             EberonContextExpression.Factor,
             FormalParameters:   EbContext.FormalParameters,
             FormalType:         EbContext.FormalType,
-            Term:               EbContext.Term,
+            Term:               EberonContextExpression.Term,
             AddOperator:        EbContext.AddOperator,
             MulOperator:        EbContext.MulOperator,
             SimpleExpression:   EbContext.SimpleExpression, 

+ 1 - 1
src/ob/ContextExpression.ob

@@ -61,7 +61,7 @@ TYPE
     PFactor = POINTER TO Factor;
 
     Factor* = RECORD(ExpressionHandler)
-        PROCEDURE handleLogicalNot();
+        PROCEDURE handleLogicalNot*();
 
         expression: Expression.PType;
         logicalNot: BOOLEAN;