about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-17 13:28:28 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-17 13:28:28 -0800
commit0c0eee435482df5e58634cf7d26e3016bba4cf12 (patch)
tree62ab71c70399db019d99375cc9fde81bc640b50f /cpp
parentd51db07c6fd4f661220730b9c9470a7267869ba2 (diff)
downloadmu-0c0eee435482df5e58634cf7d26e3016bba4cf12.tar.gz
772
Diffstat (limited to 'cpp')
-rw-r--r--cpp/002main.cc12
-rw-r--r--cpp/002main.test.cc15
2 files changed, 26 insertions, 1 deletions
diff --git a/cpp/002main.cc b/cpp/002main.cc
index 0eaea16a..ec03cf45 100644
--- a/cpp/002main.cc
+++ b/cpp/002main.cc
@@ -165,7 +165,9 @@ void setup_types() {
 }
 
 void setup_recipes() {
-  Recipe.clear();  Recipe_number.clear();  Next_recipe_number = 1;
+  Recipe.clear();  Recipe_number.clear();
+  Recipe_number["idle"] = 0;
+  Next_recipe_number = 1;
   Recipe_number["copy"] = Next_recipe_number++;
 //?   dbg << "AAA " << Recipe_number["copy"] << '\n'; //? 1
 }
@@ -220,6 +222,14 @@ bool next_instruction(istream& in, instruction* curr) {
 //?   cout << '\n'; //? 1
 //?   return true; //? 1
 
+  if (words.size() == 1 && *(words[0].end()-1) == ':') {
+    curr->is_label = true;
+    words[0].erase(words[0].end()-1);
+    curr->label = words[0];
+    trace("parse") << "label: " << curr->label;
+    return !in.eof();
+  }
+
   vector<string>::iterator p = words.begin();
   if (find(words.begin(), words.end(), "<-") != words.end()) {
 //?     cout << "instruction yields products\n"; //? 1
diff --git a/cpp/002main.test.cc b/cpp/002main.test.cc
index 52db64bb..cc14762a 100644
--- a/cpp/002main.test.cc
+++ b/cpp/002main.test.cc
@@ -21,6 +21,21 @@ void test_parse() {
   CHECK_EQ(i->products[0].properties.size(), 0);
 }
 
+void test_parse_label() {
+  compile("recipe main [\n"
+          "  foo:\n"
+          "]\n");
+  cout << '\n'; DUMP("parse");
+  CHECK(Recipe_number.find("main") != Recipe_number.end());
+  recipe r = Recipe[Recipe_number["main"]];
+  vector<instruction>::iterator i = r.step.begin();
+  CHECK_EQ(i->is_label, true);
+  CHECK_EQ(i->label, string("foo"));
+  CHECK_EQ(i->operation, 0);
+  CHECK_EQ(i->ingredients.size(), 0);
+  CHECK_EQ(i->products.size(), 0);
+}
+
 void test_parse2() {
   compile("recipe main [\n"
           "  1:integer, 2:integer <- copy 23:literal\n"
dac981ca78c49c5100eb2211b7'>3c435756 ^
3f9ee8f5 ^
3c435756 ^



51530916 ^






5f05e954 ^



51530916 ^


1ba81b0f ^
5f05e954 ^




1ba81b0f ^
51530916 ^


be16deb0 ^
b39ceb27 ^
26785f2a ^
b39ceb27 ^
8f249677 ^
b39ceb27 ^

51530916 ^


455f0338 ^

385ff136 ^
455f0338 ^



51530916 ^



fb4836dc ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137