mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 08:54:25 +00:00
Structs, arrays, owned strings, memory model, modules, debug info
- struct with default values; constructors Point(1, 2) / Point(x: 1); field access, auto-deref through pointers - []T arrays with bounds checks, literals, for-each, push/pop/insert/remove/clear/resize/find/contains/join/slice/reverse/sort - str carries its length: .len, s[i], +, comparison, sub/find/split/trim/upper/lower/replace/repeat/bytes, str(x), int(s), float(s) - Memory: values own their memory and are freed at the end of their block; assignment copies, temporaries move; parameters are lent and only copied when the function changes them; defer; new()/free() for manual heap memory - input(), read_file/write_file/file_exists, exit(), fn main([]str args) - Finch modules: import name, module.fn(), module.Struct - C structs from headers (fields, fixed arrays, nested); passed and returned by value with the System V x86-64 ABI; addr(fn) gives C a callback - link "file.c" compiles and links your own C code - -g emits DWARF debug info (gdb/lldb) - Small C runtime (runtime/finch_rt.c) embedded in the compiler, cached in ~/.cache/finch - Tests: 58, all clean under valgrind (MEMCHECK=1 tests/run.sh) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0591cd20f3
commit
1dc976bd8f
59 changed files with 4577 additions and 1047 deletions
4
tests/fail/array_compare.fn
Normal file
4
tests/fail/array_compare.fn
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// expect: compare the parts one by one
|
||||
fn main() {
|
||||
print([1] == [1])
|
||||
}
|
||||
4
tests/fail/bad_int.fn
Normal file
4
tests/fail/bad_int.fn
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// expect: can't turn "12x" into int
|
||||
fn main() {
|
||||
print(int("12x"))
|
||||
}
|
||||
4
tests/fail/defer_return.fn
Normal file
4
tests/fail/defer_return.fn
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// expect: return can't be used inside defer
|
||||
fn main() {
|
||||
defer return
|
||||
}
|
||||
6
tests/fail/each_readonly.fn
Normal file
6
tests/fail/each_readonly.fn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// expect: the loop variable 'x' can't be changed
|
||||
fn main() {
|
||||
for x in [1, 2] {
|
||||
x = 3
|
||||
}
|
||||
}
|
||||
4
tests/fail/empty_array.fn
Normal file
4
tests/fail/empty_array.fn
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// expect: an empty [] needs a type
|
||||
fn main() {
|
||||
a := []
|
||||
}
|
||||
5
tests/fail/free_value.fn
Normal file
5
tests/fail/free_value.fn
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// expect: arrays, str and structs are freed by Finch
|
||||
fn main() {
|
||||
x := 5
|
||||
free(x)
|
||||
}
|
||||
5
tests/fail/index_range.fn
Normal file
5
tests/fail/index_range.fn
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// expect: runtime error: index 5 is out of range (the length is 3)
|
||||
fn main() {
|
||||
a := [1, 2, 3]
|
||||
print(a[5])
|
||||
}
|
||||
3
tests/fail/module_missing.fn
Normal file
3
tests/fail/module_missing.fn
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// expect: can't find the module 'nothere'
|
||||
import nothere
|
||||
fn main() {}
|
||||
4
tests/fail/module_not_imported.fn
Normal file
4
tests/fail/module_not_imported.fn
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// expect: to use a module, add import geometry
|
||||
fn main() {
|
||||
v := geometry.Vec(1, 2)
|
||||
}
|
||||
5
tests/fail/pop_empty.fn
Normal file
5
tests/fail/pop_empty.fn
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// expect: runtime error: pop() on an empty array
|
||||
fn main() {
|
||||
[]int a
|
||||
a.pop()
|
||||
}
|
||||
5
tests/fail/push_type.fn
Normal file
5
tests/fail/push_type.fn
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// expect: the element must be int, but this is str
|
||||
fn main() {
|
||||
a := [1, 2]
|
||||
a.push("x")
|
||||
}
|
||||
6
tests/fail/str_null.fn
Normal file
6
tests/fail/str_null.fn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// expect: a str is never null
|
||||
fn main() {
|
||||
s := "a"
|
||||
if s == null {
|
||||
}
|
||||
}
|
||||
4
tests/fail/str_plus_int.fn
Normal file
4
tests/fail/str_plus_int.fn
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// expect: turn the other side into text first: str(...)
|
||||
fn main() {
|
||||
s := "a" + 5
|
||||
}
|
||||
8
tests/fail/struct_count.fn
Normal file
8
tests/fail/struct_count.fn
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// expect: P has 2 fields, but got 1 values
|
||||
struct P {
|
||||
int x
|
||||
int y
|
||||
}
|
||||
fn main() {
|
||||
p := P(1)
|
||||
}
|
||||
8
tests/fail/struct_no_field.fn
Normal file
8
tests/fail/struct_no_field.fn
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// expect: the struct P has no field 'y' (it has: x)
|
||||
struct P {
|
||||
int x
|
||||
}
|
||||
fn main() {
|
||||
p := P(1)
|
||||
print(p.y)
|
||||
}
|
||||
5
tests/fail/struct_self.fn
Normal file
5
tests/fail/struct_self.fn
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// expect: contains itself; use ptr[A] or []A
|
||||
struct A {
|
||||
A inner
|
||||
}
|
||||
fn main() {}
|
||||
Loading…
Reference in a new issue