Przeglądaj źródła

js -> eberon transition

Vladislav Folts 10 lat temu
rodzic
commit
04ebeaf557

BIN
bin/compiled.zip


+ 51 - 1
src/eberon/EberonContextProcedure.ob

@@ -3,7 +3,7 @@ IMPORT
     Chars, CodeGenerator,
     Context, ContextDesignator, ContextExpression, ContextHierarchy, ContextProcedure, ContextType, 
     EberonConstructor, EberonContext, EberonContextDesignator, 
-    EberonRecord, EberonTypePromotion, EberonTypes,
+    EberonDynamicArray, EberonRecord, EberonTypePromotion, EberonTypes,
     Errors, Expression, LanguageContext, Object, Procedure, Types;
 TYPE
     ProcOrMethodDeclaration* = RECORD(ContextProcedure.Declaration)
@@ -31,6 +31,12 @@ TYPE
         typeOnDemand: EberonRecord.PRecord;
     END;
 
+    FormalParameters* = RECORD(ContextProcedure.FormalParameters)
+    END;
+
+    FormalParametersProcDecl* = RECORD(ContextProcedure.FormalParametersProcDecl)
+    END;
+
     GetConstructorBoundTypeMsg = RECORD(ContextHierarchy.Message)
     END;
     GetConstructorSuperMsg = RECORD(ContextHierarchy.Message)
@@ -354,6 +360,50 @@ BEGIN
     END;
 END;
 
+PROCEDURE assertArgumentIsNotNonVarDynamicArray(VAR msg: ContextHierarchy.Message);
+VAR
+    type: Types.PStorageType;
+BEGIN
+    IF msg IS ContextProcedure.AddArgumentMsg THEN
+        arg <- msg.arg;
+        IF ~arg.isVar THEN
+            type := arg.type;
+            WHILE type IS Types.PArray DO
+                IF type IS EberonDynamicArray.PDynamicArray THEN
+                    Errors.raise("dynamic array has no use as non-VAR argument '" + msg.name + "'");
+                END;
+                type := type(Types.PArray).elementsType;
+            END;
+        END;
+    END;
+END;
+
+PROCEDURE FormalParameters.handleMessage(VAR msg: ContextHierarchy.Message): Object.PType;
+BEGIN
+    assertArgumentIsNotNonVarDynamicArray(msg);
+    RETURN SUPER(msg);
+END;
+
+PROCEDURE FormalParameters.doCheckResultType(type: Types.PStorageType);
+BEGIN
+    IF ~(type IS EberonDynamicArray.PDynamicArray) THEN
+        SUPER(type);
+    END;
+END;
+
+PROCEDURE FormalParametersProcDecl.handleMessage(VAR msg: ContextHierarchy.Message): Object.PType;
+BEGIN
+    assertArgumentIsNotNonVarDynamicArray(msg);
+    RETURN SUPER(msg);
+END;
+
+PROCEDURE FormalParametersProcDecl.doCheckResultType(type: Types.PStorageType);
+BEGIN
+    IF ~(type IS EberonDynamicArray.PDynamicArray) THEN
+        SUPER(type);
+    END;
+END;
+
 PROCEDURE InitFieldMsg.InitFieldMsg(id: STRING)
     | id(id);
 END;

+ 36 - 2
src/eberon/EberonContextType.ob

@@ -1,8 +1,8 @@
 MODULE EberonContextType;
 IMPORT
     Chars,
-    Context, ContextHierarchy, ContextProcedure, ContextType, 
-    EberonContext, EberonDynamicArray, EberonRecord, EberonTypes,
+    Context, ContextExpression, ContextHierarchy, ContextProcedure, ContextType, 
+    EberonContext, EberonDynamicArray, EberonMap, EberonRecord, EberonTypes,
     Errors,
     Object, Procedure, R := Record, ScopeBase, Types;
 CONST
@@ -27,6 +27,13 @@ TYPE
         type: Procedure.PType;
     END;
 
+    Map* = RECORD(ContextType.HandleSymbolAsType)
+        PROCEDURE isAnonymousDeclaration*(): BOOLEAN;
+        PROCEDURE typeName*(): STRING;
+
+        type: Types.PStorageType;
+    END;
+
     MethodDeclMsg = RECORD(ContextHierarchy.Message)
         PROCEDURE MethodDeclMsg(id: Context.PIdentdefInfo; type: Procedure.PType);
         
