about summary refs log blame commit diff stats
path: root/063array.mu
blob: 8272a865681cded02deee02a889ff44e45af4682 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11

                          


                                                  
   
                         



                           



                                              
                                                 
             
                           

                           
                                                            

                               

        
                                        
                    
                    

                           

                                                 
                                                            
                                                                 
                                               
                 

        
               
 
scenario array-from-args [
  run [
    local-scope
    x:address:array:character <- new-array 0, 1, 2
    10:array:character/raw <- copy *x
  ]
  memory-should-contain [
    10 <- 3  # array length
    11 <- 0
    12 <- 1
    13 <- 2
  ]
]

# create an array out of a list of scalar args
def new-array -> result:address:array:character [
  local-scope
  capacity:number <- copy 0
  {
    # while read curr-value
    curr-value:character, exists?:boolean <- next-ingredient
    break-unless exists?
    capacity <- add capacity, 1
    loop
  }
  result <- new character:type, capacity
  rewind-ingredients
  i:number <- copy 0
  {
    # while read curr-value
    done?:boolean <- greater-or-equal i, capacity
    break-if done?
    curr-value:character, exists?:boolean <- next-ingredient
    assert exists?, [error in rewinding ingredients to new-array]
    *result <- put-index *result, i, curr-value
    i <- add i, 1
    loop
  }
  return result
]