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,279 @@
1
+ /*
2
+ ** mruby/array.h - Array class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_ARRAY_H
8
+ #define MRUBY_ARRAY_H
9
+
10
+ #include "common.h"
11
+
12
+ /*
13
+ * Array class
14
+ */
15
+ MRB_BEGIN_DECL
16
+
17
+
18
+ typedef struct mrb_shared_array {
19
+ int refcnt;
20
+ mrb_int len;
21
+ mrb_value *ptr;
22
+ } mrb_shared_array;
23
+
24
+ #define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value)))
25
+ struct RArray {
26
+ MRB_OBJECT_HEADER;
27
+ union {
28
+ struct {
29
+ mrb_int len;
30
+ union {
31
+ mrb_int capa;
32
+ mrb_shared_array *shared;
33
+ } aux;
34
+ mrb_value *ptr;
35
+ } heap;
36
+ mrb_value embed[MRB_ARY_EMBED_LEN_MAX];
37
+ } as;
38
+ };
39
+
40
+ #define mrb_ary_ptr(v) ((struct RArray*)(mrb_ptr(v)))
41
+ #define mrb_ary_value(p) mrb_obj_value((void*)(p))
42
+ #define RARRAY(v) ((struct RArray*)(mrb_ptr(v)))
43
+
44
+ #define MRB_ARY_EMBED_MASK 7
45
+ #define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED_MASK)
46
+ #define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
47
+ #define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
48
+ #define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
49
+ #define ARY_EMBED_PTR(a) (&((a)->as.embed[0]))
50
+
51
+ #define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
52
+ #define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr)
53
+ #define RARRAY_LEN(a) ARY_LEN(RARRAY(a))
54
+ #define RARRAY_PTR(a) ARY_PTR(RARRAY(a))
55
+ #define ARY_SET_LEN(a,n) do {\
56
+ if (ARY_EMBED_P(a)) {\
57
+ mrb_assert((n) <= MRB_ARY_EMBED_LEN_MAX); \
58
+ ARY_SET_EMBED_LEN(a,n);\
59
+ }\
60
+ else\
61
+ (a)->as.heap.len = (n);\
62
+ } while (0)
63
+ #define ARY_CAPA(a) (ARY_EMBED_P(a)?MRB_ARY_EMBED_LEN_MAX:(a)->as.heap.aux.capa)
64
+ #define MRB_ARY_SHARED 256
65
+ #define ARY_SHARED_P(a) ((a)->flags & MRB_ARY_SHARED)
66
+ #define ARY_SET_SHARED_FLAG(a) ((a)->flags |= MRB_ARY_SHARED)
67
+ #define ARY_UNSET_SHARED_FLAG(a) ((a)->flags &= ~MRB_ARY_SHARED)
68
+
69
+ void mrb_ary_decref(mrb_state*, mrb_shared_array*);
70
+ MRB_API void mrb_ary_modify(mrb_state*, struct RArray*);
71
+ MRB_API mrb_value mrb_ary_new_capa(mrb_state*, mrb_int);
72
+
73
+ /*
74
+ * Initializes a new array.
75
+ *
76
+ * Equivalent to:
77
+ *
78
+ * Array.new
79
+ *
80
+ * @param mrb The mruby state reference.
81
+ * @return The initialized array.
82
+ */
83
+ MRB_API mrb_value mrb_ary_new(mrb_state *mrb);
84
+
85
+ /*
86
+ * Initializes a new array with initial values
87
+ *
88
+ * Equivalent to:
89
+ *
90
+ * Array[value1, value2, ...]
91
+ *
92
+ * @param mrb The mruby state reference.
93
+ * @param size The numer of values.
94
+ * @param vals The actual values.
95
+ * @return The initialized array.
96
+ */
97
+ MRB_API mrb_value mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals);
98
+
99
+ /*
100
+ * Initializes a new array with two initial values
101
+ *
102
+ * Equivalent to:
103
+ *
104
+ * Array[car, cdr]
105
+ *
106
+ * @param mrb The mruby state reference.
107
+ * @param car The first value.
108
+ * @param cdr The second value.
109
+ * @return The initialized array.
110
+ */
111
+ MRB_API mrb_value mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr);
112
+
113
+ /*
114
+ * Concatenate two arrays. The target array will be modified
115
+ *
116
+ * Equivalent to:
117
+ * ary.concat(other)
118
+ *
119
+ * @param mrb The mruby state reference.
120
+ * @param self The target array.
121
+ * @param other The array that will be concatenated to self.
122
+ */
123
+ MRB_API void mrb_ary_concat(mrb_state *mrb, mrb_value self, mrb_value other);
124
+
125
+ /*
126
+ * Create an array from the input. It tries calling to_a on the
127
+ * value. If value does not respond to that, it creates a new
128
+ * array with just this value.
129
+ *
130
+ * @param mrb The mruby state reference.
131
+ * @param value The value to change into an array.
132
+ * @return An array representation of value.
133
+ */
134
+ MRB_API mrb_value mrb_ary_splat(mrb_state *mrb, mrb_value value);
135
+
136
+ /*
137
+ * Pushes value into array.
138
+ *
139
+ * Equivalent to:
140
+ *
141
+ * ary << value
142
+ *
143
+ * @param mrb The mruby state reference.
144
+ * @param ary The array in which the value will be pushed
145
+ * @param value The value to be pushed into array
146
+ */
147
+ MRB_API void mrb_ary_push(mrb_state *mrb, mrb_value array, mrb_value value);
148
+
149
+ /*
150
+ * Pops the last element from the array.
151
+ *
152
+ * Equivalent to:
153
+ *
154
+ * ary.pop
155
+ *
156
+ * @param mrb The mruby state reference.
157
+ * @param ary The array from which the value will be popped.
158
+ * @return The popped value.
159
+ */
160
+ MRB_API mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary);
161
+
162
+ /*
163
+ * Returns a reference to an element of the array on the given index.
164
+ *
165
+ * Equivalent to:
166
+ *
167
+ * ary[n]
168
+ *
169
+ * @param mrb The mruby state reference.
170
+ * @param ary The target array.
171
+ * @param n The array index being referenced
172
+ * @return The referenced value.
173
+ */
174
+ MRB_API mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n);
175
+
176
+ /*
177
+ * Sets a value on an array at the given index
178
+ *
179
+ * Equivalent to:
180
+ *
181
+ * ary[n] = val
182
+ *
183
+ * @param mrb The mruby state reference.
184
+ * @param ary The target array.
185
+ * @param n The array index being referenced.
186
+ * @param val The value being setted.
187
+ */
188
+ MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val);
189
+
190
+ /*
191
+ * Replace the array with another array
192
+ *
193
+ * Equivalent to:
194
+ *
195
+ * ary.replace(other)
196
+ *
197
+ * @param mrb The mruby state reference
198
+ * @param self The target array.
199
+ * @param other The array to replace it with.
200
+ */
201
+ MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other);
202
+ MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
203
+
204
+ /*
205
+ * Unshift an element into the array
206
+ *
207
+ * Equivalent to:
208
+ *
209
+ * ary.unshift(item)
210
+ *
211
+ * @param mrb The mruby state reference.
212
+ * @param self The target array.
213
+ * @param item The item to unshift.
214
+ */
215
+ MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item);
216
+
217
+ /*
218
+ * Get nth element in the array
219
+ *
220
+ * Equivalent to:
221
+ *
222
+ * ary[offset]
223
+ *
224
+ * @param ary The target array.
225
+ * @param offset The element position (negative counts from the tail).
226
+ */
227
+ MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
228
+
229
+ /*
230
+ * Shifts the first element from the array.
231
+ *
232
+ * Equivalent to:
233
+ *
234
+ * ary.shift
235
+ *
236
+ * @param mrb The mruby state reference.
237
+ * @param self The array from which the value will be shifted.
238
+ * @return The shifted value.
239
+ */
240
+ MRB_API mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self);
241
+
242
+ /*
243
+ * Removes all elements from the array
244
+ *
245
+ * Equivalent to:
246
+ *
247
+ * ary.clear
248
+ *
249
+ * @param mrb The mruby state reference.
250
+ * @param self The target array.
251
+ * @return self
252
+ */
253
+ MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self);
254
+
255
+ /*
256
+ * Join the array elements together in a string
257
+ *
258
+ * Equivalent to:
259
+ *
260
+ * ary.join(sep="")
261
+ *
262
+ * @param mrb The mruby state reference.
263
+ * @param ary The target array
264
+ * @param sep The separater, can be NULL
265
+ */
266
+ MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
267
+
268
+ /*
269
+ * Update the capacity of the array
270
+ *
271
+ * @param mrb The mruby state reference.
272
+ * @param ary The target array.
273
+ * @param new_len The new capacity of the array
274
+ */
275
+ MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len);
276
+
277
+ MRB_END_DECL
278
+
279
+ #endif /* MRUBY_ARRAY_H */
@@ -0,0 +1,102 @@
1
+ /*
2
+ ** mruby/boxing_nan.h - nan boxing mrb_value definition
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_BOXING_NAN_H
8
+ #define MRUBY_BOXING_NAN_H
9
+
10
+ #ifdef MRB_USE_FLOAT
11
+ # error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT conflict <<----
12
+ #endif
13
+
14
+ #ifdef MRB_WITHOUT_FLOAT
15
+ # error ---->> MRB_NAN_BOXING and MRB_WITHOUT_FLOAT conflict <<----
16
+ #endif
17
+
18
+ #ifdef MRB_INT64
19
+ # error ---->> MRB_NAN_BOXING and MRB_INT64 conflict <<----
20
+ #endif
21
+
22
+ #define MRB_FIXNUM_SHIFT 0
23
+ #define MRB_TT_HAS_BASIC MRB_TT_OBJECT
24
+
25
+ #ifdef MRB_ENDIAN_BIG
26
+ #define MRB_ENDIAN_LOHI(a,b) a b
27
+ #else
28
+ #define MRB_ENDIAN_LOHI(a,b) b a
29
+ #endif
30
+
31
+ /* value representation by nan-boxing:
32
+ * float : FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
33
+ * object: 111111111111TTTT TTPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP
34
+ * int : 1111111111110001 0000000000000000 IIIIIIIIIIIIIIII IIIIIIIIIIIIIIII
35
+ * sym : 1111111111110001 0100000000000000 SSSSSSSSSSSSSSSS SSSSSSSSSSSSSSSS
36
+ * In order to get enough bit size to save TT, all pointers are shifted 2 bits
37
+ * in the right direction. Also, TTTTTT is the mrb_vtype + 1;
38
+ */
39
+ typedef struct mrb_value {
40
+ union {
41
+ mrb_float f;
42
+ union {
43
+ void *p;
44
+ struct {
45
+ MRB_ENDIAN_LOHI(
46
+ uint32_t ttt;
47
+ ,union {
48
+ mrb_int i;
49
+ mrb_sym sym;
50
+ };
51
+ )
52
+ };
53
+ } value;
54
+ };
55
+ } mrb_value;
56
+
57
+ #define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
58
+
59
+ #define mrb_tt(o) ((enum mrb_vtype)(((o).value.ttt & 0xfc000)>>14)-1)
60
+ #define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
61
+ #define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)((o).value.p)))<<2))
62
+ #define mrb_float(o) (o).f
63
+ #define mrb_cptr(o) mrb_ptr(o)
64
+ #define mrb_fixnum(o) (o).value.i
65
+ #define mrb_symbol(o) (o).value.sym
66
+
67
+ #ifdef MRB_64BIT
68
+ #define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
69
+ #else
70
+ #define BOXNAN_SHIFT_LONG_POINTER(v) 0
71
+ #endif
72
+
73
+ #define BOXNAN_SET_VALUE(o, tt, attr, v) do {\
74
+ (o).attr = (v);\
75
+ (o).value.ttt = 0xfff00000 | (((tt)+1)<<14);\
76
+ } while (0)
77
+
78
+ #define BOXNAN_SET_OBJ_VALUE(o, tt, v) do {\
79
+ (o).value.p = (void*)((uintptr_t)(v)>>2);\
80
+ (o).value.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
81
+ } while (0)
82
+
83
+ #define SET_FLOAT_VALUE(mrb,r,v) do { \
84
+ if (v != v) { \
85
+ (r).value.ttt = 0x7ff80000; \
86
+ (r).value.i = 0; \
87
+ } \
88
+ else { \
89
+ (r).f = v; \
90
+ }} while(0)
91
+
92
+ #define SET_NIL_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, value.i, 0)
93
+ #define SET_FALSE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
94
+ #define SET_TRUE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
95
+ #define SET_BOOL_VALUE(r,b) BOXNAN_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
96
+ #define SET_INT_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
97
+ #define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
98
+ #define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v))
99
+ #define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_OBJ_VALUE(r, MRB_TT_CPTR, v)
100
+ #define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)
101
+
102
+ #endif /* MRUBY_BOXING_NAN_H */
@@ -0,0 +1,56 @@
1
+ /*
2
+ ** mruby/boxing_no.h - unboxed mrb_value definition
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_BOXING_NO_H
8
+ #define MRUBY_BOXING_NO_H
9
+
10
+ #define MRB_FIXNUM_SHIFT 0
11
+ #define MRB_TT_HAS_BASIC MRB_TT_OBJECT
12
+
13
+ typedef struct mrb_value {
14
+ union {
15
+ #ifndef MRB_WITHOUT_FLOAT
16
+ mrb_float f;
17
+ #endif
18
+ void *p;
19
+ mrb_int i;
20
+ mrb_sym sym;
21
+ } value;
22
+ enum mrb_vtype tt;
23
+ } mrb_value;
24
+
25
+ #ifndef MRB_WITHOUT_FLOAT
26
+ #define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
27
+ #endif
28
+
29
+ #define mrb_ptr(o) (o).value.p
30
+ #define mrb_cptr(o) mrb_ptr(o)
31
+ #ifndef MRB_WITHOUT_FLOAT
32
+ #define mrb_float(o) (o).value.f
33
+ #endif
34
+ #define mrb_fixnum(o) (o).value.i
35
+ #define mrb_symbol(o) (o).value.sym
36
+ #define mrb_type(o) (o).tt
37
+
38
+ #define BOXNIX_SET_VALUE(o, ttt, attr, v) do {\
39
+ (o).tt = ttt;\
40
+ (o).attr = v;\
41
+ } while (0)
42
+
43
+ #define SET_NIL_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_FALSE, value.i, 0)
44
+ #define SET_FALSE_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
45
+ #define SET_TRUE_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
46
+ #define SET_BOOL_VALUE(r,b) BOXNIX_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
47
+ #define SET_INT_VALUE(r,n) BOXNIX_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
48
+ #ifndef MRB_WITHOUT_FLOAT
49
+ #define SET_FLOAT_VALUE(mrb,r,v) BOXNIX_SET_VALUE(r, MRB_TT_FLOAT, value.f, (v))
50
+ #endif
51
+ #define SET_SYM_VALUE(r,v) BOXNIX_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
52
+ #define SET_OBJ_VALUE(r,v) BOXNIX_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))
53
+ #define SET_CPTR_VALUE(mrb,r,v) BOXNIX_SET_VALUE(r, MRB_TT_CPTR, value.p, v)
54
+ #define SET_UNDEF_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)
55
+
56
+ #endif /* MRUBY_BOXING_NO_H */
@@ -0,0 +1,136 @@
1
+ /*
2
+ ** mruby/boxing_word.h - word boxing mrb_value definition
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_BOXING_WORD_H
8
+ #define MRUBY_BOXING_WORD_H
9
+
10
+ #if defined(MRB_INT16)
11
+ # error MRB_INT16 is too small for MRB_WORD_BOXING.
12
+ #endif
13
+
14
+ #if defined(MRB_INT64) && !defined(MRB_64BIT)
15
+ #error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode.
16
+ #endif
17
+
18
+ #ifndef MRB_WITHOUT_FLOAT
19
+ struct RFloat {
20
+ MRB_OBJECT_HEADER;
21
+ mrb_float f;
22
+ };
23
+ #endif
24
+
25
+ struct RCptr {
26
+ MRB_OBJECT_HEADER;
27
+ void *p;
28
+ };
29
+
30
+ #define MRB_FIXNUM_SHIFT 1
31
+ #ifdef MRB_WITHOUT_FLOAT
32
+ #define MRB_TT_HAS_BASIC MRB_TT_CPTR
33
+ #else
34
+ #define MRB_TT_HAS_BASIC MRB_TT_FLOAT
35
+ #endif
36
+
37
+ enum mrb_special_consts {
38
+ MRB_Qnil = 0,
39
+ MRB_Qfalse = 2,
40
+ MRB_Qtrue = 4,
41
+ MRB_Qundef = 6,
42
+ };
43
+
44
+ #define MRB_FIXNUM_FLAG 0x01
45
+ #define MRB_SYMBOL_FLAG 0x0e
46
+ #define MRB_SPECIAL_SHIFT 8
47
+
48
+ typedef union mrb_value {
49
+ union {
50
+ void *p;
51
+ struct {
52
+ unsigned int i_flag : MRB_FIXNUM_SHIFT;
53
+ mrb_int i : (MRB_INT_BIT - MRB_FIXNUM_SHIFT);
54
+ };
55
+ struct {
56
+ unsigned int sym_flag : MRB_SPECIAL_SHIFT;
57
+ mrb_sym sym : (sizeof(mrb_sym) * CHAR_BIT);
58
+ };
59
+ struct RBasic *bp;
60
+ #ifndef MRB_WITHOUT_FLOAT
61
+ struct RFloat *fp;
62
+ #endif
63
+ struct RCptr *vp;
64
+ } value;
65
+ unsigned long w;
66
+ } mrb_value;
67
+
68
+ MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state*, void*);
69
+ #ifndef MRB_WITHOUT_FLOAT
70
+ MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float);
71
+ MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
72
+ #endif
73
+
74
+ #ifndef MRB_WITHOUT_FLOAT
75
+ #define mrb_float_pool(mrb,f) mrb_word_boxing_float_pool(mrb,f)
76
+ #endif
77
+
78
+ #define mrb_ptr(o) (o).value.p
79
+ #define mrb_cptr(o) (o).value.vp->p
80
+ #ifndef MRB_WITHOUT_FLOAT
81
+ #define mrb_float(o) (o).value.fp->f
82
+ #endif
83
+ #define mrb_fixnum(o) ((mrb_int)(o).value.i)
84
+ #define mrb_symbol(o) (o).value.sym
85
+
86
+ static inline enum mrb_vtype
87
+ mrb_type(mrb_value o)
88
+ {
89
+ switch (o.w) {
90
+ case MRB_Qfalse:
91
+ case MRB_Qnil:
92
+ return MRB_TT_FALSE;
93
+ case MRB_Qtrue:
94
+ return MRB_TT_TRUE;
95
+ case MRB_Qundef:
96
+ return MRB_TT_UNDEF;
97
+ }
98
+ if (o.value.i_flag == MRB_FIXNUM_FLAG) {
99
+ return MRB_TT_FIXNUM;
100
+ }
101
+ if (o.value.sym_flag == MRB_SYMBOL_FLAG) {
102
+ return MRB_TT_SYMBOL;
103
+ }
104
+ return o.value.bp->tt;
105
+ }
106
+
107
+ #define mrb_bool(o) ((o).w != MRB_Qnil && (o).w != MRB_Qfalse)
108
+ #define mrb_fixnum_p(o) ((o).value.i_flag == MRB_FIXNUM_FLAG)
109
+ #define mrb_undef_p(o) ((o).w == MRB_Qundef)
110
+ #define mrb_nil_p(o) ((o).w == MRB_Qnil)
111
+
112
+ #define BOXWORD_SET_VALUE(o, ttt, attr, v) do { \
113
+ switch (ttt) {\
114
+ case MRB_TT_FALSE: (o).w = (v) ? MRB_Qfalse : MRB_Qnil; break;\
115
+ case MRB_TT_TRUE: (o).w = MRB_Qtrue; break;\
116
+ case MRB_TT_UNDEF: (o).w = MRB_Qundef; break;\
117
+ case MRB_TT_FIXNUM: (o).w = 0;(o).value.i_flag = MRB_FIXNUM_FLAG; (o).attr = (v); break;\
118
+ case MRB_TT_SYMBOL: (o).w = 0;(o).value.sym_flag = MRB_SYMBOL_FLAG; (o).attr = (v); break;\
119
+ default: (o).w = 0; (o).attr = (v); if ((o).value.bp) (o).value.bp->tt = ttt; break;\
120
+ }\
121
+ } while (0)
122
+
123
+ #ifndef MRB_WITHOUT_FLOAT
124
+ #define SET_FLOAT_VALUE(mrb,r,v) r = mrb_word_boxing_float_value(mrb, v)
125
+ #endif
126
+ #define SET_CPTR_VALUE(mrb,r,v) r = mrb_word_boxing_cptr_value(mrb, v)
127
+ #define SET_NIL_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_FALSE, value.i, 0)
128
+ #define SET_FALSE_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
129
+ #define SET_TRUE_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
130
+ #define SET_BOOL_VALUE(r,b) BOXWORD_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
131
+ #define SET_INT_VALUE(r,n) BOXWORD_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
132
+ #define SET_SYM_VALUE(r,v) BOXWORD_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
133
+ #define SET_OBJ_VALUE(r,v) BOXWORD_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))
134
+ #define SET_UNDEF_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)
135
+
136
+ #endif /* MRUBY_BOXING_WORD_H */