Parcourir la source

Removed manual json serialization in most code generators and in tests

Yentl Van Tendeloo il y a 8 ans
Parent
commit
ae85a354ed

+ 0 - 2
hybrid_server/classes/mvkcontroller.xml

@@ -101,8 +101,6 @@
                                     else:
                                         print("Decode " + str(data["data"]))
                                         value = json.loads(data["data"])
-                                        #TODO don't double encode it in the sender!
-                                        value = [json.loads(v) for v in value]
                                     self.input_queue[data["username"]].append((source, value))
                                 elif data["op"] == "get_output":
                                     self.output_queue[data["username"]].append(source)

+ 2 - 2
integration/test_binary2decimal.py

@@ -12,6 +12,6 @@ class TestBinary2Decimal(unittest.TestCase):
 
     def binary2decimal(self, mode):
         self.assertTrue(run_file(["binary_to_decimal.alc", "primitives.alc"],
-            ['"1"', '"10"', '"11"', '"100"', '"001"', '"1100111101"'],
-            ["1", "2", "3", "4", "1", "829"],
+            ["1", "10", "11", "100", "001", "1100111101"],
+            [1, 2, 3, 4, 1, 829],
             mode))

+ 2 - 2
integration/test_factorial.py

@@ -12,6 +12,6 @@ class TestFactorial(unittest.TestCase):
 
     def factorial(self, mode):
         self.assertTrue(run_file(["factorial.alc", "primitives.alc"],
-            ['1', '2', '3', '4'],
-            ["1", "2", "6", "24"],
+            [1, 2, 3, 4],
+            [1, 2, 6, 24],
             mode))

+ 2 - 2
integration/test_fibonacci.py

@@ -12,6 +12,6 @@ class TestFibonacci(unittest.TestCase):
 
     def fibonacci(self, mode):
         self.assertTrue(run_file(["fibonacci.alc", "primitives.alc"],
-            ['1', '2', '3', '4'],
-            ["1", "1", "2", "3"],
+            [1, 2, 3, 4],
+            [1, 1, 2, 3],
             mode))

+ 2 - 2
integration/test_fibonacci_smart.py

@@ -12,6 +12,6 @@ class TestFibonacciSmart(unittest.TestCase):
 
     def fibonacci_smart(self, mode):
         self.assertTrue(run_file(["fibonacci_smart.alc", "primitives.alc"],
-            ['1', '2', '3', '4', '5', '6', '7', '8'],
-            ["1", "1", "2", "3", "5", "8", "13", "21"],
+            [1, 2, 3, 4, 5, 6, 7, 8],
+            [1, 1, 2, 3, 5, 8, 13, 21],
             mode))

+ 4 - 4
integration/test_if_elif.py

@@ -12,8 +12,8 @@ class TestIfElif(unittest.TestCase):
 
     def if_elif_else(self, mode):
         self.assertTrue(run_file(["if_elif_else.alc", "primitives.alc"],
-            ['-1', '10', '11', '0', '1', '0', '-100'],
-            ["-1", "1", "1", "0", "1", "0", "-1"],
+            [-1, 10, 11, 0, 1, 0, -100],
+            [-1, 1, 1, 0, 1, 0, -1],
             mode))
 
     def test_po_if_elif(self):
@@ -24,6 +24,6 @@ class TestIfElif(unittest.TestCase):
 
     def if_elif(self, mode):
         self.assertTrue(run_file(["if_elif.alc", "primitives.alc"],
-                                 ['-1', '10', '11', '0', '1', '0', '-100'],
-                                 ["-1", "1", "1", "0", "1", "0", "-1"],
+                                 [-1, 10, 11, 0, 1, 0, -100],
+                                 [-1, 1, 1, 0, 1, 0, -1],
                                  mode))

+ 2 - 2
integration/test_leap_year.py

@@ -12,6 +12,6 @@ class TestLeapYear(unittest.TestCase):
 
     def leap_year(self, mode):
         self.assertTrue(run_file(["leap_year.alc", "primitives.alc"],
-            ['2016', '2015', '2014', '2013', '2012', '2001', '2000', '1999'],
-            ["True", "False", "False", "False", "True", "False", "False", "False"],
+            [2016, 2015, 2014, 2013, 2012, 2001, 2000, 1999],
+            [True, False, False, False, True, False, False, False],
             mode))

+ 114 - 114
integration/test_pn_interface.py

