Flipper Developer Docs
Loading...
Searching...
No Matches
mjs_bcode.h
1
/*
2
* Copyright (c) 2017 Cesanta Software Limited
3
* All rights reserved
4
*/
5
6
#ifndef MJS_BCODE_H_
7
#define MJS_BCODE_H_
8
9
#include "mjs_internal.h"
10
11
#include "mjs_core.h"
12
13
#if defined(__cplusplus)
14
extern
"C"
{
15
#endif
/* __cplusplus */
16
17
enum
mjs_opcode {
18
OP_NOP,
/* ( -- ) */
19
OP_DROP,
/* ( a -- ) */
20
OP_DUP,
/* ( a -- a a ) */
21
OP_SWAP,
/* ( a b -- b a ) */
22
OP_JMP,
/* ( -- ) */
23
OP_JMP_TRUE,
/* ( -- ) */
24
OP_JMP_NEUTRAL_TRUE,
/* ( -- ) */
25
OP_JMP_FALSE,
/* ( -- ) */
26
OP_JMP_NEUTRAL_FALSE,
/* ( -- ) */
27
OP_FIND_SCOPE,
/* ( a -- a b ) */
28
OP_PUSH_SCOPE,
/* ( -- a ) */
29
OP_PUSH_STR,
/* ( -- a ) */
30
OP_PUSH_TRUE,
/* ( -- a ) */
31
OP_PUSH_FALSE,
/* ( -- a ) */
32
OP_PUSH_INT,
/* ( -- a ) */
33
OP_PUSH_DBL,
/* ( -- a ) */
34
OP_PUSH_NULL,
/* ( -- a ) */
35
OP_PUSH_UNDEF,
/* ( -- a ) */
36
OP_PUSH_OBJ,
/* ( -- a ) */
37
OP_PUSH_ARRAY,
/* ( -- a ) */
38
OP_PUSH_FUNC,
/* ( -- a ) */
39
OP_PUSH_THIS,
/* ( -- a ) */
40
OP_GET,
/* ( key obj -- obj[key] ) */
41
OP_CREATE,
/* ( key obj -- ) */
42
OP_EXPR,
/* ( ... -- a ) */
43
OP_APPEND,
/* ( a b -- ) */
44
OP_SET_ARG,
/* ( a -- a ) */
45
OP_NEW_SCOPE,
/* ( -- ) */
46
OP_DEL_SCOPE,
/* ( -- ) */
47
OP_CALL,
/* ( func param1 param2 ... num_params -- result ) */
48
OP_RETURN,
/* ( -- ) */
49
OP_LOOP,
/* ( -- ) Push break & continue addresses to loop_labels */
50
OP_BREAK,
/* ( -- ) */
51
OP_CONTINUE,
/* ( -- ) */
52
OP_SETRETVAL,
/* ( a -- ) */
53
OP_EXIT,
/* ( -- ) */
54
OP_BCODE_HEADER,
/* ( -- ) */
55
OP_ARGS,
/* ( -- ) Mark the beginning of function call arguments */
56
OP_FOR_IN_NEXT,
/* ( name obj iter_ptr -- name obj iter_ptr_next ) */
57
OP_MAX
58
};
59
60
struct
pstate
;
61
struct
mjs
;
62
63
MJS_PRIVATE
void
emit_byte(
struct
pstate
*
pstate
, uint8_t
byte
);
64
MJS_PRIVATE
void
emit_int(
struct
pstate
*
pstate
, int64_t n);
65
MJS_PRIVATE
void
emit_str(
struct
pstate
*
pstate
,
const
char
* ptr,
size_t
len);
66
67
/*
68
* Inserts provided offset `v` at the offset `offset`.
69
*
70
* Returns delta at which the code was moved; the delta can be any: 0 or
71
* positive or negative.
72
*/
73
MJS_PRIVATE
int
74
mjs_bcode_insert_offset(
struct
pstate
* p,
struct
mjs
*
mjs
,
size_t
offset,
size_t
v);
75
76
/*
77
* Adds a new bcode part; does not retain `bp`.
78
*/
79
MJS_PRIVATE
void
mjs_bcode_part_add(
struct
mjs
*
mjs
,
const
struct
mjs_bcode_part
* bp);
80
81
/*
82
* Returns bcode part by the bcode number
83
*/
84
MJS_PRIVATE
struct
mjs_bcode_part
* mjs_bcode_part_get(
struct
mjs
*
mjs
,
int
num);
85
86
/*
87
* Returns bcode part by the global bcode offset
88
*/
89
MJS_PRIVATE
struct
mjs_bcode_part
* mjs_bcode_part_get_by_offset(
struct
mjs
*
mjs
,
size_t
offset);
90
91
/*
92
* Returns a number of bcode parts
93
*/
94
MJS_PRIVATE
int
mjs_bcode_parts_cnt(
struct
mjs
*
mjs
);
95
96
/*
97
* Adds the bcode being generated (mjs->bcode_gen) as a next bcode part
98
*/
99
MJS_PRIVATE
void
mjs_bcode_commit(
struct
mjs
*
mjs
);
100
101
#if defined(__cplusplus)
102
}
103
#endif
/* __cplusplus */
104
105
#endif
/* MJS_BCODE_H_ */
mjs_bcode_part
Definition
mjs_core.h:41
mjs
Definition
mjs_core.h:63
pstate
Definition
mjs_tok.h:21
lib
mjs
mjs_bcode.h
Generated by
1.12.0