about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-05-26 21:16:14 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-05-26 21:43:38 -0700
commita791c04264433696635d598471f3004c97f9ad50 (patch)
tree6a653a0f57d2af9a685056273128da86c6284f57
parent2b4bf8a800858d0e2209cd753b0ad1e95a4dfc1f (diff)
downloadmu-a791c04264433696635d598471f3004c97f9ad50.tar.gz
3020 - names in chessboard tests
Extremely ugly change.

Also ended up fixing some places where I was mixing up sources and
sinks. But I'm not going to bother updating edit/ and sandbox/ apps.
Just too many scenarios to clean up.
-rw-r--r--042name.cc12
-rw-r--r--083scenario_screen_test.mu10
-rw-r--r--chessboard.mu192
3 files changed, 118 insertions, 96 deletions
diff --git a/042name.cc b/042name.cc
index 9c40cf63..2dcfd524 100644
--- a/042name.cc
+++ b/042name.cc
@@ -59,6 +59,12 @@ void transform_names(const recipe_ordinal r) {
       int v = lookup_name(inst.ingredients.at(in), r);
       if (v >= 0) {
         inst.ingredients.at(in).set_value(v);
+        // HACK: belongs in a later layer, either in the scenario layer which
+        // introduces the 'run' pseudo-instruction which is translated to
+        // run_* recipes, or later when we start using screens and consoles in
+        // scenarios.
+        if (is_special_name(inst.ingredients.at(in).name) && caller.name.substr(0, 4) == "run_")
+          inst.ingredients.at(in).properties.push_back(pair<string, string_tree*>("raw", NULL));
       }
       else {
         raise << maybe(caller.name) << "can't find a place to store '" << inst.ingredients.at(in).name << "'\n" << end();
@@ -78,6 +84,12 @@ void transform_names(const recipe_ordinal r) {
       int v = lookup_name(inst.products.at(out), r);
       if (v >= 0) {
         inst.products.at(out).set_value(v);
+        // HACK: belongs in a later layer, either in the scenario layer which
+        // introduces the 'run' pseudo-instruction which is translated to
+        // run_* recipes, or later when we start using screens and consoles in
+        // scenarios.
+        if (is_special_name(inst.products.at(out).name) && caller.name.substr(0, 4) == "run_")
+          inst.products.at(out).properties.push_back(pair<string, string_tree*>("raw", NULL));
       }
       else {
         raise << maybe(caller.name) << "can't find a place to store '" << inst.products.at(out).name << "'\n" << end();
diff --git a/083scenario_screen_test.mu b/083scenario_screen_test.mu
index 9679e9cf..c96b6e56 100644
--- a/083scenario_screen_test.mu
+++ b/083scenario_screen_test.mu
@@ -3,8 +3,9 @@
 scenario print-character-at-top-left-2 [
   assume-screen 3/width, 2/height
   run [
-    1:character <- copy 97/a
-    screen:address:screen <- print screen:address:screen, 1:character/a
+    local-scope
+    a:character <- copy 97/a
+    screen:address:screen <- print screen:address:screen, a
   ]
   screen-should-contain [
     .a  .
@@ -15,9 +16,10 @@ scenario print-character-at-top-left-2 [
 scenario clear-line-erases-printed-characters-2 [
   assume-screen 5/width, 3/height
   run [
+    local-scope
     # print a character
-    1:character <- copy 97/a
-    screen:address:screen <- print screen:address:screen, 1:character/a
+    a:character <- copy 97/a
+    screen:address:screen <- print screen:address:screen, a
     # move cursor to start of line
     screen:address:screen <- move-cursor screen:address:screen, 0/row, 0/column
     # clear line
diff --git a/chessboard.mu b/chessboard.mu
index 57e40b19..5cd5d9db 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -28,10 +28,11 @@ scenario print-board-and-read-move [
 ]
   ]
   run [
+    local-scope
     screen:address:screen, console:address:console <- chessboard screen:address:screen, console:address:console
     # icon for the cursor
-    1:character/cursor-icon <- copy 9251/␣
-    screen <- print screen, 1:character/cursor-icon
+    cursor-icon:character <- copy 9251/␣
+    screen <- print screen, cursor-icon
   ]
   screen-should-contain [
   #            1         2         3         4         5         6         7         8         9         10        11
@@ -198,8 +199,9 @@ def initial-position -> board:address:array:address:array:character [
 scenario printing-the-board [
   assume-screen 30/width, 12/height
   run [
-    1:address:array:address:array:character/board <- initial-position
-    screen:address:screen <- print-board screen:address:screen, 1:address:array:address:array:character/board
+    local-scope
+    board:address:array:address:array:character <- initial-position
+    screen:address:screen <- print-board screen:address:screen, board
   ]
   screen-should-contain [
   #  012345678901234567890123456789
@@ -362,67 +364,68 @@ def expect-from-channel stdin:address:source:character, expected:character, scre
 scenario read-move-blocking [
   assume-screen 20/width, 2/height
   run [
-    1:address:source:character, 2:address:sink:character <- new-channel 2/capacity
-    3:number/routine <- start-running read-move, 1:address:source:character, screen:address:screen
+    local-scope
+    source:address:source:character, sink:address:sink:character <- new-channel 2/capacity
+    read-move-routine:number/routine <- start-running read-move, source, screen:address:screen
     # 'read-move' is waiting for input
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number/id
-    5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting
-    assert 5:boolean/waiting?, [ 
+    wait-for-routine read-move-routine
+    read-move-state:number <- routine-state read-move-routine
+    waiting?:boolean <- equal read-move-state, 3/waiting
+    assert waiting?, [ 
 F read-move-blocking: routine failed to pause after coming up (before any keys were pressed)]
     # press 'a'
-    2:address:sink:character <- write 2:address:sink:character, 97/a
-    restart 3:number/routine
+    sink <- write sink, 97/a
+    restart read-move-routine
     # 'read-move' still waiting for input
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number/id
-    5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting
-    assert 5:boolean/waiting?, [ 
+    wait-for-routine read-move-routine
+    read-move-state <- routine-state read-move-routine
+    waiting? <- equal read-move-state, 3/waiting
+    assert waiting?, [ 
 F read-move-blocking: routine failed to pause after rank 'a']
     # press '2'
-    2:address:sink:character <- write 2:address:sink:character, 50/'2'
-    restart 3:number/routine
+    sink <- write sink, 50/'2'
+    restart read-move-routine
     # 'read-move' still waiting for input
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number/id
-    5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting
-    assert 5:boolean/waiting?, [ 
+    wait-for-routine read-move-routine
+    read-move-state <- routine-state read-move-routine
+    waiting? <- equal read-move-state, 3/waiting
+    assert waiting?, [ 
 F read-move-blocking: routine failed to pause after file 'a2']
     # press '-'
-    2:address:sink:character <- write 2:address:sink:character, 45/'-'
-    restart 3:number/routine
+    sink <- write sink, 45/'-'
+    restart read-move-routine
     # 'read-move' still waiting for input
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number
-    5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting
-    assert 5:boolean/waiting?/routine-state, [ 
+    wait-for-routine read-move-routine
+    read-move-state <- routine-state read-move-routine
+    waiting? <- equal read-move-state, 3/waiting
+    assert waiting?, [ 
 F read-move-blocking: routine failed to pause after hyphen 'a2-']
     # press 'a'
-    2:address:sink:character <- write 2:address:sink:character, 97/a
-    restart 3:number/routine
+    sink <- write sink, 97/a
+    restart read-move-routine
     # 'read-move' still waiting for input
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number
-    5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting
-    assert 5:boolean/waiting?/routine-state, [ 
+    wait-for-routine read-move-routine
+    read-move-state <- routine-state read-move-routine
+    waiting? <- equal read-move-state, 3/waiting
+    assert waiting?, [ 
 F read-move-blocking: routine failed to pause after rank 'a2-a']
     # press '4'
-    2:address:sink:character <- write 2:address:sink:character, 52/'4'
-    restart 3:number/routine
+    sink <- write sink, 52/'4'
+    restart read-move-routine
     # 'read-move' still waiting for input
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number
-    5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting
-    assert 5:boolean/waiting?, [ 
+    wait-for-routine read-move-routine
+    read-move-state <- routine-state read-move-routine
+    waiting? <- equal read-move-state, 3/waiting
+    assert waiting?, [ 
 F read-move-blocking: routine failed to pause after file 'a2-a4']
     # press 'newline'
-    2:address:sink:character <- write 2:address:sink:character, 10  # newline
-    restart 3:number/routine
+    sink <- write sink, 10  # newline
+    restart read-move-routine
     # 'read-move' now completes
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number
-    5:boolean/completed? <- equal 4:number/routine-state, 1/completed
-    assert 5:boolean/completed?, [ 
+    wait-for-routine read-move-routine
+    read-move-state <- routine-state read-move-routine
+    completed?:boolean <- equal read-move-state, 1/completed
+    assert completed?, [ 
 F read-move-blocking: routine failed to terminate on newline]
     trace 1, [test], [reached end]
   ]
@@ -434,22 +437,23 @@ F read-move-blocking: routine failed to terminate on newline]
 scenario read-move-quit [
   assume-screen 20/width, 2/height
   run [
-    1:address:source:character, 2:address:sink:character <- new-channel 2/capacity
-    3:number/routine <- start-running read-move, 1:address:channel:character, screen:address:screen
+    local-scope
+    source:address:source:character, sink:address:sink:character <- new-channel 2/capacity
+    read-move-routine:number <- start-running read-move, source, screen:address:screen
     # 'read-move' is waiting for input
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number/id
-    5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting
-    assert 5:boolean/waiting?, [ 
+    wait-for-routine read-move-routine
+    read-move-state:number <- routine-state read-move-routine
+    waiting?:boolean <- equal read-move-state, 3/waiting
+    assert waiting?, [ 
 F read-move-quit: routine failed to pause after coming up (before any keys were pressed)]
     # press 'q'
-    2:address:sink:character <- write 2:address:sink:character, 113/q
-    restart 3:number/routine
+    sink <- write sink, 113/q
+    restart read-move-routine
     # 'read-move' completes
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number/id
-    5:boolean/completed? <- equal 4:number/routine-state, 1/completed
-    assert 5:boolean/completed?, [ 
+    wait-for-routine read-move-routine
+    read-move-state <- routine-state read-move-routine
+    completed?:boolean <- equal read-move-state, 1/completed
+    assert completed?, [ 
 F read-move-quit: routine failed to terminate on 'q']
     trace 1, [test], [reached end]
   ]
@@ -461,17 +465,18 @@ F read-move-quit: routine failed to terminate on 'q']
 scenario read-move-illegal-file [
   assume-screen 20/width, 2/height
   run [
-    1:address:source:character, 2:address:sink:character <- new-channel 2/capacity
-    3:number/routine <- start-running read-move, 1:address:source:character, screen:address:screen
+    local-scope
+    source:address:source:character, sink:address:sink:character <- new-channel 2/capacity
+    read-move-routine:number <- start-running read-move, source, screen:address:screen
     # 'read-move' is waiting for input
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number/id
-    5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting
-    assert 5:boolean/waiting?, [ 
+    wait-for-routine read-move-routine
+    read-move-state:number <- routine-state read-move-routine
+    waiting?:boolean <- equal read-move-state, 3/waiting
+    assert waiting?, [ 
 F read-move-file: routine failed to pause after coming up (before any keys were pressed)]
-    1:address:sink:character <- write 1:address:sink:character, 50/'2'
-    restart 3:number/routine
-    wait-for-routine 3:number
+    sink <- write sink, 50/'2'
+    restart read-move-routine
+    wait-for-routine read-move-routine
   ]
   screen-should-contain [
     .file too low: 2     .
@@ -482,18 +487,19 @@ F read-move-file: routine failed to pause after coming up (before any keys were
 scenario read-move-illegal-rank [
   assume-screen 20/width, 2/height
   run [
-    1:address:source:character, 2:address:sink:character <- new-channel 2/capacity
-    3:number/routine <- start-running read-move, 1:address:source:character, screen:address:screen
+    local-scope
+    source:address:source:character, sink:address:sink:character <- new-channel 2/capacity
+    read-move-routine:number <- start-running read-move, source, screen:address:screen
     # 'read-move' is waiting for input
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number/id
-    5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting
-    assert 5:boolean/waiting?, [ 
+    wait-for-routine read-move-routine
+    read-move-state:number <- routine-state read-move-routine
+    waiting?:boolean <- equal read-move-state, 3/waiting
+    assert waiting?, [ 
 F read-move-file: routine failed to pause after coming up (before any keys were pressed)]
-    1:address:sink:character <- write 1:address:sink:character, 97/a
-    1:address:sink:character <- write 1:address:sink:character, 97/a
-    restart 3:number/routine
-    wait-for-routine 3:number
+    sink <- write sink, 97/a
+    sink <- write sink, 97/a
+    restart read-move-routine
+    wait-for-routine read-move-routine
   ]
   screen-should-contain [
     .rank too high: a    .
@@ -504,18 +510,19 @@ F read-move-file: routine failed to pause after coming up (before any keys were
 scenario read-move-empty [
   assume-screen 20/width, 2/height
   run [
-    1:address:source:character, 2:address:sink:character <- new-channel 2/capacity
-    3:number/routine <- start-running read-move, 1:address:source:character, screen:address:screen
+    local-scope
+    source:address:source:character, sink:address:sink:character <- new-channel 2/capacity
+    read-move-routine:number <- start-running read-move, source, screen:address:screen
     # 'read-move' is waiting for input
-    wait-for-routine 3:number
-    4:number <- routine-state 3:number/id
-    5:boolean/waiting? <- equal 4:number/routine-state, 3/waiting
-    assert 5:boolean/waiting?, [ 
+    wait-for-routine read-move-routine
+    read-move-state:number <- routine-state read-move-routine
+    waiting?:boolean <- equal read-move-state, 3/waiting
+    assert waiting?, [ 
 F read-move-file: routine failed to pause after coming up (before any keys were pressed)]
-    1:address:sink:character <- write 1:address:sink:character, 10/newline
-    1:address:sink:character <- write 1:address:sink:character, 97/a
-    restart 3:number/routine
-    wait-for-routine 3:number
+    sink <- write sink, 10/newline
+    sink <- write sink, 97/a
+    restart read-move-routine
+    wait-for-routine read-move-routine
   ]
   screen-should-contain [
     .that's not enough   .
@@ -540,11 +547,12 @@ def make-move board:address:array:address:array:character, m:address:move -> boa
 scenario making-a-move [
   assume-screen 30/width, 12/height
   run [
-    2:address:array:address:array:character/board <- initial-position
-    3:address:move <- new move:type
-    *3:address:move <- merge 6/g, 1/'2', 6/g, 3/'4'
-    2:address:array:address:array:character/board <- make-move 2:address:array:address:array:character/board, 3:address:move
-    screen:address:screen <- print-board screen:address:screen, 2:address:array:address:array:character/board
+    local-scope
+    board:address:array:address:array:character <- initial-position
+    move:address:move <- new move:type
+    *move <- merge 6/g, 1/'2', 6/g, 3/'4'
+    board <- make-move board, move
+    screen:address:screen <- print-board screen:address:screen, board
   ]
   screen-should-contain [
   #  012345678901234567890123456789