@@ -8,12 +8,12 @@ set_inheritance = [
     ]
 
 do_instantiate_simple = [
-            '"new"', '"PetriNets"', '"abc"',
-            '"instantiate"', '"Transition"', '"t1"',
-            '"instantiate"', '"Place"', '"p1"', '"attr_add"', '"p1"', '"tokens"', '5',
-            '"instantiate"', '"Place"', '"p2"', '"attr_add"', '"p2"', '"tokens"', '0',
-            '"instantiate"', '"P2T"', '"p2t"', '"p1"', '"t1"', '"attr_add"', '"p2t"', '"weight"', '2',
-            '"instantiate"', '"T2P"', '"t2p"', '"t1"', '"p2"', '"attr_add"', '"t2p"', '"weight"', '1']
+            "new", "PetriNets", "abc",
+            "instantiate", "Transition", "t1",
+            "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
+            "instantiate", "Place", "p2", "attr_add", "p2", "tokens", 0,
+            "instantiate", "P2T", "p2t", "p1", "t1", "attr_add", "p2t", "weight", 2,
+            "instantiate", "T2P", "t2p", "t1", "p2", "attr_add", "t2p", "weight", 1]
 
 instantiate_node = ["Type to instantiate?",
                     "Name of new element?",
@@ -145,17 +145,17 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_manage(self, mode):
         self.assertTrue(run_file(all_files,
-            ['"list"',
-             '"new"', '"PetriNets"', '"abc"', '"exit"',
-             '"list"',
-             '"new"', '"PetriNets"', '"def"', '"exit"',
-             '"list"',
-             '"delete"', '"def"',
-             '"list"',
-             '"rename"', '"abc"', '"a"',
-             '"list"',
-             '"delete"', '"a"',
-             '"list"',
+            ["list",
+             "new", "PetriNets", "abc", "exit",
+             "list",
+             "new", "PetriNets", "def", "exit",
+             "list",
+             "delete", "def",
+             "list",
+             "rename", "abc", "a",
+             "list",
+             "delete", "a",
+             "list",
              ],
             init + \
                 list_menu([]) + prompt + \
@@ -174,7 +174,7 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_new_reload(self, mode):
         self.assertTrue(run_file(all_files,
-            ['"new"', '"PetriNets"', '"abc"', '"exit"', '"load"', '"abc"'],
+            ["new", "PetriNets", "abc", "exit", "load", "abc"],
             init + new + loaded + prompt + load + loaded,
             mode))
 
@@ -186,14 +186,14 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_instantiate_place(self, mode):
         self.assertTrue(run_file(all_files,
-            ['"new"', '"PetriNets"', '"abc"',
-            '"instantiate"', '"Place"', '"p1"',
-            '"attr_add"', '"p1"', '"tokens"', '5',
-            '"list"',
-            '"read"', '"p1"',
-            '"instantiate"', '"Transition"', '"t1"',
-            '"list"',
-            '"read"', '"t1"'],
+            ["new", "PetriNets", "abc",
+            "instantiate", "Place", "p1",
+            "attr_add", "p1", "tokens", 5,
+            "list",
+            "read", "p1",
+            "instantiate", "Transition", "t1",
+            "list",
+            "read", "t1"],
             init + new + loaded + \
                 instantiate_node + prompt + \
                 attr_add + prompt + \
@@ -213,11 +213,11 @@ class TestPetrinetInterface(unittest.TestCase):
     def pn_interface_instantiate_arcs(self, mode):
         self.assertTrue(run_file(all_files,
             do_instantiate_simple + [
-                    '"read"', '"p1"',
-                    '"read"', '"p2"',
-                    '"read"', '"t1"',
-                    '"read"', '"p2t"',
-                    '"read"', '"t2p"',
+                    "read", "p1",
+                    "read", "p2",
+                    "read", "t1",
+                    "read", "p2t",
+                    "read", "t2p",
                 ],
             did_instantiate_simple + \
                 read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
@@ -235,7 +235,7 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_verify_OK(self, mode):
         self.assertTrue(run_file(all_files,
-            do_instantiate_simple + ['"verify"'],
+            do_instantiate_simple + ["verify"],
             did_instantiate_simple + ["OK"], mode))
 
     def test_po_pn_interface_verify_fail_tokens(self):
@@ -246,7 +246,7 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_verify_fail_tokens(self, mode):
         self.assertTrue(run_file(all_files,
-            do_instantiate_simple + ['"modify"', '"p1"', '"tokens"', '-5', '"verify"'],
+            do_instantiate_simple + ["modify", "p1", "tokens", -5, "verify"],
             did_instantiate_simple + modify + prompt + verify_fail_tokens + prompt, mode))
 
     def test_po_pn_interface_verify_fail_weight(self):
@@ -257,7 +257,7 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_verify_fail_weight(self, mode):
         self.assertTrue(run_file(all_files,
-            do_instantiate_simple + ['"modify"', '"p2t"', '"weight"', '-2', '"verify"'],
+            do_instantiate_simple + ["modify", "p2t", "weight", -2, "verify"],
             did_instantiate_simple + modify + prompt + verify_fail_weight + prompt, mode))
 
     def test_po_pn_interface_verify_fail_structure(self):
@@ -268,10 +268,10 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_verify_fail_structure(self, mode):
         self.assertTrue(run_file(all_files,
-            ['"new"', '"PetriNets"', '"abc"',
-            '"instantiate"', '"Transition"', '"t1"',
-            '"instantiate"', '"Place"', '"p1"', '"attr_add"', '"p1"', '"tokens"', '5',
-            '"instantiate"', '"P2T"', '"p2t"', '"t1"', '"p1"', '"attr_add"', '"p2t"', '"weight"', '2', '"verify"'],
+            ["new", "PetriNets", "abc",
+            "instantiate", "Transition", "t1",
+            "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
+            "instantiate", "P2T", "p2t", "t1", "p1", "attr_add", "p2t", "weight", 2, "verify"],
             init + new + loaded + \
                 instantiate_node + prompt + \
                 instantiate_node + prompt + attr_add + prompt + \
@@ -287,7 +287,7 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_types(self, mode):
         self.assertTrue(run_file(all_files,
-            ['"new"', '"PetriNets"', '"abc"', '"types"'],
+            ["new", "PetriNets", "abc", "types"],
             init + new + loaded + list_types([("Place", "Class"), ("Transition", "Class"), ("P2T", "Association"), ("T2P", "Association"), ("Natural", "Class")]),
             mode))
 
@@ -299,10 +299,10 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_modify_place(self, mode):
         self.assertTrue(run_file(all_files,
-            ['"new"', '"PetriNets"', '"abc"',
-                '"instantiate"', '"Place"', '"p1"', '"attr_add"', '"p1"', '"tokens"', '5',
-                '"read"', '"p1"',
-                '"modify"', '"p1"', '"tokens"', '1', '"read"', '"p1"'],
+            ["new", "PetriNets", "abc",
+                "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
+                "read", "p1",
+                "modify", "p1", "tokens", 1, "read", "p1"],
             init + new + loaded + \
                 instantiate_node + prompt + attr_add + prompt + \
                 read_node("p1", "Place", [], [("tokens", "Natural", 5)]) + prompt + \
@@ -318,7 +318,7 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_verify_fail_attr_lower_cardinality(self, mode):
         self.assertTrue(run_file(all_files,
-            do_instantiate_simple + ['"instantiate"', '"Place"', '"p999"', '"verify"'],
+            do_instantiate_simple + ["instantiate", "Place", "p999", "verify"],
             did_instantiate_simple + instantiate_node + prompt + ["Lower cardinality violation for outgoing edge of type Place_tokens at p999"] + prompt,
             mode))
 
@@ -330,7 +330,7 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_verify_fail_attr_upper_cardinality(self, mode):
         self.assertTrue(run_file(all_files,
-            do_instantiate_simple + ['"attr_add"', '"p1"', '"tokens"', '5', '"verify"'],
+            do_instantiate_simple + ["attr_add", "p1", "tokens", 5, "verify"],
             did_instantiate_simple + attr_add + prompt + ["Upper cardinality violation for outgoing edge of type Place_tokens at p1"] + prompt,
             mode))
 
@@ -342,12 +342,12 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_verify_natural(self, mode):
         self.assertTrue(run_file(all_files,
-            ['"new"', '"PetriNets"', '"abc"',
-            '"instantiate"', '"Place"', '"p1"',
-            '"attr_add"', '"p1"', '"tokens"', '-5',
-            '"attr_del"', '"p1"', '"tokens"',
-            '"attr_add"', '"p1"', '"tokens"', '4',
-            '"verify"'],
+            ["new", "PetriNets", "abc",
+            "instantiate", "Place", "p1",
+            "attr_add", "p1", "tokens", -5,
+            "attr_del", "p1", "tokens",
+            "attr_add", "p1", "tokens", 4,
+            "verify"],
             init + new + loaded + \
             instantiate_node + prompt + \
             attr_add + prompt + \
@@ -364,7 +364,7 @@ class TestPetrinetInterface(unittest.TestCase):
 
     def pn_interface_verify_PN_OK(self, mode):
         self.assertTrue(run_file(all_files,
-            ['"load"', '"PetriNets"', '"verify"'],
+            ["load", "PetriNets", "verify"],
             init + load + loaded + ["OK"], mode))
 
     def test_po_rpgame(self):
@@ -440,68 +440,68 @@ Element function constraint(model : Element, name : String):
         print(constructors)
 
         self.assertTrue(run_file(all_files,
-            ['"new"', '"SimpleClassDiagrams"', '"RPGame"',
-                '"set_inheritance"', '"Inheritance"',
-                '"instantiate"', '"Class"', '"Scene"',
-                '"instantiate"', '"Class"', '"Tile"',
-                '"instantiate"', '"Class"', '"Item"',
-                '"instantiate"', '"Class"', '"Goal"',
-                '"instantiate"', '"Class"', '"Character"',
-                '"instantiate"', '"Class"', '"Hero"',
-                '"instantiate"', '"Association"', '"scene_has_tiles"', '"Scene"', '"Tile"',
-                '"instantiate"', '"Association"', '"tile_left"', '"Tile"', '"Tile"',
-                '"instantiate"', '"Association"', '"tile_right"', '"Tile"', '"Tile"',
-                '"instantiate"', '"Association"', '"tile_top"', '"Tile"', '"Tile"',
-                '"instantiate"', '"Association"', '"tile_bottom"', '"Tile"', '"Tile"',
-                '"instantiate"', '"Association"', '"character_on"', '"Character"', '"Tile"',
-                '"instantiate"', '"Association"', '"item_on"', '"Item"', '"Tile"',
-                '"instantiate"', '"Inheritance"', '"hero_is_character"', '"Hero"', '"Character"',
-                '"instantiate"', '"Inheritance"', '"goal_is_item"', '"Goal"', '"Item"',
-                '"attr_add"', '"Scene"', '"lower_cardinality"', '1',
-                '"attr_add"', '"Scene"', '"upper_cardinality"', '1',
-                '"attr_add"', '"Goal"', '"lower_cardinality"', '1',
-                '"attr_add"', '"scene_has_tiles"', '"source_lower_cardinality"', '1',
-                '"attr_add"', '"scene_has_tiles"', '"source_upper_cardinality"', '1',
-                '"attr_add"', '"scene_has_tiles"', '"target_lower_cardinality"', '1',
-                '"attr_add"', '"item_on"', '"target_lower_cardinality"', '1',
-                '"attr_add"', '"item_on"', '"target_upper_cardinality"', '1',
-                '"attr_add"', '"item_on"', '"source_upper_cardinality"', '1',
-                '"attr_add"', '"character_on"', '"target_lower_cardinality"', '1',
-                '"attr_add"', '"character_on"', '"target_upper_cardinality"', '1',
-                '"attr_add"', '"character_on"', '"source_upper_cardinality"', '1',
-                '"attr_add"', '"tile_left"', '"source_upper_cardinality"', '1',
-                '"attr_add"', '"tile_left"', '"target_upper_cardinality"', '1',
-                '"attr_add"', '"tile_right"', '"source_upper_cardinality"', '1',
-                '"attr_add"', '"tile_right"', '"target_upper_cardinality"', '1',
-                '"attr_add"', '"tile_top"', '"source_upper_cardinality"', '1',
-                '"attr_add"', '"tile_top"', '"target_upper_cardinality"', '1',
-                '"attr_add"', '"tile_bottom"', '"source_upper_cardinality"', '1',
-                '"attr_add"', '"tile_bottom"', '"target_upper_cardinality"', '1',
-                '"constrain"', '"Tile"',
-            ] + constructors + ['"verify"'] + ['"exit"'] + [
-                '"new"', '"RPGame"', '"my_game"',
-                '"instantiate"', '"Scene"', '"scene"',
-                '"instantiate"', '"Hero"', '"Link"',
-                '"instantiate"', '"Goal"', '"goal"',
-                '"instantiate"', '"Tile"', '"tile_00"',
-                '"instantiate"', '"Tile"', '"tile_01"',
-                '"instantiate"', '"Tile"', '"tile_10"',
-                '"instantiate"', '"Tile"', '"tile_11"',
-                '"instantiate"', '"scene_has_tiles"', '""', '"scene"', '"tile_00"',
-                '"instantiate"', '"scene_has_tiles"', '""', '"scene"', '"tile_01"',
-                '"instantiate"', '"scene_has_tiles"', '""', '"scene"', '"tile_10"',
-                '"instantiate"', '"scene_has_tiles"', '""', '"scene"', '"tile_11"',
-                '"instantiate"', '"character_on"', '""',  '"Link"', '"tile_00"',
-                '"instantiate"', '"item_on"', '""', '"goal"', '"tile_11"',
-                '"instantiate"', '"tile_left"', '""', '"tile_01"', '"tile_00"',
-                '"instantiate"', '"tile_left"', '""', '"tile_11"', '"tile_10"',
-                '"instantiate"', '"tile_right"', '""', '"tile_00"', '"tile_01"',
-                '"instantiate"', '"tile_right"', '""', '"tile_10"', '"tile_11"',
-                '"instantiate"', '"tile_top"', '""', '"tile_10"', '"tile_00"',
-                '"instantiate"', '"tile_top"', '""', '"tile_11"', '"tile_01"',
-                '"instantiate"', '"tile_bottom"', '""', '"tile_00"', '"tile_10"',
-                '"instantiate"', '"tile_bottom"', '""', '"tile_01"', '"tile_11"',
-                '"verify"',
+            ["new", "SimpleClassDiagrams", "RPGame",
+                "set_inheritance", "Inheritance",
+                "instantiate", "Class", "Scene",
+                "instantiate", "Class", "Tile",
+                "instantiate", "Class", "Item",
+                "instantiate", "Class", "Goal",
+                "instantiate", "Class", "Character",
+                "instantiate", "Class", "Hero",
+                "instantiate", "Association", "scene_has_tiles", "Scene", "Tile",
+                "instantiate", "Association", "tile_left", "Tile", "Tile",
+                "instantiate", "Association", "tile_right", "Tile", "Tile",
+                "instantiate", "Association", "tile_top", "Tile", "Tile",
+                "instantiate", "Association", "tile_bottom", "Tile", "Tile",
+                "instantiate", "Association", "character_on", "Character", "Tile",
+                "instantiate", "Association", "item_on", "Item", "Tile",
+                "instantiate", "Inheritance", "hero_is_character", "Hero", "Character",
+                "instantiate", "Inheritance", "goal_is_item", "Goal", "Item",
+                "attr_add", "Scene", "lower_cardinality", 1,
+                "attr_add", "Scene", "upper_cardinality", 1,
+                "attr_add", "Goal", "lower_cardinality", 1,
+                "attr_add", "scene_has_tiles", "source_lower_cardinality", 1,
+                "attr_add", "scene_has_tiles", "source_upper_cardinality", 1,
+                "attr_add", "scene_has_tiles", "target_lower_cardinality", 1,
+                "attr_add", "item_on", "target_lower_cardinality", 1,
+                "attr_add", "item_on", "target_upper_cardinality", 1,
+                "attr_add", "item_on", "source_upper_cardinality", 1,
+                "attr_add", "character_on", "target_lower_cardinality", 1,
+                "attr_add", "character_on", "target_upper_cardinality", 1,
+                "attr_add", "character_on", "source_upper_cardinality", 1,
+                "attr_add", "tile_left", "source_upper_cardinality", 1,
+                "attr_add", "tile_left", "target_upper_cardinality", 1,
+                "attr_add", "tile_right", "source_upper_cardinality", 1,
+                "attr_add", "tile_right", "target_upper_cardinality", 1,
+                "attr_add", "tile_top", "source_upper_cardinality", 1,
+                "attr_add", "tile_top", "target_upper_cardinality", 1,
+                "attr_add", "tile_bottom", "source_upper_cardinality", 1,
+                "attr_add", "tile_bottom", "target_upper_cardinality", 1,
+                "constrain", "Tile",
+            ] + constructors + ["verify"] + ["exit"] + [
+                "new", "RPGame", "my_game",
+                "instantiate", "Scene", "scene",
+                "instantiate", "Hero", "Link",
+                "instantiate", "Goal", "goal",
+                "instantiate", "Tile", "tile_00",
+                "instantiate", "Tile", "tile_01",
+                "instantiate", "Tile", "tile_10",
+                "instantiate", "Tile", "tile_11",
+                "instantiate", "scene_has_tiles", "", "scene", "tile_00",
+                "instantiate", "scene_has_tiles", "", "scene", "tile_01",
+                "instantiate", "scene_has_tiles", "", "scene", "tile_10",
+                "instantiate", "scene_has_tiles", "", "scene", "tile_11",
+                "instantiate", "character_on", "",  "Link", "tile_00",
+                "instantiate", "item_on", "", "goal", "tile_11",
+                "instantiate", "tile_left", "", "tile_01", "tile_00",
+                "instantiate", "tile_left", "", "tile_11", "tile_10",
+                "instantiate", "tile_right", "", "tile_00", "tile_01",
+                "instantiate", "tile_right", "", "tile_10", "tile_11",
+                "instantiate", "tile_top", "", "tile_10", "tile_00",
+                "instantiate", "tile_top", "", "tile_11", "tile_01",
+                "instantiate", "tile_bottom", "", "tile_00", "tile_10",
+                "instantiate", "tile_bottom", "", "tile_01", "tile_11",
+                "verify",
             ],
             init + new + loaded + \
                 set_inheritance + prompt + \

+ 2 - 2
integration/test_power.py

@@ -12,5 +12,5 @@ class TestPower(unittest.TestCase):
 
     def power(self, mode):
         self.assertTrue(run_file(["power.alc", "primitives.alc"],
-            ['1', '0', '2', '1', '5', '0', '2', '2', '3', '2', '10', '2', '10', '10'],
-            ["1", "2", "1", "4", "9", "100", "10000000000"], mode))
+            [1, 0, 2, 1, 5, 0, 2, 2, 3, 2, 10, 2, 10, 10],
+            [1, 2, 1, 4, 9, 100, 10000000000], mode))

+ 2 - 2
integration/test_remainder.py

@@ -12,5 +12,5 @@ class TestRemainder(unittest.TestCase):
 
     def remainder(self, mode):
         self.assertTrue(run_file(["remainder.alc", "primitives.alc"],
-            ['1', '2', '20', '2', '99', '100', '17', '3'],
-            ["1", "0", "99", "2"], mode))
+            [1, 2, 20, 2, 99, 100, 17, 3],
+            [1, 0, 99, 2], mode))

+ 1 - 1
integration/test_revert.py

@@ -12,6 +12,6 @@ class TestRevert(unittest.TestCase):
 
     def revert(self, mode):
         self.assertTrue(run_file(["revert.alc", "primitives.alc"],
-            ['"abc"', '"defghi"', '"This is a very simple test case!"', '"abccba"'],
+            ["abc", "defghi", "This is a very simple test case!", "abccba"],
             ["cba", "ihgfed", "!esac tset elpmis yrev a si sihT", "abccba"],
             mode))

+ 10 - 8
integration/utils.py

@@ -147,6 +147,7 @@ def run_file(files, parameters, expected, mode):
             c = len(e) if isinstance(e, set) else 1
             for _ in range(c):
                 val = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username})), timeout=240).read()
+                val = json.loads(val)
 
                 if proc.returncode is not None:
                     # Modelverse has already terminated, which isn't a good sign!
@@ -154,12 +155,12 @@ def run_file(files, parameters, expected, mode):
 
                 print("Got %s, expect %s" % (val, e))
                 if isinstance(e, set):
-                    assert str(val) in e
-                    if str(val) not in e:
+                    assert val in e
+                    if val not in e:
                         return False
                 else:
-                    assert str(val) == e
-                    if str(val) != e:
+                    assert val == e
+                    if val != e:
                         return False
 
         # All passed!
@@ -239,6 +240,7 @@ def run_barebone(parameters, expected, interface="0", timeout=False, wait=False,
                         return False
 
                     val = urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "get_output", "username": username})), timeout=240 if not timeout else 20).read()
+                    val = json.loads(val)
                 except:
                     if timeout:
                         return True
@@ -247,12 +249,12 @@ def run_barebone(parameters, expected, interface="0", timeout=False, wait=False,
 
                 print("Got %s, expect %s" % (val, e))
                 if isinstance(e, set):
-                    assert str(val) in e
-                    if str(val) not in e:
+                    assert val in e
+                    if val not in e:
                         return False
                 else:
-                    assert str(val) == e
-                    if str(val) != e:
+                    assert val == e
+                    if val != e:
                         return False
 
         # All passed!

+ 6 - 9
interface/HUTN/hutn_compiler/constructors_object_visitor.py

@@ -31,7 +31,7 @@ class ConstructorsObjectVisitor(ConstructorsVisitor):
                 urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "set_input", "data": json.dumps(data), "username": self.username})), timeout=timeout).read()
             return []
 
-        flush_data(['3', '"is_defined"', '"%s"' % self.obj_file])
+        flush_data([3, "is_defined", self.obj_file])
 
         v = urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "get_output", "username": self.username}))).read()
         simple_filename = self.real_file.rsplit("/")[-1]
@@ -44,7 +44,7 @@ class ConstructorsObjectVisitor(ConstructorsVisitor):
                 print("[COMPILE] %s" % simple_filename)
 
                 # Remove in Modelverse and recompile
-                flush_data(['3', '"remove_obj"', '"%s"' % self.obj_file])
+                flush_data([3, "remove_obj", self.obj_file])
             else:
                 self.visit = lambda i: i
                 self.dump = lambda: True
@@ -60,21 +60,18 @@ class ConstructorsObjectVisitor(ConstructorsVisitor):
             return []
 
         # Set up interface
-        flush_data(['3', '"upload"', '"%s"' % self.obj_file, '"%s"' % self.hash_file, 'true'])
+        flush_data([3, "upload", self.obj_file, self.hash_file, True])
         flush_data(v)
 
         # Upload symbol table
         data = []
         for e, v in self.object_symbols.iteritems():
-            data.append("true")
-            data.append('"%s"' % e)
-            data.append("true" if v else "false")
+            data.extend([True, e, v])
+        # Finish the symbol table
+        data.append(False)
 
         urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "set_input", "data": json.dumps(data), "username": self.username}))).read()
 
-        # Finish the symbol table
-        urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "set_input", "value": 'false', "username": self.username}))).read()
-
         # Wait for kernel to signal that it finished
         urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "set_input", "value": '2', "username": self.username}))).read()
         v = urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "get_output", "username": self.username}))).read()

