FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mruby/include/mruby/compile.h at master · koic/mruby · GitHub
koic
/
mruby
Public
forked from
mruby/mruby
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
mruby
/
include
/
mruby
/
compile.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
209 lines (179 loc) · 6.47 KB
Breadcrumbs
mruby
/
include
/
mruby
/
compile.h
Copy path
File metadata and controls
209 lines (179 loc) · 6.47 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
** @file mruby/compile.h - mruby parser
**
** See Copyright Notice in mruby.h
*/
#ifndef
MRUBY_COMPILE_H
#define
MRUBY_COMPILE_H
#include
"common.h"
/**
* MRuby Compiler
*/
MRB_BEGIN_DECL
#include
<mruby.h>
struct
mrb_parser_state
;
/* load context */
typedef
struct
mrbc_context
{
mrb_sym
*
syms
;
int
slen
;
char
*
filename
;
uint16_t
lineno
;
int
(
*
partial_hook
)(
struct
mrb_parser_state
*
);
void
*
partial_data
;
struct
RClass
*
target_class
;
mrb_bool
capture_errors
:
1
;
mrb_bool
dump_result
:
1
;
mrb_bool
no_exec
:
1
;
mrb_bool
keep_lv
:
1
;
mrb_bool
no_optimize
:
1
;
mrb_bool
no_ext_ops
:
1
;
const
struct
RProc
*
upper
;
size_t
parser_nerr
;
}
mrbc_context
;
MRB_API
mrbc_context
*
mrbc_context_new
(
mrb_state
*
mrb
);
MRB_API
void
mrbc_context_free
(
mrb_state
*
mrb
,
mrbc_context
*
cxt
);
MRB_API
const
char
*
mrbc_filename
(
mrb_state
*
mrb
,
mrbc_context
*
c
,
const
char
*
s
);
MRB_API
void
mrbc_partial_hook
(
mrb_state
*
mrb
,
mrbc_context
*
c
,
int
(
*
partial_hook
)(
struct
mrb_parser_state
*
),
void
*
data
);
MRB_API
void
mrbc_cleanup_local_variables
(
mrb_state
*
mrb
,
mrbc_context
*
c
);
/* AST node structure */
typedef
struct
mrb_ast_node
{
struct
mrb_ast_node
*
car
,
*
cdr
;
uint16_t
lineno
,
filename_index
;
}
mrb_ast_node
;
/* lexer states */
enum
mrb_lex_state_enum
{
EXPR_BEG
,
/* ignore newline, +/- is a sign. */
EXPR_END
,
/* newline significant, +/- is an operator. */
EXPR_ENDARG
,
/* ditto, and unbound braces. */
EXPR_ENDFN
,
/* ditto, and unbound braces. */
EXPR_ARG
,
/* newline significant, +/- is an operator. */
EXPR_CMDARG
,
/* newline significant, +/- is an operator. */
EXPR_MID
,
/* newline significant, +/- is a sign. */
EXPR_FNAME
,
/* ignore newline, no reserved words. */
EXPR_DOT
,
/* right after '.' or '::', no reserved words. */
EXPR_CLASS
,
/* immediate after 'class', no here document. */
EXPR_VALUE
,
/* alike EXPR_BEG but label is disallowed. */
EXPR_MAX_STATE
};
/* saved error message */
struct
mrb_parser_message
{
uint16_t
lineno
;
int
column
;
char
*
message
;
};
#define
STR_FUNC_PARSING
0x01
#define
STR_FUNC_EXPAND
0x02
#define
STR_FUNC_REGEXP
0x04
#define
STR_FUNC_WORD
0x08
#define
STR_FUNC_SYMBOL
0x10
#define
STR_FUNC_ARRAY
0x20
#define
STR_FUNC_HEREDOC
0x40
#define
STR_FUNC_XQUOTE
0x80
enum
mrb_string_type
{
str_not_parsing
=
(
0
),
str_squote
=
(
STR_FUNC_PARSING
),
str_dquote
=
(
STR_FUNC_PARSING
|
STR_FUNC_EXPAND
),
str_regexp
=
(
STR_FUNC_PARSING
|
STR_FUNC_REGEXP
|
STR_FUNC_EXPAND
),
str_sword
=
(
STR_FUNC_PARSING
|
STR_FUNC_WORD
|
STR_FUNC_ARRAY
),
str_dword
=
(
STR_FUNC_PARSING
|
STR_FUNC_WORD
|
STR_FUNC_ARRAY
|
STR_FUNC_EXPAND
),
str_ssym
=
(
STR_FUNC_PARSING
|
STR_FUNC_SYMBOL
),
str_ssymbols
=
(
STR_FUNC_PARSING
|
STR_FUNC_SYMBOL
|
STR_FUNC_ARRAY
),
str_dsymbols
=
(
STR_FUNC_PARSING
|
STR_FUNC_SYMBOL
|
STR_FUNC_ARRAY
|
STR_FUNC_EXPAND
),
str_heredoc
=
(
STR_FUNC_PARSING
|
STR_FUNC_HEREDOC
),
str_xquote
=
(
STR_FUNC_PARSING
|
STR_FUNC_XQUOTE
|
STR_FUNC_EXPAND
),
};
/* heredoc structure */
struct
mrb_parser_heredoc_info
{
mrb_bool
allow_indent
:
1
;
mrb_bool
remove_indent
:
1
;
size_t
indent
;
mrb_ast_node
*
indented
;
mrb_bool
line_head
:
1
;
enum
mrb_string_type
type
;
const
char
*
term
;
int
term_len
;
mrb_ast_node
*
doc
;
};
#define
MRB_PARSER_TOKBUF_MAX
(UINT16_MAX-1)
#define
MRB_PARSER_TOKBUF_SIZE
256
/* parser structure */
struct
mrb_parser_state
{
mrb_state
*
mrb
;
struct
mrb_pool
*
pool
;
mrb_ast_node
*
cells
;
const
char
*
s
,
*
send
;
#ifndef
MRB_NO_STDIO
/* If both f and s are non-null, it will be taken preferentially from s until s < send. */
FILE
*
f
;
#endif
mrbc_context
*
cxt
;
mrb_sym
filename_sym
;
uint16_t
lineno
;
int
column
;
enum
mrb_lex_state_enum
lstate
;
mrb_ast_node
*
lex_strterm
;
/* (type nest_level beg . end) */
unsigned
int
cond_stack
;
unsigned
int
cmdarg_stack
;
int
paren_nest
;
int
lpar_beg
;
int
in_def
,
in_single
;
mrb_bool
cmd_start
:
1
;
mrb_ast_node
*
locals
;
mrb_ast_node
*
pb
;
char
*
tokbuf
;
char
buf
[
MRB_PARSER_TOKBUF_SIZE
];
int
tidx
;
int
tsiz
;
mrb_ast_node
*
all_heredocs
;
/* list of mrb_parser_heredoc_info* */
mrb_ast_node
*
heredocs_from_nextline
;
mrb_ast_node
*
parsing_heredoc
;
mrb_ast_node
*
lex_strterm_before_heredoc
;
void
*
ylval
;
size_t
nerr
;
size_t
nwarn
;
mrb_ast_node
*
tree
;
mrb_bool
no_optimize
:
1
;
mrb_bool
capture_errors
:
1
;
mrb_bool
no_ext_ops
:
1
;
const
struct
RProc
*
upper
;
struct
mrb_parser_message
error_buffer
[
10
];
struct
mrb_parser_message
warn_buffer
[
10
];
mrb_sym
*
filename_table
;
uint16_t
filename_table_length
;
uint16_t
current_filename_index
;
mrb_ast_node
*
nvars
;
};
MRB_API
struct
mrb_parser_state
*
mrb_parser_new
(
mrb_state
*
);
MRB_API
void
mrb_parser_free
(
struct
mrb_parser_state
*
);
MRB_API
void
mrb_parser_parse
(
struct
mrb_parser_state
*
,
mrbc_context
*
);
MRB_API
void
mrb_parser_set_filename
(
struct
mrb_parser_state
*
,
char
const
*
);
MRB_API
mrb_sym
mrb_parser_get_filename
(
struct
mrb_parser_state
*
,
uint16_t
idx
);
/* utility functions */
#ifndef
MRB_NO_STDIO
MRB_API
struct
mrb_parser_state
*
mrb_parse_file
(
mrb_state
*
,
FILE
*
,
mrbc_context
*
);
#endif
MRB_API
struct
mrb_parser_state
*
mrb_parse_string
(
mrb_state
*
,
const
char
*
,
mrbc_context
*
);
MRB_API
struct
mrb_parser_state
*
mrb_parse_nstring
(
mrb_state
*
,
const
char
*
,
size_t
,
mrbc_context
*
);
MRB_API
struct
RProc
*
mrb_generate_code
(
mrb_state
*
,
struct
mrb_parser_state
*
);
MRB_API
mrb_value
mrb_load_exec
(
mrb_state
*
mrb
,
struct
mrb_parser_state
*
p
,
mrbc_context
*
c
);
/** program load functions
* Please note! Currently due to interactions with the GC calling these functions will
* leak one RProc object per function call.
* To prevent this save the current memory arena before calling and restore the arena
* right after, like so
* int ai = mrb_gc_arena_save(mrb);
* mrb_value status = mrb_load_string(mrb, buffer);
* mrb_gc_arena_restore(mrb, ai);
*/
#ifndef
MRB_NO_STDIO
MRB_API
mrb_value
mrb_load_file
(
mrb_state
*
,
FILE
*
);
MRB_API
mrb_value
mrb_load_file_cxt
(
mrb_state
*
,
FILE
*
,
mrbc_context
*
cxt
);
MRB_API
mrb_value
mrb_load_detect_file_cxt
(
mrb_state
*
mrb
,
FILE
*
fp
,
mrbc_context
*
c
);
#endif
MRB_API
mrb_value
mrb_load_string
(
mrb_state
*
mrb
,
const
char
*
s
);
MRB_API
mrb_value
mrb_load_nstring
(
mrb_state
*
mrb
,
const
char
*
s
,
size_t
len
);
MRB_API
mrb_value
mrb_load_string_cxt
(
mrb_state
*
mrb
,
const
char
*
s
,
mrbc_context
*
cxt
);
MRB_API
mrb_value
mrb_load_nstring_cxt
(
mrb_state
*
mrb
,
const
char
*
s
,
size_t
len
,
mrbc_context
*
cxt
);
/** @} */
MRB_END_DECL
#endif
/* MRUBY_COMPILE_H */
Back
|
FazBrowse Home
|
New Git URL