xnd 0.2.0dev3
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/CONTRIBUTING.md +42 -0
- data/Gemfile +3 -0
- data/History.md +0 -0
- data/README.md +7 -0
- data/Rakefile +135 -0
- data/ext/ruby_xnd/extconf.rb +70 -0
- data/ext/ruby_xnd/float_pack_unpack.c +277 -0
- data/ext/ruby_xnd/float_pack_unpack.h +39 -0
- data/ext/ruby_xnd/gc_guard.c +36 -0
- data/ext/ruby_xnd/gc_guard.h +12 -0
- data/ext/ruby_xnd/include/xnd.h +449 -0
- data/ext/ruby_xnd/lib/libxnd.a +0 -0
- data/ext/ruby_xnd/lib/libxnd.so +1 -0
- data/ext/ruby_xnd/lib/libxnd.so.0 +1 -0
- data/ext/ruby_xnd/lib/libxnd.so.0.2.0dev3 +0 -0
- data/ext/ruby_xnd/memory_block_object.c +32 -0
- data/ext/ruby_xnd/memory_block_object.h +33 -0
- data/ext/ruby_xnd/ruby_xnd.c +1953 -0
- data/ext/ruby_xnd/ruby_xnd.h +61 -0
- data/ext/ruby_xnd/ruby_xnd_internal.h +85 -0
- data/ext/ruby_xnd/util.h +170 -0
- data/ext/ruby_xnd/xnd/AUTHORS.txt +5 -0
- data/ext/ruby_xnd/xnd/INSTALL.txt +134 -0
- data/ext/ruby_xnd/xnd/LICENSE.txt +29 -0
- data/ext/ruby_xnd/xnd/MANIFEST.in +3 -0
- data/ext/ruby_xnd/xnd/Makefile.in +80 -0
- data/ext/ruby_xnd/xnd/README.rst +44 -0
- data/ext/ruby_xnd/xnd/config.guess +1530 -0
- data/ext/ruby_xnd/xnd/config.h.in +22 -0
- data/ext/ruby_xnd/xnd/config.sub +1782 -0
- data/ext/ruby_xnd/xnd/configure +4867 -0
- data/ext/ruby_xnd/xnd/configure.ac +164 -0
- data/ext/ruby_xnd/xnd/doc/Makefile +14 -0
- data/ext/ruby_xnd/xnd/doc/_static/copybutton.js +66 -0
- data/ext/ruby_xnd/xnd/doc/conf.py +26 -0
- data/ext/ruby_xnd/xnd/doc/index.rst +44 -0
- data/ext/ruby_xnd/xnd/doc/libxnd/data-structures.rst +186 -0
- data/ext/ruby_xnd/xnd/doc/libxnd/functions.rst +148 -0
- data/ext/ruby_xnd/xnd/doc/libxnd/index.rst +25 -0
- data/ext/ruby_xnd/xnd/doc/releases/index.rst +34 -0
- data/ext/ruby_xnd/xnd/doc/xnd/align-pack.rst +96 -0
- data/ext/ruby_xnd/xnd/doc/xnd/buffer-protocol.rst +42 -0
- data/ext/ruby_xnd/xnd/doc/xnd/index.rst +30 -0
- data/ext/ruby_xnd/xnd/doc/xnd/quickstart.rst +62 -0
- data/ext/ruby_xnd/xnd/doc/xnd/types.rst +674 -0
- data/ext/ruby_xnd/xnd/install-sh +527 -0
- data/ext/ruby_xnd/xnd/libxnd/Makefile.in +102 -0
- data/ext/ruby_xnd/xnd/libxnd/Makefile.vc +112 -0
- data/ext/ruby_xnd/xnd/libxnd/bitmaps.c +345 -0
- data/ext/ruby_xnd/xnd/libxnd/contrib.h +313 -0
- data/ext/ruby_xnd/xnd/libxnd/copy.c +944 -0
- data/ext/ruby_xnd/xnd/libxnd/equal.c +1216 -0
- data/ext/ruby_xnd/xnd/libxnd/inline.h +154 -0
- data/ext/ruby_xnd/xnd/libxnd/overflow.h +147 -0
- data/ext/ruby_xnd/xnd/libxnd/split.c +286 -0
- data/ext/ruby_xnd/xnd/libxnd/tests/Makefile.in +39 -0
- data/ext/ruby_xnd/xnd/libxnd/tests/Makefile.vc +44 -0
- data/ext/ruby_xnd/xnd/libxnd/tests/README.txt +2 -0
- data/ext/ruby_xnd/xnd/libxnd/tests/runtest.c +101 -0
- data/ext/ruby_xnd/xnd/libxnd/tests/test.h +48 -0
- data/ext/ruby_xnd/xnd/libxnd/tests/test_fixed.c +108 -0
- data/ext/ruby_xnd/xnd/libxnd/xnd.c +1304 -0
- data/ext/ruby_xnd/xnd/libxnd/xnd.h +449 -0
- data/ext/ruby_xnd/xnd/python/test_xnd.py +3144 -0
- data/ext/ruby_xnd/xnd/python/xnd/__init__.py +290 -0
- data/ext/ruby_xnd/xnd/python/xnd/_xnd.c +2822 -0
- data/ext/ruby_xnd/xnd/python/xnd/contrib/pretty.py +850 -0
- data/ext/ruby_xnd/xnd/python/xnd/docstrings.h +129 -0
- data/ext/ruby_xnd/xnd/python/xnd/pyxnd.h +200 -0
- data/ext/ruby_xnd/xnd/python/xnd/util.h +182 -0
- data/ext/ruby_xnd/xnd/python/xnd_randvalue.py +1121 -0
- data/ext/ruby_xnd/xnd/python/xnd_support.py +106 -0
- data/ext/ruby_xnd/xnd/setup.py +303 -0
- data/ext/ruby_xnd/xnd/vcbuild/INSTALL.txt +42 -0
- data/ext/ruby_xnd/xnd/vcbuild/runtest32.bat +16 -0
- data/ext/ruby_xnd/xnd/vcbuild/runtest64.bat +14 -0
- data/ext/ruby_xnd/xnd/vcbuild/vcbuild32.bat +29 -0
- data/ext/ruby_xnd/xnd/vcbuild/vcbuild64.bat +29 -0
- data/ext/ruby_xnd/xnd/vcbuild/vcclean.bat +13 -0
- data/ext/ruby_xnd/xnd/vcbuild/vcdistclean.bat +14 -0
- data/lib/ruby_xnd.so +0 -0
- data/lib/xnd.rb +306 -0
- data/lib/xnd/monkeys.rb +29 -0
- data/lib/xnd/version.rb +6 -0
- data/spec/debug_spec.rb +9 -0
- data/spec/gc_guard_spec.rb +10 -0
- data/spec/leakcheck.rb +9 -0
- data/spec/spec_helper.rb +877 -0
- data/spec/type_inference_spec.rb +81 -0
- data/spec/xnd_spec.rb +2921 -0
- data/xnd.gemspec +47 -0
- metadata +215 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
|
|
2
|
+
# ==============================================================================
|
|
3
|
+
# Unix Makefile for libxnd
|
|
4
|
+
# ==============================================================================
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
LIBSTATIC = @LIBSTATIC@
|
|
8
|
+
LIBNAME = @LIBNAME@
|
|
9
|
+
LIBSONAME = @LIBSONAME@
|
|
10
|
+
LIBSHARED = @LIBSHARED@
|
|
11
|
+
|
|
12
|
+
CC = @CC@
|
|
13
|
+
LD = @LD@
|
|
14
|
+
AR = @AR@
|
|
15
|
+
RANLIB = @RANLIB@
|
|
16
|
+
|
|
17
|
+
XND_INCLUDES = @CONFIGURE_INCLUDES@
|
|
18
|
+
|
|
19
|
+
CONFIGURE_CFLAGS = @CONFIGURE_CFLAGS@
|
|
20
|
+
XND_CFLAGS = $(strip -I$(XND_INCLUDES) $(CONFIGURE_CFLAGS) $(CFLAGS))
|
|
21
|
+
XND_CFLAGS_SHARED = $(XND_CFLAGS) -fPIC
|
|
22
|
+
|
|
23
|
+
CONFIGURE_LDFLAGS = @CONFIGURE_LDFLAGS@
|
|
24
|
+
XND_LDFLAGS = $(strip $(CONFIGURE_LDFLAGS) $(LDFLAGS))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
default: $(LIBSTATIC) $(LIBSHARED)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
OBJS = bitmaps.o copy.o equal.o split.o xnd.o
|
|
31
|
+
|
|
32
|
+
SHARED_OBJS = .objs/bitmaps.o .objs/copy.o .objs/equal.o .objs/split.o .objs/xnd.o
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
$(LIBSTATIC): Makefile $(OBJS)
|
|
36
|
+
$(AR) rc $(LIBSTATIC) $(OBJS)
|
|
37
|
+
$(RANLIB) $(LIBSTATIC)
|
|
38
|
+
|
|
39
|
+
$(LIBSHARED): Makefile $(SHARED_OBJS)
|
|
40
|
+
$(LD) $(XND_LDFLAGS) -o $(LIBSHARED) $(SHARED_OBJS)
|
|
41
|
+
ln -sf $(LIBSHARED) $(LIBNAME)
|
|
42
|
+
ln -sf $(LIBSHARED) $(LIBSONAME)
|
|
43
|
+
|
|
44
|
+
bitmaps.o:\
|
|
45
|
+
Makefile bitmaps.c xnd.h
|
|
46
|
+
$(CC) $(XND_CFLAGS) -c bitmaps.c
|
|
47
|
+
|
|
48
|
+
.objs/bitmaps.o:\
|
|
49
|
+
Makefile bitmaps.c xnd.h
|
|
50
|
+
$(CC) $(XND_CFLAGS_SHARED) -c bitmaps.c -o .objs/bitmaps.o
|
|
51
|
+
|
|
52
|
+
copy.o:\
|
|
53
|
+
Makefile copy.c xnd.h
|
|
54
|
+
$(CC) $(XND_CFLAGS) -c copy.c
|
|
55
|
+
|
|
56
|
+
.objs/copy.o:\
|
|
57
|
+
Makefile copy.c xnd.h
|
|
58
|
+
$(CC) $(XND_CFLAGS_SHARED) -c copy.c -o .objs/copy.o
|
|
59
|
+
|
|
60
|
+
equal.o:\
|
|
61
|
+
Makefile equal.c xnd.h
|
|
62
|
+
$(CC) $(XND_CFLAGS) -c equal.c
|
|
63
|
+
|
|
64
|
+
.objs/equal.o:\
|
|
65
|
+
Makefile equal.c xnd.h
|
|
66
|
+
$(CC) $(XND_CFLAGS_SHARED) -c equal.c -o .objs/equal.o
|
|
67
|
+
|
|
68
|
+
split.o:\
|
|
69
|
+
Makefile split.c overflow.h xnd.h
|
|
70
|
+
$(CC) $(XND_CFLAGS) -c split.c
|
|
71
|
+
|
|
72
|
+
.objs/split.o:\
|
|
73
|
+
Makefile split.c overflow.h xnd.h
|
|
74
|
+
$(CC) $(XND_CFLAGS_SHARED) -c split.c -o .objs/split.o
|
|
75
|
+
|
|
76
|
+
xnd.o:\
|
|
77
|
+
Makefile xnd.c xnd.h
|
|
78
|
+
$(CC) $(XND_CFLAGS) -c xnd.c
|
|
79
|
+
|
|
80
|
+
.objs/xnd.o:\
|
|
81
|
+
Makefile xnd.c xnd.h
|
|
82
|
+
$(CC) $(XND_CFLAGS_SHARED) -c xnd.c -o .objs/xnd.o
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# Coverage
|
|
86
|
+
coverage:\
|
|
87
|
+
Makefile clean runtest
|
|
88
|
+
./tests/runtest
|
|
89
|
+
for file in *.c; do gcov -l "$$file" > /dev/null 2>&1; done
|
|
90
|
+
|
|
91
|
+
FORCE:
|
|
92
|
+
|
|
93
|
+
clean: FORCE
|
|
94
|
+
rm -f *.o *.so *.gch *.gcda *.gcno *.gcov *.dyn *.dpi *.lock
|
|
95
|
+
rm -f $(LIBSTATIC) $(LIBSHARED) $(LIBSONAME) $(LIBNAME)
|
|
96
|
+
cd .objs && rm -f *.o *.so *.gch *.gcda *.gcno *.gcov *.dyn *.dpi *.lock
|
|
97
|
+
|
|
98
|
+
distclean: clean
|
|
99
|
+
rm -f Makefile
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
|
|
2
|
+
# ======================================================================
|
|
3
|
+
# Visual C (nmake) Makefile for libxnd
|
|
4
|
+
# ======================================================================
|
|
5
|
+
|
|
6
|
+
LIBSTATIC = libxnd-0.2.0dev3.lib
|
|
7
|
+
LIBIMPORT = libxnd-0.2.0dev3.dll.lib
|
|
8
|
+
LIBSHARED = libxnd-0.2.0dev3.dll
|
|
9
|
+
LIBNDTYPESIMPORT = libndtypes-0.2.0dev3.dll.lib
|
|
10
|
+
|
|
11
|
+
!ifndef LIBNDTYPESINCLUDE
|
|
12
|
+
LIBNDTYPESINCLUDE = ..\ndtypes\libndtypes
|
|
13
|
+
!endif
|
|
14
|
+
|
|
15
|
+
!ifndef LIBNDTYPESDIR
|
|
16
|
+
LIBNDTYPESDIR = ..\ndtypes\libndtypes
|
|
17
|
+
!endif
|
|
18
|
+
|
|
19
|
+
OPT = /MT /Ox /GS /EHsc
|
|
20
|
+
OPT_SHARED = /DXND_EXPORT /MD /Ox /GS /EHsc /Fo.objs^\
|
|
21
|
+
|
|
22
|
+
COMMON_CFLAGS = /nologo /W4 /wd4200 /wd4201 /wd4204
|
|
23
|
+
CFLAGS = $(COMMON_CFLAGS) $(OPT)
|
|
24
|
+
CFLAGS_SHARED = $(COMMON_CFLAGS) $(OPT_SHARED)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
default: $(LIBSTATIC) $(LIBSHARED)
|
|
28
|
+
copy /y xnd.h ..\python\xnd
|
|
29
|
+
copy /y $(LIBSTATIC) ..\python\xnd
|
|
30
|
+
copy /y $(LIBIMPORT) ..\python\xnd
|
|
31
|
+
copy /y $(LIBSHARED) ..\python\xnd
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
OBJS = bitmaps.obj copy.obj equal.obj split.obj xnd.obj
|
|
35
|
+
|
|
36
|
+
SHARED_OBJS = .objs\bitmaps.obj .objs\copy.obj .objs\equal.obj .objs\split.obj .objs\xnd.obj
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
$(LIBSTATIC):\
|
|
40
|
+
Makefile $(OBJS)
|
|
41
|
+
-@if exist $@ del $(LIBSTATIC)
|
|
42
|
+
lib /nologo /out:$(LIBSTATIC) $(OBJS)
|
|
43
|
+
|
|
44
|
+
$(LIBSHARED):\
|
|
45
|
+
Makefile $(SHARED_OBJS)
|
|
46
|
+
-@if exist $@ del $(LIBSHARED)
|
|
47
|
+
link /nologo /DLL /MANIFEST /out:$(LIBSHARED) /implib:$(LIBIMPORT) $(SHARED_OBJS) "/LIBPATH:$(LIBNDTYPESDIR)" $(LIBNDTYPESIMPORT)
|
|
48
|
+
mt /nologo -manifest $(LIBSHARED).manifest -outputresource:$(LIBSHARED);2
|
|
49
|
+
|
|
50
|
+
bitmaps.obj:\
|
|
51
|
+
Makefile bitmaps.c xnd.h
|
|
52
|
+
$(CC) "-I$(LIBNDTYPESINCLUDE)" $(CFLAGS) -c bitmaps.c
|
|
53
|
+
|
|
54
|
+
.objs\bitmaps.obj:\
|
|
55
|
+
Makefile bitmaps.c xnd.h
|
|
56
|
+
$(CC) "-I$(LIBNDTYPESINCLUDE)" $(CFLAGS_SHARED) -c bitmaps.c
|
|
57
|
+
|
|
58
|
+
copy.obj:\
|
|
59
|
+
Makefile copy.c xnd.h
|
|
60
|
+
$(CC) "-I$(LIBNDTYPESINCLUDE)" $(CFLAGS) -c copy.c
|
|
61
|
+
|
|
62
|
+
.objs\copy.obj:\
|
|
63
|
+
Makefile copy.c xnd.h
|
|
64
|
+
$(CC) "-I$(LIBNDTYPESINCLUDE)" $(CFLAGS_SHARED) -c copy.c
|
|
65
|
+
|
|
66
|
+
equal.obj:\
|
|
67
|
+
Makefile equal.c xnd.h
|
|
68
|
+
$(CC) "-I$(LIBNDTYPESINCLUDE)" $(CFLAGS) -c equal.c
|
|
69
|
+
|
|
70
|
+
.objs\equal.obj:\
|
|
71
|
+
Makefile equal.c xnd.h
|
|
72
|
+
$(CC) "-I$(LIBNDTYPESINCLUDE)" $(CFLAGS_SHARED) -c equal.c
|
|
73
|
+
|
|
74
|
+
split.obj:\
|
|
75
|
+
Makefile split.c overflow.h xnd.h
|
|
76
|
+
$(CC) "-I$(LIBNDTYPESINCLUDE)" $(CFLAGS) -c split.c
|
|
77
|
+
|
|
78
|
+
.objs\split.obj:\
|
|
79
|
+
Makefile split.c overflow.h xnd.h
|
|
80
|
+
$(CC) "-I$(LIBNDTYPESINCLUDE)" $(CFLAGS_SHARED) -c split.c
|
|
81
|
+
|
|
82
|
+
xnd.obj:\
|
|
83
|
+
Makefile xnd.c xnd.h
|
|
84
|
+
$(CC) "-I$(LIBNDTYPESINCLUDE)" $(CFLAGS) -c xnd.c
|
|
85
|
+
|
|
86
|
+
.objs\xnd.obj:\
|
|
87
|
+
Makefile xnd.c xnd.h
|
|
88
|
+
$(CC) "-I$(LIBNDTYPESINCLUDE)" $(CFLAGS_SHARED) -c xnd.c
|
|
89
|
+
|
|
90
|
+
check:\
|
|
91
|
+
Makefile default
|
|
92
|
+
cd tests && copy /y Makefile.vc Makefile && nmake /nologo
|
|
93
|
+
.\tests\runtest.exe
|
|
94
|
+
.\tests\runtest_shared.exe
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
FORCE:
|
|
98
|
+
|
|
99
|
+
clean: FORCE
|
|
100
|
+
del /q /f *.exe *.obj *.lib *.dll *.exp *.manifest 2>NUL
|
|
101
|
+
cd .objs && del /q /f *.obj 2>NUL
|
|
102
|
+
if exist "..\build\" rd /q /s "..\build\"
|
|
103
|
+
if exist "..\dist\" rd /q /s "..\dist\"
|
|
104
|
+
if exist "..\MANIFEST" del "..\MANIFEST"
|
|
105
|
+
if exist "..\record.txt" del "..\record.txt"
|
|
106
|
+
cd ..\python\xnd && del *.lib *.dll *.pyd xnd.h 2>NUL
|
|
107
|
+
|
|
108
|
+
distclean: clean
|
|
109
|
+
del Makefile 2>NUL
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* BSD 3-Clause License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2017-2018, plures
|
|
5
|
+
* All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
|
9
|
+
*
|
|
10
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
* this list of conditions and the following disclaimer.
|
|
12
|
+
*
|
|
13
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
* and/or other materials provided with the distribution.
|
|
16
|
+
*
|
|
17
|
+
* 3. Neither the name of the copyright holder nor the names of its
|
|
18
|
+
* contributors may be used to endorse or promote products derived from
|
|
19
|
+
* this software without specific prior written permission.
|
|
20
|
+
*
|
|
21
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
25
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
26
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
27
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
28
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
29
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
#include <stdlib.h>
|
|
35
|
+
#include <stdint.h>
|
|
36
|
+
#include <inttypes.h>
|
|
37
|
+
#include <assert.h>
|
|
38
|
+
#include "ndtypes.h"
|
|
39
|
+
#include "xnd.h"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const xnd_bitmap_t xnd_bitmap_empty = { .data = NULL, .size = 0, .next = NULL};
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
static int64_t
|
|
46
|
+
bitmap_size(int64_t nelem)
|
|
47
|
+
{
|
|
48
|
+
return (nelem + 7) / 8;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static uint8_t *
|
|
52
|
+
bits_new(int64_t n, ndt_context_t *ctx)
|
|
53
|
+
{
|
|
54
|
+
uint8_t *bits;
|
|
55
|
+
|
|
56
|
+
bits = ndt_calloc(bitmap_size(n), 1);
|
|
57
|
+
if (bits == NULL) {
|
|
58
|
+
return ndt_memory_error(ctx);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return bits;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static xnd_bitmap_t *
|
|
65
|
+
bitmap_array_new(int64_t n, ndt_context_t *ctx)
|
|
66
|
+
{
|
|
67
|
+
xnd_bitmap_t *b;
|
|
68
|
+
|
|
69
|
+
b = ndt_calloc(n, sizeof *b);
|
|
70
|
+
if (b == NULL) {
|
|
71
|
+
return ndt_memory_error(ctx);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return b;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static int
|
|
78
|
+
bitmap_init(xnd_bitmap_t *b, const ndt_t *t, int64_t nitems, ndt_context_t *ctx)
|
|
79
|
+
{
|
|
80
|
+
xnd_bitmap_t *next;
|
|
81
|
+
int64_t shape, i, k;
|
|
82
|
+
int64_t n;
|
|
83
|
+
|
|
84
|
+
assert(ndt_is_concrete(t));
|
|
85
|
+
assert(b->data == NULL);
|
|
86
|
+
assert(b->size == 0);
|
|
87
|
+
assert(b->next == NULL);
|
|
88
|
+
|
|
89
|
+
if (t->ndim == 0 && ndt_is_optional(t)) {
|
|
90
|
+
b->data = bits_new(nitems, ctx);
|
|
91
|
+
if (b->data == NULL) {
|
|
92
|
+
return -1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!ndt_subtree_is_optional(t)) {
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
switch (t->tag) {
|
|
101
|
+
case FixedDim: {
|
|
102
|
+
shape = t->FixedDim.shape;
|
|
103
|
+
return bitmap_init(b, t->FixedDim.type, nitems * shape, ctx);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
case VarDim: {
|
|
107
|
+
assert(nitems == 1);
|
|
108
|
+
n = nitems;
|
|
109
|
+
|
|
110
|
+
if (t->ndim == 1) {
|
|
111
|
+
int32_t noffsets = t->Concrete.VarDim.noffsets;
|
|
112
|
+
n = t->Concrete.VarDim.offsets[noffsets-1];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return bitmap_init(b, t->VarDim.type, n, ctx);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
case Tuple: {
|
|
119
|
+
shape = t->Tuple.shape;
|
|
120
|
+
|
|
121
|
+
n = nitems * shape;
|
|
122
|
+
b->next = bitmap_array_new(n, ctx);
|
|
123
|
+
if (b->next == NULL) {
|
|
124
|
+
xnd_bitmap_clear(b);
|
|
125
|
+
return -1;
|
|
126
|
+
}
|
|
127
|
+
b->size = n;
|
|
128
|
+
|
|
129
|
+
for (i = 0; i < nitems; i++) {
|
|
130
|
+
for (k = 0; k < shape; k++) {
|
|
131
|
+
next = b->next + i*shape + k;
|
|
132
|
+
if (bitmap_init(next, t->Tuple.types[k], 1, ctx) < 0) {
|
|
133
|
+
xnd_bitmap_clear(b);
|
|
134
|
+
return -1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
case Record: {
|
|
143
|
+
shape = t->Record.shape;
|
|
144
|
+
|
|
145
|
+
n = nitems * shape;
|
|
146
|
+
b->next = bitmap_array_new(n, ctx);
|
|
147
|
+
if (b->next == NULL) {
|
|
148
|
+
xnd_bitmap_clear(b);
|
|
149
|
+
return -1;
|
|
150
|
+
}
|
|
151
|
+
b->size = n;
|
|
152
|
+
|
|
153
|
+
for (i = 0; i < nitems; i++) {
|
|
154
|
+
for (k = 0; k < shape; k++) {
|
|
155
|
+
next = b->next + i*shape + k;
|
|
156
|
+
if (bitmap_init(next, t->Record.types[k], 1, ctx) < 0) {
|
|
157
|
+
xnd_bitmap_clear(b);
|
|
158
|
+
return -1;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return 0;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
case Ref: {
|
|
167
|
+
b->next = bitmap_array_new(nitems, ctx);
|
|
168
|
+
if (b->next == NULL) {
|
|
169
|
+
xnd_bitmap_clear(b);
|
|
170
|
+
return -1;
|
|
171
|
+
}
|
|
172
|
+
b->size = nitems;
|
|
173
|
+
|
|
174
|
+
for (i = 0; i < nitems; i++) {
|
|
175
|
+
next = b->next + i;
|
|
176
|
+
if (bitmap_init(next, t->Ref.type, 1, ctx) < 0) {
|
|
177
|
+
xnd_bitmap_clear(b);
|
|
178
|
+
return -1;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
case Constr: {
|
|
186
|
+
b->next = bitmap_array_new(nitems, ctx);
|
|
187
|
+
if (b->next == NULL) {
|
|
188
|
+
xnd_bitmap_clear(b);
|
|
189
|
+
return -1;
|
|
190
|
+
}
|
|
191
|
+
b->size = nitems;
|
|
192
|
+
|
|
193
|
+
for (i = 0; i < nitems; i++) {
|
|
194
|
+
next = b->next + i;
|
|
195
|
+
if (bitmap_init(next, t->Constr.type, 1, ctx) < 0) {
|
|
196
|
+
xnd_bitmap_clear(b);
|
|
197
|
+
return -1;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
case Nominal: {
|
|
205
|
+
b->next = bitmap_array_new(nitems, ctx);
|
|
206
|
+
if (b->next == NULL) {
|
|
207
|
+
xnd_bitmap_clear(b);
|
|
208
|
+
return -1;
|
|
209
|
+
}
|
|
210
|
+
b->size = nitems;
|
|
211
|
+
|
|
212
|
+
for (i = 0; i < nitems; i++) {
|
|
213
|
+
next = b->next + i;
|
|
214
|
+
if (bitmap_init(next, t->Nominal.type, 1, ctx) < 0) {
|
|
215
|
+
xnd_bitmap_clear(b);
|
|
216
|
+
return -1;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return 0;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
default:
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
int
|
|
229
|
+
xnd_bitmap_init(xnd_bitmap_t *b, const ndt_t *t, ndt_context_t *ctx)
|
|
230
|
+
{
|
|
231
|
+
return bitmap_init(b, t, 1, ctx);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
void
|
|
235
|
+
xnd_bitmap_clear(xnd_bitmap_t *b)
|
|
236
|
+
{
|
|
237
|
+
int64_t i;
|
|
238
|
+
|
|
239
|
+
ndt_free(b->data);
|
|
240
|
+
b->data = NULL;
|
|
241
|
+
|
|
242
|
+
if (b->next) {
|
|
243
|
+
for (i = 0; i < b->size; i++) {
|
|
244
|
+
xnd_bitmap_clear(b->next + i);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
ndt_free(b->next);
|
|
248
|
+
b->next = NULL;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
xnd_bitmap_t
|
|
253
|
+
xnd_bitmap_next(const xnd_t *x, int64_t i, ndt_context_t *ctx)
|
|
254
|
+
{
|
|
255
|
+
const ndt_t *t = x->type;
|
|
256
|
+
xnd_bitmap_t next = {.data=NULL, .size=0, .next=NULL};
|
|
257
|
+
int64_t shape;
|
|
258
|
+
|
|
259
|
+
if (!ndt_subtree_is_optional(t)) {
|
|
260
|
+
return next;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (x->bitmap.next == NULL) {
|
|
264
|
+
ndt_err_format(ctx, NDT_RuntimeError, "missing bitmap");
|
|
265
|
+
return next;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
switch (t->tag) {
|
|
269
|
+
case Tuple:
|
|
270
|
+
shape = t->Tuple.shape;
|
|
271
|
+
break;
|
|
272
|
+
case Record:
|
|
273
|
+
shape = t->Record.shape;
|
|
274
|
+
break;
|
|
275
|
+
case Ref: case Constr: case Nominal:
|
|
276
|
+
shape = 1;
|
|
277
|
+
break;
|
|
278
|
+
default:
|
|
279
|
+
ndt_err_format(ctx, NDT_RuntimeError, "type has no subtree bitmaps");
|
|
280
|
+
return next;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (i < 0 || i >= shape) {
|
|
284
|
+
ndt_err_format(ctx, NDT_ValueError, "invalid index");
|
|
285
|
+
return next;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return x->bitmap.next[x->index * shape + i];
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
void
|
|
292
|
+
xnd_set_valid(xnd_t *x)
|
|
293
|
+
{
|
|
294
|
+
const ndt_t *t = x->type;
|
|
295
|
+
int64_t n = x->index;
|
|
296
|
+
|
|
297
|
+
assert(ndt_is_optional(t));
|
|
298
|
+
assert(0 <= n);
|
|
299
|
+
|
|
300
|
+
x->bitmap.data[n / 8] |= ((uint8_t)1 << (n % 8));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
void
|
|
304
|
+
xnd_set_na(xnd_t *x)
|
|
305
|
+
{
|
|
306
|
+
const ndt_t *t = x->type;
|
|
307
|
+
int64_t n = x->index;
|
|
308
|
+
|
|
309
|
+
assert(ndt_is_optional(t));
|
|
310
|
+
assert(0 <= n);
|
|
311
|
+
|
|
312
|
+
x->bitmap.data[n / 8] &= ~((uint8_t)1 << (n % 8));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
static int
|
|
316
|
+
_xnd_is_valid(const xnd_t *x)
|
|
317
|
+
{
|
|
318
|
+
const ndt_t *t = x->type;
|
|
319
|
+
int64_t n = x->index;
|
|
320
|
+
|
|
321
|
+
assert(ndt_is_optional(t));
|
|
322
|
+
assert(0 <= n);
|
|
323
|
+
|
|
324
|
+
return x->bitmap.data[n / 8] & ((uint8_t)1 << (n % 8));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
int
|
|
328
|
+
xnd_is_valid(const xnd_t *x)
|
|
329
|
+
{
|
|
330
|
+
if (!ndt_is_optional(x->type)) {
|
|
331
|
+
return 1;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return _xnd_is_valid(x);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
int
|
|
338
|
+
xnd_is_na(const xnd_t *x)
|
|
339
|
+
{
|
|
340
|
+
if (!ndt_is_optional(x->type)) {
|
|
341
|
+
return 0;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return !_xnd_is_valid(x);
|
|
345
|
+
}
|