+ 45 - 47
interface/HUTN/hutn_compiler/constructors_visitor.py

@@ -20,7 +20,7 @@ class ConstructorsVisitor(Visitor):
         # declare all functions
         for child in tree.get_children("funcdecl"):
             if self.pre_visit_funcdecl(child):
-                self.add_constructors('true')
+                self.add_constructors(True)
 
         tail = tree.get_tail_without(["newline"])
         # tail = tree.get_children("funcdecl") +\
@@ -36,24 +36,24 @@ class ConstructorsVisitor(Visitor):
                 if child.head == "func_call":  # pop 'false'
                     self.constructors.pop()
                 if new_constructors_were_added:
-                    self.add_constructors('true')
+                    self.add_constructors(True)
         new_constructors_were_added = self.visit(last)
         if last.head == "func_call":  # pop 'false'
             self.constructors.pop()
         if new_constructors_were_added:
             if last.head != "return":
-                self.add_constructors('false')
+                self.add_constructors(False)
         elif self.constructors:
             self.constructors.pop()  # pop 'true'
-            self.add_constructors('false')
+            self.add_constructors(False)
 
     def declare(self, symbol):
         if symbol.is_global:
-            symbol.node = '"%s"' % symbol.name
-            self.add_constructors('"global"', symbol.node)
+            symbol.node = symbol.name
+            self.add_constructors("global", symbol.node)
         else:
