const, if as a value, """ text over several lines, min/max/abs/clamp, import a/b and import x as y, the fs module

- const NAME = value (numbers, text, other constants; typed: const f32 G = 9.8), also module.NAME
- x := if c { a } else { b }
- """ ... """: the closing quotes' indentation goes from every line
- min, max, abs, clamp for any numbers, unless your own function has the name
- import ui/button (a module in a folder), import path as p
- fs: read_bytes, write_bytes, exists, is_dir, mkdir (with parents), list, remove_dir, data_dir(app)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016GzNP6r8dg6WDxUVZy8wjL
This commit is contained in:
Nexoniarz 2026-10-29 09:37:41 +01:00
commit f2d6480749
21 changed files with 688 additions and 17 deletions

View file

@ -0,0 +1,5 @@
// expect: is a constant; it can't be changed
const W = 3
fn main() {
W = 4
}

View file

@ -0,0 +1,6 @@
// expect: a constant is made of numbers, text
fn f() -> int { return 1 }
const W = f()
fn main() {
print(W)
}

View file

@ -0,0 +1,6 @@
// expect: is worked out from itself
const A = B + 1
const B = A
fn main() {
print(A)
}

View file

@ -0,0 +1,4 @@
// expect: an if that gives a value needs an else
fn main() {
x := if true { 1 }
}

View file

@ -0,0 +1,4 @@
// expect: both branches of the if have to give the same type
fn main() {
x := if true { 1 } else { "one" }
}

View file

@ -0,0 +1,5 @@
// expect: is already used by another import
import path
import time as path
fn main() {
}

View file

@ -0,0 +1,6 @@
// expect: is indented less than the closing
fn main() {
s := """
a
"""
}

View file

@ -0,0 +1,33 @@
// const, if as a value, min/max/abs/clamp, import a/b and import x as y, """ text
import ui/button
import path as p
import ui/button as b2
const W = 640
const H = W / 2
const f32 G = 9.8
const TITLE = "Game " + "One"
const NEG = -W
fn main() {
print(W, H, G, TITLE, NEG, button.SIZE)
bt := button.make("ok")
button.Button other
print(bt.label, bt.w, other.w, b2.make("x").w)
print(p.base("/a/b.txt"))
x := 7
v := if x > 5 { "big" } else if x > 2 { "mid" } else { "small" }
f32 s = if x > 5 { 1.5 } else { 0.5 }
print(v, s, if x == 7 { x * 2 } else { 0 })
print(min(3, 9), max(2.5, 1), abs(-4), abs(-2.5), clamp(15, 0, 10), clamp(-3, 0, 10), min(5, 2, 8))
f32 sp = 2.0
print(clamp(sp * 3.0, 0.0, 5.0), max(u8(3), u8(200)))
shader := """
#version 330
void main() {
gl_Position = vec4(0.0);
}
"""
print(shader)
print("""one "quoted" line""")
}

View file

@ -0,0 +1,11 @@
640 320 9.8 Game One -640 3
ok 30 30 30
b.txt
big 1.5 14
3 2.5 4 2.5 10 0 2
5 200
#version 330
void main() {
gl_Position = vec4(0.0);
}
one "quoted" line

23
tests/new/std_fs.fch Normal file
View file

@ -0,0 +1,23 @@
// the fs module: bytes with NUL in them, folders, listing
import fs
fn main() -> ! {
root := "fs_test_dir"
try fs.mkdir(root + "/a/b")
print(fs.exists(root), fs.is_dir(root + "/a/b"), fs.is_dir("nope"))
data := [u8(0), u8(255), u8(13), u8(10), u8(65)]
try fs.write_bytes(root + "/a/blob.bin", data)
back := try fs.read_bytes(root + "/a/blob.bin")
print(back.len, back[0], back[1], back[4], str(back) == str(data))
write_file(root + "/z.txt", "z")
print(try fs.list(root))
print(try fs.list(root + "/a"))
print(fs.list("no_such_dir") or ["(none)"])
delete_file(root + "/a/blob.bin")
delete_file(root + "/z.txt")
try fs.remove_dir(root + "/a/b")
try fs.remove_dir(root + "/a")
try fs.remove_dir(root)
print(fs.exists(root))
fs.remove_dir(root) or { print("gone:", err) }
}

7
tests/new/std_fs.out Normal file
View file

@ -0,0 +1,7 @@
true true false
5 0 255 65 true
["a", "z.txt"]
["b", "blob.bin"]
["(none)"]
false
gone: can't remove the folder "fs_test_dir" (is it empty?)

7
tests/new/ui/button.fch Normal file
View file

@ -0,0 +1,7 @@
// a module in a folder, for tests/new/lang_additions.fch (import ui/button)
const SIZE = 3
struct Button {
str label
int w = SIZE * 10
}
fn make(str l) -> Button { return Button(label: l) }