Sfoglia il codice sorgente

added more control to ink_compile

main
Ludovic 'Archivist' Lagouardette 4 mesi fa
parent
commit
d3b58a1d84
2 ha cambiato i file con 8 aggiunte e 7 eliminazioni
  1. +2
    -1
      include/ink.h
  2. +6
    -6
      lib.c

+ 2
- 1
include/ink.h Vedi File

@ -249,8 +249,9 @@ int ink_step_everyone(struct context *pContext);
* Compiles the code and starts a main routine to execute it
* @param pContext The context to execute the code in
* @param buffer The buffer that contains the source as a NULL terminated string
* @return the routine that was created when compiling the code or -1 in case an error occured
*/
void ink_compile(struct context *pContext, const char *buffer);
int ink_compile(struct context *pContext, const char *buffer);
/**
* Includes the standard library in the specified context

+ 6
- 6
lib.c Vedi File

@ -778,7 +778,7 @@ int ink_step(struct context *pContext) {
return 1;
}
void ink_compile(struct context *pContext, const char* buffer) {
int ink_compile(struct context *pContext, const char* buffer) {
int routine, saved, executable_buffer_top;
/* Main function has a size limit of 256 (need to know that for REPL */
struct elem executable_buffer[256];
@ -799,13 +799,13 @@ void ink_compile(struct context *pContext, const char* buffer) {
err = ink_lex(pContext, buffer);
if(err < 0) {
pContext->panic = 1;
return;
return -1;
}
executable_buffer_top = 0;
err = ink_parse(pContext, executable_buffer, &executable_buffer_top);
if(err < 0) {
pContext->panic = 1;
return;
return -1;
}
if(executable_buffer_top != 0) {
integer = ink_itoa(pContext, routine);
@ -816,7 +816,7 @@ void ink_compile(struct context *pContext, const char* buffer) {
frame.executing.value = ink_add_indigenous(pContext, main_fn, executable_buffer, executable_buffer_top);
if (frame.executing.value < 0) {
pContext->panic = 1;
return;
return -1;
}
frame.executing.type = INK_FUNCTION;
frame.index = 0;
@ -824,14 +824,14 @@ void ink_compile(struct context *pContext, const char* buffer) {
pContext->routines[pContext->routine_current].top = 0;
if (err < 0) {
pContext->panic = 1;
return;
return -1;
}
} else {
pContext->routines[pContext->routine_current].panic = INK_ROUTINE_SUCCESS;
}
pContext->routine_current = saved;
return;
return routine;
}
int ink_can_run(struct context* pContext) {

Caricamento…
Annulla
Salva