-            symbol.node = '"%s"' % self.free_id
-            self.add_constructors('"declare"', symbol.node)
+            symbol.node = str(self.free_id)
+            self.add_constructors("declare", symbol.node)
             self.free_id += 1
 
     def visit_vardecl(self, tree):
@@ -62,7 +62,7 @@ class ConstructorsVisitor(Visitor):
         return True
 
     def visit_assignment(self, tree):
-        self.add_constructors('"assign"')
+        self.add_constructors("assign")
         self.visit(tree.get_tail()[0])
         self.visit(tree.get_tail()[2])
         return True
@@ -104,19 +104,19 @@ class ConstructorsVisitor(Visitor):
         self.visit_children(tree)
 
     def visit_type_specifier(self, tree):
-        self.add_constructors('"const"',
-            '{"value": "%s"}' % (tree.get_text()))
+        self.add_constructors("const",
+            {"value": tree.get_text()})
 
     def visit_actionname(self, tree):
-        self.add_constructors('"const"',
-            '{"value": "%s"}' % (tree.get_tail()[0].get_text()[1:]))
+        self.add_constructors("const",
+            {"value": tree.get_tail()[0].get_text()[1:]})
 
     def visit_string(self, tree):
         self.visit_literal(tree)
 
     # there is no such rule in the grammar, we just avoid code duplicates
     def visit_literal(self, tree):
