瀏覽代碼

First step in removing the ID propagation to client

Yentl Van Tendeloo 9 年之前
父節點
當前提交
3b9cf5c539
共有 24 個文件被更改,包括 68355 次插入68081 次删除
  1. 68308 67928
      bootstrap/bootstrap.m
  2. 6 5
      bootstrap/constructors.alc
  3. 3 3
      integration/test_constructors_al_linkable.py
  4. 4 4
      interface/HUTN/hutn_compiler/constructors_visitor.py
  5. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/action
  6. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/assign
  7. 0 8
      interface/HUTN/test/constructor_compilation_action_language/expected/declare
  8. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/dict_access
  9. 0 32
      interface/HUTN/test/constructor_compilation_action_language/expected/dictionary
  10. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/factorial
  11. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/fibonacci
  12. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/fibonacci_smart
  13. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/funccall_params
  14. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/funcdef_params
  15. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/global
  16. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/ifelse
  17. 0 32
      interface/HUTN/test/constructor_compilation_action_language/expected/list
  18. 0 0
      interface/HUTN/test/constructor_compilation_action_language/expected/selection
  19. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/types
  20. 1 1
      interface/HUTN/test/constructor_compilation_action_language/expected/while
  21. 11 1
      interface/HUTN/test/constructor_compilation_action_language/test_simple.py
  22. 0 27
      interface/HUTN/test/constructor_compilation_action_language/test_real.py
  23. 11 1
      interface/HUTN/test/graph_compilation_action_language/test_simple.py
  24. 0 28
      interface/HUTN/test/graph_compilation_action_language/test_real.py

File diff suppressed because it is too large
+ 68308 - 67928
bootstrap/bootstrap.m


+ 6 - 5
bootstrap/constructors.alc

@@ -5,6 +5,7 @@ include "io.alh"
 include "modelling.alh"
 
 Element while_stack = ?
+Element variable_map = ?
 
 Action function construct_top():
 	String command
@@ -62,7 +63,7 @@ Action function construct_top_funcdef():
 	assign = create_value(!assign)
 	resolve = create_value(!resolve)
 	constant = create_value(!constant)
-	formal = input()
+	formal = dict_read(variable_map, input())
 	func = create_node()
 	params = create_node()
 	dict_add(global, "var", formal)
@@ -86,7 +87,7 @@ Action function construct_top_funcdef():
 		param = create_node()
 		dict_add(params, string_get(arg_names_decl, counter), param)
 		dict_add(param, "name", string_get(arg_names_decl, counter))
-		output(param)
+		dict_add(variable_map, input(), param)
 		// Output each parameter in turn
 		counter = counter + 1
 
@@ -172,7 +173,7 @@ Action function construct_access():
 Action function construct_resolve():
 	Action this_element
 	this_element = create_value(!resolve)
-	dict_add(this_element, "var", input())
+	dict_add(this_element, "var", dict_read(variable_map, input()))
 	return this_element
 
 Action function construct_assign():
@@ -241,7 +242,7 @@ Action function construct_declare():
 	this_element = create_value(!declare)
 	declared_element = create_node()
 	dict_add(this_element, "var", declared_element)
-	output(declared_element)
+	dict_add(variable_map, input(), declared_element)
 	if (input()):
 		dict_add(this_element, "next", construct_unknown())
 	return this_element
@@ -304,7 +305,7 @@ Action function construct_function():
 	while (counter < nrParams):
 		param = create_node()
 		dict_add(params, string_get(arg_names_decl, counter), param)
-		output(param)
+		dict_add(variable_map, input(), param)
 		// Output each parameter in turn
 		counter = counter + 1
 

+ 3 - 3
integration/test_constructors_al_linkable.py

