Remove support for old schemas.

This commit is contained in:
Ben Wiederhake 2015-10-16 23:38:38 +02:00
parent abb3e47a98
commit 134e53c0ec
3 changed files with 50 additions and 139 deletions

View File

@ -2733,10 +2733,6 @@ void wdata (const void *x, int len) {
void wstr (const char *s) { void wstr (const char *s) {
if (s) { if (s) {
// printf ("\"%s\" ", s); // printf ("\"%s\" ", s);
if (schema_version < 1) {
wint (strlen (s));
wdata (s, strlen (s));
} else {
int x = strlen (s); int x = strlen (s);
if (x <= 254) { if (x <= 254) {
assert (write (__f, &x, 1) == 1); assert (write (__f, &x, 1) == 1);
@ -2750,7 +2746,6 @@ void wstr (const char *s) {
if (x & 3) { if (x & 3) {
wdata (&t, 4 - (x & 3)); wdata (&t, 4 - (x & 3));
} }
}
} else { } else {
// printf ("<none> "); // printf ("<none> ");
wint (0); wint (0);
@ -2827,25 +2822,7 @@ void write_args (struct tl_combinator_tree *T, struct tree_var_value **v, int *l
write_args (T->right, v, last_var); write_args (T->right, v, last_var);
return; return;
} }
if (schema_version == 1) {
wint (TLS_ARG);
} if (schema_version == 2) {
wint (TLS_ARG_V2); wint (TLS_ARG_V2);
} else {
wint (-3);
}
if (T->act == act_question_mark) {
if (schema_version >= 1) {
assert (0);
} else {
wint (-100);
}
return;
}
if (schema_version >= 1) {
} else {
wint (-99);
}
assert (T->act == act_field); assert (T->act == act_field);
assert (T->left); assert (T->left);
wstr (T->data && strcmp (T->data, "_") ? T->data : 0); wstr (T->data && strcmp (T->data, "_") ? T->data : 0);
@ -2860,21 +2837,12 @@ void write_args (struct tl_combinator_tree *T, struct tree_var_value **v, int *l
tl_set_var_value_num (v, T, 0, (*last_var) - 1); tl_set_var_value_num (v, T, 0, (*last_var) - 1);
} else { } else {
write_field_flags (f); write_field_flags (f);
if (schema_version <= 1) {
wint (-1);
}
} }
write_tree (T->left, 0, v, last_var); write_tree (T->left, 0, v, last_var);
} }
void write_array (struct tl_combinator_tree *T, struct tree_var_value **v, int *last_var) { void write_array (struct tl_combinator_tree *T, struct tree_var_value **v, int *last_var) {
if (schema_version == 1) {
wint (TLS_TREE_ARRAY);
} else if (schema_version == 2) {
wint (TLS_ARRAY); wint (TLS_ARRAY);
} else {
wint (-8);
}
write_tree (T->left, 0, v, last_var); write_tree (T->left, 0, v, last_var);
write_tree (T->right, 0, v, last_var); write_tree (T->right, 0, v, last_var);
} }
@ -2882,36 +2850,22 @@ void write_array (struct tl_combinator_tree *T, struct tree_var_value **v, int *
void write_type_rec (struct tl_combinator_tree *T, int cc, struct tree_var_value **v, int *last_var) { void write_type_rec (struct tl_combinator_tree *T, int cc, struct tree_var_value **v, int *last_var) {
if (T->act == act_arg) { if (T->act == act_arg) {
write_type_rec (T->left, cc + 1, v, last_var); write_type_rec (T->left, cc + 1, v, last_var);
if (schema_version >= 2) {
if (T->right->type == type_num_value || T->right->type == type_num) { if (T->right->type == type_num_value || T->right->type == type_num) {
wint (TLS_EXPR_NAT); wint (TLS_EXPR_NAT);
} else { } else {
wint (TLS_EXPR_TYPE); wint (TLS_EXPR_TYPE);
} }
}
write_tree (T->right, 0, v, last_var); write_tree (T->right, 0, v, last_var);
} else { } else {
assert (T->act == act_var || T->act == act_type); assert (T->act == act_var || T->act == act_type);
if (T->act == act_var) { if (T->act == act_var) {
assert (!cc); assert (!cc);
if (schema_version == 1) {
wint (TLS_TREE_TYPE_VAR);
} else if (schema_version == 2) {
wint (TLS_TYPE_VAR); wint (TLS_TYPE_VAR);
} else {
wint (-6);
}
wint (tl_get_var_value_num (v, T->data)); wint (tl_get_var_value_num (v, T->data));
write_var_type_flags (T->flags); write_var_type_flags (T->flags);
//wint (T->flags); //wint (T->flags);
} else { } else {
if (schema_version == 1) {
wint (TLS_TREE_TYPE);
} else if (schema_version == 2) {
wint (TLS_TYPE_EXPR); wint (TLS_TYPE_EXPR);
} else {
wint (-7);
}
struct tl_type *t = T->data; struct tl_type *t = T->data;
wint (t->name); wint (t->name);
write_type_flags (T->flags); write_type_flags (T->flags);
@ -2923,10 +2877,6 @@ void write_type_rec (struct tl_combinator_tree *T, int cc, struct tree_var_value
} }
void write_opt_type (struct tl_combinator_tree *T, struct tree_var_value **v, int *last_var) { void write_opt_type (struct tl_combinator_tree *T, struct tree_var_value **v, int *last_var) {
if (schema_version >= 1) {
} else {
wint (-20);
}
wint (tl_get_var_value_num (v, T->left->data)); wint (tl_get_var_value_num (v, T->left->data));
wint (T->left->type_flags); wint (T->left->type_flags);
// write_tree (T->right, 0, v, last_var); // write_tree (T->right, 0, v, last_var);
@ -2952,31 +2902,19 @@ void write_tree (struct tl_combinator_tree *T, int extra, struct tree_var_value
switch (T->type) { switch (T->type) {
case type_list_item: case type_list_item:
case type_list: case type_list:
if (schema_version >= 1) {
if (extra) { if (extra) {
wint (schema_version >= 2 ? TLS_COMBINATOR_RIGHT_V2 : TLS_COMBINATOR_RIGHT); wint (TLS_COMBINATOR_RIGHT_V2);
}
} else {
wint (extra ? -1 : -2);
} }
wint (count_list_size (T)); wint (count_list_size (T));
write_args (T, v, last_var); write_args (T, v, last_var);
break; break;
case type_num_value: case type_num_value:
wint (schema_version >= 1 ? schema_version >= 2 ? (int)TLS_NAT_CONST : (int)TLS_TREE_NAT_CONST : -4); wint ((int)TLS_NAT_CONST);
if (schema_version >= 2) {
wint (T->type_flags); wint (T->type_flags);
} else {
wll (T->type_flags);
}
break; break;
case type_num: case type_num:
wint (schema_version >= 1 ? schema_version >= 2 ? (int)TLS_NAT_VAR : (int)TLS_TREE_NAT_VAR : -5); wint ((int)TLS_NAT_VAR);
if (schema_version >= 2) {
wint (T->type_flags); wint (T->type_flags);
} else {
wll (T->type_flags);
}
wint (tl_get_var_value_num (v, T->data)); wint (tl_get_var_value_num (v, T->data));
break; break;
case type_type: case type_type:
@ -2995,7 +2933,7 @@ void write_tree (struct tl_combinator_tree *T, int extra, struct tree_var_value
} }
void write_type (struct tl_type *t) { void write_type (struct tl_type *t) {
wint (schema_version >= 1 ? TLS_TYPE : 1); wint (TLS_TYPE);
wint (t->name); wint (t->name);
wstr (t->id); wstr (t->id);
wint (t->constructors_num); wint (t->constructors_num);
@ -3016,36 +2954,29 @@ void write_combinator (struct tl_constructor *c) {
int x = 0; int x = 0;
assert (c->right); assert (c->right);
if (c->left) { if (c->left) {
if (schema_version >= 1 && is_builtin_type (c->id)) { if (is_builtin_type (c->id)) {
wint (TLS_COMBINATOR_LEFT_BUILTIN); wint (TLS_COMBINATOR_LEFT_BUILTIN);
} else { } else {
if (schema_version >= 1) {
wint (TLS_COMBINATOR_LEFT); wint (TLS_COMBINATOR_LEFT);
} // FIXME: What is that?
// wint (count_list_size (c->left)); // wint (count_list_size (c->left));
write_tree (c->left, 0, &T, &x); write_tree (c->left, 0, &T, &x);
} }
} else { } else {
if (schema_version >= 1) {
wint (TLS_COMBINATOR_LEFT); wint (TLS_COMBINATOR_LEFT);
wint (0); wint (0);
} else {
wint (-11);
}
}
if (schema_version >= 1) {
wint (schema_version >= 2 ? TLS_COMBINATOR_RIGHT_V2 : TLS_COMBINATOR_RIGHT);
} }
wint (TLS_COMBINATOR_RIGHT_V2);
write_tree (c->right, 1, &T, &x); write_tree (c->right, 1, &T, &x);
} }
void write_constructor (struct tl_constructor *c) { void write_constructor (struct tl_constructor *c) {
wint (schema_version >= 1 ? TLS_COMBINATOR : 2); wint (TLS_COMBINATOR);
write_combinator (c); write_combinator (c);
} }
void write_function (struct tl_constructor *c) { void write_function (struct tl_constructor *c) {
wint (schema_version >= 1 ? TLS_COMBINATOR : 3); wint (TLS_COMBINATOR);
write_combinator (c); write_combinator (c);
} }
@ -3056,31 +2987,16 @@ void write_type_constructors (struct tl_type *t) {
} }
} }
int MAGIC = 0x850230aa;
void write_types (int f) { void write_types (int f) {
__f = f; __f = f;
if (schema_version == 1) {
wint (TLS_SCHEMA);
} else if (schema_version == 2) {
wint (TLS_SCHEMA_V2); wint (TLS_SCHEMA_V2);
} else {
wint (MAGIC);
}
if (schema_version >= 1) {
wint (0); wint (0);
wint (time (0)); wint (time (0));
}
num = 0; num = 0;
if (schema_version >= 1) {
wint (total_types_num); wint (total_types_num);
}
tree_act_tl_type (tl_type_tree, write_type); tree_act_tl_type (tl_type_tree, write_type);
if (schema_version >= 1) {
wint (total_constructors_num); wint (total_constructors_num);
}
tree_act_tl_type (tl_type_tree, write_type_constructors); tree_act_tl_type (tl_type_tree, write_type_constructors);
if (schema_version >= 1) {
wint (total_functions_num); wint (total_functions_num);
}
tree_act_tl_constructor (tl_function_tree, write_function); tree_act_tl_constructor (tl_function_tree, write_function);
} }

20
tl-tl.h
View File

@ -25,22 +25,14 @@
#ifndef __TL_TL_H__ #ifndef __TL_TL_H__
#define __TL_TL_H__ #define __TL_TL_H__
#define TLS_SCHEMA 0xf19d9e38 #define TLS_SCHEMA_V2 0x3a2f9be2
#define TLS_TYPE 0x12eb4386 #define TLS_TYPE 0x12eb4386
#define TLS_COMBINATOR 0x5c0a1ed5 #define TLS_COMBINATOR 0x5c0a1ed5
#define TLS_COMBINATOR_LEFT_BUILTIN 0xcd211f63 #define TLS_COMBINATOR_LEFT_BUILTIN 0xcd211f63
#define TLS_COMBINATOR_LEFT 0x4c12c6d9 #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_COMBINATOR_RIGHT_V2 0x2c064372
#define TLS_ARG_V2 0x29dfe61b #define TLS_ARG_V2 0x29dfe61b
#define TLS_EXPR_TYPE 0xecc9da78 #define TLS_EXPR_TYPE 0xecc9da78
#define TLS_EXPR_NAT 0xdcb49bd8 #define TLS_EXPR_NAT 0xdcb49bd8
@ -49,4 +41,12 @@
#define TLS_TYPE_VAR 0x0142ceae #define TLS_TYPE_VAR 0x0142ceae
#define TLS_ARRAY 0xd9fb20de #define TLS_ARRAY 0xd9fb20de
#define TLS_TYPE_EXPR 0xc1863d08 #define TLS_TYPE_EXPR 0xc1863d08
/* Deprecated (old versions), read-only */
#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
#endif #endif

5
tlc.c
View File

@ -45,14 +45,12 @@
int verbosity; int verbosity;
int output_expressions; int output_expressions;
int schema_version = 2;
void usage (void) { void usage (void) {
printf ("usage: tl-parser [-v] [-h] <TL-schema-file>\n" printf ("usage: tl-parser [-v] [-h] <TL-schema-file>\n"
"\tTL compiler\n" "\tTL compiler\n"
"\t-v\toutput statistical and debug information into stderr\n" "\t-v\toutput statistical and debug information into stderr\n"
"\t-E\twhenever is possible output to stdout expressions\n" "\t-E\twhenever is possible output to stdout expressions\n"
"\t-e <file>\texport serialized schema to file\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); exit (2);
} }
@ -125,9 +123,6 @@ int main (int argc, char **argv) {
case 'e': case 'e':
vkext_file = optarg; vkext_file = optarg;
break; break;
case 'w':
schema_version = atoi (optarg);
break;
case 'v': case 'v':
verbosity++; verbosity++;
break; break;