-        self.add_constructors('"const"', tree.get_text())
+        self.add_constructors("const", tree.get_text())
 
     def visit_integer(self, tree):
         self.visit_literal(tree)
@@ -125,7 +125,7 @@ class ConstructorsVisitor(Visitor):
         self.visit_literal(tree)
 
     def visit_rvalue(self, tree):
-        self.add_constructors('"access"')
+        self.add_constructors("access")
         self.visit_lvalue(tree)
 
     def visit_lvalue(self, tree):
@@ -133,28 +133,28 @@ class ConstructorsVisitor(Visitor):
         # TODO: split visit_funcdecl in pre_visit_funcdecl and visit_funcdecl
         if symbol.node is None:
             raise Exception("Undefined variable: %s" % (symbol.name))
-        self.add_constructors('"resolve"', symbol.node)
+        self.add_constructors("resolve", symbol.node)
 
     def visit_func_call(self, tree):
         symbol = self.get_symbol(tree.get_tail()[0])
-        self.add_constructors('"call"')
+        self.add_constructors("call")
         if hasattr(symbol, "pathmv"):
-            self.add_constructors('"deref"', symbol.pathmv)
+            self.add_constructors("deref", symbol.pathmv)
         else:
             self.visit(tree.get_tail()[0])
         expressions = tree.get_children("expression")
-        self.add_constructors(str(len(expressions)))
+        self.add_constructors(len(expressions))
         for expression in expressions:
             self.visit(expression)
-        self.add_constructors('false')
+        self.add_constructors(False)
         return True
 
     def visit_input(self, tree):
-        self.add_constructors('"input"')
+        self.add_constructors("input")
         return True
 
     def visit_output(self, tree):
-        self.add_constructors('"output"')
+        self.add_constructors("output")
         self.visit(tree.get_child("expression"))
         return True
 
@@ -168,30 +168,30 @@ class ConstructorsVisitor(Visitor):
         pass  # TODO: list and dictionary
 
     def visit_ifelse(self, tree):
-        self.add_constructors('"if"')
+        self.add_constructors("if")
         expressions = tree.get_children("expression")
         blocks = tree.get_children("block")
         self.visit(expressions[0])  # condition
         self.visit(blocks[0])  # then-clause
 
         for e, b in zip(expressions[1:], blocks[1:]):
