Add #native #3
@ -3,6 +3,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "execute.h"
|
||||
@ -470,6 +471,38 @@ void execute(Stack *stack, Stack *originstack, char *modname)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Native
|
||||
|
||||
if (!strcmp(NAME, "native"))
|
||||
{
|
||||
char *modulename = malloc(strlen(ARG) + 7 * sizeof(char));
|
||||
strcpy(modulename, "./");
|
||||
strcat(modulename, ARG);
|
||||
#ifdef _WIN32
|
||||
strcat(modulename, ".dll");
|
||||
#else
|
||||
strcat(modulename, ".so");
|
||||
#endif
|
||||
void *module = dlopen(modulename, RTLD_NOW);
|
||||
|
||||
if (!module)
|
||||
kms(stack, "UNABLE TO OPEN DYNAMIC LIBRARY");
|
||||
|
||||
int (*labashka)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size );
|
||||
labashka = (int (*)(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size ))dlsym(module, "labashka");
|
||||
|
||||
|
||||
stack_init_callback(stack);
|
||||
|
||||
labashka(stack_pop_callback, stack_push_callback, stack_len_callback, stack->stacksize);
|
||||
|
||||
dlclose(module);
|
||||
|
||||
free(modulename);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Self-modifying
|
||||
|
||||
if (!strcmp(NAME, "insert")) // arg <const>
|
||||
|
22
src/stack.c
22
src/stack.c
@ -98,3 +98,25 @@ void parse_and_process(Stack *stack, FILE *file)
|
||||
stack->program[stack->program_size++] = (Instruction){duppedname, duppedarg, inst.data};
|
||||
}
|
||||
}
|
||||
|
||||
Stack *stack_callback_pointer;
|
||||
|
||||
void stack_init_callback(Stack *stack)
|
||||
{
|
||||
stack_callback_pointer = stack;
|
||||
}
|
||||
|
||||
uint16_t stack_pop_callback(void)
|
||||
{
|
||||
return stack_pop(stack_callback_pointer);
|
||||
}
|
||||
|
||||
void stack_push_callback(uint16_t number)
|
||||
{
|
||||
stack_push(stack_callback_pointer, number);
|
||||
}
|
||||
|
||||
size_t stack_len_callback(void)
|
||||
{
|
||||
return stack_callback_pointer->pointer;
|
||||
}
|
||||
|
@ -33,3 +33,11 @@ void kms(Stack *stack, const char *err);
|
||||
void parse_and_process(Stack *stack, FILE *file);
|
||||
|
||||
void repl(Stack *stack);
|
||||
|
||||
void stack_init_callback(Stack *stack);
|
||||
|
||||
uint16_t stack_pop_callback(void);
|
||||
|
||||
void stack_push_callback(uint16_t number);
|
||||
|
||||
size_t stack_len_callback(void);
|
||||
|
Loading…
Reference in New Issue
Block a user