wip repl
This commit is contained in:
parent
e862b02019
commit
0ed7fc4496
21 changed files with 1267 additions and 148 deletions
55
src/pxl8.c
55
src/pxl8.c
|
|
@ -2,6 +2,7 @@
|
|||
#define PXL8_COPYRIGHT "Copyright (c) 2024-2025 pxl8.org"
|
||||
#define PXL8_VERSION "0.1.0"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
@ -122,20 +123,12 @@ pxl8_game_result pxl8_init(pxl8_game* game, i32 argc, char* argv[]) {
|
|||
if (game->script_path[0] != '\0') {
|
||||
pxl8_result result = pxl8_script_load_main(game->script, game->script_path);
|
||||
game->script_loaded = (result == PXL8_OK);
|
||||
}
|
||||
|
||||
if (game->repl_mode) {
|
||||
game->repl = pxl8_script_repl_create();
|
||||
if (game->repl) {
|
||||
pxl8_script_repl_init(game->repl);
|
||||
fprintf(stderr, "\033[38;2;184;187;38m[pxl8 REPL]\033[0m Fennel %s - Tab for completions, Ctrl-C to exit\n", "1.5.1");
|
||||
|
||||
if (pxl8_script_load_module(game->script, "pxl8") != PXL8_OK) {
|
||||
fprintf(stderr, "Warning: Failed to setup pxl8 global: %s\n", pxl8_script_get_last_error(game->script));
|
||||
}
|
||||
if (game->script_loaded && !game->repl_mode) {
|
||||
pxl8_script_call_function(game->script, "init");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
game->last_time = game->hal->get_ticks();
|
||||
game->running = true;
|
||||
|
||||
|
|
@ -156,14 +149,42 @@ pxl8_game_result pxl8_update(pxl8_game* game) {
|
|||
|
||||
pxl8_script_check_reload(game->script);
|
||||
|
||||
if (game->repl_mode && !game->repl_started) {
|
||||
if (game->script_loaded) {
|
||||
pxl8_script_call_function(game->script, "init");
|
||||
}
|
||||
|
||||
game->repl = pxl8_script_repl_create();
|
||||
if (game->repl) {
|
||||
fprintf(stderr, "\033[38;2;184;187;38m[pxl8 REPL]\033[0m Fennel %s - Tab for completions, Ctrl-D to exit\n", "1.5.1");
|
||||
|
||||
if (pxl8_script_load_module(game->script, "pxl8") != PXL8_OK) {
|
||||
fprintf(stderr, "Warning: Failed to setup pxl8 global: %s\n", pxl8_script_get_last_error(game->script));
|
||||
}
|
||||
|
||||
pxl8_script_repl_init(game->repl);
|
||||
game->repl_started = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (game->repl_mode && game->repl) {
|
||||
if (pxl8_script_repl_should_quit(game->repl)) {
|
||||
game->running = false;
|
||||
}
|
||||
|
||||
pxl8_script_repl_command* cmd = pxl8_script_repl_pop_command(game->repl);
|
||||
if (cmd) {
|
||||
pxl8_result result = pxl8_script_eval(game->script, pxl8_script_repl_command_buffer(cmd));
|
||||
pxl8_result result = pxl8_script_eval_repl(game->script, pxl8_script_repl_command_buffer(cmd));
|
||||
if (result != PXL8_OK) {
|
||||
pxl8_error("%s", pxl8_script_get_last_error(game->script));
|
||||
if (pxl8_script_is_incomplete_input(game->script)) {
|
||||
} else {
|
||||
pxl8_error("%s", pxl8_script_get_last_error(game->script));
|
||||
pxl8_script_repl_clear_accumulator(game->repl);
|
||||
}
|
||||
} else {
|
||||
pxl8_script_repl_clear_accumulator(game->repl);
|
||||
}
|
||||
pxl8_script_repl_command_free(cmd);
|
||||
pxl8_script_repl_eval_complete(game->repl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -256,13 +277,15 @@ pxl8_game_result pxl8_frame(pxl8_game* game) {
|
|||
void pxl8_quit(pxl8_game* game) {
|
||||
if (!game) return;
|
||||
|
||||
pxl8_info("Shutting down");
|
||||
|
||||
if (game->repl_mode && game->repl) {
|
||||
fprintf(stderr, "\r\033[K");
|
||||
fflush(stderr);
|
||||
pxl8_script_repl_shutdown(game->repl);
|
||||
pxl8_script_repl_destroy(game->repl);
|
||||
}
|
||||
|
||||
pxl8_info("Shutting down");
|
||||
|
||||
if (game->cart) {
|
||||
pxl8_cart_unload(game->cart);
|
||||
free(game->cart);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue