Files
doslang-mirror/fec/tests/format/ok_forma.fe
T
coolguy 51e2568ba7 implement: unit identity -- dotted paths, name rules, source path
Units start here, with the part that needs no import graph: what a unit is
called and where it must live.

The parser only ever read a single identifier after `unit` and `import`, so
`unit game.main;` and `import std.io;` were syntax errors -- which is why the
dotted fixtures failed at the semicolon. It now reads a dotted path and stores
it canonically, dots included, since that spelling is the unit's identity
everywhere else. `import a.b as c;` parses too, with the alias on the node.

resolve.c is the new pass between parsing and checking, for the questions that
span files. It carries SPEC 8.1 so far: each path segment is ASCII lowercase,
starts with a letter, continues with letters, digits or underscore, and is at
most eight characters; and the dotted path must match the source path it was
read from, so game.world.map has to come from game/world/map.fe. The source
side is folded to lowercase before comparing, because a case-insensitive host
must not let two spellings become two units.

That rule then applied to the fixtures, which were not obeying it: 57 declared
a unit name unrelated to their file, left over from the milestone directories,
and eight had names too long to be legal. Both are now aligned -- the rule is
worth having only if the tree follows it.

units: badupper, badlong and unitbad pass. 138 -> 146 of 188. The rest of
units/ needs the import graph, which is the next piece: resolution, cycles,
bindings and visibility.
2026-08-17 03:47:28 +09:00

31 lines
1.1 KiB
Plaintext

unit ok_forma;
const FMT: str = "n={} hex={x} c={c} s={s} b={b} {{ok}}\n";
fn main() -> i32 {
var raw: [8]u8 = [0, 0, 0, 0, 0, 0, 0, 0];
var raw2: [8]u8 = [0, 0, 0, 0, 0, 0, 0, 0];
var raw3: [8]u8 = [0, 0, 0, 0, 0, 0, 0, 0];
var raw4: [8]u8 = [0, 0, 0, 0, 0, 0, 0, 0];
var raw5: [8]u8 = [0, 0, 0, 0, 0, 0, 0, 0];
var buf: []mut u8 = raw[..];
var buf2: []mut u8 = raw2[..];
var buf3: []mut u8 = raw3[..];
var buf4: []mut u8 = raw4[..];
var buf5: []mut u8 = raw5[..];
let w: io.Writer = io.null_writer();
const LOCAL_FMT: str = "value={}\n";
@print(FMT, 7, 15, 'A', "yes", true);
@fprint(w, LOCAL_FMT, 12);
let n: usize = @sprint(buf2, "A\x42\u0043defghi");
let n2: usize = @sprint(buf3, "xy");
let inner_n: usize = @sprint(buf4, "xy");
let outer_n: usize = @sprint(buf5, "n={}", @sprint(buf4, "xy"));
if n == 8 and buf2[0] == ('A' as u8) and
buf2[1] == ('B' as u8) and buf2[2] == ('C' as u8) and
n2 == 2 and buf3[0] == ('x' as u8) and
inner_n == 2 and outer_n == 3 and
buf5[0] == ('n' as u8) and buf5[2] == ('2' as u8) { return 0; }
return 1;
}