Vladislav Folts před 9 roky
rodič
revize
2cfe8f9233

binární
bin/compiled.zip


+ 7 - 46
src/eberon/EberonContextDesignator.ob

@@ -10,14 +10,6 @@ TYPE
     END;
     PType = POINTER TO Type;
 
-    MapElementVariable* = RECORD(Types.Variable)
-        PROCEDURE MapElementVariable(type: Types.PStorageType; readOnly: BOOLEAN; lval, rval: STRING);
-
-        elementType-: Types.PStorageType; 
-        readOnly: BOOLEAN; 
-        lval-, rval-: STRING;
-    END;
-
     ResultVariable = RECORD(Types.Variable)
         PROCEDURE ResultVariable(e: Expression.PType);
 
@@ -127,15 +119,14 @@ BEGIN
             Types.basic.ch, 
             EberonString.makeElementVariable(),
             ContextDesignator.getAt(SELF, Types.basic.ch),
-            "",
             "");
     ELSIF currentType IS EberonMap.PType THEN
         indexType <- currentType.elementsType;
         rtl <- SELF.root().language().rtl(EberonRtl.PType);
         rval <- rtl.getMappedValue(code, indexCode);
         lval <- code + "[" + indexCode + "]";
-        var <- NEW MapElementVariable(indexType, info(Types.PVariable).isReadOnly(), lval, rval);
-        result := NEW ContextDesignator.Index(0, indexType, var, rval, lval, "");
+        var <- NEW EberonMap.ElementVariable(indexType, info(Types.PVariable).isReadOnly(), lval, rval);
+        result := NEW ContextDesignator.Index(0, indexType, var, rval, "");
     ELSE
         result := SUPER(info, code, indexCode);
     END;
@@ -170,7 +161,7 @@ END;
 PROCEDURE endCall(VAR d: Type);
 BEGIN
     e <- d.procCall.end();
-    ContextDesignator.advance(d, e.type(), NEW ResultVariable(e), e.code(), "", FALSE);
+    ContextDesignator.advance(d, e.type(), NEW ResultVariable(e), e.code(), FALSE);
     d.procCall := NIL;
 END;
 
@@ -202,7 +193,7 @@ BEGIN
         endCall(SELF);
     ELSIF msg IS OperatorNewMsg THEN
         e <- msg.expression;
-        ContextDesignator.advance(SELF, e.type(), NEW ResultVariable(e), e.code(), "", FALSE);
+        ContextDesignator.advance(SELF, e.type(), NEW ResultVariable(e), e.code(), FALSE);
     ELSIF ~breakTypePromotion(msg) THEN (* no type promotion after calling functions *)
         result := SUPER(msg);
     END;    
@@ -224,48 +215,18 @@ BEGIN
     IF s = "SELF" THEN
         type <- SELF.handleMessage(getMethodSelfMsg)(Types.PStorageType);
         info <- NEW Variable.Declared("this", type);
-        ContextDesignator.advance(SELF, type, info, "this", "", FALSE);
+        ContextDesignator.advance(SELF, type, info, "this", FALSE);
     ELSIF s = "POINTER" THEN
         type <- SELF.handleMessage(getSelfAsPointerMsg)(Types.PStorageType);
-        ContextDesignator.advance(SELF, makePointer(type), NEW SelfAsPointer(), "", "", FALSE);
+        ContextDesignator.advance(SELF, makePointer(type), NEW SelfAsPointer(), "", FALSE);
     ELSIF s = "SUPER" THEN
         ms <- SELF.handleMessage(getMethodSuperMsg)(PSuperMethodInfo);
-        ContextDesignator.advance(SELF, ms.info.type, ms.info, ms.code, "", FALSE);
+        ContextDesignator.advance(SELF, ms.info.type, ms.info, ms.code, FALSE);
     ELSE
         SUPER(s);
     END;
 END;
 
