portable_mruby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +195 -0
- data/exe/portable-mruby +6 -0
- data/lib/portable_mruby/binary_manager.rb +225 -0
- data/lib/portable_mruby/builder.rb +97 -0
- data/lib/portable_mruby/bytecode_compiler.rb +19 -0
- data/lib/portable_mruby/c_generator.rb +94 -0
- data/lib/portable_mruby/cli.rb +136 -0
- data/lib/portable_mruby/version.rb +6 -0
- data/lib/portable_mruby.rb +15 -0
- data/vendor/mruby/bin/mrbc.com +0 -0
- data/vendor/mruby/include/mrbconf.h +230 -0
- data/vendor/mruby/include/mruby/array.h +303 -0
- data/vendor/mruby/include/mruby/boxing_nan.h +169 -0
- data/vendor/mruby/include/mruby/boxing_no.h +59 -0
- data/vendor/mruby/include/mruby/boxing_word.h +251 -0
- data/vendor/mruby/include/mruby/class.h +104 -0
- data/vendor/mruby/include/mruby/common.h +118 -0
- data/vendor/mruby/include/mruby/compile.h +185 -0
- data/vendor/mruby/include/mruby/data.h +76 -0
- data/vendor/mruby/include/mruby/debug.h +75 -0
- data/vendor/mruby/include/mruby/dump.h +159 -0
- data/vendor/mruby/include/mruby/endian.h +44 -0
- data/vendor/mruby/include/mruby/error.h +132 -0
- data/vendor/mruby/include/mruby/gc.h +72 -0
- data/vendor/mruby/include/mruby/gems/mruby-dir/include/dir_hal.h +79 -0
- data/vendor/mruby/include/mruby/gems/mruby-io/include/io_hal.h +451 -0
- data/vendor/mruby/include/mruby/gems/mruby-io/include/mruby/ext/io.h +76 -0
- data/vendor/mruby/include/mruby/gems/mruby-socket/include/socket_hal.h +83 -0
- data/vendor/mruby/include/mruby/gems/mruby-time/include/mruby/time.h +27 -0
- data/vendor/mruby/include/mruby/hash.h +234 -0
- data/vendor/mruby/include/mruby/internal.h +274 -0
- data/vendor/mruby/include/mruby/irep.h +142 -0
- data/vendor/mruby/include/mruby/istruct.h +50 -0
- data/vendor/mruby/include/mruby/khash.h +455 -0
- data/vendor/mruby/include/mruby/mempool.h +19 -0
- data/vendor/mruby/include/mruby/numeric.h +174 -0
- data/vendor/mruby/include/mruby/object.h +45 -0
- data/vendor/mruby/include/mruby/opcode.h +69 -0
- data/vendor/mruby/include/mruby/ops.h +120 -0
- data/vendor/mruby/include/mruby/presym/disable.h +72 -0
- data/vendor/mruby/include/mruby/presym/enable.h +39 -0
- data/vendor/mruby/include/mruby/presym/id.h +1423 -0
- data/vendor/mruby/include/mruby/presym/scanning.h +81 -0
- data/vendor/mruby/include/mruby/presym/table.h +2847 -0
- data/vendor/mruby/include/mruby/presym.h +41 -0
- data/vendor/mruby/include/mruby/proc.h +186 -0
- data/vendor/mruby/include/mruby/range.h +77 -0
- data/vendor/mruby/include/mruby/re.h +16 -0
- data/vendor/mruby/include/mruby/string.h +428 -0
- data/vendor/mruby/include/mruby/throw.h +57 -0
- data/vendor/mruby/include/mruby/value.h +471 -0
- data/vendor/mruby/include/mruby/variable.h +108 -0
- data/vendor/mruby/include/mruby/version.h +143 -0
- data/vendor/mruby/include/mruby.h +1614 -0
- data/vendor/mruby/lib/libmruby.a +0 -0
- metadata +102 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
** @file 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 "common.h"
|
|
11
|
+
#include "mruby/mempool.h"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* mruby Compiler
|
|
15
|
+
*/
|
|
16
|
+
MRB_BEGIN_DECL
|
|
17
|
+
|
|
18
|
+
#include <mruby.h>
|
|
19
|
+
|
|
20
|
+
struct mrb_parser_state;
|
|
21
|
+
/* load context */
|
|
22
|
+
typedef struct mrb_ccontext {
|
|
23
|
+
mrb_sym *syms;
|
|
24
|
+
int slen;
|
|
25
|
+
char *filename;
|
|
26
|
+
uint16_t lineno;
|
|
27
|
+
int (*partial_hook)(struct mrb_parser_state*);
|
|
28
|
+
void *partial_data;
|
|
29
|
+
struct RClass *target_class;
|
|
30
|
+
mrb_bool capture_errors:1;
|
|
31
|
+
mrb_bool dump_result:1;
|
|
32
|
+
mrb_bool no_exec:1;
|
|
33
|
+
mrb_bool keep_lv:1;
|
|
34
|
+
mrb_bool no_optimize:1;
|
|
35
|
+
mrb_bool no_ext_ops:1;
|
|
36
|
+
const struct RProc *upper;
|
|
37
|
+
|
|
38
|
+
size_t parser_nerr;
|
|
39
|
+
} mrb_ccontext; /* compiler context */
|
|
40
|
+
|
|
41
|
+
MRB_API mrb_ccontext* mrb_ccontext_new(mrb_state *mrb);
|
|
42
|
+
MRB_API void mrb_ccontext_free(mrb_state *mrb, mrb_ccontext *cxt);
|
|
43
|
+
MRB_API const char *mrb_ccontext_filename(mrb_state *mrb, mrb_ccontext *c, const char *s);
|
|
44
|
+
MRB_API void mrb_ccontext_partial_hook(mrb_ccontext *c, int (*partial_hook)(struct mrb_parser_state*), void*data);
|
|
45
|
+
MRB_API void mrb_ccontext_cleanup_local_variables(mrb_ccontext *c);
|
|
46
|
+
|
|
47
|
+
/* compatibility macros */
|
|
48
|
+
#define mrbc_context mrb_ccontext
|
|
49
|
+
#define mrbc_context_new mrb_ccontext_new
|
|
50
|
+
#define mrbc_context_free mrb_ccontext_free
|
|
51
|
+
#define mrbc_filename mrb_ccontext_filename
|
|
52
|
+
#define mrbc_partial_hook mrb_ccontext_partial_hook
|
|
53
|
+
#define mrbc_cleanup_local_variables mrb_ccontext_cleanup_local_variables
|
|
54
|
+
|
|
55
|
+
/* AST node structure */
|
|
56
|
+
typedef struct mrb_ast_node mrb_ast_node;
|
|
57
|
+
|
|
58
|
+
/* lexer states */
|
|
59
|
+
enum mrb_lex_state_enum {
|
|
60
|
+
EXPR_BEG, /* ignore newline, +/- is a sign. */
|
|
61
|
+
EXPR_END, /* newline significant, +/- is an operator. */
|
|
62
|
+
EXPR_ENDARG, /* ditto, and unbound braces. */
|
|
63
|
+
EXPR_ENDFN, /* ditto, and unbound braces. */
|
|
64
|
+
EXPR_ARG, /* newline significant, +/- is an operator. */
|
|
65
|
+
EXPR_CMDARG, /* newline significant, +/- is an operator. */
|
|
66
|
+
EXPR_MID, /* newline significant, +/- is a sign. */
|
|
67
|
+
EXPR_FNAME, /* ignore newline, no reserved words. */
|
|
68
|
+
EXPR_DOT, /* right after '.' or '::', no reserved words. */
|
|
69
|
+
EXPR_CLASS, /* immediate after 'class', no here document. */
|
|
70
|
+
EXPR_VALUE, /* alike EXPR_BEG but label is disallowed. */
|
|
71
|
+
EXPR_MAX_STATE
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/* saved error message */
|
|
75
|
+
struct mrb_parser_message {
|
|
76
|
+
uint16_t lineno;
|
|
77
|
+
int column;
|
|
78
|
+
char* message;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
#define MRB_PARSER_TOKBUF_MAX (UINT16_MAX-1)
|
|
82
|
+
#define MRB_PARSER_TOKBUF_SIZE 256
|
|
83
|
+
|
|
84
|
+
/* parser structure */
|
|
85
|
+
struct mrb_parser_state {
|
|
86
|
+
mrb_state *mrb;
|
|
87
|
+
mempool *pool;
|
|
88
|
+
mrb_ast_node *cells;
|
|
89
|
+
const char *s, *send;
|
|
90
|
+
#ifndef MRB_NO_STDIO
|
|
91
|
+
/* If both f and s are non-null, it will be taken preferentially from s until s < send. */
|
|
92
|
+
FILE *f;
|
|
93
|
+
#endif
|
|
94
|
+
mrb_ccontext *cxt;
|
|
95
|
+
mrb_sym filename_sym;
|
|
96
|
+
uint16_t lineno;
|
|
97
|
+
int column;
|
|
98
|
+
|
|
99
|
+
enum mrb_lex_state_enum lstate;
|
|
100
|
+
struct parser_lex_strterm *lex_strterm;
|
|
101
|
+
|
|
102
|
+
unsigned int cond_stack;
|
|
103
|
+
unsigned int cmdarg_stack;
|
|
104
|
+
int paren_nest;
|
|
105
|
+
int lpar_beg;
|
|
106
|
+
int in_def, in_single;
|
|
107
|
+
mrb_bool cmd_start:1;
|
|
108
|
+
mrb_ast_node *locals;
|
|
109
|
+
|
|
110
|
+
mrb_ast_node *pb;
|
|
111
|
+
char *tokbuf;
|
|
112
|
+
char buf[MRB_PARSER_TOKBUF_SIZE];
|
|
113
|
+
int tidx;
|
|
114
|
+
int tsiz;
|
|
115
|
+
|
|
116
|
+
mrb_ast_node *heredocs_from_nextline;
|
|
117
|
+
mrb_ast_node *parsing_heredoc;
|
|
118
|
+
|
|
119
|
+
void *ylval;
|
|
120
|
+
|
|
121
|
+
size_t nerr;
|
|
122
|
+
size_t nwarn;
|
|
123
|
+
mrb_ast_node *tree;
|
|
124
|
+
|
|
125
|
+
mrb_bool no_optimize:1;
|
|
126
|
+
mrb_bool capture_errors:1;
|
|
127
|
+
mrb_bool no_ext_ops:1;
|
|
128
|
+
const struct RProc *upper;
|
|
129
|
+
struct mrb_parser_message error_buffer[10];
|
|
130
|
+
struct mrb_parser_message warn_buffer[10];
|
|
131
|
+
|
|
132
|
+
mrb_sym* filename_table;
|
|
133
|
+
uint16_t filename_table_length;
|
|
134
|
+
uint16_t current_filename_index;
|
|
135
|
+
|
|
136
|
+
/* Variable-sized node management */
|
|
137
|
+
mrb_ast_node *nvars;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
MRB_API struct mrb_parser_state* mrb_parser_new(mrb_state*);
|
|
141
|
+
MRB_API void mrb_parser_free(struct mrb_parser_state*);
|
|
142
|
+
MRB_API void mrb_parser_parse(struct mrb_parser_state*,mrb_ccontext*);
|
|
143
|
+
|
|
144
|
+
MRB_API void mrb_parser_set_filename(struct mrb_parser_state*, char const*);
|
|
145
|
+
MRB_API mrb_sym mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx);
|
|
146
|
+
|
|
147
|
+
/* utility functions */
|
|
148
|
+
#ifndef MRB_NO_STDIO
|
|
149
|
+
MRB_API struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrb_ccontext*);
|
|
150
|
+
#endif
|
|
151
|
+
MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrb_ccontext*);
|
|
152
|
+
MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,size_t,mrb_ccontext*);
|
|
153
|
+
MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*);
|
|
154
|
+
MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrb_ccontext *c);
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* program load functions
|
|
158
|
+
*
|
|
159
|
+
* Please note! Currently due to interactions with the GC calling these functions will
|
|
160
|
+
* leak one RProc object per function call.
|
|
161
|
+
* To prevent this save the current memory arena before calling and restore the arena
|
|
162
|
+
* right after, like so
|
|
163
|
+
*
|
|
164
|
+
* int ai = mrb_gc_arena_save(mrb);
|
|
165
|
+
* mrb_value status = mrb_load_string(mrb, buffer);
|
|
166
|
+
* mrb_gc_arena_restore(mrb, ai);
|
|
167
|
+
*
|
|
168
|
+
* Also, when called from a C function defined as a method, the current stack is destroyed.
|
|
169
|
+
* If processing continues after this function, the objects obtained from the arguments
|
|
170
|
+
* must be protected as needed before this function.
|
|
171
|
+
*/
|
|
172
|
+
#ifndef MRB_NO_STDIO
|
|
173
|
+
MRB_API mrb_value mrb_load_file(mrb_state*,FILE*);
|
|
174
|
+
MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrb_ccontext *cxt);
|
|
175
|
+
MRB_API mrb_value mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrb_ccontext *c);
|
|
176
|
+
#endif
|
|
177
|
+
MRB_API mrb_value mrb_load_string(mrb_state *mrb, const char *s);
|
|
178
|
+
MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, size_t len);
|
|
179
|
+
MRB_API mrb_value mrb_load_string_cxt(mrb_state *mrb, const char *s, mrb_ccontext *cxt);
|
|
180
|
+
MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrb_ccontext *cxt);
|
|
181
|
+
|
|
182
|
+
/** @} */
|
|
183
|
+
MRB_END_DECL
|
|
184
|
+
|
|
185
|
+
#endif /* MRUBY_COMPILE_H */
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
** @file mruby/data.h - Data class
|
|
3
|
+
**
|
|
4
|
+
** See Copyright Notice in mruby.h
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef MRUBY_DATA_H
|
|
8
|
+
#define MRUBY_DATA_H
|
|
9
|
+
|
|
10
|
+
#include "common.h"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Custom C wrapped data.
|
|
14
|
+
*
|
|
15
|
+
* Defining Ruby wrappers around native objects.
|
|
16
|
+
*/
|
|
17
|
+
MRB_BEGIN_DECL
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Custom data type description.
|
|
21
|
+
*/
|
|
22
|
+
typedef struct mrb_data_type {
|
|
23
|
+
/** data type name */
|
|
24
|
+
const char *struct_name;
|
|
25
|
+
|
|
26
|
+
/** data type release function pointer */
|
|
27
|
+
void (*dfree)(mrb_state *mrb, void*);
|
|
28
|
+
} mrb_data_type;
|
|
29
|
+
|
|
30
|
+
struct RData {
|
|
31
|
+
MRB_OBJECT_HEADER;
|
|
32
|
+
struct iv_tbl *iv;
|
|
33
|
+
const mrb_data_type *type;
|
|
34
|
+
void *data;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
MRB_API struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass, void *datap, const mrb_data_type *type);
|
|
38
|
+
|
|
39
|
+
#define Data_Wrap_Struct(mrb,klass,type,ptr)\
|
|
40
|
+
mrb_data_object_alloc(mrb,klass,ptr,type)
|
|
41
|
+
|
|
42
|
+
#define Data_Make_Struct(mrb,klass,strct,type,sval,data_obj) do { \
|
|
43
|
+
(data_obj) = Data_Wrap_Struct(mrb,klass,type,NULL);\
|
|
44
|
+
(sval) = (strct*)mrb_malloc(mrb, sizeof(strct)); \
|
|
45
|
+
{ static const strct zero = { 0 }; *(sval) = zero; };\
|
|
46
|
+
(data_obj)->data = (sval);\
|
|
47
|
+
} while (0)
|
|
48
|
+
|
|
49
|
+
#define RDATA(obj) ((struct RData*)(mrb_ptr(obj)))
|
|
50
|
+
#define DATA_PTR(d) (RDATA(d)->data)
|
|
51
|
+
#define DATA_TYPE(d) (RDATA(d)->type)
|
|
52
|
+
MRB_API void mrb_data_check_type(mrb_state *mrb, mrb_value, const mrb_data_type*);
|
|
53
|
+
MRB_API void *mrb_data_get_ptr(mrb_state *mrb, mrb_value, const mrb_data_type*);
|
|
54
|
+
#define DATA_GET_PTR(mrb,obj,dtype,type) (type*)mrb_data_get_ptr(mrb,obj,dtype)
|
|
55
|
+
MRB_API void *mrb_data_check_get_ptr(mrb_state *mrb, mrb_value, const mrb_data_type*);
|
|
56
|
+
#define DATA_CHECK_GET_PTR(mrb,obj,dtype,type) (type*)mrb_data_check_get_ptr(mrb,obj,dtype)
|
|
57
|
+
|
|
58
|
+
/* obsolete functions and macros */
|
|
59
|
+
#define mrb_data_check_and_get(mrb,obj,dtype) mrb_data_get_ptr(mrb,obj,dtype)
|
|
60
|
+
#define mrb_get_datatype(mrb,val,type) mrb_data_get_ptr(mrb, val, type)
|
|
61
|
+
#define mrb_check_datatype(mrb,val,type) mrb_data_get_ptr(mrb, val, type)
|
|
62
|
+
#define Data_Get_Struct(mrb,obj,type,sval) do {\
|
|
63
|
+
*(void**)&sval = mrb_data_get_ptr(mrb, obj, type); \
|
|
64
|
+
} while (0)
|
|
65
|
+
|
|
66
|
+
MRB_INLINE void
|
|
67
|
+
mrb_data_init(mrb_value v, void *ptr, const mrb_data_type *type)
|
|
68
|
+
{
|
|
69
|
+
mrb_assert(mrb_data_p(v));
|
|
70
|
+
DATA_PTR(v) = ptr;
|
|
71
|
+
DATA_TYPE(v) = type;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
MRB_END_DECL
|
|
75
|
+
|
|
76
|
+
#endif /* MRUBY_DATA_H */
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
** @file mruby/debug.h - mruby debug info
|
|
3
|
+
**
|
|
4
|
+
** See Copyright Notice in mruby.h
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef MRUBY_DEBUG_H
|
|
8
|
+
#define MRUBY_DEBUG_H
|
|
9
|
+
|
|
10
|
+
#include "common.h"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* mruby Debugging.
|
|
14
|
+
*/
|
|
15
|
+
MRB_BEGIN_DECL
|
|
16
|
+
|
|
17
|
+
typedef enum mrb_debug_line_type {
|
|
18
|
+
mrb_debug_line_ary = 0,
|
|
19
|
+
mrb_debug_line_flat_map,
|
|
20
|
+
mrb_debug_line_packed_map
|
|
21
|
+
} mrb_debug_line_type;
|
|
22
|
+
|
|
23
|
+
typedef struct mrb_irep_debug_info_line {
|
|
24
|
+
uint32_t start_pos;
|
|
25
|
+
uint16_t line;
|
|
26
|
+
} mrb_irep_debug_info_line;
|
|
27
|
+
|
|
28
|
+
typedef struct mrb_irep_debug_info_file {
|
|
29
|
+
uint32_t start_pos;
|
|
30
|
+
mrb_sym filename_sym;
|
|
31
|
+
uint32_t line_entry_count;
|
|
32
|
+
mrb_debug_line_type line_type;
|
|
33
|
+
union {
|
|
34
|
+
const char *s;
|
|
35
|
+
void *ptr;
|
|
36
|
+
const uint16_t *ary;
|
|
37
|
+
const mrb_irep_debug_info_line *flat_map;
|
|
38
|
+
const uint8_t *packed_map;
|
|
39
|
+
} lines;
|
|
40
|
+
} mrb_irep_debug_info_file;
|
|
41
|
+
|
|
42
|
+
typedef struct mrb_irep_debug_info {
|
|
43
|
+
uint32_t pc_count;
|
|
44
|
+
uint16_t flen;
|
|
45
|
+
mrb_irep_debug_info_file **files;
|
|
46
|
+
} mrb_irep_debug_info;
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* get filename from irep's debug info and program counter
|
|
50
|
+
* @return returns NULL if not found
|
|
51
|
+
*/
|
|
52
|
+
MRB_API const char *mrb_debug_get_filename(mrb_state *mrb, const mrb_irep *irep, uint32_t pc);
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
* get line from irep's debug info and program counter
|
|
56
|
+
* @return returns -1 if not found
|
|
57
|
+
*/
|
|
58
|
+
MRB_API int32_t mrb_debug_get_line(mrb_state *mrb, const mrb_irep *irep, uint32_t pc);
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
* get line and filename from irep's debug info and program counter
|
|
62
|
+
* @return returns FALSE if not found
|
|
63
|
+
*/
|
|
64
|
+
MRB_API mrb_bool mrb_debug_get_position(mrb_state *mrb, const mrb_irep *irep, uint32_t pc, int32_t *lp, const char **fp);
|
|
65
|
+
|
|
66
|
+
MRB_API mrb_irep_debug_info *mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep);
|
|
67
|
+
MRB_API mrb_irep_debug_info_file *mrb_debug_info_append_file(
|
|
68
|
+
mrb_state *mrb, mrb_irep_debug_info *info,
|
|
69
|
+
const char *filename, uint16_t *lines,
|
|
70
|
+
uint32_t start_pos, uint32_t end_pos);
|
|
71
|
+
MRB_API void mrb_debug_info_free(mrb_state *mrb, mrb_irep_debug_info *d);
|
|
72
|
+
|
|
73
|
+
MRB_END_DECL
|
|
74
|
+
|
|
75
|
+
#endif /* MRUBY_DEBUG_H */
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
** @file mruby/dump.h - mruby binary dumper (mrbc binary format)
|
|
3
|
+
**
|
|
4
|
+
** See Copyright Notice in mruby.h
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef MRUBY_DUMP_H
|
|
8
|
+
#define MRUBY_DUMP_H
|
|
9
|
+
|
|
10
|
+
#include <mruby.h>
|
|
11
|
+
#include <mruby/irep.h>
|
|
12
|
+
#include "common.h"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Dumping compiled mruby script.
|
|
16
|
+
*/
|
|
17
|
+
MRB_BEGIN_DECL
|
|
18
|
+
|
|
19
|
+
/* flags for mrb_dump_irep{,_binary,_cfunc,_cstruct} */
|
|
20
|
+
#define MRB_DUMP_DEBUG_INFO 1
|
|
21
|
+
#define MRB_DUMP_STATIC 2
|
|
22
|
+
#define MRB_DUMP_NO_LVAR 4
|
|
23
|
+
|
|
24
|
+
#ifndef MRB_NO_STDIO
|
|
25
|
+
MRB_API mrb_value mrb_load_irep_file(mrb_state*,FILE*);
|
|
26
|
+
MRB_API mrb_value mrb_load_irep_file_cxt(mrb_state*, FILE*, mrb_ccontext*);
|
|
27
|
+
mrb_irep *mrb_read_irep_file(mrb_state*, FILE*);
|
|
28
|
+
int mrb_dump_irep_binary(mrb_state*, const mrb_irep*, uint8_t, FILE*);
|
|
29
|
+
#endif
|
|
30
|
+
/* avoid mrb_read_irep(); use mrb_read_irep_buf() instead (may cause buffer overflow) */
|
|
31
|
+
MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*);
|
|
32
|
+
MRB_API mrb_irep *mrb_read_irep_buf(mrb_state*, const void*, size_t);
|
|
33
|
+
|
|
34
|
+
/* dump/load error code
|
|
35
|
+
*
|
|
36
|
+
* NOTE: MRB_DUMP_GENERAL_FAILURE is caused by
|
|
37
|
+
* unspecified issues like malloc failed.
|
|
38
|
+
*/
|
|
39
|
+
#define MRB_DUMP_OK 0
|
|
40
|
+
#define MRB_DUMP_GENERAL_FAILURE (-1)
|
|
41
|
+
#define MRB_DUMP_WRITE_FAULT (-2)
|
|
42
|
+
#define MRB_DUMP_READ_FAULT (-3)
|
|
43
|
+
#define MRB_DUMP_INVALID_FILE_HEADER (-4)
|
|
44
|
+
#define MRB_DUMP_INVALID_IREP (-5)
|
|
45
|
+
#define MRB_DUMP_INVALID_ARGUMENT (-6)
|
|
46
|
+
|
|
47
|
+
/* null symbol length */
|
|
48
|
+
#define MRB_DUMP_NULL_SYM_LEN 0xFFFF
|
|
49
|
+
|
|
50
|
+
/* Rite Binary File header */
|
|
51
|
+
#define RITE_BINARY_IDENT "RITE"
|
|
52
|
+
/* Binary Format Version Major:Minor */
|
|
53
|
+
/* Major: Incompatible to prior versions */
|
|
54
|
+
/* Minor: Upper-compatible to prior versions */
|
|
55
|
+
#define RITE_BINARY_MAJOR_VER "03"
|
|
56
|
+
#define RITE_BINARY_MINOR_VER "00"
|
|
57
|
+
#define RITE_BINARY_FORMAT_VER RITE_BINARY_MAJOR_VER RITE_BINARY_MINOR_VER
|
|
58
|
+
#define RITE_COMPILER_NAME "MATZ"
|
|
59
|
+
#define RITE_COMPILER_VERSION "0000"
|
|
60
|
+
|
|
61
|
+
#define RITE_VM_VER "0300"
|
|
62
|
+
|
|
63
|
+
#define RITE_BINARY_EOF "END\0"
|
|
64
|
+
#define RITE_SECTION_IREP_IDENT "IREP"
|
|
65
|
+
#define RITE_SECTION_DEBUG_IDENT "DBG\0"
|
|
66
|
+
#define RITE_SECTION_LV_IDENT "LVAR"
|
|
67
|
+
|
|
68
|
+
#define MRB_DUMP_DEFAULT_STR_LEN 128
|
|
69
|
+
#define MRB_DUMP_ALIGNMENT sizeof(uint32_t)
|
|
70
|
+
|
|
71
|
+
/* binary header */
|
|
72
|
+
struct rite_binary_header {
|
|
73
|
+
uint8_t binary_ident[4]; /* Binary Identifier */
|
|
74
|
+
uint8_t major_version[2]; /* Binary Format Major Version */
|
|
75
|
+
uint8_t minor_version[2]; /* Binary Format Minor Version */
|
|
76
|
+
uint8_t binary_size[4]; /* Binary Size */
|
|
77
|
+
uint8_t compiler_name[4]; /* Compiler name */
|
|
78
|
+
uint8_t compiler_version[4];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/* section header */
|
|
82
|
+
#define RITE_SECTION_HEADER \
|
|
83
|
+
uint8_t section_ident[4]; \
|
|
84
|
+
uint8_t section_size[4]
|
|
85
|
+
|
|
86
|
+
struct rite_section_header {
|
|
87
|
+
RITE_SECTION_HEADER;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
struct rite_section_irep_header {
|
|
91
|
+
RITE_SECTION_HEADER;
|
|
92
|
+
|
|
93
|
+
uint8_t rite_version[4]; /* Rite Instruction Specification Version */
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
struct rite_section_debug_header {
|
|
97
|
+
RITE_SECTION_HEADER;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
struct rite_section_lv_header {
|
|
101
|
+
RITE_SECTION_HEADER;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
#define RITE_LV_NULL_MARK UINT16_MAX
|
|
105
|
+
|
|
106
|
+
struct rite_binary_footer {
|
|
107
|
+
RITE_SECTION_HEADER;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
static inline size_t
|
|
111
|
+
uint8_to_bin(uint8_t s, uint8_t *bin)
|
|
112
|
+
{
|
|
113
|
+
*bin = s;
|
|
114
|
+
return sizeof(uint8_t);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static inline size_t
|
|
118
|
+
uint16_to_bin(uint16_t s, uint8_t *bin)
|
|
119
|
+
{
|
|
120
|
+
*bin++ = (s >> 8) & 0xff;
|
|
121
|
+
*bin = s & 0xff;
|
|
122
|
+
return sizeof(uint16_t);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static inline size_t
|
|
126
|
+
uint32_to_bin(uint32_t l, uint8_t *bin)
|
|
127
|
+
{
|
|
128
|
+
*bin++ = (l >> 24) & 0xff;
|
|
129
|
+
*bin++ = (l >> 16) & 0xff;
|
|
130
|
+
*bin++ = (l >> 8) & 0xff;
|
|
131
|
+
*bin = l & 0xff;
|
|
132
|
+
return sizeof(uint32_t);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static inline uint32_t
|
|
136
|
+
bin_to_uint32(const uint8_t *bin)
|
|
137
|
+
{
|
|
138
|
+
return (uint32_t)bin[0] << 24 |
|
|
139
|
+
(uint32_t)bin[1] << 16 |
|
|
140
|
+
(uint32_t)bin[2] << 8 |
|
|
141
|
+
(uint32_t)bin[3];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static inline uint16_t
|
|
145
|
+
bin_to_uint16(const uint8_t *bin)
|
|
146
|
+
{
|
|
147
|
+
return (uint16_t)bin[0] << 8 |
|
|
148
|
+
(uint16_t)bin[1];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static inline uint8_t
|
|
152
|
+
bin_to_uint8(const uint8_t *bin)
|
|
153
|
+
{
|
|
154
|
+
return (uint8_t)bin[0];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
MRB_END_DECL
|
|
158
|
+
|
|
159
|
+
#endif /* MRUBY_DUMP_H */
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
** @file mruby/endian.h - detect endian-ness
|
|
3
|
+
**
|
|
4
|
+
** See Copyright Notice in mruby.h
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef MRUBY_ENDIAN_H
|
|
8
|
+
#define MRUBY_ENDIAN_H
|
|
9
|
+
|
|
10
|
+
#include <limits.h>
|
|
11
|
+
|
|
12
|
+
MRB_BEGIN_DECL
|
|
13
|
+
|
|
14
|
+
#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER__)
|
|
15
|
+
# define BYTE_ORDER __BYTE_ORDER__
|
|
16
|
+
#endif
|
|
17
|
+
#if !defined(BIG_ENDIAN) && defined(__ORDER_BIG_ENDIAN__)
|
|
18
|
+
# define BIG_ENDIAN __ORDER_BIG_ENDIAN__
|
|
19
|
+
#endif
|
|
20
|
+
#if !defined(LITTLE_ENDIAN) && defined(__ORDER_LITTLE_ENDIAN__)
|
|
21
|
+
# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#ifdef BYTE_ORDER
|
|
25
|
+
# if BYTE_ORDER == BIG_ENDIAN
|
|
26
|
+
# define littleendian 0
|
|
27
|
+
# elif BYTE_ORDER == LITTLE_ENDIAN
|
|
28
|
+
# define littleendian 1
|
|
29
|
+
# endif
|
|
30
|
+
#endif
|
|
31
|
+
#ifndef littleendian
|
|
32
|
+
/* can't distinguish endian in compile time */
|
|
33
|
+
static inline int
|
|
34
|
+
check_little_endian(void)
|
|
35
|
+
{
|
|
36
|
+
unsigned int n = 1;
|
|
37
|
+
return (*(unsigned char*)&n == 1);
|
|
38
|
+
}
|
|
39
|
+
# define littleendian check_little_endian()
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
MRB_END_DECL
|
|
43
|
+
|
|
44
|
+
#endif /* MRUBY_ENDIAN_H */
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
** @file mruby/error.h - Exception class
|
|
3
|
+
**
|
|
4
|
+
** See Copyright Notice in mruby.h
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#ifndef MRUBY_ERROR_H
|
|
8
|
+
#define MRUBY_ERROR_H
|
|
9
|
+
|
|
10
|
+
#include "common.h"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* mruby error handling.
|
|
14
|
+
*/
|
|
15
|
+
MRB_BEGIN_DECL
|
|
16
|
+
|
|
17
|
+
struct RException {
|
|
18
|
+
MRB_OBJECT_HEADER;
|
|
19
|
+
struct iv_tbl *iv;
|
|
20
|
+
struct RBasic *mesg; // NULL or probably RString
|
|
21
|
+
struct RBasic *backtrace; // NULL, RArray or RData
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/* error that should terminate execution */
|
|
25
|
+
#define MRB_EXC_EXIT 65536
|
|
26
|
+
#define MRB_EXC_EXIT_P(e) ((e)->flags & MRB_EXC_EXIT)
|
|
27
|
+
/* retrieve status value from exc; need <mruby/variable.h> and <mruby/presym.h> */
|
|
28
|
+
#define MRB_EXC_EXIT_STATUS(mrb,e) ((int)mrb_as_int((mrb),mrb_obj_iv_get((mrb),(e),MRB_SYM(status))))
|
|
29
|
+
/* exit with SystemExit status */
|
|
30
|
+
#define MRB_EXC_CHECK_EXIT(mrb,e) do {if (MRB_EXC_EXIT_P(e)) exit(MRB_EXC_EXIT_STATUS((mrb),(e)));} while (0)
|
|
31
|
+
|
|
32
|
+
#define mrb_exc_ptr(v) ((struct RException*)mrb_ptr(v))
|
|
33
|
+
|
|
34
|
+
MRB_API mrb_noreturn void mrb_sys_fail(mrb_state *mrb, const char *mesg);
|
|
35
|
+
MRB_API mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str);
|
|
36
|
+
#define mrb_exc_new_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit))
|
|
37
|
+
MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, const char *fmt, ...);
|
|
38
|
+
|
|
39
|
+
#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT32) || defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING)
|
|
40
|
+
#undef MRB_USE_RBREAK_VALUE_UNION
|
|
41
|
+
#else
|
|
42
|
+
#define MRB_USE_RBREAK_VALUE_UNION 1
|
|
43
|
+
#endif
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* flags:
|
|
47
|
+
* 0..7: enum mrb_vtype (only when defined MRB_USE_RBREAK_VALUE_UNION)
|
|
48
|
+
* 8..10: RBREAK_TAGs in src/vm.c (otherwise, set to 0)
|
|
49
|
+
*/
|
|
50
|
+
struct RBreak {
|
|
51
|
+
MRB_OBJECT_HEADER;
|
|
52
|
+
uintptr_t ci_break_index; // The top-level ci index to break. One before the return destination.
|
|
53
|
+
#ifndef MRB_USE_RBREAK_VALUE_UNION
|
|
54
|
+
mrb_value val;
|
|
55
|
+
#else
|
|
56
|
+
union mrb_value_union value;
|
|
57
|
+
#endif
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
#ifndef MRB_USE_RBREAK_VALUE_UNION
|
|
61
|
+
#define mrb_break_value_get(brk) ((brk)->val)
|
|
62
|
+
#define mrb_break_value_set(brk, v) ((brk)->val = v)
|
|
63
|
+
#else
|
|
64
|
+
#define RBREAK_VALUE_TT_MASK ((1 << 8) - 1)
|
|
65
|
+
static inline mrb_value
|
|
66
|
+
mrb_break_value_get(struct RBreak *brk)
|
|
67
|
+
{
|
|
68
|
+
mrb_value val;
|
|
69
|
+
val.value = brk->value;
|
|
70
|
+
val.tt = (enum mrb_vtype)(brk->flags & RBREAK_VALUE_TT_MASK);
|
|
71
|
+
return val;
|
|
72
|
+
}
|
|
73
|
+
static inline void
|
|
74
|
+
mrb_break_value_set(struct RBreak *brk, mrb_value val)
|
|
75
|
+
{
|
|
76
|
+
brk->value = val.value;
|
|
77
|
+
brk->flags &= ~RBREAK_VALUE_TT_MASK;
|
|
78
|
+
brk->flags |= val.tt;
|
|
79
|
+
}
|
|
80
|
+
#endif /* MRB_USE_RBREAK_VALUE_UNION */
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Error check
|
|
84
|
+
*
|
|
85
|
+
*/
|
|
86
|
+
/* clear error status in the mrb_state structure */
|
|
87
|
+
MRB_API void mrb_clear_error(mrb_state *mrb);
|
|
88
|
+
/* returns TRUE if error in the previous call; internally calls mrb_clear_error() */
|
|
89
|
+
MRB_API mrb_bool mrb_check_error(mrb_state *mrb);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Protect
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
typedef mrb_value mrb_protect_error_func(mrb_state *mrb, void *userdata);
|
|
96
|
+
MRB_API mrb_value mrb_protect_error(mrb_state *mrb, mrb_protect_error_func *body, void *userdata, mrb_bool *error);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Protect (takes mrb_value for body argument)
|
|
100
|
+
*
|
|
101
|
+
* Implemented in the mruby-error mrbgem
|
|
102
|
+
*/
|
|
103
|
+
MRB_API mrb_value mrb_protect(mrb_state *mrb, mrb_func_t body, mrb_value data, mrb_bool *state);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Ensure
|
|
107
|
+
*
|
|
108
|
+
* Implemented in the mruby-error mrbgem
|
|
109
|
+
*/
|
|
110
|
+
MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
|
|
111
|
+
mrb_func_t ensure, mrb_value e_data);
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Rescue
|
|
115
|
+
*
|
|
116
|
+
* Implemented in the mruby-error mrbgem
|
|
117
|
+
*/
|
|
118
|
+
MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
|
|
119
|
+
mrb_func_t rescue, mrb_value r_data);
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Rescue exception
|
|
123
|
+
*
|
|
124
|
+
* Implemented in the mruby-error mrbgem
|
|
125
|
+
*/
|
|
126
|
+
MRB_API mrb_value mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
|
|
127
|
+
mrb_func_t rescue, mrb_value r_data,
|
|
128
|
+
mrb_int len, struct RClass **classes);
|
|
129
|
+
|
|
130
|
+
MRB_END_DECL
|
|
131
|
+
|
|
132
|
+
#endif /* MRUBY_ERROR_H */
|