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.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +195 -0
  3. data/exe/portable-mruby +6 -0
  4. data/lib/portable_mruby/binary_manager.rb +225 -0
  5. data/lib/portable_mruby/builder.rb +97 -0
  6. data/lib/portable_mruby/bytecode_compiler.rb +19 -0
  7. data/lib/portable_mruby/c_generator.rb +94 -0
  8. data/lib/portable_mruby/cli.rb +136 -0
  9. data/lib/portable_mruby/version.rb +6 -0
  10. data/lib/portable_mruby.rb +15 -0
  11. data/vendor/mruby/bin/mrbc.com +0 -0
  12. data/vendor/mruby/include/mrbconf.h +230 -0
  13. data/vendor/mruby/include/mruby/array.h +303 -0
  14. data/vendor/mruby/include/mruby/boxing_nan.h +169 -0
  15. data/vendor/mruby/include/mruby/boxing_no.h +59 -0
  16. data/vendor/mruby/include/mruby/boxing_word.h +251 -0
  17. data/vendor/mruby/include/mruby/class.h +104 -0
  18. data/vendor/mruby/include/mruby/common.h +118 -0
  19. data/vendor/mruby/include/mruby/compile.h +185 -0
  20. data/vendor/mruby/include/mruby/data.h +76 -0
  21. data/vendor/mruby/include/mruby/debug.h +75 -0
  22. data/vendor/mruby/include/mruby/dump.h +159 -0
  23. data/vendor/mruby/include/mruby/endian.h +44 -0
  24. data/vendor/mruby/include/mruby/error.h +132 -0
  25. data/vendor/mruby/include/mruby/gc.h +72 -0
  26. data/vendor/mruby/include/mruby/gems/mruby-dir/include/dir_hal.h +79 -0
  27. data/vendor/mruby/include/mruby/gems/mruby-io/include/io_hal.h +451 -0
  28. data/vendor/mruby/include/mruby/gems/mruby-io/include/mruby/ext/io.h +76 -0
  29. data/vendor/mruby/include/mruby/gems/mruby-socket/include/socket_hal.h +83 -0
  30. data/vendor/mruby/include/mruby/gems/mruby-time/include/mruby/time.h +27 -0
  31. data/vendor/mruby/include/mruby/hash.h +234 -0
  32. data/vendor/mruby/include/mruby/internal.h +274 -0
  33. data/vendor/mruby/include/mruby/irep.h +142 -0
  34. data/vendor/mruby/include/mruby/istruct.h +50 -0
  35. data/vendor/mruby/include/mruby/khash.h +455 -0
  36. data/vendor/mruby/include/mruby/mempool.h +19 -0
  37. data/vendor/mruby/include/mruby/numeric.h +174 -0
  38. data/vendor/mruby/include/mruby/object.h +45 -0
  39. data/vendor/mruby/include/mruby/opcode.h +69 -0
  40. data/vendor/mruby/include/mruby/ops.h +120 -0
  41. data/vendor/mruby/include/mruby/presym/disable.h +72 -0
  42. data/vendor/mruby/include/mruby/presym/enable.h +39 -0
  43. data/vendor/mruby/include/mruby/presym/id.h +1423 -0
  44. data/vendor/mruby/include/mruby/presym/scanning.h +81 -0
  45. data/vendor/mruby/include/mruby/presym/table.h +2847 -0
  46. data/vendor/mruby/include/mruby/presym.h +41 -0
  47. data/vendor/mruby/include/mruby/proc.h +186 -0
  48. data/vendor/mruby/include/mruby/range.h +77 -0
  49. data/vendor/mruby/include/mruby/re.h +16 -0
  50. data/vendor/mruby/include/mruby/string.h +428 -0
  51. data/vendor/mruby/include/mruby/throw.h +57 -0
  52. data/vendor/mruby/include/mruby/value.h +471 -0
  53. data/vendor/mruby/include/mruby/variable.h +108 -0
  54. data/vendor/mruby/include/mruby/version.h +143 -0
  55. data/vendor/mruby/include/mruby.h +1614 -0
  56. data/vendor/mruby/lib/libmruby.a +0 -0
  57. metadata +102 -0