-            self.add_constructors('true', '"if"')  # else-if-clause
+            self.add_constructors(True, "if")  # else-if-clause
             self.visit(e)
             self.visit(b)
 
         if len(expressions) != len(blocks):
-            self.add_constructors('true')  # else-clause
+            self.add_constructors(True)  # else-clause
             self.visit(blocks[-1])
         else:
-            self.add_constructors('false')  # no else_clause
+            self.add_constructors(False)  # no else_clause
 
         for i in range(len(expressions)-1):
-            self.add_constructors('false')  # no next
+            self.add_constructors(False)  # no next
 
         return True
 
     def visit_while(self, tree):
-        self.add_constructors('"while"')
+        self.add_constructors("while")
         self.visit(tree.get_child("expression"))
         self.visit(tree.get_child("block"))
         return True
@@ -207,12 +207,12 @@ class ConstructorsVisitor(Visitor):
                 self.visit(child)
                 if child.head == "func_call":  # pop 'false'
                     self.constructors.pop()
-                self.add_constructors('true')
+                self.add_constructors(True)
         self.visit(last)
         if last.head == "func_call":  # pop 'false'
             self.constructors.pop()
         if last.head != "return":
-            self.add_constructors('false')
+            self.add_constructors(False)
 
     def visit_func_body(self, tree):
         self.visit_children(tree)
@@ -220,7 +220,7 @@ class ConstructorsVisitor(Visitor):
     def pre_visit_funcdecl(self, tree):
         func_body = tree.get_child("func_body")
         symbol = self.get_symbol(tree)
-        symbol.node = '"%s"' % symbol.name
+        symbol.node = symbol.name
         return False
 
     def visit_funcdecl(self, tree):
@@ -229,8 +229,8 @@ class ConstructorsVisitor(Visitor):
         if func_body:
             if symbol.name in ["input", "output"]:
                 return False
-            self.add_constructors('"funcdef"', symbol.node,
-                                  str(len(symbol.params)))
+            self.add_constructors("funcdef", symbol.node,
+                                  len(symbol.params))
             for p in tree.get_children("parameter"):
                 self.visit(p)
             self.visit(func_body)
@@ -239,12 +239,10 @@ class ConstructorsVisitor(Visitor):
             # TODO: fix funcdecl special case: "X function f(...) = ..."
             # Note: replicates "Element x; x = ?primiteves/a" behavior
             # Dangerous: SemanticsVisitor handles it as a function
-            pathmv = tree.get_child("ANYTHING").get_text()
-
             # pathmv is needed in visit_func_call(self, tree)
-            symbol.pathmv = '"{}"'.format(pathmv)
+            symbol.pathmv = tree.get_child("ANYTHING").get_text()
 
-            self.add_constructors('"global"', symbol.node, '"deref"', symbol.pathmv)
+            self.add_constructors("global", symbol.node, "deref", symbol.pathmv)
 
             # reason: "X function f(Y) = Z" adds no constructors
             return True
@@ -254,32 +252,32 @@ class ConstructorsVisitor(Visitor):
 
     def visit_parameter(self, tree):
         symbol = self.get_symbol(tree)
-        symbol.node = '"%s"' % self.free_id
+        symbol.node = str(self.free_id)
         self.add_constructors(symbol.node)
         self.free_id += 1
 
     def visit_return(self, tree):
-        self.add_constructors('"return"')
+        self.add_constructors("return")
         if len(tree.get_tail()) > 2:
-            self.add_constructors('true')
+            self.add_constructors(True)
             self.visit(tree.get_tail()[1])
         else:
-            self.add_constructors('false')
+            self.add_constructors(False)
         return True
 
     def visit_bool(self, tree):
         if tree.get_text() == "True":
-            self.add_constructors('"const"', 'true')
+            self.add_constructors("const", True)
         else:
-            self.add_constructors('"const"', 'false')
+            self.add_constructors("const", False)
 
     def visit_definition(self, tree):
         # First declare it
         symbol = self.get_symbol(tree)
-        symbol.node = '"%s"' % symbol.name
+        symbol.node = symbol.name
 
         # Now generate constructors
-        self.add_constructors('"global"', '"%s"' % symbol.name)
+        self.add_constructors("global", symbol.name)
 
         # Determine whether it is just a constant, or a deref
         atom = tree.get_child("atomvalue")
@@ -288,9 +286,9 @@ class ConstructorsVisitor(Visitor):
             dest = atom.get_child("deref").get_child("ANYTHING")
             if dest is None:
                 # Just an empty questionmark!
-                self.add_constructors('"empty"')
+                self.add_constructors("empty")
             else:
-                self.add_constructors('"deref"', '"%s"' % dest.get_text())
+                self.add_constructors("deref", dest.get_text())
         else:
             # Constant
             self.visit(atom)

+ 7 - 13
interface/HUTN/hutn_compiler/primitives_object_visitor.py

@@ -30,7 +30,7 @@ class PrimitivesObjectVisitor(PrimitivesVisitor):
         # Check if file is already compiled (with same hash) in Modelverse
         urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "set_input", "element_type": "V", "value": '"%s"' % self.username, "username": "user_manager"}))).read()
 
-        flush_data(['3', '"is_defined"', '"%s"' % self.obj_file])
+        flush_data([3, "is_defined", self.obj_file])
 
         v = urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "get_output", "username": self.username}))).read()
         v = json.loads(v)
@@ -44,7 +44,7 @@ class PrimitivesObjectVisitor(PrimitivesVisitor):
                 print("[COMPILE] %s" % simple_filename)
 
                 # Remove in Modelverse and recompile