-PROCEDURE MapElementVariable.MapElementVariable(type: Types.PStorageType; readOnly: BOOLEAN; lval, rval: STRING)
-    | elementType(type),
-      readOnly(readOnly),
-      lval(lval),
-      rval(rval);
-END;
-
-PROCEDURE MapElementVariable.type(): Types.PStorageType;
-    RETURN SELF.elementType;
-END;
-
-PROCEDURE MapElementVariable.isReference(): BOOLEAN;
-    RETURN FALSE;
-END;
-
-PROCEDURE MapElementVariable.isReadOnly(): BOOLEAN;
-    RETURN SELF.readOnly;
-END;
-
-PROCEDURE MapElementVariable.idType(): STRING;
-VAR
-    result: STRING;
-BEGIN
-    result := "MAP's element of type '" + SELF.elementType.description() + "'";
-    IF SELF.readOnly THEN
-        result := "read-only " + result;
-    END;
-    RETURN result;
-END;
-
 PROCEDURE ResultVariable.ResultVariable(e: Expression.PType)
     | expression(e);
 END;

+ 3 - 3
src/eberon/EberonLanguageContext.ob

@@ -1,6 +1,6 @@
 MODULE EberonLanguageContext;
 IMPORT 
-	EberonContextDesignator, EberonTypePromotion, Expression, LanguageContext, Types;
+	EberonMap, EberonTypePromotion, Expression, LanguageContext, Types;
 TYPE
 	CodeTraits* = RECORD(LanguageContext.CodeTraits)
 	END;
@@ -11,7 +11,7 @@ VAR
 BEGIN
 	IF info IS EberonTypePromotion.Variable THEN
 		result := info.id();
-	ELSIF (info IS EberonContextDesignator.MapElementVariable) & ~info.elementType.isScalar() THEN
+	ELSIF (info IS EberonMap.ElementVariable) & ~info.elementType.isScalar() THEN
 		result := info.rval;
 	ELSE
 		result := SUPER(info);
@@ -23,7 +23,7 @@ PROCEDURE CodeTraits.assign(VAR info: Types.Id; right: Expression.PType): STRING
 VAR
     result: STRING;
 BEGIN
-	IF info IS EberonContextDesignator.MapElementVariable THEN
+	IF info IS EberonMap.ElementVariable THEN
     	result := info.lval + " = " + Expression.deref(right).code();
     ELSE
     	result := SUPER(info, right);

+ 38 - 0
src/eberon/EberonMap.ob

@@ -37,6 +37,14 @@ TYPE
     MethodCallClear = RECORD(Procedure.StdCall)
     END;
 
+    ElementVariable* = RECORD(Types.Variable)
+        PROCEDURE ElementVariable*(type: Types.PStorageType; readOnly: BOOLEAN; lval, rval: STRING);
+
+        elementType-: Types.PStorageType; 
+        readOnly: BOOLEAN; 
+        lval-, rval-: STRING;
+    END;
+
 PROCEDURE Type.initializer(cx: Context.Type): STRING;
     RETURN "{}";
 END;
@@ -125,5 +133,35 @@ PROCEDURE MethodClearField.designatorCode(leadCode: STRING; cx: Context.Type): T
     RETURN NEW Types.FieldCode(cx.rtl()(EberonRtl.PType).clearMap(leadCode), "", "");
 END;
 
+PROCEDURE ElementVariable.ElementVariable(type: Types.PStorageType; readOnly: BOOLEAN; lval, rval: STRING)
+    | elementType(type),
+      readOnly(readOnly),
+      lval(lval),
+      rval(rval);
+END;
+
+PROCEDURE ElementVariable.type(): Types.PStorageType;
+    RETURN SELF.elementType;
+END;
+
+PROCEDURE ElementVariable.isReference(): BOOLEAN;
+    RETURN FALSE;
+END;
+
+PROCEDURE ElementVariable.isReadOnly(): BOOLEAN;
+    RETURN SELF.readOnly;
+END;
+
+PROCEDURE ElementVariable.idType(): STRING;
+VAR
+    result: STRING;
+BEGIN
+    result := "MAP's element of type '" + SELF.elementType.description() + "'";
+    IF SELF.readOnly THEN
+        result := "read-only " + result;
+    END;
+    RETURN result;
+END;
+
 END EberonMap.
 

+ 4 - 5
src/eberon/EberonOperator.ob

