No matching definitions.

tur/sized

stdlib/sized.tur

static sizes and size arithmetic for memory layout verification.

Since: Phase SZ0

defn

static-int

(static-int [n :int] :StaticInt)

construct a StaticInt from a literal integer.

nthe integer value

A (StaticInt) wrapping n.

(static-int 10)  ; => SInt(10)

Since: Phase SZ0

defn

static-int-val

(static-int-val [si :StaticInt] :int)

extract the integer value from a StaticInt.

sia (StaticInt) value

The wrapped integer.

(static-int-val (static-int 10))  ; => 10

Since: Phase SZ0

defn

static-int-add

(static-int-add [a :StaticInt b :StaticInt] :StaticInt)

add two StaticInt values.

afirst (StaticInt)
bsecond (StaticInt)

A (StaticInt) representing a + b.

(static-int-val (static-int-add (static-int 3) (static-int 4)))  ; => 7

Since: Phase SZ0

defn

static-int-mul

(static-int-mul [a :StaticInt b :StaticInt] :StaticInt)

multiply two StaticInt values.

afirst (StaticInt)
bsecond (StaticInt)

A (StaticInt) representing a * b.

(static-int-val (static-int-mul (static-int 3) (static-int 4)))  ; => 12

Since: Phase SZ0

defn

size-static

(size-static [n :int] :Size)

create a literal Size from an integer.

nthe integer literal

A (Size) representing the literal value n.

(size-eval (size-static 4))  ; => 4

Since: Phase SZ0

defn

size-add

(size-add [s1 :Size s2 :Size] :Size)

create a Size representing the sum of two sizes.

s1the first (Size)
s2the second (Size)

A (Size) representing s1 + s2.

(size-eval (size-add (size-static 3) (size-static 4)))  ; => 7

Since: Phase SZ0

defn

size-mul

(size-mul [s1 :Size s2 :Size] :Size)

create a Size representing the product of two sizes.

s1the first (Size)
s2the second (Size)

A (Size) representing s1 * s2.

(size-eval (size-mul (size-static 3) (size-static 4)))  ; => 12

Since: Phase SZ0

defn

size-eval

(size-eval [s :Size] :int)

evaluate a Size expression to a runtime integer.

sthe (Size) expression to evaluate

The integer value of the size expression.

(size-eval (size-add (size-static 2) (size-mul (size-static 3) (size-static 4))))  ; => 14

Since: Phase SZ0

defn

sized-vec-nil

(sized-vec-nil :SizedVec)

construct an empty SizedVec.

An empty (SizedVec Size int).

(sized-vec-nil)  ; => SVNil

Since: Phase SZ0

defn

sized-vec-cons

(sized-vec-cons [x :int xs :SizedVec] :SizedVec)

prepend an integer element to a SizedVec.

xthe integer element to prepend
xsthe existing (SizedVec Size int)

A new (SizedVec Size int) with x at the front.

(sized-vec-cons 1 (sized-vec-nil))  ; => SVCons(1, SVNil)

Since: Phase SZ0

defn

sized-vec-len

(sized-vec-len [v :SizedVec] :int)

compute the runtime length of a SizedVec.

vthe (SizedVec Size int) to measure

The number of elements in v as an int.

(sized-vec-len (sized-vec-cons 1 (sized-vec-cons 2 (sized-vec-nil))))  ; => 2

Since: Phase SZ0

defn

sized-vec-head-or

(sized-vec-head-or [dflt :int v :SizedVec] :int)

return the first element, or dflt if empty.

dfltvalue returned when v is empty
vthe (SizedVec Size int) to inspect

The first element of v, or dflt if v is empty.

(sized-vec-head-or 99 (sized-vec-nil))                           ; => 99
  (sized-vec-head-or 99 (sized-vec-cons 7 (sized-vec-nil)))       ; => 7

Since: Phase SZ0

defn

sized-vec-tail

(sized-vec-tail [v :SizedVec] :SizedVec)

return all elements after the first.

vthe (SizedVec Size int) to take the tail of

The tail (SizedVec Size int); SVNil if v is empty.

(sized-vec-len (sized-vec-tail (sized-vec-cons 1 (sized-vec-cons 2 (sized-vec-nil)))))  ; => 1

Since: Phase SZ0

defn

sized-vec-sum

(sized-vec-sum [v :SizedVec] :int)

sum all integer elements of a SizedVec.

vthe (SizedVec Size int) to sum

The integer sum of all elements; 0 for empty.

(sized-vec-sum (sized-vec-cons 1 (sized-vec-cons 2 (sized-vec-cons 3 (sized-vec-nil)))))  ; => 6

Since: Phase SZ0

defn

sized-vec-size

(sized-vec-size [v :SizedVec] :Size)

compute a Size expression for the runtime length.

vthe (SizedVec Size int) to measure

A (Static n) where n is the runtime length of v.

(size-eval (sized-vec-size (sized-vec-cons 1 (sized-vec-cons 2 (sized-vec-nil)))))  ; => 2

Since: Phase SZ0

defn

size-eq?

(size-eq? [s1 :Size s2 :Size] :bool)

check whether two Size expressions evaluate to equal integers.