-                flush_data(['3', '"remove_obj"', '"%s"' % self.obj_file])
+                flush_data([3, "remove_obj", self.obj_file])
             else:
                 self.visit = lambda i: i
                 self.dump = lambda: True
@@ -55,26 +55,20 @@ class PrimitivesObjectVisitor(PrimitivesVisitor):
         data = []
 
         # Set up interface
-        data.append("3")
+        data = [3, "upload", self.obj_file, self.hash_file, False]
 
         # Start uploading the code
-        data.append('"upload"')
-        data.append('"%s"' % (self.obj_file))
-        data.append('"%s"' % (self.hash_file))
-        data.append('false')
-        data.append(json.dumps(v))
+        data.append(v)
 
         # Upload symbol table
         for e, v in self.object_symbols.iteritems():
-            data.append("true")
-            data.append('"%s"' % e)
-            data.append("true" if v else "false")
+            data.extend([True, e, v])
 
         # Finish the symbol table
-        data.append('false')
+        data.append(False)
 
         # Wait for kernel to signal that it finished
-        data.append('2')
+        data.append(2)
 
         urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "set_input", "data": json.dumps(data), "username": self.username}))).read()
         v = urllib2.urlopen(urllib2.Request(self.address, urllib.urlencode({"op": "get_output", "username": self.username}))).read()

+ 10 - 11
interface/HUTN/hutn_compiler/primitives_visitor.py

@@ -1,5 +1,6 @@
 import string
 from visitor import Visitor
+import json
 
 class PrimitivesVisitor(Visitor):
     def __init__(self, args):
@@ -11,7 +12,7 @@ class PrimitivesVisitor(Visitor):
 
     def debug(self, node, tree, msg=""):
         if self.debug_symbols:
-            self.dict(node, "__debug", self.value('"[%s] %s"' % (tree.get_reference_line(), msg)))
+            self.dict(node, "__debug", self.value("[%s] %s" % (tree.get_reference_line(), msg)))
 
     def node(self):
         self.output.append(("N", self.free_id))
@@ -21,12 +22,10 @@ class PrimitivesVisitor(Visitor):
     def dict(self, src, val, trgt):
         if src is None or trgt is None:
             raise Exception("Got None")
-        if isinstance(val, str):
-            val = "\"%s\"" % val
         self.output.append(("D", (src, val, trgt)))
 
     def value(self, value):
-        self.output.append(("V", (self.free_id, value)))
+        self.output.append(("V", (self.free_id, json.dumps(value))))
         self.free_id += 1
         return self.free_id - 1
 
@@ -101,7 +100,7 @@ class PrimitivesVisitor(Visitor):
 
         if symbol.is_global:
             d = self.value("global")
-            n = self.value('"%s"' % symbol.name)
+            n = self.value(symbol.name)
         else:
             d = self.value("declare")
             n = self.node()
@@ -223,7 +222,7 @@ class PrimitivesVisitor(Visitor):
         arg_nodes_reversed = []
 
         for i in reversed(range(len(expressions))):
-            arg_name = '"{}"'.format(string.ascii_lowercase[i])
+            arg_name = string.ascii_lowercase[i]
 
             arg_node = self.node()
             name_node = self.value(arg_name)
@@ -331,7 +330,7 @@ class PrimitivesVisitor(Visitor):
         new_value = self.node()
         self.function_values[symbol.name] = new_value
 
-        root = self.value('"%s"' % symbol.name)
+        root = self.value(symbol.name)
         symbol.node = root
         declare = self.value("global")
         self.dict(declare, "var", root)
@@ -366,14 +365,14 @@ class PrimitivesVisitor(Visitor):
                     self.dict(ps, string.ascii_lowercase[i], n)
 
                     # Add the name in case we want to pre-compile in the MvK
-                    self.dict(n, "name", self.value('"%s"' % string.ascii_lowercase[i]))
+                    self.dict(n, "name", self.value(string.ascii_lowercase[i]))
             b = self.get_primitive(func_body)
             self.dict(vf, "body", b)
         else:
             # TODO: fix funcdecl special case: "X function f(...) = ..."
             # Note: replicates "Element x; x = ?primiteves/a" behavior
             # Dangerous: SemanticsVisitor handles it as a function
-            root = self.value('"%s"' % symbol.name)
+            root = self.value(symbol.name)
             symbol.node = root
 
             if tree.get_child("ASSIGN"):
@@ -401,7 +400,7 @@ class PrimitivesVisitor(Visitor):
 
     def visit_definition(self, tree):
         symbol = self.get_symbol(tree)
-        root = self.value('"%s"' % symbol.name)
+        root = self.value(symbol.name)
 
         declare = self.value("global")
         self.dict(declare, "var", root)
@@ -424,7 +423,7 @@ class PrimitivesVisitor(Visitor):
             resolve = self.value("resolve")
             self.dict(call, "func", access)
             self.dict(access, "var", resolve)
-            self.dict(resolve, "var", self.value('"create_node"'))
+            self.dict(resolve, "var", self.value("create_node"))
             value = call
 
         self.dict(assign, "value", value)

+ 1 - 0
kernel/modelverse_kernel/primitives.py

@@ -515,6 +515,7 @@ def deserialize(a, root, **remainder):
             yield [("CD", [source, value, target])]
         else:
             print("Unknown graph type: " + str(graph_type))
+    print("Done deserialize")
     raise PrimitiveFinished(id_mappings["auto_initial_IP"])
 
 def log(a, **remainder):