Procházet zdrojové kódy

js -> eberon transition

Vladislav Folts před 9 roky
rodič
revize
12076b17ca

binární
bin/compiled.zip


+ 66 - 3
src/eberon/EberonContextDesignator.ob

@@ -1,8 +1,9 @@
 MODULE EberonContextDesignator;
 IMPORT
-    ContextDesignator, ContextHierarchy, ContextProcedure,
+    CodeGenerator,
+    ContextDesignator, ContextExpression, ContextHierarchy, ContextProcedure,
     EberonConstructor, EberonMap, EberonRtl, EberonString, EberonTypePromotion,
-    Errors, Expression, Object, Procedure, Record, TypeId, Types, Variable;
+    Errors, Expression, Module, Object, Operator, Procedure, Record, TypeId, Types, Variable;
 TYPE
     Type* = RECORD(ContextDesignator.Type)
         procCall: Procedure.PCallGenerator;
@@ -17,7 +18,7 @@ TYPE
         code: STRING;
     END;
 
-    ResultVariable* = RECORD(Types.Variable)
+    ResultVariable = RECORD(Types.Variable)
         PROCEDURE ResultVariable(e: Expression.PType);
 
         expression: Expression.PType;
@@ -42,6 +43,14 @@ TYPE
     SelfAsPointer = RECORD(Types.Id)
     END;
 
+    ExpressionProcedureCall* = RECORD(ContextHierarchy.Node)
+        PROCEDURE ExpressionProcedureCall(parent: ContextHierarchy.PNode);
+    END;
+
+    AssignmentOrProcedureCall* = RECORD(ContextExpression.ExpressionHandler)
+        right: Expression.PType;
+    END;
+
     OperatorNew* = RECORD(ContextDesignator.QIdentHandler)
         PROCEDURE handleExpression(e: Expression.PType);
 
@@ -369,6 +378,60 @@ PROCEDURE SelfAsPointer.idType(): STRING;
     RETURN "SELF(POINTER)";
 END;
 
+PROCEDURE ExpressionProcedureCall.ExpressionProcedureCall(parent: ContextHierarchy.PNode)
+    | SUPER(parent);
+BEGIN
+    NEW(SELF.attributes);
+END;
+
+PROCEDURE ExpressionProcedureCall.endParse(): BOOLEAN;
+VAR
+    e: Expression.PType;
+BEGIN
+    d <- SELF.attributes.designator;
+    info <- d.info();
+    IF info^ IS ResultVariable THEN
+        e := info.expression;
+        e := NEW Expression.Type(d.code(), d.type(), NIL, e.constValue(), e.maxPrecedence());
+    ELSE
+        e := ContextExpression.designatorAsExpression(d);
+    END;
+    SELF.parent()^(ContextExpression.ExpressionHandler).handleExpression(e);
+    RETURN TRUE;
+END;
+
+PROCEDURE AssignmentOrProcedureCall.handleExpression(e: Expression.PType);
+BEGIN
+    SELF.right := e;
+END;
+
+PROCEDURE AssignmentOrProcedureCall.codeGenerator(): CodeGenerator.PIGenerator;
+    RETURN CodeGenerator.nullGenerator;
+END;
+
+PROCEDURE AssignmentOrProcedureCall.endParse(): BOOLEAN;
+VAR
+    code: STRING;
+BEGIN
+    d <- SELF.attributes.designator;
+    type <- d.type();
+    IF SELF.right # NIL THEN
+        left <- Expression.make(d.code(), type, d, NIL);
+        code := Operator.assign(left, SELF.right, ContextHierarchy.makeLanguageContext(SELF(POINTER)));
+    ELSIF ~(d.info()^ IS ResultVariable) THEN
+        procCall <- ContextProcedure.makeCall(SELF(POINTER), type, d.info());
+        result <- procCall.end();
+        Module.assertProcStatementResult(result.type());
+        code := d.code() + result.code();
+    ELSE
+        Module.assertProcStatementResult(type);
+        code := d.code();
+    END;
+
+    SELF.parent().codeGenerator().write(code);
+    RETURN TRUE;
+END;
+
 PROCEDURE OperatorNew.handleQIdent(q: ContextHierarchy.QIdent);
 BEGIN
     found <- ContextHierarchy.getQIdSymbolAndScope(SELF.root()^, q);