s1the first (Size) expression
s2the second (Size) expression

true if both evaluate to the same integer, false otherwise.

(size-eq? (size-static 4) (size-add (size-static 1) (size-static 3)))  ; => true

Since: Phase SZ1

defn

size-le?

(size-le? [s1 :Size s2 :Size] :bool)

check whether s1 evaluates to <= s2.

s1the first (Size) expression
s2the second (Size) expression

true if s1 <= s2 as integers.

(size-le? (size-static 3) (size-static 4))  ; => true

Since: Phase SZ1

defn

size-lt?

(size-lt? [s1 :Size s2 :Size] :bool)

check whether s1 evaluates to < s2.

s1the first (Size) expression
s2the second (Size) expression

true if s1 < s2 as integers.

(size-lt? (size-static 3) (size-static 4))  ; => true

Since: Phase SZ1

defn

size-ge?

(size-ge? [s1 :Size s2 :Size] :bool)

check whether s1 evaluates to >= s2.

s1the first (Size) expression
s2the second (Size) expression

true if s1 >= s2 as integers.

(size-ge? (size-static 5) (size-static 5))  ; => true

Since: Phase SZ1

defn

size-gt?

(size-gt? [s1 :Size s2 :Size] :bool)

check whether s1 evaluates to > s2.

s1the first (Size) expression
s2the second (Size) expression

true if s1 > s2 as integers.

(size-gt? (size-static 5) (size-static 4))  ; => true

Since: Phase SZ1

defn

size-normalize

(size-normalize [s :Size] :Size)

reduce a Size expression to its canonical (Static n) form.

sthe (Size) expression to normalize

A (Static n) where n is the evaluated integer of s.

(size-eval (size-normalize (size-add (size-static 2) (size-mul (size-static 3) (size-static 4)))))  ; => 14

Since: Phase SZ1

defn

size-simplify

(size-simplify [s :Size] :Size)

apply algebraic reduction rules to a Size expression.

sthe (Size) expression to simplify

A simplified (Size) expression.

(size-eval (size-simplify (size-add (size-static 0) (size-static 7))))  ; => 7
  (size-eval (size-simplify (size-mul (size-static 1) (size-static 9))))  ; => 9

Since: Phase SZ1

defn

size-assert-eq!

(size-assert-eq! [s1 :Size s2 :Size] :nil)

panic at runtime if two Size expressions evaluate differently.

s1the actual (Size) (e.g., from sized-vec-size)
s2the expected (Size)

nil on success; panics with "sized type mismatch" on failure.

(size-assert-eq! (size-static 4) (size-add (size-static 2) (size-static 2)))

Since: Phase SZ1

defn

size-assert-le!

(size-assert-le! [s1 :Size s2 :Size] :nil)

panic at runtime if s1 evaluates to greater than s2.

s1the actual (Size) to check
s2the upper bound (Size)

nil on success; panics with "sized type mismatch" on failure.

(size-assert-le! (size-static 3) (size-static 10))

Since: Phase SZ1

defn

size-compat?

(size-compat? [s1 :Size s2 :Size] :bool)

check whether two Size expressions are compatible (equal).

s1the first (Size)
s2the second (Size)

true if both sizes evaluate to the same integer.

(size-compat? (size-static 4) (size-add (size-static 2) (size-static 2)))  ; => true

Since: Phase SZ1

defn

sized-vec-of-1

(sized-vec-of-1 [a :int] :SizedVec)

construct a 1-element SizedVec, size inferred as 1.

athe element

A (SizedVec Size int) containing [a].

(sized-vec-len (sized-vec-of-1 42))  ; => 1

Since: Phase SZ1

defn

sized-vec-of-2

(sized-vec-of-2 [a :int b :int] :SizedVec)

construct a 2-element SizedVec, size inferred as 2.

athe first element
bthe second element

A (SizedVec Size int) containing [a, b].

(sized-vec-len (sized-vec-of-2 1 2))  ; => 2

Since: Phase SZ1

defn

sized-vec-of-3

(sized-vec-of-3 [a :int b :int c :int] :SizedVec)

construct a 3-element SizedVec, size inferred as 3.

athe first element
bthe second element
cthe third element

A (SizedVec Size int) containing [a, b, c].

(sized-vec-len (sized-vec-of-3 1 2 3))  ; => 3

Since: Phase SZ1

defn

sized-vec-of-4

(sized-vec-of-4 [a :int b :int c :int d :int] :SizedVec)

construct a 4-element SizedVec, size inferred as 4.

athe first element
bthe second element
cthe third element
dthe fourth element

A (SizedVec Size int) containing [a, b, c, d].

(sized-vec-len (sized-vec-of-4 1 2 3 4))  ; => 4

Since: Phase SZ1

defn

sized-vec-from-list

(sized-vec-from-list [lst])

convert a cons list to a SizedVec, inferring the size at runtime.

lsta cons list (0 for empty, or pointer to cons cell)

A (SizedVec Size int) with the same elements in the same order.

(sized-vec-len (sized-vec-from-list (cons 1 (cons 2 (cons 3 (nil-value))))))  ; => 3

Since: Phase SZ1