소스 검색

Added support for boolean and longreal properties
flag properties don't have an expression any more, only type boolean

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6545 8c9fc860-2736-0410-a75d-ab315db34111

felixf 9 년 전
부모
커밋
9bf936102f
3개의 변경된 파일55개의 추가작업 그리고 8개의 파일을 삭제
  1. 20 0
      source/ActiveCellsRuntime.mod
  2. 23 3
      source/FoxIntermediateBackend.Mod
  3. 12 5
      source/FoxSemanticChecker.Mod

+ 20 - 0
source/ActiveCellsRuntime.mod

@@ -42,6 +42,12 @@ type
 		procedure AddIntegerProperty*(c: any; const name: array of char; value: longint);
 		end AddIntegerProperty;
 
+		procedure AddBooleanProperty*(c: any; const name: array of char; value: boolean);
+		end AddBooleanProperty;
+
+		procedure AddRealProperty*(c: any; const name: array of char; value: longreal);
+		end AddRealProperty;
+
 		procedure FinishedProperties*(var c: any);
 		end FinishedProperties;
 
@@ -163,6 +169,20 @@ type
 		GetContext().AddIntegerProperty(c.c, name, value);
 	end AddIntegerProperty;
 
+	procedure AddBooleanProperty*(c: Cell; const name: array of char; var newValue: boolean; value: boolean);
+	begin
+		if EnableTrace then trace(c, name, newValue, value); end;
+		newValue := value;
+		GetContext().AddBooleanProperty(c.c, name, value);
+	end AddBooleanProperty;
+
+	procedure AddRealProperty*(c: Cell; const name: array of char; var newValue: longreal; value: longreal);
+	begin
+		if EnableTrace then trace(c, name, newValue, value, entier(value)); end;
+		newValue := value;
+		GetContext().AddRealProperty(c.c, name, value);
+	end AddRealProperty;
+
 	procedure FinishedProperties*(c: Cell);
 	begin
 		if EnableTrace then trace(c); end;

+ 23 - 3
source/FoxIntermediateBackend.Mod

@@ -7075,7 +7075,13 @@ TYPE
 				Global.GetSymbolNameInScope(property, cellType.cellScope , name);
 				PushConstString(name);
 				
-				IF SemanticChecker.IsStringType(property.type) OR (property.type.resolved IS SyntaxTree.IntegerType) THEN 
+				IF (value # NIL) THEN 
+					ASSERT(
+						SemanticChecker.IsStringType(property.type) 
+						OR (property.type.resolved IS SyntaxTree.IntegerType) 
+						OR (property.type.resolved IS SyntaxTree.FloatType)
+						OR (property.type.resolved IS SyntaxTree.BooleanType)
+						);
 					left := SyntaxTree.NewSymbolDesignator(-1,left,cell); left.SetType(system.anyType);
 					left := SyntaxTree.NewDereferenceDesignator(-1, left); left.SetType(cellType);
 					d := SyntaxTree.NewSymbolDesignator(-1, left, property); d.SetType(property.type);
@@ -7087,7 +7093,9 @@ TYPE
 					ReleaseOperand(op);
 				END;
 				
-				IF SemanticChecker.IsStringType(property.type) THEN 
+				IF value = NIL THEN
+					CallThis(position,"ActiveCellsRuntime","AddFlagProperty",3);
+				ELSIF SemanticChecker.IsStringType(property.type) THEN 
 					ASSERT(SemanticChecker.IsStringType(value.type));
 					Designate(value, op);
 					Emit(Push(property.position, op.tag));
@@ -7100,8 +7108,20 @@ TYPE
 					Emit(Push(property.position, op.op));
 					ReleaseOperand(op);
 					CallThis(position,"ActiveCellsRuntime","AddIntegerProperty",5);
+				ELSIF (property.type.resolved IS SyntaxTree.BooleanType) THEN
+					ASSERT(value.type.resolved IS SyntaxTree.BooleanType);
+					Evaluate(value, op); 
+					Emit(Push(property.position, op.op));
+					ReleaseOperand(op);
+					CallThis(position,"ActiveCellsRuntime","AddBooleanProperty",5);
+				ELSIF (property.type.resolved IS SyntaxTree.FloatType) THEN
+					ASSERT((value.type.resolved IS SyntaxTree.FloatType) & (value.type.resolved(SyntaxTree.FloatType).sizeInBits =64));
+					Evaluate(value, op); 
+					Emit(Push(property.position, op.op));
+					ReleaseOperand(op);
+					CallThis(position,"ActiveCellsRuntime","AddRealProperty",-1); (* must import *)
 				ELSE
-					CallThis(position,"ActiveCellsRuntime","AddFlagProperty",3);
+					HALT(200);
 				END;
 		END AddProperty;
 		

+ 12 - 5
source/FoxSemanticChecker.Mod

@@ -839,7 +839,7 @@ TYPE
 			this := modifiers;
 			WHILE this # NIL DO
 				IF ~this.resolved THEN
-					IF checkUse OR (this.expression = NIL) THEN
+					IF checkUse THEN
 						Error(this.position,Diagnostics.Invalid,"unexpected modifier");
 					ELSE
 						this.SetExpression(ResolveExpression(this.expression));
@@ -1043,6 +1043,8 @@ TYPE
 			qualifiedIdentifier: SyntaxTree.QualifiedIdentifier;
 			recordBase: SyntaxTree.RecordType;
 			numberMethods, int: LONGINT;
+			real: LONGREAL;
+			bool: BOOLEAN;
 			variable: SyntaxTree.Variable;
 			v: SyntaxTree.Expression;
 			str: Scanner.StringType;
@@ -1095,19 +1097,24 @@ TYPE
 							property.SetValue(v);
 							IF IsIntegerValue(modifier.expression, int) THEN
 								(*property.SetValue(modifier.expression);*)
+								modifier.SetExpression(NewConversion(modifier.position, modifier.expression, system.longintType, NIL));
 								property.SetType(system.longintType);
+							ELSIF IsRealValue(modifier.expression, real) THEN
+								modifier.SetExpression(NewConversion(modifier.position, modifier.expression, system.longrealType, NIL));
+								property.SetType(system.longrealType);
+							ELSIF IsBooleanValue(modifier.expression, bool) THEN
+								property.SetType(system.booleanType);
 							ELSIF IsStringValue(modifier.expression, str) THEN
 								(*property.SetValue(modifier.expression);*)
 								atype := SyntaxTree.NewArrayType(-1, NIL, SyntaxTree.Static);
 								atype.SetArrayBase(modifier.expression.type(SyntaxTree.StringType).baseType);
 								atype.SetLength(Global.NewIntegerValue(system,-1, (* type(SyntaxTree.StringType).length *) 256 (*! check if this is a good idea *) ));
 								property.SetType(atype);
-				ELSE
+							ELSE
 								Error(modifier.position, Diagnostics.Invalid, "unsupported property type");
 							END;
 						ELSE (* flag property *)
-							ASSERT(modifier.resolved);
-							property.SetValue(SyntaxTree.NewBooleanValue(position,TRUE));
+							(*property.SetValue(SyntaxTree.NewBooleanValue(position,TRUE));*)
 							property.SetType(system.booleanType);
 						END;
 						(* property.SetScope(x.cellScope); *) (* not required, will be done during entry *)
@@ -6556,7 +6563,7 @@ TYPE
 
 		PROCEDURE VisitProperty(property: SyntaxTree.Property);
 		BEGIN
-			VisitVariable(property);
+			VisitVariable(property)
 		END VisitProperty;