prism-cli 0.0.1
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/bin/prism +116 -0
- data/dist/prism.js +893 -0
- data/main.c +151 -0
- data/mruby/build/emscripten/lib/libmruby.a +0 -0
- data/mruby/include/mrbconf.h +149 -0
- data/mruby/include/mruby.h +1291 -0
- data/mruby/include/mruby/array.h +296 -0
- data/mruby/include/mruby/boxing_nan.h +102 -0
- data/mruby/include/mruby/boxing_no.h +56 -0
- data/mruby/include/mruby/boxing_word.h +144 -0
- data/mruby/include/mruby/class.h +97 -0
- data/mruby/include/mruby/common.h +77 -0
- data/mruby/include/mruby/compile.h +195 -0
- data/mruby/include/mruby/data.h +76 -0
- data/mruby/include/mruby/debug.h +66 -0
- data/mruby/include/mruby/dump.h +196 -0
- data/mruby/include/mruby/error.h +75 -0
- data/mruby/include/mruby/gc.h +91 -0
- data/mruby/include/mruby/hash.h +229 -0
- data/mruby/include/mruby/irep.h +75 -0
- data/mruby/include/mruby/istruct.h +47 -0
- data/mruby/include/mruby/khash.h +274 -0
- data/mruby/include/mruby/numeric.h +161 -0
- data/mruby/include/mruby/object.h +44 -0
- data/mruby/include/mruby/opcode.h +69 -0
- data/mruby/include/mruby/ops.h +117 -0
- data/mruby/include/mruby/proc.h +131 -0
- data/mruby/include/mruby/range.h +73 -0
- data/mruby/include/mruby/re.h +16 -0
- data/mruby/include/mruby/string.h +450 -0
- data/mruby/include/mruby/throw.h +55 -0
- data/mruby/include/mruby/value.h +313 -0
- data/mruby/include/mruby/variable.h +141 -0
- data/mruby/include/mruby/version.h +110 -0
- data/src/prism.rb +317 -0
- data/wasm-server.js +23 -0
- metadata +79 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
/*
|
2
|
+
** 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) = 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
|
+
static inline void
|
67
|
+
mrb_data_init(mrb_value v, void *ptr, const mrb_data_type *type)
|
68
|
+
{
|
69
|
+
mrb_assert(mrb_type(v) == MRB_TT_DATA);
|
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,66 @@
|
|
1
|
+
/*
|
2
|
+
** 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 = 1
|
20
|
+
} mrb_debug_line_type;
|
21
|
+
|
22
|
+
typedef struct mrb_irep_debug_info_line {
|
23
|
+
uint32_t start_pos;
|
24
|
+
uint16_t line;
|
25
|
+
} mrb_irep_debug_info_line;
|
26
|
+
|
27
|
+
typedef struct mrb_irep_debug_info_file {
|
28
|
+
uint32_t start_pos;
|
29
|
+
mrb_sym filename_sym;
|
30
|
+
uint32_t line_entry_count;
|
31
|
+
mrb_debug_line_type line_type;
|
32
|
+
union {
|
33
|
+
void *ptr;
|
34
|
+
mrb_irep_debug_info_line *flat_map;
|
35
|
+
uint16_t *ary;
|
36
|
+
} lines;
|
37
|
+
} mrb_irep_debug_info_file;
|
38
|
+
|
39
|
+
typedef struct mrb_irep_debug_info {
|
40
|
+
uint32_t pc_count;
|
41
|
+
uint16_t flen;
|
42
|
+
mrb_irep_debug_info_file **files;
|
43
|
+
} mrb_irep_debug_info;
|
44
|
+
|
45
|
+
/*
|
46
|
+
* get line from irep's debug info and program counter
|
47
|
+
* @return returns NULL if not found
|
48
|
+
*/
|
49
|
+
MRB_API const char *mrb_debug_get_filename(mrb_state *mrb, mrb_irep *irep, ptrdiff_t pc);
|
50
|
+
|
51
|
+
/*
|
52
|
+
* get line from irep's debug info and program counter
|
53
|
+
* @return returns -1 if not found
|
54
|
+
*/
|
55
|
+
MRB_API int32_t mrb_debug_get_line(mrb_state *mrb, mrb_irep *irep, ptrdiff_t pc);
|
56
|
+
|
57
|
+
MRB_API mrb_irep_debug_info *mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep);
|
58
|
+
MRB_API mrb_irep_debug_info_file *mrb_debug_info_append_file(
|
59
|
+
mrb_state *mrb, mrb_irep_debug_info *info,
|
60
|
+
const char *filename, uint16_t *lines,
|
61
|
+
uint32_t start_pos, uint32_t end_pos);
|
62
|
+
MRB_API void mrb_debug_info_free(mrb_state *mrb, mrb_irep_debug_info *d);
|
63
|
+
|
64
|
+
MRB_END_DECL
|
65
|
+
|
66
|
+
#endif /* MRUBY_DEBUG_H */
|
@@ -0,0 +1,196 @@
|
|
1
|
+
/*
|
2
|
+
** 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
|
+
#define DUMP_DEBUG_INFO 1
|
20
|
+
#define DUMP_ENDIAN_BIG 2
|
21
|
+
#define DUMP_ENDIAN_LIL 4
|
22
|
+
#define DUMP_ENDIAN_NAT 6
|
23
|
+
#define DUMP_ENDIAN_MASK 6
|
24
|
+
|
25
|
+
int mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size);
|
26
|
+
#ifndef MRB_DISABLE_STDIO
|
27
|
+
int mrb_dump_irep_binary(mrb_state*, mrb_irep*, uint8_t, FILE*);
|
28
|
+
int mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep*, uint8_t flags, FILE *f, const char *initname);
|
29
|
+
mrb_irep *mrb_read_irep_file(mrb_state*, FILE*);
|
30
|
+
MRB_API mrb_value mrb_load_irep_file(mrb_state*,FILE*);
|
31
|
+
MRB_API mrb_value mrb_load_irep_file_cxt(mrb_state*, FILE*, mrbc_context*);
|
32
|
+
#endif
|
33
|
+
MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*);
|
34
|
+
|
35
|
+
/* dump/load error code
|
36
|
+
*
|
37
|
+
* NOTE: MRB_DUMP_GENERAL_FAILURE is caused by
|
38
|
+
* unspecified issues like malloc failed.
|
39
|
+
*/
|
40
|
+
#define MRB_DUMP_OK 0
|
41
|
+
#define MRB_DUMP_GENERAL_FAILURE (-1)
|
42
|
+
#define MRB_DUMP_WRITE_FAULT (-2)
|
43
|
+
#define MRB_DUMP_READ_FAULT (-3)
|
44
|
+
#define MRB_DUMP_CRC_ERROR (-4)
|
45
|
+
#define MRB_DUMP_INVALID_FILE_HEADER (-5)
|
46
|
+
#define MRB_DUMP_INVALID_IREP (-6)
|
47
|
+
#define MRB_DUMP_INVALID_ARGUMENT (-7)
|
48
|
+
|
49
|
+
/* null symbol length */
|
50
|
+
#define MRB_DUMP_NULL_SYM_LEN 0xFFFF
|
51
|
+
|
52
|
+
/* Rite Binary File header */
|
53
|
+
#define RITE_BINARY_IDENT "RITE"
|
54
|
+
#define RITE_BINARY_IDENT_LIL "ETIR"
|
55
|
+
#define RITE_BINARY_FORMAT_VER "0006"
|
56
|
+
#define RITE_COMPILER_NAME "MATZ"
|
57
|
+
#define RITE_COMPILER_VERSION "0000"
|
58
|
+
|
59
|
+
#define RITE_VM_VER "0002"
|
60
|
+
|
61
|
+
#define RITE_BINARY_EOF "END\0"
|
62
|
+
#define RITE_SECTION_IREP_IDENT "IREP"
|
63
|
+
#define RITE_SECTION_LINENO_IDENT "LINE"
|
64
|
+
#define RITE_SECTION_DEBUG_IDENT "DBG\0"
|
65
|
+
#define RITE_SECTION_LV_IDENT "LVAR"
|
66
|
+
|
67
|
+
#define MRB_DUMP_DEFAULT_STR_LEN 128
|
68
|
+
#define MRB_DUMP_ALIGNMENT sizeof(uint32_t)
|
69
|
+
|
70
|
+
/* binary header */
|
71
|
+
struct rite_binary_header {
|
72
|
+
uint8_t binary_ident[4]; /* Binary Identifier */
|
73
|
+
uint8_t binary_version[4]; /* Binary Format Version */
|
74
|
+
uint8_t binary_crc[2]; /* Binary CRC */
|
75
|
+
uint8_t binary_size[4]; /* Binary Size */
|
76
|
+
uint8_t compiler_name[4]; /* Compiler name */
|
77
|
+
uint8_t compiler_version[4];
|
78
|
+
};
|
79
|
+
|
80
|
+
/* section header */
|
81
|
+
#define RITE_SECTION_HEADER \
|
82
|
+
uint8_t section_ident[4]; \
|
83
|
+
uint8_t section_size[4]
|
84
|
+
|
85
|
+
struct rite_section_header {
|
86
|
+
RITE_SECTION_HEADER;
|
87
|
+
};
|
88
|
+
|
89
|
+
struct rite_section_irep_header {
|
90
|
+
RITE_SECTION_HEADER;
|
91
|
+
|
92
|
+
uint8_t rite_version[4]; /* Rite Instruction Specification Version */
|
93
|
+
};
|
94
|
+
|
95
|
+
struct rite_section_lineno_header {
|
96
|
+
RITE_SECTION_HEADER;
|
97
|
+
};
|
98
|
+
|
99
|
+
struct rite_section_debug_header {
|
100
|
+
RITE_SECTION_HEADER;
|
101
|
+
};
|
102
|
+
|
103
|
+
struct rite_section_lv_header {
|
104
|
+
RITE_SECTION_HEADER;
|
105
|
+
};
|
106
|
+
|
107
|
+
#define RITE_LV_NULL_MARK UINT16_MAX
|
108
|
+
|
109
|
+
struct rite_binary_footer {
|
110
|
+
RITE_SECTION_HEADER;
|
111
|
+
};
|
112
|
+
|
113
|
+
static inline int
|
114
|
+
bigendian_p()
|
115
|
+
{
|
116
|
+
int i;
|
117
|
+
char *p;
|
118
|
+
|
119
|
+
i = 1;
|
120
|
+
p = (char*)&i;
|
121
|
+
return p[0]?0:1;
|
122
|
+
}
|
123
|
+
|
124
|
+
static inline size_t
|
125
|
+
uint8_to_bin(uint8_t s, uint8_t *bin)
|
126
|
+
{
|
127
|
+
*bin = s;
|
128
|
+
return sizeof(uint8_t);
|
129
|
+
}
|
130
|
+
|
131
|
+
static inline size_t
|
132
|
+
uint16_to_bin(uint16_t s, uint8_t *bin)
|
133
|
+
{
|
134
|
+
*bin++ = (s >> 8) & 0xff;
|
135
|
+
*bin = s & 0xff;
|
136
|
+
return sizeof(uint16_t);
|
137
|
+
}
|
138
|
+
|
139
|
+
static inline size_t
|
140
|
+
uint32_to_bin(uint32_t l, uint8_t *bin)
|
141
|
+
{
|
142
|
+
*bin++ = (l >> 24) & 0xff;
|
143
|
+
*bin++ = (l >> 16) & 0xff;
|
144
|
+
*bin++ = (l >> 8) & 0xff;
|
145
|
+
*bin = l & 0xff;
|
146
|
+
return sizeof(uint32_t);
|
147
|
+
}
|
148
|
+
|
149
|
+
static inline size_t
|
150
|
+
uint32l_to_bin(uint32_t l, uint8_t *bin)
|
151
|
+
{
|
152
|
+
bin[3] = (l >> 24) & 0xff;
|
153
|
+
bin[2] = (l >> 16) & 0xff;
|
154
|
+
bin[1] = (l >> 8) & 0xff;
|
155
|
+
bin[0] = l & 0xff;
|
156
|
+
return sizeof(uint32_t);
|
157
|
+
}
|
158
|
+
|
159
|
+
static inline uint32_t
|
160
|
+
bin_to_uint32(const uint8_t *bin)
|
161
|
+
{
|
162
|
+
return (uint32_t)bin[0] << 24 |
|
163
|
+
(uint32_t)bin[1] << 16 |
|
164
|
+
(uint32_t)bin[2] << 8 |
|
165
|
+
(uint32_t)bin[3];
|
166
|
+
}
|
167
|
+
|
168
|
+
static inline uint32_t
|
169
|
+
bin_to_uint32l(const uint8_t *bin)
|
170
|
+
{
|
171
|
+
return (uint32_t)bin[3] << 24 |
|
172
|
+
(uint32_t)bin[2] << 16 |
|
173
|
+
(uint32_t)bin[1] << 8 |
|
174
|
+
(uint32_t)bin[0];
|
175
|
+
}
|
176
|
+
|
177
|
+
static inline uint16_t
|
178
|
+
bin_to_uint16(const uint8_t *bin)
|
179
|
+
{
|
180
|
+
return (uint16_t)bin[0] << 8 |
|
181
|
+
(uint16_t)bin[1];
|
182
|
+
}
|
183
|
+
|
184
|
+
static inline uint8_t
|
185
|
+
bin_to_uint8(const uint8_t *bin)
|
186
|
+
{
|
187
|
+
return (uint8_t)bin[0];
|
188
|
+
}
|
189
|
+
|
190
|
+
MRB_END_DECL
|
191
|
+
|
192
|
+
/** @internal crc.c */
|
193
|
+
uint16_t
|
194
|
+
calc_crc_16_ccitt(const uint8_t *src, size_t nbytes, uint16_t crc);
|
195
|
+
|
196
|
+
#endif /* MRUBY_DUMP_H */
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/*
|
2
|
+
** 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
|
+
};
|
21
|
+
|
22
|
+
#define mrb_exc_ptr(v) ((struct RException*)mrb_ptr(v))
|
23
|
+
|
24
|
+
MRB_API void mrb_sys_fail(mrb_state *mrb, const char *mesg);
|
25
|
+
MRB_API mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str);
|
26
|
+
#define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit))
|
27
|
+
MRB_API mrb_value mrb_make_exception(mrb_state *mrb, mrb_int argc, const mrb_value *argv);
|
28
|
+
MRB_API mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc);
|
29
|
+
MRB_API mrb_value mrb_get_backtrace(mrb_state *mrb);
|
30
|
+
MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, const char *fmt, ...);
|
31
|
+
|
32
|
+
/* declaration for `fail` method */
|
33
|
+
MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value);
|
34
|
+
|
35
|
+
struct RBreak {
|
36
|
+
MRB_OBJECT_HEADER;
|
37
|
+
struct RProc *proc;
|
38
|
+
mrb_value val;
|
39
|
+
};
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Protect
|
43
|
+
*
|
44
|
+
* @mrbgem mruby-error
|
45
|
+
*/
|
46
|
+
MRB_API mrb_value mrb_protect(mrb_state *mrb, mrb_func_t body, mrb_value data, mrb_bool *state);
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Ensure
|
50
|
+
*
|
51
|
+
* @mrbgem mruby-error
|
52
|
+
*/
|
53
|
+
MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
|
54
|
+
mrb_func_t ensure, mrb_value e_data);
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Rescue
|
58
|
+
*
|
59
|
+
* @mrbgem mruby-error
|
60
|
+
*/
|
61
|
+
MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
|
62
|
+
mrb_func_t rescue, mrb_value r_data);
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Rescue exception
|
66
|
+
*
|
67
|
+
* @mrbgem mruby-error
|
68
|
+
*/
|
69
|
+
MRB_API mrb_value mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
|
70
|
+
mrb_func_t rescue, mrb_value r_data,
|
71
|
+
mrb_int len, struct RClass **classes);
|
72
|
+
|
73
|
+
MRB_END_DECL
|
74
|
+
|
75
|
+
#endif /* MRUBY_ERROR_H */
|
@@ -0,0 +1,91 @@
|
|
1
|
+
/*
|
2
|
+
** mruby/gc.h - garbage collector for mruby
|
3
|
+
**
|
4
|
+
** See Copyright Notice in mruby.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef MRUBY_GC_H
|
8
|
+
#define MRUBY_GC_H
|
9
|
+
|
10
|
+
#include "common.h"
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Uncommon memory management stuffs.
|
14
|
+
*/
|
15
|
+
MRB_BEGIN_DECL
|
16
|
+
|
17
|
+
|
18
|
+
struct mrb_state;
|
19
|
+
|
20
|
+
#define MRB_EACH_OBJ_OK 0
|
21
|
+
#define MRB_EACH_OBJ_BREAK 1
|
22
|
+
typedef int (mrb_each_object_callback)(struct mrb_state *mrb, struct RBasic *obj, void *data);
|
23
|
+
void mrb_objspace_each_objects(struct mrb_state *mrb, mrb_each_object_callback *callback, void *data);
|
24
|
+
MRB_API void mrb_free_context(struct mrb_state *mrb, struct mrb_context *c);
|
25
|
+
|
26
|
+
#ifndef MRB_GC_ARENA_SIZE
|
27
|
+
#define MRB_GC_ARENA_SIZE 100
|
28
|
+
#endif
|
29
|
+
|
30
|
+
typedef enum {
|
31
|
+
MRB_GC_STATE_ROOT = 0,
|
32
|
+
MRB_GC_STATE_MARK,
|
33
|
+
MRB_GC_STATE_SWEEP
|
34
|
+
} mrb_gc_state;
|
35
|
+
|
36
|
+
/* Disable MSVC warning "C4200: nonstandard extension used: zero-sized array
|
37
|
+
* in struct/union" when in C++ mode */
|
38
|
+
#ifdef _MSC_VER
|
39
|
+
#pragma warning(push)
|
40
|
+
#pragma warning(disable : 4200)
|
41
|
+
#endif
|
42
|
+
|
43
|
+
typedef struct mrb_heap_page {
|
44
|
+
struct RBasic *freelist;
|
45
|
+
struct mrb_heap_page *prev;
|
46
|
+
struct mrb_heap_page *next;
|
47
|
+
struct mrb_heap_page *free_next;
|
48
|
+
struct mrb_heap_page *free_prev;
|
49
|
+
mrb_bool old:1;
|
50
|
+
void *objects[];
|
51
|
+
} mrb_heap_page;
|
52
|
+
|
53
|
+
#ifdef _MSC_VER
|
54
|
+
#pragma warning(pop)
|
55
|
+
#endif
|
56
|
+
|
57
|
+
typedef struct mrb_gc {
|
58
|
+
mrb_heap_page *heaps; /* heaps for GC */
|
59
|
+
mrb_heap_page *sweeps;
|
60
|
+
mrb_heap_page *free_heaps;
|
61
|
+
size_t live; /* count of live objects */
|
62
|
+
#ifdef MRB_GC_FIXED_ARENA
|
63
|
+
struct RBasic *arena[MRB_GC_ARENA_SIZE]; /* GC protection array */
|
64
|
+
#else
|
65
|
+
struct RBasic **arena; /* GC protection array */
|
66
|
+
int arena_capa;
|
67
|
+
#endif
|
68
|
+
int arena_idx;
|
69
|
+
|
70
|
+
mrb_gc_state state; /* state of gc */
|
71
|
+
int current_white_part; /* make white object by white_part */
|
72
|
+
struct RBasic *gray_list; /* list of gray objects to be traversed incrementally */
|
73
|
+
struct RBasic *atomic_gray_list; /* list of objects to be traversed atomically */
|
74
|
+
size_t live_after_mark;
|
75
|
+
size_t threshold;
|
76
|
+
int interval_ratio;
|
77
|
+
int step_ratio;
|
78
|
+
mrb_bool iterating :1;
|
79
|
+
mrb_bool disabled :1;
|
80
|
+
mrb_bool full :1;
|
81
|
+
mrb_bool generational :1;
|
82
|
+
mrb_bool out_of_memory :1;
|
83
|
+
size_t majorgc_old_threshold;
|
84
|
+
} mrb_gc;
|
85
|
+
|
86
|
+
MRB_API mrb_bool
|
87
|
+
mrb_object_dead_p(struct mrb_state *mrb, struct RBasic *object);
|
88
|
+
|
89
|
+
MRB_END_DECL
|
90
|
+
|
91
|
+
#endif /* MRUBY_GC_H */
|