Add "call"
This commit is contained in:
parent
55ea69b4b4
commit
d9b8904f88
@ -481,6 +481,47 @@ void execute(Stack *stack, Stack *originstack, char *modname)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp(NAME, "call"))
|
||||
{
|
||||
|
||||
unsigned short len = stack_pop(stack);
|
||||
char *string = calloc(len, sizeof(char));
|
||||
|
||||
for (int i = len - 1; i != -1; i--)
|
||||
string[i] = stack_pop(stack);
|
||||
|
||||
if (!strcmp(string, modname))
|
||||
{
|
||||
printf("MODULE %s: CAN'T EXECUTE ITSELF\n", string);
|
||||
kms(stack, "CAN'T EXECUTE ITSELF");
|
||||
}
|
||||
|
||||
FILE *file = fopen(string, "r");
|
||||
if (!file)
|
||||
{
|
||||
printf("ERROR OPENING MODULE: %s\n", string);
|
||||
kms(stack, "ERROR OPENING MODULE");
|
||||
}
|
||||
|
||||
DATA = DATA ? DATA : STACK_SIZE;
|
||||
|
||||
Stack *tempstack = program_init(DATA);
|
||||
|
||||
parse_and_process(tempstack, file);
|
||||
|
||||
fclose(file);
|
||||
|
||||
execute(tempstack, stack, string);
|
||||
|
||||
for (int i = 0; i < tempstack->pointer; i++)
|
||||
stack_push(stack, tempstack->memory[i]);
|
||||
|
||||
free(tempstack);
|
||||
free(string);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Native
|
||||
|
||||
if (!strcmp(NAME, "native"))
|
||||
|
Loading…
Reference in New Issue
Block a user