forked from ground/ground
Stuff
This commit is contained in:
@@ -150,7 +150,20 @@ GroundValue groundRunFunction(GroundFunction* function, size_t argc, ...) {
|
||||
va_list args;
|
||||
va_start(args, argc);
|
||||
|
||||
GroundScope callScope = copyGroundScope(&function->closure);
|
||||
if (function == NULL) {
|
||||
return createErrorGroundValue(createGroundError("Null function passed to groundRunFunction", "valueError", NULL, NULL));
|
||||
}
|
||||
|
||||
// Seems to crash some functions
|
||||
// GroundScope callScope = copyGroundScope(&function->closure);
|
||||
|
||||
GroundScope callScope = {
|
||||
.labels = malloc(sizeof(GroundLabel*)),
|
||||
.variables = malloc(sizeof(GroundVariable*)),
|
||||
.isMainScope = false
|
||||
};
|
||||
*callScope.variables = NULL;
|
||||
*callScope.labels = NULL;
|
||||
|
||||
if (argc != function->argSize) {
|
||||
return createErrorGroundValue(createGroundError("Too few or too many arguments for function", "callError", NULL, NULL));
|
||||
|
||||
14
src/types.c
14
src/types.c
@@ -2,6 +2,20 @@
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
static char out_buf[65536];
|
||||
static int out_pos = 0;
|
||||
|
||||
void wasm_print(const char* str) {
|
||||
int len = strlen(str);
|
||||
if (out_pos + len < (int)sizeof(out_buf) - 1) {
|
||||
memcpy(out_buf + out_pos, str, len);
|
||||
out_pos += len;
|
||||
out_buf[out_pos] = '\0';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
GroundValue createIntGroundValue(int64_t in) {
|
||||
GroundValue gv;
|
||||
gv.data.intVal = in;
|
||||
|
||||
18
src/types.h
18
src/types.h
@@ -10,6 +10,24 @@
|
||||
|
||||
#define MAX_ID_LEN 64
|
||||
|
||||
// If targeting WASM, define WASM specific stuff
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
|
||||
void wasm_print(const char* str);
|
||||
|
||||
#undef printf
|
||||
#define printf(fmt, ...) do { \
|
||||
int __needed = snprintf(NULL, 0, fmt, ##__VA_ARGS__) + 1; \
|
||||
char* __buf = malloc(__needed); \
|
||||
if (__buf) { \
|
||||
snprintf(__buf, __needed, fmt, ##__VA_ARGS__); \
|
||||
wasm_print(__buf); \
|
||||
free(__buf); \
|
||||
} \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
typedef enum GroundInstType {
|
||||
IF, JUMP, END, INPUT, PRINT, PRINTLN, SET, GETTYPE, EXISTS, SETLIST, SETLISTAT, GETLISTAT, GETLISTSIZE, LISTAPPEND, GETSTRSIZE, GETSTRCHARAT, ADD, SUBTRACT, MULTIPLY, DIVIDE, EQUAL, INEQUAL, NOT, GREATER, LESSER, STOI, STOD, ITOC, CTOI, TOSTRING, FUN, RETURN, ENDFUN, PUSHARG, CALL, STRUCT, ENDSTRUCT, INIT, GETFIELD, SETFIELD, USE, EXTERN, CREATELABEL, PAUSE, DROP, ERRORCMD
|
||||
} GroundInstType;
|
||||
|
||||
Reference in New Issue
Block a user