Browse Source

js -> eberon transition

Vladislav Folts 9 years ago
parent
commit
cf1501c0f9

BIN
bin/compiled.zip


+ 5 - 3
build.py

@@ -127,10 +127,12 @@ def run_tests(bin, unit_test=None, code_test=None):
 def recompile(bin):
     print('recompile oberon sources using "%s"...' % bin)
     compiler = os.path.join(root, 'src', 'oc_nodejs.js')
-    sources = ['ContextAssignment.ob', 'ContextCase.ob', 'ContextConst.ob', 
-               'ContextIdentdef.ob', 'ContextLoop.ob', 'ContextModule.ob', 'ContextProcedure.ob', 
+    sources = ['ContextAssignment.ob', 'ContextCase.ob', 
+               'ContextIdentdef.ob', 'ContextModule.ob', 
                'EberonSymbols.ob', 'EberonCast.ob', 
-               'EberonContextExpression.ob', 'EberonContextIdentdef.ob', 'EberonContextInPlace.ob', 'EberonContextLoop.ob', 'EberonContextType.ob', 'EberonContextVar.ob', 'EberonOperatorScopes.ob',
+               'EberonContextExpression.ob', 'EberonContextIdentdef.ob', 'EberonContextIf.ob', 
+               'EberonContextInPlace.ob', 'EberonContextLoop.ob', 'EberonContextType.ob', 
+               'EberonContextVar.ob', 'EberonOperatorScopes.ob',
                'OberonContext.ob', 'OberonContextType.ob', 'OberonContextVar.ob',
                'OberonSymbols.ob', 'Lexer.ob', 'Module.ob']
     

+ 1 - 1
src/eberon/EberonContext.ob

@@ -1,6 +1,6 @@
 MODULE EberonContext;
 IMPORT 
-    Context, ContextConst, ContextVar, Errors;
+    Context, ContextConst, Errors;
 TYPE
     IdentdefInfo* = RECORD(Context.IdentdefInfo)
         PROCEDURE IdentdefInfo*(id: STRING; exported: BOOLEAN; ro: BOOLEAN);

+ 42 - 0
src/eberon/EberonContextIf.ob

@@ -0,0 +1,42 @@
+MODULE EberonContextIf;
+IMPORT
+    ContextIf, ContextHierarchy, EberonOperatorScopes, Object;
+TYPE
+    Type* = RECORD(ContextIf.Type)
+        PROCEDURE Type(parent: ContextHierarchy.PNode);
+
+        scopes: EberonOperatorScopes.Type;
+    END;
+
+PROCEDURE Type.Type(parent: ContextHierarchy.PNode)
+    | SUPER(parent),
+      scopes(parent);
+END;
+
+PROCEDURE Type.handleLiteral(s: STRING);
+BEGIN
+    SUPER(s);
+    IF s = "THEN" THEN
+        SELF.scopes.doThen();
+    ELSIF (s = "ELSIF") OR (s = "ELSE") THEN
+        SELF.scopes.alternate();
+    END;
+END;
+
+PROCEDURE Type.handleMessage(VAR msg: ContextHierarchy.Message): Object.PType;
+VAR
+    result: Object.PType;
+BEGIN
+    IF ~SELF.scopes.handleMessage(msg) THEN
+        result := SUPER(msg);
+    END;
+    RETURN result;
+END;
+
+PROCEDURE Type.endParse(): BOOLEAN;
+BEGIN
+    SELF.scopes.reset();
+    RETURN SUPER();
+END;
+
+END EberonContextIf.

+ 0 - 25
src/eberon/eberon_context.js

@@ -52,30 +52,6 @@ var ChainedContext = ContextHierarchy.Node;
 ChainedContext.extend = Class.extend;
 ChainedContext.prototype.init = ContextHierarchy.Node;
 
-var If = Class.extend.call(ContextIf.Type, {
-    init: function EberonContext$If(context){
-        ContextIf.Type.call(this, context);
-        this.__scopes = new EberonOperatorScopes.Type(this);
-    },
-    handleMessage: function(msg){
-        if (this.__scopes.handleMessage(msg))
-            return;
-
-        return ContextIf.Type.prototype.handleMessage.call(this, msg);
-    },
-    handleLiteral: function(s){
-        ContextIf.Type.prototype.handleLiteral.call(this, s);
-        if (s == "THEN")
-            this.__scopes.doThen();
-        else if (s == "ELSIF" || s == "ELSE")
-            this.__scopes.alternate();
-    },
-    endParse: function(){
-        this.__scopes.reset();
-        ContextIf.Type.prototype.endParse.call(this);
-    }
-});
-
 var CaseLabel = Class.extend.call(ContextCase.Label, {
     init: function EberonContext$CaseLabel(context){
         ContextCase.Label.call(this, context);
@@ -202,6 +178,5 @@ exports.CaseLabel = CaseLabel;
 exports.FormalParameters = FormalParameters;
 exports.FormalParametersProcDecl = FormalParametersProcDecl;
 exports.FormalType = FormalType;
-exports.If = If;
 exports.ModuleDeclaration = ModuleDeclaration;
 exports.MapDecl = MapDecl;

+ 2 - 1
src/eberon/eberon_grammar.js

@@ -9,6 +9,7 @@ var EberonContext = require("js/EberonContext.js");
 var EberonContextDesignator = require("js/EberonContextDesignator.js");
 var EberonContextExpression = require("js/EberonContextExpression.js");
 var EberonContextIdentdef = require("js/EberonContextIdentdef.js");
+var EberonContextIf = require("js/EberonContextIf.js");
 var EberonContextInPlace = require("js/EberonContextInPlace.js");
 var EberonContextLoop = require("js/EberonContextLoop.js");
 var EberonContextProcedure = require("js/EberonContextProcedure.js");
@@ -162,7 +163,7 @@ exports.language = {
             Expression:         EberonContextExpression.ExpressionNode,
             For:                EberonContextLoop.For,
             While:              EberonContextLoop.While,
-            If:                 EbContext.If,
+            If:                 EberonContextIf.Type,
             CaseLabel:          EbContext.CaseLabel,
             Repeat:             EberonContextLoop.Repeat,
             ModuleDeclaration:  EbContext.ModuleDeclaration

+ 1 - 1
src/ob/ContextIf.ob

@@ -3,7 +3,7 @@ IMPORT
     ContextExpression, ContextHierarchy, Errors, Expression, Types;
 TYPE
     Type* = RECORD(ContextExpression.ExpressionHandler)
-        PROCEDURE Type(parent: ContextHierarchy.PNode);
+        PROCEDURE Type*(parent: ContextHierarchy.PNode);
     END;
 
 PROCEDURE handleIfExpression*(e: Expression.PType);