summary refs log blame commit diff stats
path: root/LICENSE
blob: 8cb51645a3f41b240015fe9ee6bce9a45910b6d1 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                                        
Copyright (c) 2020, Andinus <andinus@nand.sh>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
multiple files' href='/akkartik/mu/commit/edit/008-sandbox-trace.mu?h=hlt&id=a90faae99043042ec5e2d0de21b7dbe0eba29e3a'>a90faae9 ^
455fbac6 ^
bbe0801a ^
455fbac6 ^
a90faae9 ^





3151fb23 ^
a90faae9 ^



















455fbac6 ^

a90faae9 ^





3151fb23 ^
a90faae9 ^






e00d4854 ^
a90faae9 ^

455fbac6 ^
a90faae9 ^

1ead3562 ^
a90faae9 ^

455fbac6 ^
a90faae9 ^


455fbac6 ^

a90faae9 ^



3151fb23 ^
c1585c88 ^
a90faae9 ^



fa94f4d9 ^
a90faae9 ^



455fbac6 ^
a90faae9 ^
fa94f4d9 ^
a90faae9 ^



3151fb23 ^
c1585c88 ^
a90faae9 ^






b4bccf49 ^
455fbac6 ^
b4bccf49 ^



1ead3562 ^
b4bccf49 ^
350ca0c6 ^
455fbac6 ^



b4bccf49 ^


a90faae9 ^

fa94f4d9 ^
a90faae9 ^




455fbac6 ^
a90faae9 ^





455fbac6 ^
a90faae9 ^





aaf61a53 ^
a90faae9 ^





1ead3562 ^
a90faae9 ^
350ca0c6 ^
a90faae9 ^
350ca0c6 ^
a90faae9 ^




455fbac6 ^
a90faae9 ^








bbc28b80 ^
a90faae9 ^




1ead3562 ^
a90faae9 ^
1ead3562 ^
a90faae9 ^






455fbac6 ^
a90faae9 ^
3f7eed6c ^
a90faae9 ^
8beff53e ^
a90faae9 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210


                                                              
                                       

                                   
                                            



             
                                               


                  

                                                                                                                                                                               



                                                                                      
                                                



                                                                                                                              
                                    



                    
                                                                                                                          
                                            
                                                               





                                                                                      
                                                



















                                                                                        

                                                                                                                          





                                                                                      
                                                






                                                                                                                              
                                       

                                   
                                            

             
         

          
                                               


                  

                                                                                                                                                                               



                                                                                      
                                                
                                                



                                                                                                                              
                                    



                    
                                                                                                                          
   
                                  



                                                                                      
                                                
                                                






                                                                                        
                        
                                      



                           
                                                                                                                                                                                                              
             
                  



                                                                                          


                                                            

                                                       
                                                




                                                                                  
                                                                         





                                                                                     
                                                                                    





                                                                    
                                                                                     





                          
                                                                                                                                         
             
                  
                                                      
                                     




                                                                                   
                                                                                 








                                                                          
                                                                         




                                                                                
                                       
   
                






                                                                                                    
                                                                              
                                                           
                                                                           
   
                             
 
## clicking on the code typed into a sandbox toggles its trace

scenario sandbox-click-on-code-toggles-app-trace [
  trace-until 100/app  # trace too long
  assume-screen 40/width, 10/height
  # basic recipe
  1:address:shared:array:character <- new [ 
recipe foo [
  stash [abc]
]]
  # run it
  2:address:shared:array:character <- new [foo]
  assume-console [
    press F4
  ]
  3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character
  event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data
  screen-should-contain [
    .                     run (F4)           .
    .                                       .
    .recipe foo [        ┊━━━━━━━━━━━━━━━━━━━.
    .  stash [abc]       0                 x.
    .]                   foo                .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━.
    .                                       .
  ]
  # click on the code in the sandbox
  assume-console [
    left-click 4, 21
  ]
  run [
    event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data
    4:character/cursor-icon <- copy 9251/    print screen:address:shared:screen, 4:character/cursor-icon
  ]
  # trace now printed and cursor shouldn't have budged
  screen-should-contain [
    .                     run (F4)           .
    .                                      .
    .recipe foo [        ┊━━━━━━━━━━━━━━━━━━━.
    .  stash [abc]       0                 x.
    .]                   foo                .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊abc                .
    .                    ┊━━━━━━━━━━━━━━━━━━━.
    .                                       .
  ]
  screen-should-contain-in-color 245/grey, [
    .                                        .
    .                                       .
    .                    ┊━━━━━━━━━━━━━━━━━━━.
    .                                      x.
    .                                       .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊abc                .
    .                    ┊━━━━━━━━━━━━━━━━━━━.
    .                                       .
  ]
  # click again on the same region
  assume-console [
    left-click 4, 25
  ]
  run [
    event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data
    print screen:address:shared:screen, 4:character/cursor-icon
  ]
  # trace hidden again
  screen-should-contain [
    .                     run (F4)           .
    .                                      .
    .recipe foo [        ┊━━━━━━━━━━━━━━━━━━━.
    .  stash [abc]       0                 x.
    .]                   foo                .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━.
    .                                       .
  ]
]

