Skip to content

Commit

Permalink
Improvements to kilo REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
danielinux authored and jaromil committed Oct 1, 2024
1 parent ef0af4c commit d0351d3
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 36 deletions.
22 changes: 15 additions & 7 deletions src/cjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ static int cjit_compile_and_run(TCCState *TCC, const char *code, int argc, char
const char main_fn[]="main";
int err_fds[2];
int err_r, err_w;
const char compile_errmsg[]= "Code compilation error in source\n";
const char reloc_errmsg[]= "Code relocation error in source\n";
const char nomain_errmsg[]= "Symbol 'main' was not found in source\n";
const char compile_errmsg[]= "Code compilation error in source";
const char reloc_errmsg[]= "Code relocation error in source";
const char nomain_errmsg[]= "Symbol 'main' was not found in source";


*err_msg = NULL;
Expand Down Expand Up @@ -201,7 +201,7 @@ static void error_callback(void *ctx, const char *msg)
}
}

#define ERR_MAX 128
#define ERR_MAX 80
static int cjit_check_buffer(void *tcs, char *code, char **err_msg)
{
TCCState *TCC = (TCCState *)tcs;
Expand All @@ -212,6 +212,9 @@ static int cjit_check_buffer(void *tcs, char *code, char **err_msg)
res = cjit_compile_and_run(TCC, code, 0, NULL, 0, err_msg);
if (res != 0) {
if(err_msg) {
if (strlen(err_msg) > ERR_MAX -1) {
err_msg[ERR_MAX - 1] = 0;
}
char *p = strchr(err_msg, '\n');
if (p) *p = 0;
editorSetStatusMessage(*err_msg);
Expand Down Expand Up @@ -255,7 +258,15 @@ static int cjit_cli(TCCState *TCC)
if (err_msg)
_err(err_msg);
} else {
int row = 0;
initEditor();

editorInsertRow(row++, "#include <stdio.h>", 18);
editorInsertRow(row++, "#include <stdlib.h>", 19);
editorInsertRow(row++, "", 0);
editorInsertRow(row++, "int main(int argc, char **argv) {", 33);
editorInsertRow(row++, "", 0);
editorInsertRow(row++, "}", 1);
enableRawMode(STDIN_FILENO);
editorSetStatusMessage(
"HELP: Ctrl-S = save | Ctrl-Q = quit | Ctrl-F = find | Ctrl-R Run");
Expand Down Expand Up @@ -854,9 +865,6 @@ int main(int argc, char **argv) {
if(! write_to_file(tmpdir,"libtcc1.a",(char*)&libtcc1,libtcc1_len) )
goto endgame;

//// TCC DEFAULT PATHS
tcc_add_include_path(TCC,"/usr/include/x86_64-linux-musl");


#if defined(LIBC_MUSL)
if(! write_to_file(tmpdir,"libc.so",(char*)&musl_libc,musl_libc_len) )
Expand Down
Loading

0 comments on commit d0351d3

Please sign in to comment.