6#ifndef MJS_CORE_PUBLIC_H_
7#define MJS_CORE_PUBLIC_H_
9#if !defined(_MSC_VER) || _MSC_VER >= 1700
12typedef unsigned __int64 uint64_t;
14typedef unsigned char uint8_t;
18#include "mjs_features.h"
20#if defined(__cplusplus)
24#ifndef MJS_ENABLE_DEBUG
25#define MJS_ENABLE_DEBUG 0
56typedef uint64_t mjs_val_t;
65#define MAKE_TAG(s, t) ((uint64_t)(s) << 63 | (uint64_t)0x7ff0 << 48 | (uint64_t)(t) << 48)
67#define MJS_TAG_OBJECT MAKE_TAG(1, 1)
68#define MJS_TAG_FOREIGN MAKE_TAG(1, 2)
69#define MJS_TAG_UNDEFINED MAKE_TAG(1, 3)
70#define MJS_TAG_BOOLEAN MAKE_TAG(1, 4)
71#define MJS_TAG_NAN MAKE_TAG(1, 5)
72#define MJS_TAG_STRING_I MAKE_TAG(1, 6)
73#define MJS_TAG_STRING_5 MAKE_TAG(1, 7)
74#define MJS_TAG_STRING_O MAKE_TAG(1, 8)
75#define MJS_TAG_STRING_F MAKE_TAG(1, 9)
76#define MJS_TAG_STRING_C MAKE_TAG(1, 10)
77#define MJS_TAG_STRING_D MAKE_TAG(1, 11)
78#define MJS_TAG_ARRAY MAKE_TAG(1, 12)
79#define MJS_TAG_FUNCTION MAKE_TAG(1, 13)
80#define MJS_TAG_FUNCTION_FFI MAKE_TAG(1, 14)
81#define MJS_TAG_NULL MAKE_TAG(1, 15)
83#define MJS_TAG_ARRAY_BUF MAKE_TAG(0, 1)
84#define MJS_TAG_ARRAY_BUF_VIEW MAKE_TAG(0, 2)
86#define MJS_TAG_MASK MAKE_TAG(1, 15)
107 MJS_TYPE_ARRAY_BUF_VIEW,
110 MJS_TYPE_OBJECT_GENERIC,
111 MJS_TYPE_OBJECT_ARRAY,
112 MJS_TYPE_OBJECT_FUNCTION,
120typedef enum mjs_err {
127 MJS_NOT_IMPLEMENTED_ERROR,
136typedef void (*mjs_flags_poller_t)(
struct mjs*
mjs);
141struct mjs* mjs_create(
void* context);
144void mjs_destroy(
struct mjs*
mjs);
146mjs_val_t mjs_get_global(
struct mjs*
mjs);
215void mjs_own(
struct mjs*
mjs, mjs_val_t* v);
222int mjs_disown(
struct mjs*
mjs, mjs_val_t* v);
224mjs_err_t mjs_set_errorf(
struct mjs*
mjs, mjs_err_t err,
const char* fmt, ...);
226void mjs_exit(
struct mjs*
mjs);
228void mjs_set_exec_flags_poller(
struct mjs*
mjs, mjs_flags_poller_t poller);
230void* mjs_get_context(
struct mjs*
mjs);
239mjs_err_t mjs_prepend_errorf(
struct mjs*
mjs, mjs_err_t err,
const char* fmt, ...);
246void mjs_print_error(
struct mjs*
mjs, FILE* fp,
const char* msg,
int print_stack_trace);
252const char* mjs_strerror(
struct mjs*
mjs,
enum mjs_err err);
254const char* mjs_get_stack_trace(
struct mjs*
mjs);
263void mjs_set_generate_jsc(
struct mjs*
mjs,
int generate_jsc);
269int mjs_nargs(
struct mjs*
mjs);
275mjs_val_t mjs_arg(
struct mjs*
mjs,
int n);
280void mjs_return(
struct mjs*
mjs, mjs_val_t v);
282#if defined(__cplusplus)