1
0
Fork 0
forked from fun/fun

Added a simple REPL.

This commit is contained in:
Johannes Findeisen 2025-09-14 18:42:23 +02:00
commit 3a2afdea69
3 changed files with 93 additions and 1 deletions

View file

@ -1202,4 +1202,28 @@ Bytecode *parse_file_to_bytecode(const char *path) {
free(src);
return bc;
}
Bytecode *parse_string_to_bytecode(const char *source) {
if (!source) {
fprintf(stderr, "Error: null source provided\n");
return NULL;
}
size_t len = strlen(source);
/* reset error state */
g_has_error = 0;
g_err_pos = 0;
g_err_msg[0] = '\0';
Bytecode *bc = compile_minimal(source, len);
if (g_has_error) {
int line = 1, col = 1;
calc_line_col(source, len, g_err_pos, &line, &col);
fprintf(stderr, "Parse error <input>:%d:%d: %s\n", line, col, g_err_msg);
if (bc) bytecode_free(bc);
return NULL;
}
return bc;
}