Commit 8bbfda4c authored by Vysheng's avatar Vysheng

files for new version

parent 1dad2e89
This diff is collapsed.
/*
This file is part of VK/KittenPHP-DB-Engine Library.
VK/KittenPHP-DB-Engine Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
VK/KittenPHP-DB-Engine Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with VK/KittenPHP-DB-Engine Library. If not, see <http://www.gnu.org/licenses/>.
Copyright 2009-2012 Vkontakte Ltd
2009-2012 Nikolai Durov
2009-2012 Andrei Lopatin
2012 Anton Maydell
*/
#ifndef __CRC32_H__
#define __CRC32_H__
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned int crc32_table[256];
unsigned crc32_partial (const void *data, int len, unsigned crc);
//unsigned crc32_partial_fast (const void *data, int len, unsigned crc);
//unsigned crc32_partial_fastest (const void *data, int len, unsigned crc);
unsigned compute_crc32 (const void *data, int len);
unsigned compute_crc32_combine (unsigned crc1, unsigned crc2, int len2);
extern unsigned long long crc64_table[256];
unsigned long long crc64_partial (const void *data, int len, unsigned long long crc);
unsigned long long crc64 (const void *data, int len);
//unsigned gf32_matrix_times (unsigned *matrix, unsigned vector);
/* crc32_check_and_repair returns
0 : Cyclic redundancy check is ok
1 : Cyclic redundancy check fails, but we fix one bit in input
2 : Cyclic redundancy check fails, but we fix one bit in input_crc32
-1 : Cyclic redundancy check fails, no repair possible.
In this case *input_crc32 will be equal crc32 (input, l)
Case force_exit == 1 (case 1, 2: kprintf call, case -1: assert fail).
*/
int crc32_check_and_repair (void *input, int l, unsigned *input_crc32, int force_exit);
#ifdef __cplusplus
}
#endif
#endif
......@@ -92,7 +92,7 @@ int get_random_bytes (unsigned char *buf, int n) {
void my_clock_gettime (int clock_id UU, struct timespec *T) {
#ifdef __MACH__
// We are ignoring MONOTONIC and hope time doesn't go back to often
// We are ignoring MONOTONIC and hope time doesn't go back too often
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
......
This diff is collapsed.
This diff is collapsed.
/*
This file is part of VK/KittenPHP-DB-Engine.
VK/KittenPHP-DB-Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
VK/KittenPHP-DB-Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VK/KittenPHP-DB-Engine. If not, see <http://www.gnu.org/licenses/>.
This program is released under the GPL with the additional exemption
that compiling, linking, and/or using OpenSSL is allowed.
You are free to remove this exemption from derived works.
Copyright 2012-2013 Vkontakte Ltd
2012-2013 Vitaliy Valtman
*/
#ifndef __TL_PARSER_NEW_H__
#define __TL_PARSER_NEW_H__
enum lex_type {
lex_error,
lex_char,
lex_triple_minus,
lex_uc_ident,
lex_lc_ident,
lex_eof,
lex_final,
lex_new,
lex_none,
lex_num,
lex_empty
};
struct curlex {
char *ptr;
int len;
enum lex_type type;
int flags;
};
struct parse {
char *text;
int pos;
int len;
int line;
int line_pos;
struct curlex lex;
};
enum tree_type {
type_tl_program,
type_fun_declarations,
type_constr_declarations,
type_declaration,
type_combinator_decl,
type_equals,
type_partial_app_decl,
type_final_decl,
type_full_combinator_id,
type_opt_args,
type_args,
type_args1,
type_args2,
type_args3,
type_args4,
type_boxed_type_ident,
type_subexpr,
type_partial_comb_app_decl,
type_partial_type_app_decl,
type_final_new,
type_final_final,
type_final_empty,
// type_type,
type_var_ident,
type_var_ident_opt,
type_multiplicity,
type_type_term,
type_term,
type_percent,
type_result_type,
type_expr,
type_nat_term,
type_combinator_id,
type_nat_const,
type_type_ident,
type_builtin_combinator_decl,
type_exclam,
type_optional_arg_def
};
struct tree {
char *text;
int len;
enum tree_type type;
int lex_line;
int lex_line_pos;
int flags;
int size;
int nc;
struct tree **c;
};
#define TL_ACT(x) (x == act_var ? "act_var" : x == act_field ? "act_field" : x == act_plus ? "act_plus" : x == act_type ? "act_type" : x == act_nat_const ? "act_nat_const" : x == act_array ? "act_array" : x == act_question_mark ? "act_question_mark" : \
x == act_union ? "act_union" : x == act_arg ? "act_arg" : x == act_opt_field ? "act_opt_field" : "act_unknown")
#define TL_TYPE(x) (x == type_num ? "type_num" : x == type_type ? "type_type" : x == type_list_item ? "type_list_item" : x == type_list ? "type_list" : x == type_num_value ? "type_num_value" : "type_unknown")
enum combinator_tree_action {
act_var,
act_field,
act_plus,
act_type,
act_nat_const,
act_array,
act_question_mark,
act_union,
act_arg,
act_opt_field
};
enum combinator_tree_type {
type_num,
type_num_value,
type_type,
type_list_item,
type_list
};
struct tl_combinator_tree {
enum combinator_tree_action act;
struct tl_combinator_tree *left, *right;
char *name;
void *data;
long long flags;
enum combinator_tree_type type;
int type_len;
long long type_flags;
};
struct tl_program {
int types_num;
int functions_num;
int constructors_num;
struct tl_type **types;
struct tl_function **functions;
// struct tl_constuctor **constructors;
};
struct tl_type {
char *id;
char *print_id;
char *real_id;
unsigned name;
int flags;
int params_num;
long long params_types;
int constructors_num;
struct tl_constructor **constructors;
};
struct tl_constructor {
char *id;
char *print_id;
char *real_id;
unsigned name;
struct tl_type *type;
struct tl_combinator_tree *left;
struct tl_combinator_tree *right;
};
struct tl_var {
char *id;
struct tl_combinator_tree *ptr;
int type;
int flags;
};
struct parse *tl_init_parse_file (const char *fname);
struct tree *tl_parse_lex (struct parse *P);
void tl_print_parse_error (void);
struct tl_program *tl_parse (struct tree *T);
void write_types (int f);
#define FLAG_BARE 1
#define FLAG_OPT_VAR (1 << 17)
#define FLAG_EXCL (1 << 18)
#define FLAG_OPT_FIELD (1 << 20)
#define FLAG_IS_VAR (1 << 21)
#define FLAG_DEFAULT_CONSTRUCTOR (1 << 25)
#define FLAG_EMPTY (1 << 10)
#endif
/*
This file is part of VK/KittenPHP-DB-Engine.
VK/KittenPHP-DB-Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
VK/KittenPHP-DB-Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VK/KittenPHP-DB-Engine. If not, see <http://www.gnu.org/licenses/>.
This program is released under the GPL with the additional exemption
that compiling, linking, and/or using OpenSSL is allowed.
You are free to remove this exemption from derived works.
Copyright 2012-2013 Vkontakte Ltd
2012-2013 Vitaliy Valtman
*/
#ifndef __TL_TL_H__
#define __TL_TL_H__
#define TLS_SCHEMA 0xf19d9e38
#define TLS_TYPE 0x12eb4386
#define TLS_COMBINATOR 0x5c0a1ed5
#define TLS_COMBINATOR_LEFT_BUILTIN 0xcd211f63
#define TLS_COMBINATOR_LEFT 0x4c12c6d9
#define TLS_COMBINATOR_RIGHT 0xd325b367
#define TLS_ARG 0x46afe232
#define TLS_TREE_NAT_CONST 0xc09f07d7
#define TLS_TREE_NAT_VAR 0x90ea6f58
#define TLS_TREE_TYPE_VAR 0x1caa237a
#define TLS_TREE_ARRAY 0x80479360
#define TLS_TREE_TYPE 0x10f32190
#define TLS_SCHEMA_V2 0x3a2f9be2
#define TLS_COMBINATOR_RIGHT_V2 0x2c064372
#define TLS_ARG_V2 0x29dfe61b
#define TLS_EXPR_TYPE 0xecc9da78
#define TLS_EXPR_NAT 0xdcb49bd8
#define TLS_NAT_CONST 0xdcb49bd8
#define TLS_NAT_VAR 0x4e8a14f0
#define TLS_TYPE_VAR 0x0142ceae
#define TLS_ARRAY 0xd9fb20de
#define TLS_TYPE_EXPR 0xc1863d08
#endif
/*
This file is part of VK/KittenPHP-DB-Engine.
VK/KittenPHP-DB-Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
VK/KittenPHP-DB-Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VK/KittenPHP-DB-Engine. If not, see <http://www.gnu.org/licenses/>.
This program is released under the GPL with the additional exemption
that compiling, linking, and/or using OpenSSL is allowed.
You are free to remove this exemption from derived works.
Copyright 2012-2013 Vkontakte Ltd
2012-2013 Vitaliy Valtman
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "tl-parser.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include "config.h"
#include <execinfo.h>
int verbosity;
int output_expressions;
int schema_version = 2;
void usage (void) {
printf ("usage: tlc [-v] [-h] <TL-schema-file>\n"
"\tTL compiler\n"
"\t-v\toutput statistical and debug information into stderr\n"
"\t-E\twhenever is possible output to stdout expressions\n"
"\t-e <file>\texport serialized schema to file\n"
"\t-w\t custom version of serialized schema (0 - very old, 1 - old, 2 - current (default))\n"
);
exit (2);
}
int vkext_write (const char *filename) {
int f = open (filename, O_CREAT | O_WRONLY | O_TRUNC, 0640);
assert (f >= 0);
write_types (f);
close (f);
return 0;
}
void logprintf (const char *format, ...) __attribute__ ((format (printf, 1, 2)));
void logprintf (const char *format __attribute__ ((unused)), ...) {
}
void hexdump (int *in_ptr, int *in_end) {
int *ptr = in_ptr;
while (ptr < in_end) { printf (" %08x", *(ptr ++)); }
printf ("\n");
}
#ifdef HAVE_EXECINFO_H
void print_backtrace (void) {
void *buffer[255];
const int calls = backtrace (buffer, sizeof (buffer) / sizeof (void *));
backtrace_symbols_fd (buffer, calls, 1);
}
#else
void print_backtrace (void) {
if (write (1, "No libexec. Backtrace disabled\n", 32) < 0) {
// Sad thing
}
}
#endif
void sig_segv_handler (int signum __attribute__ ((unused))) {
if (write (1, "SIGSEGV received\n", 18) < 0) {
// Sad thing
}
print_backtrace ();
exit (EXIT_FAILURE);
}
void sig_abrt_handler (int signum __attribute__ ((unused))) {
if (write (1, "SIGABRT received\n", 18) < 0) {
// Sad thing
}
print_backtrace ();
exit (EXIT_FAILURE);
}
int main (int argc, char **argv) {
signal (SIGSEGV, sig_segv_handler);
signal (SIGABRT, sig_abrt_handler);
int i;
char *vkext_file = 0;
while ((i = getopt (argc, argv, "Ehve:w:")) != -1) {
switch (i) {
case 'E':
output_expressions++;
break;
case 'h':
usage ();
return 2;
case 'e':
vkext_file = optarg;
break;
case 'w':
schema_version = atoi (optarg);
break;
case 'v':
verbosity++;
break;
}
}
if (argc != optind + 1) {
usage ();
}
struct parse *P = tl_init_parse_file (argv[optind]);
if (!P) {
return 0;
}
struct tree *T;
if (!(T = tl_parse_lex (P))) {
fprintf (stderr, "Error in parse:\n");
tl_print_parse_error ();
return 0;
} else {
if (verbosity) {
fprintf (stderr, "Parse ok\n");
}
if (!tl_parse (T)) {
if (verbosity) {
fprintf (stderr, "Fail\n");
}
return 1;
} else {
if (verbosity) {
fprintf (stderr, "Ok\n");
}
}
}
if (vkext_file) {
vkext_write (vkext_file);
}
return 0;
}
......@@ -151,6 +151,13 @@ void tree_check_ ## X_NAME (struct tree_ ## X_NAME *T) { \
tree_check_ ## X_NAME (T->left); \
tree_check_ ## X_NAME (T->right); \
}\
struct tree_ ## X_NAME *tree_clear_ ## X_NAME (struct tree_ ## X_NAME *T) { \
if (!T) { return 0; }\
tree_clear_ ## X_NAME (T->left); \
tree_clear_ ## X_NAME (T->right); \
delete_tree_node_ ## X_NAME (T); \
return 0; \
} \
#define int_cmp(a,b) ((a) - (b))
#pragma pack(pop)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment