Browse Source

refactor (prepare for dynamic array methods)

Vladislav Folts 11 years ago
parent
commit
5aeda9f64b
6 changed files with 42 additions and 24 deletions
  1. BIN
      bin/compiled.zip
  2. 9 8
      src/context.js
  3. 2 2
      src/eberon/EberonTypes.ob
  4. 24 9
      src/eberon/eberon_context.js
  5. 6 4
      src/ob/Module.ob
  6. 1 1
      src/ob/Types.ob

BIN
bin/compiled.zip


+ 9 - 8
src/context.js

@@ -337,13 +337,10 @@ exports.Designator = ChainedContext.extend({
         this.__derefCode = this.__code;
         this.__derefCode = this.__code;
         this.__propCode = "\"" + id + "\"";
         this.__propCode = "\"" + id + "\"";
         this.__code += "." + id;
         this.__code += "." + id;
-        this.__info = this._makeDenoteVar(field, isReadOnly);
+        this.__info = field.asVar(isReadOnly, this);
         this.__currentType = field.type();
         this.__currentType = field.type();
         this.__scope = undefined;
         this.__scope = undefined;
     },
     },
-    _makeDenoteVar: function(field, isReadOnly){
-        return Type.makeVariable(field.type(), isReadOnly);
-    },
     _makeDerefVar: function(){
     _makeDerefVar: function(){
         return Type.makeVariableRef(this.__currentType, false);
         return Type.makeVariableRef(this.__currentType, false);
     },
     },
@@ -1697,16 +1694,17 @@ function isTypeRecursive(type, base){
 }
 }
 
 
 var RecordField = Type.Field.extend({
 var RecordField = Type.Field.extend({
-    init: function Context$RecordField(identdef, type, recordType){
+    init: function Context$RecordField(identdef, type){
         this.__identdef = identdef;
         this.__identdef = identdef;
         this.__type = type;
         this.__type = type;
-        this.__refcordType = recordType;
     },
     },
     id: function(){return this.__identdef.id();},
     id: function(){return this.__identdef.id();},
     exported: function(){return this.__identdef.exported();},
     exported: function(){return this.__identdef.exported();},
     identdef: function(){return this.__identdef;},
     identdef: function(){return this.__identdef;},
     type: function(){return this.__type;},
     type: function(){return this.__type;},
-    recordType: function(){return this.__refcordType;}
+    asVar: function(isReadOnly){ 
+        return Type.makeVariable(this.__type, isReadOnly); 
+    }
 });
 });
 
 
 exports.RecordDecl = ChainedContext.extend({
 exports.RecordDecl = ChainedContext.extend({
@@ -1724,7 +1722,7 @@ exports.RecordDecl = ChainedContext.extend({
         if (isTypeRecursive(type, this.__type))
         if (isTypeRecursive(type, this.__type))
             throw new Errors.Error("recursive field definition: '"
             throw new Errors.Error("recursive field definition: '"
                 + field.id() + "'");
                 + field.id() + "'");
-        this.__type.addField(new RecordField(field, type, this.__type));
+        this.__type.addField(this._makeField(field, type));
         if (field.exported())
         if (field.exported())
             this.parent().exportField(field.id());
             this.parent().exportField(field.id());
     },
     },
@@ -1758,6 +1756,9 @@ exports.RecordDecl = ChainedContext.extend({
 
 
         gen.closeScope("");
         gen.closeScope("");
         gen.closeScope(");\n");
         gen.closeScope(");\n");
+    },
+    _makeField: function(field, type){
+        return new RecordField(field, type);
     }
     }
 });
 });
 
 

+ 2 - 2
src/eberon/EberonTypes.ob

@@ -108,9 +108,9 @@ PROCEDURE DynamicArrayMethod.type(): Types.PType;
     RETURN dynamicArrayAddType
     RETURN dynamicArrayAddType
 END DynamicArrayMethod.type;
 END DynamicArrayMethod.type;
 
 
-PROCEDURE DynamicArrayMethod.recordType(): Types.PType;
+PROCEDURE DynamicArrayMethod.asVar(): Types.PId;
     RETURN NIL
     RETURN NIL
-END DynamicArrayMethod.recordType;
+END DynamicArrayMethod.asVar;
 
 
 BEGIN
 BEGIN
     (*dynamicArrayAddType := makeMethodType("add", Procedure.makeStd("add", NIL), Procedure.makeProcCallGenerator);*)
     (*dynamicArrayAddType := makeMethodType("add", Procedure.makeStd("add", NIL), Procedure.makeProcCallGenerator);*)

+ 24 - 9
src/eberon/eberon_context.js

@@ -193,14 +193,6 @@ var Designator = Context.Designator.extend({
         }
         }
         return Context.Designator.prototype._indexSequence.call(this, type, info);
         return Context.Designator.prototype._indexSequence.call(this, type, info);
     },
     },
-    _makeDenoteVar: function(field, isReadOnly){
-        var type = field.type();
-        if (type instanceof EberonTypes.MethodType)
-            return new MethodVariable(type);
-        if (!isReadOnly && this.qualifyScope(Type.recordScope(field.recordType())))
-            isReadOnly = field.identdef().isReadOnly();
-        return Context.Designator.prototype._makeDenoteVar(field, isReadOnly);
-    },
     _makeDerefVar: function(info){
     _makeDerefVar: function(info){
         if (info instanceof TypeNarrowVariable)
         if (info instanceof TypeNarrowVariable)
             return new DereferencedTypeNarrowVariable(info);
             return new DereferencedTypeNarrowVariable(info);
@@ -357,6 +349,26 @@ var AssignmentOrProcedureCall = Context.Chained.extend({
     }
     }
 });
 });
 
 
+var RecordField = Context.RecordField.extend({
+    init: function EberonContext$RecordField(field, type, recordType){
+        Context.RecordField.prototype.init.call(this, field, type);
+        this.__recordType = recordType;
+    },
+    asVar: function(isReadOnly, context){ 
+        if (!isReadOnly && context.qualifyScope(Type.recordScope(this.__recordType)))
+            isReadOnly = this.identdef().isReadOnly();
+        return Context.RecordField.prototype.asVar.call(this, isReadOnly); 
+    }
+});
+
+var RecordFieldAsMethod = Context.RecordField.extend({
+    init: function EberonContext$RecordFieldAsMethod(field, type){
+        Context.RecordField.prototype.init.call(this, field, type);
+    },
+    asVar: function(){ 
+        return new MethodVariable(this.type()); 
+    }
+});
 var RecordType = Type.Record.extend({
 var RecordType = Type.Record.extend({
     init: function EberonContext$RecordType(name, cons, scope){
     init: function EberonContext$RecordType(name, cons, scope){
         Type.Record.prototype.init.call(this);
         Type.Record.prototype.init.call(this);
@@ -408,7 +420,7 @@ var RecordType = Type.Record.extend({
                   + "': method already was declared"
                   + "': method already was declared"
                 : "cannot declare method, record already has field '" + id + "'");
                 : "cannot declare method, record already has field '" + id + "'");
 
 
-        this.__declaredMethods[id] = new Context.RecordField(methodId, type);
+        this.__declaredMethods[id] = new RecordFieldAsMethod(methodId, type);
 
 
         if (!methodId.exported())
         if (!methodId.exported())
             this.__nonExportedMethods.push(id);
             this.__nonExportedMethods.push(id);
@@ -589,6 +601,9 @@ var RecordDecl = Context.RecordDecl.extend({
         if (msg instanceof Context.AddArgumentMsg) // not used
         if (msg instanceof Context.AddArgumentMsg) // not used
             return undefined;
             return undefined;
         return Context.RecordDecl.prototype.handleMessage.call(this, msg);
         return Context.RecordDecl.prototype.handleMessage.call(this, msg);
+    },
+    _makeField: function(field, type){
+        return new RecordField(field, type, this.__type);
     }
     }
 });
 });
 
 

+ 6 - 4
src/ob/Module.ob

@@ -9,7 +9,8 @@ TYPE
     AnyType* = RECORD(Types.StorageType)
     AnyType* = RECORD(Types.StorageType)
         PROCEDURE callGenerator(cx: LanguageContext.PType; id: STRING): Procedure.PCallGenerator;
         PROCEDURE callGenerator(cx: LanguageContext.PType; id: STRING): Procedure.PCallGenerator;
         PROCEDURE denote(id: STRING): Types.PField;
         PROCEDURE denote(id: STRING): Types.PField;
-        asField: POINTER TO AnyField
+        asField: POINTER TO AnyField;
+        asVar: Types.PId
     END;
     END;
 
 
     AnyField = RECORD(Types.Field)
     AnyField = RECORD(Types.Field)
@@ -54,9 +55,9 @@ PROCEDURE AnyField.type(): Types.PType;
     RETURN any
     RETURN any
 END AnyField.type;
 END AnyField.type;
 
 
-PROCEDURE AnyField.recordType(): Types.PType;
-    RETURN any
-END AnyField.recordType;
+PROCEDURE AnyField.asVar(): Types.PId;
+    RETURN any.asVar
+END AnyField.asVar;
 
 
 PROCEDURE AnyTypeProc.args(): JsArray.Type;
 PROCEDURE AnyTypeProc.args(): JsArray.Type;
     RETURN NIL
     RETURN NIL
@@ -138,6 +139,7 @@ BEGIN
     
     
     NEW(any);
     NEW(any);
     NEW(any.asField); 
     NEW(any.asField); 
+    any.asVar := Types.makeTypeId(any);
 
 
     doProcSymbol := makeDoProcSymbol();
     doProcSymbol := makeDoProcSymbol();
     varTypeSymbol := makeVarTypeSymbol();
     varTypeSymbol := makeVarTypeSymbol();

+ 1 - 1
src/ob/Types.ob

@@ -85,7 +85,7 @@ TYPE
         PROCEDURE id*(): STRING;
         PROCEDURE id*(): STRING;
         PROCEDURE exported*(): BOOLEAN;
         PROCEDURE exported*(): BOOLEAN;
         PROCEDURE type*(): PType;
         PROCEDURE type*(): PType;
-        PROCEDURE recordType*(): PType 
+        PROCEDURE asVar*(): PId 
     END;
     END;
     PField* = POINTER TO Field;
     PField* = POINTER TO Field;