about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-20 20:32:05 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-20 20:32:05 -0800
commit7232de7061e8c370ad6cf76988489d78e269f8b9 (patch)
tree65e9ec1e7f935f3718718e836c79e0f0a7ff03ee
parenta4559f7287599a981a3b38a82b741f57d50e85c4 (diff)
downloadmu-7232de7061e8c370ad6cf76988489d78e269f8b9.tar.gz
802 - mu comments
Comments at end of line are still hacky; we just rely on the fact that
excess ingredients do no harm. We'll need to be smarter when we get our
first vararg recipe.
-rw-r--r--cpp/.traces/get_address6
-rw-r--r--cpp/011load16
-rw-r--r--cpp/017and-record6
3 files changed, 20 insertions, 8 deletions
diff --git a/cpp/.traces/get_address b/cpp/.traces/get_address
index 5b8510e4..359df5d0 100644
--- a/cpp/.traces/get_address
+++ b/cpp/.traces/get_address
@@ -7,6 +7,12 @@ parse/0:   product: {name: "13", type: 2}
 parse/0: instruction: 19
 parse/0:   ingredient: {name: "12", type: 3}
 parse/0:   ingredient: {name: "1", type: 0}
+parse/0:   ingredient: {name: "#", type: 0}
+parse/0:   ingredient: {name: "todo", type: 0}
+parse/0:   ingredient: {name: "product", type: 0}
+parse/0:   ingredient: {name: "is", type: 0}
+parse/0:   ingredient: {name: "an", type: 0}
+parse/0:   ingredient: {name: "address", type: 0}
 parse/0:   product: {name: "15", type: 1}
 run/0: instruction 0
 run/0: ingredient 0 is 34
diff --git a/cpp/011load b/cpp/011load
index f2855e5f..0193eeac 100644
--- a/cpp/011load
+++ b/cpp/011load
@@ -13,6 +13,7 @@ int add_recipe(string form) {
   istringstream in(form);
   in >> std::noskipws;
 
+  skip_comments_and_newlines(in);
   string _recipe = next_word(in);
   if (_recipe != "recipe")
     raise << "top-level forms must be of the form 'recipe _name_ [ _instruction_ ... ]'\n";
@@ -25,7 +26,7 @@ int add_recipe(string form) {
   if (next_word(in) != "[")
     raise << "recipe body must begin with '['\n";
 
-  skip_newlines(in);
+  skip_comments_and_newlines(in);
 
   instruction curr;
   while (next_instruction(in, &curr)) {
@@ -38,7 +39,7 @@ bool next_instruction(istream& in, instruction* curr) {
   curr->clear();
   if (in.eof()) return false;
   skip_whitespace(in);  if (in.eof()) return false;
-  skip_newlines(in);  if (in.eof()) return false;
+  skip_comments_and_newlines(in);  if (in.eof()) return false;
 
   vector<string> words;
   while (in.peek() != '\n') {
@@ -47,7 +48,7 @@ bool next_instruction(istream& in, instruction* curr) {
     words.push_back(word);
     skip_whitespace(in);  if (in.eof()) return false;
   }
-  skip_newlines(in);  if (in.eof()) return false;
+  skip_comments_and_newlines(in);  if (in.eof()) return false;
 
   if (words.size() == 1 && *(words[0].end()-1) == ':') {
     curr->is_label = true;
@@ -112,9 +113,14 @@ void skip_whitespace(istream& in) {
   }
 }
 
-void skip_newlines(istream& in) {
-  while (in.peek() == '\n')
+void skip_comments_and_newlines(istream& in) {
+  while (in.peek() == '\n' || in.peek() == '#') {
+    if (in.peek() == '#') {
+      in.get();
+      while (in.peek() != '\n') in.get();
+    }
     in.get();
+  }
 }
 
 void skip_comma(istream& in) {
diff --git a/cpp/017and-record b/cpp/017and-record
index f38b031f..359fd2bc 100644
--- a/cpp/017and-record
+++ b/cpp/017and-record
@@ -12,9 +12,9 @@ vector<type_number> b;
 b.push_back(boolean);
 Type[integer_boolean].elements.push_back(b);
 
-// Records can be copied around with a single instruction just like integers,
-// no matter how large they are.
 :(scenario copy_multiple_locations)
+# Records can be copied around with a single instruction just like integers,
+# no matter how large they are.
 recipe main [
   1:integer <- copy 34:literal
   2:boolean <- copy 0:literal
@@ -105,7 +105,7 @@ case GET_ADDRESS: {
 recipe main [
   12:integer <- copy 34:literal
   13:boolean <- copy 0:literal
-  15:integer <- get-address 12:integer-boolean, 1:offset
+  15:integer <- get-address 12:integer-boolean, 1:offset  # todo: product is an address
 ]
 +run: instruction 2
 +run: ingredient 0 is 12