kuroko/vm.h

58 lines
1.2 KiB
C
Raw Normal View History

#pragma once
#include "kuroko.h"
#include "value.h"
#include "table.h"
#include "object.h"
#define FRAMES_MAX 64
typedef struct {
KrkClosure * closure;
uint8_t * ip;
size_t slots;
} CallFrame;
typedef enum {
METHOD_INIT,
METHOD_STR,
METHOD__MAX,
} KrkSpecialMethods;
typedef struct {
CallFrame frames[FRAMES_MAX];
size_t frameCount;
size_t stackSize;
KrkValue * stack;
KrkValue * stackTop;
2020-12-26 10:53:15 +03:00
KrkTable globals;
KrkTable strings;
KrkTable modules;
KrkUpvalue * openUpvalues;
KrkObj * objects;
size_t bytesAllocated;
size_t nextGC;
size_t grayCount;
size_t grayCapacity;
size_t exitOnFrame;
KrkObj** grayStack;
KrkValue specialMethodNames[METHOD__MAX];
2020-12-28 05:11:50 +03:00
unsigned char enableDebugging:1;
unsigned char enableTracing:1;
unsigned char enableScanTracing:1;
unsigned char enableStressGC:1;
} KrkVM;
extern KrkVM vm;
extern void krk_initVM(void);
extern void krk_freeVM(void);
2020-12-28 04:54:25 +03:00
extern KrkValue krk_interpret(const char * src, int newScope, char *, char *);
extern KrkValue krk_runfile(const char * fileName, int newScope, char *, char *);
extern void krk_push(KrkValue value);
extern KrkValue krk_pop(void);
2020-12-28 05:11:50 +03:00
extern const char * krk_typeName(KrkValue value);
2020-12-28 05:25:42 +03:00
extern void krk_defineNative(const char * name, NativeFn function);