Skip to content

Commit

Permalink
adding more array test stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
aiverson committed Dec 13, 2023
1 parent b7d9e11 commit f21e71e
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions testfile.alc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let prim-sub = (intrinsic "return function(a, b) return a - b end" : prim-arith-

# this should error becaused prim-type is not a prim-type and therefore can't be an arg to a prim-func-type
# but it doesn't.
let array-type =
let prim-array-type =
intrinsic
""""
-- terms and terms_gen implicitly in env
Expand All @@ -29,6 +29,52 @@ let array-type =
:
prim-func-type (T : (boxed prim-type)) -> (array : (boxed prim-type))

let prim-array-set =
intrinsic
""""
local function array_get(_elem_type, array, index, elem)
array[index] = elem
end
:
prim-func-type (T : (boxed prim-type)) (arr : (unbox (prim-array-type T))) (index : prim-number) (elem : (unbox T)) ->

let prim-array-get =
intrinsic
""""
local function array_get(_elem_type, array, index)
return array[index]
end
:
prim-func-type (T : (boxed prim-type)) (arr : (unbox (prim-array-type T))) (index : prim-number) -> (elem : (unbox T))


let prim-array-new =
intrinsic
""""
local function array_get(_elem_type, array)
return {}
end
:
prim-func-type (T : (boxed prim-type)) -> (arr : (unbox (prim-array-type T)))

let array-type =
lambda ((T : prim-type))
let (typ) = (prim-array-type (box prim-type T))
typ
let array-set =
lambda (T : prim-type, arr : (array-type T), index : prim-number, elem : T)
let ( ) = prim-array-set(box(prim-type, T), arr, index, elem)
let array-get =
lambda (T : prim-type, arr : (array-type T), index : prim-number)
let (elem) = prim-array-get(box(prim-type, T), arr, index)
let array-new =
lambda ((T : prim-type))
let (elem) = prim-array-new(box(prim-type, T))

let arr = array-new(prim-number)
array-set(prim-number, arr, 1, 3)
array-set(prim-number, arr, 2, 5)

#let (val) =
# + x 5

Expand All @@ -49,4 +95,4 @@ let sub =

sub 5 (sub 3 2)

number-array
sub(array-get(prim-number, arr, 2), array-get(prim-number, arr, 1))

0 comments on commit f21e71e

Please sign in to comment.