summaryrefslogtreecommitdiff
path: root/src/fype.c
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-28 16:15:57 +0200
committerPaul Buetow <paul@buetow.org>2026-02-28 16:15:57 +0200
commit2a2227d529f3788b8e08752d37deb1a449f3b9bc (patch)
tree09a840230ca824a3df5491a3cc9263b72955f1a9 /src/fype.c
parent5f557ebafb596755cb3047cbdafa6122166c26ac (diff)
Clean up scanner_run() and interpret_run(): narrow signatures, fix SoC [SoC/DIP]
Three issues resolved: 1. scanner_run() no longer takes Fype*. New signature: scanner_run(List*, Tupel*, char **c_filename_out) Verbose-mode list_iterate() and basename extraction moved to fype_run() (the composition root), leaving scanner_run() as pure tokenizer: open source -> tokenize -> post-process -> return filename. 2. interpret_run() no longer takes Fype*. New signature: interpret_run(List *p_list_token, Hash *p_hash_syms) Fype* unpacking happens in fype_run(); interpret.h no longer includes fype.h. scanner.h no longer includes fype.h either. 3. _CODESTR_INDEX file-global (which made the scanner non-reentrant) moved into the Scanner struct as i_codestr_index, initialized to 0 in scanner_new(). _scanner_has_next_char() and _scanner_get_next_char() use p_scanner->i_codestr_index instead. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/fype.c')
-rw-r--r--src/fype.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/fype.c b/src/fype.c
index ebd906d..681a48c 100644
--- a/src/fype.c
+++ b/src/fype.c
@@ -35,7 +35,10 @@
#include "fype.h"
+#include <string.h>
+
#include "argv.h"
+#include "core/token.h"
#include "core/garbage.h"
#include "core/interpret.h"
#include "core/scanner.h"
@@ -80,11 +83,24 @@ fype_run(int i_argc, char **pc_argv) {
// argv: Maintains command line options
argv_run(p_fype, i_argc, pc_argv);
- // scanner: Creates a list of token
- scanner_run(p_fype);
+ // scanner: Tokenise source into the token list
+ char *c_filename = NULL;
+ scanner_run(p_fype->p_list_token, p_fype->p_tupel_argv, &c_filename);
+
+ // Verbose mode: print the token list after scanning
+ if (argv_checkopts("TV", p_fype->p_tupel_argv))
+ list_iterate(p_fype->p_list_token, token_print_cb);
+
+ // Derive the script basename (filename minus the .fy extension)
+ if (c_filename) {
+ int i_len = strlen(c_filename) - 3;
+ p_fype->c_basename = calloc(i_len + 1, sizeof(char));
+ strncpy(p_fype->c_basename, c_filename, i_len);
+ p_fype->c_basename[i_len] = 0;
+ }
// interpret: Interpret the list of token
- interpret_run(p_fype);
+ interpret_run(p_fype->p_list_token, p_fype->p_hash_syms);
fype_delete(p_fype);