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.
@@ -0,0 +1,296 @@
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_ensure_array_type(mrb_state *mrb, mrb_value self);
203
+ MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
204
+
205
+ /*
206
+ * Unshift an element into the array
207
+ *
208
+ * Equivalent to:
209
+ *
210
+ * ary.unshift(item)
211
+ *
212
+ * @param mrb The mruby state reference.
213
+ * @param self The target array.
214
+ * @param item The item to unshift.
215
+ */
216
+ MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item);
217
+
218
+ /*
219
+ * Get nth element in the array
220
+ *
221
+ * Equivalent to:
222
+ *
223
+ * ary[offset]
224
+ *
225
+ * @param ary The target array.
226
+ * @param offset The element position (negative counts from the tail).
227
+ */
228
+ MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
229
+
230
+ /*
231
+ * Replace subsequence of an array.
232
+ *
233
+ * Equivalent to:
234
+ *
235
+ * ary.shift
236
+ *
237
+ * @param mrb The mruby state reference.
238
+ * @param self The array from which the value will be shifted.
239
+ * @param head Beginning position of a replacement subsequence.
240
+ * @param len Length of a replacement subsequence.
241
+ * @param rpl The array of replacement elements.
242
+ * @return The receiver array.
243
+ */
244
+ MRB_API mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl);
245
+
246
+ /*
247
+ * Shifts the first element from the array.
248
+ *
249
+ * Equivalent to:
250
+ *
251
+ * ary.shift
252
+ *
253
+ * @param mrb The mruby state reference.
254
+ * @param self The array from which the value will be shifted.
255
+ * @return The shifted value.
256
+ */
257
+ MRB_API mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self);
258
+
259
+ /*
260
+ * Removes all elements from the array
261
+ *
262
+ * Equivalent to:
263
+ *
264
+ * ary.clear
265
+ *
266
+ * @param mrb The mruby state reference.
267
+ * @param self The target array.
268
+ * @return self
269
+ */
270
+ MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self);
271
+
272
+ /*
273
+ * Join the array elements together in a string
274
+ *
275
+ * Equivalent to:
276
+ *
277
+ * ary.join(sep="")
278
+ *
279
+ * @param mrb The mruby state reference.
280
+ * @param ary The target array
281
+ * @param sep The separater, can be NULL
282
+ */
283
+ MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
284
+
285
+ /*
286
+ * Update the capacity of the array
287
+ *
288
+ * @param mrb The mruby state reference.
289
+ * @param ary The target array.
290
+ * @param new_len The new capacity of the array
291
+ */
292
+ MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len);
293
+
294
+ MRB_END_DECL
295
+
296
+ #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 */