about summary refs log tree commit diff stats
path: root/116write-buffered.subx
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-12-19 08:38:59 -0800
committerKartik K. Agaram <vc@akkartik.com>2023-12-19 08:38:59 -0800
commitb44567ba2358847014720278eb946d33e4f2179d (patch)
tree4fc96c101e7c7b6e32cda3b6fa720a75132a5e96 /116write-buffered.subx
parent204589b2ffc8aa16fa2953017eaa6614f7d05eb5 (diff)
downloadmu-b44567ba2358847014720278eb946d33e4f2179d.tar.gz
much love main
Diffstat (limited to '116write-buffered.subx')
0 files changed, 0 insertions, 0 deletions
5497090a ^
9636c7ae ^
5497090a ^
9636c7ae ^

5497090a ^
9636c7ae ^


5497090a ^
9636c7ae ^
5497090a ^
9636c7ae ^



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




                                                                          
                         









                                                                       
                                   



                                                           
                                                     

        
                                                                     
                    
                            

                           
                                                               


                                                                          
                                                                                       
                                                          
                                       



                                     
scenario array-from-args [
  run [
    1:address:array:location <- init-array 0:literal, 1:literal, 2:literal
    2:array:location <- copy 1:address:array:location/deref
  ]
  memory-should-contain [
    2 <- 3  # array length
    3 <- 0
    4 <- 1
    5 <- 2
  ]
]

# create an array out of a list of scalar args
recipe init-array [
  default-space:address:array:location <- new location:type, 30:literal
  capacity:number <- copy 0:literal
  {
    # while read curr-value
    curr-value:location, exists?:boolean <- next-ingredient
    break-unless exists?:boolean
    capacity:number <- add capacity:number, 1:literal
    loop
  }
  result:address:array:location <- new location:type, capacity:number
  rewind-ingredients
  i:number <- copy 0:literal
  {
    # while read curr-value
    done?:boolean <- greater-or-equal i:number, capacity:number
    break-if done?:boolean
    curr-value:location, exists?:boolean <- next-ingredient
    assert exists?:boolean, [error in rewinding ingredients to init-array]
    tmp:address:location <- index-address result:address:array:location/deref, i:number
    tmp:address:location/deref <- copy curr-value:location
    i:number <- add i:number, 1:literal
    loop
  }
  reply result:address:array:location
]