From 90560d7194f3e451ddab9d4033c98d2e6aec977b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 23 Aug 2015 10:19:23 -0700 Subject: 2062 --- html/075scenario_console.cc.html | 77 ++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 39 deletions(-) (limited to 'html/075scenario_console.cc.html') diff --git a/html/075scenario_console.cc.html b/html/075scenario_console.cc.html index 96de3221..16b68e11 100644 --- a/html/075scenario_console.cc.html +++ b/html/075scenario_console.cc.html @@ -13,14 +13,13 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.Constant { color: #00a0a0; } .cSpecial { color: #008000; } .CommentedCode { color: #6c6c6c; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } +.Constant { color: #00a0a0; } --> @@ -64,13 +63,13 @@ scenario keyboard-in-scenario [ ] :(before "End Scenario Globals") -const long long int CONSOLE = Next_predefined_global_for_scenarios++; +const long long int CONSOLE = Next_predefined_global_for_scenarios++; :(before "End Special Scenario Variable Names(r)") Name[r]["console"] = CONSOLE; //: allow naming just for 'console' :(before "End is_special_name Cases") -if (s == "console") return true; +if (s == "console") return true; //: Unlike assume-keyboard, assume-console is easiest to implement as just a //: primitive recipe. @@ -79,22 +78,22 @@ ASSUME_CONSOLE, :(before "End Primitive Recipe Numbers") Recipe_ordinal["assume-console"] = ASSUME_CONSOLE; :(before "End Primitive Recipe Implementations") -case ASSUME_CONSOLE: { +case ASSUME_CONSOLE: { //? cerr << "aaa: " << current_instruction().ingredients.at(0).name << '\n'; //? 2 // create a temporary recipe just for parsing; it won't contain valid instructions istringstream in("[" + current_instruction().ingredients.at(0).name + "]"); recipe r = slurp_recipe(in); - long long int num_events = count_events(r); + long long int num_events = count_events(r); //? cerr << "fff: " << num_events << '\n'; //? 3 // initialize the events - long long int size = num_events*size_of_event() + /*space for length*/1; + long long int size = num_events*size_of_event() + /*space for length*/1; ensure_space(size); - long long int event_data_address = Current_routine->alloc; + long long int event_data_address = Current_routine->alloc; Memory[event_data_address] = num_events; ++Current_routine->alloc; - for (long long int i = 0; i < SIZE(r.steps); ++i) { - const instruction& curr = r.steps.at(i); - if (curr.name == "left-click") { + for (long long int i = 0; i < SIZE(r.steps); ++i) { + const instruction& curr = r.steps.at(i); + if (curr.name == "left-click") { Memory[Current_routine->alloc] = /*tag for 'touch-event' variant of 'event' exclusive-container*/2; Memory[Current_routine->alloc+1+/*offset of 'type' in 'mouse-event'*/0] = TB_KEY_MOUSE_LEFT; Memory[Current_routine->alloc+1+/*offset of 'row' in 'mouse-event'*/1] = to_integer(curr.ingredients.at(0).name); @@ -102,24 +101,24 @@ Recipe_ordinal["assume-console"] = ASSUM //? cerr << "AA left click: " << Memory[Current_routine->alloc+2] << ' ' << Memory[Current_routine->alloc+3] << '\n'; //? 1 Current_routine->alloc += size_of_event(); } - else if (curr.name == "press") { + else if (curr.name == "press") { Memory[Current_routine->alloc] = /*tag for 'keycode' variant of 'event' exclusive-container*/1; Memory[Current_routine->alloc+1] = to_integer(curr.ingredients.at(0).name); //? cerr << "AA press: " << Memory[Current_routine->alloc+1] << '\n'; //? 3 Current_routine->alloc += size_of_event(); } // End Event Handlers - else { + else { // keyboard input assert(curr.name == "type"); - const string& contents = curr.ingredients.at(0).name; - const char* raw_contents = contents.c_str(); - long long int num_keyboard_events = unicode_length(contents); - long long int curr = 0; + const string& contents = curr.ingredients.at(0).name; + const char* raw_contents = contents.c_str(); + long long int num_keyboard_events = unicode_length(contents); + long long int curr = 0; //? cerr << "AAA: " << num_keyboard_events << '\n'; //? 1 - for (long long int i = 0; i < num_keyboard_events; ++i) { + for (long long int i = 0; i < num_keyboard_events; ++i) { Memory[Current_routine->alloc] = /*tag for 'text' variant of 'event' exclusive-container*/0; - uint32_t curr_character; + uint32_t curr_character; assert(curr < SIZE(contents)); tb_utf8_char_to_unicode(&curr_character, &raw_contents[curr]); //? cerr << "AA keyboard: " << curr_character << '\n'; //? 3 @@ -198,57 +197,57 @@ REPLACE_IN_CONSOLE, :(before "End Primitive Recipe Numbers") Recipe_ordinal["replace-in-console"] = REPLACE_IN_CONSOLE; :(before "End Primitive Recipe Implementations") -case REPLACE_IN_CONSOLE: { +case REPLACE_IN_CONSOLE: { assert(scalar(ingredients.at(0))); //? cerr << "console: " << Memory[CONSOLE] << '\n'; //? 1 - if (!Memory[CONSOLE]) { + if (!Memory[CONSOLE]) { raise << "console not initialized\n" << end(); break; } - long long int console_data = Memory[Memory[CONSOLE]+1]; + long long int console_data = Memory[Memory[CONSOLE]+1]; //? cerr << "console data starts at " << console_data << '\n'; //? 1 - long long int size = Memory[console_data]; // array size + long long int size = Memory[console_data]; // array size //? cerr << "size of console data is " << size << '\n'; //? 1 - for (long long int i = 0, curr = console_data+1; i < size; ++i, curr+=size_of_event()) { + for (long long int i = 0, curr = console_data+1; i < size; ++i, curr+=size_of_event()) { //? cerr << curr << '\n'; //? 1 - if (Memory[curr] != /*text*/0) continue; - if (Memory[curr+1] != ingredients.at(0).at(0)) continue; - for (long long int n = 0; n < size_of_event(); ++n) + if (Memory[curr] != /*text*/0) continue; + if (Memory[curr+1] != ingredients.at(0).at(0)) continue; + for (long long int n = 0; n < size_of_event(); ++n) Memory[curr+n] = ingredients.at(1).at(n); } break; } :(code) -long long int count_events(const recipe& r) { - long long int result = 0; - for (long long int i = 0; i < SIZE(r.steps); ++i) { - const instruction& curr = r.steps.at(i); +long long int count_events(const recipe& r) { + long long int result = 0; + for (long long int i = 0; i < SIZE(r.steps); ++i) { + const instruction& curr = r.steps.at(i); //? cerr << "aa: " << curr.name << '\n'; //? 3 //? cerr << "bb: " << curr.ingredients.at(0).name << '\n'; //? 1 - if (curr.name == "type") + if (curr.name == "type") result += unicode_length(curr.ingredients.at(0).name); - else + else result++; //? cerr << "cc: " << result << '\n'; //? 1 } return result; } -long long int size_of_event() { +long long int size_of_event() { // memoize result if already computed - static long long int result = 0; - if (result) return result; + static long long int result = 0; + if (result) return result; vector<type_ordinal> type; type.push_back(Type_ordinal["event"]); result = size_of(type); return result; } -long long int size_of_events() { +long long int size_of_events() { // memoize result if already computed - static long long int result = 0; - if (result) return result; + static long long int result = 0; + if (result) return result; vector<type_ordinal> type; assert(Type_ordinal["console"]); type.push_back(Type_ordinal["console"]); -- cgit 1.4.1-2-gfad0