Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to build with MJS_ENABLE_DEBUG=0 #180

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3313,8 +3313,11 @@ extern "C" {

struct mjs_bcode_part;

#if MJS_ENABLE_DEBUG
MJS_PRIVATE const char *opcodetostr(uint8_t opcode);
MJS_PRIVATE size_t mjs_disasm_single(const uint8_t *code, size_t i);
#endif

MJS_PRIVATE const char *mjs_stringify_type(enum mjs_type t);

/*
Expand Down Expand Up @@ -8552,7 +8555,9 @@ MJS_PRIVATE mjs_err_t mjs_execute(struct mjs *mjs, size_t off, mjs_val_t *res) {
#endif

code = (const uint8_t *) bp.data.p;
#if MJS_ENABLE_DEBUG
mjs_disasm_single(code, i);
#endif
prev_opcode = opcode;
opcode = code[i];
switch (opcode) {
Expand Down Expand Up @@ -8964,7 +8969,9 @@ MJS_PRIVATE mjs_err_t mjs_exec_internal(struct mjs *mjs, const char *path,
size_t off = mjs->bcode_len;
mjs_val_t r = MJS_UNDEFINED;
mjs->error = mjs_parse(path, src, mjs);
#if MJS_ENABLE_DEBUG
if (cs_log_level >= LL_VERBOSE_DEBUG) mjs_dump(mjs, 1);
#endif
if (generate_jsc == -1) generate_jsc = mjs->generate_jsc;
if (mjs->error == MJS_OK) {
#if MJS_GENERATE_JSC && defined(CS_MMAP)
Expand Down Expand Up @@ -14163,6 +14170,8 @@ void mjs_dump(struct mjs *mjs, int do_disasm) {
LOG(LL_VERBOSE_DEBUG, ("------- MJS VM DUMP END"));
}

#endif

MJS_PRIVATE int mjs_check_arg(struct mjs *mjs, int arg_num,
const char *arg_name, enum mjs_type expected_type,
mjs_val_t *parg) {
Expand Down Expand Up @@ -14286,5 +14295,3 @@ int mjs_get_offset_by_call_frame_num(struct mjs *mjs, int cf_num) {
}
return ret;
}

#endif
8 changes: 6 additions & 2 deletions mjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ typedef unsigned char uint8_t;
extern "C" {
#endif /* __cplusplus */

#define MJS_ENABLE_DEBUG 1
#ifndef MJS_ENABLE_DEBUG
#define MJS_ENABLE_DEBUG 0
#endif

/*
* Double-precision floating-point number, IEEE 754
Expand Down Expand Up @@ -385,7 +387,9 @@ typedef unsigned char uint8_t;
extern "C" {
#endif /* __cplusplus */

#define MJS_ENABLE_DEBUG 1
#ifndef MJS_ENABLE_DEBUG
#define MJS_ENABLE_DEBUG 0
#endif

/*
* Double-precision floating-point number, IEEE 754
Expand Down
14 changes: 9 additions & 5 deletions mjs_no_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ typedef unsigned char uint8_t;
extern "C" {
#endif /* __cplusplus */

#define MJS_ENABLE_DEBUG 1
#ifndef MJS_ENABLE_DEBUG
#define MJS_ENABLE_DEBUG 0
#endif

/*
* Double-precision floating-point number, IEEE 754
Expand Down Expand Up @@ -4651,7 +4653,9 @@ MJS_PRIVATE mjs_err_t mjs_exec_internal(struct mjs *mjs, const char *path,
size_t off = mjs->bcode_len;
mjs_val_t r = MJS_UNDEFINED;
mjs->error = mjs_parse(path, src, mjs);
#if MJS_ENABLE_DEBUG
if (cs_log_level >= LL_VERBOSE_DEBUG) mjs_dump(mjs, 1);
#endif
if (generate_jsc == -1) generate_jsc = mjs->generate_jsc;
if (mjs->error == MJS_OK) {
#if MJS_GENERATE_JSC && defined(CS_MMAP)
Expand Down Expand Up @@ -9639,8 +9643,6 @@ void mjs_fprintf(mjs_val_t v, struct mjs *mjs, FILE *fp) {
mjs_jprintf(v, mjs, &out);
}

#if MJS_ENABLE_DEBUG

MJS_PRIVATE const char *opcodetostr(uint8_t opcode) {
static const char *names[] = {
"NOP", "DROP", "DUP", "SWAP", "JMP", "JMP_TRUE", "JMP_NEUTRAL_TRUE",
Expand Down Expand Up @@ -9819,6 +9821,8 @@ void mjs_disasm(const uint8_t *code, size_t len) {
}
}

#if MJS_ENABLE_DEBUG

static void mjs_dump_obj_stack(const char *name, const struct mbuf *m,
struct mjs *mjs) {
char buf[50];
Expand Down Expand Up @@ -9850,6 +9854,8 @@ void mjs_dump(struct mjs *mjs, int do_disasm) {
LOG(LL_VERBOSE_DEBUG, ("------- MJS VM DUMP END"));
}

#endif

MJS_PRIVATE int mjs_check_arg(struct mjs *mjs, int arg_num,
const char *arg_name, enum mjs_type expected_type,
mjs_val_t *parg) {
Expand Down Expand Up @@ -9973,5 +9979,3 @@ int mjs_get_offset_by_call_frame_num(struct mjs *mjs, int cf_num) {
}
return ret;
}

#endif
4 changes: 3 additions & 1 deletion src/mjs_core_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ typedef unsigned char uint8_t;
extern "C" {
#endif /* __cplusplus */

#define MJS_ENABLE_DEBUG 1
#ifndef MJS_ENABLE_DEBUG
#define MJS_ENABLE_DEBUG 0
#endif

/*
* Double-precision floating-point number, IEEE 754
Expand Down
4 changes: 4 additions & 0 deletions src/mjs_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,9 @@ MJS_PRIVATE mjs_err_t mjs_execute(struct mjs *mjs, size_t off, mjs_val_t *res) {
#endif

code = (const uint8_t *) bp.data.p;
#if MJS_ENABLE_DEBUG
mjs_disasm_single(code, i);
#endif
prev_opcode = opcode;
opcode = code[i];
switch (opcode) {
Expand Down Expand Up @@ -996,7 +998,9 @@ MJS_PRIVATE mjs_err_t mjs_exec_internal(struct mjs *mjs, const char *path,
size_t off = mjs->bcode_len;
mjs_val_t r = MJS_UNDEFINED;
mjs->error = mjs_parse(path, src, mjs);
#if MJS_ENABLE_DEBUG
if (cs_log_level >= LL_VERBOSE_DEBUG) mjs_dump(mjs, 1);
#endif
if (generate_jsc == -1) generate_jsc = mjs->generate_jsc;
if (mjs->error == MJS_OK) {
#if MJS_GENERATE_JSC && defined(CS_MMAP)
Expand Down
4 changes: 2 additions & 2 deletions src/mjs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ void mjs_dump(struct mjs *mjs, int do_disasm) {
LOG(LL_VERBOSE_DEBUG, ("------- MJS VM DUMP END"));
}

#endif

MJS_PRIVATE int mjs_check_arg(struct mjs *mjs, int arg_num,
const char *arg_name, enum mjs_type expected_type,
mjs_val_t *parg) {
Expand Down Expand Up @@ -427,5 +429,3 @@ int mjs_get_offset_by_call_frame_num(struct mjs *mjs, int cf_num) {
}
return ret;
}

#endif
3 changes: 3 additions & 0 deletions src/mjs_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ extern "C" {

struct mjs_bcode_part;

#if MJS_ENABLE_DEBUG
MJS_PRIVATE const char *opcodetostr(uint8_t opcode);
MJS_PRIVATE size_t mjs_disasm_single(const uint8_t *code, size_t i);
#endif

MJS_PRIVATE const char *mjs_stringify_type(enum mjs_type t);

/*
Expand Down