Loading...
Searching...
No Matches
mjs_util.h
1/*
2 * Copyright (c) 2016 Cesanta Software Limited
3 * All rights reserved
4 */
5
6#ifndef MJS_UTIL_H_
7#define MJS_UTIL_H_
8
9#include "common/frozen/frozen.h"
10#include "mjs_core.h"
11#include "mjs_util_public.h"
12
13#if defined(__cplusplus)
14extern "C" {
15#endif /* __cplusplus */
16
17struct mjs_bcode_part;
18
19#if MJS_ENABLE_DEBUG
20MJS_PRIVATE const char* opcodetostr(uint8_t opcode);
21MJS_PRIVATE size_t mjs_disasm_single(const uint8_t* code, size_t i);
22#endif
23
24MJS_PRIVATE const char* mjs_stringify_type(enum mjs_type t);
25
26/*
27 * Checks that the given argument is provided, and checks its type. If check
28 * fails, sets error in the mjs context, and returns 0; otherwise returns 1.
29 *
30 * If `arg_num` >= 0, checks argument; otherwise (`arg_num` is negative) checks
31 * `this`. `arg_name` is used for the error message only. If `parg` is not
32 * NULL, writes resulting value at this location in case of success.
33 */
34MJS_PRIVATE int mjs_check_arg(
35 struct mjs* mjs,
36 int arg_num,
37 const char* arg_name,
38 enum mjs_type expected_type,
39 mjs_val_t* parg);
40
41/*
42 * mjs_normalize_idx takes and index in the string and the string size, and
43 * returns the index which is >= 0 and <= size. Negative index is interpreted
44 * as size + index.
45 */
46MJS_PRIVATE int mjs_normalize_idx(int idx, int size);
47
48MJS_PRIVATE const char* mjs_get_bcode_filename(struct mjs* mjs, struct mjs_bcode_part* bp);
49
50/* Print JS value `v` to the JSON stream `out`. */
51void mjs_jprintf(mjs_val_t v, struct mjs* mjs, struct json_out* out);
52
53#if defined(__cplusplus)
54}
55#endif /* __cplusplus */
56
57#endif /* MJS_UTIL_H_ */
Definition frozen.h:118
Definition mjs_core.h:41
Definition mjs_core.h:63