@@ -172,6 +179,33 @@ BEGIN
     RETURN TRUE;
 END;
 
+PROCEDURE Map.handleQIdent(q: ContextHierarchy.QIdent);
+BEGIN
+    s <- ContextHierarchy.getQIdSymbolAndScope(SELF.root()^, q);
+    type <- ContextExpression.unwrapType(s.symbol().info());
+    SELF.setType(type);
+END;
+
+PROCEDURE Map.setType(type: Types.PStorageType);
+BEGIN
+    SELF.type := type;
+END;
+
+(* anonymous types can be used in map declaration *)
+PROCEDURE Map.isAnonymousDeclaration(): BOOLEAN;
+    RETURN TRUE;
+END;
+
+PROCEDURE Map.typeName(): STRING;
+    RETURN "";
+END;
+
+PROCEDURE Map.endParse(): BOOLEAN;
+BEGIN
+    SELF.parent()^(ContextType.HandleSymbolAsType).setType(NEW EberonMap.Type(SELF.type));
+    RETURN TRUE;
+END;
+
 PROCEDURE MethodDeclMsg.MethodDeclMsg(id: Context.PIdentdefInfo; type: Procedure.PType)
     | id(id),
       type(type);

+ 0 - 68
src/eberon/eberon_context.js

@@ -52,56 +52,6 @@ var ChainedContext = ContextHierarchy.Node;
 ChainedContext.extend = Class.extend;
 ChainedContext.prototype.init = ContextHierarchy.Node;
 
