Added two more compiler passes
authorDavid Kerkeslager <kerkeslager@gmail.com>
Sat, 30 Dec 2017 09:04:48 +0000 (04:04 -0500)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Sat, 30 Dec 2017 09:04:48 +0000 (04:04 -0500)
conversion.py [new file with mode: 0644]
desugaring.py [new file with mode: 0644]
main.py

diff --git a/conversion.py b/conversion.py
new file mode 100644 (file)
index 0000000..8c47a4d
--- /dev/null
@@ -0,0 +1,13 @@
+import collections
+
+CPSProgram = collections.namedtuple(
+    'CPSProgram',
+    (
+        'statement_list',
+    ),
+)
+
+def convert(program):
+    return CPSProgram(
+        statement_list=program.statement_list,
+    )
diff --git a/desugaring.py b/desugaring.py
new file mode 100644 (file)
index 0000000..ef51639
--- /dev/null
@@ -0,0 +1,13 @@
+import collections
+
+DesugaredProgram = collections.namedtuple(
+    'DesugaredProgram',
+    (
+        'statement_list',
+    ),
+)
+
+def desugar(program):
+    return DesugaredProgram(
+        statement_list=program.statement_list,
+    )
diff --git a/main.py b/main.py
index be48e78..c649a0b 100644 (file)
--- a/main.py
+++ b/main.py
@@ -1,5 +1,7 @@
 import sys
 
+import conversion
+import desugaring
 import generation
 import normalization
 import parsing
@@ -13,8 +15,10 @@ with open(source_path, 'r') as f:
 
 tokens = tokenization.tokenize(source)
 parsed = parsing.parse(tokens)
-normalized = normalization.normalize(parsed)
-transformed = transformation.transform(normalized)
+desugared = desugaring.desugar(parsed)
+normalized = normalization.normalize(desugared)
+converted = conversion.convert(normalized)
+transformed = transformation.transform(converted)
 generated = generation.generate(transformed)
 
 assert source_path.endswith('.fur')