rural 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.
data/ext/vlerq.h ADDED
@@ -0,0 +1,350 @@
1
+ /* vlerq.h - this is the single-source-file header of Vlerq for Ruby */
2
+
3
+ /* %includeDir<../src>% */
4
+ /* %includeDir<../_ruby>% */
5
+
6
+ /* %include<defs.h>% */
7
+ /*
8
+ * defs.h - Binding-specific definitions needed by the general code.
9
+ */
10
+
11
+ typedef unsigned long Object_p;
12
+
13
+ struct Shared *(GetShared) (void);
14
+ /* %include<column.h>% */
15
+ /*
16
+ * column.h - Definition of sequences, columns, and items.
17
+ */
18
+
19
+ #include <stdint.h>
20
+ /* on OpenBSD, use this line instead: typedef int intptr_t; */
21
+
22
+ #ifdef __sparc__
23
+ #define VALUES_MUST_BE_ALIGNED 1
24
+ #endif
25
+
26
+ #if WORDS_BIGENDIAN
27
+ #define _BIG_ENDIAN 1
28
+ #endif
29
+
30
+ #if DEBUG
31
+ #define Assert(x) do if (!(x)) FailedAssert(#x, __FILE__, __LINE__); while (0)
32
+ #else
33
+ #define Assert(x)
34
+ #endif
35
+
36
+ #define INVALID_COUNT (-1)
37
+
38
+ #define PUSH_KEEP_REFS \
39
+ { Buffer keep, *prevkeeps = GetShared()->keeps; \
40
+ InitBuffer(&keep); \
41
+ GetShared()->keeps = &keep;
42
+ #define POP_KEEP_REFS \
43
+ ReleaseSequences((Sequence_p*) BufferAsPtr(&keep, 1), \
44
+ BufferFill(keep) / sizeof(Sequence_p)); \
45
+ ReleaseBuffer(&keep, 0); \
46
+ GetShared()->keeps = prevkeeps; \
47
+ }
48
+
49
+ /* keep in sync with CharAsItemType() in column.c */
50
+ typedef enum ItemTypes {
51
+ IT_unknown,
52
+ IT_int,
53
+ IT_wide,
54
+ IT_float,
55
+ IT_double,
56
+ IT_string,
57
+ IT_bytes,
58
+ IT_object,
59
+ IT_column,
60
+ IT_view,
61
+ IT_error
62
+ } ItemTypes;
63
+
64
+ typedef enum ErrorCodes {
65
+ EC_cioor,
66
+ EC_rioor,
67
+ EC_cizwv,
68
+ EC_nmcw,
69
+ EC_rambe,
70
+ EC_nalor,
71
+ EC_wnoa
72
+ } ErrorCodes;
73
+
74
+ typedef struct Shared {
75
+ struct SharedInfo *info; /* ext_tcl.c */
76
+ int refs; /* ext_tcl.c */
77
+ struct Buffer *keeps; /* column.c */
78
+ intptr_t position; /* emit.c: current file emit offset */
79
+ struct Buffer *itembuf; /* emit.c: current item buffer */
80
+ struct Buffer *colbuf; /* emit.c: current column buffer */
81
+ struct Sequence *empty; /* view.c */
82
+ } Shared, *Shared_p;
83
+
84
+ typedef struct RefCounted *RefCounted_p;
85
+ typedef struct Sequence *Sequence_p;
86
+ typedef struct Column *Column_p;
87
+ typedef union Item *Item_p;
88
+ typedef Sequence_p View_p;
89
+
90
+ typedef int (*Sizer) (Sequence_p seq);
91
+ typedef ItemTypes (*Getter) (int row, Item_p item);
92
+ typedef void (*Cleaner) (RefCounted_p seq);
93
+
94
+ typedef struct RefCounted {
95
+ Cleaner cleaner; /* called during cleanup */
96
+ int refcount; /* reference count */
97
+ int filler; /* needed for 64b alignment, can reuse for any purpose */
98
+ } RefCounted;
99
+
100
+ typedef struct Sequence {
101
+ RefCounted head; /* manages ref counts, must be first is struct */
102
+ Getter getter; /* function to access a single item */
103
+ union { int i; void *p; } data[4]; /* getter-specific use */
104
+ } Sequence;
105
+
106
+ #define S_Count(seq) ((seq)->head.filler)
107
+
108
+ #define IncRefCount(seq) AdjustSeqRefs(seq, 1)
109
+ #define DecRefCount(seq) AdjustSeqRefs(seq, -1)
110
+
111
+ typedef struct Column {
112
+ Sequence_p seq; /* the sequence which will handle accesses */
113
+ int pos; /* position of this column in the view */
114
+ } Column;
115
+
116
+ typedef union Item {
117
+ char b [8]; /* used for raw access and byte-swapping */
118
+ int q [2]; /* used for hash calculation of wides and doubles */
119
+ int i; /* IT_int */
120
+ int64_t w; /* IT_wide */
121
+ float f; /* IT_float */
122
+ double d; /* IT_double */
123
+ const void *p; /* used to convert pointers */
124
+ const char *s; /* IT_string */
125
+ struct { const uint8_t *ptr; int len; } u; /* IT_bytes */
126
+ Object_p o; /* IT_object */
127
+ Column c; /* IT_column */
128
+ View_p v; /* IT_view */
129
+ ErrorCodes e; /* IT_error */
130
+ } Item;
131
+
132
+ void *(AdjustSeqRefs) (void *refs, int count);
133
+ void (AppendToStringColumn) (const void *s, int bytes, Column_p column);
134
+ int (CastObjToItem) (char type, Item_p item);
135
+ ItemTypes (CharAsItemType) (char type);
136
+ Column (CoerceCmd) (Object_p obj, const char *str);
137
+ void (FailedAssert) (const char *msg, const char *file, int line);
138
+ Column (ForceStringColumn) (Column column);
139
+ ItemTypes (GetItem) (int row, Item_p item);
140
+ Item (GetTypedItem) (int row, Column column, ItemTypes type);
141
+ Column (InitColumn) (int count, Getter proc, int auxbytes);
142
+ Sequence_p (KeepRef) (Sequence_p seq);
143
+ Column (NewCountsColumn) (Column column);
144
+ Column (NewIntVec) (int count, int **dataptr);
145
+ Column (NewIotaColumn) (int count);
146
+ Column (NewPtrVec) (int count, intptr_t **dataptr);
147
+ Column (NewSequenceColumn) (ItemTypes type, const Sequence_p *p, int n);
148
+ Column (NewStringColumn) (int maxitems, int maxbytes, int istext);
149
+ Column (OmitColumn) (Column omit, int size);
150
+ void (ReleaseSequences) (Sequence_p *refs, int count);
151
+
152
+ /* the following must be supplied in the language binding */
153
+ Column (CoerceColumn) (ItemTypes type, Object_p obj);
154
+ int (ColumnByName) (View_p meta, Object_p obj);
155
+ Object_p (ItemAsObj) (ItemTypes type, Item_p item);
156
+ Column (ObjAsColumn) (Object_p obj);
157
+ int (ObjToItem) (ItemTypes type, Item_p item);
158
+ /* %include<buffer.h>% */
159
+ /*
160
+ * buffer.h - Definition of a simple temporary buffer.
161
+ */
162
+
163
+ typedef struct Buffer *Buffer_p;
164
+ typedef struct Overflow *Overflow_p;
165
+
166
+ typedef struct Buffer {
167
+ union { char *c; int *i; const void **p; } fill;
168
+ char *limit;
169
+ Overflow_p head;
170
+ char *ofill;
171
+ intptr_t ocount;
172
+ char *result;
173
+ char buf [128];
174
+ char slack [8];
175
+ } Buffer;
176
+
177
+ #define ADD_CHAR_TO_BUF(b,x) \
178
+ { char _c = x; \
179
+ if ((b).fill.c < (b).limit) *(b).fill.c++ = _c; \
180
+ else AddToBuffer(&(b), &_c, sizeof _c); }
181
+
182
+ #define ADD_INT_TO_BUF(b,x) \
183
+ { int _i = x; \
184
+ if ((b).fill.c < (b).limit) *(b).fill.i++ = _i; \
185
+ else AddToBuffer(&(b), &_i, sizeof _i); }
186
+
187
+ #define ADD_PTR_TO_BUF(b,x) \
188
+ { const void *_p = x; \
189
+ if ((b).fill.c < (b).limit) *(b).fill.p++ = _p; \
190
+ else AddToBuffer(&(b), &_p, sizeof _p); }
191
+
192
+ #define BufferFill(b) ((b).ocount + ((b).fill.c - (b).buf))
193
+
194
+ void InitBuffer(Buffer_p bp);
195
+ void ReleaseBuffer(Buffer_p bp, int keep);
196
+ void AddToBuffer(Buffer_p bp, const void *data, intptr_t len);
197
+ char *BufferAsPtr(Buffer_p bp, int fast);
198
+ Column BufferAsIntCol(Buffer_p bp);
199
+ /* %include<view.h>% */
200
+ /*
201
+ * view.h - Definition of views.
202
+ */
203
+
204
+ typedef enum MetaCols {
205
+ MC_name, MC_type, MC_subv, MC_limit
206
+ } MetaCols;
207
+
208
+ #define V_Cols(view) ((Column_p) ((view) + 1))
209
+ #define V_Types(view) (*(char**) ((view)->data))
210
+ #define V_Meta(view) (*(View_p*) ((view)->data+1))
211
+
212
+ #define ViewWidth(view) ViewSize(V_Meta(view))
213
+ #define ViewCol(view,col) (V_Cols(view)[col])
214
+ #define ViewColType(view,col) ((ItemTypes) V_Types(view)[col])
215
+ #define ViewCompat(view1,view2) MetaIsCompatible(V_Meta(view1), V_Meta(view2))
216
+
217
+ View_p (CloneView) (View_p view);
218
+ View_p (ColMapView) (View_p view, Column mapcol);
219
+ View_p (ColOmitView) (View_p view, Column mapcol);
220
+ View_p (DescAsMeta) (const char** desc, const char* end);
221
+ View_p (DescToMeta) (const char *desc);
222
+ View_p (EmptyMetaView) (void);
223
+ View_p (FirstView) (View_p view, int count);
224
+ char (GetColType) (View_p meta, int col);
225
+ View_p (IndirectView) (View_p meta, Sequence_p seq);
226
+ View_p (LastView) (View_p view, int count);
227
+ View_p (NameColView) (View_p view);
228
+ View_p (NewView) (View_p meta);
229
+ View_p (NoColumnView) (int rows);
230
+ View_p (PairView) (View_p view1, View_p view2);
231
+ View_p (TakeView) (View_p view, int count);
232
+ int (MetaIsCompatible) (View_p meta1, View_p meta2);
233
+ Column (ViewAsCol) (View_p view);
234
+ int (ViewCompare) (View_p view1, View_p view2);
235
+ int (ViewSize) (View_p view);
236
+ void (ViewStructure) (View_p meta, Buffer_p buffer);
237
+ void (ReleaseUnusedViews) (void);
238
+ void (SetViewColumns) (View_p view, int first, int count, Column src);
239
+ View_p (TagView) (View_p view, const char* name);
240
+ /* %include<file.h>% */
241
+ /*
242
+ * file.h - Definition of memory-mapped file access.
243
+ */
244
+
245
+ typedef Sequence_p MappedFile_p;
246
+
247
+ #define MF_Data(map) ((const char*) ((map)->data[0].p))
248
+ #define MF_Length(map) ((intptr_t) (map)->data[1].p)
249
+
250
+ MappedFile_p (InitMappedFile) (const char *data, intptr_t length, Cleaner fun);
251
+ View_p (MappedToView) (MappedFile_p map);
252
+ View_p (MapSubview) (MappedFile_p map, intptr_t offset, View_p meta);
253
+ View_p (OpenDataFile) (const char *filename);
254
+ MappedFile_p (OpenMappedFile) (const char *filename);
255
+ /* %include<wrap_gen.h>% */
256
+ /* wrap_gen.h - generated code, do not edit */
257
+
258
+ ItemTypes (AppendCmd_VV) (Item_p a);
259
+ ItemTypes (AtRowCmd_OI) (Item_p a);
260
+ ItemTypes (BlockedCmd_V) (Item_p a);
261
+ ItemTypes (CloneCmd_V) (Item_p a);
262
+ ItemTypes (CoerceCmd_OS) (Item_p a);
263
+ ItemTypes (ColConvCmd_C) (Item_p a);
264
+ ItemTypes (ColMapCmd_Vn) (Item_p a);
265
+ ItemTypes (ColOmitCmd_Vn) (Item_p a);
266
+ ItemTypes (CompareCmd_VV) (Item_p a);
267
+ ItemTypes (CompatCmd_VV) (Item_p a);
268
+ ItemTypes (ConcatCmd_VV) (Item_p a);
269
+ ItemTypes (CountsCmd_VN) (Item_p a);
270
+ ItemTypes (CountsColCmd_C) (Item_p a);
271
+ ItemTypes (CountViewCmd_I) (Item_p a);
272
+ ItemTypes (DataCmd_VX) (Item_p a);
273
+ ItemTypes (DefCmd_OO) (Item_p a);
274
+ ItemTypes (DeleteCmd_VII) (Item_p a);
275
+ ItemTypes (EmitCmd_V) (Item_p a);
276
+ ItemTypes (ExceptCmd_VV) (Item_p a);
277
+ ItemTypes (ExceptMapCmd_VV) (Item_p a);
278
+ ItemTypes (FirstCmd_VI) (Item_p a);
279
+ ItemTypes (GetCmd_VX) (Item_p a);
280
+ ItemTypes (GetColCmd_VN) (Item_p a);
281
+ ItemTypes (GetInfoCmd_VVI) (Item_p a);
282
+ ItemTypes (GroupCmd_VnS) (Item_p a);
283
+ ItemTypes (GroupedCmd_ViiS) (Item_p a);
284
+ ItemTypes (GroupInfoCmd_V) (Item_p a);
285
+ ItemTypes (HashColCmd_SO) (Item_p a);
286
+ ItemTypes (HashFindCmd_VIViii) (Item_p a);
287
+ ItemTypes (HashInfoCmd_V) (Item_p a);
288
+ ItemTypes (HashViewCmd_V) (Item_p a);
289
+ ItemTypes (IjoinCmd_VV) (Item_p a);
290
+ ItemTypes (InsertCmd_VIV) (Item_p a);
291
+ ItemTypes (IntersectCmd_VV) (Item_p a);
292
+ ItemTypes (IotaCmd_I) (Item_p a);
293
+ ItemTypes (IsectMapCmd_VV) (Item_p a);
294
+ ItemTypes (JoinCmd_VVS) (Item_p a);
295
+ ItemTypes (JoinInfoCmd_VV) (Item_p a);
296
+ ItemTypes (LastCmd_VI) (Item_p a);
297
+ ItemTypes (LoadCmd_O) (Item_p a);
298
+ ItemTypes (LoopCmd_X) (Item_p a);
299
+ ItemTypes (MaxCmd_VN) (Item_p a);
300
+ ItemTypes (MdefCmd_O) (Item_p a);
301
+ ItemTypes (MdescCmd_S) (Item_p a);
302
+ ItemTypes (MetaCmd_V) (Item_p a);
303
+ ItemTypes (MinCmd_VN) (Item_p a);
304
+ ItemTypes (NameColCmd_V) (Item_p a);
305
+ ItemTypes (NamesCmd_V) (Item_p a);
306
+ ItemTypes (OmitMapCmd_iI) (Item_p a);
307
+ ItemTypes (OpenCmd_S) (Item_p a);
308
+ ItemTypes (PairCmd_VV) (Item_p a);
309
+ ItemTypes (ProductCmd_VV) (Item_p a);
310
+ ItemTypes (RefCmd_OX) (Item_p a);
311
+ ItemTypes (RefsCmd_O) (Item_p a);
312
+ ItemTypes (RemapCmd_Vi) (Item_p a);
313
+ ItemTypes (RemapSubCmd_ViII) (Item_p a);
314
+ ItemTypes (RenameCmd_VO) (Item_p a);
315
+ ItemTypes (RepeatCmd_VI) (Item_p a);
316
+ ItemTypes (ReplaceCmd_VIIV) (Item_p a);
317
+ ItemTypes (ReverseCmd_V) (Item_p a);
318
+ ItemTypes (RowEqCmd_IVIV) (Item_p a);
319
+ ItemTypes (RowHashCmd_VI) (Item_p a);
320
+ ItemTypes (SaveCmd_VS) (Item_p a);
321
+ ItemTypes (SetCmd_VIX) (Item_p a);
322
+ ItemTypes (SizeCmd_V) (Item_p a);
323
+ ItemTypes (SliceCmd_VIII) (Item_p a);
324
+ ItemTypes (SortCmd_V) (Item_p a);
325
+ ItemTypes (SortMapCmd_V) (Item_p a);
326
+ ItemTypes (SpreadCmd_VI) (Item_p a);
327
+ ItemTypes (StepCmd_VIIII) (Item_p a);
328
+ ItemTypes (StrLookupCmd_Ss) (Item_p a);
329
+ ItemTypes (StructDescCmd_V) (Item_p a);
330
+ ItemTypes (StructureCmd_V) (Item_p a);
331
+ ItemTypes (SumCmd_VN) (Item_p a);
332
+ ItemTypes (TagCmd_VS) (Item_p a);
333
+ ItemTypes (TakeCmd_VI) (Item_p a);
334
+ ItemTypes (ToCmd_OO) (Item_p a);
335
+ ItemTypes (TypeCmd_O) (Item_p a);
336
+ ItemTypes (TypesCmd_V) (Item_p a);
337
+ ItemTypes (UngroupCmd_VN) (Item_p a);
338
+ ItemTypes (UnionCmd_VV) (Item_p a);
339
+ ItemTypes (UnionMapCmd_VV) (Item_p a);
340
+ ItemTypes (UniqueCmd_V) (Item_p a);
341
+ ItemTypes (UniqueMapCmd_V) (Item_p a);
342
+ ItemTypes (ViewCmd_X) (Item_p a);
343
+ ItemTypes (ViewAsColCmd_V) (Item_p a);
344
+ ItemTypes (ViewConvCmd_V) (Item_p a);
345
+ ItemTypes (WidthCmd_V) (Item_p a);
346
+ ItemTypes (WriteCmd_VS) (Item_p a);
347
+
348
+ /* end of generated code */
349
+
350
+ /* end of generated code */