feat(v4.0.0): reading a line and splitting it into words and numbers
The first layer of the compiler capsule, on the host node: TIB >IN SPAN SOURCE BL EXPECT QUERY WORD ENCLOSE CONVERT NUMBER and the comment words. The definitions are text, v4/capsule/core.v4 (the core words they rest on) and v4/capsule/input.v4, assembled by the text assembler, which can now read a file. EXPECT, QUERY, WORD and ENCLOSE behave as v3's. CONVERT and NUMBER are FORTH-79 (ruled 2026-10-04): any BASE, a double in the standard order, and NUMBER returns a signed double or sets NODE-ERROR. Executed at both cell widths against C and against values recorded from the v3 binary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
31fcdcd0a3
commit
443439c3d2
@@ -394,6 +394,35 @@ int v4_text_assemble(v4_text *t, const char *source)
|
||||
return !t->failed;
|
||||
}
|
||||
|
||||
int v4_text_assemble_file(v4_text *t, const char *path)
|
||||
{
|
||||
const char *base = strrchr(path, '/');
|
||||
char *text = NULL, was[sizeof t->message];
|
||||
long size = 0;
|
||||
FILE *f;
|
||||
|
||||
if (t->failed) return 0;
|
||||
base = base ? base + 1 : path;
|
||||
f = fopen(path, "rb");
|
||||
if (f && fseek(f, 0, SEEK_END) == 0 && (size = ftell(f)) >= 0 && fseek(f, 0, SEEK_SET) == 0)
|
||||
text = malloc((size_t)size + 1u);
|
||||
if (!text || fread(text, 1, (size_t)size, f) != (size_t)size) {
|
||||
if (f) fclose(f);
|
||||
free(text);
|
||||
t->line = 0;
|
||||
fail(t, "cannot read", path);
|
||||
return 0;
|
||||
}
|
||||
fclose(f);
|
||||
text[size] = 0;
|
||||
if (!v4_text_assemble(t, text)) {
|
||||
memcpy(was, t->message, sizeof was);
|
||||
snprintf(t->message, sizeof t->message, "%.40s, %.170s", base, was);
|
||||
}
|
||||
free(text);
|
||||
return !t->failed;
|
||||
}
|
||||
|
||||
int v4_text_finish(v4_text *t)
|
||||
{
|
||||
if (t->failed) return 0;
|
||||
|
||||
Reference in New Issue
Block a user