flush
authorMichael Wallner <mike@php.net>
Mon, 12 Oct 2015 19:14:56 +0000 (21:14 +0200)
committerMichael Wallner <mike@php.net>
Mon, 12 Oct 2015 19:14:56 +0000 (21:14 +0200)
.gitignore
idl/Makefile
idl/compiler.c [new file with mode: 0644]
idl/lexer.h
idl/lexer.re
idl/main.c
idl/main.h [new file with mode: 0644]
idl/parser.y
idl/types.h
idl/validator.c
idl/validator.h

index 6a24edfda9c54554af4880d685510685e3faa3ed..492bf339e7f3f8d110bbe102c6219ef40d21e64b 100644 (file)
@@ -5,3 +5,6 @@
 /idl/parser.c
 /idl/parser.out
 /idl/makeheaders*
 /idl/parser.c
 /idl/parser.out
 /idl/makeheaders*
+/idl/lemon.c
+/idl/lempar.c
+/idl/lemon
index 84860c93b00b9b300e20d46620cf796ecaa3545f..ccc4bf6eac32902d83ca6059593cdb49f2f95cae 100644 (file)
@@ -1,29 +1,51 @@
 CFLAGS += -g -D$(shell uname | tr a-z A-Z)
 CFLAGS += -g -D$(shell uname | tr a-z A-Z)
+SOURCES := parser.c lexer.c validator.c compiler.c main.c
+HEADERS := $(addsuffix .[ch], $(basename $(SOURCES)))
+
+GENERATED_FILES := $(addsuffix .h, $(basename $(SOURCES)))
+
 .PHONY: all
 .PHONY: all
-all: main
+all: headers main
+
+.PHONY: headers
+headers: makeheaders $(SOURCES)
+       ./makeheaders $(HEADERS) types.h
+
+GENERATED_FILES += lempar.c
+lempar.c:
+       curl -sSo $@ "http://www.sqlite.org/src/raw/tool/lempar.c?name=3617143ddb9b176c3605defe6a9c798793280120"
+
+GENERATED_FILES += lemon.c
+lemon.c:
+       curl -sSo $@ "http://www.sqlite.org/src/raw/tool/lemon.c?name=039f813b520b9395740c52f9cbf36c90b5d8df03"
+
+GENERATED_FILES += lemon
+lemon: lemon.c | lempar.c
 
 
+GENERATED_FILES += makeheaders.c
 makeheaders.c:
 makeheaders.c:
-       curl -sSO http://www.hwaci.com/sw/mkhdr/makeheaders.c
+       curl -sSo makeheaders.c "https://www.fossil-scm.org/xfer/raw/src/makeheaders.c?name=c42268ec69aae42b8dd10471fd73377d789873ca"
+#http://www.hwaci.com/sw/mkhdr/makeheaders.c
 
 GENERATED_FILES += makeheaders
 makeheaders: makeheaders.c
 
 GENERATED_FILES += main
 
 GENERATED_FILES += makeheaders
 makeheaders: makeheaders.c
 
 GENERATED_FILES += main
-main: main.c parser.c lexer.c validator.c
-
-GENERATED_FILES += parser.h
-parser.h: parser.c makeheaders
-       ./makeheaders $<:$@
-       touch $@
+main: $(SOURCES)
 
 GENERATED_FILES += parser.c
 
 GENERATED_FILES += parser.c
-parser.c: parser.y types.h
-       lemon -c -m $<
+parser.c: parser.y lemon
+       ./lemon -c -m $<
 
 GENERATED_FILES += lexer.c
 
 GENERATED_FILES += lexer.c
-lexer.c: lexer.re parser.h
+lexer.c: lexer.re
        re2c -o $@ $<
 
        re2c -o $@ $<
 
+%.h: headers
+
+%.c: %.h
+       touch $@
+
 .PHONY: clean
 clean:
 .PHONY: clean
 clean:
