mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 00:44:27 +00:00
Struct defaults apply inside structs; exit() ends an or-block; 1e9 literals; x * 2.0 stays f32; floats print as the shortest exact text; str(x, digits)
Also frees main's args and the message of a failing main (valgrind was not clean on two tests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b24a7845ef
commit
6142e47e71
10 changed files with 207 additions and 10 deletions
43
tests/new/defaults_numbers.fch
Normal file
43
tests/new/defaults_numbers.fch
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// struct defaults apply inside structs too; number literals and float text
|
||||
|
||||
struct Audio {
|
||||
int rate = 48000
|
||||
float volume = 0.8
|
||||
}
|
||||
|
||||
struct Mixer {
|
||||
Audio audio
|
||||
[]Audio extra
|
||||
int voices = 5
|
||||
}
|
||||
|
||||
struct Box[T] {
|
||||
T item
|
||||
Audio audio
|
||||
}
|
||||
|
||||
fn make() -> Mixer {
|
||||
Mixer m
|
||||
return m
|
||||
}
|
||||
|
||||
fn scale(f32 x) -> f32 {
|
||||
return x * 2.0 + 1
|
||||
}
|
||||
|
||||
fn main() {
|
||||
a := Mixer()
|
||||
Mixer b
|
||||
c := Mixer(voices: 2)
|
||||
list := [Mixer()]
|
||||
m := ["x": Mixer()]
|
||||
map[str]Mixer counts
|
||||
counts["new"].voices += 1
|
||||
bx := Box[int]()
|
||||
print(a.audio.rate, b.audio.volume, c.audio.rate, c.voices, list[0].audio.rate, m["x"].audio.rate)
|
||||
print(make().audio.rate, counts["new"].audio.rate, counts["new"].voices, bx.audio.rate)
|
||||
|
||||
print(1e3, 2.5e-3, 1E+6, 1_000.5e1, scale(1.5))
|
||||
print(1.0 / 3.0, 0.1 + 0.2, 100000000.0, 1e20, 1e-7, float(7), f32(0.1))
|
||||
print(str(3.14159, 2), str(2, 1), str(f32(0.1)), "x=" + str(0.25), [0.5, 1.25])
|
||||
}
|
||||
5
tests/new/defaults_numbers.out
Normal file
5
tests/new/defaults_numbers.out
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
48000 0.8 48000 2 48000 48000
|
||||
48000 48000 6 48000
|
||||
1000 0.0025 1000000 10005 4
|
||||
0.3333333333333333 0.30000000000000004 100000000 1e+20 1e-07 7 0.1
|
||||
3.14 2.0 0.1 x=0.25 [0.5, 1.25]
|
||||
12
tests/new/exit_or.fch
Normal file
12
tests/new/exit_or.fch
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// exit(...) ends an or-block, like return
|
||||
fn load(str p) -> int! {
|
||||
return error("no such file")
|
||||
}
|
||||
|
||||
fn main() {
|
||||
n := load("a.txt") or {
|
||||
print("stopping:", err)
|
||||
exit(0)
|
||||
}
|
||||
print("never", n)
|
||||
}
|
||||
1
tests/new/exit_or.out
Normal file
1
tests/new/exit_or.out
Normal file
|
|
@ -0,0 +1 @@
|
|||
stopping: no such file
|
||||
5
tests/new/fail/after_exit.fch
Normal file
5
tests/new/fail/after_exit.fch
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// expect: this code can never run (it comes after return, break, continue or exit)
|
||||
fn main() {
|
||||
exit(1)
|
||||
print("x")
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
5
|
||||
(4, 5) of length 6.40312
|
||||
(4, 5) of length 6.4031242374328485
|
||||
Vec(x: 0, y: 0)
|
||||
10 Box(corner: Vec(x: 0, y: 0), size: Vec(x: 2, y: 5))
|
||||
total 3
|
||||
|
|
|
|||
Loading…
Reference in a new issue