Kaynağa Gözat

Small extension to bootstrap primitives (list_pop) and some minor changes to test to include a test for transformations

Yentl Van Tendeloo 8 yıl önce
ebeveyn
işleme
b9d6aeb2ae

+ 6 - 0
bootstrap/primitives.alc

@@ -173,3 +173,9 @@ Integer function integer_modulo(a : Integer, b : Integer):
 
 Boolean function has_input():
 	return (element_neq(dict_read(read_userroot(), "input"), dict_read(read_userroot(),"last_input")))!
+
+Element function list_pop(lst : Element, index : Integer):
+	Element v
+	v = list_read(lst, index)
+	list_delete(lst, index)
+	return v!

+ 10 - 0
bootstrap/transform.alc

@@ -51,3 +51,13 @@ Element function make_matching_schedule(LHS_model : Element):
 						set_add(workset, reverseKeyLookup(LHS_model["model"], read_out(LHS_model["model"][next], counter)))
 
 	return schedule!
+
+Void function transform(host_model : Element, LHS_model : Element, RHS_model : Element):
+	Element schedule
+
+	schedule = make_matching_schedule(LHS_model)
+	output("Got schedule")
+	while (read_nr_out(schedule) > 0):
+		output(list_pop(schedule, 0))
+
+	return!

+ 21 - 0
integration/code/pn_interface.alc

@@ -8,6 +8,7 @@ include "metamodels.alh"
 include "modelling.alh"
 include "compilation_manager.alh"
 include "ramify.alh"
+include "transform.alh"
 
 Element function model_loaded(model : Element):
 	String cmd
@@ -373,5 +374,25 @@ Element function main():
 				output("success")
 			else:
 				output("Model not found; aborting")
+		elif (command == "transform"):
+			Element result
+			String lhs
+			String rhs
+			output("Which model do you want to transform?")
+			name = input()
+			if (dict_in(root, name)):
+				output("Which LHS do you want to match?")
+				lhs = input()
+				if (dict_in(root, lhs)):
+					output("Which RHS do you want to rewrite?")
+					rhs = input()
+					if (dict_in(root, rhs)):
+						transform(root[name], root[lhs], root[rhs])
+					else:
+						output("Unknown RHS selected!")
+				else:
+					output("Unknown LHS selected!")
+			else:
+				output("Unknown host model selected!")
 		else:
 			output("Command not recognized, use 'help' for a list of possible commands")

+ 32 - 0
integration/test_pn_interface.py

@@ -30,6 +30,7 @@ all_files = [   "pn_interface.alc",
                 "object_operations.alc",
                 "conformance_scd.alc",
                 "library.alc",
+                "transform.alc",
                 "ramify.alc",
                 "metamodels.alc",
                 "constructors.alc",
@@ -536,3 +537,34 @@ Element function constraint(model : Element, name : String):
                 (instantiate_edge + prompt) * 14 + \
                 ["OK"],
             mode))
+
+    def test_po_pn_interface_transform(self):
+        self.assertTrue(run_file(all_files,
+            ["new", "PetriNets", "pn",
+                "instantiate", "Place", "p1",
+                "instantiate", "Place", "p2",
+                "instantiate", "Transition", "t1",
+                "instantiate", "P2T", "p2t", "p1", "t1",
+                "instantiate", "P2T", "p2t2", "p2", "t1",
+                "attr_add", "p1", "tokens", 5,
+                "attr_add", "p2", "tokens", 2,
+                "attr_add", "p2t", "weight", 1,
+                "attr_add", "p2t2", "weight", 2,
+                "verify", "exit",
+             "ramify", "PetriNets",
+             "new", "PetriNets_PRE", "pn_LHS",
+                "instantiate", "LHS", "lhs",
+                "instantiate", "Pre_Place", "p",
+                "instantiate", "Pre_Transition", "t",
+                "instantiate", "Pre_P2T", "pt",
+                "instantiate", "LHS_contains", "", "lhs", "p",
+                "instantiate", "LHS_contains", "", "lhs", "t",
+                "instantiate", "LHS_contains", "", "lhs", "pt",
+                "attr_add", "p", "label", "old_p",
+                "attr_add", "t", "label", "old_t",
+                "attr_add", "pt", "label", "old_pt",
+                "verify", "exit",
+             "transform", "pn", "PetriNets_PRE", "PetriNets_PRE",
+                ],
+            None, "PO"))
+

+ 5 - 0
integration/utils.py

@@ -146,6 +146,11 @@ def run_file(files, parameters, expected, mode):
         flush_data(address, parameters)
         
         # ... and wait for replies
+        if expected is None:
+            while 1:
+                val = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username})), timeout=240).read()
+                val = json.loads(val)
+                print(val)
         for e in expected:
             c = len(e) if isinstance(e, set) else 1
             for _ in range(c):

+ 1 - 0
interface/HUTN/includes/primitives.alh

@@ -95,3 +95,4 @@ Float function time()
 Element function exec(a : Element)
 Element function resolve(var_name : String)
 Boolean function has_input()
+Element function list_pop(lst : Element, index : Integer)

+ 2 - 0
interface/HUTN/includes/transform.alh

@@ -0,0 +1,2 @@
+Element function make_matching_schedule(LHS_model : Element)
+Void function transform(host_model : Element, LHS_model : Element, RHS_model : Element)