From 6d17ef493bbec78ebda37e50e0cc8ce21fd9f46b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 5 May 2015 17:41:10 -0700 Subject: 1266 - 'start-running' returns a unique routine id --- cpp/.traces/start_running_returns_routine_id | 24 +++++++++++++++++++++ cpp/038scheduler.cc | 32 +++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 cpp/.traces/start_running_returns_routine_id diff --git a/cpp/.traces/start_running_returns_routine_id b/cpp/.traces/start_running_returns_routine_id new file mode 100644 index 00000000..868b4ed2 --- /dev/null +++ b/cpp/.traces/start_running_returns_routine_id @@ -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 diff --git a/cpp/038scheduler.cc b/cpp/038scheduler.cc index f750e4a3..dbefe556 100644 --- a/cpp/038scheduler.cc +++ b/cpp/038scheduler.cc @@ -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 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) -- cgit 1.4.1-2-gfad0