move some stuff around
This commit is contained in:
@@ -3,9 +3,4 @@ b :: import "@std/build"
|
|||||||
config :: b.BuildConfig{
|
config :: b.BuildConfig{
|
||||||
name = "honey",
|
name = "honey",
|
||||||
source = "source",
|
source = "source",
|
||||||
libraries = &[],
|
|
||||||
lib_paths = &[],
|
|
||||||
includes = &[],
|
|
||||||
defines = &[],
|
|
||||||
links = &[],
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,19 @@ import "@std/debug"
|
|||||||
import "@std/mem"
|
import "@std/mem"
|
||||||
import "@std/arraylist"
|
import "@std/arraylist"
|
||||||
|
|
||||||
|
test import "@std/arraylist"
|
||||||
|
|
||||||
program ::
|
program ::
|
||||||
`# these are immutable
|
`# these are immutable
|
||||||
`x :: 32
|
`x :: 32
|
||||||
`y :: 3.2
|
`y :: 3.2
|
||||||
|
`
|
||||||
|
`# these are mutable
|
||||||
|
`z u32 = 54
|
||||||
|
|
||||||
main func() void {
|
main func() void {
|
||||||
|
debug.print("PROGRAM::[[\n{}\n]]\n\n", {program})
|
||||||
|
|
||||||
tokens std.ArrayList(Token) = arraylist.init(mem.c_allocator)
|
tokens std.ArrayList(Token) = arraylist.init(mem.c_allocator)
|
||||||
defer arraylist.deinit(&tokens)
|
defer arraylist.deinit(&tokens)
|
||||||
|
|
||||||
@@ -17,7 +24,9 @@ main func() void {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug.print("TOKENS::[[\n", {})
|
||||||
for tokens.items |token| {
|
for tokens.items |token| {
|
||||||
debug.print("{}\n", { token.kind })
|
debug.print("{}\n", { token.kind })
|
||||||
}
|
}
|
||||||
|
debug.print("]]\n", {})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ deinit func($T type, list @mut ArrayList(T)) void {
|
|||||||
list.capacity = 0
|
list.capacity = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
reserve func($T type, list @mut ArrayList(T), minimum_capacity usize) void ! mem.AllocError {
|
reserve func($T type, list @mut ArrayList(T), min_capacity usize) void ! mem.AllocError {
|
||||||
if minimum_capacity <= list.capacity {
|
if min_capacity <= list.capacity {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,13 +32,13 @@ reserve func($T type, list @mut ArrayList(T), minimum_capacity usize) void ! mem
|
|||||||
if list.capacity >= 8 {
|
if list.capacity >= 8 {
|
||||||
half usize :: divtrunc!(list.capacity, 2)
|
half usize :: divtrunc!(list.capacity, 2)
|
||||||
if list.capacity > maxval!(usize) - half {
|
if list.capacity > maxval!(usize) - half {
|
||||||
new_capacity = minimum_capacity
|
new_capacity = min_capacity
|
||||||
} else {
|
} else {
|
||||||
new_capacity = list.capacity + half
|
new_capacity = list.capacity + half
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if new_capacity < minimum_capacity {
|
if new_capacity < min_capacity {
|
||||||
new_capacity = minimum_capacity
|
new_capacity = min_capacity
|
||||||
}
|
}
|
||||||
|
|
||||||
length usize :: list.items.len
|
length usize :: list.items.len
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import "@std/mem"
|
||||||
|
import "@std/testing"
|
||||||
|
|
||||||
|
handles_append test {
|
||||||
|
list ArrayList(i32) = init(mem.c_allocator)
|
||||||
|
defer deinit(&list)
|
||||||
|
|
||||||
|
try append(&list, 42)
|
||||||
|
|
||||||
|
try testing.expect_equal(1, list.items.len)
|
||||||
|
try testing.expect_equal(42, list.items[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
handles_clear test {
|
||||||
|
list ArrayList(i32) = init(mem.c_allocator)
|
||||||
|
defer deinit(&list)
|
||||||
|
|
||||||
|
try append(&list, 42)
|
||||||
|
clear(&list)
|
||||||
|
|
||||||
|
try testing.expect_equal(0, list.items.len)
|
||||||
|
}
|
||||||
|
|
||||||
|
handles_reserve test {
|
||||||
|
list ArrayList(i32) = init(mem.c_allocator)
|
||||||
|
defer deinit(&list)
|
||||||
|
|
||||||
|
try reserve(&list, 10)
|
||||||
|
|
||||||
|
try testing.expect_equal(10, list.capacity)
|
||||||
|
try testing.expect_equal(0, list.items.len)
|
||||||
|
}
|
||||||
+8
-8
@@ -5,13 +5,13 @@
|
|||||||
# build.bro, reads the config, and writes root/build/name.
|
# build.bro, reads the config, and writes root/build/name.
|
||||||
#
|
#
|
||||||
# Declarative and literal-only: one executable per build. List fields take an
|
# Declarative and literal-only: one executable per build. List fields take an
|
||||||
# address-of an array literal (`&["raylib"]`); empty lists are written `&[]`.
|
# address-of an array literal (`&["raylib"]`) and default to empty.
|
||||||
BuildConfig :: struct {
|
BuildConfig :: struct {
|
||||||
name []u8 # output executable name under root/build
|
name []u8 # output executable name under root/build
|
||||||
source []u8 # program package directory, relative to build.bro
|
source []u8 # program package directory, relative to build.bro
|
||||||
libraries [][]u8 # library names to link (-l)
|
libraries [][]u8 = &[] # library names to link (-l)
|
||||||
lib_paths [][]u8 # library search directories (-L)
|
lib_paths [][]u8 = &[] # library search directories (-L)
|
||||||
includes [][]u8 # C include directories (-I)
|
includes [][]u8 = &[] # C include directories (-I)
|
||||||
defines [][]u8 # C preprocessor defines (name or name=value)
|
defines [][]u8 = &[] # C preprocessor defines (name or name=value)
|
||||||
links [][]u8 # extra linker inputs (object/source files, -framework pairs)
|
links [][]u8 = &[] # extra linker inputs (object/source files, -framework pairs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import "@std/debug"
|
||||||
|
|
||||||
|
Error :: enum {
|
||||||
|
expectation_failed
|
||||||
|
}
|
||||||
|
|
||||||
|
SourceLocation :: struct {
|
||||||
|
file []u8
|
||||||
|
line usize
|
||||||
|
column usize
|
||||||
|
}
|
||||||
|
|
||||||
|
expect func(condition bool, location SourceLocation) void ! Error {
|
||||||
|
if !condition {
|
||||||
|
debug.print("{s}:{d}:{d}: expectation failed\n", {location.file, location.line, location.column})
|
||||||
|
return .expectation_failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect_equal func($T type, expected, actual T, location SourceLocation) void ! Error {
|
||||||
|
if expected != actual {
|
||||||
|
debug.print("{s}:{d}:{d}: expected {}, found {}\n", {location.file, location.line, location.column, expected, actual})
|
||||||
|
return .expectation_failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run func(name []u8, callback *func() void ! Error) bool {
|
||||||
|
callback() catch |_| {
|
||||||
|
debug.print("{s} [failed]\n", {name,})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
debug.print("{s} [ok]\n", {name,})
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
summary func(passed, failed i32) void {
|
||||||
|
debug.print("{d} passed, {d} failed\n", {passed, failed})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user