feat+fix: make compiler STRONGAAA

- FEAT: add source code length field in `fzl_reader_t` struct
- FIX: check name, lpair (lparen) and rpair (rparen) when lexing call
- FIX: check string literal termination
- FIX: increment position even on empty string to prevent infinite
lexing loop
- FIX: add string terminator in `fzl_mktoken` when allocating space for
string value
- FIX: add check for errors in recursevly called `walk`
- FIX: change source code holder from stack-stored `char[8192]` to
dynamically allocated with actual file size holder
- FIX: correct constant hasing util to hash actual string value instead
of link
This commit is contained in:
samsonium
2026-10-10 21:03:23 +03:00
parent f49a54c878
commit 1db985ecb5
7 changed files with 47 additions and 14 deletions
+7 -2
View File
@@ -102,7 +102,7 @@ int main(int argc, char **argv)
if (args->verbose)
printf("> analyze\n-> reading file...");
char source[8192];
char *source;
FILE *fd = fopen(args->filepath, "r");
if (!fd)
{
@@ -114,11 +114,15 @@ int main(int argc, char **argv)
size_t fsz = ftell(fd);
rewind(fd);
source = malloc(fsz + 1);
fread(source, fsz, 1, fd);
fclose(fd);
source[fsz] = '\0';
if (args->verbose)
{
printf("ok!\n");
printf("--> Red %ld bytes\n", fsz);
printf("-> tokenizing...");
}
@@ -218,10 +222,11 @@ int main(int argc, char **argv)
if (args->verbose)
printf("ok!\n");
free(source);
free(args);
fzl_freereader(rd);
fzl_freeparser(parser);
fzl_freeast(parser->root);
fzl_freeparser(parser);
fzl_freewalker(walker);
fzl_freewriter(writer);