1266 - 'start-running' returns a unique routine id

This commit is contained in:
Kartik K. Agaram 2015-05-05 17:41:10 -07:00
parent 6673e1fc45
commit 6d17ef493b
2 changed files with 55 additions and 1 deletions

View File

@ -0,0 +1,24 @@
parse/0: instruction: start-running
parse/0: ingredient: {name: "f2", value: 0, type: 0, properties: ["f2": "recipe"]}
parse/0: product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
parse/0: instruction: copy
parse/0: ingredient: {name: "44", value: 0, type: 0, properties: ["44": "literal"]}
parse/0: product: {name: "12", value: 0, type: 1, properties: ["12": "integer"]}
after-brace/0: recipe f1
after-brace/0: start-running ...
after-brace/0: recipe f2
after-brace/0: copy ...
new/0: routine allocated memory from 1000 to 101000
schedule/0: f1
run/0: instruction f1/0
run/0: {name: "1", value: 1, type: 1, properties: ["1": "integer"]} <- start-running/34 {name: "f2", value: 0, type: 0, properties: ["f2": "recipe"]}
run/0: ingredient 0 is f2
new/0: routine allocated memory from 101000 to 201000
mem/0: storing 2 in location 1
schedule/0: f2
run/0: instruction f2/0
run/0: {name: "12", value: 12, type: 1, properties: ["12": "integer"]} <- copy/1 {name: "44", value: 44, type: 0, properties: ["44": "literal"]}
run/0: ingredient 0 is 44
mem/0: storing 44 in location 12
schedule/0: f1
schedule/0: f2

View File

@ -90,6 +90,20 @@ for (index_t i = 0; i < Routines.size(); ++i)
delete Routines[i];
Routines.clear();
//:: To schedule new routines to run, call 'start-scheduling'.
//: 'start-scheduling' will return a unique id for the routine that was
//: created.
:(before "End routine Fields")
index_t id;
:(before "End Globals")
index_t Next_routine_id = 1;
:(before "End Setup")
Next_routine_id = 1;
:(before "End routine Constructor")
id = Next_routine_id;
Next_routine_id++;
:(before "End Primitive Recipe Declarations")
START_RUNNING,
:(before "End Primitive Recipe Numbers")
@ -98,7 +112,13 @@ Recipe_number["start-running"] = START_RUNNING;
case START_RUNNING: {
trace("run") << "ingredient 0 is " << current_instruction().ingredients[0].name;
assert(!current_instruction().ingredients[0].initialized);
Routines.push_back(new routine(Recipe_number[current_instruction().ingredients[0].name]));
routine* new_routine = new routine(Recipe_number[current_instruction().ingredients[0].name]);
Routines.push_back(new_routine);
if (!current_instruction().products.empty()) {
vector<long long int> result;
result.push_back(new_routine->id);
write_memory(current_instruction().products[0], result);
}
break;
}
@ -135,6 +155,16 @@ recipe f2 [
+schedule: f1
+run: instruction f1/2
:(scenario start_running_returns_routine_id)
% Scheduling_interval = 1;
recipe f1 [
1:integer <- start-running f2:recipe
]
recipe f2 [
12:integer <- copy 44:literal
]
+mem: storing 2 in location 1
:(scenario scheduler_skips_completed_routines)
# this scenario will require some careful setup in escaped C++
# (straining our tangle capabilities to near-breaking point)