@@ -101,15 +101,14 @@ PROCEDURE CastOpRecord.assign(cx: LanguageContext.PType; left: Designator.Type;
 VAR
     result: STRING;
 BEGIN
-    leftCode <- left.code();
-    leftLval <- left.lval();
-    IF leftCode # leftLval THEN (* TRUE for putting to MAP *)
+    info <- left.info();
+    IF info^ IS EberonMap.ElementVariable THEN
         (* optimize the case when the temporary is used - do not clone it 
            but only if types exactly match - derived temporary still must be cloned *)
         IF (right.designator() = NIL) & (left.type() = right.type()) THEN
-            result := leftLval + " = " + right.code();
+            result := info.lval + " = " + right.code();
         ELSE
-            result := leftLval + " = " 
+            result := info.lval + " = " 
                     + cx.language.rtl.clone(right.code(), 
                                             generateTypeInfo(left.type()), 
                                             Record.constructor(cx.cx^, left.type()(Record.PType)^));

+ 1 - 1
src/ob/Cast.ob

@@ -153,7 +153,7 @@ PROCEDURE CastOpArray.clone(cx: LanguageContext.PType; e: Expression.PType): STR
 END;
 
 PROCEDURE CastOpRecord.assign(cx: LanguageContext.PType; left: Designator.Type; right: Expression.PType): STRING;
-    RETURN cx.language.rtl.copy(right.code(), left.lval(), Record.generateTypeInfo(left.type()));
+    RETURN cx.language.rtl.copy(right.code(), left.code(), Record.generateTypeInfo(left.type()));
 END;
 
 PROCEDURE CastOpStrToChar.make(cx: LanguageContext.PType; e: Expression.PType): Expression.PType;

+ 9 - 19
src/ob/ContextDesignator.ob

@@ -5,12 +5,12 @@ IMPORT
     Record, ScopeBase, String, TypeId, Types, Variable;
 TYPE
     Index* = RECORD
-        PROCEDURE Index*(length: INTEGER; type: Types.PType; info: Types.PId; code, lval, asProperty: STRING);
+        PROCEDURE Index*(length: INTEGER; type: Types.PType; info: Types.PId; code, asProperty: STRING);
 
         length: INTEGER;
         type: Types.PType;
         info: Types.PId;
-        code, lval, asProperty: STRING;
+        code, asProperty: STRING;
     END;
     PIndex* = POINTER TO Index;
 
@@ -31,7 +31,7 @@ TYPE
         scope: ScopeBase.PType;
         currentType-: Types.PType;
         info-: Types.PId;
-        code, derefCode, propCode, lval: STRING;
+        code, derefCode, propCode: STRING;
         indexExpression: Expression.PType;
     END;
 
@@ -53,12 +53,11 @@ VAR
     beginCallMsg: BeginCallMsg;
     endCallMsg: EndCallMsg;
 
-PROCEDURE Index.Index(length: INTEGER; type: Types.PType; info: Types.PId; code, lval, asProperty: STRING)
+PROCEDURE Index.Index(length: INTEGER; type: Types.PType; info: Types.PId; code, asProperty: STRING)
     | length(length),
       type(type),
       info(info),
       code(code),
-      lval(lval),
       asProperty(asProperty);
 END;
 
@@ -131,15 +130,13 @@ BEGIN
         Errors.raise("POINTER TO type expected, got '"
                      + designator.currentType.description() + "'");
     END;
-    
-    designator.lval := "";
 END;
 
 PROCEDURE getAt*(d: Type; type: Types.PStorageType): STRING;
     RETURN d.root().language().codeTraits.getAt(d.derefCode, Expression.deref(d.indexExpression).code(), type);
 END;
 
-PROCEDURE advance*(VAR d: Type; type: Types.PType; info: Types.PId; code, lval: STRING; replace: BOOLEAN);
+PROCEDURE advance*(VAR d: Type; type: Types.PType; info: Types.PId; code: STRING; replace: BOOLEAN);
 BEGIN
     d.currentType := type;
     d.info := info;
@@ -148,7 +145,6 @@ BEGIN
     ELSE
         d.code := d.code + code;
     END;
-    d.lval := lval;
 END;
 
 PROCEDURE Type.handleLiteral(s: STRING);
@@ -156,7 +152,7 @@ BEGIN
     IF (s = "]") OR (s = ",") THEN
         index <- handleIndexExpression(SELF);
         SELF.propCode := index.asProperty;
-        advance(SELF, index.type, index.info, SELF.code + index.code, index.lval, FALSE);
+        advance(SELF, index.type, index.info, SELF.code + index.code, FALSE);
     END;
     IF (s = "[") OR (s = ",") THEN
         SELF.derefCode := SELF.code;
@@ -188,7 +184,7 @@ BEGIN
         fieldCode <- field.designatorCode(SELF.code, SELF);
         SELF.derefCode := fieldCode.derefCode;
         SELF.propCode := fieldCode.propCode;
-        advance(SELF, currentType, field.asVar(SELF.code, isReadOnly, SELF), fieldCode.code, "", TRUE);
+        advance(SELF, currentType, field.asVar(SELF.code, isReadOnly, SELF), fieldCode.code, TRUE);
         SELF.scope := NIL;
     END;
 END;
@@ -221,7 +217,6 @@ PROCEDURE Type.doIndexSequence(info: Types.PId; code, indexCode: STRING): PIndex
 VAR
     length: INTEGER;
     indexType: Types.PStorageType;
-    lval: STRING;
 BEGIN
     type <- SELF.currentType;
     IF type IS Types.PArray THEN
@@ -247,7 +242,7 @@ BEGIN
     readOnly <- (info IS Types.PConst) 
              OR ((info IS Types.PVariable) & info.isReadOnly());
     v <- NEW Variable.PropertyVariable(indexType, leadCode, indexCode, readOnly);
-    RETURN NEW Index(length, indexType, v, wholeCode, lval, indexCode);
+    RETURN NEW Index(length, indexType, v, wholeCode, indexCode);
 END;
 
 PROCEDURE discardCode*(VAR d: Type);
@@ -261,13 +256,8 @@ END;
 
 PROCEDURE Type.endParse(): BOOLEAN;
 BEGIN
-    code <- SELF.code;
-    lval <- SELF.lval;
-    IF LEN(lval) = 0 THEN
-        lval := code;
-    END;
     SELF.parent().attributes.designator :=
-        NEW Designator.Type(code, lval, SELF.currentType, SELF.info, SELF.scope);
+        NEW Designator.Type(SELF.code, SELF.currentType, SELF.info, SELF.scope);
     RETURN TRUE;
 END;
 

+ 2 - 9
src/ob/Designator.ob

@@ -3,16 +3,14 @@ IMPORT
     ScopeBase, Types;
 TYPE
     Type* = RECORD
-        PROCEDURE Type*(code: STRING; lval: STRING; type: Types.PType; info: Types.PId; scope: ScopeBase.PType);
+        PROCEDURE Type*(code: STRING; type: Types.PType; info: Types.PId; scope: ScopeBase.PType);
 
         PROCEDURE code*(): STRING;
-        PROCEDURE lval*(): STRING;
         PROCEDURE type*(): Types.PType;
         PROCEDURE info*(): Types.PId;
         PROCEDURE scope*(): ScopeBase.PType;
 
         mCode: STRING;
-        mLval: STRING;
         mType: Types.PType;
         mInfo: Types.PId;
         mScope: ScopeBase.PType
@@ -24,10 +22,6 @@ PROCEDURE Type.code(): STRING;
     RETURN SELF.mCode
 END;
 
-PROCEDURE Type.lval(): STRING;
-    RETURN SELF.mLval
-END;
-
 PROCEDURE Type.type(): Types.PType;
     RETURN SELF.mType
 END;
@@ -40,9 +34,8 @@ PROCEDURE Type.scope(): ScopeBase.PType;
     RETURN SELF.mScope
 END;
 
-PROCEDURE Type.Type(code: STRING; lval: STRING; type: Types.PType; info: Types.PId; scope: ScopeBase.PType)
+PROCEDURE Type.Type(code: STRING; type: Types.PType; info: Types.PId; scope: ScopeBase.PType)
   | mCode(code),
-    mLval(lval),
     mType(type),
     mInfo(info),
     mScope(scope);

+ 1 - 1
src/ob/Operator.ob

@@ -475,7 +475,7 @@ BEGIN
         Errors.raise("cannot assign to " + info.idType());
     END; 
 
-    leftCode := left.lval();
+    leftCode := left.code();
     rightCode := right.code();
     leftType <- left.type();
     rightType <- right.type();