-var MapDecl = ChainedContext.extend({
-    init: function EberonContext$MapDecl(context){
-        ChainedContext.prototype.init.call(this, context);
-        this.__type = undefined;
-    },
-    handleQIdent: function(q){
-        var s = ContextHierarchy.getQIdSymbolAndScope(this.root(), q);
-        var type = ContextExpression.unwrapType(s.symbol().info());
-        this.setType(type);
-    },
-    // anonymous types can be used in map declaration
-    setType: function(type){
-        this.__type = type;
-    },
-    isAnonymousDeclaration: function(){return true;},
-    typeName: function(){return "";},
-    endParse: function(){
-        this.parent().setType(new EberonMap.Type(this.__type));
-    }
-});
-
-function assertArgumentIsNotNonVarDynamicArray(msg){
-    if (msg instanceof ContextProcedure.AddArgumentMsg){
-        var arg = msg.arg;
-        if (!arg.isVar){
-            var type = arg.type;
-            while (type instanceof Type.Array){
-                if (type instanceof EberonDynamicArray.DynamicArray)
-                    throw new Errors.Error("dynamic array has no use as non-VAR argument '" + msg.name + "'");
-                type = type.elementsType;
-            }
-        }
-    }
-}
-
-var FormalParameters = Class.extend.call(ContextProcedure.FormalParameters, {
-    init: function EberonContext$FormalParameters(context){
-        ContextProcedure.FormalParameters.call(this, context);
-    },
-    handleMessage: function(msg){
-        assertArgumentIsNotNonVarDynamicArray(msg);
-        return ContextProcedure.FormalParameters.prototype.handleMessage.call(this, msg);
-    },
-    doCheckResultType: function(type){
-        if (type instanceof EberonDynamicArray.DynamicArray)
-            return;
-        ContextProcedure.FormalParameters.prototype.doCheckResultType.call(this, type);
-    }
-});
-
 var FormalType = Class.extend.call(ContextType.HandleSymbolAsType, {
     init: function EberonContext$FormalType(context){
         ContextType.HandleSymbolAsType.call(this, context);
@@ -129,21 +79,6 @@ var FormalType = Class.extend.call(ContextType.HandleSymbolAsType, {
     }
 });
 
-var FormalParametersProcDecl = Class.extend.call(ContextProcedure.FormalParametersProcDecl, {
-    init: function EberonContext$FormalParametersProcDecl(context){
-        ContextProcedure.FormalParametersProcDecl.call(this, context);
-    },
-    handleMessage: function(msg){
-        assertArgumentIsNotNonVarDynamicArray(msg);
-        return ContextProcedure.FormalParametersProcDecl.prototype.handleMessage.call(this, msg);
-    },
-    doCheckResultType: function(type){
-        if (type instanceof EberonDynamicArray.DynamicArray)
-            return;
-        ContextProcedure.FormalParametersProcDecl.prototype.doCheckResultType.call(this, type);
-    }
-});
-
 var ModuleDeclaration = Class.extend.call(ContextModule.Declaration, {
     init: function EberonContext$ModuleDeclaration(context){
         ContextModule.Declaration.call(this, context);
@@ -155,8 +90,5 @@ var ModuleDeclaration = Class.extend.call(ContextModule.Declaration, {
     }
 });
 
-exports.FormalParameters = FormalParameters;
-exports.FormalParametersProcDecl = FormalParametersProcDecl;
 exports.FormalType = FormalType;
 exports.ModuleDeclaration = ModuleDeclaration;
-exports.MapDecl = MapDecl;

+ 4 - 4
src/eberon/eberon_grammar.js

@@ -31,7 +31,7 @@ var repeat = Parser.repeat;
 var required = Parser.required;
 
 function makeStrucType(base, type){
-    var mapType = context(and("MAP", "OF", type), EbContext.MapDecl);
+    var mapType = context(and("MAP", "OF", type), EberonContextType.Map);
     return or(base, mapType);
 }
 
@@ -46,7 +46,7 @@ function makeStatement(base, statementSequence, ident, expression){
 function makeProcedureHeading(ident, identdef, formalParameters){
     return and("PROCEDURE",
                context(and(optional(and(ident, ".")), identdef), EberonContextProcedure.ProcOrMethodId),
-               context(optional(formalParameters), EbContext.FormalParametersProcDecl)
+               context(optional(formalParameters), EberonContextProcedure.FormalParametersProcDecl)
                );
 }
 
@@ -90,7 +90,7 @@ function makeMethodHeading(identdef, formalParameters){
     return context(
         and("PROCEDURE",
             identdef,
-            context(optional(formalParameters), EbContext.FormalParametersProcDecl)),
+            context(optional(formalParameters), EberonContextProcedure.FormalParametersProcDecl)),
         EberonContextType.MethodHeading);
 }
 
@@ -155,7 +155,7 @@ exports.language = {
             variableDeclaration: EberonContextVar.Declaration,
             ArrayDecl:          EberonContextType.Array,
             Factor:             EberonContextExpression.Factor,
-            FormalParameters:   EbContext.FormalParameters,
+            FormalParameters:   EberonContextProcedure.FormalParameters,
             FormalType:         EbContext.FormalType,
             Term:               EberonContextExpression.Term,
             AddOperator:        EberonContextExpression.AddOperator,

+ 4 - 4
src/ob/ContextProcedure.ob

@@ -24,10 +24,10 @@ TYPE
     PDeclaration = POINTER TO Declaration;
 
     FormalParameters* = RECORD(ContextHierarchy.Node)
-        PROCEDURE FormalParameters(parent: ContextType.PDeclarationAndIdentHandle);
+        PROCEDURE FormalParameters*(parent: ContextType.PDeclarationAndIdentHandle);
 
         PROCEDURE handleQIdent(q: ContextHierarchy.QIdent);
-        PROCEDURE doCheckResultType(type: Types.PStorageType);
+        PROCEDURE doCheckResultType*(type: Types.PStorageType);
 
         arguments: ARRAY * OF Types.PProcedureArgument;
         type: Procedure.PDefined;
@@ -48,8 +48,8 @@ TYPE
     AddArgumentMsg* = RECORD(ContextHierarchy.Message)
         PROCEDURE AddArgumentMsg(name: STRING; arg: Types.PProcedureArgument);
 
-        name: STRING;
-        arg: Types.PProcedureArgument;
+        name-: STRING;
+        arg-: Types.PProcedureArgument;
     END;
 
     EndParametersMsg* = RECORD(ContextHierarchy.Message)

+ 1 - 1
src/ob/ContextType.ob

@@ -5,7 +5,7 @@ IMPORT
     Scope, ScopeBase, String, Symbols, TypeId, Types;
 TYPE
     HandleSymbolAsType* = RECORD(ContextHierarchy.Node)
-        PROCEDURE handleQIdent(q: ContextHierarchy.QIdent);
+        PROCEDURE handleQIdent*(q: ContextHierarchy.QIdent);
         PROCEDURE setType*(type: Types.PStorageType);
     END;
     PHandleSymbolAsType = POINTER TO HandleSymbolAsType;