scenario sandbox-shows-app-trace-and-result [
  trace-until 100/app  # trace too long
  assume-screen 40/width, 10/height
  # basic recipe
  1:address:shared:array:character <- new [ 
recipe foo [
  stash [abc]
  reply 4
]]
  # run it
  2:address:shared:array:character <- new [foo]
  assume-console [
    press F4
  ]
  3:address:shared:programming-environment-data <- new-programming-environment screen:address:shared:screen, 1:address:shared:array:character, 2:address:shared:array:character
  event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data
  screen-should-contain [
    .                     run (F4)           .
    .                                       .
    .recipe foo [        ┊━━━━━━━━━━━━━━━━━━━.
    .  stash [abc]       0                 x.
    .  reply 4           foo                .
    .]                   4                  .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━.
    .                                       .
  ]
  # click on the code in the sandbox
  assume-console [
    left-click 4, 21
  ]
  run [
    event-loop screen:address:shared:screen, console:address:shared:console, 3:address:shared:programming-environment-data
  ]
  # trace now printed above result
  screen-should-contain [
    .                     run (F4)           .
    .                                       .
    .recipe foo [        ┊━━━━━━━━━━━━━━━━━━━.
    .  stash [abc]       0                 x.
    .  reply 4           foo                .
    .]                   abc                .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊4                  .
    .                    ┊━━━━━━━━━━━━━━━━━━━.
    .                                       .
  ]
]

container sandbox-data [
  trace:address:shared:array:character
  display-trace?:boolean
]

# replaced in a later layer
def! update-sandbox sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data, idx:number -> sandbox:address:shared:sandbox-data, env:address:shared:programming-environment-data [
  local-scope
  load-ingredients
  data:address:shared:array:character <- get *sandbox, data:offset
  response:address:address:shared:array:character <- get-address *sandbox, response:offset
  trace:address:address:shared:array:character <- get-address *sandbox, trace:offset
  fake-screen:address:address:shared:screen <- get-address *sandbox, screen:offset
  *response, _, *fake-screen, *trace <- run-interactive data
]

# clicks on sandbox code toggle its display-trace? flag
after <global-touch> [
  # check if it's inside the code of any sandbox
  {
    sandbox-left-margin:number <- get *current-sandbox, left:offset
    click-column:number <- get *t, column:offset
    on-sandbox-side?:boolean <- greater-or-equal click-column, sandbox-left-margin
    break-unless on-sandbox-side?
    first-sandbox:address:shared:sandbox-data <- get *env, sandbox:offset
    break-unless first-sandbox
    first-sandbox-begins:number <- get *first-sandbox, starting-row-on-screen:offset
    click-row:number <- get *t, row:offset
    below-sandbox-editor?:boolean <- greater-or-equal click-row, first-sandbox-begins
    break-unless below-sandbox-editor?
    # identify the sandbox whose code is being clicked on
    sandbox:address:shared:sandbox-data <- find-click-in-sandbox-code env, click-row
    break-unless sandbox
    # toggle its display-trace? property
    x:address:boolean <- get-address *sandbox, display-trace?:offset
    *x <- not *x
    hide-screen screen
    screen <- render-sandbox-side screen, env, 1/clear
    screen <- update-cursor screen, recipes, current-sandbox, *sandbox-in-focus?, env
    # no change in cursor
    show-screen screen
    loop +next-event:label
  }
]

def find-click-in-sandbox-code env:address:shared:programming-environment-data, click-row:number -> sandbox:address:shared:sandbox-data [
  local-scope
  load-ingredients
  # assert click-row >= sandbox.starting-row-on-screen
  sandbox <- get *env, sandbox:offset
  start:number <- get *sandbox, starting-row-on-screen:offset
  clicked-on-sandboxes?:boolean <- greater-or-equal click-row, start
  assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor]
  # while click-row < sandbox.next-sandbox.starting-row-on-screen
  {
    next-sandbox:address:shared:sandbox-data <- get *sandbox, next-sandbox:offset
    break-unless next-sandbox
    next-start:number <- get *next-sandbox, starting-row-on-screen:offset
    found?:boolean <- lesser-than click-row, next-start
    break-if found?
    sandbox <- copy next-sandbox
    loop
  }
  # return sandbox if click is in its code region
  code-ending-row:number <- get *sandbox, code-ending-row-on-screen:offset
  click-above-response?:boolean <- lesser-than click-row, code-ending-row
  start:number <- get *sandbox, starting-row-on-screen:offset
  click-below-menu?:boolean <- greater-than click-row, start
  click-on-sandbox-code?:boolean <- and click-above-response?, click-below-menu?
  {
    break-if click-on-sandbox-code?
    return 0/no-click-in-sandbox-output
  }
  return sandbox
]

# when rendering a sandbox, dump its trace before response/warning if display-trace? property is set
after <render-sandbox-results> [
  {
    display-trace?:boolean <- get *sandbox, display-trace?:offset
    break-unless display-trace?
    sandbox-trace:address:shared:array:character <- get *sandbox, trace:offset
    break-unless sandbox-trace  # nothing to print; move on
    row, screen <- render screen, sandbox-trace, left, right, 245/grey, row
  }
  <render-sandbox-trace-done>
]