Parcourir la source

Fixed many more bugs

Yentl Van Tendeloo il y a 8 ans
Parent
commit
f84ec2eab5

BIN
bootstrap/bootstrap.m.gz


+ 1 - 0
bootstrap/bootstrap.py

@@ -102,6 +102,7 @@ def bootstrap():
                     "read_userroot": ["Element"],
                     "deserialize": ["Element", "String"],
                     "log": ["String", "String"],
+                    "time": ["Float"],
                 }
 
     initial_user = "user_manager"

BIN
bootstrap/minimal.m.gz


+ 5 - 2
integration/code/fsa_design.mvc

@@ -4,14 +4,16 @@ include "primitives.alh"
 SCD FiniteStateAutomata_Design{
     Class String {
         $
-            if (bool_not(is_physical_float(self))):
-                return "Float has no float value"!
+            if (bool_not(is_physical_string(self))):
+                return "String has no string value"!
             else:
                 return "OK"!
         $
     }
 
     Class State {
+        lower_cardinality = 1
+
         name : String {
             target_lower_cardinality = 1
             target_upper_cardinality = 1
@@ -19,6 +21,7 @@ SCD FiniteStateAutomata_Design{
     }
 
     Class InitialState {
+        upper_cardinality = 1
     }
 
     Association Transition {

+ 30 - 15
integration/code/fsa_semantics.alc

@@ -22,6 +22,7 @@ Element function retype_to_runtime(design_model : Element):
 
 	runtime_model = instantiate_model(import_node("models/FiniteStateAutomata_Runtime"))
 
+	log("Retyping")
 	all_states = allInstances(design_model, "State")
 	while (list_len(all_states) > 0):
 		element_name = set_pop(all_states)
@@ -42,25 +43,32 @@ Element function retype_to_runtime(design_model : Element):
 			// There is a raise attribute
 			instantiate_attribute(runtime_model, element_name, "raise", read_attribute(design_model, element_name, "raise"))
 
+	log("DONE")
 	return runtime_model!
 
 Element function sanitize(new_runtime_model : Element, old_runtime_model : Element, auto : Boolean):
 	String cstate
 	String cstate_obj
-
-	cstate_obj = instantiate_node(new_runtime_model, "CurrentState", "")
-	cstate = readAssociationDestination(old_runtime_model, set_pop(allInstances(old_runtime_model, "CurrentStateLink")))
-	if (bool_not(dict_in(new_runtime_model["model"], cstate))):
-		// Current state removed, so fix
-		if (auto):
-			cstate = set_pop(allInstances(new_runtime_model, "InitialState"))
-		else:
-			while (bool_not(dict_in(new_runtime_model["model"], cstate))):
-				output("REQUEST_CURRENT_STATE")
-				cstate = input()
+	log("Start sanitize")
+
+	if (read_nr_out(allInstances(old_runtime_model, "CurrentState")) > 0):
+		cstate = readAssociationDestination(old_runtime_model, set_pop(allInstances(old_runtime_model, "CurrentStateLink")))
+		cstate_obj = instantiate_node(new_runtime_model, "CurrentState", "")
+		if (bool_not(dict_in(new_runtime_model["model"], cstate))):
+			// Current state removed, so fix
+			if (auto):
+				cstate = set_pop(allInstances(new_runtime_model, "InitialState"))
+			else:
+				while (bool_not(dict_in(new_runtime_model["model"], cstate))):
+					output("REQUEST_CURRENT_STATE")
+					cstate = input()
+	else:
+		// Initialize for the first time
+		cstate = set_pop(allInstances(new_runtime_model, "InitialState"))
 	
 	instantiate_link(new_runtime_model, "CurrentStateLink", "", cstate_obj, cstate)
 
+	log("Sanitize OK")
 	return new_runtime_model!
 
 Void function do_transition(model : Element, start_time : Float, event : String):
@@ -72,6 +80,7 @@ Void function do_transition(model : Element, start_time : Float, event : String)
 	String new_state
 	String raise
 
+	log("Transition executing")
 	cstate_link = set_pop(allInstances(model, "CurrentStateLink"))
 	cstate = readAssociationDestination(model, cstate_link)
 	cstate_obj = readAssociationSource(model, cstate_link)
@@ -119,24 +128,30 @@ Void function execute_fsa(design_model : Element):
 	simulation_time = 0.0
 	old_runtime_model = instantiate_model(import_node("models/FiniteStateAutomata_Runtime"))
 	runtime_model = retype_to_runtime(design_model)
-	runtime_model = sanitize(runtime_model, old_runtime_model, True)
 
 	conforming = conformance_scd(design_model)
+	log("Conformance: " + conforming)
 	if (conforming == "OK"):
 		output("CONFORMANCE_OK")
 	else:
 		output("CONFORMANCE_FAIL")
 
 	while (True):
+		log("Check input")
 		if (has_input()):
 			cmd = input()
 		else:
-			cmd = "skip"
+			if (conforming == "OK"):
+				cmd = "skip"
+			else:
+				cmd = input()
+		log("Do: " + cmd)
 
 		// Process input
 		if (cmd == "skip"):
-			output("SIM_TIME " + cast_v2s(time() - start_time))
-			output("SIM_STATE " + cast_v2s(readAssociationDestination(runtime_model, set_pop(allInstances(runtime_model, "CurrentStateLink")))))
+			if (conforming == "OK"):
+				output("SIM_TIME " + cast_v2s(time() - start_time))
+				output("SIM_STATE " + cast_v2s(readAssociationDestination(runtime_model, set_pop(allInstances(runtime_model, "CurrentStateLink")))))
 			
 		elif (cmd == "pause"):
 			// Pausing merely stops a running simulation