diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-04-15 09:12:48 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-04-15 09:12:48 -0700 |
commit | 2cc42dcec9809efd12de279a7cc4641db691e0a8 (patch) | |
tree | c5e1cdcaad3dc3bae84647b4f2a1b74a093af372 | |
parent | d762cddf4c49bcdef6e3d7358565374525a685a0 (diff) | |
download | mu-2cc42dcec9809efd12de279a7cc4641db691e0a8.tar.gz |
2834 - make 'wait-for-location' more intuitive
Previously to watch an address we had to perform a lookup of it, which the instruction then proceeded to undo. This way wait-for-instruction no longer supports literal ingredients, but the real-world usage becomes cleaner.
-rw-r--r-- | 063wait.cc | 25 | ||||
-rw-r--r-- | 072channel.mu | 4 |
2 files changed, 18 insertions, 11 deletions
diff --git a/063wait.cc b/063wait.cc index 46bd406f..19bfb2d8 100644 --- a/063wait.cc +++ b/063wait.cc @@ -7,15 +7,16 @@ def f1 [ 1:number <- copy 0 start-running f2 - wait-for-location 1:number + 2:address:number <- copy 1/unsafe + wait-for-location 2:address:number # now wait for f2 to run and modify location 1 before using its value - 2:number <- copy 1:number + 3:number <- copy 1:number ] def f2 [ 1:number <- copy 34 ] -# if we got the synchronization wrong we'd be storing 0 in location 2 -+mem: storing 34 in location 2 +# if we got the synchronization wrong we'd be storing 0 in location 3 ++mem: storing 34 in location 3 //: define the new state that all routines can be in @@ -36,16 +37,22 @@ WAIT_FOR_LOCATION, put(Recipe_ordinal, "wait-for-location", WAIT_FOR_LOCATION); :(before "End Primitive Recipe Checks") case WAIT_FOR_LOCATION: { + if (SIZE(inst.ingredients) != 1) { + raise << maybe(get(Recipe, r).name) << "'wait-for-location' requires exactly one ingredient, but got " << to_original_string(inst) << '\n' << end(); + break; + } + if (!is_mu_address(inst.ingredients.at(0))) { + raise << maybe(get(Recipe, r).name) << "'wait-for-location' requires an address ingredient, but got " << inst.ingredients.at(0).original_string << '\n' << end(); + } break; } :(before "End Primitive Recipe Implementations") case WAIT_FOR_LOCATION: { - reagent loc = current_instruction().ingredients.at(0); - canonize(loc); + int loc = ingredients.at(0).at(0); Current_routine->state = WAITING; - Current_routine->waiting_on_location = loc.value; - Current_routine->old_value_of_waiting_location = get_or_insert(Memory, loc.value); - trace(9998, "run") << "waiting for location " << loc.value << " to change from " << no_scientific(get_or_insert(Memory, loc.value)) << end(); + Current_routine->waiting_on_location = loc; + Current_routine->old_value_of_waiting_location = get_or_insert(Memory, loc); + trace(9998, "run") << "waiting for location " << loc << " to change from " << no_scientific(get_or_insert(Memory, loc)) << end(); break; } diff --git a/072channel.mu b/072channel.mu index 0e9b0041..2633b80a 100644 --- a/072channel.mu +++ b/072channel.mu @@ -66,7 +66,7 @@ def write out:address:shared:sink:_elem, val:_elem -> out:address:shared:sink:_e full:boolean <- channel-full? chan break-unless full full-address:address:number <- get-address *chan, first-full:offset - wait-for-location *full-address + wait-for-location full-address } # store val circular-buffer:address:shared:array:_elem <- get *chan, data:offset @@ -93,7 +93,7 @@ def read in:address:shared:source:_elem -> result:_elem, in:address:shared:sourc empty?:boolean <- channel-empty? chan break-unless empty? free-address:address:number <- get-address *chan, first-free:offset - wait-for-location *free-address + wait-for-location free-address } # read result full:address:number <- get-address *chan, first-full:offset |