From 199d8bbc6d5793d895311cb0d2296f3e1279a3e0 Mon Sep 17 00:00:00 2001 From: JJ Date: Fri, 10 May 2024 00:54:48 -0700 Subject: std: replace static with const, fix std.ast --- std/prelude/arrays.pk | 14 +++++++------- std/prelude/clone.pk | 2 +- std/prelude/format.pk | 4 ++-- std/prelude/lists.pk | 2 +- std/prelude/options.pk | 2 +- std/prelude/strings.pk | 1 + 6 files changed, 13 insertions(+), 12 deletions(-) (limited to 'std/prelude') diff --git a/std/prelude/arrays.pk b/std/prelude/arrays.pk index 6f57865..d8512dd 100644 --- a/std/prelude/arrays.pk +++ b/std/prelude/arrays.pk @@ -3,28 +3,28 @@ ## Primitive fixed-size arrays. Their size is statically known at compile-time. @[magic] -pub type array[T, size: static uint] +pub type array[T, size: const uint] ## Array access. Returns None if i is out of range. @[magic] -pub func get[T, size: static uint](self: lent array[T, size], i: uint): lent T? +pub func get[T, size: const uint](self: lent array[T, size], i: uint): lent T? ## Array access. Returns None if i is out of range. @[magic] -pub func get[T, size: static uint](self: mut array[T, size], i: uint): mut T? +pub func get[T, size: const uint](self: mut array[T, size], i: uint): mut T? ## Array mutation. # todo: how do we detect range errors? @[magic] -pub func set[T, size: static uint](self: mut array[T, size], i: uint, val: T): Success[IndexOutOfBounds] +pub func set[T, size: const uint](self: mut array[T, size], i: uint, val: T): Success[IndexOutOfBounds] ## A helper function to get the length of an array. ## Known to the compiler, and computed at compile-time. @[inline] -pub func len[T, size: static uint](self: lent array[T, size]): uint = size +pub func len[T, size: const uint](self: lent array[T, size]): uint = size -type ArrayIter[T, size: static uint] = struct +type ArrayIter[T, size: const uint] = struct ... -pub func iter[T, size: static uint](self: array[T, size]): ArrayIter[T, S] = +pub func iter[T, size: const uint](self: array[T, size]): ArrayIter[T, S] = ... # todo: Eq, PartialEq, Ord, PartialOrd diff --git a/std/prelude/clone.pk b/std/prelude/clone.pk index 5d11cdb..0ddfcf6 100644 --- a/std/prelude/clone.pk +++ b/std/prelude/clone.pk @@ -18,7 +18,7 @@ pub func clone[T: Clone](self: tuple[T]): tuple[T] = ... ## Implementation of `clone` for arrays of any size. -pub func clone[T: Clone, size: static[uint]](self: array[T, size]): array[T, size] = +pub func clone[T: Clone, size: const uint](self: array[T, size]): array[T, size] = var res: array[T, size] for i in 0 .. size do res.push(self.i.clone) diff --git a/std/prelude/format.pk b/std/prelude/format.pk index 6fc7c99..3bb5825 100644 --- a/std/prelude/format.pk +++ b/std/prelude/format.pk @@ -21,7 +21,7 @@ pub func print(params: varargs[Display]) = ## Note: this function is special! It does not count as a side effect. ## This breaks effect tracking, of course: but `dbg` is for debugging. ## It will produce a warning in code compiled for release. -@[no_side_effect] +@[pure] pub func dbg(params: varargs[Debug]) = stdout.write(params.map(x => x.dbg).join(" "), "\n") @@ -46,7 +46,7 @@ pub func dbg[T: Debug](self: Iter[T]): str = "[{}]".fmt(self.map(x => x.dbg).join(", ")) ## The fmt macro. Builds a formatted string from its arguments. -pub macro fmt(self: static[str], args: varargs[Display]): str = +pub macro fmt(self: const str, args: varargs[Display]): str = let parts = self.split("{}") if parts.len != args.len + 1 then macro_error("wrong number of arguments") diff --git a/std/prelude/lists.pk b/std/prelude/lists.pk index 57de91b..1bce693 100644 --- a/std/prelude/lists.pk +++ b/std/prelude/lists.pk @@ -4,7 +4,7 @@ ## The fundamental list type. Heap-allocated. ## Equivalent to Vec in other languages. -@[unsafe] # unsafe on a struct tells us raw field access breaks invariants. +@[opaque] # opaque on a struct tells us raw field access breaks invariants. pub type list[T] = struct data: ptr T capacity: int diff --git a/std/prelude/options.pk b/std/prelude/options.pk index d5cfb9d..4825803 100644 --- a/std/prelude/options.pk +++ b/std/prelude/options.pk @@ -19,7 +19,7 @@ pub func ![T](self: T?): T = else raise "empty" ## Indirect access. Propagates `None`. -pub macro ?[T](self: T?) = +pub macro ?[T](self: Option[T]) = quote match `self` of Some(x) then x diff --git a/std/prelude/strings.pk b/std/prelude/strings.pk index e86d520..a8c72fb 100644 --- a/std/prelude/strings.pk +++ b/std/prelude/strings.pk @@ -6,6 +6,7 @@ ## ## We do not want methods defined on `list[byte]` to carry over, ## so we define `str` as a newtype. +@[opaque] pub type str = struct data: list[byte] -- cgit v1.2.3-70-g09d2