+ 0 - 55
src/eberon/eberon_context.js

@@ -52,59 +52,6 @@ var ChainedContext = ContextHierarchy.Node;
 ChainedContext.extend = Class.extend;
 ChainedContext.prototype.init = ContextHierarchy.Node;
 
-var ExpressionProcedureCall = ChainedContext.extend({
-    init: function EberonContext$init(context){
-        ChainedContext.prototype.init.call(this, context);
-        this.attributes = {};
-    },
-    endParse: function(){
-        var parent = this.parent();
-        var d = this.attributes.designator;
-        var info = d.info();
-        var e;
-        if (info instanceof EberonContextDesignator.ResultVariable){
-            e = info.expression;
-            e = new Expression.Type(d.code(), d.type(), undefined, e.constValue(), e.maxPrecedence());
-        }
-        else
-            e = ContextExpression.designatorAsExpression(d);
-        parent.handleExpression(e);
-    }
-});
-
-var AssignmentOrProcedureCall = ChainedContext.extend({
-    init: function EberonContext$init(context){
-        ChainedContext.prototype.init.call(this, context);
-        this.attributes = {};
-        this.__right = undefined;
-    },
-    handleExpression: function(e){
-        this.__right = e;
-    },
-    codeGenerator: function(){return CodeGenerator.nullGenerator();},
-    endParse: function(){
-        var d = this.attributes.designator;
-        var type = d.type();
-        var code;
-        if (this.__right){
-            var left = Expression.make(d.code(), type, d);
-            code = op.assign(left, this.__right, ContextHierarchy.makeLanguageContext(this));
-        }
-        else if (!(d.info() instanceof EberonContextDesignator.ResultVariable)){
-            var procCall = ContextProcedure.makeCall(this, type, d.info());
-            var result = procCall.end();
-            Module.assertProcStatementResult(result.type());
-            code = d.code() + result.code();
-        }
-        else{
-            Module.assertProcStatementResult(type);
-            code = d.code();
-        }
-    
-    this.parent().codeGenerator().write(code);
-    }
-});
-
 var ConstDecl = Class.extend.call(ContextConst.Type, {
     init: function EberonContext$ConstDecl(context){
         ContextConst.Type.call(this, context);
@@ -337,14 +284,12 @@ var ModuleDeclaration = Class.extend.call(ContextModule.Declaration, {
 
 exports.CaseLabel = CaseLabel;
 exports.ConstDecl = ConstDecl;
-exports.ExpressionProcedureCall = ExpressionProcedureCall;
 exports.For = For;
 exports.FormalParameters = FormalParameters;
 exports.FormalParametersProcDecl = FormalParametersProcDecl;
 exports.FormalType = FormalType;
 exports.If = If;
 exports.ModuleDeclaration = ModuleDeclaration;
-exports.AssignmentOrProcedureCall = AssignmentOrProcedureCall;
 exports.MapDecl = MapDecl;
 exports.Repeat = Repeat;
 exports.VariableDeclaration = VariableDeclaration;

+ 2 - 2
src/eberon/eberon_grammar.js

@@ -53,7 +53,7 @@ function makeInPlaceInit(ident, expression, inPlaceContext){
 function makeAssignmentOrProcedureCall(ident, designator, assignment, expression){
     return or(
         makeInPlaceInit(ident, expression, EberonContextInPlace.VariableInit),
-        context(and(designator, optional(assignment)), EbContext.AssignmentOrProcedureCall)
+        context(and(designator, optional(assignment)), EberonContextDesignator.AssignmentOrProcedureCall)
         );
 }
 
@@ -68,7 +68,7 @@ function makeDesignator(ident, qualident, selector, actualParameters){
         and(or(self, "SUPER", operatorNew, qualident), 
             repeat(or(selector, actualParameters))), EberonContextDesignator.Type);
     return { 
-        factor: context(designator, EbContext.ExpressionProcedureCall),
+        factor: context(designator, EberonContextDesignator.ExpressionProcedureCall),
         assignmentOrProcedureCall: function(assignment, expression){
             return makeAssignmentOrProcedureCall(ident, designator, assignment, expression);
         }