source: EcnlProtoTool/trunk/mruby-1.2.0/include/mruby/compile.h@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr
File size: 5.7 KB
Line 
1/*
2** mruby/compile.h - mruby parser
3**
4** See Copyright Notice in mruby.h
5*/
6
7#ifndef MRUBY_COMPILE_H
8#define MRUBY_COMPILE_H
9
10#include "mruby/common.h"
11
12/**
13 * MRuby Compiler
14 */
15MRB_BEGIN_DECL
16
17#include "mruby.h"
18
19struct mrb_jmpbuf;
20
21struct mrb_parser_state;
22/* load context */
23typedef struct mrbc_context {
24 mrb_sym *syms;
25 int slen;
26 char *filename;
27 short lineno;
28 int (*partial_hook)(struct mrb_parser_state*);
29 void *partial_data;
30 struct RClass *target_class;
31 mrb_bool capture_errors:1;
32 mrb_bool dump_result:1;
33 mrb_bool no_exec:1;
34 mrb_bool keep_lv:1;
35 mrb_bool no_optimize:1;
36} mrbc_context;
37
38MRB_API mrbc_context* mrbc_context_new(mrb_state *mrb);
39MRB_API void mrbc_context_free(mrb_state *mrb, mrbc_context *cxt);
40MRB_API const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s);
41MRB_API void mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*partial_hook)(struct mrb_parser_state*), void*data);
42
43MRB_API mrb_value mrb_toplevel_run_keep(mrb_state*, struct RProc*, unsigned int);
44
45/* AST node structure */
46typedef struct mrb_ast_node {
47 struct mrb_ast_node *car, *cdr;
48 uint16_t lineno, filename_index;
49} mrb_ast_node;
50
51/* lexer states */
52enum mrb_lex_state_enum {
53 EXPR_BEG, /* ignore newline, +/- is a sign. */
54 EXPR_END, /* newline significant, +/- is an operator. */
55 EXPR_ENDARG, /* ditto, and unbound braces. */
56 EXPR_ENDFN, /* ditto, and unbound braces. */
57 EXPR_ARG, /* newline significant, +/- is an operator. */
58 EXPR_CMDARG, /* newline significant, +/- is an operator. */
59 EXPR_MID, /* newline significant, +/- is an operator. */
60 EXPR_FNAME, /* ignore newline, no reserved words. */
61 EXPR_DOT, /* right after '.' or '::', no reserved words. */
62 EXPR_CLASS, /* immediate after 'class', no here document. */
63 EXPR_VALUE, /* alike EXPR_BEG but label is disallowed. */
64 EXPR_MAX_STATE
65};
66
67/* saved error message */
68struct mrb_parser_message {
69 int lineno;
70 int column;
71 char* message;
72};
73
74#define STR_FUNC_PARSING 0x01
75#define STR_FUNC_EXPAND 0x02
76#define STR_FUNC_REGEXP 0x04
77#define STR_FUNC_WORD 0x08
78#define STR_FUNC_SYMBOL 0x10
79#define STR_FUNC_ARRAY 0x20
80#define STR_FUNC_HEREDOC 0x40
81#define STR_FUNC_XQUOTE 0x80
82
83enum mrb_string_type {
84 str_not_parsing = (0),
85 str_squote = (STR_FUNC_PARSING),
86 str_dquote = (STR_FUNC_PARSING|STR_FUNC_EXPAND),
87 str_regexp = (STR_FUNC_PARSING|STR_FUNC_REGEXP|STR_FUNC_EXPAND),
88 str_sword = (STR_FUNC_PARSING|STR_FUNC_WORD|STR_FUNC_ARRAY),
89 str_dword = (STR_FUNC_PARSING|STR_FUNC_WORD|STR_FUNC_ARRAY|STR_FUNC_EXPAND),
90 str_ssym = (STR_FUNC_PARSING|STR_FUNC_SYMBOL),
91 str_ssymbols = (STR_FUNC_PARSING|STR_FUNC_SYMBOL|STR_FUNC_ARRAY),
92 str_dsymbols = (STR_FUNC_PARSING|STR_FUNC_SYMBOL|STR_FUNC_ARRAY|STR_FUNC_EXPAND),
93 str_heredoc = (STR_FUNC_PARSING|STR_FUNC_HEREDOC),
94 str_xquote = (STR_FUNC_PARSING|STR_FUNC_XQUOTE|STR_FUNC_EXPAND),
95};
96
97/* heredoc structure */
98struct mrb_parser_heredoc_info {
99 mrb_bool allow_indent:1;
100 mrb_bool line_head:1;
101 enum mrb_string_type type;
102 const char *term;
103 int term_len;
104 mrb_ast_node *doc;
105};
106
107#define MRB_PARSER_BUF_SIZE 1024
108
109/* parser structure */
110struct mrb_parser_state {
111 mrb_state *mrb;
112 struct mrb_pool *pool;
113 mrb_ast_node *cells;
114 const char *s, *send;
115#ifndef MRB_DISABLE_STDIO
116 FILE *f;
117#endif
118 mrbc_context *cxt;
119 char const *filename;
120 int lineno;
121 int column;
122
123 enum mrb_lex_state_enum lstate;
124 mrb_ast_node *lex_strterm; /* (type nest_level beg . end) */
125
126 unsigned int cond_stack;
127 unsigned int cmdarg_stack;
128 int paren_nest;
129 int lpar_beg;
130 int in_def, in_single;
131 mrb_bool cmd_start:1;
132 mrb_ast_node *locals;
133
134 mrb_ast_node *pb;
135 char buf[MRB_PARSER_BUF_SIZE];
136 int bidx;
137
138 mrb_ast_node *all_heredocs; /* list of mrb_parser_heredoc_info* */
139 mrb_ast_node *heredocs_from_nextline;
140 mrb_ast_node *parsing_heredoc;
141 mrb_ast_node *lex_strterm_before_heredoc;
142 mrb_bool heredoc_end_now:1; /* for mirb */
143
144 void *ylval;
145
146 size_t nerr;
147 size_t nwarn;
148 mrb_ast_node *tree;
149
150 mrb_bool no_optimize:1;
151 mrb_bool capture_errors:1;
152 struct mrb_parser_message error_buffer[10];
153 struct mrb_parser_message warn_buffer[10];
154
155 mrb_sym* filename_table;
156 size_t filename_table_length;
157 int current_filename_index;
158
159 struct mrb_jmpbuf* jmp;
160};
161
162MRB_API struct mrb_parser_state* mrb_parser_new(mrb_state*);
163MRB_API void mrb_parser_free(struct mrb_parser_state*);
164MRB_API void mrb_parser_parse(struct mrb_parser_state*,mrbc_context*);
165
166MRB_API void mrb_parser_set_filename(struct mrb_parser_state*, char const*);
167MRB_API char const* mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx);
168
169/* utility functions */
170#ifndef MRB_DISABLE_STDIO
171MRB_API struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrbc_context*);
172#endif
173MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*);
174MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int,mrbc_context*);
175MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*);
176
177/* program load functions */
178#ifndef MRB_DISABLE_STDIO
179MRB_API mrb_value mrb_load_file(mrb_state*,FILE*);
180MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt);
181#endif
182MRB_API mrb_value mrb_load_string(mrb_state *mrb, const char *s);
183MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, int len);
184MRB_API mrb_value mrb_load_string_cxt(mrb_state *mrb, const char *s, mrbc_context *cxt);
185MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *cxt);
186
187/** @} */
188MRB_END_DECL
189
190#endif /* MRUBY_COMPILE_H */
Note: See TracBrowser for help on using the repository browser.