@@ -152,14 +152,14 @@ class TestConstructorsActionLanguageLinkable(unittest.TestCase):
     def test_constructors_declare_and_assign(self):
         commands = [
                     '"declare"',
-                        1,
+                        '"1"',
                         'true',
                     '"assign"',
-                        '"resolve"', 1,
+                        '"resolve"', '"1"',
                         '"const"', '5',
                         'true',
                     '"output"',
-                        '"access"', '"resolve"', 1,
+                        '"access"', '"resolve"', '"1"',
                         'true',
                     '"return"',
                         'true',

+ 4 - 4
interface/HUTN/hutn_compiler/constructors_visitor.py

@@ -52,8 +52,8 @@ class ConstructorsVisitor(Visitor):
             symbol.node = '"%s"' % symbol.name
             self.add_constructors('"global"', symbol.node)
         else:
-            symbol.node = self.free_id
-            self.add_constructors('"declare"', self.free_id)
+            symbol.node = '"%s"' % self.free_id
+            self.add_constructors('"declare"', symbol.node)
             self.free_id += 1
 
     def visit_vardecl(self, tree):
@@ -253,9 +253,9 @@ class ConstructorsVisitor(Visitor):
             return False
 
     def visit_parameter(self, tree):
-        self.add_constructors(self.free_id)
         symbol = self.get_symbol(tree)
-        symbol.node = self.free_id
+        symbol.node = '"%s"' % self.free_id
+        self.add_constructors(symbol.node)
         self.free_id += 1
 
     def visit_return(self, tree):

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/action

@@ -1 +1 @@
-["\"funcdef\"", "\"test\"", "0", "\"declare\"", 0, "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "{\"value\": \"if\"}", "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "{\"value\": \"while\"}", "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "{\"value\": \"assign\"}", "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "{\"value\": \"global\"}", "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "{\"value\": \"call\"}", "false", "false"]
+["\"funcdef\"", "\"test\"", "0", "\"declare\"", "\"0\"", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"if\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"while\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"assign\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"global\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"call\"}", "false", "false"]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/assign

@@ -1 +1 @@
-["\"funcdef\"", "\"test\"", "0", "\"declare\"", 0, "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "1", "false", "false"]
+["\"funcdef\"", "\"test\"", "0", "\"declare\"", "\"0\"", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "1", "false", "false"]

+ 0 - 8
interface/HUTN/test/constructor_compilation_action_language/expected/declare

@@ -1,8 +0,0 @@
-V auto_0(resolve)
-D auto_0,"var",123456
-V auto_1(1)
-V auto_2(constant)
-D auto_2,"node",auto_1
-V auto_initial_IP(assign)
-D auto_initial_IP,"var",auto_0
-D auto_initial_IP,"value",auto_2

File diff suppressed because it is too large
+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/dict_access


+ 0 - 32
interface/HUTN/test/constructor_compilation_action_language/expected/dictionary

@@ -1,32 +0,0 @@
-V auto_0("a")
-V auto_initial_IP(global)
-D auto_initial_IP,"var",auto_0
-V auto_2(resolve)
-D auto_2,"var",auto_0
-N auto_3
-V auto_4(1)
-V auto_5(2)
-E auto_6(auto_3,auto_5)
-E auto_7(auto_6,auto_4)
-V auto_8("abc")
-V auto_9(5)
-E auto_10(auto_3,auto_9)
-E auto_11(auto_10,auto_8)
-V auto_12(1)
-N auto_13
-V auto_14(5)
-V auto_15("def")
-E auto_16(auto_13,auto_15)
-E auto_17(auto_16,auto_14)
-E auto_18(auto_3,auto_13)
-E auto_19(auto_18,auto_12)
-V auto_20(True)
-V auto_21(False)
-E auto_22(auto_3,auto_21)
-E auto_23(auto_22,auto_20)
-V auto_24(constant)
-D auto_24,"node",auto_3
-V auto_25(assign)
-D auto_25,"var",auto_2
-D auto_25,"value",auto_24
-D auto_initial_IP,"next",auto_25

File diff suppressed because it is too large
+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/factorial


File diff suppressed because it is too large
+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/fibonacci


File diff suppressed because it is too large
+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/fibonacci_smart


+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/funccall_params

@@ -1 +1 @@
-["\"funcdef\"", "\"abc\"", "1", 0, "\"assign\"", "\"resolve\"", 0, "\"const\"", "1", "false", "true", "\"funcdef\"", "\"main\"", "0", "\"call\"", "\"access\"", "\"resolve\"", "\"abc\"", "1", "\"const\"", "2", "false", "false"]
+["\"funcdef\"", "\"abc\"", "1", "\"0\"", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "1", "false", "true", "\"funcdef\"", "\"main\"", "0", "\"call\"", "\"access\"", "\"resolve\"", "\"abc\"", "1", "\"const\"", "2", "false", "false"]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/funcdef_params

@@ -1 +1 @@
-["\"funcdef\"", "\"abc\"", "1", 0, "\"assign\"", "\"resolve\"", 0, "\"const\"", "1", "false", "false"]
+["\"funcdef\"", "\"abc\"", "1", "\"0\"", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "1", "false", "false"]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/global

@@ -1 +1 @@
-["\"global\"", "\"a\"", "\"const\"", "1", "true", "\"global\"", "\"b\"", "true", "\"funcdef\"", "\"abc\"", "0", "\"declare\"", 0, "false", "false"]
+["\"global\"", "\"a\"", "\"const\"", "1", "true", "\"global\"", "\"b\"", "true", "\"funcdef\"", "\"abc\"", "0", "\"declare\"", "\"0\"", "false", "false"]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/ifelse

@@ -1 +1 @@
-["\"funcdef\"", "\"main\"", "0", "\"declare\"", 0, "true", "\"if\"", "\"const\"", "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "2", "false", "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "3", "false", "false", "false"]
+["\"funcdef\"", "\"main\"", "0", "\"declare\"", "\"0\"", "true", "\"if\"", "\"const\"", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "2", "false", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "3", "false", "false", "false"]

+ 0 - 32
interface/HUTN/test/constructor_compilation_action_language/expected/list

@@ -1,32 +0,0 @@
-V auto_0("a")
-V auto_initial_IP(global)
-D auto_initial_IP,"var",auto_0
-V auto_2(resolve)
-D auto_2,"var",auto_0
-N auto_3
-V auto_4("a")
-D auto_3,0,auto_4
-V auto_5("b")
-D auto_3,1,auto_5
-V auto_6(4)
-D auto_3,2,auto_6
-V auto_7(6)
-D auto_3,3,auto_7
-V auto_8("def")
-D auto_3,4,auto_8
-N auto_9
-V auto_10("g")
-D auto_9,0,auto_10
-V auto_11("h")
-D auto_9,1,auto_11
-V auto_12(3)
-D auto_9,2,auto_12
-D auto_3,5,auto_9
-V auto_13(3)
-D auto_3,6,auto_13
-V auto_14(constant)
-D auto_14,"node",auto_3
-V auto_15(assign)
-D auto_15,"var",auto_2
-D auto_15,"value",auto_14
-D auto_initial_IP,"next",auto_15

+ 0 - 0
interface/HUTN/test/constructor_compilation_action_language/expected/selection


+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/types

@@ -1 +1 @@
-["\"funcdef\"", "\"main\"", "0", "\"declare\"", 0, "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "{\"value\": \"Integer\"}", "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "{\"value\": \"Type\"}", "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "{\"value\": \"Action\"}", "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "{\"value\": \"String\"}", "false", "false"]
+["\"funcdef\"", "\"main\"", "0", "\"declare\"", "\"0\"", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"Integer\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"Type\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"Action\"}", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "{\"value\": \"String\"}", "false", "false"]

+ 1 - 1
interface/HUTN/test/constructor_compilation_action_language/expected/while

@@ -1 +1 @@
-["\"funcdef\"", "\"main\"", "0", "\"declare\"", 0, "true", "\"while\"", "\"const\"", "true", "\"assign\"", "\"resolve\"", 0, "\"const\"", "2", "false", "false", "false"]
+["\"funcdef\"", "\"main\"", "0", "\"declare\"", "\"0\"", "true", "\"while\"", "\"const\"", "true", "\"assign\"", "\"resolve\"", "\"0\"", "\"const\"", "2", "false", "false", "false"]

+ 11 - 1
interface/HUTN/test/constructor_compilation_action_language/test_simple.py

@@ -15,7 +15,7 @@ def compile_file(obj, filename):
         pass
     assert result == expected
 
-class TestSimple(unittest.TestCase):
+class TestCompile(unittest.TestCase):
     def test_assign(self):
         compile_file(self, "assign.al")
 
@@ -57,3 +57,13 @@ class TestSimple(unittest.TestCase):
 
     def test_dict_access(self):
         compile_file(self, "dict_access.al")
+
+    def test_fibonacci(self):
+        compile_file(self, "fibonacci.al")
+
+    def test_fibonacci_smart(self):
+        compile_file(self, "fibonacci_smart.al")
+
+    def test_factorial(self):
+        compile_file(self, "factorial.al")
+

+ 0 - 27
interface/HUTN/test/constructor_compilation_action_language/test_real.py

@@ -1,27 +0,0 @@
-import unittest
-import util
-
-from hutn_compiler.compiler import main
-import json
-
-def compile_file(obj, filename):
-    result = main(util.get_code_path(filename), "grammars/actionlanguage.g", "CS", [])
-    try:
-        expected = json.loads(open(util.get_expected_path(filename)).read())
-    except:
-        #f = open(util.get_expected_path(filename), 'w')
-        #f.write(json.dumps(result))
-        #f.close()
-        pass
-    assert result == expected
-
-class TestReal(unittest.TestCase):
-    def test_fibonacci(self):
-        compile_file(self, "fibonacci.al")
-
-    def test_fibonacci_smart(self):
-        compile_file(self, "fibonacci_smart.al")
-
-    def test_factorial(self):
-        compile_file(self, "factorial.al")
-

+ 11 - 1
interface/HUTN/test/graph_compilation_action_language/test_simple.py

@@ -17,7 +17,7 @@ def compile_file(obj, filename):
         pass
     assert result == expected
 
-class TestSimple(unittest.TestCase):
+class TestCompile(unittest.TestCase):
     def test_assign(self):
         compile_file(self, "assign.al")
 
@@ -59,3 +59,13 @@ class TestSimple(unittest.TestCase):
 
     def test_dict_access(self):
         compile_file(self, "dict_access.al")
+
+    def test_fibonacci(self):
+        compile_file(self, "fibonacci.al")
+
+    def test_fibonacci_smart(self):
+        compile_file(self, "fibonacci_smart.al")
+
+    def test_factorial(self):
+        compile_file(self, "factorial.al")
+

+ 0 - 28
interface/HUTN/test/graph_compilation_action_language/test_real.py

@@ -1,28 +0,0 @@
-import unittest
-import util
-from postproc import postproc
-
-from hutn_compiler.compiler import main
-
-def compile_file(obj, filename):
-    result = main(util.get_code_path(filename), "grammars/actionlanguage.g", "PS", [])
-    expected = open(util.get_expected_path(filename)).read()
-    result = postproc(result)
-    expected = postproc(expected)
-    if result != expected:
-        #f = open(util.get_expected_path(filename), 'w')
-        #f.write(result)
-        #f.close()
-        pass
-    assert result == expected
-
-class TestReal(unittest.TestCase):
-    def test_fibonacci(self):
-        compile_file(self, "fibonacci.al")
-
-    def test_fibonacci_smart(self):
-        compile_file(self, "fibonacci_smart.al")
-
-    def test_factorial(self):
-        compile_file(self, "factorial.al")
-