about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/010vm1
-rw-r--r--cpp/012run1
-rw-r--r--cpp/023transform36
3 files changed, 38 insertions, 0 deletions
diff --git a/cpp/010vm b/cpp/010vm
index 53496fde..a8dd451a 100644
--- a/cpp/010vm
+++ b/cpp/010vm
@@ -12,6 +12,7 @@ int Next_recipe_number = 1;
 struct recipe {
   string name;
   vector<instruction> steps;
+  // End Recipe Fields
 };
 
 :(before "struct recipe")
diff --git a/cpp/012run b/cpp/012run
index 3d1395a9..bb084b39 100644
--- a/cpp/012run
+++ b/cpp/012run
@@ -90,6 +90,7 @@ if (argc > 1) {
 //: helper for tests
 
 :(before "End Globals")
+// track recipes added so that we can cleanup after each test
 vector<recipe_number> recipes_added_by_test;
 
 :(code)
diff --git a/cpp/023transform b/cpp/023transform
new file mode 100644
index 00000000..3ab2cdbb
--- /dev/null
+++ b/cpp/023transform
@@ -0,0 +1,36 @@
+//: Let's start making mu more ergonomic to use. We'll create a list of tools
+//: that each transform a recipe. Anybody can add to the list.
+//:
+//: The hope is that this framework of transform tools will provide a
+//: deconstructed alternative to conventional compilers.
+
+:(replace{} "void run(string form)")
+void run(string form) {
+  vector<recipe_number> tmp = add_recipes(form);
+  recipes_added_by_test.insert(recipes_added_by_test.end(), tmp.begin(), tmp.end());
+  transform_all();
+  run(recipes_added_by_test.front());
+}
+
+:(before "End Recipe Fields")
+size_t transformed_until;
+  recipe() :transformed_until(0) {}
+
+:(before "End Types")
+typedef void (*transform_fn)(recipe_number);
+
+:(before "End Globals")
+vector<transform_fn> Transform;
+
+:(code)
+void transform_all() {
+  for (size_t t = 0; t < Transform.size(); ++t) {
+    for (unordered_map<recipe_number, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
+      recipe& r = p->second;
+      if (r.steps.empty()) continue;
+      if (r.transformed_until != t-1) continue;
+      (*Transform[t])(/*recipe_number*/p->first);
+      r.transformed_until = t;
+    }
+  }
+}