From dd66068298b0a11f2a1f195376cba98e0c8570b5 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 17 Jun 2018 00:05:38 -0700 Subject: 4261 - start using literals for 'true' and 'false' They uncovered one bug: in edit/003-shortcuts.mu was returning 0 for an address in one place where I thought it was returning 0 for a boolean. Now we've eliminated this bad interaction between tangling and punning literals. --- sandbox/002-typing.mu | 50 ++++++++++++++++---------------- sandbox/003-shortcuts.mu | 52 +++++++++++++++++----------------- sandbox/004-programming-environment.mu | 4 +-- sandbox/005-sandbox.mu | 2 +- sandbox/006-sandbox-copy.mu | 10 +++---- sandbox/007-sandbox-delete.mu | 6 ++-- sandbox/008-sandbox-edit.mu | 8 +++--- sandbox/011-errors.mu | 6 ++-- sandbox/012-editor-undo.mu | 4 +-- 9 files changed, 71 insertions(+), 71 deletions(-) (limited to 'sandbox') diff --git a/sandbox/002-typing.mu b/sandbox/002-typing.mu index 47885c4f..a67fcf3c 100644 --- a/sandbox/002-typing.mu +++ b/sandbox/002-typing.mu @@ -50,23 +50,23 @@ def editor-event-loop screen:&:screen, console:&:console, editor:&:editor -> scr def move-cursor editor:&:editor, screen:&:screen, t:touch-event -> in-focus?:bool, editor:&:editor [ local-scope load-inputs - return-unless editor, 0/false + return-unless editor, false click-row:num <- get t, row:offset - return-unless click-row, 0/false # ignore clicks on 'menu' + return-unless click-row, false # ignore clicks on 'menu' click-column:num <- get t, column:offset left:num <- get *editor, left:offset too-far-left?:bool <- lesser-than click-column, left - return-if too-far-left?, 0/false + return-if too-far-left?, false right:num <- get *editor, right:offset too-far-right?:bool <- greater-than click-column, right - return-if too-far-right?, 0/false + return-if too-far-right?, false # position cursor editor <- snap-cursor editor, screen, click-row, click-column undo-coalesce-tag:num <- copy 0/never # gain focus - return 1/true + return true ] # Variant of 'render' that only moves the cursor (coordinates and @@ -166,7 +166,7 @@ def snap-cursor editor:&:editor, screen:&:screen, target-row:num, target-column: def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> go-render?:bool, screen:&:screen, editor:&:editor [ local-scope load-inputs - return-unless editor, 0/don't-render + return-unless editor, false/don't-render screen-width:num <- screen-width screen screen-height:num <- screen-height screen left:num <- get *editor, left:offset @@ -185,7 +185,7 @@ def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> go-render # ignore any other special characters regular-character?:bool <- greater-or-equal c, 32/space - return-unless regular-character?, 0/don't-render + return-unless regular-character?, false/don't-render # otherwise type it in go-render? <- insert-at-cursor editor, c, screen @@ -197,7 +197,7 @@ def handle-keyboard-event screen:&:screen, editor:&:editor, e:event -> go-render assert is-keycode?, [event was of unknown type; neither keyboard nor mouse] # handlers for each special key will go here - return 1/go-render + return true/go-render ] def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> go-render?:bool, editor:&:editor, screen:&:screen [ @@ -232,7 +232,7 @@ def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> go-render?:bool break-if overflow? move-cursor screen, save-row, save-column print screen, c - return 0/don't-render + return false/don't-render } { # not at right margin? print the character and rest of line @@ -245,7 +245,7 @@ def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> go-render?:bool { # hit right margin? give up and let caller render at-right?:bool <- greater-than curr-column, right - return-if at-right?, 1/go-render + return-if at-right?, true/go-render break-unless curr # newline? done. currc:char <- get *curr, value:offset @@ -256,9 +256,9 @@ def insert-at-cursor editor:&:editor, c:char, screen:&:screen -> go-render?:bool curr <- next curr loop } - return 0/don't-render + return false/don't-render } - return 1/go-render + return true/go-render ] # helper for tests @@ -708,7 +708,7 @@ after [ at-end-of-line? <- equal next-character, 10/newline } # break unless ((eol? and at-wrap?) or (~eol? and just-before-wrap?)) - move-cursor-to-next-line?:bool <- copy 0/false + move-cursor-to-next-line?:bool <- copy false { break-if at-end-of-line? move-cursor-to-next-line? <- copy just-before-wrap? @@ -735,7 +735,7 @@ after [ break-unless below-screen? } - return 1/go-render + return true/go-render } ] @@ -829,7 +829,7 @@ container editor [ ] after [ - *result <- put *result, indent?:offset, 1/true + *result <- put *result, indent?:offset, true ] scenario editor-moves-cursor-down-after-inserting-newline [ @@ -859,7 +859,7 @@ after [ insert-new-line-and-indent editor, screen - return 1/go-render + return true/go-render } ] @@ -885,7 +885,7 @@ def insert-new-line-and-indent editor:&:editor, screen:&:screen -> editor:&:edit { below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal, never greater break-unless below-screen? - + cursor-row <- subtract cursor-row, 1 # bring back into screen range *editor <- put *editor, cursor-row:offset, cursor-row } @@ -915,16 +915,16 @@ def at-start-of-wrapped-line? editor:&:editor -> result:bool [ left:num <- get *editor, left:offset cursor-column:num <- get *editor, cursor-column:offset cursor-at-left?:bool <- equal cursor-column, left - return-unless cursor-at-left?, 0/false + return-unless cursor-at-left?, false before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset before-before-cursor:&:duplex-list:char <- prev before-cursor - return-unless before-before-cursor, 0/false # cursor is at start of editor + return-unless before-before-cursor, false # cursor is at start of editor char-before-cursor:char <- get *before-cursor, value:offset cursor-after-newline?:bool <- equal char-before-cursor, 10/newline - return-if cursor-after-newline?, 0/false + return-if cursor-after-newline?, false # if cursor is at left margin and not at start, but previous character is not a newline, # then we're at start of a wrapped line - return 1/true + return true ] # takes a pointer 'curr' into the doubly-linked list and its sentinel, counts @@ -1095,8 +1095,8 @@ after [ { paste-start?:bool <- equal k, 65507/paste-start break-unless paste-start? - *editor <- put *editor, indent?:offset, 0/false - return 1/go-render + *editor <- put *editor, indent?:offset, false + return true/go-render } ] @@ -1104,8 +1104,8 @@ after [ { paste-end?:bool <- equal k, 65506/paste-end break-unless paste-end? - *editor <- put *editor, indent?:offset, 1/true - return 1/go-render + *editor <- put *editor, indent?:offset, true + return true/go-render } ] diff --git a/sandbox/003-shortcuts.mu b/sandbox/003-shortcuts.mu index c12429f0..db19443d 100644 --- a/sandbox/003-shortcuts.mu +++ b/sandbox/003-shortcuts.mu @@ -113,7 +113,7 @@ def delete-before-cursor editor:&:editor, screen:&:screen -> go-render?:bool, ba data:&:duplex-list:char <- get *editor, data:offset # if at start of text (before-cursor at § sentinel), return prev:&:duplex-list:char <- prev before-cursor - return-unless prev, 0/no-more-render, 0/nothing-deleted + return-unless prev, false/no-more-render, 0/nothing-deleted trace 10, [app], [delete-before-cursor] original-row:num <- get *editor, cursor-row:offset move-cursor-coordinates-left editor @@ -126,7 +126,7 @@ def delete-before-cursor editor:&:editor, screen:&:screen -> go-render?:bool, ba cursor-column:num <- get *editor, cursor-column:offset # did we just backspace over a newline? same-row?:bool <- equal cursor-row, original-row - return-unless same-row?, 1/go-render + return-unless same-row?, true/go-render left:num <- get *editor, left:offset right:num <- get *editor, right:offset curr:&:duplex-list:char <- next before-cursor @@ -135,7 +135,7 @@ def delete-before-cursor editor:&:editor, screen:&:screen -> go-render?:bool, ba { # hit right margin? give up and let caller render at-right?:bool <- greater-or-equal curr-column, right - return-if at-right?, 1/go-render + return-if at-right?, true/go-render break-unless curr # newline? done. currc:char <- get *curr, value:offset @@ -149,7 +149,7 @@ def delete-before-cursor editor:&:editor, screen:&:screen -> go-render?:bool, ba # we're guaranteed not to be at the right margin space:char <- copy 32/space screen <- print screen, space - go-render? <- copy 0/false + go-render? <- copy false ] def move-cursor-coordinates-left editor:&:editor -> editor:&:editor [ @@ -373,11 +373,11 @@ def delete-at-cursor editor:&:editor, screen:&:screen -> go-render?:bool, delete before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset data:&:duplex-list:char <- get *editor, data:offset deleted-cell:&:duplex-list:char <- next before-cursor - return-unless deleted-cell, 0/don't-render + return-unless deleted-cell, false/don't-render currc:char <- get *deleted-cell, value:offset data <- remove deleted-cell, data deleted-newline?:bool <- equal currc, 10/newline - return-if deleted-newline?, 1/go-render + return-if deleted-newline?, true/go-render # wasn't a newline? render rest of line curr:&:duplex-list:char <- next before-cursor # refresh after remove above cursor-row:num <- get *editor, cursor-row:offset @@ -388,7 +388,7 @@ def delete-at-cursor editor:&:editor, screen:&:screen -> go-render?:bool, delete { # hit right margin? give up and let caller render at-right?:bool <- greater-or-equal curr-column, screen-width - return-if at-right?, 1/go-render + return-if at-right?, true/go-render break-unless curr currc:char <- get *curr, value:offset at-newline?:bool <- equal currc, 10/newline @@ -401,7 +401,7 @@ def delete-at-cursor editor:&:editor, screen:&:screen -> go-render?:bool, delete # we're guaranteed not to be at the right margin space:char <- copy 32/space screen <- print screen, space - go-render? <- copy 0/false + go-render? <- copy false ] # right arrow @@ -465,10 +465,10 @@ def move-cursor-coordinates-right editor:&:editor, screen-height:num -> go-rende cursor-column <- copy left *editor <- put *editor, cursor-column:offset, cursor-column below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal - return-unless below-screen?, 0/don't-render + return-unless below-screen?, false/don't-render cursor-row <- subtract cursor-row, 1 # bring back into screen range *editor <- put *editor, cursor-row:offset, cursor-row - return 1/go-render + return true/go-render } # if the line wraps, move cursor to start of next row { @@ -487,15 +487,15 @@ def move-cursor-coordinates-right editor:&:editor, screen-height:num -> go-rende cursor-column <- copy left *editor <- put *editor, cursor-column:offset, cursor-column below-screen?:bool <- greater-or-equal cursor-row, screen-height # must be equal - return-unless below-screen?, 0/no-more-render + return-unless below-screen?, false/no-more-render cursor-row <- subtract cursor-row, 1 # bring back into screen range *editor <- put *editor, cursor-row:offset, cursor-row - return 1/go-render + return true/go-render } # otherwise move cursor one character right cursor-column <- add cursor-column, 1 *editor <- put *editor, cursor-column:offset, cursor-column - go-render? <- copy 0/false + go-render? <- copy false ] scenario editor-moves-cursor-to-next-line-with-right-arrow [ @@ -717,7 +717,7 @@ after [ trace 10, [app], [left arrow] # if not at start of text (before-cursor at § sentinel) prev:&:duplex-list:char <- prev before-cursor - return-unless prev, 0/don't-render + return-unless prev, false/don't-render move-cursor-coordinates-left editor before-cursor <- copy prev @@ -1511,7 +1511,7 @@ after [ move-to-start-of-screen-line editor undo-coalesce-tag:num <- copy 0/never - return 0/don't-render + return false/don't-render } ] @@ -1523,7 +1523,7 @@ after [ move-to-start-of-screen-line editor undo-coalesce-tag:num <- copy 0/never - return 0/don't-render + return false/don't-render } ] @@ -1736,7 +1736,7 @@ after [ move-to-end-of-line editor undo-coalesce-tag:num <- copy 0/never - return 0/don't-render + return false/don't-render } ] @@ -1748,7 +1748,7 @@ after [ move-to-end-of-line editor undo-coalesce-tag:num <- copy 0/never - return 0/don't-render + return false/don't-render } ] @@ -1947,7 +1947,7 @@ def minimal-render-for-ctrl-u screen:&:screen, editor:&:editor, deleted-cells:&: { # if we have a wrapped line, give up and render the whole screen wrap?:bool <- greater-or-equal i, right - return-if wrap?, 1/go-render + return-if wrap?, true/go-render curr <- next curr break-unless curr c:char <- get *curr, value:offset @@ -1963,11 +1963,11 @@ def minimal-render-for-ctrl-u screen:&:screen, editor:&:editor, deleted-cells:&: left:num <- get *editor, left:offset end:num <- subtract right, left wrap?:bool <- greater-or-equal old-row-len, end - return-if wrap?, 1/go-render + return-if wrap?, true/go-render curr-line:text <- buffer-to-array buf curr-row:num <- get *editor, cursor-row:offset render-code screen, curr-line, curr-column, right, curr-row - return 0/dont-render + return false/dont-render ] def delete-to-start-of-line editor:&:editor -> result:&:duplex-list:char, editor:&:editor [ @@ -2332,7 +2332,7 @@ def minimal-render-for-ctrl-k screen:&:screen, editor:&:editor, deleted-cells:&: local-scope load-inputs # if we deleted nothing, there's nothing to render - return-unless deleted-cells, 0/dont-render + return-unless deleted-cells, false/dont-render # if the line used to wrap before, give up and render the whole screen curr-column:num <- get *editor, cursor-column:offset num-deleted-cells:num <- length deleted-cells @@ -2341,9 +2341,9 @@ def minimal-render-for-ctrl-k screen:&:screen, editor:&:editor, deleted-cells:&: right:num <- get *editor, right:offset end:num <- subtract right, left wrap?:bool <- greater-or-equal old-row-len, end - return-if wrap?, 1/go-render + return-if wrap?, true/go-render clear-line-until screen, right - return 0/dont-render + return false/dont-render ] def delete-to-end-of-line editor:&:editor -> result:&:duplex-list:char, editor:&:editor [ @@ -2613,7 +2613,7 @@ def render-line-from-start screen:&:screen, editor:&:editor, right-margin:num -> curr:&:duplex-list:char <- copy line-start { render-all?:bool <- greater-or-equal i, end - return-if render-all?, 1/go-render + return-if render-all?, true/go-render break-unless curr c:char <- get *curr, value:offset newline?:bool <- equal c, 10/newline @@ -2625,7 +2625,7 @@ def render-line-from-start screen:&:screen, editor:&:editor, right-margin:num -> loop } clear-line-until screen, right - return 0/dont-render + return false/dont-render ] def before-start-of-screen-line editor:&:editor -> result:&:duplex-list:char [ diff --git a/sandbox/004-programming-environment.mu b/sandbox/004-programming-environment.mu index dccd7c9a..1208d0e8 100644 --- a/sandbox/004-programming-environment.mu +++ b/sandbox/004-programming-environment.mu @@ -31,7 +31,7 @@ def event-loop screen:&:screen, console:&:console, env:&:environment, resources: # if we fall behind we'll stop updating the screen, but then we have to # render the entire screen when we catch up. # todo: test this - render-all-on-no-more-events?:bool <- copy 0/false + render-all-on-no-more-events?:bool <- copy false { # looping over each (keyboard or touch) event as it occurs +next-event @@ -86,7 +86,7 @@ def event-loop screen:&:screen, console:&:console, env:&:environment, resources: { break-if more-events? break-unless render-all-on-no-more-events? - render-all-on-no-more-events? <- copy 0/false + render-all-on-no-more-events? <- copy false screen <- render-all screen, env, render } screen <- update-cursor screen, current-sandbox, env diff --git a/sandbox/005-sandbox.mu b/sandbox/005-sandbox.mu index 4b56ad27..ae4372a1 100644 --- a/sandbox/005-sandbox.mu +++ b/sandbox/005-sandbox.mu @@ -188,7 +188,7 @@ def update-recipes env:&:environment, resources:&:resources, screen:&:screen -> load-inputs in:text <- slurp resources, [lesson/recipes.mu] reload in - errors-found? <- copy 0/false + errors-found? <- copy false ] # replaced in a later layer diff --git a/sandbox/006-sandbox-copy.mu b/sandbox/006-sandbox-copy.mu index 541618e6..4b7222f3 100644 --- a/sandbox/006-sandbox-copy.mu +++ b/sandbox/006-sandbox-copy.mu @@ -154,7 +154,7 @@ def should-attempt-copy? click-row:num, click-column:num, env:&:environment -> r load-inputs # are we below the sandbox editor? click-sandbox-area?:bool <- click-on-sandbox-area? click-row, env - return-unless click-sandbox-area?, 0/false + return-unless click-sandbox-area?, false # narrower, is the click in the columns spanning the 'copy' button? first-sandbox:&:editor <- get *env, current-sandbox:offset assert first-sandbox, [!!] @@ -162,7 +162,7 @@ def should-attempt-copy? click-row:num, click-column:num, env:&:environment -> r sandbox-right-margin:num <- get *first-sandbox, right:offset _, _, copy-button-left:num, copy-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin copy-button-vertical-area?:bool <- within-range? click-column, copy-button-left, copy-button-right - return-unless copy-button-vertical-area?, 0/false + return-unless copy-button-vertical-area?, false # finally, is sandbox editor empty? current-sandbox:&:editor <- get *env, current-sandbox:offset result <- empty-editor? current-sandbox @@ -173,8 +173,8 @@ def try-copy-sandbox click-row:num, env:&:environment -> clicked-on-copy-button? load-inputs # identify the sandbox to copy, if the click was actually on the 'copy' button sandbox:&:sandbox <- find-sandbox env, click-row - return-unless sandbox, 0/false - clicked-on-copy-button? <- copy 1/true + return-unless sandbox, false + clicked-on-copy-button? <- copy true text:text <- get *sandbox, data:offset current-sandbox:&:editor <- get *env, current-sandbox:offset current-sandbox <- insert-text current-sandbox, text @@ -201,7 +201,7 @@ def click-on-sandbox-area? click-row:num, env:&:environment -> result:bool [ local-scope load-inputs first-sandbox:&:sandbox <- get *env, sandbox:offset - return-unless first-sandbox, 0/false + return-unless first-sandbox, false first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset result <- greater-or-equal click-row, first-sandbox-begins ] diff --git a/sandbox/007-sandbox-delete.mu b/sandbox/007-sandbox-delete.mu index 2e8ab759..01f01f42 100644 --- a/sandbox/007-sandbox-delete.mu +++ b/sandbox/007-sandbox-delete.mu @@ -82,7 +82,7 @@ def should-attempt-delete? click-row:num, click-column:num, env:&:environment -> load-inputs # are we below the sandbox editor? click-sandbox-area?:bool <- click-on-sandbox-area? click-row, env - return-unless click-sandbox-area?, 0/false + return-unless click-sandbox-area?, false # narrower, is the click in the columns spanning the 'copy' button? first-sandbox:&:editor <- get *env, current-sandbox:offset assert first-sandbox, [!!] @@ -97,8 +97,8 @@ def try-delete-sandbox click-row:num, env:&:environment -> clicked-on-delete-but load-inputs # identify the sandbox to delete, if the click was actually on the 'delete' button sandbox:&:sandbox <- find-sandbox env, click-row - return-unless sandbox, 0/false - clicked-on-delete-button? <- copy 1/true + return-unless sandbox, false + clicked-on-delete-button? <- copy true env <- delete-sandbox env, sandbox ] diff --git a/sandbox/008-sandbox-edit.mu b/sandbox/008-sandbox-edit.mu index 3cef65ce..fb3981bf 100644 --- a/sandbox/008-sandbox-edit.mu +++ b/sandbox/008-sandbox-edit.mu @@ -125,7 +125,7 @@ def should-attempt-edit? click-row:num, click-column:num, env:&:environment -> r load-inputs # are we below the sandbox editor? click-sandbox-area?:bool <- click-on-sandbox-area? click-row, env - return-unless click-sandbox-area?, 0/false + return-unless click-sandbox-area?, false # narrower, is the click in the columns spanning the 'edit' button? first-sandbox:&:editor <- get *env, current-sandbox:offset assert first-sandbox, [!!] @@ -133,7 +133,7 @@ def should-attempt-edit? click-row:num, click-column:num, env:&:environment -> r sandbox-right-margin:num <- get *first-sandbox, right:offset edit-button-left:num, edit-button-right:num, _ <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin edit-button-vertical-area?:bool <- within-range? click-column, edit-button-left, edit-button-right - return-unless edit-button-vertical-area?, 0/false + return-unless edit-button-vertical-area?, false # finally, is sandbox editor empty? current-sandbox:&:editor <- get *env, current-sandbox:offset result <- empty-editor? current-sandbox @@ -144,8 +144,8 @@ def try-edit-sandbox click-row:num, env:&:environment -> clicked-on-edit-button? load-inputs # identify the sandbox to edit, if the click was actually on the 'edit' button sandbox:&:sandbox <- find-sandbox env, click-row - return-unless sandbox, 0/false - clicked-on-edit-button? <- copy 1/true + return-unless sandbox, false + clicked-on-edit-button? <- copy true # 'edit' button = 'copy' button + 'delete' button text:text <- get *sandbox, data:offset current-sandbox:&:editor <- get *env, current-sandbox:offset diff --git a/sandbox/011-errors.mu b/sandbox/011-errors.mu index 893515bf..8678989f 100644 --- a/sandbox/011-errors.mu +++ b/sandbox/011-errors.mu @@ -15,10 +15,10 @@ def! update-recipes env:&:environment, resources:&:resources, screen:&:screen -> { break-unless recipe-errors update-status screen, [errors found ], 1/red - errors-found? <- copy 1/true + errors-found? <- copy true return } - errors-found? <- copy 0/false + errors-found? <- copy false ] before [ @@ -47,7 +47,7 @@ before [ error-index:num <- get *env, error-index:offset sandboxes-completed-successfully?:bool <- equal error-index, -1 break-if sandboxes-completed-successfully? - errors-found? <- copy 1/true + errors-found? <- copy true } ] diff --git a/sandbox/012-editor-undo.mu b/sandbox/012-editor-undo.mu index e5782f0c..23448ea2 100644 --- a/sandbox/012-editor-undo.mu +++ b/sandbox/012-editor-undo.mu @@ -74,7 +74,7 @@ after [ redo <- push op, redo *editor <- put *editor, redo:offset, redo - return 1/go-render + return true/go-render } ] @@ -92,7 +92,7 @@ after [ undo <- push op, undo *editor <- put *editor, undo:offset, undo - return 1/go-render + return true/go-render } ] -- cgit 1.4.1-2-gfad0