From 76755b2836b0dadd88f82635f661f9d9df77604d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 10 Nov 2015 21:35:42 -0800 Subject: 2423 - describe shape-shifting in html docs --- html/075scenario_console.cc.html | 105 +++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 48 deletions(-) (limited to 'html/075scenario_console.cc.html') diff --git a/html/075scenario_console.cc.html b/html/075scenario_console.cc.html index c578c2a8..6ef48e09 100644 --- a/html/075scenario_console.cc.html +++ b/html/075scenario_console.cc.html @@ -43,10 +43,10 @@ scenario keyboard-in-scenario [ type [abc] ] run [ - 1:character, console:address, 2:boolean <- read-key console:address - 3:character, console:address, 4:boolean <- read-key console:address - 5:character, console:address, 6:boolean <- read-key console:address - 7:character, console:address, 8:boolean, 9:boolean <- read-key console:address + 1:character, console:address:console, 2:boolean <- read-key console:address:console + 3:character, console:address:console, 4:boolean <- read-key console:address:console + 5:character, console:address:console, 6:boolean <- read-key console:address:console + 7:character, console:address:console, 8:boolean, 9:boolean <- read-key console:address:console ] memory-should-contain [ 1 <- 97 # 'a' @@ -70,47 +70,50 @@ Name[r]["console"] = CONSOLE:(before "End is_special_name Cases") if (s == "console") return true; -//: Unlike assume-keyboard, assume-console is easiest to implement as just a -//: primitive recipe. :(before "End Primitive Recipe Declarations") ASSUME_CONSOLE, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["assume-console"] = ASSUME_CONSOLE; +put(Recipe_ordinal, "assume-console", ASSUME_CONSOLE); +:(before "End Primitive Recipe Checks") +case ASSUME_CONSOLE: { + break; +} :(before "End Primitive Recipe Implementations") case ASSUME_CONSOLE: { // create a temporary recipe just for parsing; it won't contain valid instructions istringstream in("[" + current_instruction().ingredients.at(0).name + "]"); - recipe r = slurp_body(in); + recipe r; + slurp_body(in, r); long long int num_events = count_events(r); - // initialize the events + // initialize the events like in new-fake-console 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; - Memory[event_data_address] = num_events; + put(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") { - 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); - Memory[Current_routine->alloc+1+/*offset of 'column' in 'mouse-event'*/2] = to_integer(curr.ingredients.at(1).name); + put(Memory, Current_routine->alloc, /*tag for 'touch-event' variant of 'event' exclusive-container*/2); + put(Memory, Current_routine->alloc+1+/*offset of 'type' in 'mouse-event'*/0, TB_KEY_MOUSE_LEFT); + put(Memory, Current_routine->alloc+1+/*offset of 'row' in 'mouse-event'*/1, to_integer(curr.ingredients.at(0).name)); + put(Memory, Current_routine->alloc+1+/*offset of 'column' in 'mouse-event'*/2, to_integer(curr.ingredients.at(1).name)); Current_routine->alloc += size_of_event(); } else if (curr.name == "press") { string key = curr.ingredients.at(0).name; if (is_integer(key)) - Memory[Current_routine->alloc+1] = to_integer(key); - else if (Key.find(key) != Key.end()) - Memory[Current_routine->alloc+1] = Key[key]; + put(Memory, Current_routine->alloc+1, to_integer(key)); + else if (contains_key(Key, key)) + put(Memory, Current_routine->alloc+1, Key[key]); else - raise << "assume-console: can't press " << key << '\n' << end(); - if (Memory[Current_routine->alloc+1] < 256) + raise_error << "assume-console: can't press " << key << '\n' << end(); + if (get_or_insert(Memory, Current_routine->alloc+1) < 256) // these keys are in ascii - Memory[Current_routine->alloc] = /*tag for 'text' variant of 'event' exclusive-container*/0; + put(Memory, Current_routine->alloc, /*tag for 'text' variant of 'event' exclusive-container*/0); else { // distinguish from unicode - Memory[Current_routine->alloc] = /*tag for 'keycode' variant of 'event' exclusive-container*/1; + put(Memory, Current_routine->alloc, /*tag for 'keycode' variant of 'event' exclusive-container*/1); } Current_routine->alloc += size_of_event(); } @@ -123,22 +126,23 @@ case ASSUME_CONSOLE: { long long int num_keyboard_events = unicode_length(contents); long long int curr = 0; for (long long int i = 0; i < num_keyboard_events; ++i) { - Memory[Current_routine->alloc] = /*tag for 'text' variant of 'event' exclusive-container*/0; + put(Memory, Current_routine->alloc, /*tag for 'text' variant of 'event' exclusive-container*/0); uint32_t curr_character; assert(curr < SIZE(contents)); tb_utf8_char_to_unicode(&curr_character, &raw_contents[curr]); - Memory[Current_routine->alloc+/*skip exclusive container tag*/1] = curr_character; + put(Memory, Current_routine->alloc+/*skip exclusive container tag*/1, curr_character); curr += tb_utf8_char_length(raw_contents[curr]); Current_routine->alloc += size_of_event(); } } } assert(Current_routine->alloc == event_data_address+size); - // wrap the array of events in an event object - ensure_space(size_of_events()); - Memory[CONSOLE] = Current_routine->alloc; - Current_routine->alloc += size_of_events(); - Memory[Memory[CONSOLE]+/*offset of 'data' in container 'events'*/1] = event_data_address; + // wrap the array of events in a console object + ensure_space(size_of_console()); + put(Memory, CONSOLE, Current_routine->alloc); + Current_routine->alloc += size_of_console(); + long long int console_address = get_or_insert(Memory, CONSOLE); + put(Memory, console_address+/*offset of 'data' in container 'events'*/1, event_data_address); break; } @@ -212,15 +216,15 @@ scenario events-in-scenario [ ] run [ # 3 keyboard events; each event occupies 4 locations - 1:event <- read-event console:address - 5:event <- read-event console:address - 9:event <- read-event console:address + 1:event <- read-event console:address:console + 5:event <- read-event console:address:console + 9:event <- read-event console:address:console # mouse click - 13:event <- read-event console:address + 13:event <- read-event console:address:console # non-character keycode - 17:event <- read-event console:address + 17:event <- read-event console:address:console # final keyboard event - 21:event <- read-event console:address + 21:event <- read-event console:address:console ] memory-should-contain [ 1 <- 0 # 'text' @@ -256,21 +260,26 @@ scenario events-in-scenario [ :(before "End Primitive Recipe Declarations") REPLACE_IN_CONSOLE, :(before "End Primitive Recipe Numbers") -Recipe_ordinal["replace-in-console"] = REPLACE_IN_CONSOLE; +put(Recipe_ordinal, "replace-in-console", REPLACE_IN_CONSOLE); +:(before "End Primitive Recipe Checks") +case REPLACE_IN_CONSOLE: { + break; +} :(before "End Primitive Recipe Implementations") case REPLACE_IN_CONSOLE: { assert(scalar(ingredients.at(0))); - if (!Memory[CONSOLE]) { - raise << "console not initialized\n" << end(); + if (!get_or_insert(Memory, CONSOLE)) { + raise_error << "console not initialized\n" << end(); break; } - long long int console_data = Memory[Memory[CONSOLE]+1]; - long long int size = Memory[console_data]; // array size + long long int console_address = get_or_insert(Memory, CONSOLE); + long long int console_data = get_or_insert(Memory, console_address+1); + long long int size = get_or_insert(Memory, console_data); // array size for (long long int i = 0, curr = console_data+1; i < size; ++i, curr+=size_of_event()) { - if (Memory[curr] != /*text*/0) continue; - if (Memory[curr+1] != ingredients.at(0).at(0)) continue; + if (get_or_insert(Memory, curr) != /*text*/0) continue; + if (get_or_insert(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); + put(Memory, curr+n, ingredients.at(1).at(n)); } break; } @@ -292,20 +301,20 @@ long long int size_of_event() // memoize result if already computed static long long int result = 0; if (result) return result; - vector<type_ordinal> type; - type.push_back(Type_ordinal["event"]); + type_tree* type = new type_tree(get(Type_ordinal, "event")); result = size_of(type); + delete type; return result; } -long long int size_of_events() { +long long int size_of_console() { // memoize result if already computed static long long int result = 0; if (result) return result; - vector<type_ordinal> type; - assert(Type_ordinal["console"]); - type.push_back(Type_ordinal["console"]); + assert(get(Type_ordinal, "console")); + type_tree* type = new type_tree(get(Type_ordinal, "console")); result = size_of(type); + delete type; return result; } -- cgit 1.4.1-2-gfad0