From 0e4a335edc7d4e584924fd6b298156e45d2626c8 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 6 Sep 2015 16:35:46 -0700 Subject: 2175 --- html/075scenario_console.cc.html | 100 ++++++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 23 deletions(-) (limited to 'html/075scenario_console.cc.html') diff --git a/html/075scenario_console.cc.html b/html/075scenario_console.cc.html index 16b68e11..c578c2a8 100644 --- a/html/075scenario_console.cc.html +++ b/html/075scenario_console.cc.html @@ -14,7 +14,6 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background- body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } .cSpecial { color: #008000; } -.CommentedCode { color: #6c6c6c; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } @@ -79,12 +78,10 @@ ASSUME_CONSOLE, Recipe_ordinal["assume-console"] = ASSUME_CONSOLE; :(before "End Primitive Recipe Implementations") 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); + recipe r = slurp_body(in); 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; ensure_space(size); @@ -98,13 +95,23 @@ case ASSUME_CONSOLE: { 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); -//? 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") { - 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 + 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]; + else + raise << "assume-console: can't press " << key << '\n' << end(); + if (Memory[Current_routine->alloc+1] < 256) + // these keys are in ascii + 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; + } Current_routine->alloc += size_of_event(); } // End Event Handlers @@ -115,13 +122,11 @@ case ASSUME_CONSOLE: { 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) { 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]); -//? cerr << "AA keyboard: " << curr_character << '\n'; //? 3 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(); @@ -133,24 +138,80 @@ case ASSUME_CONSOLE: { ensure_space(size_of_events()); Memory[CONSOLE] = Current_routine->alloc; Current_routine->alloc += size_of_events(); -//? cerr << "writing " << event_data_address << " to location " << Memory[CONSOLE]+1 << '\n'; //? 1 Memory[Memory[CONSOLE]+/*offset of 'data' in container 'events'*/1] = event_data_address; -//? cerr << Memory[Memory[CONSOLE]+1] << '\n'; //? 1 -//? cerr << "alloc now " << Current_routine->alloc << '\n'; //? 1 break; } +:(before "End Globals") +map<string, long long int> Key; +:(before "End One-time Setup") +initialize_key_names(); +:(code) +void initialize_key_names() { + Key["F1"] = TB_KEY_F1; + Key["F2"] = TB_KEY_F2; + Key["F3"] = TB_KEY_F3; + Key["F4"] = TB_KEY_F4; + Key["F5"] = TB_KEY_F5; + Key["F6"] = TB_KEY_F6; + Key["F7"] = TB_KEY_F7; + Key["F8"] = TB_KEY_F8; + Key["F9"] = TB_KEY_F9; + Key["F10"] = TB_KEY_F10; + Key["F11"] = TB_KEY_F11; + Key["F12"] = TB_KEY_F12; + Key["insert"] = TB_KEY_INSERT; + Key["delete"] = TB_KEY_DELETE; + Key["home"] = TB_KEY_HOME; + Key["end"] = TB_KEY_END; + Key["page-up"] = TB_KEY_PGUP; + Key["page-down"] = TB_KEY_PGDN; + Key["up-arrow"] = TB_KEY_ARROW_UP; + Key["down-arrow"] = TB_KEY_ARROW_DOWN; + Key["left-arrow"] = TB_KEY_ARROW_LEFT; + Key["right-arrow"] = TB_KEY_ARROW_RIGHT; + Key["ctrl-a"] = TB_KEY_CTRL_A; + Key["ctrl-b"] = TB_KEY_CTRL_B; + Key["ctrl-c"] = TB_KEY_CTRL_C; + Key["ctrl-d"] = TB_KEY_CTRL_D; + Key["ctrl-e"] = TB_KEY_CTRL_E; + Key["ctrl-f"] = TB_KEY_CTRL_F; + Key["ctrl-g"] = TB_KEY_CTRL_G; + Key["backspace"] = TB_KEY_BACKSPACE; + Key["ctrl-h"] = TB_KEY_CTRL_H; + Key["tab"] = TB_KEY_TAB; + Key["ctrl-i"] = TB_KEY_CTRL_I; + Key["ctrl-j"] = TB_KEY_CTRL_J; + Key["enter"] = TB_KEY_NEWLINE; // ignore CR/LF distinction; there is only 'enter' + Key["ctrl-k"] = TB_KEY_CTRL_K; + Key["ctrl-l"] = TB_KEY_CTRL_L; + Key["ctrl-m"] = TB_KEY_CTRL_M; + Key["ctrl-n"] = TB_KEY_CTRL_N; + Key["ctrl-o"] = TB_KEY_CTRL_O; + Key["ctrl-p"] = TB_KEY_CTRL_P; + Key["ctrl-q"] = TB_KEY_CTRL_Q; + Key["ctrl-r"] = TB_KEY_CTRL_R; + Key["ctrl-s"] = TB_KEY_CTRL_S; + Key["ctrl-t"] = TB_KEY_CTRL_T; + Key["ctrl-u"] = TB_KEY_CTRL_U; + Key["ctrl-v"] = TB_KEY_CTRL_V; + Key["ctrl-w"] = TB_KEY_CTRL_W; + Key["ctrl-x"] = TB_KEY_CTRL_X; + Key["ctrl-y"] = TB_KEY_CTRL_Y; + Key["ctrl-z"] = TB_KEY_CTRL_Z; + Key["escape"] = TB_KEY_ESC; +} + :(scenario events_in_scenario) scenario events-in-scenario [ assume-console [ type [abc] left-click 0, 1 - press 65515 # up arrow + press up-arrow type [d] ] run [ # 3 keyboard events; each event occupies 4 locations -#? $start-tracing #? 2 1:event <- read-event console:address 5:event <- read-event console:address 9:event <- read-event console:address @@ -179,7 +240,7 @@ scenario events-in-scenario [ 15 <- 0 # row 16 <- 1 # column 17 <- 1 # 'keycode' - 18 <- 65515 # up arrow + 18 <- 65517 # up arrow 19 <- 0 # unused 20 <- 0 # unused 21 <- 0 # 'text' @@ -199,17 +260,13 @@ Recipe_ordinal["replace-in-console"] = R :(before "End Primitive Recipe Implementations") case REPLACE_IN_CONSOLE: { assert(scalar(ingredients.at(0))); -//? cerr << "console: " << Memory[CONSOLE] << '\n'; //? 1 if (!Memory[CONSOLE]) { raise << "console not initialized\n" << end(); break; } 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 -//? 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()) { -//? 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) @@ -223,13 +280,10 @@ long long int count_events(const recipe& r0; 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") result += unicode_length(curr.ingredients.at(0).name); else result++; -//? cerr << "cc: " << result << '\n'; //? 1 } return result; } -- cgit 1.4.1-2-gfad0