浏览代码

Attributes now work with RAMification and transformation

Yentl Van Tendeloo 8 年之前
父节点
当前提交
9c48d364e6

二进制
bootstrap/bootstrap.m.gz


+ 39 - 13
bootstrap/transform.alc

@@ -206,7 +206,9 @@ Element function get_possible_bindings(host_model : Element, schedule_model : El
 				func = get_func_AL_model(value)
 				log("Func: " + cast_e2s(func))
 				log("EXEC")
-				result = func(host_model, option, attribute)
+				log("Read attribute with name: " + string_substr(attribute, string_len("constraint_"), string_len(attribute) + 1))
+				log("Value: " + cast_e2s(read_attribute(host_model, option, string_substr(attribute, string_len("constraint_"), string_len(attribute) + 1))))
+				result = func(read_attribute(host_model, option, string_substr(attribute, string_len("constraint_"), string_len(attribute) + 1)))
 				log("Got result of constraint eval: " + cast_v2s(result))
 			else:
 				log("Attribute unconstrained, so add always")
@@ -339,7 +341,6 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 	Element RHS_map
 	String tmp
 	Element value
-	Element value_function
 	Element action
 	Element original_RHS_labels
 
@@ -369,17 +370,7 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 	while (read_nr_out(labels_to_add) > 0):
 		// Add the elements linked to these labels
 		label = list_pop(labels_to_add, 0)
-		if (element_neq(read_attribute(schedule_model, RHS_map[label], "value"), read_root())):
-			// There is a value associated with this node
-			value_function = read_attribute(schedule_model, RHS_map[label], "value")
-			value = value_function(host_model, mapping)
-
-			typename = read_type(schedule_model, RHS_map[label])
-			original_typename = string_substr(typename, 5, string_len(typename))
-			new_name = instantiate_value(host_model, original_typename, "", value)
-			dict_add(new_mapping, label, new_name)
-
-		elif (is_edge(schedule_model["model"][RHS_map[label]])):
+		if (is_edge(schedule_model["model"][RHS_map[label]])):
 			// Edge
 			src = read_attribute(schedule_model, reverseKeyLookup(schedule_model["model"], read_edge_src(schedule_model["model"][RHS_map[label]])), "label")
 			dst = read_attribute(schedule_model, reverseKeyLookup(schedule_model["model"], read_edge_dst(schedule_model["model"][RHS_map[label]])), "label")
@@ -401,8 +392,43 @@ Void function rewrite(host_model : Element, schedule_model : Element, RHS : Stri
 			new_name = instantiate_node(host_model, original_typename, "")
 			dict_add(new_mapping, label, new_name)
 
+	Element attributes
+	String attribute
+	Element result
+	Element func
+
 	while (read_nr_out(original_RHS_labels) > 0):
+		// Perform actions
 		label = set_pop(original_RHS_labels)
+
+		// Do all attribute actions that are defined
+		attributes = dict_keys(getAttributeList(schedule_model, RHS_map[label]))
+		while (read_nr_out(attributes) > 0):
+			attribute = set_pop(attributes)
+			if (bool_not(string_startswith(attribute, "value_"))):
+				continue!
+
+			log("Execute attribute " + attribute)
+			value = read_attribute(schedule_model, RHS_map[label], attribute)
+			if (element_neq(value, read_root())):
+				func = get_func_AL_model(value)
+				log("Func: " + cast_e2s(func))
+				log("EXEC")
+				result = func(host_model, new_mapping[label], mapping)
+				log("Got result of constraint eval: " + cast_v2s(result))
+
+				if (has_value(result)):
+					// New value defined, so assign!
+					instantiate_attribute(host_model, new_mapping[label], string_substr(attribute, string_len("value_"), string_len(attribute) + 1), result)
+					log("Created new value for attribute!")
+				else:
+					// Non-value return means to destroy the attribute!
+					unset_attribute(host_model, new_mapping[label], string_substr(attribute, string_len("value_"), string_len(attribute) + 1))
+					log("Deleted attribute!")
+			else:
+				log("Attribute undefined, so leave it be!")
+
+		// Do the global action of each element
 		action = read_attribute(schedule_model, RHS_map[label], "action")
 		if (element_neq(action, read_root())):
 			Element func

+ 52 - 45
core/core_formalism.mvc

@@ -2,59 +2,66 @@ import models/SimpleClassDiagrams as SimpleClassDiagrams
 include "primitives.alh"
 
 SimpleClassDiagrams CoreFormalism {
-    Attribute String {
-        $
-            if (bool_not(is_physical_string(self))):
-                return "String has no string value"!
-            else:
-                return "OK"!
-        $
+    SimpleAttribute String {
+        constraint = $
+            String function constraint(model : Element, name : String):
+                if (bool_not(is_physical_string(model["model"][name]))):
+                    return "String has no string value"!
+                else:
+                    return "OK"!
+            $
     }
 
-    Attribute Permissions {
-        $
-            if (bool_not(is_physical_string(self))):
-                return "Permissions has no string value"!
-            else:
-                return "OK"!
-        $
+    SimpleAttribute Permissions {
+        constraint = $
+            String function constraint(model : Element, name : String):
+                if (bool_not(is_physical_string(model["model"][name]))):
+                    return "Permissions has no string value"!
+                else:
+                    return "OK"!
+            $
     }
 
-    Attribute Boolean {
-        $
-            if (bool_not(is_physical_boolean(self))):
-                return "Boolean has no bool value"!
-            else:
-                return "OK"!
-        $
+    SimpleAttribute Boolean {
+        constraint = $
+            String function constraint(model : Element, name : String):
+                if (bool_not(is_physical_boolean(model["model"][name]))):
+                    return "Boolean has no bool value"!
+                else:
+                    return "OK"!
+            $
     }
 
-    Attribute Natural {
-        $
-            if (bool_not(is_physical_int(self))):
-                return "Natural has no integer value"!
-            elif (integer_lt(self, 0)):
-                return "Natural has negative value"!
-            else:
-                return "OK"!
-        $
+    SimpleAttribute Natural {
+        constraint = $
+            String function constraint(model : Element, name : String):
+                if (bool_not(is_physical_int(model["model"][name]))):
+                    return "Natural has no integer value"!
+                elif (integer_lt(model["model"][name], 0)):
+                    return "Natural has negative value"!
+                else:
+                    return "OK"!
+            $
     }
 
-    Attribute TypeMapping {
-        $
-            if (has_value(self)):
-                return "TypeMapping cannot have a value for root node!"!
-            Element keys
-            String key
-            keys = dict_keys(self)
-            while (read_nr_out(keys) > 0):
-                key = set_pop(keys)
-                if (bool_not(is_physical_string(key))):
-                    return ("Key on type mapping is not a string: " + cast_e2s(key))!
-                elif (bool_not(is_physical_string(self[key]))):
-                    return ("Value on type mapping is not a string for key " + cast_e2s(key))!
-            return "OK"!
-        $
+    SimpleAttribute TypeMapping {
+        constraint = $
+            String function constraint(model : Element, name : String):
+                Element self
+                self = model["model"][name]
+                if (has_value(self)):
+                    return "TypeMapping cannot have a value for root node!"!
+                Element keys
+                String key
+                keys = dict_keys(self)
+                while (read_nr_out(keys) > 0):
+                    key = set_pop(keys)
+                    if (bool_not(is_physical_string(key))):
+                        return ("Key on type mapping is not a string: " + cast_e2s(key))!
+                    elif (bool_not(is_physical_string(self[key]))):
+                        return ("Value on type mapping is not a string for key " + cast_e2s(key))!
+                return "OK"!
+            $
     }
 
     Class User {

+ 14 - 12
integration/code/cbd_design.mvc

@@ -3,21 +3,23 @@ include "primitives.alh"
 
 SCD CausalBlockDiagrams_Design{
     AttributeValue Float {
-        $
-            if (bool_not(is_physical_float(self))):
-                return "Float has no float value"!
-            else:
-                return "OK"!
-        $
+        constraint = $
+            String constraint(model : Element, name : String):
+                if (bool_not(is_physical_float(model["model"][name]))):
+                    return "Float has no float value"!
+                else:
+                    return "OK"!
+            $
     }
 
     AttributeValue String {
-        $
-            if (bool_not(is_physical_string(self))):
-                return "String has no string value"!
-            else:
-                return "OK"!
-        $
+        constraint = $
+            String constraint(model : Element, name : String):
+                if (bool_not(is_physical_string(model["model"][name]))):
+                    return "String has no string value"!
+                else:
+                    return "OK"!
+            $
     }
 
     Class Block{}

+ 14 - 12
integration/code/cbd_runtime.mvc

@@ -3,21 +3,23 @@ include "primitives.alh"
 
 SCD CausalBlockDiagrams_Runtime{
     AttributeValue Float {
-        $
-            if (bool_not(is_physical_float(self))):
-                return "Float has no float value"!
-            else:
-                return "OK"!
-        $
+        constraint = $
+            String constraint(model : Element, name : String):
+                if (bool_not(is_physical_float(model["model"][name]))):
+                    return "Float has no float value"!
+                else:
+                    return "OK"!
+            $
     }
 
     AttributeValue String {
-        $
-            if (bool_not(is_physical_string(self))):
-                return "String has no string value"!
-            else:
-                return "OK"!
-        $
+        constraint = $
+            String constraint(model : Element, name : String):
+                if (bool_not(is_physical_string(model["model"][name]))):
+                    return "String has no string value"!
+                else:
+                    return "OK"!
+            $
     }
 
     Class Block{

+ 7 - 6
integration/code/fsa_design.mvc

@@ -3,12 +3,13 @@ include "primitives.alh"
 
 SCD FiniteStateAutomata_Design{
     AttributeValue String {
-        $
-            if (bool_not(is_physical_string(self))):
-                return "String has no string value"!
-            else:
-                return "OK"!
-        $
+        constraint = $
+            String constraint(model : Element, name : String):
+                if (bool_not(is_physical_string(model["model"][name]))):
+                    return "String has no string value"!
+                else:
+                    return "OK"!
+            $
     }
 
     Class State {

+ 7 - 6
integration/code/fsa_runtime.mvc

@@ -3,12 +3,13 @@ include "primitives.alh"
 
 SCD FiniteStateAutomata_Runtime{
     AttributeValue String {
-        $
-            if (bool_not(is_physical_string(self))):
-                return "String has no string value"!
-            else:
-                return "OK"!
-        $
+        constraint = $
+            String constraint(model : Element, name : String):
+                if (bool_not(is_physical_string(model["model"][name]))):
+                    return "String has no string value"!
+                else:
+                    return "OK"!
+            $
     }
 
     Class State {

+ 0 - 1
integration/code/my_petrinet_with_MM.mvc

@@ -1,5 +1,4 @@
 import models/SimpleClassDiagrams as SCD
-include "primitives.alh"
 
 SCD PetriNets{
     AttributeValue Natural {}

+ 0 - 2
integration/code/my_petrinet_with_MM_and_constraints.mvc

@@ -5,8 +5,6 @@ SCD PetriNets{
     SimpleAttribute Natural {
         constraint =
             $
-            include "primitives.alh"
-
             String function constraint_Natural(model : Element, name : String):
                 Element self
                 self = model["model"][name]

+ 0 - 2
integration/code/petrinets_constraints.mvc

@@ -5,8 +5,6 @@ SCD PetriNets{
     SimpleAttribute Natural {
         constraint =
             $
-            include "primitives.alh"
-
             String function constraint_Natural(model : Element, name : String):
                 Element self
                 self = model["model"][name]

+ 18 - 25
integration/code/pn_design_to_runtime.mvc

@@ -1,4 +1,6 @@
 import models/RAM_PetriNets_Design_Runtime as RAM_PN_DR
+include "primitives.alh"
+include "modelling.alh"
 
 RAM_PN_DR annotate {
     Composite schedule {
@@ -16,12 +18,9 @@ RAM_PN_DR annotate {
                 }
                 Post_PetriNets_Runtime/Transition ct2 {
                     label = "1"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(model : Element, name : String, mapping : Element):
-                            instantiate_attribute(model, name, "executing", False)
-                            return!
+                    value_executing = $
+                        Boolean function value(model : Element, name : String, mapping : Element):
+                            return True!
                         $
                 }
                 Post_D2R_TransitionLink (ct1, ct2){
@@ -41,13 +40,13 @@ RAM_PN_DR annotate {
                 }
                 Post_PetriNets_Runtime/Place cp2 {
                     label = "1"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(model : Element, name : String, mapping : Element):
-                            instantiate_attribute(model, name, "tokens", read_attribute(model, mapping["0"], "tokens"))
-                            instantiate_attribute(model, name, "name", read_attribute(model, mapping["0"], "name"))
-                            return!
+                    value_tokens = $
+                        Integer function value(model : Element, name : String, mapping : Element):
+                            return read_attribute(model, mapping["0"], "tokens")!
+                        $
+                    value_name = $
+                        Integer function value(model : Element, name : String, mapping : Element):
+                            return read_attribute(model, mapping["0"], "name")!
                         $
                 }
                 Post_D2R_PlaceLink (cp1, cp2){
@@ -103,12 +102,9 @@ RAM_PN_DR annotate {
                 }
                 Post_PetriNets_Runtime/P2T rhs_cp2t_p2t2(rhs_cp2t_p2, rhs_cp2t_t2) {
                     label = "7"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            instantiate_attribute(host_model, name, "weight", read_attribute(host_model, mapping["2"], "weight"))
-                            return!
+                    value_weight = $
+                        Integer function value(host_model : Element, name : String, mapping : Element):
+                            return read_attribute(host_model, mapping["2"], "weight")!
                         $
                 }
             }
@@ -161,12 +157,9 @@ RAM_PN_DR annotate {
                 }
                 Post_PetriNets_Runtime/T2P (rhs_ct2p_t2, rhs_ct2p_p2) {
                     label = "7"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            instantiate_attribute(host_model, name, "weight", read_attribute(host_model, mapping["2"], "weight"))
-                            return!
+                    value_weight = $
+                        Integer function value(host_model : Element, name : String, mapping : Element):
+                            return read_attribute(host_model, mapping["2"], "weight")!
                         $
                 }
             }

+ 2 - 2
integration/code/pn_print.mvc

@@ -1,4 +1,6 @@
 import models/RAM_PetriNets_Runtime as RAM_PN_R
+include "primitives.alh"
+include "modelling.alh"
 
 RAM_PN_R print {
     Composite schedule {
@@ -13,8 +15,6 @@ RAM_PN_R print {
                 Post_PetriNets/Place {
                     label = "0"
                     action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
                         Void function action(model : Element, name : String, mapping : Element):
                             output((cast_v2s(read_attribute(model, name, "name")) + " --> ") + cast_v2s(read_attribute(model, name, "tokens")))
                             return!

+ 15 - 19
integration/code/pn_runtime_to_design.mvc

@@ -1,4 +1,6 @@
 import models/RAM_PetriNets_Design_Runtime as RAM_PN_DR
+include "primitives.alh"
+include "modelling.alh"
 
 RAM_PN_DR annotate {
     Composite schedule {
@@ -34,13 +36,13 @@ RAM_PN_DR annotate {
                 }
                 Post_PetriNets/Place cp2 {
                     label = "1"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            instantiate_attribute(host_model, name, "tokens", read_attribute(host_model, mapping["0"], "tokens"))
-                            instantiate_attribute(host_model, name, "name", read_attribute(host_model, mapping["0"], "name"))
-                            return!
+                    value_tokens = $
+                        Integer function value(host_model : Element, name : String, mapping : Element):
+                            return read_attribute(host_model, mapping["0"], "tokens")!
+                        $
+                    value_name = $
+                        String function value(host_model : Element, name : String, mapping : Element):
+                            return read_attribute(host_model, mapping["0"], "name")!
                         $
                 }
                 Post_R2D_PlaceLink (cp1, cp2){
@@ -96,12 +98,9 @@ RAM_PN_DR annotate {
                 }
                 Post_PetriNets/P2T rhs_cp2t_p2t2(rhs_cp2t_p2, rhs_cp2t_t2) {
                     label = "7"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            instantiate_attribute(host_model, name, "weight", read_attribute(host_model, mapping["2"], "weight"))
-                            return!
+                    value_weight = $
+                        Integer function value(host_model : Element, name : String, mapping : Element):
+                            return read_attribute(host_model, mapping["2"], "weight")!
                         $
                 }
             }
@@ -154,12 +153,9 @@ RAM_PN_DR annotate {
                 }
                 Post_PetriNets/T2P (rhs_ct2p_t2, rhs_ct2p_p2) {
                     label = "7"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            instantiate_attribute(host_model, name, "weight", read_attribute(host_model, mapping["2"], "weight"))
-                            return!
+                    value_weight = $
+                        Integer function value(host_model : Element, name : String, mapping : Element):
+                            return read_attribute(host_model, mapping["2"], "weight")!
                         $
                 }
             }

+ 23 - 63
integration/code/pn_simulate.mvc

@@ -1,4 +1,6 @@
 import models/RAM_PetriNets_Runtime_Runtime as RAM_PN_R
+include "primitives.alh"
+include "modelling.alh"
 
 RAM_PN_R s {
     Composite schedule {
@@ -21,8 +23,6 @@ RAM_PN_R s {
 					label = "11"
 				}
 				constraint = $
-					include "primitives.alh"
-					include "modelling.alh"
 					Boolean function constraint(host_model : Element, mapping : Element):
 						Integer tokens
 						Integer weight
@@ -34,14 +34,9 @@ RAM_PN_R s {
             RHS {
                 Post_PetriNets_Runtime/Transition {
                     label = "1"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            log("MARK " + name)
-                            unset_attribute(host_model, name, "executing")
-                            instantiate_attribute(host_model, name, "executing", True)
-                            return!
+                    value_executing = $
+                        Boolean function value(host_model : Element, name : String, mapping : Element):
+                            return True!
                         $
                 }
             }
@@ -50,12 +45,9 @@ RAM_PN_R s {
             LHS {
                 Pre_PetriNets_Runtime/Transition lhs_consume_t{
                     label = "0"
-                    constraint = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Boolean function constraint(host_model : Element, name : String):
-                            // Check if this node is executing currently
-                            return value_eq(read_attribute(host_model, name, "executing"), True)!
+                    constraint_executing = $
+                        Boolean function constraint(value : Boolean):
+                            return value!
                         $
                 }
                 Pre_PetriNets_Runtime/Place lhs_consume_p{
@@ -71,20 +63,9 @@ RAM_PN_R s {
                 }
                 Post_PetriNets_Runtime/Place rhs_consume_p {
                     label = "1"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            Integer tokens
-                            Integer weight
-                            tokens = read_attribute(host_model, name, "tokens")
-                            weight = read_attribute(host_model, mapping["2"], "weight")
-                            unset_attribute(host_model, name, "tokens")
-                            instantiate_attribute(host_model, name, "tokens", tokens - weight)
-                            log("Consume for " + cast_v2s(read_attribute(host_model, name, "name")))
-                            log("Previous: " + cast_v2s(tokens))
-                            log("Now: " + cast_v2s(tokens - weight))
-                            return!
+                    value_tokens = $
+                        Integer function value(host_model : Element, name : String, mapping : Element):
+                            return integer_subtraction(read_attribute(host_model, name, "tokens"), read_attribute(host_model, mapping["2"], "weight"))!
                         $
                 }
                 Post_PetriNets_Runtime/P2T (rhs_consume_p, rhs_consume_t){
@@ -96,12 +77,9 @@ RAM_PN_R s {
             LHS {
                 Pre_PetriNets_Runtime/Transition lhs_produce_t{
                     label = "0"
-                    constraint = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Boolean function constraint(host_model : Element, name : String):
-                            // Check if this node is executing currently
-                            return value_eq(read_attribute(host_model, name, "executing"), True)!
+                    constraint_executing = $
+                        Boolean function constraint(value : Boolean):
+                            return value!
                         $
                 }
                 Pre_PetriNets_Runtime/Place lhs_produce_p{
@@ -117,20 +95,9 @@ RAM_PN_R s {
                 }
                 Post_PetriNets_Runtime/Place rhs_produce_p{
                     label = "1"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            Integer tokens
-                            Integer weight
-                            tokens = read_attribute(host_model, name, "tokens")
-                            weight = read_attribute(host_model, mapping["2"], "weight")
-                            unset_attribute(host_model, name, "tokens")
-                            instantiate_attribute(host_model, name, "tokens", tokens + weight)
-                            log("Produce for " + cast_v2s(read_attribute(host_model, name, "name")))
-                            log("Previous: " + cast_v2s(tokens))
-                            log("Now: " + cast_v2s(tokens + weight))
-                            return!
+                    value_tokens = $
+                        Integer function value(host_model : Element, name : String, mapping : Element):
+                            return integer_addition(read_attribute(host_model, name, "tokens"), read_attribute(host_model, mapping["2"], "weight"))!
                         $
                 }
                 Post_PetriNets_Runtime/T2P (rhs_produce_t, rhs_produce_p){
@@ -142,25 +109,18 @@ RAM_PN_R s {
             LHS {
                 Pre_PetriNets_Runtime/Transition {
                     label = "0"
-                    constraint = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Boolean function constraint(host_model : Element, name : String):
-                            // Check if this node is executing currently
-                            return value_eq(read_attribute(host_model, name, "executing"), True)!
+                    constraint_executing = $
+                        Boolean function constraint(value : Boolean):
+                            return value!
                         $
                 }
             }
             RHS {
                 Post_PetriNets_Runtime/Transition {
                     label = "0"
-                    action = $
-                        include "primitives.alh"
-                        include "modelling.alh"
-                        Void function action(host_model : Element, name : String, mapping : Element):
-                            unset_attribute(host_model, name, "executing")
-                            instantiate_attribute(host_model, name, "executing", False)
-                            return!
+                    value_executing = $
+                        Boolean function value(host_model : Element, name : String, mapping : Element):
+                            return False!
                         $
                 }
             }

+ 0 - 127
integration/code/rpgame.mvc

@@ -1,127 +0,0 @@
-import models/SimpleClassDiagrams as SCD
-include "primitives.alh"
-include "object_operations.alh"
-
-SCD RPGame{
-    Class Tile {
-        $
-        Element associations
-        Element back_associations
-        Element association
-        String destination
-        associations = allOutgoingAssociationInstances(model, name, "tile_left")
-        while (0 < list_len(associations)):
-            association = set_pop(associations)
-            destination = readAssociationDestination(model, association)
-            back_associations = allOutgoingAssociationInstances(model, destination, "tile_right")
-            if (list_len(back_associations) < 1):
-                return "Left link does not have a right link back"!
-            else:
-                association = set_pop(back_associations)
-                destination = readAssociationDestination(model, association)
-                if (destination != name):
-                    return "Right link does not have a left link back to the same tile"!
-        associations = allOutgoingAssociationInstances(model, name, "tile_right")
-        while (0 < list_len(associations)):
-            association = set_pop(associations)
-            destination = readAssociationDestination(model, association)
-            back_associations = allOutgoingAssociationInstances(model, destination, "tile_left")
-            if (list_len(back_associations) < 1):
-                return "Right link does not have a left link back"!
-            else:
-                association = set_pop(back_associations)
-                destination = readAssociationDestination(model, association)
-                if (destination != name):
-                    return "Right link does not have a left link back to the same tile"!
-        associations = allOutgoingAssociationInstances(model, name, "tile_top")
-        while (0 < list_len(associations)):
-            association = set_pop(associations)
-            destination = readAssociationDestination(model, association)
-            back_associations = allOutgoingAssociationInstances(model, destination, "tile_bottom")
-            if (list_len(back_associations) < 1):
-                return "Top link does not have a bottom link back"!
-            else:
-                association = set_pop(back_associations)
-                destination = readAssociationDestination(model, association)
-                if (destination != name):
-                    return "Top link does not have a bottom link back to the same tile"!
-        associations = allOutgoingAssociationInstances(model, name, "tile_bottom")
-        while (0 < list_len(associations)):
-            association = set_pop(associations)
-            destination = readAssociationDestination(model, association)
-            back_associations = allOutgoingAssociationInstances(model, destination, "tile_top")
-            if (list_len(back_associations) < 1):
-                return "Bottom link does not have a top link back"!
-            else:
-                association = set_pop(back_associations)
-                destination = readAssociationDestination(model, association)
-                if (destination != name):
-                    return "Bottom link does not have a top link back to the same tile"!
-        return "OK"!
-        $
-    }
-    Association tile_left (Tile, Tile){
-        source_upper_cardinality = 1
-        target_upper_cardinality = 1
-    }
-    Association tile_right (Tile, Tile){
-        source_upper_cardinality = 1
-        target_upper_cardinality = 1
-    }
-    Association tile_top (Tile, Tile){
-        source_upper_cardinality = 1
-        target_upper_cardinality = 1
-    }
-    Association tile_bottom (Tile, Tile){
-        source_upper_cardinality = 1
-        target_upper_cardinality = 1
-    }
-    Class Scene {}
-    Association Scene_has_tiles (Scene, Tile){
-        source_lower_cardinality = 1
-        source_upper_cardinality = 1
-        target_lower_cardinality = 1
-    }
-    Class Item {}
-    Association Item_on_tile (Item, Tile){
-        source_upper_cardinality = 1
-        target_lower_cardinality = 1
-        target_upper_cardinality = 1
-    }
-    Class Goal : Item {}
-    Class Character {}
-    Association Character_on_tile (Character, Tile){
-        source_upper_cardinality = 1
-        target_lower_cardinality = 1
-        target_upper_cardinality = 1
-    }
-    Class Hero : Character {}
-}
-
-export RPGame to models/RPGame
-
-RPGame my_game {
-    Scene scene {}
-    Hero link {}
-    Goal goal {}
-    Tile tile_00 {}
-    Tile tile_01 {}
-    Tile tile_10 {}
-    Tile tile_11 {}
-    Scene_has_tiles (scene, tile_00) {}
-    Scene_has_tiles (scene, tile_01) {}
-    Scene_has_tiles (scene, tile_10) {}
-    Scene_has_tiles (scene, tile_11) {}
-    Character_on_tile (link, tile_00) {}
-    Item_on_tile (goal, tile_11) {}
-    tile_left (tile_01, tile_00) {}
-    tile_right (tile_00, tile_01) {}
-    tile_left (tile_11, tile_10) {}
-    tile_right (tile_10, tile_11) {}
-    tile_top (tile_10, tile_00) {}
-    tile_bottom (tile_00, tile_10) {}
-    tile_top (tile_11, tile_01) {}
-    tile_bottom (tile_01, tile_11) {}
-}
-
-export my_game to models/my_game

+ 0 - 97
integration/code/rpgame_semantics.alc

@@ -1,97 +0,0 @@
-include "primitives.alh"
-include "modelling.alh"
-include "object_operations.alh"
-include "library.alh"
-include "conformance_scd.alh"
-include "random.alh"
-
-Void function main():
-	Element model
-	String verify_result
-
-	while (True):
-		output("Which model do you want to execute with RPGame semantics?")
-		model = import_node(input())
-
-		if (element_eq(model, read_root())):
-			output("Could not find model; aborting")
-		elif (element_neq(model["metamodel"], import_node("models/RPGame"))):
-			log("Got metamodel: " + cast_e2s(model["metamodel"]))
-			log("Expected metamodel: " + cast_e2s(import_node("models/RPGame")))
-			output("Not a RPGame model; aborting")
-		else:
-			verify_result = conformance_scd(model)
-			if (verify_result == "OK"):
-				output("Model OK!")
-				execute_rpgame(model)
-			else:
-				output("Non-conforming model: " + verify_result)
-
-	return!
-
-String function getHeroTile(model : Element, hero : String):
-	return set_pop(followAssociation(model, hero, "Character_on_tile"))!
-
-String function getGoalTile(model : Element, goal : String):
-	return set_pop(followAssociation(model, goal, "Item_on_tile"))!
-
-Void function setHeroTile(model : Element, hero : String, tile : String):
-	Element assocs
-
-	assocs = allOutgoingAssociationInstances(model, hero, "Character_on_tile")
-	while (0 < list_len(assocs)):
-		model_delete_element(model, set_pop(assocs))
-
-	instantiate_link(model, "Character_on_tile", "", hero, tile)
-
-	return!
-
-Element function getConnectedTiles(model : Element, tile : String):
-	Element left
-	Element right
-	Element top
-	Element bottom
-	Element result
-
-	result = create_node()
-	left = followAssociation(model, tile, "tile_left")
-	right = followAssociation(model, tile, "tile_right")
-	top = followAssociation(model, tile, "tile_top")
-	bottom = followAssociation(model, tile, "tile_bottom")
-
-	while (dict_len(left) > 0):
-		set_add(result, set_pop(left))
-	while (dict_len(right) > 0):
-		set_add(result, set_pop(right))
-	while (dict_len(top) > 0):
-		set_add(result, set_pop(top))
-	while (dict_len(bottom) > 0):
-		set_add(result, set_pop(bottom))
-
-	return result!
-
-Void function execute_rpgame(model : Element):
-	String hero
-	String goal
-	String hero_tile
-	String goal_tile
-
-	log("Executing model!")
-
-	// Make the assumption that only a single hero and goal exist
-	hero = set_pop(allInstances(model, "Hero"))
-	goal = set_pop(allInstances(model, "Goal"))
-
-	log("Got all tiles")
-	goal_tile = getGoalTile(model, goal)
-	log("Got goal tile: " + goal_tile)
-	hero_tile = getHeroTile(model, hero)
-	log("Got hero tile: " + hero_tile)
-
-	log("Keep executing")
-	while (hero_tile != goal_tile):
-		output((("Hero: " + hero_tile) + " -- Goal: ") + goal_tile)
-		hero_tile = random_choice(getConnectedTiles(model, hero_tile))
-		setHeroTile(model, hero, hero_tile)
-	output("Hero reached goal!")
-	return!

+ 1 - 2
integration/code/several_petrinets.mvc

@@ -1,12 +1,11 @@
 import models/SimpleClassDiagrams as SCD
 include "primitives.alh"
+include "modelling.alh"
 
 SCD PetriNets{
     SimpleAttribute Natural {
         constraint =
             $
-            include "primitives.alh"
-
             String function constraint_Natural(model : Element, name : String):
                 Element self
                 self = model["model"][name]

+ 1 - 2
interface/HUTN/grammars/modelling.g

@@ -13,8 +13,7 @@ grammar{
 
     model_attribute : ((LCURLY MODEL_ID RCURLY)? model_element)
                     | (MODEL_ID OPTIONAL? COLON MODEL_ID (LCURLY NEWLINE? model_attr_instance* RCURLY)? NEWLINE?)
-                    | (model_attr_instance)
-                    | (NEWLINE? DOLLAR ANYTHING_EXCEPT_DOLLAR DOLLAR NEWLINE?);
+                    | (model_attr_instance);
 
     model_attr_instance: (MODEL_ID ASSIGN value NEWLINE?)
                        | (MODEL_ID ASSIGN NEWLINE? DOLLAR ANYTHING_EXCEPT_DOLLAR DOLLAR NEWLINE?);

+ 2 - 18
interface/HUTN/hutn_compiler/model_visitor.py

@@ -29,7 +29,7 @@ class ModelVisitor(Visitor):
             self.visit(t)
 
     def visit_include_files(self, tree):
-        self.includes.append(tree.get_children("STRVALUE")[0].get_text())
+        self.includes.append('include %s' % tree.get_children("STRVALUE")[0].get_text())
 
     def visit_import(self, tree):
         url = tree.get_children("MV_URL")[0]
@@ -87,7 +87,6 @@ class ModelVisitor(Visitor):
     def visit_model_attribute(self, tree):
         children = tree.get_children("MODEL_ID")
         is_definition = bool(tree.get_children("COLON"))
-        is_constraint = bool(tree.get_children("DOLLAR"))
         is_assign = bool(tree.get_children("model_attr_instance"))
         is_nested = bool(tree.get_children("model_element"))
 
@@ -108,21 +107,6 @@ class ModelVisitor(Visitor):
                 self.current_element.pop()
         elif is_assign:
             self.visit(tree.get_children("model_attr_instance")[0])
-        elif is_constraint:
-            constraint = tree.get_children("ANYTHING_EXCEPT_DOLLAR")[0].get_text()
-            whitespaces = len(constraint) - len(constraint.lstrip())
-            constraint = "\n".join(["\t" + line[whitespaces-1:].replace("    ", "\t") for line in constraint.split("\n") if len(line.strip()) != 0])
-            constraint = "".join(["include %s\n" % i for i in self.includes]) + \
-                         "String function constraint(model : Element, name : String):\n" + \
-                         "\tElement self\n" + \
-                         '\tself = model["model"][name]\n' + \
-                         constraint + "\n"
-            with open(".constraint.alc", 'w') as f:
-                f.write(constraint)
-                f.flush()
-            directory = os.path.realpath(__file__).rsplit(os.sep, 1)[0]
-            compiled = do_compile(".constraint.alc", directory + "/../grammars/actionlanguage.g", "CS")
-            self.constructors.extend(["instantiate_attribute_code", self.current_model, self.current_element[-1], "constraint"] + compiled)
         elif is_nested:
             if tree.get_children("MODEL_ID"):
                 contains_link = tree.get_children("MODEL_ID")[0].get_text()
@@ -138,7 +122,7 @@ class ModelVisitor(Visitor):
 	    code_fragments = [i for i in code_fragments if i.strip() != ""]
 	    code_fragments = [i.replace("    ", "\t") for i in code_fragments]
 	    initial_tabs = min([len(i) - len(i.lstrip("\t")) for i in code_fragments])
-	    code_fragments = [i[initial_tabs:] for i in code_fragments]
+	    code_fragments = self.includes + [i[initial_tabs:] for i in code_fragments]
 	    code = "\n".join(code_fragments)
             code += "\n"