From bec8fef4607fac18fa92da87e95e0da1c3ac76f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sat, 15 May 2021 01:32:46 +0200 Subject: [PATCH] move in Gwion --- AstDesc.txt | 267 ---------------------------------------------------- Makefile | 10 +- pass.sh | 145 ---------------------------- 3 files changed, 5 insertions(+), 417 deletions(-) delete mode 100644 AstDesc.txt delete mode 100644 pass.sh diff --git a/AstDesc.txt b/AstDesc.txt deleted file mode 100644 index bc93b87..0000000 --- a/AstDesc.txt +++ /dev/null @@ -1,267 +0,0 @@ -Symbol - -Array_Sub - ?Exp exp - -ID_List - Symbol xid - ?ID_List next - -Type_List - Type_Decl* td - ?Type_List next - -Tmpl* - ?ID_List list - ?Type_List call - -Range* - ?Exp start - ?Exp end - -Type_Decl* - Symbol xid - ?Array_Sub array - ?Type_List types - ?Type_Decl* next - -: Prim -Symbol* id - =Symbol id * - -m_uint* num - -m_float* float - -m_str* str - -Array_Sub* array - =Array_Sub array * - -Range** range - =Range* range * - -Exp* hack - =Exp exp * - -Exp* typeof - =Exp exp * - -Exp* interp - =Exp exp * - -m_str* char - -void* nil - -Symbol perform - -: -!PRIM -Exp_Primary* prim - !prim prim & - -### Exp -: -Var_Decl - ?Symbol xid - ?Array_Sub array - -Var_Decl_List - Var_Decl self - ?Var_Decl_List next - -Exp_Decl* - ?Type_Decl* td - Var_Decl_List list - -Exp_Binary* - Exp lhs - Exp rhs - Symbol op - -Exp_Unary* - Symbol op - ?Exp exp - ?Type_Decl* td - ?Stmt code - -#skip primary -Exp_Cast* - Type_Decl* td - Exp exp - -Exp_Postfix* exp_post - Symbol op - Exp exp - -Exp_Call* - Exp func - ?Exp args - ?Tmpl* tmpl - -Exp_Array* - Exp base - Array_Sub array - -Exp_Slice* - Exp base - Range* range - -Exp_If* - Exp cond - ?Exp if_exp - Exp else_exp - -Exp_Dot* - Exp base - Symbol xid - -Exp_Lambda* - Func_Def def - -Type_Decl* exp_td - -!exp -Exp - !exp exp & - ?Exp next - -### Stmt -: -Stmt_Exp - ?Exp val - -Stmt_Flow stmt_while - Exp cond - Stmt Body - -Stmt_Flow stmt_until - Exp cond - Stmt Body - -Stmt_For - Stmt c1 - ?Stmt c2 - ?Exp c3 - Stmt body - -Stmt_Each - Symbol sym - Exp - Stmt body - -Stmt_Loop - Exp cond - Stmt body - -Stmt_If - Exp cond - Stmt if_body - ?Stmt else_body - -Stmt_Code - ?Stmt_List - -Stmt_VarLoop - Exp exp - Stmt body - -Stmt_Exp Stmt_Break - -Stmt_Exp Stmt_Continue - -Stmt_Exp stmt_return - ?Exp val - -Stmt_List case_list - Stmt_Case stmt->d.stmt_match & - ?Case_List next - -Stmt_Match - Exp cond - Case_List list - ?Stmt where - -Stmt_Match stmt_case - Exp cond - Stmt_List list - ?Exp when - -Stmt_Index - -Stmt_PP - -Stmt_Exp stmt_retry - -Stmt_Try - stmt - -Stmt_Defer - stmt - -!Stmt -Stmt - !stmt stmt & - -Arg_List - ?Type_Decl* td - Var_Decl - ?Arg_List next - -Union_List - Type_Decl* td - Symbol xid - -### Section -: -Stmt_List - Stmt - ?Stmt_List next - -: -Func_Base* - ?Type_Decl* td - Symbol xid - ?Arg_List args - ?Tmpl* - -Func_Def - Func_Base* base - ?Stmt d.code - -Class_Def - Type_Def base & - ?Ast body - -Enum_Def - ID_List list - ?Symbol xid - -Union_Def - Union_List l - ?Symbol xid - ?Tmpl* - -Fptr_Def - Func_Base* base - -Type_Def - ?Type_Decl ext - Symbol xid - ?Tmpl tmpl - -Extend_Def - Ast body - Type_Decl td - -!section -Section* - !section section *(void**)& - -### Ast -: -Ast - Section* - ?Ast next - diff --git a/Makefile b/Makefile index 2bdc7aa..3bb414c 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,9 @@ PRG := gwfmt CFLAGS += -Wall -Wextra -Wno-unused # Includes -CFLAGS += -I/usr/local/include/gwion/util -CFLAGS += -I/usr/local/include/gwion/ast -CFLAGS += -I/usr/local/include/libtermcolor +CFLAGS += -I../util/include +CFLAGS += -I../ast/include +CFLAGS += -I../util/libtermcolor/include CFLAGS += -Iinclude #CFLAGS += -flto -Ofast @@ -35,10 +35,10 @@ endif all: ${PRG} -${PRG}: src/${PRG}.o src/unpy.o lib${PRG}.a +${PRG}: src/${PRG}.o src/unpy.o libgwion-fmt.a ${CC} ${CFLAGS} $? -Iinclude -lgwion_ast -lgwion_util ${LDFLAGS} -lpthread -lm -o ${PRG} -lib${PRG}.a: src/lint.o +libgwion-fmt.a: src/lint.o ${AR} ${AR_OPT} src/unpy.c: src/unpy.l diff --git a/pass.sh b/pass.sh deleted file mode 100644 index e06adf9..0000000 --- a/pass.sh +++ /dev/null @@ -1,145 +0,0 @@ -#!/bin/bash -[ $# -lt 2 ] && { - echo "usage: $0 AstDesc" - exit 1 -} - -gtype="$1" -section="" -return_type="void" - -#################### -# utility function # -#################### -cname() { - echo "$1" | tr '[:upper:]' '[:lower:]' | sed 's/\*//g' | sed 's/ //g' -} - -dname() { - echo "$1" | tr '[:lower:]' '[:upper:]' -} - -# section name -sname() { - if [ "$1" ] - then echo "$(cname "$1")_" - fi -} - -ctype() { - name="$1" - if [ "${name: -1}" = "*" ] - then echo "${name:0:-1} *" - else echo "$name " - fi -} - -#################### -# common variables # -#################### -gname="$(cname "$gtype")" - - -member() { - echo "$@" | while read -r type name access - do - if [ "${type:0:1}" = "=" ] - then - type=$(cname "${type:1}") - echo " ${gname}_${s}$type(a, ${access}b);" - continue - fi - if [ "${type:0:1}" = "!" ] - then - type=${type:1} - echo " ${gname}_$(cname "$type")_func[b->${type}_type](a, ${access}b->d);" - continue - fi - if [ "${type:0:1}" = "?" ] - then - type=${type:1} - opt=1 - fi - type=$(cname "$type") - if [ "$name" ] - then n=$(cname "$name") - else n="$type" - fi - if [ "$opt" ] - then - printf " if(b->%s)\n " "$n" - fi - echo " ${gname}_${s}${type}(a, ${access}b->${n});" - done -} - -struct() { - echo "$@" | while read -r type name access - do - s=$(sname "$section") - if [ "$name" ] - then n=$(cname "$name") - else n=$(cname "$type") - fi - echo "ANN static $return_type ${gname}_${s}${n}($(ctype "$gtype")a, $(ctype "$type")b);" >> "${gname}.h" - echo "ANN static $return_type ${gname}_${s}${n}($(ctype "$gtype")a, $(ctype "$type")b) {" - done -} - -decl() { - echo "$@" | while read -r type - do - echo "DECL_$(dname "$type")_FUNC($gname, $return_type, $gtype)" - done -} - -cat << EOF > "${gname}.h" -typedef struct { - -} ${gtype/\*/}; - -EOF - -cat << EOF > "${gname}.c" -#include "gwion_util.h" -#include "gwion_ast.h" -#include "${gname}.h" - -EOF - -while IFS= read -r line -do - case "${line:0:1}" in - "#");; - "" ) printf "}\n\n";; - "!" ) decl "${line:1}";; - ":") section="${line:1}";; - " ") member "$line";; - *) struct "$line";; - esac -done < "$2" >> "${gname}.c" - -cat << EOF >> "${gname}.c" -int main(int argc, char **argv) { - MemPool mp = mempool_ini(sizeof(struct Exp_)); - SymTable* st = new_symbol_table(mp, 65347); - struct PPArg_ ppa = {}; - ${gtype/\*/} ${gname} = {}; - pparg_ini(mp, &ppa); - for(int i = 1; i < argc; ++i) { - FILE* file = fopen(argv[i], "r"); - if(!file) - continue; - struct AstGetter_ arg = { argv[i], file, st , .ppa=&ppa }; - const Ast ast = parse(&arg); - if(ast) { - ${gname}_ast(&${gname}, ast); - free_ast(mp, ast); - } - fclose(file); - } - pparg_end(&ppa); - free_symbols(st); - mempool_end(mp); -} -EOF