diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-31 23:44:52 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-06-01 00:11:31 -0700 |
commit | 87fbfc2d4607ff31d5b0b023f41d8ba439dd5958 (patch) | |
tree | c511ff6d2ea35991dca67f905559d81d6004b5a3 | |
parent | 4bbd3ded0b767ae0919551776e4c17189140e735 (diff) | |
download | mu-87fbfc2d4607ff31d5b0b023f41d8ba439dd5958.tar.gz |
1518 - still horribly broken
Just figured out why a first keystroke of backspace was sending me out for a spin: run_interactive needs all early exits that don't actually run anything to increment the current_step_index(). FML, this is lousy..
-rw-r--r-- | 011load.cc | 1 | ||||
-rw-r--r-- | 020run.cc | 7 | ||||
-rw-r--r-- | 035call.cc | 1 | ||||
-rw-r--r-- | 038scheduler.cc | 3 | ||||
-rw-r--r-- | 060string.mu | 11 | ||||
-rw-r--r-- | 070display.cc | 1 | ||||
-rw-r--r-- | 078run_interactive.cc | 58 | ||||
-rw-r--r-- | repl.mu | 35 |
8 files changed, 115 insertions, 2 deletions
diff --git a/011load.cc b/011load.cc index b779aa9e..94f73634 100644 --- a/011load.cc +++ b/011load.cc @@ -36,6 +36,7 @@ vector<recipe_number> load(istream& in) { } // todo: save user-defined recipes to mu's memory Recipe[Recipe_number[recipe_name]] = slurp_recipe(in); +//? cerr << Recipe_number[recipe_name] << ": " << recipe_name << '\n'; //? 1 Recipe[Recipe_number[recipe_name]].name = recipe_name; // track added recipes because we may need to undo them in tests; see below recently_added_recipes.push_back(Recipe_number[recipe_name]); diff --git a/020run.cc b/020run.cc index 07a02229..0c91b71d 100644 --- a/020run.cc +++ b/020run.cc @@ -54,8 +54,10 @@ void run(recipe_number r) { void run_current_routine() { // curly on a separate line, because later layers will modify header +//? cerr << "AAA 6\n"; //? 2 while (!Current_routine->completed()) // later layers will modify condition { +//? cerr << "AAA 7: " << current_step_index() << '\n'; //? 1 // Running One Instruction. if (current_instruction().is_label) { ++current_step_index(); continue; } trace(Initial_callstack_depth+Callstack_depth, "run") << current_instruction().to_string(); @@ -70,6 +72,7 @@ void run_current_routine() // Instructions below will write to 'products' or to 'instruction_counter'. vector<vector<double> > products; long long int instruction_counter = current_step_index(); +//? cerr << "AAA 8: " << current_instruction().operation << " ^" << Recipe[current_instruction().operation].name << "$\n"; //? 1 switch (current_instruction().operation) { // Primitive Recipe Implementations case COPY: { @@ -88,6 +91,7 @@ void run_current_routine() } current_step_index() = instruction_counter+1; } +//? cerr << "AAA 9\n"; //? 1 stop_running_current_routine:; } @@ -159,10 +163,13 @@ load_permanently("core.mu"); :(code) // helper for tests void run(string form) { +//? cerr << "AAA 2\n"; //? 1 vector<recipe_number> tmp = load(form); if (tmp.empty()) return; transform_all(); +//? cerr << "AAA 3\n"; //? 1 run(tmp.front()); +//? cerr << "YYY\n"; //? 1 } //:: Reading from memory, writing to memory. diff --git a/035call.cc b/035call.cc index 3b574cc2..f36f987e 100644 --- a/035call.cc +++ b/035call.cc @@ -108,6 +108,7 @@ inline const vector<instruction>& routine::steps() const { // it, and the one below that, and so on while (current_step_index() >= SIZE(Current_routine->steps())) { --Callstack_depth; +//? cerr << "reply " << Current_routine->calls.size() << '\n'; //? 1 Current_routine->calls.pop_front(); if (Current_routine->calls.empty()) return; // todo: no results returned warning diff --git a/038scheduler.cc b/038scheduler.cc index f98a8fca..3541a141 100644 --- a/038scheduler.cc +++ b/038scheduler.cc @@ -46,7 +46,9 @@ long long int Scheduling_interval = 500; Scheduling_interval = 500; :(replace{} "void run(recipe_number r)") void run(recipe_number r) { +//? cerr << "AAA 4\n"; //? 1 Routines.push_back(new routine(r)); +//? cerr << "AAA " << Routines.size() << " routines\n"; //? 1 Current_routine_index = 0, Current_routine = Routines.at(0); while (!all_routines_done()) { skip_to_next_routine(); @@ -58,6 +60,7 @@ void run(recipe_number r) { //? trace("schedule") << Current_routine->id << " " << current_recipe_name(); //? 1 run_current_routine(Scheduling_interval); // Scheduler State Transitions +//? cerr << "AAA completed? " << Current_routine->completed() << '\n'; //? 1 if (Current_routine->completed()) Current_routine->state = COMPLETED; // End Scheduler State Transitions diff --git a/060string.mu b/060string.mu index 227115ad..47a05c5a 100644 --- a/060string.mu +++ b/060string.mu @@ -156,13 +156,22 @@ recipe buffer-append [ default-space:address:array:location <- new location:type, 30:literal in:address:buffer <- next-ingredient c:character <- next-ingredient + len:address:number <- get-address in:address:buffer/deref, length:offset + { + # backspace? just drop last character if it exists and return + backspace?:boolean <- equal c:character, 8:literal/backspace + break-unless backspace?:boolean + empty?:boolean <- lesser-or-equal len:address:number/deref, 0:literal + reply-if empty?:boolean, in:address:buffer/same-as-ingredient:0 + len:address:number <- subtract len:address:number, 1:literal + reply in:address:buffer/same-as-ingredient:0 + } { # grow buffer if necessary full?:boolean <- buffer-full? in:address:buffer break-unless full?:boolean in:address:buffer <- grow-buffer in:address:buffer } - len:address:number <- get-address in:address:buffer/deref, length:offset s:address:array:character <- get in:address:buffer/deref, data:offset dest:address:character <- index-address s:address:array:character/deref, len:address:number/deref dest:address:character/deref <- copy c:character diff --git a/070display.cc b/070display.cc index fd96733a..a0c964c1 100644 --- a/070display.cc +++ b/070display.cc @@ -13,6 +13,7 @@ long long int Display_row = 0, Display_column = 0; SWITCH_TO_DISPLAY, :(before "End Primitive Recipe Numbers") Recipe_number["switch-to-display"] = SWITCH_TO_DISPLAY; +//? cerr << "switch-to-display: " << SWITCH_TO_DISPLAY << '\n'; //? 1 :(before "End Primitive Recipe Implementations") case SWITCH_TO_DISPLAY: { tb_init(); diff --git a/078run_interactive.cc b/078run_interactive.cc new file mode 100644 index 00000000..25ca4dd9 --- /dev/null +++ b/078run_interactive.cc @@ -0,0 +1,58 @@ +//: Helper for the repl. + +:(before "End Primitive Recipe Declarations") +RUN_INTERACTIVE, +:(before "End Primitive Recipe Numbers") +Recipe_number["run-interactive"] = RUN_INTERACTIVE; +//? cerr << "run-interactive: " << RUN_INTERACTIVE << '\n'; //? 1 +:(before "End Primitive Recipe Implementations") +case RUN_INTERACTIVE: { + assert(scalar(ingredients.at(0))); +//? cerr << "AAA 0\n"; //? 1 + run_interactive(ingredients.at(0).at(0)); +//? cerr << "ZZZ\n"; //? 1 + continue; // not done with caller; don't increment current_step_index() +} + +:(code) +// manual tests: +// just an integer prints value of that location in memory +// instruction executes [not yet working] +// backspace at start begins new attempt +void run_interactive(long long int address) { +//? tb_shutdown(); //? 1 + long long int size = Memory[address]; + if (size == 0) { + ++current_step_index(); + return; + } + ostringstream tmp; + for (long long int curr = address+1; curr < address+size; ++curr) { + // todo: unicode + tmp << (char)(int)Memory[curr]; + } +//? cerr << size << ' ' << Memory[address+size] << '\n'; //? 1 + assert(Memory[address+size] == 10); // skip the newline + if (Recipe_number.find("interactive") == Recipe_number.end()) + Recipe_number["interactive"] = Next_recipe_number++; + if (is_integer(tmp.str())) { + cerr << "=> " << Memory[to_integer(tmp.str())] << '\n'; + ++current_step_index(); + return; + } +//? exit(0); //? 1 + if (Name[Recipe_number["interactive"]].find(tmp.str()) != Name[Recipe_number["interactive"]].end()) { + cerr << "=> " << Memory[Name[Recipe_number["interactive"]][tmp.str()]] << '\n'; + ++current_step_index(); + return; + } +//? tb_shutdown(); //? 1 +//? cerr << tmp.str(); //? 1 +//? exit(0); //? 1 +//? cerr << "AAA 1\n"; //? 1 + Recipe.erase(Recipe_number["interactive"]); + // call run(string) but without the scheduling + load("recipe interactive [\n"+tmp.str()+"]\n"); + transform_all(); + Current_routine->calls.push_front(call(Recipe_number["interactive"])); +} diff --git a/repl.mu b/repl.mu index ace65309..dce9b033 100644 --- a/repl.mu +++ b/repl.mu @@ -9,7 +9,16 @@ recipe main [ { inst:address:array:character, 0:literal/real-keyboard, 0:literal/real-screen <- read-instruction 0:literal/real-keyboard, 0:literal/real-screen break-unless inst:address:array:character - 0:literal/real-screen <- print-string 0:literal/real-screen, inst:address:array:character +#? 0:literal/real-screen <- print-string 0:literal/real-screen, inst:address:array:character + run-interactive inst:address:array:character +#? print-character-to-display 97:literal/a +#? print-character-to-display 97:literal/a +#? print-character-to-display 97:literal/a +#? print-character-to-display 10:literal/newline + # assume run-interactive printed on the current line +#? $print [a7] #? 1 + move-cursor-down-on-display + clear-line-on-display # just to refresh the screen loop } return-to-console @@ -77,6 +86,9 @@ recipe slurp-regular-characters [ characters-slurped:number <- copy 0:literal { +next-character +#? $print [a0 #? 1 +#? ] #? 1 +#? move-cursor-down-on-display #? 1 # read character c:character, k:address:keyboard <- wait-for-key k:address:keyboard # quit? @@ -115,19 +127,40 @@ recipe slurp-regular-characters [ print-character x:address:screen, c:character # default color # append result:address:buffer <- buffer-append result:address:buffer, c:character +#? $print [a1 #? 1 +#? ] #? 1 +#? move-cursor-down-on-display #? 1 # backspace? decrement and maybe return { +#? $print [a2 #? 1 +#? ] #? 1 +#? move-cursor-down-on-display #? 1 backspace?:boolean <- equal c:character, 8:literal/backspace break-unless backspace?:boolean +#? $print [a3 #? 1 +#? ] #? 1 +#? move-cursor-down-on-display #? 1 characters-slurped:number <- subtract characters-slurped:number, 1:literal { +#? $print [a4 #? 1 +#? ] #? 1 +#? move-cursor-down-on-display #? 1 done?:boolean <- lesser-or-equal characters-slurped:number, 0:literal break-unless done?:boolean +#? $print [a5 #? 1 +#? ] #? 1 +#? move-cursor-down-on-display #? 1 trace [app], [slurp-regular-characters: too many backspaces; returning] +#? $print [a6 #? 1 +#? ] #? 1 +#? move-cursor-down-on-display #? 1 reply result:address:buffer, k:address:keyboard/same-as-ingredient:1, x:address:screen/same-as-ingredient:2 } loop +next-character:label } +#? $print [a9 #? 1 +#? ] #? 1 +#? move-cursor-down-on-display #? 1 # otherwise increment characters-slurped:number <- add characters-slurped:number, 1:literal # done with this instruction? |