ruby2d 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/assets/README.md +8 -0
  3. data/assets/ios/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
  4. data/assets/ios/Assets.xcassets/Contents.json +6 -0
  5. data/assets/ios/Base.lproj/LaunchScreen.storyboard +27 -0
  6. data/assets/ios/Info.plist +43 -0
  7. data/assets/ios/MRuby.framework/Headers/mrbconf.h +145 -0
  8. data/assets/ios/MRuby.framework/Headers/mruby.h +1279 -0
  9. data/assets/ios/MRuby.framework/Headers/mruby/array.h +279 -0
  10. data/assets/ios/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
  11. data/assets/ios/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
  12. data/assets/ios/MRuby.framework/Headers/mruby/boxing_word.h +136 -0
  13. data/assets/ios/MRuby.framework/Headers/mruby/class.h +94 -0
  14. data/assets/ios/MRuby.framework/Headers/mruby/common.h +72 -0
  15. data/assets/ios/MRuby.framework/Headers/mruby/compile.h +194 -0
  16. data/assets/ios/MRuby.framework/Headers/mruby/data.h +75 -0
  17. data/assets/ios/MRuby.framework/Headers/mruby/debug.h +66 -0
  18. data/assets/ios/MRuby.framework/Headers/mruby/dump.h +196 -0
  19. data/assets/ios/MRuby.framework/Headers/mruby/error.h +75 -0
  20. data/assets/ios/MRuby.framework/Headers/mruby/gc.h +91 -0
  21. data/assets/ios/MRuby.framework/Headers/mruby/hash.h +182 -0
  22. data/assets/ios/MRuby.framework/Headers/mruby/irep.h +62 -0
  23. data/assets/ios/MRuby.framework/Headers/mruby/istruct.h +47 -0
  24. data/assets/ios/MRuby.framework/Headers/mruby/khash.h +274 -0
  25. data/assets/ios/MRuby.framework/Headers/mruby/numeric.h +161 -0
  26. data/assets/ios/MRuby.framework/Headers/mruby/object.h +45 -0
  27. data/assets/ios/MRuby.framework/Headers/mruby/opcode.h +161 -0
  28. data/assets/ios/MRuby.framework/Headers/mruby/proc.h +131 -0
  29. data/assets/ios/MRuby.framework/Headers/mruby/range.h +49 -0
  30. data/assets/ios/MRuby.framework/Headers/mruby/re.h +16 -0
  31. data/assets/ios/MRuby.framework/Headers/mruby/string.h +440 -0
  32. data/assets/ios/MRuby.framework/Headers/mruby/throw.h +55 -0
  33. data/assets/ios/MRuby.framework/Headers/mruby/value.h +309 -0
  34. data/assets/ios/MRuby.framework/Headers/mruby/variable.h +138 -0
  35. data/assets/ios/MRuby.framework/Headers/mruby/version.h +110 -0
  36. data/assets/ios/MRuby.framework/Info.plist +20 -0
  37. data/assets/ios/MRuby.framework/MRuby +0 -0
  38. data/assets/ios/MyApp.xcodeproj/project.pbxproj +362 -0
  39. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  40. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
  41. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcuserdata/Tom.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  42. data/assets/ios/MyApp.xcodeproj/xcuserdata/Tom.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  43. data/assets/ios/main.c +1 -0
  44. data/assets/opal.js +8434 -6329
  45. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +12 -0
  46. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json +6 -0
  47. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json +17 -0
  48. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +12 -0
  49. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json +6 -0
  50. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +12 -0
  51. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json +6 -0
  52. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +12 -0
  53. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json +6 -0
  54. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json +17 -0
  55. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +12 -0
  56. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json +6 -0
  57. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +12 -0
  58. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json +6 -0
  59. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json +32 -0
  60. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json +12 -0
  61. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json +12 -0
  62. data/assets/tvos/Assets.xcassets/Contents.json +6 -0
  63. data/assets/tvos/Assets.xcassets/LaunchImage.launchimage/Contents.json +15 -0
  64. data/assets/tvos/Info.plist +30 -0
  65. data/assets/tvos/MRuby.framework/Headers/mrbconf.h +145 -0
  66. data/assets/tvos/MRuby.framework/Headers/mruby.h +1279 -0
  67. data/assets/tvos/MRuby.framework/Headers/mruby/array.h +279 -0
  68. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
  69. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
  70. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_word.h +136 -0
  71. data/assets/tvos/MRuby.framework/Headers/mruby/class.h +94 -0
  72. data/assets/tvos/MRuby.framework/Headers/mruby/common.h +72 -0
  73. data/assets/tvos/MRuby.framework/Headers/mruby/compile.h +194 -0
  74. data/assets/tvos/MRuby.framework/Headers/mruby/data.h +75 -0
  75. data/assets/tvos/MRuby.framework/Headers/mruby/debug.h +66 -0
  76. data/assets/tvos/MRuby.framework/Headers/mruby/dump.h +196 -0
  77. data/assets/tvos/MRuby.framework/Headers/mruby/error.h +75 -0
  78. data/assets/tvos/MRuby.framework/Headers/mruby/gc.h +91 -0
  79. data/assets/tvos/MRuby.framework/Headers/mruby/hash.h +182 -0
  80. data/assets/tvos/MRuby.framework/Headers/mruby/irep.h +62 -0
  81. data/assets/tvos/MRuby.framework/Headers/mruby/istruct.h +47 -0
  82. data/assets/tvos/MRuby.framework/Headers/mruby/khash.h +274 -0
  83. data/assets/tvos/MRuby.framework/Headers/mruby/numeric.h +161 -0
  84. data/assets/tvos/MRuby.framework/Headers/mruby/object.h +45 -0
  85. data/assets/tvos/MRuby.framework/Headers/mruby/opcode.h +161 -0
  86. data/assets/tvos/MRuby.framework/Headers/mruby/proc.h +131 -0
  87. data/assets/tvos/MRuby.framework/Headers/mruby/range.h +49 -0
  88. data/assets/tvos/MRuby.framework/Headers/mruby/re.h +16 -0
  89. data/assets/tvos/MRuby.framework/Headers/mruby/string.h +440 -0
  90. data/assets/tvos/MRuby.framework/Headers/mruby/throw.h +55 -0
  91. data/assets/tvos/MRuby.framework/Headers/mruby/value.h +309 -0
  92. data/assets/tvos/MRuby.framework/Headers/mruby/variable.h +138 -0
  93. data/assets/tvos/MRuby.framework/Headers/mruby/version.h +110 -0
  94. data/assets/tvos/MRuby.framework/Info.plist +20 -0
  95. data/assets/tvos/MRuby.framework/MRuby +0 -0
  96. data/assets/tvos/MyApp.xcodeproj/project.pbxproj +344 -0
  97. data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  98. data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
  99. data/assets/tvos/main.c +1 -0
  100. data/bin/ruby2d +219 -64
  101. data/ext/ruby2d/extconf.rb +1 -1
  102. data/ext/ruby2d/ruby2d.c +117 -19
  103. data/lib/ruby2d/color.rb +1 -1
  104. data/lib/ruby2d/version.rb +1 -1
  105. data/lib/ruby2d/window.rb +16 -10
  106. metadata +102 -5
