1321 - *finally*, fixed the chessboard sluggishness

This commit is contained in:
Kartik K. Agaram 2015-05-10 06:02:36 -07:00
parent cf9af27878
commit 134dad7c4b
4 changed files with 47 additions and 3 deletions

View File

@ -324,6 +324,23 @@ case RESTART: {
break;
}
:(before "End Primitive Recipe Declarations")
STOP,
:(before "End Primitive Recipe Numbers")
Recipe_number["stop"] = STOP;
:(before "End Primitive Recipe Implementations")
case STOP: {
assert(ingredients.at(0).size() == 1); // routine id must be scalar
index_t id = ingredients.at(0).at(0);
for (index_t i = 0; i < Routines.size(); ++i) {
if (Routines.at(i)->id == id) {
Routines.at(i)->state = COMPLETED;
break;
}
}
break;
}
:(before "End Primitive Recipe Declarations")
_DUMP_ROUTINES,
:(before "End Primitive Recipe Numbers")

View File

@ -120,3 +120,31 @@ for (index_t i = 0; i < Routines.size(); ++i) {
}
}
}
:(before "End Primitive Recipe Declarations")
SWITCH,
:(before "End Primitive Recipe Numbers")
Recipe_number["switch"] = SWITCH;
:(before "End Primitive Recipe Implementations")
case SWITCH: {
index_t id = some_other_running_routine();
if (id) {
assert(id != Current_routine->id);
cerr << "waiting on " << id << " from " << Current_routine->id << '\n';
Current_routine->state = WAITING;
Current_routine->waiting_on_routine = id;
}
break;
}
:(code)
index_t some_other_running_routine() {
for (index_t i = 0; i < Routines.size(); ++i) {
if (i == Current_routine_index) continue;
assert(Routines.at(i) != Current_routine);
assert(Routines.at(i)->id != Current_routine->id);
if (Routines.at(i)->state == RUNNING)
return Routines.at(i)->id;
}
return 0;
}

View File

@ -35,6 +35,8 @@ recipe read-key [
idx:address:integer/deref <- add idx:address:integer/deref, 1:literal
reply c:character, 1:literal/found, x:address:keyboard/same-as-ingredient:0
}
# real keyboard input is infrequent; avoid polling it too much
switch
c:character, found?:boolean <- read-key-from-keyboard
reply c:character, found?:boolean, x:address:keyboard/same-as-ingredient:0
]

View File

@ -489,9 +489,6 @@ scenario making-a-move [
#? $print c:character
#? ]
# todo:
# problem with buffering
# some way of closing channels
recipe chessboard [
default-space:address:array:location <- new location:type, 30:literal
board:address:array:address:array:character <- initial-position