diff options
-rw-r--r-- | 010vm.cc | 4 | ||||
-rw-r--r-- | 042name.cc | 8 | ||||
-rw-r--r-- | 056recipe_header.cc | 8 | ||||
-rw-r--r-- | 061recipe.cc | 23 | ||||
-rw-r--r-- | 062scheduler.cc | 22 | ||||
-rw-r--r-- | 063wait.cc | 4 | ||||
-rw-r--r-- | 071channel.mu | 2 | ||||
-rw-r--r-- | 091run_interactive.cc | 2 | ||||
-rw-r--r-- | Readme.md | 2 | ||||
-rw-r--r-- | channel.mu | 4 | ||||
-rw-r--r-- | chessboard.mu | 14 | ||||
-rw-r--r-- | fork.mu | 2 | ||||
-rw-r--r-- | mu.vim | 1 |
13 files changed, 47 insertions, 49 deletions
diff --git a/010vm.cc b/010vm.cc index 59229ad6..94fa23b7 100644 --- a/010vm.cc +++ b/010vm.cc @@ -248,14 +248,14 @@ reagent::reagent(string s) :original_string(s), value(0), initialized(false), ty name = properties.at(0).first; type = new_type_tree(properties.at(0).second); if (is_integer(name) && type == NULL) { - type = new type_tree(0); assert(!properties.at(0).second); properties.at(0).second = new string_tree("literal"); + type = new type_tree(get(Type_ordinal, "literal")); } if (name == "_" && type == NULL) { - type = new type_tree(0); assert(!properties.at(0).second); properties.at(0).second = new string_tree("dummy"); + type = new type_tree(get(Type_ordinal, "literal")); } // End Parsing reagent } diff --git a/042name.cc b/042name.cc index 2622f41c..7ad45b89 100644 --- a/042name.cc +++ b/042name.cc @@ -44,18 +44,20 @@ void transform_names(const recipe_ordinal r) { // End transform_names(inst) Special-cases // map names to addresses for (long long int in = 0; in < SIZE(inst.ingredients); ++in) { + if (disqualified(inst.ingredients.at(in), inst, caller.name)) continue; if (is_numeric_location(inst.ingredients.at(in))) numeric_locations_used = true; if (is_named_location(inst.ingredients.at(in))) names_used = true; - if (disqualified(inst.ingredients.at(in), inst, caller.name)) continue; + if (is_integer(inst.ingredients.at(in).name)) continue; if (!already_transformed(inst.ingredients.at(in), names)) { raise_error << maybe(caller.name) << "use before set: " << inst.ingredients.at(in).name << '\n' << end(); } inst.ingredients.at(in).set_value(lookup_name(inst.ingredients.at(in), r)); } for (long long int out = 0; out < SIZE(inst.products); ++out) { + if (disqualified(inst.products.at(out), inst, caller.name)) continue; if (is_numeric_location(inst.products.at(out))) numeric_locations_used = true; if (is_named_location(inst.products.at(out))) names_used = true; - if (disqualified(inst.products.at(out), inst, caller.name)) continue; + if (is_integer(inst.products.at(out).name)) continue; if (names.find(inst.products.at(out).name) == names.end()) { trace(9993, "name") << "assign " << inst.products.at(out).name << " " << curr_idx << end(); names[inst.products.at(out).name] = curr_idx; @@ -70,12 +72,12 @@ void transform_names(const recipe_ordinal r) { bool disqualified(/*mutable*/ reagent& x, const instruction& inst, const string& recipe_name) { if (!x.type) { + // End transform_names Exceptions raise_error << maybe(recipe_name) << "missing type for " << x.original_string << " in '" << inst.to_string() << "'\n" << end(); return true; } if (is_raw(x)) return true; if (is_literal(x)) return true; - if (is_integer(x.name)) return true; // End Disqualified Reagents if (x.initialized) return true; return false; diff --git a/056recipe_header.cc b/056recipe_header.cc index 6797cab8..15c407a5 100644 --- a/056recipe_header.cc +++ b/056recipe_header.cc @@ -332,10 +332,8 @@ void deduce_types_from_header(const recipe_ordinal r) { trace(9992, "transform") << "instruction: " << inst.to_string() << end(); for (long long int i = 0; i < SIZE(inst.ingredients); ++i) { if (inst.ingredients.at(i).type) continue; - if (header_type.find(inst.ingredients.at(i).name) == header_type.end()) { - raise << maybe(caller_recipe.name) << "unknown variable " << inst.ingredients.at(i).name << " in '" << inst.to_string() << "'\n" << end(); + if (header_type.find(inst.ingredients.at(i).name) == header_type.end()) continue; - } if (!inst.ingredients.at(i).type) inst.ingredients.at(i).type = new type_tree(*get(header_type, inst.ingredients.at(i).name)); if (!inst.ingredients.at(i).properties.at(0).second) @@ -345,10 +343,8 @@ void deduce_types_from_header(const recipe_ordinal r) { for (long long int i = 0; i < SIZE(inst.products); ++i) { trace(9993, "transform") << " product: " << debug_string(inst.products.at(i)) << end(); if (inst.products.at(i).type) continue; - if (header_type.find(inst.products.at(i).name) == header_type.end()) { - raise << maybe(caller_recipe.name) << "unknown variable " << inst.products.at(i).name << " in '" << inst.to_string() << "'\n" << end(); + if (header_type.find(inst.products.at(i).name) == header_type.end()) continue; - } if (!inst.products.at(i).type) inst.products.at(i).type = new type_tree(*get(header_type, inst.products.at(i).name)); if (!inst.products.at(i).properties.at(0).second) diff --git a/061recipe.cc b/061recipe.cc index 42cc2279..3d7c0eaa 100644 --- a/061recipe.cc +++ b/061recipe.cc @@ -3,23 +3,24 @@ //: recipes, return recipes from recipes and so on. :(before "End Mu Types Initialization") -// 'recipe' is a literal -put(Type_ordinal, "recipe", 0); -// 'recipe-ordinal' is the literal that can store recipe literals -type_ordinal recipe_ordinal = put(Type_ordinal, "recipe-ordinal", Next_type_ordinal++); -get_or_insert(Type, recipe_ordinal).name = "recipe-ordinal"; +put(Type_ordinal, "recipe-literal", 0); +// 'recipe' variables can store recipe-literal +type_ordinal recipe = put(Type_ordinal, "recipe", Next_type_ordinal++); +get_or_insert(Type, recipe).name = "recipe"; -:(before "End Reagent-parsing Exceptions") -if (r.properties.at(0).second && r.properties.at(0).second->value == "recipe") { - r.set_value(get(Recipe_ordinal, r.name)); - return; +:(before "End transform_names Exceptions") +if (!x.properties.at(0).second && contains_key(Recipe_ordinal, x.name)) { + x.properties.at(0).second = new string_tree("recipe-literal"); + x.type = new type_tree(get(Type_ordinal, "recipe-literal")); + x.set_value(get(Recipe_ordinal, x.name)); + return true; } :(code) bool is_mu_recipe(reagent r) { if (!r.type) return false; - if (r.type->value == get(Type_ordinal, "recipe")) return true; - if (r.type->value == get(Type_ordinal, "recipe-ordinal")) return true; + if (r.properties.at(0).second->value == "recipe") return true; + if (r.properties.at(0).second->value == "recipe-literal") return true; // End is_mu_recipe Cases return false; } diff --git a/062scheduler.cc b/062scheduler.cc index 39568072..cd52f48c 100644 --- a/062scheduler.cc +++ b/062scheduler.cc @@ -3,7 +3,7 @@ :(scenario scheduler) recipe f1 [ - start-running f2:recipe + start-running f2 # wait for f2 to run { jump-unless 1:number, -1 @@ -158,7 +158,7 @@ case START_RUNNING: { break; } if (!is_mu_recipe(inst.ingredients.at(0))) { - raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'start-running' should be a recipe, but got " << inst.ingredients.at(0).original_string << '\n' << end(); + raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'start-running' should be a recipe, but got " << debug_string(inst.ingredients.at(0)) << '\n' << end(); break; } break; @@ -194,7 +194,7 @@ recipe f1 [ :(scenario scheduler_interleaves_routines) % Scheduling_interval = 1; recipe f1 [ - start-running f2:recipe + start-running f2 1:number <- copy 0 2:number <- copy 0 ] @@ -203,7 +203,7 @@ recipe f2 [ 4:number <- copy 0 ] +schedule: f1 -+run: start-running f2:recipe ++run: start-running f2 +schedule: f2 +run: 3:number <- copy 0 +schedule: f1 @@ -215,7 +215,7 @@ recipe f2 [ :(scenario start_running_takes_ingredients) recipe f1 [ - start-running f2:recipe, 3 + start-running f2, 3 # wait for f2 to run { jump-unless 1:number, -1 @@ -229,7 +229,7 @@ recipe f2 [ :(scenario start_running_returns_routine_id) recipe f1 [ - 1:number <- start-running f2:recipe + 1:number <- start-running f2 ] recipe f2 [ 12:number <- copy 44 @@ -272,7 +272,7 @@ recipe f1 [ % Hide_errors = true; % Scheduling_interval = 2; recipe f1 [ - start-running f2:recipe + start-running f2 1:number <- copy 0 2:number <- copy 0 ] @@ -294,7 +294,7 @@ recipe f2 [ :(scenario scheduler_kills_orphans) recipe main [ - start-running f1:recipe + start-running f1 # f1 never actually runs because its parent completes without waiting for it ] recipe f1 [ @@ -325,7 +325,7 @@ bool has_completed_parent(long long int routine_index) { :(scenario routine_state_test) % Scheduling_interval = 2; recipe f1 [ - 1:number/child-id <- start-running f2:recipe + 1:number/child-id <- start-running f2 12:number <- copy 0 # race condition since we don't care about location 12 # thanks to Scheduling_interval, f2's one instruction runs in between here and completes 2:number/state <- routine-state 1:number/child-id @@ -447,7 +447,7 @@ case _DUMP_ROUTINES: { :(scenario routine_discontinues_past_limit) % Scheduling_interval = 2; recipe f1 [ - 1:number/child-id <- start-running f2:recipe + 1:number/child-id <- start-running f2 limit-time 1:number/child-id, 10 # padding loop just to make sure f2 has time to completed 2:number <- copy 20 @@ -516,7 +516,7 @@ case LIMIT_TIME: { :(scenario new_concurrent) recipe f1 [ - start-running f2:recipe + start-running f2 1:address:number/raw <- new number:type # wait for f2 to complete { diff --git a/063wait.cc b/063wait.cc index ef3d30e5..888edcdf 100644 --- a/063wait.cc +++ b/063wait.cc @@ -6,7 +6,7 @@ :(scenario wait_for_location) recipe f1 [ 1:number <- copy 0 - start-running f2:recipe + start-running f2 wait-for-location 1:number # now wait for f2 to run and modify location 1 before using its value 2:number <- copy 1:number @@ -67,7 +67,7 @@ for (long long int i = 0; i < SIZE(Routines); ++i) { :(scenario wait_for_routine) recipe f1 [ 1:number <- copy 0 - 12:number/routine <- start-running f2:recipe + 12:number/routine <- start-running f2 wait-for-routine 12:number/routine # now wait for f2 to run and modify location 1 before using its value 3:number <- copy 1:number diff --git a/071channel.mu b/071channel.mu index d3b4752f..f331904c 100644 --- a/071channel.mu +++ b/071channel.mu @@ -324,7 +324,7 @@ scenario buffer-lines-blocks-until-newline [ assert 3:boolean, [ F buffer-lines-blocks-until-newline: channel should be empty after init] # buffer stdin into buffered-stdin, try to read from buffered-stdin - 4:number/buffer-routine <- start-running buffer-lines:recipe, 1:address:channel/stdin, 2:address:channel/buffered-stdin + 4:number/buffer-routine <- start-running buffer-lines, 1:address:channel/stdin, 2:address:channel/buffered-stdin wait-for-routine 4:number/buffer-routine 5:boolean <- channel-empty? 2:address:channel/buffered-stdin assert 5:boolean, [ diff --git a/091run_interactive.cc b/091run_interactive.cc index 352d2d23..0fe335ed 100644 --- a/091run_interactive.cc +++ b/091run_interactive.cc @@ -154,7 +154,7 @@ load(string( "recipe sandbox [\n" + "local-scope\n" + "screen:address:screen/shared <- new-fake-screen 30, 5\n" + - "r:number/routine_id <- start-running interactive:recipe, screen\n" + + "r:number/routine_id <- start-running interactive, screen\n" + "limit-time r, 100000/instructions\n" + "wait-for-routine r\n" + "sandbox-state:number <- routine-state r/routine_id\n" + diff --git a/Readme.md b/Readme.md index cda37208..0559b80c 100644 --- a/Readme.md +++ b/Readme.md @@ -355,7 +355,7 @@ Another example, this time with concurrency. ``` recipe main [ - start-running thread2:recipe + start-running thread2 { $print 34 loop diff --git a/channel.mu b/channel.mu index 5c3ea735..def7c08b 100644 --- a/channel.mu +++ b/channel.mu @@ -36,8 +36,8 @@ recipe main [ local-scope chan:address:channel <- new-channel 3 # create two background 'routines' that communicate by a channel - routine1:character <- start-running producer:recipe, chan - routine2:character <- start-running consumer:recipe, chan + routine1:number <- start-running producer, chan + routine2:number <- start-running consumer, chan wait-for-routine routine1 wait-for-routine routine2 ] diff --git a/chessboard.mu b/chessboard.mu index e5f894fa..3347e253 100644 --- a/chessboard.mu +++ b/chessboard.mu @@ -72,10 +72,10 @@ recipe chessboard screen:address:screen, console:address:console -> screen:addre board:address:array:address:array:character <- initial-position # hook up stdin stdin:address:channel <- new-channel 10/capacity - start-running send-keys-to-channel:recipe, console, stdin, screen + start-running send-keys-to-channel, console, stdin, screen # buffer lines in stdin buffered-stdin:address:channel <- new-channel 10/capacity - start-running buffer-lines:recipe, stdin, buffered-stdin + start-running buffer-lines, stdin, buffered-stdin { msg:address:array:character <- new [Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves. ] @@ -381,7 +381,7 @@ scenario read-move-blocking [ assume-screen 20/width, 2/height run [ 1:address:channel <- new-channel 2 - 2:number/routine <- start-running read-move:recipe, 1:address:channel, screen:address:screen + 2:number/routine <- start-running read-move, 1:address:channel, screen:address:screen # 'read-move' is waiting for input wait-for-routine 2:number 3:number <- routine-state 2:number/id @@ -453,7 +453,7 @@ scenario read-move-quit [ assume-screen 20/width, 2/height run [ 1:address:channel <- new-channel 2 - 2:number/routine <- start-running read-move:recipe, 1:address:channel, screen:address:screen + 2:number/routine <- start-running read-move, 1:address:channel, screen:address:screen # 'read-move' is waiting for input wait-for-routine 2:number 3:number <- routine-state 2:number/id @@ -480,7 +480,7 @@ scenario read-move-illegal-file [ assume-screen 20/width, 2/height run [ 1:address:channel <- new-channel 2 - 2:number/routine <- start-running read-move:recipe, 1:address:channel, screen:address:screen + 2:number/routine <- start-running read-move, 1:address:channel, screen:address:screen # 'read-move' is waiting for input wait-for-routine 2:number 3:number <- routine-state 2:number/id @@ -501,7 +501,7 @@ scenario read-move-illegal-rank [ assume-screen 20/width, 2/height run [ 1:address:channel <- new-channel 2 - 2:number/routine <- start-running read-move:recipe, 1:address:channel, screen:address:screen + 2:number/routine <- start-running read-move, 1:address:channel, screen:address:screen # 'read-move' is waiting for input wait-for-routine 2:number 3:number <- routine-state 2:number/id @@ -523,7 +523,7 @@ scenario read-move-empty [ assume-screen 20/width, 2/height run [ 1:address:channel <- new-channel 2 - 2:number/routine <- start-running read-move:recipe, 1:address:channel, screen:address:screen + 2:number/routine <- start-running read-move, 1:address:channel, screen:address:screen # 'read-move' is waiting for input wait-for-routine 2:number 3:number <- routine-state 2:number/id diff --git a/fork.mu b/fork.mu index 1d717181..3aa37227 100644 --- a/fork.mu +++ b/fork.mu @@ -1,7 +1,7 @@ # example program: running multiple routines recipe main [ - start-running thread2:recipe + start-running thread2 { $print 34 loop diff --git a/mu.vim b/mu.vim index 35d192ac..90d130e3 100644 --- a/mu.vim +++ b/mu.vim @@ -52,7 +52,6 @@ highlight link muLabel Constant syntax match muLiteral %[^ ]\+:type/\?[^ ,]*% syntax match muLiteral %[^ ]\+:offset/\?[^ ,]*% syntax match muLiteral %[^ ]\+:variant/\?[^ ,]*% -syntax match muLiteral %[^ ]\+:recipe/\?[^ ,]*% highlight link muLiteral Constant syntax keyword muKeyword default-space global-space new-default-space local-scope next-ingredient ingredient load-ingredients | highlight link muKeyword Constant |