@@ -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 "0004"
56
+ #define RITE_COMPILER_NAME "MATZ"
57
+ #define RITE_COMPILER_VERSION "0000"
58
+
59
+ #define RITE_VM_VER "0000"
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 */
@@ -0,0 +1,182 @@
1
+ /*
2
+ ** mruby/hash.h - Hash class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_HASH_H
8
+ #define MRUBY_HASH_H
9
+
10
+ #include "common.h"
11
+ #include <mruby/khash.h>
12
+
13
+ /**
14
+ * Hash class
15
+ */
16
+ MRB_BEGIN_DECL
17
+
18
+ struct RHash {
19
+ MRB_OBJECT_HEADER;
20
+ struct iv_tbl *iv;
21
+ struct kh_ht *ht;
22
+ };
23
+
24
+ #define mrb_hash_ptr(v) ((struct RHash*)(mrb_ptr(v)))
25
+ #define mrb_hash_value(p) mrb_obj_value((void*)(p))
26
+
27
+ MRB_API mrb_value mrb_hash_new_capa(mrb_state*, mrb_int);
28
+
29
+ /*
30
+ * Initializes a new hash.
31
+ *
32
+ * Equivalent to:
33
+ *
34
+ * Hash.new
35
+ *
36
+ * @param mrb The mruby state reference.
37
+ * @return The initialized hash.
38
+ */
39
+ MRB_API mrb_value mrb_hash_new(mrb_state *mrb);
40
+
41
+ /*
42
+ * Sets a keys and values to hashes.
43
+ *
44
+ * Equivalent to:
45
+ *
46
+ * hash[key] = val
47
+ *
48
+ * @param mrb The mruby state reference.
49
+ * @param hash The target hash.
50
+ * @param key The key to set.
51
+ * @param val The value to set.
52
+ * @return The value.
53
+ */
54
+ MRB_API void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val);
55
+
56
+ /*
57
+ * Gets a value from a key. If the key is not found, the default of the
58
+ * hash is used.
59
+ *
60
+ * Equivalent to:
61
+ *
62
+ * hash[key]
63
+ *
64
+ * @param mrb The mruby state reference.
65
+ * @param hash The target hash.
66
+ * @param key The key to get.
67
+ * @return The found value.
68
+ */
69
+ MRB_API mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key);
70
+
71
+ /*
72
+ * Gets a value from a key. If the key is not found, the default parameter is
73
+ * used.
74
+ *
75
+ * Equivalent to:
76
+ *
77
+ * hash.hash_key?(key) ? hash[key] : def
78
+ *
79
+ * @param mrb The mruby state reference.
80
+ * @param hash The target hash.
81
+ * @param key The key to get.
82
+ * @param def The default value.
83
+ * @return The found value.
84
+ */
85
+ MRB_API mrb_value mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value def);
86
+
87
+ /*
88
+ * Deletes hash key and value pair.
89
+ *
90
+ * Equivalent to:
91
+ *
92
+ * hash.delete(key)
93
+ *
94
+ * @param mrb The mruby state reference.
95
+ * @param hash The target hash.
96
+ * @param key The key to delete.
97
+ * @return The deleted value.
98
+ */
99
+ MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key);
100
+
101
+ /*
102
+ * Gets an array of keys.
103
+ *
104
+ * Equivalent to:
105
+ *
106
+ * hash.keys
107
+ *
108
+ * @param mrb The mruby state reference.
109
+ * @param hash The target hash.
110
+ * @return An array with the keys of the hash.
111
+ */
112
+ MRB_API mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash);
113
+ MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
114
+
115
+ /*
116
+ * Check if the hash is empty
117
+ *
118
+ * Equivalent to:
119
+ *
120
+ * hash.empty?
121
+ *
122
+ * @param mrb The mruby state reference.
123
+ * @param self The target hash.
124
+ * @return True if the hash is empty, false otherwise.
125
+ */
126
+ MRB_API mrb_value mrb_hash_empty_p(mrb_state *mrb, mrb_value self);
127
+
128
+ /*
129
+ * Gets an array of values.
130
+ *
131
+ * Equivalent to:
132
+ *
133
+ * hash.values
134
+ *
135
+ * @param mrb The mruby state reference.
136
+ * @param hash The target hash.
137
+ * @return An array with the values of the hash.
138
+ */
139
+ MRB_API mrb_value mrb_hash_values(mrb_state *mrb, mrb_value hash);
140
+
141
+ /*
142
+ * Clears the hash.
143
+ *
144
+ * Equivalent to:
145
+ *
146
+ * hash.clear
147
+ *
148
+ * @param mrb The mruby state reference.
149
+ * @param hash The target hash.
150
+ * @return The hash
151
+ */
152
+ MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash);
153
+
154
+ /* declaration of struct kh_ht */
155
+ /* be careful when you touch the internal */
156
+ typedef struct {
157
+ mrb_value v;
158
+ mrb_int n;
159
+ } mrb_hash_value;
160
+
161
+ KHASH_DECLARE(ht, mrb_value, mrb_hash_value, TRUE)
162
+
163
+ /* RHASH_TBL allocates st_table if not available. */
164
+ #define RHASH(obj) ((struct RHash*)(mrb_ptr(obj)))
165
+ #define RHASH_TBL(h) (RHASH(h)->ht)
166
+ #define RHASH_IFNONE(h) mrb_iv_get(mrb, (h), mrb_intern_lit(mrb, "ifnone"))
167
+ #define RHASH_PROCDEFAULT(h) RHASH_IFNONE(h)
168
+ MRB_API struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash);
169
+
170
+ #define MRB_HASH_DEFAULT 1
171
+ #define MRB_HASH_PROC_DEFAULT 2
172
+ #define MRB_RHASH_DEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_DEFAULT)
173
+ #define MRB_RHASH_PROCDEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_PROC_DEFAULT)
174
+
175
+ /* GC functions */
176
+ void mrb_gc_mark_hash(mrb_state*, struct RHash*);
177
+ size_t mrb_gc_mark_hash_size(mrb_state*, struct RHash*);
178
+ void mrb_gc_free_hash(mrb_state*, struct RHash*);
179
+
180
+ MRB_END_DECL
181
+
182
+ #endif /* MRUBY_HASH_H */