-       -rm -f $(GENERATED_FILES)
+       -echo rm -f $(GENERATED_FILES)
diff --git a/idl/compiler.c b/idl/compiler.c
new file mode 100644 (file)
index 0000000..7250836
--- /dev/null
@@ -0,0 +1,18 @@
+#include <stdlib.h>
+
+#include "compiler.h"
+
+#if INTERFACE
+typedef struct PSI_Compiler {
+       decl_typedefs *defs;
+       decls *decls;
+       impls *impls;
+       char *lib;
+       char *fn;
+} PSI_Compiler;
+#endif
+
+PSI_Compiler *PSI_CompilerInit(PSI_Compiler *C, PSI_Validator *V)
+{
+
+}
index be1ee574be95de0c64442ba340c246cfc07fcefd..3f74a287668b513ec1f9458973dac3855bcdbeef 100644 (file)
-#define BSIZE 256
-
+/* \aThis file was automatically generated.  Do not edit! */
+#undef INTERFACE
+#define PSI_T_COMMENT                         1
+#define PSI_T_NULL                           27
+#define PSI_T_MIXED                          42
+#define PSI_T_VOID                           10
+#define PSI_T_BOOLVAL                        35
+#define PSI_T_BOOL                           43
+#define PSI_T_INTVAL                         33
+#define PSI_T_INT                            11
+#define PSI_T_FLOATVAL                       34
+#define PSI_T_FLOAT                          12
+#define PSI_T_FUNCTION                       24
+#define PSI_T_DOUBLE                         13
+#define PSI_T_SET                            36
+#define PSI_T_SINT16                         16
+#define PSI_T_SINT32                         18
+#define PSI_T_SINT64                         20
+#define PSI_T_SINT8                          14
+#define PSI_T_STRING                         44
+#define PSI_T_STRVAL                         32
+#define PSI_T_UINT16                         17
+#define PSI_T_UINT32                         19
+#define PSI_T_UINT64                         21
+#define PSI_T_UINT8                          15
+#define PSI_T_ARRAY                          45
+#define PSI_T_TO_BOOL                        40
+#define PSI_T_TO_FLOAT                       39
+#define PSI_T_TO_INT                         38
+#define PSI_T_TO_STRING                      37
+#define PSI_T_TYPEDEF                         5
+#define PSI_T_LET                            31
+#define PSI_T_LIB                             2
+#define PSI_T_RET                            41
+#define PSI_T_NSNAME                         25
+#define PSI_T_QUOTED_STRING                   3
+#define PSI_T_DIGIT                          46
+#define PSI_T_NAME                            6
+#define PSI_T_REFERENCE                      29
+#define PSI_T_POINTER                        50
+#define PSI_T_DOLLAR                         28
+#define PSI_T_EQUALS                         30
+#define PSI_T_DOT                            47
+#define PSI_T_RBRACE                         23
+#define PSI_T_LBRACE                         22
+#define PSI_T_COLON                          26
+#define PSI_T_COMMA                           9
+#define PSI_T_EOS                             4
+#define PSI_T_RPAREN                          8
+#define PSI_T_LPAREN                          7
 typedef int token_t;
 typedef int token_t;
-
-typedef struct PSI_Token {
+typedef struct PSI_Lexer PSI_Lexer;
+typedef struct decl_typedefs decl_typedefs;
+typedef struct decl_typedef decl_typedef;
+typedef struct decl_type decl_type;
+struct decl_type {
+       char *name;
        token_t type;
        token_t type;
-       unsigned line;
-       size_t size;
-       char text[1];
-} PSI_Token;
-
-typedef struct impls impls;
+       struct decl_type *real;
+};
+struct decl_typedef {
+       char *alias;
+       decl_type *type;
+};
+struct decl_typedefs {
+       size_t count;
+       decl_typedef **list;
+};
 typedef struct decls decls;
 typedef struct decls decls;
