ndtypes 0.2.0dev4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +50 -0
- data/Gemfile +2 -0
- data/History.md +0 -0
- data/README.md +19 -0
- data/Rakefile +125 -0
- data/ext/ruby_ndtypes/extconf.rb +55 -0
- data/ext/ruby_ndtypes/gc_guard.c +36 -0
- data/ext/ruby_ndtypes/gc_guard.h +12 -0
- data/ext/ruby_ndtypes/ndtypes/AUTHORS.txt +5 -0
- data/ext/ruby_ndtypes/ndtypes/INSTALL.txt +101 -0
- data/ext/ruby_ndtypes/ndtypes/LICENSE.txt +29 -0
- data/ext/ruby_ndtypes/ndtypes/MANIFEST.in +3 -0
- data/ext/ruby_ndtypes/ndtypes/Makefile.in +87 -0
- data/ext/ruby_ndtypes/ndtypes/README.rst +47 -0
- data/ext/ruby_ndtypes/ndtypes/config.guess +1530 -0
- data/ext/ruby_ndtypes/ndtypes/config.h.in +67 -0
- data/ext/ruby_ndtypes/ndtypes/config.sub +1782 -0
- data/ext/ruby_ndtypes/ndtypes/configure +5260 -0
- data/ext/ruby_ndtypes/ndtypes/configure.ac +161 -0
- data/ext/ruby_ndtypes/ndtypes/doc/Makefile +14 -0
- data/ext/ruby_ndtypes/ndtypes/doc/_static/copybutton.js +66 -0
- data/ext/ruby_ndtypes/ndtypes/doc/conf.py +26 -0
- data/ext/ruby_ndtypes/ndtypes/doc/grammar/grammar.rst +27 -0
- data/ext/ruby_ndtypes/ndtypes/doc/index.rst +56 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/context.rst +131 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/encodings.rst +68 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/fields-values.rst +175 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/functions.rst +72 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/index.rst +43 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/init.rst +48 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/io.rst +100 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/memory.rst +124 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/predicates.rst +110 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/typedef.rst +31 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/types.rst +594 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/util.rst +166 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/buffer-protocol.rst +27 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/index.rst +21 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/pattern-matching.rst +330 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/quickstart.rst +144 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/types.rst +544 -0
- data/ext/ruby_ndtypes/ndtypes/doc/releases/index.rst +35 -0
- data/ext/ruby_ndtypes/ndtypes/install-sh +527 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.in +271 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.vc +269 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.c +230 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.c +268 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.h +109 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.in +73 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.vc +70 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/README.txt +16 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.c +2179 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.h +134 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.y +428 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.c +2543 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.h +735 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.l +176 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.c +543 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.c +110 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/context.c +228 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.c +634 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/encodings.c +116 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.c +288 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.c +3067 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.h +180 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.y +417 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/io.c +1658 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.c +2773 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.h +734 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.l +222 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/match.c +1132 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.c +2323 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h.in +893 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/overflow.h +161 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.c +473 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.h +92 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.c +246 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.c +269 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.h +197 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.in +48 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.vc +46 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.c +1007 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.c +442 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/slice.h +42 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.c +238 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.h +50 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.c +371 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.h +100 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.in +55 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.vc +45 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.c +82 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.h +49 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/runtest.c +1657 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test.h +85 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_array.c +115 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_buffer.c +137 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_indent.c +201 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_match.c +2397 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_numba.c +57 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse.c +349 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_error.c +27839 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_roundtrip.c +350 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_record.c +231 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typecheck.c +375 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typedef.c +65 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/valgrind.supp +30 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/bench.c +79 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/indent.c +94 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/print_ast.c +96 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/util.c +474 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/values.c +228 -0
- data/ext/ruby_ndtypes/ndtypes/python/bench.py +49 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndt_randtype.py +409 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndt_support.py +14 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/__init__.py +70 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/_ndtypes.c +1332 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/docstrings.h +319 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/pyndtypes.h +154 -0
- data/ext/ruby_ndtypes/ndtypes/python/test_ndtypes.py +1977 -0
- data/ext/ruby_ndtypes/ndtypes/setup.py +288 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/INSTALL.txt +41 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest32.bat +15 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest64.bat +13 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild32.bat +38 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild64.bat +38 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcclean.bat +13 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcdistclean.bat +14 -0
- data/ext/ruby_ndtypes/ruby_ndtypes.c +1003 -0
- data/ext/ruby_ndtypes/ruby_ndtypes.h +37 -0
- data/ext/ruby_ndtypes/ruby_ndtypes_internal.h +28 -0
- data/lib/ndtypes.rb +45 -0
- data/lib/ndtypes/errors.rb +2 -0
- data/lib/ndtypes/version.rb +6 -0
- data/ndtypes.gemspec +47 -0
- data/spec/gc_table_spec.rb +10 -0
- data/spec/ndtypes_spec.rb +289 -0
- data/spec/spec_helper.rb +241 -0
- metadata +242 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
/* A Bison parser, made by GNU Bison 3.0.4. */
|
2
|
+
|
3
|
+
/* Bison interface for Yacc-like parsers in C
|
4
|
+
|
5
|
+
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
|
6
|
+
|
7
|
+
This program is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the GNU General Public License as published by
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
This program is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
GNU General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU General Public License
|
18
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
19
|
+
|
20
|
+
/* As a special exception, you may create a larger work that contains
|
21
|
+
part or all of the Bison parser skeleton and distribute that work
|
22
|
+
under terms of your choice, so long as that work isn't itself a
|
23
|
+
parser generator using the skeleton or a modified version thereof
|
24
|
+
as a parser skeleton. Alternatively, if you modify or redistribute
|
25
|
+
the parser skeleton itself, you may (at your option) remove this
|
26
|
+
special exception, which will cause the skeleton and the resulting
|
27
|
+
Bison output files to be licensed under the GNU General Public
|
28
|
+
License without this special exception.
|
29
|
+
|
30
|
+
This special exception was added by the Free Software Foundation in
|
31
|
+
version 2.2 of Bison. */
|
32
|
+
|
33
|
+
#ifndef YY_NDT_BP_BPGRAMMAR_H_INCLUDED
|
34
|
+
# define YY_NDT_BP_BPGRAMMAR_H_INCLUDED
|
35
|
+
/* Debug traces. */
|
36
|
+
#ifndef YYDEBUG
|
37
|
+
# define YYDEBUG 0
|
38
|
+
#endif
|
39
|
+
#if YYDEBUG
|
40
|
+
extern int ndt_bpdebug;
|
41
|
+
#endif
|
42
|
+
/* "%code requires" blocks. */
|
43
|
+
#line 292 "bpgrammar.y" /* yacc.c:1909 */
|
44
|
+
|
45
|
+
#include <ctype.h>
|
46
|
+
#include <assert.h>
|
47
|
+
#include "ndtypes.h"
|
48
|
+
#include "parsefuncs.h"
|
49
|
+
#include "seq.h"
|
50
|
+
#include "overflow.h"
|
51
|
+
#define YY_TYPEDEF_YY_SCANNER_T
|
52
|
+
typedef void * yyscan_t;
|
53
|
+
|
54
|
+
#line 55 "bpgrammar.h" /* yacc.c:1909 */
|
55
|
+
|
56
|
+
/* Token type. */
|
57
|
+
#ifndef YYTOKENTYPE
|
58
|
+
# define YYTOKENTYPE
|
59
|
+
enum yytokentype
|
60
|
+
{
|
61
|
+
ENDMARKER = 0,
|
62
|
+
BYTES = 258,
|
63
|
+
RECORD = 259,
|
64
|
+
PAD = 260,
|
65
|
+
AT = 261,
|
66
|
+
EQUAL = 262,
|
67
|
+
LESS = 263,
|
68
|
+
GREATER = 264,
|
69
|
+
BANG = 265,
|
70
|
+
COMMA = 266,
|
71
|
+
COLON = 267,
|
72
|
+
LPAREN = 268,
|
73
|
+
RPAREN = 269,
|
74
|
+
LBRACE = 270,
|
75
|
+
RBRACE = 271,
|
76
|
+
RARROW = 272,
|
77
|
+
ERRTOKEN = 273,
|
78
|
+
DTYPE = 274,
|
79
|
+
INTEGER = 275,
|
80
|
+
NAME = 276
|
81
|
+
};
|
82
|
+
#endif
|
83
|
+
|
84
|
+
/* Value type. */
|
85
|
+
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
86
|
+
|
87
|
+
union YYSTYPE
|
88
|
+
{
|
89
|
+
#line 325 "bpgrammar.y" /* yacc.c:1909 */
|
90
|
+
|
91
|
+
ndt_t *ndt;
|
92
|
+
ndt_field_t *field;
|
93
|
+
ndt_field_seq_t *field_seq;
|
94
|
+
ndt_string_seq_t *string_seq;
|
95
|
+
ndt_type_seq_t *type_seq;
|
96
|
+
char *string;
|
97
|
+
unsigned char uchar;
|
98
|
+
uint16_t uint16;
|
99
|
+
|
100
|
+
#line 101 "bpgrammar.h" /* yacc.c:1909 */
|
101
|
+
};
|
102
|
+
|
103
|
+
typedef union YYSTYPE YYSTYPE;
|
104
|
+
# define YYSTYPE_IS_TRIVIAL 1
|
105
|
+
# define YYSTYPE_IS_DECLARED 1
|
106
|
+
#endif
|
107
|
+
|
108
|
+
/* Location type. */
|
109
|
+
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
|
110
|
+
typedef struct YYLTYPE YYLTYPE;
|
111
|
+
struct YYLTYPE
|
112
|
+
{
|
113
|
+
int first_line;
|
114
|
+
int first_column;
|
115
|
+
int last_line;
|
116
|
+
int last_column;
|
117
|
+
};
|
118
|
+
# define YYLTYPE_IS_DECLARED 1
|
119
|
+
# define YYLTYPE_IS_TRIVIAL 1
|
120
|
+
#endif
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
int ndt_bpparse (yyscan_t scanner, ndt_t **ast, ndt_context_t *ctx);
|
125
|
+
/* "%code provides" blocks. */
|
126
|
+
#line 303 "bpgrammar.y" /* yacc.c:1909 */
|
127
|
+
|
128
|
+
#define YY_DECL extern int ndt_bplexfunc(YYSTYPE *yylval_param, YYLTYPE *yylloc_param, yyscan_t yyscanner, ndt_context_t *ctx)
|
129
|
+
extern int ndt_bplexfunc(YYSTYPE *, YYLTYPE *, yyscan_t, ndt_context_t *);
|
130
|
+
void yyerror(YYLTYPE *loc, yyscan_t scanner, ndt_t **ast, ndt_context_t *ctx, const char *msg);
|
131
|
+
|
132
|
+
#line 133 "bpgrammar.h" /* yacc.c:1909 */
|
133
|
+
|
134
|
+
#endif /* !YY_NDT_BP_BPGRAMMAR_H_INCLUDED */
|
@@ -0,0 +1,428 @@
|
|
1
|
+
%{
|
2
|
+
/*
|
3
|
+
* BSD 3-Clause License
|
4
|
+
*
|
5
|
+
* Copyright (c) 2017-2018, plures
|
6
|
+
* All rights reserved.
|
7
|
+
*
|
8
|
+
* Redistribution and use in source and binary forms, with or without
|
9
|
+
* modification, are permitted provided that the following conditions are met:
|
10
|
+
*
|
11
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
12
|
+
* this list of conditions and the following disclaimer.
|
13
|
+
*
|
14
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
15
|
+
* this list of conditions and the following disclaimer in the documentation
|
16
|
+
* and/or other materials provided with the distribution.
|
17
|
+
*
|
18
|
+
* 3. Neither the name of the copyright holder nor the names of its
|
19
|
+
* contributors may be used to endorse or promote products derived from
|
20
|
+
* this software without specific prior written permission.
|
21
|
+
*
|
22
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
25
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
26
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
27
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
28
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
29
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
30
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
31
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
*/
|
33
|
+
|
34
|
+
|
35
|
+
#include "bpgrammar.h"
|
36
|
+
#include "bplexer.h"
|
37
|
+
|
38
|
+
|
39
|
+
void
|
40
|
+
yyerror(YYLTYPE *loc, yyscan_t scanner, ndt_t **ast, ndt_context_t *ctx,
|
41
|
+
const char *msg)
|
42
|
+
{
|
43
|
+
(void)scanner;
|
44
|
+
(void)ast;
|
45
|
+
|
46
|
+
ndt_err_format(ctx, NDT_ParseError, "%d:%d: %s\n", loc->first_line,
|
47
|
+
loc->first_column, msg);
|
48
|
+
}
|
49
|
+
|
50
|
+
int
|
51
|
+
yylex(YYSTYPE *val, YYLTYPE *loc, yyscan_t scanner, ndt_context_t *ctx)
|
52
|
+
{
|
53
|
+
return ndt_bplexfunc(val, loc, scanner, ctx);
|
54
|
+
}
|
55
|
+
|
56
|
+
static uint16_t
|
57
|
+
add_uint16(uint16_t a, uint16_t b, ndt_context_t *ctx)
|
58
|
+
{
|
59
|
+
bool overflow = 0;
|
60
|
+
uint16_t c = ADDu16(a, b, &overflow);
|
61
|
+
|
62
|
+
if (overflow) {
|
63
|
+
ndt_err_format(ctx, NDT_ValueError, "overflow while adding uint16");
|
64
|
+
return UINT16_MAX;
|
65
|
+
}
|
66
|
+
|
67
|
+
return c;
|
68
|
+
}
|
69
|
+
|
70
|
+
static ndt_t *
|
71
|
+
primitive_native(char dtype, ndt_context_t *ctx)
|
72
|
+
{
|
73
|
+
switch (dtype) {
|
74
|
+
case '?': return ndt_primitive(Bool, 0, ctx);
|
75
|
+
|
76
|
+
case 'c': return ndt_char(Ascii, ctx);
|
77
|
+
case 'b': return ndt_primitive(Int8, 0, ctx);
|
78
|
+
case 'B': return ndt_primitive(Uint8, 0, ctx);
|
79
|
+
|
80
|
+
case 'h': return ndt_signed(sizeof(short), 0, ctx);
|
81
|
+
case 'i': return ndt_signed(sizeof(int), 0, ctx);
|
82
|
+
case 'l': return ndt_signed(sizeof(long), 0, ctx);
|
83
|
+
case 'q': return ndt_signed(sizeof(long long), 0, ctx);
|
84
|
+
case 'n': return ndt_signed(sizeof(size_t), 0, ctx);
|
85
|
+
|
86
|
+
case 'H': return ndt_unsigned(sizeof(unsigned short), 0, ctx);
|
87
|
+
case 'I': return ndt_unsigned(sizeof(unsigned int), 0, ctx);
|
88
|
+
case 'L': return ndt_unsigned(sizeof(unsigned long), 0, ctx);
|
89
|
+
case 'Q': return ndt_unsigned(sizeof(unsigned long long), 0, ctx);
|
90
|
+
case 'N': return ndt_unsigned(sizeof(size_t), 0, ctx);
|
91
|
+
|
92
|
+
case 'e': return ndt_primitive(Float16, 0, ctx);
|
93
|
+
case 'f': return ndt_primitive(Float32, 0, ctx);
|
94
|
+
case 'd': return ndt_primitive(Float64, 0, ctx);
|
95
|
+
|
96
|
+
case 'E': return ndt_primitive(Complex32, 0, ctx);
|
97
|
+
case 'F': return ndt_primitive(Complex64, 0, ctx);
|
98
|
+
case 'D': return ndt_primitive(Complex128, 0, ctx);
|
99
|
+
|
100
|
+
default:
|
101
|
+
ndt_err_format(ctx, NDT_ValueError,
|
102
|
+
"invalid or unsupported dtype '%c'", dtype);
|
103
|
+
return NULL;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
static ndt_t *
|
108
|
+
primitive_fixed(char dtype, uint32_t flags, ndt_context_t *ctx)
|
109
|
+
{
|
110
|
+
switch (dtype) {
|
111
|
+
case '?': return ndt_primitive(Bool, flags, ctx);
|
112
|
+
|
113
|
+
case 'c': return ndt_char(Ascii, ctx);
|
114
|
+
case 'b': return ndt_primitive(Int8, flags, ctx);
|
115
|
+
case 'B': return ndt_primitive(Uint8, flags, ctx);
|
116
|
+
|
117
|
+
case 'h': return ndt_primitive(Int16, flags, ctx);
|
118
|
+
case 'i': return ndt_primitive(Int32, flags, ctx);
|
119
|
+
case 'l': return ndt_primitive(Int32, flags, ctx);
|
120
|
+
case 'q': return ndt_primitive(Int64, flags, ctx);
|
121
|
+
|
122
|
+
case 'H': return ndt_primitive(Uint16, flags, ctx);
|
123
|
+
case 'I': return ndt_primitive(Uint32, flags, ctx);
|
124
|
+
case 'L': return ndt_primitive(Uint32, flags, ctx);
|
125
|
+
case 'Q': return ndt_primitive(Uint64, flags, ctx);
|
126
|
+
|
127
|
+
case 'e': return ndt_primitive(Float16, flags, ctx);
|
128
|
+
case 'f': return ndt_primitive(Float32, flags, ctx);
|
129
|
+
case 'd': return ndt_primitive(Float64, flags, ctx);
|
130
|
+
|
131
|
+
case 'E': return ndt_primitive(Complex32, flags, ctx);
|
132
|
+
case 'F': return ndt_primitive(Complex64, flags, ctx);
|
133
|
+
case 'D': return ndt_primitive(Complex128, flags, ctx);
|
134
|
+
|
135
|
+
default:
|
136
|
+
ndt_err_format(ctx, NDT_ValueError,
|
137
|
+
"invalid or unsupported dtype '%c'", dtype);
|
138
|
+
return NULL;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
static ndt_t *
|
143
|
+
make_dtype(char modifier, char dtype, ndt_context_t *ctx)
|
144
|
+
{
|
145
|
+
switch (modifier) {
|
146
|
+
case '@':
|
147
|
+
return primitive_native(dtype, ctx);
|
148
|
+
case '=':
|
149
|
+
return primitive_fixed(dtype, 0, ctx);
|
150
|
+
case '<':
|
151
|
+
return primitive_fixed(dtype, NDT_LITTLE_ENDIAN, ctx);
|
152
|
+
case '>':
|
153
|
+
return primitive_fixed(dtype, NDT_BIG_ENDIAN, ctx);
|
154
|
+
case '!':
|
155
|
+
return primitive_fixed(dtype, NDT_BIG_ENDIAN, ctx);
|
156
|
+
default:
|
157
|
+
ndt_err_format(ctx, NDT_RuntimeError, "invalid modifier '%c'",
|
158
|
+
modifier);
|
159
|
+
return NULL;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
static ndt_t *
|
164
|
+
make_fixed_bytes(char *v, ndt_context_t *ctx)
|
165
|
+
{
|
166
|
+
uint16_opt_t align = {None, 0};
|
167
|
+
int64_t datasize = 1;
|
168
|
+
|
169
|
+
if (v != NULL) {
|
170
|
+
datasize = ndt_strtoll(v, 0, INT64_MAX, ctx);
|
171
|
+
ndt_free(v);
|
172
|
+
if (ndt_err_occurred(ctx)) {
|
173
|
+
return NULL;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
if (datasize < 1) {
|
178
|
+
ndt_err_format(ctx, NDT_ValueError,
|
179
|
+
"fixed bytes datasize must be greater than 0");
|
180
|
+
return NULL;
|
181
|
+
}
|
182
|
+
|
183
|
+
return ndt_fixed_bytes(datasize, align, ctx);
|
184
|
+
}
|
185
|
+
|
186
|
+
static ndt_t *
|
187
|
+
make_dimensions(ndt_string_seq_t *seq, ndt_t *type, ndt_context_t *ctx)
|
188
|
+
{
|
189
|
+
ndt_t *t;
|
190
|
+
int64_t shape;
|
191
|
+
int64_t i;
|
192
|
+
|
193
|
+
if (seq->len < 1 || seq->len > NDT_MAX_DIM) {
|
194
|
+
ndt_err_format(ctx, NDT_ValueError,
|
195
|
+
"number of dimensions must be between 1 and %d", NDT_MAX_DIM);
|
196
|
+
ndt_string_seq_del(seq);
|
197
|
+
ndt_del(type);
|
198
|
+
return NULL;
|
199
|
+
}
|
200
|
+
|
201
|
+
for (i=seq->len-1, t=type; i>=0; i--, type=t) {
|
202
|
+
shape = ndt_strtoll(seq->ptr[i], 0, INT_MAX, ctx);
|
203
|
+
if (ndt_err_occurred(ctx)) {
|
204
|
+
ndt_string_seq_del(seq);
|
205
|
+
return NULL;
|
206
|
+
}
|
207
|
+
|
208
|
+
t = ndt_fixed_dim(type, shape, INT64_MAX, ctx);
|
209
|
+
if (t == NULL) {
|
210
|
+
ndt_string_seq_del(seq);
|
211
|
+
return NULL;
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
ndt_string_seq_del(seq);
|
216
|
+
|
217
|
+
return t;
|
218
|
+
}
|
219
|
+
|
220
|
+
static ndt_field_t *
|
221
|
+
make_field(char *name, ndt_t *type, uint16_t padding, ndt_context_t *ctx)
|
222
|
+
{
|
223
|
+
uint16_opt_t align = {None, 0};
|
224
|
+
uint16_opt_t pack = {None, 0};
|
225
|
+
uint16_opt_t pad = {Some, 0};
|
226
|
+
|
227
|
+
pad.Some = padding;
|
228
|
+
return ndt_field(name, type, align, pack, pad, ctx);
|
229
|
+
}
|
230
|
+
|
231
|
+
static ndt_t *
|
232
|
+
make_record(ndt_field_seq_t *fields, ndt_context_t *ctx)
|
233
|
+
{
|
234
|
+
uint16_opt_t align = {None, 0};
|
235
|
+
uint16_opt_t pack = {None, 0};
|
236
|
+
ndt_t *t;
|
237
|
+
int64_t i;
|
238
|
+
|
239
|
+
fields = ndt_field_seq_finalize(fields);
|
240
|
+
if (fields == NULL) {
|
241
|
+
return ndt_record(Nonvariadic, NULL, 0, align, pack, ctx);
|
242
|
+
}
|
243
|
+
|
244
|
+
assert(fields->len >= 1);
|
245
|
+
|
246
|
+
fields->ptr[0].Concrete.align = 1;
|
247
|
+
fields->ptr[0].Concrete.explicit_align = true;
|
248
|
+
|
249
|
+
for (i = 1; i < fields->len; i++) {
|
250
|
+
uint16_t a = 1;
|
251
|
+
if (fields->ptr[i-1].Concrete.pad != 0) {
|
252
|
+
a = fields->ptr[i-1].type->align + fields->ptr[i-1].Concrete.pad;
|
253
|
+
}
|
254
|
+
fields->ptr[i].Concrete.align = a;
|
255
|
+
fields->ptr[i].Concrete.explicit_align = true;
|
256
|
+
}
|
257
|
+
|
258
|
+
t = ndt_record(Nonvariadic, fields->ptr, fields->len, align, pack, ctx);
|
259
|
+
ndt_free(fields);
|
260
|
+
|
261
|
+
return t;
|
262
|
+
}
|
263
|
+
|
264
|
+
static ndt_type_seq_t *
|
265
|
+
broadcast_seq_new(ndt_t *type, ndt_context_t *ctx)
|
266
|
+
{
|
267
|
+
ndt_t *t;
|
268
|
+
|
269
|
+
t = ndt_ellipsis_dim(NULL, type, ctx);
|
270
|
+
if (t == NULL) {
|
271
|
+
return NULL;
|
272
|
+
}
|
273
|
+
|
274
|
+
return ndt_type_seq_new(t, ctx);
|
275
|
+
}
|
276
|
+
|
277
|
+
static ndt_type_seq_t *
|
278
|
+
broadcast_seq_append(ndt_type_seq_t *seq, ndt_t *type, ndt_context_t *ctx)
|
279
|
+
{
|
280
|
+
ndt_t *t;
|
281
|
+
|
282
|
+
t = ndt_ellipsis_dim(NULL, type, ctx);
|
283
|
+
if (t == NULL) {
|
284
|
+
ndt_type_seq_del(seq);
|
285
|
+
return NULL;
|
286
|
+
}
|
287
|
+
|
288
|
+
return ndt_type_seq_append(seq, t, ctx);
|
289
|
+
}
|
290
|
+
%}
|
291
|
+
|
292
|
+
%code requires {
|
293
|
+
#include <ctype.h>
|
294
|
+
#include <assert.h>
|
295
|
+
#include "ndtypes.h"
|
296
|
+
#include "parsefuncs.h"
|
297
|
+
#include "seq.h"
|
298
|
+
#include "overflow.h"
|
299
|
+
#define YY_TYPEDEF_YY_SCANNER_T
|
300
|
+
typedef void * yyscan_t;
|
301
|
+
}
|
302
|
+
|
303
|
+
%code provides {
|
304
|
+
#define YY_DECL extern int ndt_bplexfunc(YYSTYPE *yylval_param, YYLTYPE *yylloc_param, yyscan_t yyscanner, ndt_context_t *ctx)
|
305
|
+
extern int ndt_bplexfunc(YYSTYPE *, YYLTYPE *, yyscan_t, ndt_context_t *);
|
306
|
+
void yyerror(YYLTYPE *loc, yyscan_t scanner, ndt_t **ast, ndt_context_t *ctx, const char *msg);
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
%pure-parser
|
311
|
+
%error-verbose
|
312
|
+
|
313
|
+
|
314
|
+
%locations
|
315
|
+
%initial-action {
|
316
|
+
@$.first_line = 1;
|
317
|
+
@$.first_column = 1;
|
318
|
+
@$.last_line = 1;
|
319
|
+
@$.last_column = 1;
|
320
|
+
}
|
321
|
+
|
322
|
+
%lex-param {yyscan_t scanner} {ndt_context_t *ctx}
|
323
|
+
%parse-param {yyscan_t scanner} {ndt_t **ast} {ndt_context_t *ctx}
|
324
|
+
|
325
|
+
%union {
|
326
|
+
ndt_t *ndt;
|
327
|
+
ndt_field_t *field;
|
328
|
+
ndt_field_seq_t *field_seq;
|
329
|
+
ndt_string_seq_t *string_seq;
|
330
|
+
ndt_type_seq_t *type_seq;
|
331
|
+
char *string;
|
332
|
+
unsigned char uchar;
|
333
|
+
uint16_t uint16;
|
334
|
+
}
|
335
|
+
|
336
|
+
%start input
|
337
|
+
%type <ndt> input
|
338
|
+
%type <ndt> datatype
|
339
|
+
|
340
|
+
%type <ndt> record
|
341
|
+
%type <field> field
|
342
|
+
%type <field_seq> field_seq
|
343
|
+
|
344
|
+
%type <ndt> dtype
|
345
|
+
%type <type_seq> dtype_seq
|
346
|
+
|
347
|
+
%type <string_seq> dimensions
|
348
|
+
%type <string> repeat
|
349
|
+
|
350
|
+
%type <ndt> function
|
351
|
+
|
352
|
+
%type <uchar> modifier
|
353
|
+
%type <uint16> padding
|
354
|
+
|
355
|
+
%token
|
356
|
+
BYTES RECORD PAD
|
357
|
+
|
358
|
+
AT EQUAL LESS GREATER BANG COMMA COLON LPAREN RPAREN LBRACE RBRACE RARROW
|
359
|
+
ERRTOKEN
|
360
|
+
|
361
|
+
%token <uchar>
|
362
|
+
DTYPE
|
363
|
+
|
364
|
+
%token <string>
|
365
|
+
INTEGER NAME
|
366
|
+
|
367
|
+
%token ENDMARKER 0 "end of file"
|
368
|
+
|
369
|
+
%destructor { ndt_del($$); } <ndt>
|
370
|
+
%destructor { ndt_field_del($$); } <field>
|
371
|
+
%destructor { ndt_field_seq_del($$); } <field_seq>
|
372
|
+
%destructor { ndt_string_seq_del($$); } <string_seq>
|
373
|
+
%destructor { ndt_type_seq_del($$); } <type_seq>
|
374
|
+
%destructor { ndt_free($$); } <string>
|
375
|
+
|
376
|
+
%%
|
377
|
+
|
378
|
+
input:
|
379
|
+
datatype ENDMARKER { $$ = $1; *ast = $$; YYACCEPT; }
|
380
|
+
|
381
|
+
datatype:
|
382
|
+
LPAREN dimensions RPAREN dtype { $$ = make_dimensions($2, $4, ctx); if ($$ == NULL) YYABORT; }
|
383
|
+
| dtype { $$ = $1; }
|
384
|
+
| function { $$ = $1; }
|
385
|
+
|
386
|
+
dimensions:
|
387
|
+
INTEGER { $$ = ndt_string_seq_new($1, ctx); if ($$ == NULL) YYABORT; }
|
388
|
+
| dimensions COMMA INTEGER { $$ = ndt_string_seq_append($1, $3, ctx); if ($$ == NULL) YYABORT; }
|
389
|
+
|
390
|
+
dtype:
|
391
|
+
modifier DTYPE { $$ = make_dtype($1, $2, ctx); if ($$ == NULL) YYABORT; }
|
392
|
+
| repeat BYTES { $$ = make_fixed_bytes($1, ctx); if ($$ == NULL) YYABORT; }
|
393
|
+
| record { $$ = $1; }
|
394
|
+
|
395
|
+
record:
|
396
|
+
RECORD LBRACE field_seq RBRACE { $$ = make_record($3, ctx); if ($$ == NULL) YYABORT; }
|
397
|
+
|
398
|
+
field_seq:
|
399
|
+
field { $$ = ndt_field_seq_new($1, ctx); if ($$ == NULL) YYABORT; }
|
400
|
+
| field_seq field { $$ = ndt_field_seq_append($1, $2, ctx); if ($$ == NULL) YYABORT; }
|
401
|
+
|
402
|
+
field:
|
403
|
+
datatype COLON NAME COLON padding { $$ = make_field($3, $1, $5, ctx); if ($$ == NULL) YYABORT; }
|
404
|
+
|
405
|
+
function:
|
406
|
+
dtype_seq RARROW dtype_seq { $$ = mk_function($1, $3, ctx); if ($$ == NULL) YYABORT; }
|
407
|
+
|
408
|
+
dtype_seq:
|
409
|
+
dtype { $$ = broadcast_seq_new($1, ctx); if ($$ == NULL) YYABORT; }
|
410
|
+
| dtype_seq dtype { $$ = broadcast_seq_append($1, $2, ctx); if ($$ == NULL) YYABORT; }
|
411
|
+
|
412
|
+
modifier:
|
413
|
+
%empty { $$ = '@'; }
|
414
|
+
| AT { $$ = '@'; }
|
415
|
+
| EQUAL { $$ = '='; }
|
416
|
+
| LESS { $$ = '<'; }
|
417
|
+
| GREATER { $$ = '>'; }
|
418
|
+
| BANG { $$ = '!'; }
|
419
|
+
|
420
|
+
repeat:
|
421
|
+
%empty { $$ = NULL; }
|
422
|
+
| INTEGER { $$ = $1; if ($$ == NULL) YYABORT; }
|
423
|
+
|
424
|
+
padding:
|
425
|
+
%empty { $$ = 0; }
|
426
|
+
| padding PAD { $$ = add_uint16($1, 1, ctx); if (ndt_err_occurred(ctx)) YYABORT; }
|
427
|
+
|
428
|
+
|