Cosmo/src/cvm.h

48 lines
1.5 KiB
C
Raw Normal View History

2020-10-28 05:16:30 +00:00
#ifndef COSMOVM_H
#define COSMOVM_H
2020-11-12 23:17:41 +00:00
#include <string.h>
2020-10-28 05:16:30 +00:00
#include "cosmo.h"
#include "cstate.h"
typedef enum {
COSMOVM_OK,
COSMOVM_RUNTIME_ERR,
COSMOVM_BUILDTIME_ERR
} COSMOVMRESULT;
// args = # of pass parameters, nresults = # of expected results
COSMO_API COSMOVMRESULT cosmoV_call(CState *state, int args, int nresults);
2020-12-05 23:55:09 +00:00
COSMO_API void cosmoV_makeObject(CState *state, int pairs);
COSMO_API void cosmoV_makeDictionary(CState *state, int pairs);
2020-11-13 05:04:09 +00:00
COSMO_API bool cosmoV_getObject(CState *state, CObjObject *object, CValue key, CValue *val);
2020-11-13 18:54:06 +00:00
COSMO_API void cosmoV_error(CState *state, const char *format, ...);
2020-11-12 23:17:41 +00:00
// nice to have wrappers
// pushes a cosmo_Number to the stack
static inline void cosmoV_pushNumber(CState *state, cosmo_Number num) {
cosmoV_pushValue(state, cosmoV_newNumber(num));
}
// pushes a boolean to the stack
static inline void cosmoV_pushBoolean(CState *state, bool b) {
cosmoV_pushValue(state, cosmoV_newBoolean(b));
}
// pushes a C Function to the stack
static inline void cosmoV_pushCFunction(CState *state, CosmoCFunction func) {
cosmoV_pushValue(state, cosmoV_newObj(cosmoO_newCFunction(state, func)));
}
static inline void cosmoV_pushLString(CState *state, const char *str, size_t len) {
cosmoV_pushValue(state, cosmoV_newObj(cosmoO_copyString(state, str, len)));
}
// accepts a null terminated string and copys the buffer to the VM heap
static inline void cosmoV_pushString(CState *state, const char *str) {
cosmoV_pushLString(state, str, strlen(str));
}
2020-10-28 05:16:30 +00:00
#endif