diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-17 22:18:21 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-17 22:18:21 -0400 |
| commit | ca62aa365faee27895f8cb1eccddd7af8a7d15c9 (patch) | |
| tree | 22d191de7f16c889c407ef92f27ef9efb3303998 | |
| parent | 80ca0f0b1ba04c1aa3d7bb1a62928dbcecbb3bd8 (diff) | |
Switch types to use wordier syntax `[T]` -> `List(T)` etc
40 files changed, 341 insertions, 283 deletions
diff --git a/docs/arrays.md b/docs/arrays.md index 543e44e1..8715cf3c 100644 --- a/docs/arrays.md +++ b/docs/arrays.md @@ -232,38 +232,38 @@ variable or dereference a heap pointer, it may trigger copy-on-write behavior. ## Array Methods -- [`func binary_search(arr: [T], by: func(x,y:&T->Int32) = T.compare -> Int)`](#binary_search) -- [`func by(arr: [T], step: Int -> [T])`](#by) -- [`func clear(arr: @[T] -> Void)`](#clear) -- [`func counts(arr: [T] -> {T,Int})`](#counts) -- [`func find(arr: [T], target: T -> Int?)`](#find) -- [`func first(arr: [T], predicate: func(item:&T -> Bool) -> Int)`](#first) -- [`func from(arr: [T], first: Int -> [T])`](#from) -- [`func has(arr: [T] -> Bool)`](#has) -- [`func heap_pop(arr: @[T], by: func(x,y:&T->Int32) = T.compare -> T?)`](#heap_pop) -- [`func heap_push(arr: @[T], item: T, by=T.compare -> Void)`](#heap_push) -- [`func heapify(arr: @[T], by: func(x,y:&T->Int32) = T.compare -> Void)`](#heapify) -- [`func insert(arr: @[T], item: T, at: Int = 0 -> Void)`](#insert) -- [`func insert_all(arr: @[T], items: [T], at: Int = 0 -> Void)`](#insert_all) -- [`func pop(arr: &[T], index: Int = -1 -> T?)`](#pop) -- [`func random(arr: [T], rng: RNG = random -> T)`](#random) -- [`func remove_at(arr: @[T], at: Int = -1, count: Int = 1 -> Void)`](#remove_at) -- [`func remove_item(arr: @[T], item: T, max_count: Int = -1 -> Void)`](#remove_item) -- [`func reversed(arr: [T] -> [T])`](#reversed) -- [`func sample(arr: [T], count: Int, weights: [Num]? = ![Num], rng: RNG = random -> [T])`](#sample) -- [`func shuffle(arr: @[T], rng: RNG = random -> Void)`](#shuffle) -- [`func shuffled(arr: [T], rng: RNG = random -> [T])`](#shuffled) -- [`func slice(arr: [T], from: Int, to: Int -> [T])`](#slice) -- [`func sort(arr: @[T], by=T.compare -> Void)`](#sort) -- [`sorted(arr: [T], by=T.compare -> [T])`](#sorted) -- [`to(arr: [T], last: Int -> [T])`](#to) -- [`unique(arr: [T] -> {T})`](#unique) +- [`func binary_search(arr:List(T), by: func(x,y:&T->Int32) = T.compare -> Int)`](#binary_search) +- [`func by(arr:List(T), step: Int -> List(T))`](#by) +- [`func clear(arr:@List(T) -> Void)`](#clear) +- [`func counts(arr:List(T) -> Table(T, Int))`](#counts) +- [`func find(arr:List(T), target: T -> Int?)`](#find) +- [`func first(arr:List(T), predicate: func(item:&T -> Bool) -> Int)`](#first) +- [`func from(arr:List(T), first: Int -> List(T))`](#from) +- [`func has(arr:List(T) -> Bool)`](#has) +- [`func heap_pop(arr:@List(T), by: func(x,y:&T->Int32) = T.compare -> T?)`](#heap_pop) +- [`func heap_push(arr:@List(T), item: T, by=T.compare -> Void)`](#heap_push) +- [`func heapify(arr:@List(T), by: func(x,y:&T->Int32) = T.compare -> Void)`](#heapify) +- [`func insert(arr:@List(T), item: T, at: Int = 0 -> Void)`](#insert) +- [`func insert_all(arr:@List(T), items:List(T), at: Int = 0 -> Void)`](#insert_all) +- [`func pop(arr:&List(T), index: Int = -1 -> T?)`](#pop) +- [`func random(arr:List(T), rng: RNG = random -> T)`](#random) +- [`func remove_at(arr:@List(T), at: Int = -1, count: Int = 1 -> Void)`](#remove_at) +- [`func remove_item(arr:@List(T), item: T, max_count: Int = -1 -> Void)`](#remove_item) +- [`func reversed(arr:List(T) -> List(T))`](#reversed) +- [`func sample(arr:List(T), count: Int, weights:List(Num)? = ![Num], rng: RNG = random -> List(T))`](#sample) +- [`func shuffle(arr:@List(T), rng: RNG = random -> Void)`](#shuffle) +- [`func shuffled(arr:List(T), rng: RNG = random -> List(T))`](#shuffled) +- [`func slice(arr:List(T), from: Int, to: Int -> List(T))`](#slice) +- [`func sort(arr:@List(T), by=T.compare -> Void)`](#sort) +- [`sorted(arr:List(T), by=T.compare -> List(T))`](#sorted) +- [`to(arr:List(T), last: Int -> List(T))`](#to) +- [`unique(arr:List(T) -> Set(T))`](#unique) ### `binary_search` Performs a binary search on a sorted array. ```tomo -func binary_search(arr: [T], by: func(x,y:&T->Int32) = T.compare -> Int) +func binary_search(arr:List(T), by: func(x,y:&T->Int32) = T.compare -> Int) ``` - `arr`: The sorted array to search. @@ -294,7 +294,7 @@ place where it would be found if it were inserted and the array were sorted. Creates a new array with elements spaced by the specified step value. ```tomo -func by(arr: [T], step: Int -> [T]) +func by(arr:List(T), step: Int -> List(T)) ``` - `arr`: The original array. @@ -315,7 +315,7 @@ A new array with every `step`-th element from the original array. Clears all elements from the array. ```tomo -func clear(arr: @[T] -> Void) +func clear(arr:@List(T) -> Void) ``` - `arr`: The mutable reference to the array to be cleared. @@ -334,7 +334,7 @@ Nothing. Counts the occurrences of each element in the array. ```tomo -func counts(arr: [T] -> {T,Int}) +func counts(arr:List(T) -> Table(T, Int)) ``` - `arr`: The array to count elements in. @@ -354,7 +354,7 @@ A table mapping each element to its count. Finds the index of the first occurrence of an element (if any). ```tomo -func find(arr: [T], target: T -> Int?) +func find(arr:List(T), target: T -> Int?) ``` - `arr`: The array to search through. @@ -378,7 +378,7 @@ The index of the first occurrence or `!Int` if not found. Find the index of the first item that matches a predicate function (if any). ```tomo -func first(arr: [T], predicate: func(item:&T -> Bool) -> Int) +func first(arr:List(T), predicate: func(item:&T -> Bool) -> Int) ``` - `arr`: The array to search through. @@ -403,7 +403,7 @@ item matches. Returns a slice of the array starting from a specified index. ```tomo -func from(arr: [T], first: Int -> [T]) +func from(arr:List(T), first: Int -> List(T)) ``` - `arr`: The original array. @@ -424,7 +424,7 @@ A new array starting from the specified index. Checks if the array has any elements. ```tomo -func has(arr: [T] -> Bool) +func has(arr:List(T) -> Bool) ``` - `arr`: The array to check. @@ -445,7 +445,7 @@ Removes and returns the top element of a heap or `none` if the array is empty. By default, this is the *minimum* value in the heap. ```tomo -func heap_pop(arr: @[T], by: func(x,y:&T->Int32) = T.compare -> T?) +func heap_pop(arr:@List(T), by: func(x,y:&T->Int32) = T.compare -> T?) ``` - `arr`: The mutable reference to the heap. @@ -470,7 +470,7 @@ Adds an element to the heap and maintains the heap property. By default, this is a *minimum* heap. ```tomo -func heap_push(arr: @[T], item: T, by=T.compare -> Void) +func heap_push(arr:@List(T), item: T, by=T.compare -> Void) ``` - `arr`: The mutable reference to the heap. @@ -492,7 +492,7 @@ Nothing. Converts an array into a heap. ```tomo -func heapify(arr: @[T], by: func(x,y:&T->Int32) = T.compare -> Void) +func heapify(arr:@List(T), by: func(x,y:&T->Int32) = T.compare -> Void) ``` - `arr`: The mutable reference to the array to be heapified. @@ -514,7 +514,7 @@ Nothing. Inserts an element at a specified position in the array. ```tomo -func insert(arr: @[T], item: T, at: Int = 0 -> Void) +func insert(arr:@List(T), item: T, at: Int = 0 -> Void) ``` - `arr`: The mutable reference to the array. @@ -544,7 +544,7 @@ Nothing. Inserts an array of items at a specified position in the array. ```tomo -func insert_all(arr: @[T], items: [T], at: Int = 0 -> Void) +func insert_all(arr:@List(T), items:List(T), at: Int = 0 -> Void) ``` - `arr`: The mutable reference to the array. @@ -576,7 +576,7 @@ the array, the item at that index will be removed and the array will become one element shorter. ```tomo -func pop(arr: &[T], index: Int = -1 -> T?) +func pop(arr:&List(T), index: Int = -1 -> T?) ``` - `arr`: The array to remove an item from. @@ -607,7 +607,7 @@ otherwise the item at the given index. Selects a random element from the array. ```tomo -func random(arr: [T], rng: RNG = random -> T) +func random(arr:List(T), rng: RNG = random -> T) ``` - `arr`: The array from which to select a random element. @@ -628,7 +628,7 @@ A random element from the array. Removes elements from the array starting at a specified index. ```tomo -func remove_at(arr: @[T], at: Int = -1, count: Int = 1 -> Void) +func remove_at(arr:@List(T), at: Int = -1, count: Int = 1 -> Void) ``` - `arr`: The mutable reference to the array. @@ -656,7 +656,7 @@ arr:remove_at(2, count=2) Removes all occurrences of a specified item from the array. ```tomo -func remove_item(arr: @[T], item: T, max_count: Int = -1 -> Void) +func remove_item(arr:@List(T), item: T, max_count: Int = -1 -> Void) ``` - `arr`: The mutable reference to the array. @@ -684,7 +684,7 @@ arr:remove_item(20, max_count=1) Returns a reversed slice of the array. ```tomo -func reversed(arr: [T] -> [T]) +func reversed(arr:List(T) -> List(T)) ``` - `arr`: The array to be reversed. @@ -705,7 +705,7 @@ Selects a sample of elements from the array, optionally with weighted probabilities. ```tomo -func sample(arr: [T], count: Int, weights: [Num]? = ![Num], rng: RNG = random -> [T]) +func sample(arr:List(T), count: Int, weights:List(Num)? = ![Num], rng: RNG = random -> List(T)) ``` - `arr`: The array to sample from. @@ -739,7 +739,7 @@ A list of sampled elements from the array. Shuffles the elements of the array in place. ```tomo -func shuffle(arr: @[T], rng: RNG = random -> Void) +func shuffle(arr:@List(T), rng: RNG = random -> Void) ``` - `arr`: The mutable reference to the array to be shuffled. @@ -759,7 +759,7 @@ Nothing. Creates a new array with elements shuffled. ```tomo -func shuffled(arr: [T], rng: RNG = random -> [T]) +func shuffled(arr:List(T), rng: RNG = random -> List(T)) ``` - `arr`: The array to be shuffled. @@ -780,7 +780,7 @@ A new array with shuffled elements. Returns a slice of the array spanning the given indices (inclusive). ```tomo -func slice(arr: [T], from: Int, to: Int -> [T]) +func slice(arr:List(T), from: Int, to: Int -> List(T)) ``` - `arr`: The original array. @@ -807,7 +807,7 @@ second-to-last, and so on. Sorts the elements of the array in place in ascending order (small to large). ```tomo -func sort(arr: @[T], by=T.compare -> Void) +func sort(arr:@List(T), by=T.compare -> Void) ``` - `arr`: The mutable reference to the array to be sorted. @@ -835,7 +835,7 @@ arr:sort(func(a,b:&Int): a:abs() <> b:abs()) Creates a new array with elements sorted. ```tomo -sorted(arr: [T], by=T.compare -> [T]) +sorted(arr:List(T), by=T.compare -> List(T)) ``` - `arr`: The array to be sorted. @@ -860,7 +860,7 @@ A new array with sorted elements. Returns a slice of the array from the start of the original array up to a specified index (inclusive). ```tomo -to(arr: [T], last: Int -> [T]) +to(arr:List(T), last: Int -> List(T)) ``` - `arr`: The original array. @@ -884,7 +884,7 @@ A new array containing elements from the start up to the specified index. Returns a Set that contains the unique elements of the array. ```tomo -unique(arr: [T] -> {T}) +unique(arr:List(T) -> Set(T)) ``` - `arr`: The array to process. diff --git a/docs/command-line-parsing.md b/docs/command-line-parsing.md index 127cf232..230105d5 100644 --- a/docs/command-line-parsing.md +++ b/docs/command-line-parsing.md @@ -104,20 +104,20 @@ Array-of-text arguments can be passed like this: ```tomo # many-texts.tm -func main(args:[Text]): +func main(args:List(Text)): >> args ``` ```bash $ tomo many-texts.tm ->> [] : [Text] +>> [] :List(Text) $ tomo many-texts.tm one two three ->> ["one", "two", "three"] : [Text] +>> ["one", "two", "three"] :List(Text) $ tomo many-texts.tm --args=one,two,three ->> ["one", "two", "three"] : [Text] +>> ["one", "two", "three"] :List(Text) $ tomo many-texts.tm -- one --not-a-flag 'a space' ->> ["one", "--not-a-flag", "a space"] : [Text] +>> ["one", "--not-a-flag", "a space"] :List(Text) ``` diff --git a/docs/functions.md b/docs/functions.md index edd1261a..3cb37875 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -98,7 +98,7 @@ evicted if the cache has reached the maximum size and needs to insert a new entry: ```tomo -func doop(x:Int, y:Text, z:[Int]; cache_size=100 -> Text): +func doop(x:Int, y:Text, z:List(Int); cache_size=100 -> Text): return "x=$x y=$y z=$z" ``` diff --git a/docs/langs.md b/docs/langs.md index 0e6242db..b2709db8 100644 --- a/docs/langs.md +++ b/docs/langs.md @@ -100,6 +100,6 @@ struct Foo(x,y:Int): convert(f:Foo -> Sh): return Sh.from_text("$(f.x),$(f.y)") -convert(texts:[Text] -> Sh): +convert(texts:List(Text) -> Sh): return $Sh" ":join([Sh(t) for t in texts]) ``` diff --git a/docs/mutexed.md b/docs/mutexed.md index 97357f39..06e16b6b 100644 --- a/docs/mutexed.md +++ b/docs/mutexed.md @@ -17,7 +17,7 @@ nums := mutexed [10, 20, 30] holding nums: # Inside this block, the type of `nums` is `&[Int]` >> nums - = &[10, 20, 30] : &[Int] + = &[10, 20, 30] :&List(Int) thread := Thread.new(func(): holding nums: diff --git a/docs/optionals.md b/docs/optionals.md index 84f886b7..fbd7bac7 100644 --- a/docs/optionals.md +++ b/docs/optionals.md @@ -115,7 +115,7 @@ maybe_x = !Int >> maybe_x or fail("No value!") # Failure! -func do_stuff(matches:[Text]): +func do_stuff(matches:List(Text)): pass for line in lines: diff --git a/docs/paths.md b/docs/paths.md index cb4bb055..9d80244b 100644 --- a/docs/paths.md +++ b/docs/paths.md @@ -39,7 +39,7 @@ intended. Paths can be created from text with slashes using - [`func accessed(path:Path, follow_symlinks=yes -> Moment?)`](#accessed) - [`func append(path: Path, text: Text, permissions: Int32 = 0o644[32] -> Void)`](#append) -- [`func append_bytes(path: Path, bytes: [Byte], permissions: Int32 = 0o644[32] -> Void)`](#append_bytes) +- [`func append_bytes(path: Path, bytes:List(Byte), permissions: Int32 = 0o644[32] -> Void)`](#append_bytes) - [`func base_name(path: Path -> Text)`](#base_name) - [`func by_line(path: Path -> func(->Text?)?)`](#by_line) - [`func can_execute(path:Path -> Bool)`](#can_execute) @@ -47,14 +47,14 @@ intended. Paths can be created from text with slashes using - [`func can_write(path:Path -> Bool)`](#can_write) - [`func changed(path:Path, follow_symlinks=yes -> Moment?)`](#changed) - [`func child(path: Path, child:Text -> Path)`](#child) -- [`func children(path: Path, include_hidden=no -> [Path])`](#children) +- [`func children(path: Path, include_hidden=no -> List(Path))`](#children) - [`func create_directory(path: Path, permissions=0o755[32] -> Void)`](#create_directory) - [`func exists(path: Path -> Bool)`](#exists) - [`func expand_home(path: Path -> Path)`](#expand_home) - [`func extension(path: Path, full=yes -> Text)`](#extension) -- [`func files(path: Path, include_hidden=no -> [Path])`](#files) -- [`func from_components(components:[Text] -> Path)`](#from_components) -- [`func glob(path: Path -> [Path])`](#glob) +- [`func files(path: Path, include_hidden=no -> List(Path))`](#files) +- [`func from_components(components:List(Text) -> Path)`](#from_components) +- [`func glob(path: Path -> List(Path))`](#glob) - [`func group(path: Path, follow_symlinks=yes -> Text?)`](#group) - [`func is_directory(path: Path, follow_symlinks=yes -> Bool)`](#is_directory) - [`func is_file(path: Path, follow_symlinks=yes -> Bool)`](#is_file) @@ -64,17 +64,17 @@ intended. Paths can be created from text with slashes using - [`func owner(path: Path, follow_symlinks=yes -> Text?)`](#owner) - [`func parent(path: Path -> Path)`](#parent) - [`func read(path: Path -> Text?)`](#read) -- [`func read_bytes(path: Path -> [Byte]?)`](#read_bytes) +- [`func read_bytes(path: Path -> List(Byte)?)`](#read_bytes) - [`func relative_to(path: Path, relative_to=(./) -> Path)`](#relative_to) - [`func remove(path: Path, ignore_missing=no -> Void)`](#remove) - [`func resolved(path: Path, relative_to=(./) -> Path)`](#resolved) - [`func set_owner(path:Path, owner=none:Text, group=none:Text, follow_symlinks=yes)`](#set_owner) -- [`func subdirectories(path: Path, include_hidden=no -> [Path])`](#subdirectories) +- [`func subdirectories(path: Path, include_hidden=no -> List(Path))`](#subdirectories) - [`func unique_directory(path: Path -> Path)`](#unique_directory) - [`func write(path: Path, text: Text, permissions=0o644[32] -> Void)`](#write) -- [`func write_bytes(path: Path, bytes: [Byte], permissions=0o644[32] -> Void)`](#write_bytes) +- [`func write_bytes(path: Path, bytes:List(Byte), permissions=0o644[32] -> Void)`](#write_bytes) - [`func write_unique(path: Path, text: Text -> Path)`](#write_unique) -- [`func write_unique_bytes(path: Path, bytes: [Byte] -> Path)`](#write_unique_bytes) +- [`func write_unique_bytes(path: Path, bytes:List(Byte) -> Path)`](#write_unique_bytes) ### `accessed` Gets the file access time of a file. @@ -127,7 +127,7 @@ Appends the given bytes to the file at the specified path, creating the file if it doesn't already exist. Failure to write will result in a runtime error. ```tomo -func append_bytes(path: Path, bytes: [Byte], permissions: Int32 = 0o644[32] -> Void) +func append_bytes(path: Path, bytes:List(Byte), permissions: Int32 = 0o644[32] -> Void) ``` - `path`: The path of the file to append to. @@ -298,7 +298,7 @@ changed, or `none` if no such file or directory exists. Return a path that is a child of another path. ```tomo -func child(path: Path, child: Text -> [Path]) +func child(path: Path, child: Text -> List(Path)) ``` - `path`: The path of a directory. @@ -319,7 +319,7 @@ A new path representing the child. Returns a list of children (files and directories) within the directory at the specified path. Optionally includes hidden files. ```tomo -func children(path: Path, include_hidden=no -> [Path]) +func children(path: Path, include_hidden=no -> List(Path)) ``` - `path`: The path of the directory. @@ -434,7 +434,7 @@ no file extension. Returns a list of files within the directory at the specified path. Optionally includes hidden files. ```tomo -func files(path: Path, include_hidden: Bool = no -> [Path]) +func files(path: Path, include_hidden: Bool = no -> List(Path)) ``` - `path`: The path of the directory. @@ -455,7 +455,7 @@ A list of file paths. Returns a path built from an array of path components. ```tomo -func from_components(components: [Text] -> Path) +func from_components(components:List(Text) -> Path) ``` - `components`: An array of path components. @@ -486,7 +486,7 @@ specific details: - The shell-style syntax `**` for matching subdirectories is not supported. ```tomo -func glob(path: Path -> [Path]) +func glob(path: Path -> List(Path)) ``` - `path`: The path of the directory which may contain special globbing characters @@ -726,7 +726,7 @@ Reads the contents of the file at the specified path or a null value if the file could not be read. ```tomo -func read_bytes(path: Path -> [Byte]?) +func read_bytes(path: Path -> List(Byte)?) ``` - `path`: The path of the file to read. @@ -738,10 +738,10 @@ returned. **Example:** ```tomo >> (./hello.txt):read() -= [72[B], 101[B], 108[B], 108[B], 111[B]] : [Byte]? += [72[B], 101[B], 108[B], 108[B], 111[B]] :List(Byte)? >> (./nosuchfile.xxx):read() -= none : [Byte]? += none :List(Byte)? ``` --- @@ -837,7 +837,7 @@ Nothing. If a path does not exist, a failure will be raised. Returns a list of subdirectories within the directory at the specified path. Optionally includes hidden subdirectories. ```tomo -func subdirectories(path: Path, include_hidden=no -> [Path]) +func subdirectories(path: Path, include_hidden=no -> List(Path)) ``` - `path`: The path of the directory. @@ -910,7 +910,7 @@ it doesn't already exist. Sets the file permissions as specified. If the file writing cannot be successfully completed, a runtime error is raised. ```tomo -func write(path: Path, bytes: [Byte], permissions=0o644[32] -> Void) +func write(path: Path, bytes:List(Byte), permissions=0o644[32] -> Void) ``` - `path`: The path of the file to write to. @@ -960,7 +960,7 @@ file is created if it doesn't exist. This is useful for creating temporary files. ```tomo -func write_unique_bytes(path: Path, bytes: [Byte] -> Path) +func write_unique_bytes(path: Path, bytes:List(Byte) -> Path) ``` - `path`: The base path for generating the unique file. This path must include diff --git a/docs/patterns.md b/docs/patterns.md index 728b978e..c14ca23f 100644 --- a/docs/patterns.md +++ b/docs/patterns.md @@ -22,13 +22,13 @@ functions that would normally be handled by a more extensive API: Text.has(pattern:Pattern -> Bool) Text.each(pattern:Pattern, fn:func(m:Match), recursive=yes -> Text) Text.find(pattern:Pattern, start=1 -> Match?) -Text.find_all(pattern:Pattern -> [Match]) -Text.matches(pattern:Pattern -> [Text]?) +Text.find_all(pattern:Pattern -> List(Match)) +Text.matches(pattern:Pattern -> List(Text)?) Text.map(pattern:Pattern, fn:func(m:Match -> Text), recursive=yes -> Text) -Text.replace(pattern:Pattern, replacement:Text, placeholder:Pattern=$//, recursive=yes -> [Text]) -Text.replace_all(replacements:{Pattern,Text}, placeholder:Pattern=$//, recursive=yes -> [Text]) -Text.split(pattern:Pattern -> [Text]) -Text.trim(pattern=$/{whitespace}/, trim_left=yes, trim_right=yes -> [Text]) +Text.replace(pattern:Pattern, replacement:Text, placeholder:Pattern=$//, recursive=yes -> List(Text)) +Text.replace_all(replacements:Table(Pattern, Text), placeholder:Pattern=$//, recursive=yes -> List(Text)) +Text.split(pattern:Pattern -> List(Text)) +Text.trim(pattern=$/{whitespace}/, trim_left=yes, trim_right=yes -> List(Text)) ``` ## Matches diff --git a/docs/pointers.md b/docs/pointers.md index f1bd1b5a..5cada7c6 100644 --- a/docs/pointers.md +++ b/docs/pointers.md @@ -12,7 +12,7 @@ a new, different value and assigning it to a pointer's memory location to replace the value that previously resided there. ```tomo -func no_mutation_possible(nums:[Int]): +func no_mutation_possible(nums:List(Int)): nums[1] = 10 // This performs a copy-on-write and creates a new array // The new array is only accessible as a local variable here ... @@ -21,7 +21,7 @@ no_mutation_possible(my_nums) >> my_nums = [0, 1, 2] -func do_mutation(nums:@[Int]): +func do_mutation(nums:@List(Int)): nums[1] = 10 // The mutates the value at the given pointer's location ... my_nums := @[0, 1, 2] diff --git a/docs/rng.md b/docs/rng.md index 90c75362..398215c0 100644 --- a/docs/rng.md +++ b/docs/rng.md @@ -21,12 +21,12 @@ This documentation provides details on RNG functions available in the API. - [`func bool(rng: RNG, p: Num = 0.5 -> Bool)`](#bool) - [`func byte(rng: RNG -> Byte)`](#byte) -- [`func bytes(rng: RNG, count: Int -> [Byte])`](#bytes) +- [`func bytes(rng: RNG, count: Int -> List(Byte))`](#bytes) - [`func copy(rng: RNG -> RNG)`](#copy) - [`func int(rng: RNG, min: Int, max: Int -> Int)`](#int`, `int64`, `int32`, `int16`, `int8) -- [`func new(seed: [Byte] = (/dev/urandom):read_bytes(40)! -> RNG)`](#new) +- [`func new(seed:List(Byte) = (/dev/urandom):read_bytes(40)! -> RNG)`](#new) - [`func num(rng: RNG, min: Num = 0.0, max: Num = 1.0 -> Int)`](#num`, `num32) -- [`func set_seed(rng: RNG, seed: [Byte])`](#set_seed) +- [`func set_seed(rng: RNG, seed:List(Byte))`](#set_seed) ### `bool` Generate a random boolean value with a given probability. @@ -77,7 +77,7 @@ A random byte (0-255). Generate an array of uniformly random bytes with the given length. ```tomo -func bytes(rng: RNG, count: Int -> [Byte]) +func bytes(rng: RNG, count: Int -> List(Byte)) ``` - `rng`: The random number generator to use. @@ -153,7 +153,7 @@ is greater than `max`, an error will be raised. Return a new random number generator. ```tomo -func new(seed: [Byte] = (/dev/urandom):read_bytes(40)! -> RNG) +func new(seed:List(Byte) = (/dev/urandom):read_bytes(40)! -> RNG) ``` - `seed`: The seed use for the random number generator. A seed length of 40 @@ -200,7 +200,7 @@ A floating point number uniformly chosen from the range `[min, max]` Set the seed for an RNG. ```tomo -func set_seed(rng: RNG, seed: [Byte]) +func set_seed(rng: RNG, seed:List(Byte)) ``` - `rng`: The random number generator to modify. diff --git a/docs/serialization.md b/docs/serialization.md index 764a6b27..af100c92 100644 --- a/docs/serialization.md +++ b/docs/serialization.md @@ -16,7 +16,7 @@ will return an array of bytes that encode the value's data: ```tomo value := Int64(5) >> serialized := value:serialized() -= [0x0A] : [Byte] += [0x0A] : List(Byte) ``` Serialization produces a fairly compact representation of data as a flat array @@ -59,7 +59,7 @@ c.next = @Cycle("B", next=c) >> c = @Cycle(name="A", next=@Cycle(name="B", next=@~1)) >> serialized := c:serialized() -= [0x02, 0x02, 0x41, 0x01, 0x04, 0x02, 0x42, 0x01, 0x02] : [Byte] += [0x02, 0x02, 0x41, 0x01, 0x04, 0x02, 0x42, 0x01, 0x02] : List(Byte) >> roundtrip := DESERIALIZE(serialized):@Cycle = @Cycle(name="A", next=@Cycle(name="B", next=@~1)) : @Cycle ``` diff --git a/docs/sets.md b/docs/sets.md index 778740a3..a7c88d0e 100644 --- a/docs/sets.md +++ b/docs/sets.md @@ -75,23 +75,23 @@ iterating over any of the new values. ## Set Methods -- [`func add(set:{T}, item: T -> Void)`](#add) -- [`func add_all(set:@{T}, items: [T] -> Void)`](#add_all) -- [`func clear(set:@{T} -> Void)`](#clear) -- [`func has(set:{T}, item:T -> Bool)`](#has) -- [`func (set: {T}, other: {T}, strict: Bool = no -> Bool)`](#is_subset_of) -- [`func is_superset_of(set:{T}, other: {T}, strict: Bool = no -> Bool)`](#is_superset_of) -- [`func overlap(set:{T}, other: {T} -> {T})`](#overlap) -- [`func remove(set:@{T}, item: T -> Void)`](#remove) -- [`func remove_all(set:@{T}, items: [T] -> Void)`](#remove_all) -- [`func with(set:{T}, other: {T} -> {T})`](#with) -- [`func without(set:{T}, other: {T} -> {T})`](#without) +- [`func add(set:Set(T), item: T -> Void)`](#add) +- [`func add_all(set:@Set(T), items:List(T) -> Void)`](#add_all) +- [`func clear(set:@Set(T) -> Void)`](#clear) +- [`func has(set:Set(T), item:T -> Bool)`](#has) +- [`func (set:Set(T), other:Set(T), strict: Bool = no -> Bool)`](#is_subset_of) +- [`func is_superset_of(set:Set(T), other:Set(T), strict: Bool = no -> Bool)`](#is_superset_of) +- [`func overlap(set:Set(T), other:Set(T) -> Set(T))`](#overlap) +- [`func remove(set:@Set(T), item: T -> Void)`](#remove) +- [`func remove_all(set:@Set(T), items:List(T) -> Void)`](#remove_all) +- [`func with(set:Set(T), other:Set(T) -> Set(T))`](#with) +- [`func without(set:Set(T), other:Set(T) -> Set(T))`](#without) ### `add` Adds an item to the set. ```tomo -func add(set:{T}, item: T -> Void) +func add(set:Set(T), item: T -> Void) ``` - `set`: The mutable reference to the set. @@ -111,7 +111,7 @@ Nothing. Adds multiple items to the set. ```tomo -func add_all(set:@{T}, items: [T] -> Void) +func add_all(set:@Set(T), items:List(T) -> Void) ``` - `set`: The mutable reference to the set. @@ -131,7 +131,7 @@ Nothing. Removes all items from the set. ```tomo -func clear(set:@{T} -> Void) +func clear(set:@Set(T) -> Void) ``` - `set`: The mutable reference to the set. @@ -150,7 +150,7 @@ Nothing. Checks if the set contains a specified item. ```tomo -func has(set:{T}, item:T -> Bool) +func has(set:Set(T), item:T -> Bool) ``` - `set`: The set to check. @@ -171,7 +171,7 @@ func has(set:{T}, item:T -> Bool) Checks if the set is a subset of another set. ```tomo -func (set: {T}, other: {T}, strict: Bool = no -> Bool) +func (set:Set(T), other:Set(T), strict: Bool = no -> Bool) ``` - `set`: The set to check. @@ -193,7 +193,7 @@ func (set: {T}, other: {T}, strict: Bool = no -> Bool) Checks if the set is a superset of another set. ```tomo -func is_superset_of(set:{T}, other: {T}, strict: Bool = no -> Bool) +func is_superset_of(set:Set(T), other:Set(T), strict: Bool = no -> Bool) ``` - `set`: The set to check. @@ -212,7 +212,7 @@ func is_superset_of(set:{T}, other: {T}, strict: Bool = no -> Bool) Creates a new set with items that are in both the original set and another set. ```tomo -func overlap(set:{T}, other: {T} -> {T}) +func overlap(set:Set(T), other:Set(T) -> Set(T)) ``` - `set`: The original set. @@ -233,7 +233,7 @@ A new set containing only items present in both sets. Removes an item from the set. ```tomo -func remove(set:@{T}, item: T -> Void) +func remove(set:@Set(T), item: T -> Void) ``` - `set`: The mutable reference to the set. @@ -253,7 +253,7 @@ Nothing. Removes multiple items from the set. ```tomo -func remove_all(set:@{T}, items: [T] -> Void) +func remove_all(set:@Set(T), items:List(T) -> Void) ``` - `set`: The mutable reference to the set. @@ -273,7 +273,7 @@ Nothing. Creates a new set that is the union of the original set and another set. ```tomo -func with(set:{T}, other: {T} -> {T}) +func with(set:Set(T), other:Set(T) -> Set(T)) ``` - `set`: The original set. @@ -294,7 +294,7 @@ A new set containing all items from both sets. Creates a new set with items from the original set but without items from another set. ```tomo -func without(set:{T}, other: {T} -> {T}) +func without(set:Set(T), other:Set(T) -> Set(T)) ``` - `set`: The original set. diff --git a/docs/tables.md b/docs/tables.md index 42af25d4..78c91c5d 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -75,9 +75,9 @@ table value: ```tomo >> t2.fallback -= {"A"=10} : {Text,Int}? += {"A"=10} : Table(Text, Int)? >> t.fallback -= none : {Text,Int}? += none : Table(Text, Int)? ``` ## Setting Values @@ -133,19 +133,19 @@ iterating over any of the new values. ## Table Methods -- [`func bump(t:@{K,V}, key: K, amount: Int = 1 -> Void)`](#bump) -- [`func clear(t:@{K,V})`](#clear) -- [`func get(t:{K,V}, key: K -> V?)`](#get) -- [`func has(t:{K,V}, key: K -> Bool)`](#has) -- [`func remove(t:{K,V}, key: K -> Void)`](#remove) -- [`func set(t:{K,V}, key: K, value: V -> Void)`](#set) +- [`func bump(t:@Table(K,V), key: K, amount: Int = 1 -> Void)`](#bump) +- [`func clear(t:@Table(K,V))`](#clear) +- [`func get(t:Table(K, V), key: K -> V?)`](#get) +- [`func has(t:Table(K, V), key: K -> Bool)`](#has) +- [`func remove(t:Table(K, V), key: K -> Void)`](#remove) +- [`func set(t:Table(K, V), key: K, value: V -> Void)`](#set) ### `bump` Increments the value associated with a key by a specified amount. If the key is not already in the table, its value will be assumed to be zero. ```tomo -func bump(t:@{K,V}, key: K, amount: Int = 1 -> Void) +func bump(t:@Table(K,V), key: K, amount: Int = 1 -> Void) ``` - `t`: The reference to the table. @@ -170,7 +170,7 @@ t:bump("B", 10) Removes all key-value pairs from the table. ```tomo -func clear(t:@{K,V}) +func clear(t:@Table(K,V)) ``` - `t`: The reference to the table. @@ -189,7 +189,7 @@ Nothing. Retrieves the value associated with a key, or returns null if the key is not present. ```tomo -func get(t:{K,V}, key: K -> V?) +func get(t:Table(K, V), key: K -> V?) ``` - `t`: The table. @@ -220,7 +220,7 @@ The value associated with the key or null if the key is not found. Checks if the table contains a specified key. ```tomo -func has(t:{K,V}, key: K -> Bool) +func has(t:Table(K, V), key: K -> Bool) ``` - `t`: The table. @@ -243,7 +243,7 @@ func has(t:{K,V}, key: K -> Bool) Removes the key-value pair associated with a specified key. ```tomo -func remove(t:{K,V}, key: K -> Void) +func remove(t:Table(K, V), key: K -> Void) ``` - `t`: The reference to the table. @@ -266,7 +266,7 @@ t:remove("A") Sets or updates the value associated with a specified key. ```tomo -func set(t:{K,V}, key: K, value: V -> Void) +func set(t:Table(K, V), key: K, value: V -> Void) ``` - `t`: The reference to the table. diff --git a/docs/text.md b/docs/text.md index 79fc5dd5..1467a9e4 100644 --- a/docs/text.md +++ b/docs/text.md @@ -275,31 +275,31 @@ pattern documentation](patterns.md) for more details. - [`func by_line(text: Text -> func(->Text?))`](#by_line) - [`func by_match(text: Text, pattern: Pattern -> func(->Match?))`](#by_match) - [`func by_split(text: Text, pattern: Pattern = $// -> func(->Text?))`](#by_split) -- [`func bytes(text: Text -> [Byte])`](#bytes) +- [`func bytes(text: Text -> List(Byte))`](#bytes) - [`func caseless_equals(a: Text, b:Text, language:Text = "C" -> Bool)`](#caseless_equals) -- [`func codepoint_names(text: Text -> [Text])`](#codepoint_names) +- [`func codepoint_names(text: Text -> List(Text))`](#codepoint_names) - [`func each(text: Text, pattern: Pattern, fn: func(m: Match), recursive: Bool = yes -> Int?)`](#each) - [`func ends_with(text: Text, suffix: Text -> Bool)`](#ends_with) - [`func find(text: Text, pattern: Pattern, start: Int = 1 -> Int?)`](#find) -- [`func find_all(text: Text, pattern: Pattern -> [Match])`](#find_all) +- [`func find_all(text: Text, pattern: Pattern -> List(Match))`](#find_all) - [`func from(text: Text, first: Int -> Text)`](#from) -- [`func from_codepoint_names(codepoints: [Int32] -> [Text])`](#from_bytes) +- [`func from_codepoint_names(codepoints:List(Int32) -> List(Text))`](#from_bytes) - [`func from_c_string(str: CString -> Text)`](#from_c_string) -- [`func from_codepoint_names(codepoint_names: [Text] -> [Text])`](#from_codepoint_names) -- [`func from_codepoint_names(codepoints: [Int32] -> [Text])`](#from_codepoints) +- [`func from_codepoint_names(codepoint_names:List(Text) -> List(Text))`](#from_codepoint_names) +- [`func from_codepoint_names(codepoints:List(Int32) -> List(Text))`](#from_codepoints) - [`func has(text: Text, pattern: Pattern -> Bool)`](#has) -- [`func join(glue: Text, pieces: [Text] -> Text)`](#join) -- [`func split(text: Text -> [Text])`](#lines) +- [`func join(glue: Text, pieces:List(Text) -> Text)`](#join) +- [`func split(text: Text -> List(Text))`](#lines) - [`func middle_pad(text: Text, width: Int, pad: Text = " " -> Text)`](#middle_pad) - [`func left_pad(text: Text, width: Int, pad: Text = " " -> Text)`](#left_pad) -- [`func lines(text: Text, pattern: Pattern = "" -> [Text])`](#lines) +- [`func lines(text: Text, pattern: Pattern = "" -> List(Text))`](#lines) - [`func lower(text: Text, language: Text = "C" -> Text)`](#lower) - [`func map(text: Text, pattern: Pattern, fn: func(text:Match)->Text -> Text, recursive: Bool = yes)`](#map) -- [`func matches(text: Text, pattern: Pattern -> [Text])`](#matches) +- [`func matches(text: Text, pattern: Pattern -> List(Text))`](#matches) - [`func quoted(text: Text, color: Bool = no -> Text)`](#quoted) - [`func repeat(text: Text, count:Int -> Text)`](#repeat) - [`func replace(text: Text, pattern: Pattern, replacement: Text, backref: Pattern = $/\/, recursive: Bool = yes -> Text)`](#replace) -- [`func replace_all(replacements:{Pattern,Text}, backref: Pattern = $/\/, recursive: Bool = yes -> Text)`](#replace_all) +- [`func replace_all(replacements:Table(Pattern, Text), backref: Pattern = $/\/, recursive: Bool = yes -> Text)`](#replace_all) - [`func reversed(text: Text -> Text)`](#reversed) - [`func right_pad(text: Text, width: Int, pad: Text = " " -> Text)`](#right_pad) - [`func slice(text: Text, from: Int = 1, to: Int = -1 -> Text)`](#slice) @@ -308,7 +308,7 @@ pattern documentation](patterns.md) for more details. - [`func to(text: Text, last: Int -> Text)`](#to) - [`func trim(text: Text, pattern: Pattern = $/{whitespace/, trim_left: Bool = yes, trim_right: Bool = yes -> Text)`](#trim) - [`func upper(text: Text, language: Text "C" -> Text)`](#upper) -- [`func utf32_codepoints(text: Text -> [Int32])`](#utf32_codepoints) +- [`func utf32_codepoints(text: Text -> List(Int32))`](#utf32_codepoints) ### `as_c_string` Converts a `Text` value to a C-style string. @@ -439,7 +439,7 @@ Converts a `Text` value to an array of bytes representing a UTF8 encoding of the text. ```tomo -func bytes(text: Text -> [Byte]) +func bytes(text: Text -> List(Byte)) ``` - `text`: The text to be converted to UTF8 bytes. @@ -450,7 +450,7 @@ An array of bytes (`[Byte]`) representing the text in UTF8 encoding. **Example:** ```tomo >> "Amélie":bytes() -= [65[B], 109[B], 195[B], 169[B], 108[B], 105[B], 101[B]] : [Byte] += [65[B], 109[B], 195[B], 169[B], 108[B], 105[B], 101[B]] :List(Byte) ``` --- @@ -486,7 +486,7 @@ func caseless_equals(a: Text, b:Text, language:Text = "C" -> Bool) Returns an array of the names of each codepoint in the text. ```tomo -func codepoint_names(text: Text -> [Text]) +func codepoint_names(text: Text -> List(Text)) ``` - `text`: The text from which to extract codepoint names. @@ -583,7 +583,7 @@ struct containing information about the match. Finds all occurrences of a [pattern](patterns.md) in the given text. ```tomo -func find_all(text: Text, pattern: Pattern -> [Match]) +func find_all(text: Text, pattern: Pattern -> List(Match)) ``` - `text`: The text to be searched. @@ -646,7 +646,7 @@ text will be normalized, so the resulting text's UTF8 bytes may not exactly match the input. ```tomo -func from_codepoint_names(codepoints: [Int32] -> [Text]) +func from_codepoint_names(codepoints:List(Int32) -> List(Text)) ``` - `codepoints`: The UTF32 codepoints in the desired text. @@ -688,7 +688,7 @@ specification) as its codepoints. Note: the text will be normalized, so the resulting text's codepoints may not exactly match the input codepoints. ```tomo -func from_codepoint_names(codepoint_names: [Text] -> [Text]) +func from_codepoint_names(codepoint_names:List(Text) -> List(Text)) ``` - `codepoint_names`: The names of each codepoint in the desired text. Names @@ -716,7 +716,7 @@ the text will be normalized, so the resulting text's codepoints may not exactly match the input codepoints. ```tomo -func from_codepoint_names(codepoints: [Int32] -> [Text]) +func from_codepoint_names(codepoints:List(Int32) -> List(Text)) ``` - `codepoints`: The UTF32 codepoints in the desired text. @@ -763,7 +763,7 @@ func has(text: Text, pattern: Pattern -> Bool) Joins an array of text pieces with a specified glue. ```tomo -func join(glue: Text, pieces: [Text] -> Text) +func join(glue: Text, pieces:List(Text) -> Text) ``` - `glue`: The text used to join the pieces. @@ -837,7 +837,7 @@ Splits the text into an array of lines of text, preserving blank lines, ignoring trailing newlines, and handling `\r\n` the same as `\n`. ```tomo -func lines(text: Text -> [Text]) +func lines(text: Text -> List(Text)) ``` - `text`: The text to be split into lines. @@ -919,7 +919,7 @@ of the matching text captures or a null value if the entire text doesn't match the pattern. ```tomo -func matches(text: Text, pattern: Pattern -> [Text]) +func matches(text: Text, pattern: Pattern -> List(Text)) ``` - `text`: The text to be searched. @@ -932,10 +932,10 @@ or a null value otherwise. **Example:** ```tomo >> "hello world":matches($/{id}/) -= none : [Text]? += none :List(Text)? >> "hello world":matches($/{id} {id}/) -= ["hello", "world"] : [Text]? += ["hello", "world"] :List(Text)? ``` --- @@ -1052,7 +1052,7 @@ modified. See [`replace()`](#replace) for more information about replacement behavior. ```tomo -func replace_all(replacements:{Pattern,Text}, backref: Pattern = $/\/, recursive: Bool = yes -> Text) +func replace_all(replacements:Table(Pattern, Text), backref: Pattern = $/\/, recursive: Bool = yes -> Text) ``` - `text`: The text in which to perform replacements. @@ -1168,7 +1168,7 @@ the string. Splits the text into an array of substrings based on a [pattern](patterns.md). ```tomo -func split(text: Text, pattern: Pattern = "" -> [Text]) +func split(text: Text, pattern: Pattern = "" -> List(Text)) ``` - `text`: The text to be split. @@ -1326,7 +1326,7 @@ The uppercase version of the text. Returns an array of Unicode code points for UTF32 encoding of the text. ```tomo -func utf32_codepoints(text: Text -> [Int32]) +func utf32_codepoints(text: Text -> List(Int32)) ``` - `text`: The text from which to extract Unicode code points. @@ -1337,5 +1337,5 @@ An array of 32-bit integer Unicode code points (`[Int32]`). **Example:** ```tomo >> "Amélie":utf32_codepoints() -= [65[32], 109[32], 233[32], 108[32], 105[32], 101[32]] : [Int32] += [65[32], 109[32], 233[32], 108[32], 105[32], 101[32]] :List(Int32) ``` diff --git a/environment.c b/environment.c index afa9524b..5c93295c 100644 --- a/environment.c +++ b/environment.c @@ -63,8 +63,8 @@ env_t *new_compilation_unit(CORD libname) (void)bind_type(env, "Int", Type(BigIntType)); (void)bind_type(env, "Int32", Type(IntType, .bits=TYPE_IBITS32)); (void)bind_type(env, "Memory", Type(MemoryType)); - MATCH_TYPE = declare_type(env, "struct Match(text:Text, index:Int, captures:[Text])"); - PATH_TYPE = declare_type(env, "struct Path(type:Int32, components:[Text])"); + MATCH_TYPE = declare_type(env, "struct Match(text:Text, index:Int, captures:List(Text))"); + PATH_TYPE = declare_type(env, "struct Path(type:Int32, components:List(Text))"); THREAD_TYPE = declare_type(env, "struct Thread(; opaque)"); RNG_TYPE = declare_type(env, "struct RNG(state:@Memory)"); @@ -82,15 +82,15 @@ env_t *new_compilation_unit(CORD libname) {"Void", Type(VoidType), "Void_t", "Void$info", {}}, {"Abort", Type(AbortType), "void", "Abort$info", {}}, {"Memory", Type(MemoryType), "Memory_t", "Memory$info", {}}, - {"Bool", Type(BoolType), "Bool_t", "Bool$info", TypedArray(ns_entry_t, + {"Bool", Type(BoolType), "Bool_t", "Bool$info", TypedList(ns_entry_t, {"parse", "Bool$parse", "func(text:Text -> Bool?)"}, )}, - {"Byte", Type(ByteType), "Byte_t", "Byte$info", TypedArray(ns_entry_t, + {"Byte", Type(ByteType), "Byte_t", "Byte$info", TypedList(ns_entry_t, {"max", "Byte$max", "Byte"}, {"hex", "Byte$hex", "func(byte:Byte, uppercase=yes, prefix=no -> Text)"}, {"min", "Byte$min", "Byte"}, )}, - {"Int", Type(BigIntType), "Int_t", "Int$info", TypedArray(ns_entry_t, + {"Int", Type(BigIntType), "Int_t", "Int$info", TypedList(ns_entry_t, {"abs", "Int$abs", "func(x:Int -> Int)"}, {"bit_and", "Int$bit_and", "func(x,y:Int -> Int)"}, {"bit_or", "Int$bit_or", "func(x,y:Int -> Int)"}, @@ -121,9 +121,9 @@ env_t *new_compilation_unit(CORD libname) {"times", "Int$times", "func(x,y:Int -> Int)"}, {"to", "Int$to", "func(first:Int,last:Int,step=none:Int -> func(->Int?))"}, )}, - {"Int64", Type(IntType, .bits=TYPE_IBITS64), "Int64_t", "Int64$info", TypedArray(ns_entry_t, + {"Int64", Type(IntType, .bits=TYPE_IBITS64), "Int64_t", "Int64$info", TypedList(ns_entry_t, {"abs", "labs", "func(i:Int64 -> Int64)"}, - {"bits", "Int64$bits", "func(x:Int64 -> [Bool])"}, + {"bits", "Int64$bits", "func(x:Int64 -> List(Bool))"}, {"clamped", "Int64$clamped", "func(x,low,high:Int64 -> Int64)"}, {"divided_by", "Int64$divided_by", "func(x,y:Int64 -> Int64)"}, {"format", "Int64$format", "func(i:Int64, digits=0 -> Text)"}, @@ -142,9 +142,9 @@ env_t *new_compilation_unit(CORD libname) {"wrapping_minus", "Int64$wrapping_minus", "func(x:Int64,y:Int64 -> Int64)"}, {"wrapping_plus", "Int64$wrapping_plus", "func(x:Int64,y:Int64 -> Int64)"}, )}, - {"Int32", Type(IntType, .bits=TYPE_IBITS32), "Int32_t", "Int32$info", TypedArray(ns_entry_t, + {"Int32", Type(IntType, .bits=TYPE_IBITS32), "Int32_t", "Int32$info", TypedList(ns_entry_t, {"abs", "abs", "func(i:Int32 -> Int32)"}, - {"bits", "Int32$bits", "func(x:Int32 -> [Bool])"}, + {"bits", "Int32$bits", "func(x:Int32 -> List(Bool))"}, {"clamped", "Int32$clamped", "func(x,low,high:Int32 -> Int32)"}, {"divided_by", "Int32$divided_by", "func(x,y:Int32 -> Int32)"}, {"format", "Int32$format", "func(i:Int32, digits=0 -> Text)"}, @@ -163,9 +163,9 @@ env_t *new_compilation_unit(CORD libname) {"wrapping_minus", "Int32$wrapping_minus", "func(x:Int32,y:Int32 -> Int32)"}, {"wrapping_plus", "Int32$wrapping_plus", "func(x:Int32,y:Int32 -> Int32)"}, )}, - {"Int16", Type(IntType, .bits=TYPE_IBITS16), "Int16_t", "Int16$info", TypedArray(ns_entry_t, + {"Int16", Type(IntType, .bits=TYPE_IBITS16), "Int16_t", "Int16$info", TypedList(ns_entry_t, {"abs", "abs", "func(i:Int16 -> Int16)"}, - {"bits", "Int16$bits", "func(x:Int16 -> [Bool])"}, + {"bits", "Int16$bits", "func(x:Int16 -> List(Bool))"}, {"clamped", "Int16$clamped", "func(x,low,high:Int16 -> Int16)"}, {"divided_by", "Int16$divided_by", "func(x,y:Int16 -> Int16)"}, {"format", "Int16$format", "func(i:Int16, digits=0 -> Text)"}, @@ -184,9 +184,9 @@ env_t *new_compilation_unit(CORD libname) {"wrapping_minus", "Int16$wrapping_minus", "func(x:Int16,y:Int16 -> Int16)"}, {"wrapping_plus", "Int16$wrapping_plus", "func(x:Int16,y:Int16 -> Int16)"}, )}, - {"Int8", Type(IntType, .bits=TYPE_IBITS8), "Int8_t", "Int8$info", TypedArray(ns_entry_t, + {"Int8", Type(IntType, .bits=TYPE_IBITS8), "Int8_t", "Int8$info", TypedList(ns_entry_t, {"abs", "abs", "func(i:Int8 -> Int8)"}, - {"bits", "Int8$bits", "func(x:Int8 -> [Bool])"}, + {"bits", "Int8$bits", "func(x:Int8 -> List(Bool))"}, {"clamped", "Int8$clamped", "func(x,low,high:Int8 -> Int8)"}, {"divided_by", "Int8$divided_by", "func(x,y:Int8 -> Int8)"}, {"format", "Int8$format", "func(i:Int8, digits=0 -> Text)"}, @@ -209,7 +209,7 @@ env_t *new_compilation_unit(CORD libname) #define F(name) {#name, #name, "func(n:Num -> Num)"} #define F_opt(name) {#name, #name, "func(n:Num -> Num?)"} #define F2(name) {#name, #name, "func(x,y:Num -> Num)"} - {"Num", Type(NumType, .bits=TYPE_NBITS64), "Num_t", "Num$info", TypedArray(ns_entry_t, + {"Num", Type(NumType, .bits=TYPE_NBITS64), "Num_t", "Num$info", TypedList(ns_entry_t, {"near", "Num$near", "func(x,y:Num, ratio=1e-9, min_epsilon=1e-9 -> Bool)"}, {"clamped", "Num$clamped", "func(x,low,high:Num -> Num)"}, {"format", "Num$format", "func(n:Num, precision=16 -> Text)"}, @@ -240,7 +240,7 @@ env_t *new_compilation_unit(CORD libname) #define F(name) {#name, #name"f", "func(n:Num32 -> Num32)"} #define F_opt(name) {#name, #name"f", "func(n:Num32 -> Num32?)"} #define F2(name) {#name, #name"f", "func(x,y:Num32 -> Num32)"} - {"Num32", Type(NumType, .bits=TYPE_NBITS32), "Num32_t", "Num32$info", TypedArray(ns_entry_t, + {"Num32", Type(NumType, .bits=TYPE_NBITS32), "Num32_t", "Num32$info", TypedList(ns_entry_t, {"near", "Num32$near", "func(x,y:Num32, ratio=Num32(1e-9), min_epsilon=Num32(1e-9) -> Bool)"}, {"clamped", "Num32$clamped", "func(x,low,high:Num32 -> Num32)"}, {"format", "Num32$format", "func(n:Num32, precision=8 -> Text)"}, @@ -263,21 +263,21 @@ env_t *new_compilation_unit(CORD libname) F_opt(tan), F(tanh), F_opt(tgamma), F(trunc), F_opt(y0), F_opt(y1), F2(atan2), F2(copysign), F2(fdim), F2(hypot), F2(nextafter), )}, - {"CString", Type(CStringType), "char*", "CString$info", TypedArray(ns_entry_t, + {"CString", Type(CStringType), "char*", "CString$info", TypedList(ns_entry_t, {"as_text", "CString$as_text_simple", "func(str:CString -> Text)"}, )}, #undef F2 #undef F_opt #undef F #undef C - {"Match", MATCH_TYPE, "Match_t", "Match", TypedArray(ns_entry_t, + {"Match", MATCH_TYPE, "Match_t", "Match", TypedList(ns_entry_t, // No methods )}, - {"Pattern", Type(TextType, .lang="Pattern", .env=namespace_env(env, "Pattern")), "Pattern_t", "Pattern$info", TypedArray(ns_entry_t, + {"Pattern", Type(TextType, .lang="Pattern", .env=namespace_env(env, "Pattern")), "Pattern_t", "Pattern$info", TypedList(ns_entry_t, {"escape_int", "Int$value_as_text", "func(i:Int -> Pattern)"}, {"escape_text", "Pattern$escape_text", "func(text:Text -> Pattern)"}, )}, - {"Moment", Type(MomentType), "Moment_t", "Moment", TypedArray(ns_entry_t, + {"Moment", Type(MomentType), "Moment_t", "Moment", TypedList(ns_entry_t, // Used as a default for functions below: {"now", "Moment$now", "func(->Moment)"}, @@ -305,10 +305,10 @@ env_t *new_compilation_unit(CORD libname) {"unix_timestamp", "Moment$unix_timestamp", "func(moment:Moment -> Int64)"}, {"year", "Moment$year", "func(moment:Moment,timezone=none:Text -> Int)"}, )}, - {"Path", PATH_TYPE, "Path_t", "Path$info", TypedArray(ns_entry_t, + {"Path", PATH_TYPE, "Path_t", "Path$info", TypedList(ns_entry_t, {"accessed", "Path$accessed", "func(path:Path, follow_symlinks=yes -> Moment?)"}, {"append", "Path$append", "func(path:Path, text:Text, permissions=Int32(0o644))"}, - {"append_bytes", "Path$append_bytes", "func(path:Path, bytes:[Byte], permissions=Int32(0o644))"}, + {"append_bytes", "Path$append_bytes", "func(path:Path, bytes:List(Byte), permissions=Int32(0o644))"}, {"base_name", "Path$base_name", "func(path:Path -> Text)"}, {"by_line", "Path$by_line", "func(path:Path -> func(->Text?)?)"}, {"can_execute", "Path$can_execute", "func(path:Path -> Bool)"}, @@ -316,15 +316,15 @@ env_t *new_compilation_unit(CORD libname) {"can_write", "Path$can_write", "func(path:Path -> Bool)"}, {"changed", "Path$changed", "func(path:Path, follow_symlinks=yes -> Moment?)"}, {"child", "Path$with_component", "func(path:Path, child:Text -> Path)"}, - {"children", "Path$children", "func(path:Path, include_hidden=no -> [Path])"}, + {"children", "Path$children", "func(path:Path, include_hidden=no -> List(Path))"}, {"concatenated_with", "Path$concat", "func(a,b:Path -> Path)"}, {"create_directory", "Path$create_directory", "func(path:Path, permissions=Int32(0o755))"}, {"exists", "Path$exists", "func(path:Path -> Bool)"}, {"expand_home", "Path$expand_home", "func(path:Path -> Path)"}, {"extension", "Path$extension", "func(path:Path, full=yes -> Text)"}, - {"files", "Path$children", "func(path:Path, include_hidden=no -> [Path])"}, - {"from_components", "Path$from_components", "func(components:[Text] -> Path)"}, - {"glob", "Path$glob", "func(path:Path -> [Path])"}, + {"files", "Path$children", "func(path:Path, include_hidden=no -> List(Path))"}, + {"from_components", "Path$from_components", "func(components:List(Text) -> Path)"}, + {"glob", "Path$glob", "func(path:Path -> List(Path))"}, {"group", "Path$group", "func(path:Path, follow_symlinks=yes -> Text?)"}, {"is_directory", "Path$is_directory", "func(path:Path, follow_symlinks=yes -> Bool)"}, {"is_file", "Path$is_file", "func(path:Path, follow_symlinks=yes -> Bool)"}, @@ -335,23 +335,23 @@ env_t *new_compilation_unit(CORD libname) {"owner", "Path$owner", "func(path:Path, follow_symlinks=yes -> Text?)"}, {"parent", "Path$parent", "func(path:Path -> Path)"}, {"read", "Path$read", "func(path:Path -> Text?)"}, - {"read_bytes", "Path$read_bytes", "func(path:Path, limit=none:Int -> [Byte]?)"}, + {"read_bytes", "Path$read_bytes", "func(path:Path, limit=none:Int -> List(Byte)?)"}, {"relative_to", "Path$relative_to", "func(path:Path, relative_to:Path -> Path)"}, {"remove", "Path$remove", "func(path:Path, ignore_missing=no)"}, {"resolved", "Path$resolved", "func(path:Path, relative_to=(./) -> Path)"}, {"set_owner", "Path$set_owner", "func(path:Path, owner=none:Text, group=none:Text, follow_symlinks=yes)"}, - {"subdirectories", "Path$children", "func(path:Path, include_hidden=no -> [Path])"}, + {"subdirectories", "Path$children", "func(path:Path, include_hidden=no -> List(Path))"}, {"unique_directory", "Path$unique_directory", "func(path:Path -> Path)"}, {"write", "Path$write", "func(path:Path, text:Text, permissions=Int32(0o644))"}, - {"write_bytes", "Path$write_bytes", "func(path:Path, bytes:[Byte], permissions=Int32(0o644))"}, + {"write_bytes", "Path$write_bytes", "func(path:Path, bytes:List(Byte), permissions=Int32(0o644))"}, {"write_unique", "Path$write_unique", "func(path:Path, text:Text -> Path)"}, - {"write_unique_bytes", "Path$write_unique_bytes", "func(path:Path, bytes:[Byte] -> Path)"}, + {"write_unique_bytes", "Path$write_unique_bytes", "func(path:Path, bytes:List(Byte) -> Path)"}, )}, // RNG must come after Path so we can read bytes from /dev/urandom - {"RNG", RNG_TYPE, "RNG_t", "RNG", TypedArray(ns_entry_t, + {"RNG", RNG_TYPE, "RNG_t", "RNG", TypedList(ns_entry_t, {"bool", "RNG$bool", "func(rng:RNG, p=0.5 -> Bool)"}, {"byte", "RNG$byte", "func(rng:RNG -> Byte)"}, - {"bytes", "RNG$bytes", "func(rng:RNG, count:Int -> [Byte])"}, + {"bytes", "RNG$bytes", "func(rng:RNG, count:Int -> List(Byte))"}, {"copy", "RNG$copy", "func(rng:RNG -> RNG)"}, {"int", "RNG$int", "func(rng:RNG, min,max:Int -> Int)"}, {"int16", "RNG$int16", "func(rng:RNG, min=Int16.min, max=Int16.max -> Int16)"}, @@ -361,51 +361,51 @@ env_t *new_compilation_unit(CORD libname) {"new", "RNG$new", "func(seed=(/dev/urandom):read_bytes(40)! -> RNG)"}, {"num", "RNG$num", "func(rng:RNG, min=0.0, max=1.0 -> Num)"}, {"num32", "RNG$num32", "func(rng:RNG, min=Num32(0.0), max=Num32(1.0) -> Num32)"}, - {"set_seed", "RNG$set_seed", "func(rng:RNG, seed:[Byte])"}, + {"set_seed", "RNG$set_seed", "func(rng:RNG, seed:List(Byte))"}, )}, - {"Text", TEXT_TYPE, "Text_t", "Text$info", TypedArray(ns_entry_t, + {"Text", TEXT_TYPE, "Text_t", "Text$info", TypedList(ns_entry_t, {"as_c_string", "Text$as_c_string", "func(text:Text -> CString)"}, {"at", "Text$cluster", "func(text:Text, index:Int -> Text)"}, {"by_line", "Text$by_line", "func(text:Text -> func(->Text?))"}, {"by_match", "Text$by_match", "func(text:Text, pattern:Pattern -> func(->Match?))"}, {"by_split", "Text$by_split", "func(text:Text, pattern=$Pattern'' -> func(->Text?))"}, - {"bytes", "Text$utf8_bytes", "func(text:Text -> [Byte])"}, + {"bytes", "Text$utf8_bytes", "func(text:Text -> List(Byte))"}, {"caseless_equals", "Text$equal_ignoring_case", "func(a,b:Text, language=\"C\" -> Bool)"}, - {"codepoint_names", "Text$codepoint_names", "func(text:Text -> [Text])"}, + {"codepoint_names", "Text$codepoint_names", "func(text:Text -> List(Text))"}, {"ends_with", "Text$ends_with", "func(text,suffix:Text -> Bool)"}, {"each", "Text$each", "func(text:Text, pattern:Pattern, fn:func(match:Match), recursive=yes)"}, {"find", "Text$find", "func(text:Text, pattern:Pattern, start=1 -> Match?)"}, - {"find_all", "Text$find_all", "func(text:Text, pattern:Pattern -> [Match])"}, + {"find_all", "Text$find_all", "func(text:Text, pattern:Pattern -> List(Match))"}, {"from", "Text$from", "func(text:Text, first:Int -> Text)"}, - {"from_bytes", "Text$from_bytes", "func(bytes:[Byte] -> Text?)"}, + {"from_bytes", "Text$from_bytes", "func(bytes:List(Byte) -> Text?)"}, {"from_c_string", "Text$from_str", "func(str:CString -> Text?)"}, - {"from_codepoint_names", "Text$from_codepoint_names", "func(codepoint_names:[Text] -> Text?)"}, - {"from_codepoints", "Text$from_codepoints", "func(codepoints:[Int32] -> Text)"}, + {"from_codepoint_names", "Text$from_codepoint_names", "func(codepoint_names:List(Text) -> Text?)"}, + {"from_codepoints", "Text$from_codepoints", "func(codepoints:List(Int32) -> Text)"}, {"from_text", "Path$from_text", "func(text:Text -> Path)"}, {"has", "Text$has", "func(text:Text, pattern:Pattern -> Bool)"}, - {"join", "Text$join", "func(glue:Text, pieces:[Text] -> Text)"}, + {"join", "Text$join", "func(glue:Text, pieces:List(Text) -> Text)"}, {"left_pad", "Text$left_pad", "func(text:Text, count:Int, pad=\" \" -> Text)"}, - {"lines", "Text$lines", "func(text:Text -> [Text])"}, + {"lines", "Text$lines", "func(text:Text -> List(Text))"}, {"lower", "Text$lower", "func(text:Text, language=\"C\" -> Text)"}, {"map", "Text$map", "func(text:Text, pattern:Pattern, fn:func(match:Match -> Text), recursive=yes -> Text)"}, - {"matches", "Text$matches", "func(text:Text, pattern:Pattern -> [Text]?)"}, + {"matches", "Text$matches", "func(text:Text, pattern:Pattern -> List(Text)?)"}, {"middle_pad", "Text$middle_pad", "func(text:Text, count:Int, pad=\" \" -> Text)"}, {"quoted", "Text$quoted", "func(text:Text, color=no -> Text)"}, {"repeat", "Text$repeat", "func(text:Text, count:Int -> Text)"}, {"replace", "Text$replace", "func(text:Text, pattern:Pattern, replacement:Text, backref=$/\\/, recursive=yes -> Text)"}, - {"replace_all", "Text$replace_all", "func(text:Text, replacements:{Pattern,Text}, backref=$/\\/, recursive=yes -> Text)"}, + {"replace_all", "Text$replace_all", "func(text:Text, replacements:Table(Pattern, Text), backref=$/\\/, recursive=yes -> Text)"}, {"reversed", "Text$reversed", "func(text:Text -> Text)"}, {"right_pad", "Text$right_pad", "func(text:Text, count:Int, pad=\" \" -> Text)"}, {"slice", "Text$slice", "func(text:Text, from=1, to=-1 -> Text)"}, - {"split", "Text$split", "func(text:Text, pattern=$Pattern'' -> [Text])"}, + {"split", "Text$split", "func(text:Text, pattern=$Pattern'' -> List(Text))"}, {"starts_with", "Text$starts_with", "func(text,prefix:Text -> Bool)"}, {"title", "Text$title", "func(text:Text, language=\"C\" -> Text)"}, {"to", "Text$to", "func(text:Text, last:Int -> Text)"}, {"trim", "Text$trim", "func(text:Text, pattern=$/{whitespace}/, trim_left=yes, trim_right=yes -> Text)"}, {"upper", "Text$upper", "func(text:Text, language=\"C\" -> Text)"}, - {"utf32_codepoints", "Text$utf32_codepoints", "func(text:Text -> [Int32])"}, + {"utf32_codepoints", "Text$utf32_codepoints", "func(text:Text -> List(Int32))"}, )}, - {"Thread", THREAD_TYPE, "Thread_t", "Thread", TypedArray(ns_entry_t, + {"Thread", THREAD_TYPE, "Thread_t", "Thread", TypedList(ns_entry_t, {"new", "Thread$new", "func(fn:func() -> Thread)"}, {"cancel", "Thread$cancel", "func(thread:Thread)"}, {"join", "Thread$join", "func(thread:Thread)"}, diff --git a/examples/base64/base64.tm b/examples/base64/base64.tm index fadfed20..e2adc206 100644 --- a/examples/base64/base64.tm +++ b/examples/base64/base64.tm @@ -28,7 +28,7 @@ lang Base64: func parse(text:Text -> Base64?): return Base64.from_bytes(text:bytes()) - func from_bytes(bytes:[Byte] -> Base64?): + func from_bytes(bytes:List(Byte) -> Base64?): output := &[Byte(0) for _ in bytes.length * 4 / 3 + 4] src := Int64(1) dest := Int64(1) @@ -64,7 +64,7 @@ lang Base64: func decode_text(b64:Base64 -> Text?): return Text.from_bytes(b64:decode_bytes() or return none) - func decode_bytes(b64:Base64 -> [Byte]?): + func decode_bytes(b64:Base64 -> List(Byte)?): bytes := b64.text:bytes() output := &[Byte(0) for _ in bytes.length/4 * 3] src := Int64(1) diff --git a/examples/colorful/colorful.tm b/examples/colorful/colorful.tm index e5baf4ac..f0901ae2 100644 --- a/examples/colorful/colorful.tm +++ b/examples/colorful/colorful.tm @@ -21,7 +21,7 @@ lang Colorful: say(c:for_terminal(), newline=newline) -func main(texts:[Text], files=[:Path], by_line=no): +func main(texts:List(Text), files=[:Path], by_line=no): for i,text in texts: colorful := Colorful.from_text(text) colorful:print(newline=no) @@ -113,13 +113,13 @@ enum _Color(Default, Bright(color:Int16), Color8Bit(color:Int16), Color24Bit(col pass fail("Invalid underline color: '$c'") -func _toggle(sequences:&[Text], cur,new:Bool, apply,unapply:Text; inline): +func _toggle(sequences:&List(Text), cur,new:Bool, apply,unapply:Text; inline): if new and not cur: sequences:insert(apply) else if cur and not new: sequences:insert(unapply) -func _toggle2(sequences:&[Text], cur1,cur2,new1,new2:Bool, apply1,apply2,unapply:Text; inline): +func _toggle2(sequences:&List(Text), cur1,cur2,new1,new2:Bool, apply1,apply2,unapply:Text; inline): return if new1 == cur1 and new2 == cur2 if (cur1 and not new1) or (cur2 and not new2): # Gotta wipe at least one sequences:insert(unapply) diff --git a/examples/commands/commands.tm b/examples/commands/commands.tm index a0e73908..4a6adeb0 100644 --- a/examples/commands/commands.tm +++ b/examples/commands/commands.tm @@ -2,11 +2,11 @@ use ./commands.c -extern run_command:func(exe:Text, args:[Text], env:{Text,Text}, input:[Byte], output:&[Byte], error:&[Byte] -> Int32) +extern run_command:func(exe:Text, args:List(Text), env:Table(Text,Text), input:List(Byte), output:&List(Byte), error:&List(Byte) -> Int32) enum ExitType(Exited(status:Int32), Signaled(signal:Int32), Failed) -struct ProgramResult(stdout:[Byte], stderr:[Byte], exit_type:ExitType): +struct ProgramResult(stdout:List(Byte), stderr:List(Byte), exit_type:ExitType): func or_fail(r:ProgramResult -> ProgramResult): when r.exit_type is Exited(status): if status == 0: @@ -54,13 +54,13 @@ struct Command(command:Text, args=[:Text], env={:Text,Text}): func get_output(command:Command, input="", trim_newline=yes -> Text?): return command:run(input=input):output_text(trim_newline=trim_newline) - func get_output_bytes(command:Command, input="", input_bytes=[:Byte] -> [Byte]?): + func get_output_bytes(command:Command, input="", input_bytes=[:Byte] -> List(Byte)?): result := command:run(input=input, input_bytes=input_bytes) when result.exit_type is Exited(status): if status == 0: return result.stdout return none else: return none -func main(command:Text, args:[Text], input=""): +func main(command:Text, args:List(Text), input=""): cmd := Command(command, args) say(cmd:get_output(input=input)!) diff --git a/examples/game/world.tm b/examples/game/world.tm index 58fcd4fa..643ae7ae 100644 --- a/examples/game/world.tm +++ b/examples/game/world.tm @@ -37,7 +37,7 @@ func solve_overlap(a_pos:Vector2, a_size:Vector2, b_pos:Vector2, b_size:Vector2 return Vector2(0, 0) -struct World(player:@Player, goal:@Box, boxes:@[@Box], dt_accum=Num32(0.0), won=no): +struct World(player:@Player, goal:@Box, boxes:@List(@Box), dt_accum=Num32(0.0), won=no): DT := (Num32(1.)/Num32(60.))! STIFFNESS := Num32(0.3) diff --git a/examples/ini/ini.tm b/examples/ini/ini.tm index 1c50ac37..e6f0a7e3 100644 --- a/examples/ini/ini.tm +++ b/examples/ini/ini.tm @@ -6,9 +6,9 @@ _HELP := " $_USAGE " -func parse_ini(path:Path -> {Text,{Text,Text}}): +func parse_ini(path:Path -> Table(Text, Table(Text, Text))): text := path:read() or exit("Could not read INI file: $\[31;1]$(path)$\[]") - sections := @{:Text,@{Text,Text}} + sections := @{:Text,@Table(Text, Text)} current_section := @{:Text,Text} # Line wraps: diff --git a/examples/learnxiny.tm b/examples/learnxiny.tm index e2058558..d015137d 100644 --- a/examples/learnxiny.tm +++ b/examples/learnxiny.tm @@ -242,9 +242,9 @@ func takes_many_types( integer:Int, floating_point_number:Num, text_aka_string:Text, - array_of_ints:[Int], - table_of_text_to_bools:{Text,Bool}, - pointer_to_mutable_array_of_ints:@[Int], + array_of_ints:List(Int), + table_of_text_to_bools:Table(Text,Bool), + pointer_to_mutable_array_of_ints:@List(Int), optional_int:Int?, function_from_int_to_text:func(x:Int -> Text), ): diff --git a/examples/pthread/pthread.tm b/examples/pthread/pthread.tm index 13d94e40..e33d2b1f 100644 --- a/examples/pthread/pthread.tm +++ b/examples/pthread/pthread.tm @@ -53,7 +53,7 @@ struct pthread_t(; extern, opaque): func cancel(p:@pthread_t): inline C { pthread_cancel(*_$p); } func detatch(p:@pthread_t): inline C { pthread_detach(*_$p); } -struct IntQueue(_queue:@[Int], _mutex:@pthread_mutex_t, _cond:@pthread_cond_t): +struct IntQueue(_queue:@List(Int), _mutex:@pthread_mutex_t, _cond:@pthread_cond_t): func new(initial=[:Int] -> IntQueue): return IntQueue(@initial, pthread_mutex_t.new(), pthread_cond_t.new()) diff --git a/examples/shell/shell.tm b/examples/shell/shell.tm index cf5fcd2e..86100912 100644 --- a/examples/shell/shell.tm +++ b/examples/shell/shell.tm @@ -4,13 +4,13 @@ lang Shell: convert(text:Text -> Shell): return Shell.from_text("'" ++ text:replace($/'/, `'"'"'`) ++ "'") - convert(texts:[Text] -> Shell): + convert(texts:List(Text) -> Shell): return Shell.from_text(" ":join([Shell(t).text for t in texts])) convert(path:Path -> Shell): return Shell(Text(path:expand_home())) - convert(paths:[Path] -> Shell): + convert(paths:List(Path) -> Shell): return Shell.from_text(" ":join([Shell(Text(p)).text for p in paths])) convert(n:Int -> Shell): return Shell.from_text(Text(n)) @@ -30,6 +30,6 @@ lang Shell: func get_output(shell:Shell, input="", trim_newline=yes -> Text?): return shell:command():get_output(input=input, trim_newline=trim_newline) - func get_output_bytes(shell:Shell, input="", input_bytes=[:Byte] -> [Byte]?): + func get_output_bytes(shell:Shell, input="", input_bytes=[:Byte] -> List(Byte)?): return shell:command():get_output_bytes(input=input, input_bytes=input_bytes) diff --git a/examples/tomo-install/tomo-install.tm b/examples/tomo-install/tomo-install.tm index 0205c380..cd806f28 100644 --- a/examples/tomo-install/tomo-install.tm +++ b/examples/tomo-install/tomo-install.tm @@ -9,7 +9,7 @@ _HELP := " Usage: $_USAGE " -func find_urls(path:Path -> [Text]): +func find_urls(path:Path -> List(Text)): urls := @[:Text] if path:is_directory(): for f in path:children(): @@ -20,7 +20,7 @@ func find_urls(path:Path -> [Text]): urls:insert(m[-1]) return urls -func main(paths:[Path]): +func main(paths:List(Path)): if paths.length == 0: paths = [(./)] diff --git a/examples/tomodeps/tomodeps.tm b/examples/tomodeps/tomodeps.tm index 8149ff88..44ac6e45 100644 --- a/examples/tomodeps/tomodeps.tm +++ b/examples/tomodeps/tomodeps.tm @@ -9,7 +9,7 @@ _HELP := " enum Dependency(File(path:Path), Module(name:Text)) -func _get_file_dependencies(file:Path -> {Dependency}): +func _get_file_dependencies(file:Path -> Set(Dependency)): if not file:is_file(): !! Could not read file: $file return {:Dependency} @@ -25,7 +25,7 @@ func _get_file_dependencies(file:Path -> {Dependency}): deps:add(Dependency.Module(module_name)) return deps[] -func _build_dependency_graph(dep:Dependency, dependencies:@{Dependency,{Dependency}}): +func _build_dependency_graph(dep:Dependency, dependencies:@Table(Dependency,Set(Dependency))): return if dependencies:has(dep) dependencies[dep] = {:Dependency} # Placeholder @@ -55,8 +55,8 @@ func _build_dependency_graph(dep:Dependency, dependencies:@{Dependency,{Dependen for dep2 in dep_deps: _build_dependency_graph(dep2, dependencies) -func get_dependency_graph(dep:Dependency -> {Dependency,{Dependency}}): - graph := @{:Dependency,{Dependency}} +func get_dependency_graph(dep:Dependency -> Table(Dependency, Set(Dependency))): + graph := @{:Dependency,Set(Dependency)} _build_dependency_graph(dep, graph) return graph @@ -70,7 +70,7 @@ func _printable_name(dep:Dependency -> Text): else: return "$(\x1b)[31;1m$(f) (not found)$(\x1b)[m" -func _draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}, already_printed:@{Dependency}, prefix="", is_last=yes): +func _draw_tree(dep:Dependency, dependencies:Table(Dependency,Set(Dependency)), already_printed:@Set(Dependency), prefix="", is_last=yes): if already_printed:has(dep): say(prefix ++ (if is_last: "└── " else: "├── ") ++ _printable_name(dep) ++ " $\x1b[2m(recursive)$\x1b[m") return @@ -85,7 +85,7 @@ func _draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}, already_ is_child_last := (i == children.length) _draw_tree(child, dependencies, already_printed, child_prefix, is_child_last) -func draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}): +func draw_tree(dep:Dependency, dependencies:Table(Dependency,Set(Dependency))): printed := @{:Dependency} say(_printable_name(dep)) printed:add(dep) @@ -94,7 +94,7 @@ func draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}): is_child_last := (i == deps.length) _draw_tree(child, dependencies, already_printed=printed, is_last=is_child_last) -func main(files:[Text]): +func main(files:List(Text)): if files.length == 0: exit(" Please provide at least one file! diff --git a/examples/wrap/wrap.tm b/examples/wrap/wrap.tm index c90713a9..4040ee65 100644 --- a/examples/wrap/wrap.tm +++ b/examples/wrap/wrap.tm @@ -71,13 +71,13 @@ func wrap(text:Text, width:Int, min_split=3, hyphen="-" -> Text): return \n:join(lines) -func _can_fit_word(line:Text, letters:[Text], width:Int -> Bool; inline): +func _can_fit_word(line:Text, letters:List(Text), width:Int -> Bool; inline): if line == "": return letters.length <= width else: return line.length + 1 + letters.length <= width -func main(files:[Path], width=80, inplace=no, min_split=3, rewrap=yes, hyphen=UNICODE_HYPHEN): +func main(files:List(Path), width=80, inplace=no, min_split=3, rewrap=yes, hyphen=UNICODE_HYPHEN): if files.length == 0: files = [(/dev/stdin)] @@ -54,7 +54,7 @@ static const char *keywords[] = { "yes", "xor", "while", "when", "use", "unless", "struct", "stop", "skip", "return", "or", "not", "none", "no", "mutexed", "mod1", "mod", "pass", "lang", "inline", "in", "if", "holding", "func", "for", "extern", "enum", "end", "else", "do", "deserialize", "defer", "begin", "and", - "_min_", "_max_", NULL, + "_min_", "_max_", "Table", "List", "Set", NULL, }; enum {NORMAL_FUNCTION=0, EXTERN_FUNCTION=1}; @@ -564,7 +564,7 @@ PARSER(parse_moment) { type_ast_t *parse_table_type(parse_ctx_t *ctx, const char *pos) { const char *start = pos; - if (!match(&pos, "{")) return NULL; + if (!match(&pos, "Table(")) return NULL; whitespace(&pos); type_ast_t *key_type = parse_type(ctx, pos); if (!key_type) return NULL; @@ -580,20 +580,20 @@ type_ast_t *parse_table_type(parse_ctx_t *ctx, const char *pos) { return NULL; } whitespace(&pos); - expect_closing(ctx, &pos, "}", "I wasn't able to parse the rest of this table type"); + expect_closing(ctx, &pos, ")", "I wasn't able to parse the rest of this table type"); return NewTypeAST(ctx->file, start, pos, TableTypeAST, .key=key_type, .value=value_type, .default_value=default_value); } type_ast_t *parse_set_type(parse_ctx_t *ctx, const char *pos) { const char *start = pos; - if (!match(&pos, "{")) return NULL; + if (!match(&pos, "Set(")) return NULL; whitespace(&pos); type_ast_t *item_type = parse_type(ctx, pos); if (!item_type) return NULL; pos = item_type->end; whitespace(&pos); if (match(&pos, ",")) return NULL; - expect_closing(ctx, &pos, "}", "I wasn't able to parse the rest of this set type"); + expect_closing(ctx, &pos, ")", "I wasn't able to parse the rest of this set type"); return NewTypeAST(ctx->file, start, pos, SetTypeAST, .item=item_type); } @@ -611,10 +611,10 @@ type_ast_t *parse_func_type(parse_ctx_t *ctx, const char *pos) { type_ast_t *parse_array_type(parse_ctx_t *ctx, const char *pos) { const char *start = pos; - if (!match(&pos, "[")) return NULL; + if (!match(&pos, "List(")) return NULL; type_ast_t *type = expect(ctx, start, &pos, parse_type, "I couldn't parse an array item type after this point"); - expect_closing(ctx, &pos, "]", "I wasn't able to parse the rest of this array type"); + expect_closing(ctx, &pos, ")", "I wasn't able to parse the rest of this array type"); return NewTypeAST(ctx->file, start, pos, ArrayTypeAST, .item=type); } @@ -759,6 +759,15 @@ static INLINE bool match_separator(const char **pos) { // Either comma or newlin PARSER(parse_array) { const char *start = pos; + + if (match(&pos, "List(")) { + whitespace(&pos); + type_ast_t *item_type = expect(ctx, pos-1, &pos, parse_type, "I couldn't parse a type for this array"); + whitespace(&pos); + expect_closing(ctx, &pos, ")", "I wasn't able to parse the rest of this array"); + return NewAST(ctx->file, start, pos, Array, .item_type=item_type); + } + if (!match(&pos, "[")) return NULL; whitespace(&pos); @@ -798,6 +807,46 @@ PARSER(parse_array) { PARSER(parse_table) { const char *start = pos; + + if (match(&pos, "Table(")) { + whitespace(&pos); + type_ast_t *key_type = expect(ctx, pos-1, &pos, parse_type, "I couldn't parse a key type for this table"); + whitespace(&pos); + type_ast_t *value_type = NULL; + ast_t *default_value = NULL; + if (match(&pos, ",")) { + value_type = expect(ctx, pos-1, &pos, parse_type, "I couldn't parse the value type for this table"); + } else if (match(&pos, "=")) { + default_value = expect(ctx, pos-1, &pos, parse_extended_expr, "I couldn't parse the default value for this table"); + } else { + return NULL; + } + whitespace(&pos); + + ast_t *fallback = NULL; + if (match(&pos, ";")) { + for (;;) { + whitespace(&pos); + const char *attr_start = pos; + if (match_word(&pos, "fallback")) { + whitespace(&pos); + if (!match(&pos, "=")) parser_err(ctx, attr_start, pos, "I expected an '=' after 'fallback'"); + if (fallback) + parser_err(ctx, attr_start, pos, "This table already has a fallback"); + fallback = expect(ctx, attr_start, &pos, parse_expr, "I expected a fallback table"); + } else { + break; + } + whitespace(&pos); + if (!match(&pos, ";")) break; + } + } + + expect_closing(ctx, &pos, ")", "I wasn't able to parse the rest of this table"); + return NewAST(ctx->file, start, pos, Table, .key_type=key_type, .value_type=value_type, + .default_value=default_value, .fallback=fallback); + } + if (!match(&pos, "{")) return NULL; whitespace(&pos); @@ -874,6 +923,15 @@ PARSER(parse_table) { PARSER(parse_set) { const char *start = pos; + + if (match(&pos, "Set(")) { + whitespace(&pos); + type_ast_t *item_type = expect(ctx, pos-1, &pos, parse_type, "I couldn't parse a key type for this set"); + whitespace(&pos); + expect_closing(ctx, &pos, ")", "I wasn't able to parse the rest of this set"); + return NewAST(ctx->file, start, pos, Set, .item_type=item_type); + } + if (!match(&pos, "{")) return NULL; whitespace(&pos); diff --git a/stdlib/arrays.c b/stdlib/arrays.c index 41d46741..1e1ce5f0 100644 --- a/stdlib/arrays.c +++ b/stdlib/arrays.c @@ -555,7 +555,7 @@ public Text_t Array$as_text(const void *obj, bool colorize, const TypeInfo_t *ty { Array_t *arr = (Array_t*)obj; if (!arr) - return Text$concat(Text("["), generic_as_text(NULL, false, type->ArrayInfo.item), Text("]")); + return Text$concat(Text("List("), generic_as_text(NULL, false, type->ArrayInfo.item), Text(")")); const TypeInfo_t *item_type = type->ArrayInfo.item; Text_t text = Text("["); diff --git a/stdlib/arrays.h b/stdlib/arrays.h index 332a1db0..6b88b1ee 100644 --- a/stdlib/arrays.h +++ b/stdlib/arrays.h @@ -36,7 +36,7 @@ #define Array_set(item_type, arr, index, value, start, end) \ Array_lvalue(item_type, arr_expr, index, start, end) = value #define is_atomic(x) _Generic(x, bool: true, int8_t: true, int16_t: true, int32_t: true, int64_t: true, float: true, double: true, default: false) -#define TypedArray(t, ...) ({ t items[] = {__VA_ARGS__}; \ +#define TypedList(t, ...) ({ t items[] = {__VA_ARGS__}; \ (Array_t){.length=sizeof(items)/sizeof(items[0]), \ .stride=(int64_t)&items[1] - (int64_t)&items[0], \ .data=memcpy(GC_MALLOC(sizeof(items)), items, sizeof(items)), \ @@ -48,7 +48,7 @@ .data=memcpy(GC_MALLOC(sizeof(items)), items, sizeof(items)), \ .atomic=0, \ .data_refcount=0}; }) -#define Array(x, ...) ({ __typeof(x) items[] = {x, __VA_ARGS__}; \ +#define List(x, ...) ({ __typeof(x) items[] = {x, __VA_ARGS__}; \ (Array_t){.length=sizeof(items)/sizeof(items[0]), \ .stride=(int64_t)&items[1] - (int64_t)&items[0], \ .data=memcpy(is_atomic(x) ? GC_MALLOC_ATOMIC(sizeof(items)) : GC_MALLOC(sizeof(items)), items, sizeof(items)), \ diff --git a/stdlib/tables.c b/stdlib/tables.c index 97419327..73a3af19 100644 --- a/stdlib/tables.c +++ b/stdlib/tables.c @@ -582,16 +582,16 @@ public Text_t Table$as_text(const void *obj, bool colorize, const TypeInfo_t *ty if (!t) { if (table.value != &Void$info) return Text$concat( - Text("{"), + Text("Table("), generic_as_text(NULL, false, table.key), - Text(","), + Text(", "), generic_as_text(NULL, false, table.value), - Text("}")); + Text(")")); else return Text$concat( - Text("{"), + Text("Set("), generic_as_text(NULL, false, table.key), - Text("}")); + Text(")")); } int64_t val_off = (int64_t)value_offset(type); @@ -606,7 +606,7 @@ public Text_t Table$as_text(const void *obj, bool colorize, const TypeInfo_t *ty } if (t->fallback) { - text = Text$concat(text, Text("; fallback="), Table$as_text(t->fallback, colorize, type)); + text = Text$concat(text, colorize ? Text("; \033[33mfallback\033[m=") : Text("; fallback="), Table$as_text(t->fallback, colorize, type)); } text = Text$concat(text, Text("}")); diff --git a/test/arrays.tm b/test/arrays.tm index 965ef95c..30a0a2c7 100644 --- a/test/arrays.tm +++ b/test/arrays.tm @@ -1,7 +1,7 @@ func main(): do: >> [:Num32] - = [] : [Num32] + = [] : List(Num32) do: >> arr := [10, 20, 30] diff --git a/test/corecursive_func.tm b/test/corecursive_func.tm index b5f5f13e..64bf64d0 100644 --- a/test/corecursive_func.tm +++ b/test/corecursive_func.tm @@ -1,10 +1,10 @@ -func ping(x:Int->[Text]): +func ping(x:Int-> List(Text)): if x > 0: return ["ping: $x"] ++ pong(x-1) else: return ["ping: $x"] -func pong(x:Int->[Text]): +func pong(x:Int-> List(Text)): if x > 0: return ["pong: $x"] ++ ping(x-1) else: diff --git a/test/for.tm b/test/for.tm index e3774815..0476ea74 100644 --- a/test/for.tm +++ b/test/for.tm @@ -1,5 +1,5 @@ -func all_nums(nums:[Int] -> Text): +func all_nums(nums:List(Int) -> Text): result := "" for num in nums: result ++= "$num," @@ -7,7 +7,7 @@ func all_nums(nums:[Int] -> Text): return "EMPTY" return result -func labeled_nums(nums:[Int] -> Text): +func labeled_nums(nums:List(Int) -> Text): result := "" for i,num in nums: result ++= "$i:$num," @@ -15,14 +15,14 @@ func labeled_nums(nums:[Int] -> Text): return "EMPTY" return result -func table_str(t:{Text,Text} -> Text): +func table_str(t:Table(Text,Text) -> Text): str := "" for k,v in t: str ++= "$k:$v," else: return "EMPTY" return str -func table_key_str(t:{Text,Text} -> Text): +func table_key_str(t:Table(Text,Text) -> Text): str := "" for k in t: str ++= "$k," diff --git a/test/iterators.tm b/test/iterators.tm index 4a85e6f9..d4287272 100644 --- a/test/iterators.tm +++ b/test/iterators.tm @@ -1,7 +1,7 @@ struct Pair(x:Text, y:Text) -func pairwise(strs:[Text] -> func(->Pair?)): +func pairwise(strs:List(Text) -> func(->Pair?)): i := 1 return func(): if i + 1 > strs.length: return none:Pair diff --git a/test/optionals.tm b/test/optionals.tm index 0b2a2209..f5d26707 100644 --- a/test/optionals.tm +++ b/test/optionals.tm @@ -25,7 +25,7 @@ func maybe_int64(should_i:Bool->Int64?): else: return none -func maybe_array(should_i:Bool->[Int]?): +func maybe_array(should_i:Bool-> List(Int)?): if should_i: return [10, 20, 30] else: @@ -128,9 +128,9 @@ func main(): !! ... !! Arrays: >> yep := maybe_array(yes) - = [10, 20, 30] : [Int]? + = [10, 20, 30] : List(Int)? >> nope := maybe_array(no) - = none : [Int]? + = none : List(Int)? >> if yep: >> yep = [10, 20, 30] diff --git a/test/paths.tm b/test/paths.tm index 1302f7a5..d51d5d26 100644 --- a/test/paths.tm +++ b/test/paths.tm @@ -25,7 +25,7 @@ func main(): >> tmpfile:read() = "Hello world!" : Text? >> tmpfile:read_bytes() - = [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21] : [Byte]? + = [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21] : List(Byte)? >> tmpdir:files():has(tmpfile) = yes @@ -38,7 +38,7 @@ func main(): >> (./does-not-exist.xxx):read() = none : Text? >> (./does-not-exist.xxx):read_bytes() - = none : [Byte]? + = none : List(Byte)? if lines := (./does-not-exist.xxx):by_line(): fail("I could read lines in a nonexistent file") else: diff --git a/test/serialization.tm b/test/serialization.tm index 433caab3..f7cb85d4 100644 --- a/test/serialization.tm +++ b/test/serialization.tm @@ -38,7 +38,7 @@ func main(): do: >> obj := [Int64(10), Int64(20), Int64(30)]:reversed() >> bytes := obj:serialized() - >> deserialize(bytes -> [Int64]) == obj + >> deserialize(bytes -> List(Int64)) == obj = yes do: @@ -50,7 +50,7 @@ func main(): do: >> obj := @[10, 20] >> bytes := obj:serialized() - >> roundtrip := deserialize(bytes -> @[Int]) + >> roundtrip := deserialize(bytes -> @List(Int)) >> roundtrip == obj = no >> roundtrip[] == obj[] @@ -59,7 +59,7 @@ func main(): do: >> obj := {"A"=10, "B"=20; fallback={"C"=30}} >> bytes := obj:serialized() - >> deserialize(bytes -> {Text,Int}) == obj + >> deserialize(bytes -> Table(Text, Int)) == obj = yes do: @@ -84,7 +84,7 @@ func main(): do: >> obj := {10, 20, 30} >> bytes := obj:serialized() - >> deserialize(bytes -> {Int}) == obj + >> deserialize(bytes -> Set(Int)) == obj = yes do: diff --git a/test/tables.tm b/test/tables.tm index c97c35a0..ad2d051b 100644 --- a/test/tables.tm +++ b/test/tables.tm @@ -22,7 +22,7 @@ func main(): >> t.length = 2 >> t.fallback - = none : {Text,Int}? + = none : Table(Text, Int)? >> t.keys = ["one", "two"] @@ -42,7 +42,7 @@ func main(): >> t2.length = 1 >> t2.fallback - = {"one"=1, "two"=2} : {Text,Int}? + = {"one"=1, "two"=2} : Table(Text, Int)? t2_str := "" for k,v in t2: diff --git a/test/text.tm b/test/text.tm index 4e38e346..e598e8c1 100644 --- a/test/text.tm +++ b/test/text.tm @@ -51,7 +51,7 @@ func main(): amelie := "Am$(\UE9)lie" >> amelie:split() - = ["A", "m", "é", "l", "i", "e"] : [Text] + = ["A", "m", "é", "l", "i", "e"] : List(Text) >> amelie:utf32_codepoints() = [65, 109, 233, 108, 105, 101] >> amelie:bytes() @@ -63,7 +63,7 @@ func main(): amelie2 := "Am$(\U65\U301)lie" >> amelie2:split() - = ["A", "m", "é", "l", "i", "e"] : [Text] + = ["A", "m", "é", "l", "i", "e"] : List(Text) >> amelie2:utf32_codepoints() = [65, 109, 233, 108, 105, 101] >> amelie2:bytes() @@ -271,13 +271,13 @@ func main(): = " good(x, fn(y), BAD(z), w) " >> "Hello":matches($/{id}/) - = ["Hello"] : [Text]? + = ["Hello"] : List(Text)? >> "Hello":matches($/{lower}/) - = none : [Text]? + = none : List(Text)? >> "Hello":matches($/{upper}/) - = none : [Text]? + = none : List(Text)? >> "Hello...":matches($/{id}/) - = none : [Text]? + = none : List(Text)? if matches := "hello world":matches($/{id} {id}/): >> matches @@ -36,19 +36,19 @@ CORD type_to_cord(type_t *t) { case NumType: return Match(t, NumType)->bits == TYPE_NBITS32 ? "Num32" : "Num"; case ArrayType: { auto array = Match(t, ArrayType); - return CORD_asprintf("[%r]", type_to_cord(array->item_type)); + return CORD_asprintf("List(%r)", type_to_cord(array->item_type)); } case TableType: { auto table = Match(t, TableType); if (table->default_value) - return CORD_asprintf("{%r=%.*s}", type_to_cord(table->key_type), + return CORD_asprintf("Table(%r=%.*s)", type_to_cord(table->key_type), table->default_value->end - table->default_value->start, table->default_value->start); else - return CORD_asprintf("{%r:%r}", type_to_cord(table->key_type), type_to_cord(table->value_type)); + return CORD_asprintf("Table(%r, %r)", type_to_cord(table->key_type), type_to_cord(table->value_type)); } case SetType: { auto set = Match(t, SetType); - return CORD_asprintf("{%r}", type_to_cord(set->item_type)); + return CORD_asprintf("Set(%r)", type_to_cord(set->item_type)); } case ClosureType: { return type_to_cord(Match(t, ClosureType)->fn); |