@@ -0,0 +1,428 @@
1
+ /**
2
+ ** @file mruby/string.h - String class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_STRING_H
8
+ #define MRUBY_STRING_H
9
+
10
+ #include "common.h"
11
+
12
+ /**
13
+ * String class
14
+ */
15
+ MRB_BEGIN_DECL
16
+
17
+ extern const char mrb_digitmap[];
18
+
19
+ #define RSTRING_EMBED_LEN_MAX \
20
+ ((mrb_int)(sizeof(void*) * 3 + sizeof(void*) - 32 / CHAR_BIT - 1))
21
+
22
+ struct RString {
23
+ MRB_OBJECT_HEADER;
24
+ union {
25
+ struct {
26
+ mrb_ssize len;
27
+ union {
28
+ mrb_ssize capa;
29
+ struct mrb_shared_string *shared;
30
+ struct RString *fshared;
31
+ } aux;
32
+ char *ptr;
33
+ } heap;
34
+ } as;
35
+ };
36
+ struct RStringEmbed {
37
+ MRB_OBJECT_HEADER;
38
+ char ary[RSTRING_EMBED_LEN_MAX+1];
39
+ };
40
+
41
+ #define RSTR_SET_TYPE(s, type) ((s)->flags = ((s)->flags & ~(MRB_STR_TYPE_MASK|MRB_STR_EMBED_LEN_MASK)) | MRB_STR_##type)
42
+
43
+ #define MRB_STR_NORMAL 0
44
+ #define MRB_STR_SHARED 1
45
+ #define MRB_STR_FSHARED 2
46
+ #define MRB_STR_NOFREE 4
47
+ #define MRB_STR_EMBED 8
48
+ #define MRB_STR_TYPE_MASK 15
49
+
50
+ #define MRB_STR_EMBED_LEN_SHIFT 6
51
+ #define MRB_STR_EMBED_LEN_BITS 5
52
+ #define MRB_STR_EMBED_LEN_MASK (((1 << MRB_STR_EMBED_LEN_BITS) - 1) << MRB_STR_EMBED_LEN_SHIFT)
53
+
54
+ #define MRB_STR_BINARY 16
55
+ #define MRB_STR_SINGLE_BYTE 32
56
+ #define MRB_STR_STATE_MASK 48
57
+
58
+ #define RSTR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED)
59
+ #define RSTR_SET_EMBED_FLAG(s) ((s)->flags |= MRB_STR_EMBED)
60
+ #define RSTR_SET_EMBED_LEN(s, n) do {\
61
+ size_t tmp_n = (n);\
62
+ (s)->flags &= ~MRB_STR_EMBED_LEN_MASK;\
63
+ (s)->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\
64
+ } while (0)
65
+ #define RSTR_SET_LEN(s, n) do {\
66
+ if (RSTR_EMBED_P(s)) {\
67
+ RSTR_SET_EMBED_LEN((s),(n));\
68
+ }\
69
+ else {\
70
+ (s)->as.heap.len = (mrb_ssize)(n);\
71
+ }\
72
+ } while (0)
73
+ #define RSTR_EMBED_PTR(s) (((struct RStringEmbed*)(s))->ary)
74
+ #define RSTR_EMBED_LEN(s)\
75
+ (mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT)
76
+ #define RSTR_EMBEDDABLE_P(len) ((len) <= RSTRING_EMBED_LEN_MAX)
77
+
78
+ #define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_PTR(s) : (s)->as.heap.ptr)
79
+ #define RSTR_LEN(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len)
80
+ #define RSTR_CAPA(s) (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa)
81
+
82
+ #define RSTR_SHARED_P(s) ((s)->flags & MRB_STR_SHARED)
83
+ #define RSTR_FSHARED_P(s) ((s)->flags & MRB_STR_FSHARED)
84
+ #define RSTR_NOFREE_P(s) ((s)->flags & MRB_STR_NOFREE)
85
+
86
+ #ifdef MRB_UTF8_STRING
87
+ # define RSTR_SINGLE_BYTE_P(s) ((s)->flags & MRB_STR_SINGLE_BYTE)
88
+ # define RSTR_SET_SINGLE_BYTE_FLAG(s) ((s)->flags |= MRB_STR_SINGLE_BYTE)
89
+ # define RSTR_UNSET_SINGLE_BYTE_FLAG(s) ((s)->flags &= ~MRB_STR_SINGLE_BYTE)
90
+ # define RSTR_WRITE_SINGLE_BYTE_FLAG(s, v) (RSTR_UNSET_SINGLE_BYTE_FLAG(s), (s)->flags |= v)
91
+ # define RSTR_COPY_SINGLE_BYTE_FLAG(dst, src) RSTR_WRITE_SINGLE_BYTE_FLAG(dst, RSTR_SINGLE_BYTE_P(src))
92
+ #else
93
+ # define RSTR_SINGLE_BYTE_P(s) TRUE
94
+ # define RSTR_SET_SINGLE_BYTE_FLAG(s) (void)0
95
+ # define RSTR_UNSET_SINGLE_BYTE_FLAG(s) (void)0
96
+ # define RSTR_WRITE_SINGLE_BYTE_FLAG(s, v) (void)0
97
+ # define RSTR_COPY_SINGLE_BYTE_FLAG(dst, src) (void)0
98
+ #endif
99
+ #define RSTR_SET_ASCII_FLAG(s) RSTR_SET_SINGLE_BYTE_FLAG(s)
100
+ #define RSTR_BINARY_P(s) ((s)->flags & MRB_STR_BINARY)
101
+
102
+ /**
103
+ * Returns a pointer from a Ruby string
104
+ */
105
+ #define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s)))
106
+ #define RSTRING(s) mrb_str_ptr(s)
107
+ #define RSTRING_PTR(s) RSTR_PTR(RSTRING(s))
108
+ #define RSTRING_EMBED_LEN(s) RSTR_EMBED_LEN(RSTRING(s))
109
+ #define RSTRING_LEN(s) RSTR_LEN(RSTRING(s))
110
+ #define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s))
111
+ #define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s))
112
+ #define RSTRING_CSTR(mrb,s) mrb_string_cstr(mrb, s)
113
+
114
+ MRB_API void mrb_str_modify(mrb_state *mrb, struct RString *s);
115
+ /* mrb_str_modify() with keeping ASCII flag if set */
116
+ MRB_API void mrb_str_modify_keep_ascii(mrb_state *mrb, struct RString *s);
117
+
118
+ /**
119
+ * Finds the index of a substring in a string
120
+ */
121
+ MRB_API mrb_int mrb_str_index(mrb_state *mrb, mrb_value str, const char *p, mrb_int len, mrb_int offset);
122
+ #define mrb_str_index_lit(mrb, str, lit, off) mrb_str_index(mrb, str, lit, mrb_strlen_lit(lit), off);
123
+
124
+ /**
125
+ * Appends self to other. Returns self as a concatenated string.
126
+ *
127
+ *
128
+ * Example:
129
+ *
130
+ * int
131
+ * main(int argc,
132
+ * char **argv)
133
+ * {
134
+ * // Variable declarations.
135
+ * mrb_value str1;
136
+ * mrb_value str2;
137
+ *
138
+ * mrb_state *mrb = mrb_open();
139
+ * if (!mrb)
140
+ * {
141
+ * // handle error
142
+ * }
143
+ *
144
+ * // Creates new Ruby strings.
145
+ * str1 = mrb_str_new_lit(mrb, "abc");
146
+ * str2 = mrb_str_new_lit(mrb, "def");
147
+ *
148
+ * // Concatenates str2 to str1.
149
+ * mrb_str_concat(mrb, str1, str2);
150
+ *
151
+ * // Prints new Concatenated Ruby string.
152
+ * mrb_p(mrb, str1);
153
+ *
154
+ * mrb_close(mrb);
155
+ * return 0;
156
+ * }
157
+ *
158
+ * Result:
159
+ *
160
+ * => "abcdef"
161
+ *
162
+ * @param mrb The current mruby state.
163
+ * @param self String to concatenate.
164
+ * @param other String to append to self.
165
+ * @return [mrb_value] Returns a new String appending other to self.
166
+ */
167
+ MRB_API void mrb_str_concat(mrb_state *mrb, mrb_value self, mrb_value other);
168
+
169
+ /**
170
+ * Adds two strings together.
171
+ *
172
+ *
173
+ * Example:
174
+ *
175
+ * int
176
+ * main(int argc,
177
+ * char **argv)
178
+ * {
179
+ * // Variable declarations.
180
+ * mrb_value a;
181
+ * mrb_value b;
182
+ * mrb_value c;
183
+ *
184
+ * mrb_state *mrb = mrb_open();
185
+ * if (!mrb)
186
+ * {
187
+ * // handle error
188
+ * }
189
+ *
190
+ * // Creates two Ruby strings from the passed in C strings.
191
+ * a = mrb_str_new_lit(mrb, "abc");
192
+ * b = mrb_str_new_lit(mrb, "def");
193
+ *
194
+ * // Prints both C strings.
195
+ * mrb_p(mrb, a);
196
+ * mrb_p(mrb, b);
197
+ *
198
+ * // Concatenates both Ruby strings.
199
+ * c = mrb_str_plus(mrb, a, b);
200
+ *
201
+ * // Prints new Concatenated Ruby string.
202
+ * mrb_p(mrb, c);
203
+ *
204
+ * mrb_close(mrb);
205
+ * return 0;
206
+ * }
207
+ *
208
+ *
209
+ * Result:
210
+ *
211
+ * => "abc" # First string
212
+ * => "def" # Second string
213
+ * => "abcdef" # First & Second concatenated.
214
+ *
215
+ * @param mrb The current mruby state.
216
+ * @param a First string to concatenate.
217
+ * @param b Second string to concatenate.
218
+ * @return [mrb_value] Returns a new String containing a concatenated to b.
219
+ */
220
+ MRB_API mrb_value mrb_str_plus(mrb_state *mrb, mrb_value a, mrb_value b);
221
+
222
+ /**
223
+ * Converts pointer into a Ruby string.
224
+ *
225
+ * @param mrb The current mruby state.
226
+ * @param p The pointer to convert to Ruby string.
227
+ * @return [mrb_value] Returns a new Ruby String.
228
+ */
229
+ MRB_API mrb_value mrb_ptr_to_str(mrb_state *mrb, void *p);
230
+
231
+ /**
232
+ * Returns an object as a Ruby string.
233
+ *
234
+ * @param mrb The current mruby state.
235
+ * @param obj An object to return as a Ruby string.
236
+ * @return [mrb_value] An object as a Ruby string.
237
+ */
238
+ MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj);
239
+
240
+ /**
241
+ * Resizes the string's length. Returns the amount of characters
242
+ * in the specified by len.
243
+ *
244
+ * Example:
245
+ *
246
+ * int
247
+ * main(int argc,
248
+ * char **argv)
249
+ * {
250
+ * // Variable declaration.
251
+ * mrb_value str;
252
+ *
253
+ * mrb_state *mrb = mrb_open();
254
+ * if (!mrb)
255
+ * {
256
+ * // handle error
257
+ * }
258
+ * // Creates a new string.
259
+ * str = mrb_str_new_lit(mrb, "Hello, world!");
260
+ * // Returns 5 characters of
261
+ * mrb_str_resize(mrb, str, 5);
262
+ * mrb_p(mrb, str);
263
+ *
264
+ * mrb_close(mrb);
265
+ * return 0;
266
+ * }
267
+ *
268
+ * Result:
269
+ *
270
+ * => "Hello"
271
+ *
272
+ * @param mrb The current mruby state.
273
+ * @param str The Ruby string to resize.
274
+ * @param len The length.
275
+ * @return [mrb_value] An object as a Ruby string.
276
+ */
277
+ MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len);
278
+
279
+ /**
280
+ * Returns a sub string.
281
+ *
282
+ * Example:
283
+ *
284
+ * int
285
+ * main(int argc,
286
+ * char const **argv)
287
+ * {
288
+ * // Variable declarations.
289
+ * mrb_value str1;
290
+ * mrb_value str2;
291
+ *
292
+ * mrb_state *mrb = mrb_open();
293
+ * if (!mrb)
294
+ * {
295
+ * // handle error
296
+ * }
297
+ * // Creates new string.
298
+ * str1 = mrb_str_new_lit(mrb, "Hello, world!");
299
+ * // Returns a sub-string within the range of 0..2
300
+ * str2 = mrb_str_substr(mrb, str1, 0, 2);
301
+ *
302
+ * // Prints sub-string.
303
+ * mrb_p(mrb, str2);
304
+ *
305
+ * mrb_close(mrb);
306
+ * return 0;
307
+ * }
308
+ *
309
+ * Result:
310
+ *
311
+ * => "He"
312
+ *
313
+ * @param mrb The current mruby state.
314
+ * @param str Ruby string.
315
+ * @param beg The beginning point of the sub-string.
316
+ * @param len The end point of the sub-string.
317
+ * @return [mrb_value] An object as a Ruby sub-string.
318
+ */
319
+ MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len);
320
+
321
+ MRB_API mrb_value mrb_str_new_capa(mrb_state *mrb, mrb_int capa);
322
+ #define mrb_str_buf_new(mrb, capa) mrb_str_new_capa(mrb, (capa))
323
+
324
+ /* NULL terminated C string from mrb_value */
325
+ MRB_API const char *mrb_string_cstr(mrb_state *mrb, mrb_value str);
326
+ /* NULL terminated C string from mrb_value; `str` will be updated */
327
+ MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *str);
328
+ /* obsolete: use RSTRING_PTR() */
329
+ #define mrb_string_value_ptr(mrb, str) RSTRING_PTR(str)
330
+ /* obsolete: use RSTRING_LEN() */
331
+ #define mrb_string_value_len(mrb, str) RSTRING_LEN(str)
332
+ /* obsolete: substituted by a macro; shall be removed */
333
+ #define mrb_str_strlen(mrb, s) strlen(RSTR_PTR(s))
334
+
335
+ /**
336
+ * Duplicates a string object.
337
+ *
338
+ *
339
+ * @param mrb The current mruby state.
340
+ * @param str Ruby string.
341
+ * @return [mrb_value] Duplicated Ruby string.
342
+ */
343
+ MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str);
344
+
345
+ /**
346
+ * Returns a symbol from a passed in Ruby string.
347
+ *
348
+ * @param mrb The current mruby state.
349
+ * @param self Ruby string.
350
+ * @return [mrb_value] A symbol.
351
+ */
352
+ MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self);
353
+
354
+ MRB_API mrb_value mrb_str_to_integer(mrb_state *mrb, mrb_value str, mrb_int base, mrb_bool badcheck);
355
+ /* obsolete: use mrb_str_to_integer() */
356
+ #define mrb_str_to_inum(mrb, str, base, badcheck) mrb_str_to_integer(mrb, str, base, badcheck)
357
+ MRB_API double mrb_str_to_dbl(mrb_state *mrb, mrb_value str, mrb_bool badcheck);
358
+
359
+ /**
360
+ * Returns true if the strings match and false if the strings don't match.
361
+ *
362
+ * @param mrb The current mruby state.
363
+ * @param str1 Ruby string to compare.
364
+ * @param str2 Ruby string to compare.
365
+ * @return [mrb_value] boolean value.
366
+ */
367
+ MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2);
368
+
369
+ /**
370
+ * Returns a concatenated string comprised of a Ruby string and a C string.
371
+ *
372
+ * @param mrb The current mruby state.
373
+ * @param str Ruby string.
374
+ * @param ptr A C string.
375
+ * @param len length of C string.
376
+ * @return [mrb_value] A Ruby string.
377
+ * @see mrb_str_cat_cstr
378
+ */
379
+ MRB_API mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len);
380
+
381
+ /**
382
+ * Returns a concatenated string comprised of a Ruby string and a C string.
383
+ *
384
+ * @param mrb The current mruby state.
385
+ * @param str Ruby string.
386
+ * @param ptr A C string.
387
+ * @return [mrb_value] A Ruby string.
388
+ * @see mrb_str_cat
389
+ */
390
+ MRB_API mrb_value mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr);
391
+ MRB_API mrb_value mrb_str_cat_str(mrb_state *mrb, mrb_value str, mrb_value str2);
392
+ #define mrb_str_cat_lit(mrb, str, lit) mrb_str_cat(mrb, str, lit, mrb_strlen_lit(lit))
393
+
394
+ /**
395
+ * Adds str2 to the end of str1.
396
+ */
397
+ MRB_API mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2);
398
+
399
+ /**
400
+ * Returns 0 if both Ruby strings are equal. Returns a value < 0 if Ruby str1 is less than Ruby str2. Returns a value > 0 if Ruby str2 is greater than Ruby str1.
401
+ */
402
+ MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
403
+
404
+ /**
405
+ * Returns a newly allocated C string from a Ruby string.
406
+ * This is an utility function to pass a Ruby string to C library functions.
407
+ *
408
+ * - Returned string does not contain any NUL characters (but terminator).
409
+ * - It raises an ArgumentError exception if Ruby string contains
410
+ * NUL characters.
411
+ * - Returned string will be freed automatically on next GC.
412
+ * - Caller can modify returned string without affecting Ruby string
413
+ * (e.g. it can be used for mkstemp(3)).
414
+ *
415
+ * @param mrb The current mruby state.
416
+ * @param str Ruby string. Must be an instance of String.
417
+ * @return [char *] A newly allocated C string.
418
+ */
419
+ MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str);
420
+
421
+ /* For backward compatibility */
422
+ #define mrb_str_cat2(mrb, str, ptr) mrb_str_cat_cstr(mrb, str, ptr)
423
+ #define mrb_str_buf_cat(mrb, str, ptr, len) mrb_str_cat(mrb, str, ptr, len)
424
+ #define mrb_str_buf_append(mrb, str, str2) mrb_str_cat_str(mrb, str, str2)
425
+
426
+ MRB_END_DECL
427
+
428
+ #endif /* MRUBY_STRING_H */
@@ -0,0 +1,57 @@
1
+ /**
2
+ ** @file mruby/throw.h - mruby exception throwing handler
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRB_THROW_H
8
+ #define MRB_THROW_H
9
+
10
+ #if defined(MRB_USE_CXX_ABI) && !defined(__cplusplus)
11
+ # error Trying to use C++ exception handling in C code
12
+ #endif
13
+
14
+ #if defined(MRB_USE_CXX_EXCEPTION)
15
+
16
+ # if defined(__cplusplus)
17
+
18
+ #define MRB_TRY(buf) try {
19
+ #define MRB_CATCH(buf) } catch(mrb_jmpbuf *e) { if (e != (buf)) { throw e; }
20
+ #define MRB_END_EXC(buf) }
21
+
22
+ #define MRB_THROW(buf) throw(buf)
23
+ typedef void *mrb_jmpbuf_impl;
24
+
25
+ # else
26
+ # error "need to be compiled with C++ compiler"
27
+ # endif /* __cplusplus */
28
+
29
+ #else
30
+
31
+ #include <setjmp.h>
32
+
33
+ #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
34
+ #define MRB_SETJMP _setjmp
35
+ #define MRB_LONGJMP _longjmp
36
+ #elif defined(__MINGW64__) && !defined(_M_ARM64) && defined(__GNUC__) && __GNUC__ >= 4
37
+ #define MRB_SETJMP __builtin_setjmp
38
+ #define MRB_LONGJMP __builtin_longjmp
39
+ #else
40
+ #define MRB_SETJMP setjmp
41
+ #define MRB_LONGJMP longjmp
42
+ #endif
43
+
44
+ #define MRB_TRY(buf) if (MRB_SETJMP((buf)->impl) == 0) {
45
+ #define MRB_CATCH(buf) } else {
46
+ #define MRB_END_EXC(buf) }
47
+
48
+ #define MRB_THROW(buf) MRB_LONGJMP((buf)->impl, 1);
49
+ #define mrb_jmpbuf_impl jmp_buf
50
+
51
+ #endif
52
+
53
+ struct mrb_jmpbuf {
54
+ mrb_jmpbuf_impl impl;
55
+ };
56
+
57
+ #endif /* MRB_THROW_H */