aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
Diffstat (limited to 'std')
-rw-r--r--std/ast.pk31
-rw-r--r--std/prelude/io.pk2
-rw-r--r--std/prelude/iterators.pk2
-rw-r--r--std/prelude/lists.pk4
-rw-r--r--std/prelude/numbers.pk4
-rw-r--r--std/prelude/strings.pk18
6 files changed, 33 insertions, 28 deletions
diff --git a/std/ast.pk b/std/ast.pk
index 4b8a783..21a5569 100644
--- a/std/ast.pk
+++ b/std/ast.pk
@@ -1,13 +1,14 @@
## std.ast: Exposes the AST for building and operating on with macros.
## The `Expr` type represents the abstract syntax tree of Puck itself.
-## It notably lacks type information.
-## It is, however, syntactically correct-by-construction.
+## It notably lacks type information. It is also not necessarily syntactically
+## correct-by-construction: Cond, Try, and Match expressions must have at least
+## one branch in their branches (yet this is not expressible here).
pub type Expr = union
Ident(string)
Number(int)
Float(float)
- Char(chr)
+ Char(char)
String(str)
Struct(list[(field: str, value: Expr)])
Tuple(list[(field: str?, value: Expr)])
@@ -29,17 +30,25 @@ pub type Expr = union
params: list[(id: Pattern, kind: Type?)],
kind: Type?,
body: list[Expr])
- TypeDecl(public: bool, id: str, generics: list[str], alias: Type)
- Module(public: bool, id: str, body: list[Expr])
+ TypeDecl(
+ public: bool,
+ id: str,
+ generics: list[str],
+ body: Type)
+ Module(
+ public: bool,
+ id: str,
+ generics: list[str],
+ body: list[Expr])
Use(path: str)
Call(id: str, params: list[Expr])
Cond(
branches: list[(cond: Expr, body: list[Expr])],
- else_body: list[Expr]?)
+ else_body: list[Expr])
Try(
try_body: list[Expr],
catches: list[(exceptions: list[str], body: list[Expr])],
- finally_body: list[Expr]?)
+ finally_body: list[Expr])
Match(
item: ref Expr,
branches: list[(pattern: Pattern, guard: Expr?, body: list[Expr])])
@@ -54,15 +63,11 @@ pub type Type = ref union
Int(size: uint)
Dec(size: uint)
Float(size: uint)
- String
Func(from: list[Type], to: Type)
Struct(list[(id: str, kind: Type)])
Tuple(list[(id: str?, kind: Type)])
Union(list[(id: str, kind: Type)])
- Class( # todo: generics
- funcs: list[(id: str, from: list[Type], to: Type?)]
- for_type: Type?
- )
+ Class(list[(id: str, from: list[Type], to: Type?)])
Array(size: uint, kind: Type)
List(Type)
Slice(Type) # todo: plus ownership
@@ -76,7 +81,7 @@ pub type Type = ref union
pub type Pattern = union
Ident(str)
- Number(int), Float(float), Char(chr), String(str)
+ Number(int), Float(float), Char(char), String(str)
Struct(name: str, params: list[Pattern])
Tuple(list[Pattern])
List(list[Pattern])
diff --git a/std/prelude/io.pk b/std/prelude/io.pk
index 026d12a..d44f403 100644
--- a/std/prelude/io.pk
+++ b/std/prelude/io.pk
@@ -27,7 +27,7 @@ pub func read(file: File): str? =
pub func lines(file: File): Iter[str] =
...
-pub func chars(file: File): Iter[chr] =
+pub func chars(file: File): Iter[char] =
...
pub func exists(file: File): bool =
diff --git a/std/prelude/iterators.pk b/std/prelude/iterators.pk
index 1403b55..1e60379 100644
--- a/std/prelude/iterators.pk
+++ b/std/prelude/iterators.pk
@@ -159,7 +159,7 @@ pub func unzip[T, U](self: Iter[(T, U)]): (Iter[T], Iter[U])
# equivalent of collect. useful for type conversion
pub func to[T](self: LazyIter[T]): list[T]
-pub func to(self: LazyIter[chr]): str
+pub func to(self: LazyIter[char]): str
pub type BoundIter[T] = class
next(mut Self): T?
diff --git a/std/prelude/lists.pk b/std/prelude/lists.pk
index 1bce693..c4b8739 100644
--- a/std/prelude/lists.pk
+++ b/std/prelude/lists.pk
@@ -7,8 +7,8 @@
@[opaque] # opaque on a struct tells us raw field access breaks invariants.
pub type list[T] = struct
data: ptr T
- capacity: int
- length: int
+ capacity: uint
+ length: uint
## A transparent, common alias for a list of bytes.
pub type bytes = list[byte]
diff --git a/std/prelude/numbers.pk b/std/prelude/numbers.pk
index 801591a..aad747c 100644
--- a/std/prelude/numbers.pk
+++ b/std/prelude/numbers.pk
@@ -65,10 +65,10 @@ pub type dec128
pub type byte = u8
## A primitive char type. 4 bytes wide.
## These represent distinct Unicode characters, and are useful with `str`.
-pub type chr = u32
+pub type char = u32
## Get the underlying length of a char, in bytes. 1-4.
-pub func len(self: chr): uint =
+pub func len(self: char): uint =
...
## The IEEE floating point value of *Not a Number*.
diff --git a/std/prelude/strings.pk b/std/prelude/strings.pk
index a8c72fb..5c71047 100644
--- a/std/prelude/strings.pk
+++ b/std/prelude/strings.pk
@@ -22,7 +22,7 @@ pub func len(self: lent str): uint =
res
## Pushes a character to the end of a mutable string.
-pub func push(self: mut str, val: chr) =
+pub func push(self: mut str, val: char) =
self.data.push(val.byte) # todo: obsolete by from/to conversion??
## Pushes an owned string to the end of a mutable string.
@@ -34,29 +34,29 @@ pub func push(self: mut str, val: str) =
## SAFETY: We return early upon an empty string.
## And decrement by one char for a non-empty string.
@[safe]
-pub func pop(self: mut str): chr? =
+pub func pop(self: mut str): char? =
let char = self.chars.rev.next?
self.data.set_len(self.len - char.len) # this is normally unsafe.
Some(char)
## Returns the character at the provided index, if it exists.
-pub func get(self: str, i: uint): chr? =
+pub func get(self: str, i: uint): char? =
...
## Sets the character at the provided index, if it exists.
## As strings are packed, this may call str.grow and reallocate.
## oh fuck we have to insert + remove anyway
-pub func set(self: mut str, i: uint, val: chr) =
+pub func set(self: mut str, i: uint, val: char) =
...
## Inserts a character at an arbitrary position within a string.
## Panics on failure. (todo: can we do better?)
-pub func insert(self: mut str, i: uint, val: chr) =
+pub func insert(self: mut str, i: uint, val: char) =
...
## Removes and returns a character at an arbitrary position within a string.
## Panics on failure. (todo: can we do better?)
-pub func remove(self: mut str, i: uint): chr =
+pub func remove(self: mut str, i: uint): char? =
...
## Syntactic sugar for string appending.
@@ -70,9 +70,9 @@ pub func &(a: str, b: str): str =
## Conversion from a string to a list of bytes. Zero-cost.
pub func to(self: str): list[byte] = self.data
-## Conversion from a str to a list[chr]. Reallocates.
-pub func to(self: str): list[chr] =
- var res: list[chr]
+## Conversion from a str to a list[char]. Reallocates.
+pub func to(self: str): list[char] =
+ var res: list[char]
for char in self do res.push(char)
res
## Conversion from a char to an array of bytes. Zero-cost.