2020-10-28 05:16:30 +00:00
|
|
|
#ifndef COSMOMAIN_H
|
|
|
|
#define COSMOMAIN_H
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2020-12-27 19:36:17 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2021-01-04 22:20:05 +00:00
|
|
|
/*
|
|
|
|
SAFE_STACK:
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
#define SAFE_STACK
|
2020-12-04 06:04:14 +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;
|
|
|
|
|
2020-12-04 06:04:14 +00:00
|
|
|
#ifdef NAN_BOXXED
|
|
|
|
typedef union CValue CValue;
|
|
|
|
#else
|
2020-10-28 05:16:30 +00:00
|
|
|
typedef struct CValue CValue;
|
2020-12-04 06:04:14 +00:00
|
|
|
#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;
|
|
|
|
typedef struct CObjString CObjString;
|
|
|
|
typedef struct CObjUpval CObjUpval;
|
|
|
|
typedef struct CObjFunction CObjFunction;
|
|
|
|
typedef struct CObjCFunction CObjCFunction;
|
2020-11-10 01:44:12 +00:00
|
|
|
typedef struct CObjMethod CObjMethod;
|
Added CObjError, cosmoV_throw(), pcall(), and cosmoV_printError()
Errors are now handled very differently, parser errors and VM errors are now treated the same.
When cosmoV_error is called, cosmoV_throw is also called, which formats the error object and sets the panic state.
state->error now points to the latest CObjError when state->panic is true. To get a nice formatted Objection message, use
cosmoV_printError() and pass the state->error. pcall() was added to the standard base library. When called, the first argument
passed is called with the subsequent arguments given. If the call completed successfully, `true`,`nil` is returned. However
when an error occurs during the call, `false`,`<error>` is returned. Simply print the `<error>` to retrieve the error string.
2021-01-06 04:27:59 +00:00
|
|
|
typedef struct CObjError CObjError;
|
2020-11-17 01:58:16 +00:00
|
|
|
typedef struct CObjObject CObjObject;
|
2021-01-25 22:14:51 +00:00
|
|
|
typedef struct CObjTable CObjTable;
|
2020-10-28 05:16:30 +00:00
|
|
|
typedef struct CObjClosure CObjClosure;
|
|
|
|
|
|
|
|
typedef uint8_t INSTRUCTION;
|
|
|
|
|
|
|
|
#define COSMOMAX_UPVALS 80
|
2021-02-07 20:00:00 +00:00
|
|
|
#define FRAME_MAX 64
|
|
|
|
#define STACK_MAX (256 * FRAME_MAX)
|
2020-10-28 05:16:30 +00:00
|
|
|
|
2021-02-07 20:00:00 +00:00
|
|
|
#define COSMO_API extern
|
|
|
|
#define UNNAMEDCHUNK "_main"
|
|
|
|
#define COSMOASSERT(x) assert(x)
|
2020-10-28 05:16:30 +00:00
|
|
|
|
|
|
|
#define CERROR(err) \
|
|
|
|
printf("%s : %s\n", "[ERROR]", err)
|
|
|
|
|
2021-01-02 05:06:24 +00:00
|
|
|
#endif
|