qr_reader-native 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.
- checksums.yaml +7 -0
- data/LICENSE-mruby.txt +22 -0
- data/LICENSE-spinel.txt +19 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/ext/qr_reader_native/SPINEL_VERSION +1 -0
- data/ext/qr_reader_native/extconf.rb +8 -0
- data/ext/qr_reader_native/mruby/error.h +13 -0
- data/ext/qr_reader_native/mruby/internal.h +145 -0
- data/ext/qr_reader_native/mruby/string.h +22 -0
- data/ext/qr_reader_native/mruby.h +93 -0
- data/ext/qr_reader_native/mruby_shim.h +118 -0
- data/ext/qr_reader_native/qr_reader_native.c +13513 -0
- data/ext/qr_reader_native/qr_reader_native.h +29 -0
- data/ext/qr_reader_native/qr_reader_native_ext.c +598 -0
- data/ext/qr_reader_native/re_cased.h +71 -0
- data/ext/qr_reader_native/re_compile.c +5784 -0
- data/ext/qr_reader_native/re_ctype.h +3540 -0
- data/ext/qr_reader_native/re_exec.c +2190 -0
- data/ext/qr_reader_native/re_internal.h +671 -0
- data/ext/qr_reader_native/re_prop.h +4629 -0
- data/ext/qr_reader_native/re_spinel.c +363 -0
- data/ext/qr_reader_native/re_spinel.h +22 -0
- data/ext/qr_reader_native/re_spinel_utf8.inc +97 -0
- data/ext/qr_reader_native/re_utf8.c +156 -0
- data/ext/qr_reader_native/sp_alloc.c +1447 -0
- data/ext/qr_reader_native/sp_alloc.h +1196 -0
- data/ext/qr_reader_native/sp_argf.h +33 -0
- data/ext/qr_reader_native/sp_array.c +1052 -0
- data/ext/qr_reader_native/sp_array.h +456 -0
- data/ext/qr_reader_native/sp_bigint.c +5826 -0
- data/ext/qr_reader_native/sp_bigint.h +117 -0
- data/ext/qr_reader_native/sp_cold.c +5259 -0
- data/ext/qr_reader_native/sp_compat.h +402 -0
- data/ext/qr_reader_native/sp_core.c +818 -0
- data/ext/qr_reader_native/sp_core.h +56 -0
- data/ext/qr_reader_native/sp_crypto.c +877 -0
- data/ext/qr_reader_native/sp_crypto.h +169 -0
- data/ext/qr_reader_native/sp_dtoa.c +1533 -0
- data/ext/qr_reader_native/sp_dtoa.h +29 -0
- data/ext/qr_reader_native/sp_encoding_names.h +172 -0
- data/ext/qr_reader_native/sp_enum.h +86 -0
- data/ext/qr_reader_native/sp_exc.c +1185 -0
- data/ext/qr_reader_native/sp_exc.h +186 -0
- data/ext/qr_reader_native/sp_exc_ctx.h +56 -0
- data/ext/qr_reader_native/sp_fiber.c +889 -0
- data/ext/qr_reader_native/sp_fiber.h +162 -0
- data/ext/qr_reader_native/sp_fiber_ctx.h +84 -0
- data/ext/qr_reader_native/sp_format.c +695 -0
- data/ext/qr_reader_native/sp_format.h +83 -0
- data/ext/qr_reader_native/sp_gc.c +1793 -0
- data/ext/qr_reader_native/sp_gc.h +762 -0
- data/ext/qr_reader_native/sp_hash.c +131 -0
- data/ext/qr_reader_native/sp_hash.h +131 -0
- data/ext/qr_reader_native/sp_inspect.c +215 -0
- data/ext/qr_reader_native/sp_inspect.h +128 -0
- data/ext/qr_reader_native/sp_io.c +1676 -0
- data/ext/qr_reader_native/sp_io.h +272 -0
- data/ext/qr_reader_native/sp_iobuffer.c +1014 -0
- data/ext/qr_reader_native/sp_iobuffer.h +167 -0
- data/ext/qr_reader_native/sp_marshal.c +487 -0
- data/ext/qr_reader_native/sp_marshal.h +60 -0
- data/ext/qr_reader_native/sp_net.c +1029 -0
- data/ext/qr_reader_native/sp_net.h +205 -0
- data/ext/qr_reader_native/sp_pack.c +1254 -0
- data/ext/qr_reader_native/sp_poly_cold.c +1220 -0
- data/ext/qr_reader_native/sp_proc.c +410 -0
- data/ext/qr_reader_native/sp_proc.h +327 -0
- data/ext/qr_reader_native/sp_process.c +547 -0
- data/ext/qr_reader_native/sp_process_status.c +211 -0
- data/ext/qr_reader_native/sp_process_status.h +66 -0
- data/ext/qr_reader_native/sp_random.c +287 -0
- data/ext/qr_reader_native/sp_random.h +52 -0
- data/ext/qr_reader_native/sp_range.h +144 -0
- data/ext/qr_reader_native/sp_re.c +1379 -0
- data/ext/qr_reader_native/sp_re.h +186 -0
- data/ext/qr_reader_native/sp_re_names.h +59 -0
- data/ext/qr_reader_native/sp_sched.c +4044 -0
- data/ext/qr_reader_native/sp_sched.h +295 -0
- data/ext/qr_reader_native/sp_slab.c +1507 -0
- data/ext/qr_reader_native/sp_str.c +1462 -0
- data/ext/qr_reader_native/sp_str.h +306 -0
- data/ext/qr_reader_native/sp_str_crypt.c +23 -0
- data/ext/qr_reader_native/sp_string.c +92 -0
- data/ext/qr_reader_native/sp_string.h +253 -0
- data/ext/qr_reader_native/sp_system.c +78 -0
- data/ext/qr_reader_native/sp_system.h +18 -0
- data/ext/qr_reader_native/sp_time.c +860 -0
- data/ext/qr_reader_native/sp_time.h +100 -0
- data/ext/qr_reader_native/sp_types.h +292 -0
- data/ext/qr_reader_native/spinel_rt.h +19017 -0
- data/ext/qr_reader_native/unicase.c +399 -0
- data/ext/qr_reader_native/unicase.h +901 -0
- data/lib/qr_reader/native.rb +6 -0
- metadata +153 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#ifndef SP_RANGE_H
|
|
2
|
+
#define SP_RANGE_H
|
|
3
|
+
/* sp_range.h -- Range value-type helpers (see sp_types.h for sp_Range).
|
|
4
|
+
*
|
|
5
|
+
* sp_range_new / _to_ia are called from optcarrot's hot path (range
|
|
6
|
+
* literals / iteration), so they stay `static inline` here -- each
|
|
7
|
+
* generated TU still compiles its own copy, identical to when they lived
|
|
8
|
+
* directly in spinel_rt.h. sp_range_new_step / _eq are trivial
|
|
9
|
+
* single-expression constructors; marking them inline too is effectively a
|
|
10
|
+
* no-op (GCC already inlines such leaf functions at -O2) and keeps the
|
|
11
|
+
* whole small cluster together instead of splitting by a usage-count
|
|
12
|
+
* threshold that could drift under future edits.
|
|
13
|
+
*
|
|
14
|
+
* sp_range_include / sp_range_str see 0 optcarrot uses and have never been
|
|
15
|
+
* inline, so their bodies compile once into libspinel_rt.a (lib/sp_cold.c).
|
|
16
|
+
*/
|
|
17
|
+
#include "sp_types.h" /* sp_Range */
|
|
18
|
+
#include "sp_array.h" /* sp_IntArray_from_range / _from_range_step */
|
|
19
|
+
|
|
20
|
+
/* An Integer against a Float, compared exactly as CRuby does (#7505):
|
|
21
|
+
-1, 0 or 1, or 2 when the Float is NaN. Converting the Integer to a double
|
|
22
|
+
is exact only up to 2^53; above it 2**53 + 1 and 2.0**53 compared equal.
|
|
23
|
+
The double comparison decides every case it can; an apparent tie with an
|
|
24
|
+
Integer past 2^53 is settled on the integers, where the Float is integral. */
|
|
25
|
+
static SP_INLINE int sp_int_flt_cmp(sp_int i, sp_float d) {
|
|
26
|
+
if (d != d) return 2;
|
|
27
|
+
double di = (double)i;
|
|
28
|
+
if (di < d) return -1;
|
|
29
|
+
if (di > d) return 1;
|
|
30
|
+
if (i >= -9007199254740992LL && i <= 9007199254740992LL) return 0;
|
|
31
|
+
if (d >= 9223372036854775808.0) return -1;
|
|
32
|
+
if (d < -9223372036854775808.0) return 1;
|
|
33
|
+
long long t = (long long)d;
|
|
34
|
+
return ((long long)i > t) - ((long long)i < t);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Boxed copy/freeze operations stay out of the generated translation unit. */
|
|
38
|
+
sp_RbVal sp_range_dup(sp_RbVal v, int keep_frozen);
|
|
39
|
+
void sp_range_freeze(sp_RbVal v);
|
|
40
|
+
sp_bool sp_range_frozen(sp_RbVal v);
|
|
41
|
+
|
|
42
|
+
static inline sp_Range sp_range_new(sp_int f,sp_int l,sp_int e){sp_Range r;r.first=f;r.last=l;r.excl=e;r.step=0;r.fend=0.0;r.fe=0;r.unfrozen=0;return r;}
|
|
43
|
+
static inline sp_Range sp_range_new_step(sp_int f,sp_int l,sp_int e,sp_int s){sp_Range r;r.first=f;r.last=l;r.excl=e;r.step=s;r.fend=0.0;r.fe=0;r.unfrozen=0;return r;}
|
|
44
|
+
/* (1..2.5) / (1...2.5): an Integer begin with a finite Float end. The walk
|
|
45
|
+
stops at the last Integer the end admits -- floor(end), or end - 1 for an
|
|
46
|
+
excluded integral end -- and the end itself is kept for the readers that
|
|
47
|
+
answer it (sp_types.h). An end past sp_int's reach walks without end, as
|
|
48
|
+
an endless range does. */
|
|
49
|
+
sp_Range sp_range_new_fend(sp_int f, sp_float e, sp_int x);
|
|
50
|
+
/* A use that answers in Integers what CRuby answers with the Float end
|
|
51
|
+
(bsearch, step, rand, a clamp to the end): say so for such a Range. */
|
|
52
|
+
void sp_range_fend_unsupported(const char *m);
|
|
53
|
+
static inline void sp_range_int_only(sp_Range r, const char *m){if(r.fe)sp_range_fend_unsupported(m);}
|
|
54
|
+
/* A Range used as an index span (Array#[], String#[], fill, byteslice, ...):
|
|
55
|
+
CRuby converts each end with to_int, so a Float end truncates toward zero
|
|
56
|
+
and keeps its exclusivity -- a[1...2.5] is a[1...2], a[0..-2.5] a[0..-2] --
|
|
57
|
+
where the walk bounds floor it and fold the exclusivity in. */
|
|
58
|
+
static inline sp_Range sp_range_ix(sp_Range r){
|
|
59
|
+
if(!r.fe)return r;
|
|
60
|
+
sp_float t=r.fend!=r.fend?0.0:r.fend>9.2e18?9.2e18:r.fend<-9.2e18?-9.2e18:r.fend;
|
|
61
|
+
sp_Range x=sp_range_new(r.first,(sp_int)t,r.fe==2);
|
|
62
|
+
return x;
|
|
63
|
+
}
|
|
64
|
+
/* The end as a number for comparisons, and whether it was excluded as written. */
|
|
65
|
+
static inline sp_float sp_range_end_num(sp_Range r){return r.fe?r.fend:(sp_float)r.last;}
|
|
66
|
+
static inline sp_bool sp_range_excl_end(sp_Range r){return r.fe?r.fe==2:r.excl!=0;}
|
|
67
|
+
/* The effective stride: a literal `a..b` range stores 0, which iterates by +1. */
|
|
68
|
+
static inline sp_int sp_range_step(sp_Range r){return r.step==0?1:r.step;}
|
|
69
|
+
/* Number of elements the range enumerates (0 for an empty one), honoring step. */
|
|
70
|
+
static inline sp_int sp_range_count(sp_Range r){
|
|
71
|
+
sp_int s=sp_range_step(r);
|
|
72
|
+
sp_int lastv=r.excl?(r.last-(s>0?1:-1)):r.last;
|
|
73
|
+
sp_int n=(lastv-r.first)/s+1;
|
|
74
|
+
return n<0?0:n;
|
|
75
|
+
}
|
|
76
|
+
/* Materialize the range into an int array (ascending or descending per step).
|
|
77
|
+
The +1 stride (every literal `a..b` range) keeps the tight from_range loop; a
|
|
78
|
+
real step only appears for downto / explicit step, so it pays the general
|
|
79
|
+
path only then. */
|
|
80
|
+
static inline sp_IntArray *sp_range_to_ia(sp_Range r){
|
|
81
|
+
/* an endless range cannot materialize (CRuby raises instead of hanging) */
|
|
82
|
+
if(r.last==INTPTR_MAX)sp_raise_cls("RangeError","cannot convert endless range to an array");
|
|
83
|
+
if(r.first==INTPTR_MIN)sp_raise_cls("TypeError","can't iterate from NilClass");
|
|
84
|
+
sp_int s=sp_range_step(r);
|
|
85
|
+
if(s==1)return sp_IntArray_from_range(r.first,r.last-r.excl);
|
|
86
|
+
return sp_IntArray_from_range_step(r.first,r.last,s,r.excl);
|
|
87
|
+
}
|
|
88
|
+
/* Last enumerated element (== first for an empty range), and the min/max of the
|
|
89
|
+
enumerated set -- direction-aware, so a descending range reports them right. */
|
|
90
|
+
static inline sp_int sp_range_last_elem(sp_Range r){
|
|
91
|
+
sp_int n=sp_range_count(r);
|
|
92
|
+
return n<=0?r.first:r.first+(n-1)*sp_range_step(r);
|
|
93
|
+
}
|
|
94
|
+
/* min/max of an EMPTY (backwards, or exclusive single-point) range is nil
|
|
95
|
+
(SP_INT_NIL, the nullable-int sentinel) -- CRuby returns nil there. A
|
|
96
|
+
descending step range (5.downto(1)) still enumerates, so only a
|
|
97
|
+
positive-step empty span is nil (#2412). */
|
|
98
|
+
static inline sp_int sp_range_min_v(sp_Range r){
|
|
99
|
+
/* a beginless range has no minimum; an endless one's is its begin (#3668) */
|
|
100
|
+
if(r.first==INTPTR_MIN)sp_raise_cls("RangeError","cannot get the minimum of beginless range");
|
|
101
|
+
if(r.last==INTPTR_MAX)return r.first;
|
|
102
|
+
if(sp_range_count(r)<=0)return SP_INT_NIL; sp_int a=r.first,b=sp_range_last_elem(r); return a<b?a:b; }
|
|
103
|
+
void sp_range_fend_max_raise(sp_Range r);
|
|
104
|
+
static inline sp_int sp_range_max_v(sp_Range r){
|
|
105
|
+
/* a beginless range's maximum is its end; an endless one has none (#3668) */
|
|
106
|
+
/* a Float end (an infinite one too) is the maximum, which this Integer
|
|
107
|
+
reader cannot answer */
|
|
108
|
+
if(r.fe){if(r.first!=INTPTR_MIN&&(sp_float)r.first>r.fend)return SP_INT_NIL;sp_range_fend_max_raise(r);}
|
|
109
|
+
if(r.last==INTPTR_MAX)sp_raise_cls("RangeError","cannot get the maximum of endless range");
|
|
110
|
+
if(r.first==INTPTR_MIN)return r.excl?r.last-1:r.last;
|
|
111
|
+
if(sp_range_count(r)<=0)return SP_INT_NIL; sp_int a=r.first,b=sp_range_last_elem(r); return a>b?a:b; }
|
|
112
|
+
/* == compares the ends as numbers ((1..2.0) == (1..2)), eql? by class too */
|
|
113
|
+
static inline sp_bool sp_range_eq(sp_Range a,sp_Range b){
|
|
114
|
+
if(!a.fe&&!b.fe)return a.first==b.first&&a.last==b.last&&a.excl==b.excl;
|
|
115
|
+
return a.first==b.first&&sp_range_end_num(a)==sp_range_end_num(b)&&sp_range_excl_end(a)==sp_range_excl_end(b);}
|
|
116
|
+
static inline sp_bool sp_range_eql(sp_Range a,sp_Range b){return (a.fe!=0)==(b.fe!=0)&&sp_range_eq(a,b);}
|
|
117
|
+
|
|
118
|
+
sp_bool sp_range_include(sp_Range *r, sp_int x);
|
|
119
|
+
sp_bool sp_range_cover_f(sp_Range *r, sp_float x);
|
|
120
|
+
const char *sp_range_str(sp_Range r);
|
|
121
|
+
const char *sp_range_inspect(sp_Range r);
|
|
122
|
+
|
|
123
|
+
/* Float/String Range value-type ops -- 0 optcarrot uses, bodies in
|
|
124
|
+
lib/sp_cold.c (see sp_types.h for sp_FloatRange/sp_StrRange). */
|
|
125
|
+
sp_FloatRange sp_frange_new(sp_float f, sp_float l, sp_int e);
|
|
126
|
+
sp_FloatRange sp_frange_new_o(sp_float f, sp_float l, sp_int e, sp_int om);
|
|
127
|
+
sp_bool sp_frange_cover(sp_FloatRange r, sp_float x);
|
|
128
|
+
sp_bool sp_frange_cover_i(sp_FloatRange r, sp_int x);
|
|
129
|
+
sp_bool sp_frange_eq(sp_FloatRange a, sp_FloatRange b);
|
|
130
|
+
const char *sp_frange_inspect(sp_FloatRange r);
|
|
131
|
+
sp_RbVal sp_box_frange(sp_FloatRange v);
|
|
132
|
+
sp_float sp_frange_max(sp_FloatRange r);
|
|
133
|
+
sp_StrRange sp_srange_new(const char *f, const char *l, sp_int e);
|
|
134
|
+
sp_StrArray *sp_srange_to_a(sp_StrRange r);
|
|
135
|
+
sp_bool sp_srange_eq(sp_StrRange a, sp_StrRange b);
|
|
136
|
+
sp_bool sp_srange_cover(sp_StrRange r, const char *x);
|
|
137
|
+
sp_bool sp_srange_include(sp_StrRange r, const char *x);
|
|
138
|
+
const char *sp_srange_min_v(sp_StrRange r);
|
|
139
|
+
const char *sp_srange_max_v(sp_StrRange r);
|
|
140
|
+
const char *sp_srange_to_s(sp_StrRange r);
|
|
141
|
+
const char *sp_srange_inspect(sp_StrRange r);
|
|
142
|
+
sp_RbVal sp_box_srange(sp_StrRange v);
|
|
143
|
+
|
|
144
|
+
#endif
|