Cosmo/src/cosmo.h

68 lines
1.9 KiB
C
Raw Normal View History

2020-10-28 05:16:30 +00:00
#ifndef COSMOMAIN_H
#define COSMOMAIN_H
2023-02-09 18:32:48 +00:00
#include <assert.h>
#include <stdbool.h>
2020-10-28 05:16:30 +00:00
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
2023-02-09 18:32:48 +00:00
#include <stdlib.h>
2020-10-28 05:16:30 +00:00
2023-02-09 18:32:48 +00:00
/*
2021-01-04 22:20:05 +00:00
SAFE_STACK:
2023-02-09 18:32:48 +00:00
if undefined, the stack will not be checked for stack overflows. This may improve
performance, however this will produce undefined behavior as you reach the stack limit (and may
cause a seg fault!). It is recommended to keep this enabled.
2021-01-04 22:20:05 +00:00
*/
// #define SAFE_STACK
/*
NAN_BOXXED:
if undefined, the interpreter will use a tagged union to store values. This is the default.
Note that even though the sizeof(CValue) is 8 bytes for NAN_BOXXED (as opposed to 16 bytes for
the tagged union) no performance benefits were measured. I recommend keeping this undefined for
now.
*/
2023-02-09 18:32:48 +00:00
// #define NAN_BOXXED
2020-10-28 05:16:30 +00:00
// forward declare *most* stuff so our headers are cleaner
typedef struct CState CState;
typedef struct CChunk CChunk;
2021-02-15 22:20:04 +00:00
typedef struct CCallFrame CCallFrame;
#ifdef NAN_BOXXED
typedef union CValue CValue;
#else
2020-10-28 05:16:30 +00:00
typedef struct CValue CValue;
#endif
2020-10-28 05:16:30 +00:00
2021-02-15 22:20:04 +00:00
typedef struct CValueArray CValueArray;
typedef uint32_t cosmo_Flag;
2020-10-28 05:16:30 +00:00
// objs
typedef struct CObj CObj;
2021-03-20 06:44:03 +00:00
typedef struct CObjObject CObjObject;
2020-10-28 05:16:30 +00:00
typedef struct CObjString CObjString;
typedef struct CObjUpval CObjUpval;
typedef struct CObjFunction CObjFunction;
typedef struct CObjCFunction CObjCFunction;
typedef struct CObjMethod CObjMethod;
typedef struct CObjError CObjError;
typedef struct CObjTable CObjTable;
2020-10-28 05:16:30 +00:00
typedef struct CObjClosure CObjClosure;
typedef uint8_t INSTRUCTION;
typedef int (*cosmo_Reader)(CState *state, void *data, size_t size, const void *ud);
typedef int (*cosmo_Writer)(CState *state, const void *data, size_t size, const void *ud);
2020-10-28 05:16:30 +00:00
#define COSMOMAX_UPVALS 80
#define FRAME_MAX 64
#define STACK_MAX (256 * FRAME_MAX)
2020-10-28 05:16:30 +00:00
#define COSMO_API extern
#define UNNAMEDCHUNK "_main"
#define COSMOASSERT(x) assert(x)
2020-10-28 05:16:30 +00:00
2021-01-02 05:06:24 +00:00
#endif