-typedef struct decl_typedefs decl_typedefs;
-
-typedef struct PSI_Lexer {
+typedef struct decl decl;
+typedef struct decl_abi decl_abi;
+struct decl_abi {
+       char *convention;
+};
+typedef struct decl_arg decl_arg;
+typedef struct decl_var decl_var;
+struct decl_var {
+       char *name;
+       unsigned pointer_level;
+};
+struct decl_arg {
+       decl_type *type;
+       decl_var *var;
+};
+typedef struct decl_args decl_args;
+struct decl_args {
+       decl_arg **args;
+       size_t count;
+};
+struct decl {
+       decl_abi *abi;
+       decl_arg *func;
+       decl_args *args;
+       void *dlptr;
+};
+struct decls {
+       size_t count;
+       decl **list;
+};
+typedef struct impls impls;
+typedef struct impl impl;
+typedef struct impl_func impl_func;
+typedef struct impl_args impl_args;
+typedef struct impl_arg impl_arg;
+typedef struct impl_type impl_type;
+struct impl_type {
+       char *name;
+       token_t type;
+};
+typedef struct impl_var impl_var;
+struct impl_var {
+       char *name;
+       unsigned reference:1;
+};
+typedef struct impl_def_val impl_def_val;
+struct impl_def_val {
+       token_t type;
+       union {
+               int64_t digits;
+               double decimals;
+       } v;
+       unsigned is_null:1;
+};
+struct impl_arg {
+       impl_type *type;
+       impl_var *var;
+       impl_def_val *def;
+};
+struct impl_args {
+       impl_arg **args;
+       size_t count;
+};
+struct impl_func {
+       char *name;
+       impl_args *args;
+       impl_type *return_type;
+};
+typedef struct impl_stmts impl_stmts;
+typedef struct impl_stmt impl_stmt;
+typedef struct let_stmt let_stmt;
+typedef struct let_value let_value;
+typedef struct let_func let_func;
+struct let_func {
+       token_t type;
+       char *name;
+};
+struct let_value {
+       let_func *func;
+       impl_var *var;
+       unsigned null_pointer_ref:1;
+};
+struct let_stmt {
+       decl_var *var;
+       let_value *val;
+};
+typedef struct set_stmt set_stmt;
+typedef struct set_value set_value;
+typedef struct set_func set_func;
+struct set_func {
+       token_t type;
+       char *name;
+};
+typedef struct decl_vars decl_vars;
+struct decl_vars {
+       decl_var **vars;
+       size_t count;
+};
+struct set_value {
+       set_func *func;
+       decl_vars *vars;
+};
+struct set_stmt {
+       impl_var *var;
+       set_value *val;
+};
+typedef struct ret_stmt ret_stmt;
+struct ret_stmt {
+       set_func *func;
+       decl_var *decl;
+};
+struct impl_stmt {
+       token_t type;
+       union {
+               let_stmt *let;
+               set_stmt *set;
+               ret_stmt *ret;
+               void *ptr;
+       } s;
+};
+struct impl_stmts {
+       impl_stmt **stmts;
+       size_t count;
+};
+struct impl {
+       impl_func *func;
+       impl_stmts *stmts;
+};
+struct impls {
+       size_t count;
+       impl **list;
+};
+#define BSIZE 256
+struct PSI_Lexer {
        decl_typedefs *defs;
        decls *decls;
        impls *impls;
        decl_typedefs *defs;
        decls *decls;
        impls *impls;
@@ -22,12 +209,19 @@ typedef struct PSI_Lexer {
        FILE *fp;
        size_t line;
        char *cur, *tok, *lim, *eof, *ctx, *mrk, buf[BSIZE];
        FILE *fp;
        size_t line;
        char *cur, *tok, *lim, *eof, *ctx, *mrk, buf[BSIZE];
-} PSI_Lexer;
-
-PSI_Lexer *PSI_LexerInit(PSI_Lexer *L, const char *filename);
-size_t PSI_LexerFill(PSI_Lexer *L, size_t n);
+};
 token_t PSI_LexerScan(PSI_Lexer *L);
 token_t PSI_LexerScan(PSI_Lexer *L);
-void PSI_LexerDtor(PSI_Lexer *L);
+PSI_Lexer *PSI_LexerInit(PSI_Lexer *L,const char *filename);
 void PSI_LexerFree(PSI_Lexer **L);
 void PSI_LexerFree(PSI_Lexer **L);
-
-PSI_Token *PSI_TokenAlloc(PSI_Lexer *L, token_t t);
+void PSI_LexerDtor(PSI_Lexer *L);
+size_t PSI_LexerFill(PSI_Lexer *L,size_t n);
+typedef struct PSI_Token PSI_Token;
+struct PSI_Token {
+       token_t type;
+       unsigned line;
+       size_t size;
+       char text[1];
+};
+PSI_Token *PSI_TokenAlloc(PSI_Lexer *L,token_t t);
+#define YYMAXFILL 10
+#define INTERFACE 0
index d52436ae361a146e0eefcb702ebdaedc36402a15..4c9e0fea282726115b70d93dfcc0c0dc1d33168b 100644 (file)
@@ -5,13 +5,23 @@
 #include <assert.h>
 
 #include "lexer.h"
 #include <assert.h>
 
 #include "lexer.h"
-#include "parser.h"
-#include "types.h"
 
 
-#ifndef BSIZE
+#if INTERFACE
 /*!max:re2c*/
 #define BSIZE 256
 /*!max:re2c*/
 #define BSIZE 256
+
+typedef struct PSI_Lexer {
+       decl_typedefs *defs;
+       decls *decls;
+       impls *impls;
+       char *lib;
+       char *fn;
+       FILE *fp;
+       size_t line;
+       char *cur, *tok, *lim, *eof, *ctx, *mrk, buf[BSIZE];
+} PSI_Lexer;
 #endif
 #endif
+
 #if BSIZE < YYMAXFILL
 # error BSIZE must be greater than YYMAXFILL
 #endif
 #if BSIZE < YYMAXFILL
 # error BSIZE must be greater than YYMAXFILL
 #endif
index f8029581734cc2fb2efdf707447a17773d4d6ece..c4664be36b45d426523d69d9487a0bfb0f0520ea 100644 (file)
@@ -1,9 +1,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "lexer.h"
-#include "parser.h"
-#include "validator.h"
+
+#include "main.h"
 
 static int TRACE;
 
 
 static int TRACE;
 
diff --git a/idl/main.h b/idl/main.h
new file mode 100644 (file)
index 0000000..bb8b14a
--- /dev/null
@@ -0,0 +1,196 @@
+/* \aThis file was automatically generated.  Do not edit! */
+#undef INTERFACE
+typedef struct PSI_Validator PSI_Validator;
+typedef struct decl_typedefs decl_typedefs;
+typedef struct decl_typedef decl_typedef;
+typedef struct decl_type decl_type;
+typedef int token_t;
+struct decl_type {
+       char *name;
+       token_t type;
+       struct decl_type *real;
+};
+struct decl_typedef {
+       char *alias;
+       decl_type *type;
+};
+struct decl_typedefs {
+       size_t count;
+       decl_typedef **list;
+};
+typedef struct decls decls;
+typedef struct decl decl;
+typedef struct decl_abi decl_abi;
+struct decl_abi {
+       char *convention;
+};
+typedef struct decl_arg decl_arg;
+typedef struct decl_var decl_var;
+struct decl_var {
+       char *name;
+       unsigned pointer_level;
+};
+struct decl_arg {
+       decl_type *type;
+       decl_var *var;
+};
+typedef struct decl_args decl_args;
+struct decl_args {
+       decl_arg **args;
+       size_t count;
+};
+struct decl {
+       decl_abi *abi;
+       decl_arg *func;
+       decl_args *args;
+       void *dlptr;
+};
+struct decls {
+       size_t count;
+       decl **list;
+};
+typedef struct impls impls;
+typedef struct impl impl;
+typedef struct impl_func impl_func;
+typedef struct impl_args impl_args;
+typedef struct impl_arg impl_arg;
+typedef struct impl_type impl_type;
+struct impl_type {
+       char *name;
+       token_t type;
+};
+typedef struct impl_var impl_var;
+struct impl_var {
+       char *name;
+       unsigned reference:1;
+};
+typedef struct impl_def_val impl_def_val;
+struct impl_def_val {
+       token_t type;
+       union {
+               int64_t digits;
+               double decimals;
+       } v;
+       unsigned is_null:1;
+};
+struct impl_arg {
+       impl_type *type;
+       impl_var *var;
+       impl_def_val *def;
+};
+struct impl_args {
+       impl_arg **args;
+       size_t count;
+};
+struct impl_func {
+       char *name;
+       impl_args *args;
+       impl_type *return_type;
+};
+typedef struct impl_stmts impl_stmts;
+typedef struct impl_stmt impl_stmt;
+typedef struct let_stmt let_stmt;
+typedef struct let_value let_value;
+typedef struct let_func let_func;
+struct let_func {
+       token_t type;
+       char *name;
+};
+struct let_value {
+       let_func *func;
+       impl_var *var;
+       unsigned null_pointer_ref:1;
+};
+struct let_stmt {
+       decl_var *var;
+       let_value *val;
+};
+typedef struct set_stmt set_stmt;
+typedef struct set_value set_value;
+typedef struct set_func set_func;
+struct set_func {
+       token_t type;
+       char *name;
+};
+typedef struct decl_vars decl_vars;
+struct decl_vars {
+       decl_var **vars;
+       size_t count;
+};
+struct set_value {
+       set_func *func;
+       decl_vars *vars;
+};
+struct set_stmt {
+       impl_var *var;
+       set_value *val;
+};
+typedef struct ret_stmt ret_stmt;
+struct ret_stmt {
+       set_func *func;
+       decl_var *decl;
+};
+struct impl_stmt {
+       token_t type;
+       union {
+               let_stmt *let;
+               set_stmt *set;
+               ret_stmt *ret;
+               void *ptr;
+       } s;
+};
+struct impl_stmts {
+       impl_stmt **stmts;
+       size_t count;
+};
+struct impl {
+       impl_func *func;
+       impl_stmts *stmts;
+};
+struct impls {
+       size_t count;
+       impl **list;
+};
+struct PSI_Validator {
+       decl_typedefs *defs;
+       decls *decls;
+       impls *impls;
+       char *lib;
+       char *fn;
+       void *dlopened;
+};
+void PSI_ValidatorDtor(PSI_Validator *V);
+int PSI_ValidatorValidate(PSI_Validator *V);
+typedef struct PSI_Lexer PSI_Lexer;
+#define BSIZE 256
+struct PSI_Lexer {
+       decl_typedefs *defs;
+       decls *decls;
+       impls *impls;
+       char *lib;
+       char *fn;
+       FILE *fp;
+       size_t line;
+       char *cur, *tok, *lim, *eof, *ctx, *mrk, buf[BSIZE];
+};
+void PSI_LexerDtor(PSI_Lexer *L);
+PSI_Validator *PSI_ValidatorInit(PSI_Validator *V,PSI_Lexer *L);
+void PSI_ParserFree(void *p,void(*freeProc)(void *));
+PSI_Lexer *PSI_LexerInit(PSI_Lexer *L,const char *filename);
+void *PSI_ParserAlloc(void *(*mallocProc)(size_t));
+int main(int argc,char *argv[]);
+typedef struct PSI_Token PSI_Token;
+struct PSI_Token {
+       token_t type;
+       unsigned line;
+       size_t size;
+       char text[1];
+};
+#define PSI_ParserTOKENTYPE PSI_Token *
+#define PSI_ParserARG_PDECL ,PSI_Lexer *L
+void PSI_Parser(void *yyp,int yymajor,PSI_ParserTOKENTYPE yyminor PSI_ParserARG_PDECL);
+PSI_Token *PSI_TokenAlloc(PSI_Lexer *L,token_t t);
+token_t PSI_LexerScan(PSI_Lexer *L);
+#if !defined(NDEBUG)
+void PSI_ParserTrace(FILE *TraceFILE,char *zTracePrompt);
+#endif
index 051533292dcc9cc00ff1d17b1e1a7f0c85ca4915..de0de4ac471f776b05a4cd42c785cdea0896898a 100644 (file)
@@ -3,9 +3,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
-#include "lexer.h"
+
 #include "parser.h"
 #include "parser.h"
-#include "types.h"
 
 static void syntax_error(const char *fn, size_t ln, const char *msg, ...) {
        fprintf(stderr, "WARNING: Syntax error on line %zu in '%s'%s", ln, fn, msg ? ": ": "\n");
 
 static void syntax_error(const char *fn, size_t ln, const char *msg, ...) {
        fprintf(stderr, "WARNING: Syntax error on line %zu in '%s'%s", ln, fn, msg ? ": ": "\n");
index 7225b5d7966f847e043778e2fc27882e34ee7db4..e3a0eade8eb133cbabb9406f2fea54e0c97bdf39 100644 (file)
@@ -1,17 +1,12 @@
-typedef struct PSI_Data {
-       decl_typedefs *defs;
-       decls *decls;
-       impls *impls;
-       char *lib;
-       char *fn;
-} PSI_Data;
 
 
-static inline void PSI_DataExchange(PSI_Data *dest, PSI_Data *src) {
-       memcpy(dest, src, sizeof(*dest));
-       memset(src, 0, sizeof(*src));
-}
+typedef int token_t;
 
 
-struct decl_typedef;
+typedef struct PSI_Token {
+       token_t type;
+       unsigned line;
+       size_t size;
+       char text[1];
+} PSI_Token;
 
 typedef struct decl_type {
        char *name;
 
 typedef struct decl_type {
        char *name;
@@ -592,3 +587,31 @@ static void free_impls(impls *impls) {
        free(impls->list);
        free(impls);
 }
        free(impls->list);
        free(impls);
 }
+
+typedef struct PSI_Data {
+       decl_typedefs *defs;
+       decls *decls;
+       impls *impls;
+       char *lib;
+       char *fn;
+} PSI_Data;
+
+EXPORT static inline void PSI_DataExchange(PSI_Data *dest, PSI_Data *src) {
+       memcpy(dest, src, sizeof(*dest));
+       memset(src, 0, sizeof(*src));
+}
+
+EXPORT static inline void PSI_DataDtor(PSI_Data *data) {
+       if (data->defs) {
+               free_decl_typedefs(data->defs);
+       }
+       if (data->decls) {
+               free_decls(data->decls);
+       }
+       if (data->impls) {
+               free_impls(data->impls);
+       }
+       if (data->fn) {
+               free(data->fn);
+       }
+}
index d2b7cfee94221c38c8b248045fff24a0d5a626f9..e81d92315a9abadc8760adb23d2490f3b53be5f8 100644 (file)
@@ -3,11 +3,20 @@
 #include <string.h>
 #include <dlfcn.h>
 #include <sys/param.h>
 #include <string.h>
 #include <dlfcn.h>
 #include <sys/param.h>
-#include "lexer.h"
-#include "parser.h"
-#include "types.h"
+
 #include "validator.h"
 
 #include "validator.h"
 
+#if INTERFACE
+typedef struct PSI_Validator {
+       decl_typedefs *defs;
+       decls *decls;
+       impls *impls;
+       char *lib;
+       char *fn;
+       void *dlopened;
+} PSI_Validator;
+#endif
+
 PSI_Validator *PSI_ValidatorInit(PSI_Validator *V, PSI_Lexer *L)
 {
        if (!V) {
 PSI_Validator *PSI_ValidatorInit(PSI_Validator *V, PSI_Lexer *L)
 {
        if (!V) {
index c7e826404af42eba4f79948dd10c4e0af2968ec5..51828f870aaeb771b1a770a31727490647043bf6 100644 (file)
-
-typedef struct PSI_Validator {
+/* \aThis file was automatically generated.  Do not edit! */
+#undef INTERFACE
+typedef struct PSI_Validator PSI_Validator;
+typedef struct decl_typedefs decl_typedefs;
+typedef struct decl_typedef decl_typedef;
+typedef struct decl_type decl_type;
+typedef int token_t;
+struct decl_type {
+       char *name;
+       token_t type;
+       struct decl_type *real;
+};
+struct decl_typedef {
+       char *alias;
+       decl_type *type;
+};
+struct decl_typedefs {
+       size_t count;
+       decl_typedef **list;
+};
+typedef struct decls decls;
+typedef struct decl decl;
+typedef struct decl_abi decl_abi;
+struct decl_abi {
+       char *convention;
+};
+typedef struct decl_arg decl_arg;
+typedef struct decl_var decl_var;
+struct decl_var {
+       char *name;
+       unsigned pointer_level;
+};
+struct decl_arg {
+       decl_type *type;
+       decl_var *var;
+};
+typedef struct decl_args decl_args;
+struct decl_args {
+       decl_arg **args;
+       size_t count;
+};
+struct decl {
+       decl_abi *abi;
+       decl_arg *func;
+       decl_args *args;
+       void *dlptr;
+};
+struct decls {
+       size_t count;
+       decl **list;
+};
+typedef struct impls impls;
+typedef struct impl impl;
+typedef struct impl_func impl_func;
+typedef struct impl_args impl_args;
+typedef struct impl_arg impl_arg;
+typedef struct impl_type impl_type;
+struct impl_type {
+       char *name;
+       token_t type;
+};
+typedef struct impl_var impl_var;
+struct impl_var {
+       char *name;
+       unsigned reference:1;
+};
+typedef struct impl_def_val impl_def_val;
+struct impl_def_val {
+       token_t type;
+       union {
+               int64_t digits;
+               double decimals;
+       } v;
+       unsigned is_null:1;
+};
+struct impl_arg {
+       impl_type *type;
+       impl_var *var;
+       impl_def_val *def;
+};
+struct impl_args {
+       impl_arg **args;
+       size_t count;
+};
+struct impl_func {
+       char *name;
+       impl_args *args;
+       impl_type *return_type;
+};
+typedef struct impl_stmts impl_stmts;
+typedef struct impl_stmt impl_stmt;
+typedef struct let_stmt let_stmt;
+typedef struct let_value let_value;
+typedef struct let_func let_func;
+struct let_func {
+       token_t type;
+       char *name;
+};
+struct let_value {
+       let_func *func;
+       impl_var *var;
+       unsigned null_pointer_ref:1;
+};
+struct let_stmt {
+       decl_var *var;
+       let_value *val;
+};
+typedef struct set_stmt set_stmt;
+typedef struct set_value set_value;
+typedef struct set_func set_func;
+struct set_func {
+       token_t type;
+       char *name;
+};
+typedef struct decl_vars decl_vars;
+struct decl_vars {
+       decl_var **vars;
+       size_t count;
+};
+struct set_value {
+       set_func *func;
+       decl_vars *vars;
+};
+struct set_stmt {
+       impl_var *var;
+       set_value *val;
+};
+typedef struct ret_stmt ret_stmt;
+struct ret_stmt {
+       set_func *func;
+       decl_var *decl;
+};
+struct impl_stmt {
+       token_t type;
+       union {
+               let_stmt *let;
+               set_stmt *set;
+               ret_stmt *ret;
+               void *ptr;
+       } s;
+};
+struct impl_stmts {
+       impl_stmt **stmts;
+       size_t count;
+};
+struct impl {
+       impl_func *func;
+       impl_stmts *stmts;
+};
+struct impls {
+       size_t count;
+       impl **list;
+};
+struct PSI_Validator {
        decl_typedefs *defs;
        decls *decls;
        impls *impls;
        char *lib;
        char *fn;
        void *dlopened;
        decl_typedefs *defs;
        decls *decls;
        impls *impls;
        char *lib;
        char *fn;
        void *dlopened;
-} PSI_Validator;
-
-PSI_Validator *PSI_ValidatorInit(PSI_Validator *V, PSI_Lexer *L);
+};
 int PSI_ValidatorValidate(PSI_Validator *V);
 int PSI_ValidatorValidate(PSI_Validator *V);
-void PSI_ValidatorDtor(PSI_Validator *V);
+#define PSI_T_NAME                            6
 void PSI_ValidatorFree(PSI_Validator **V);
 void PSI_ValidatorFree(PSI_Validator **V);
+void PSI_ValidatorDtor(PSI_Validator *V);
+typedef struct PSI_Data PSI_Data;
+struct PSI_Data {
+       decl_typedefs *defs;
+       decls *decls;
+       impls *impls;
+       char *lib;
+       char *fn;
+};
+typedef struct PSI_Lexer PSI_Lexer;
+#define BSIZE 256
+struct PSI_Lexer {
+       decl_typedefs *defs;
+       decls *decls;
+       impls *impls;
+       char *lib;
+       char *fn;
+       FILE *fp;
+       size_t line;
+       char *cur, *tok, *lim, *eof, *ctx, *mrk, buf[BSIZE];
+};
+PSI_Validator *PSI_ValidatorInit(PSI_Validator *V,PSI_Lexer *L);
+#define INTERFACE 0