Skip to content

Commit

Permalink
🎨 Build out of tree and mp_vector macros
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Dec 10, 2024
1 parent c507d99 commit 618c2c8
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 262 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.o
build
*.a
.d
gwfmt
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ CFLAGS += -DBUILD_ON_WINDOWS=1 -D_XOPEN_SOURCE=700
LDFLAGS += -Wl,--enable-auto-import
endif

SRC := $(wildcard src/*.c)
OBJ := $(SRC:src/%.c=build/%.o)

all: ${PRG}

${PRG}: src/${PRG}.o src/unpy.o src/gwion_config.o libgwion_fmt.a
${PRG}: build/${PRG}.o build/unpy.o build/gwion_config.o libgwion_fmt.a
${CC} ${DEPFLAGS} ${CFLAGS} $^ -Iinclude -lgwion -lgwion_ast -lgwion_util ${LDFLAGS} -ldl -lpthread -lm -o $@

libgwion_fmt.a: src/lint.o src/casing.o
libgwion_fmt.a: build/lint.o build/casing.o
${AR} ${AR_OPT}

src/unpy.c: src/unpy.l
${LEX} src/unpy.l

clean:
rm -rf src/*.o ${PRG} libgwion_fmt.a
rm -rf build/*.o ${PRG} libgwion_fmt.a

install: all
install ${PRG} ${PREFIX}/bin
Expand All @@ -55,12 +58,15 @@ uninstall:
rm ${PREFIX}/lib/lib${PRG}.a
rm ${PREFIX}/include/${PRG}.h

.c.o:
$(info compile $(<:.c=))
@${CC} $(DEPFLAGS) ${CFLAGS} ${PACKAGE_INFO} ${INSTALL_PREFIX} -c $< -o $(<:.c=.o)
@mv -f $(DEPDIR)/$(@F:.o=.Td) $(DEPDIR)/$(@F:.o=.d) && touch $@
@echo $@: config.mk >> $(DEPDIR)/$(@F:.o=.d)
build/%.o: $(subst build,src, $(@:.o=.c))
$(info compile $(subst build/,,$(@:.o=)))
@mkdir -p $(shell dirname $@) > /dev/null
@mkdir -p $(subst build,.d,$(shell dirname $@)) > /dev/null
@${CC} $(DEPFLAGS) ${CFLAGS} -c $(subst build,src,$(@:.o=.c)) -o $@
@mv -f $(subst build,${DEPDIR},$(@:.o=.Td)) $(subst build,${DEPDIR},$(@:.o=.d)) && touch $@

DEPDIR := .d
$(shell mkdir -p $(DEPDIR) >/dev/null)
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$(@F:.o=.Td)
DEPFLAGS = -MT $@ -MMD -MP -MF $(subst build,${DEPDIR},$(@:.o=.Td))
DEPS := $(subst build,$(DEPDIR),$(OBJ:.o=.d))
-include $(DEPS)
59 changes: 30 additions & 29 deletions include/gwfmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,33 @@ typedef struct GwFmtMark {
uint16_t line;
char sign[16];
} GwFmtMark;

MK_VECTOR_TYPE(GwFmtMark, mark)

typedef struct Config {
Casing cases[LastCase];
char colors[LastColor][MAX_COLOR_LENGTH];
} Config;

typedef struct GwfmtState {
GwText text;
PPArg *ppa;
Config *config;
unsigned int nindent;
MP_Vector *marks; // NOTE: make it a vector?
unsigned int base_column;
bool py;
bool unpy;
bool onlypy;
bool minimize;
bool color;
bool builtin;
bool pretty;
bool show_line;
bool header;
bool use_tabs;
bool error;
bool fix_case;
bool check_case;
GwText text;
PPArg *ppa;
Config *config;
unsigned int nindent;
GwFmtMarkList *marks;
unsigned int base_column;
bool py;
bool unpy;
bool onlypy;
bool minimize;
bool color;
bool builtin;
bool pretty;
bool show_line;
bool header;
bool use_tabs;
bool error;
bool fix_case;
bool check_case;
} GwfmtState;

void gwfmt_state_init(GwfmtState *ls);
Expand Down Expand Up @@ -102,15 +103,15 @@ ANN void gwfmt_lparen(Gwfmt *a);
ANN void gwfmt_rparen(Gwfmt *a);
ANN void gwfmt_lbrace(Gwfmt *a);
ANN void gwfmt_rbrace(Gwfmt *a);
ANN void gwfmt_exp(Gwfmt *a, Exp* b);
ANN void gwfmt_func_def(Gwfmt *a, Func_Def b);
ANN void gwfmt_class_def(Gwfmt *a, Class_Def b);
ANN void gwfmt_enum_def(Gwfmt *a, Enum_Def b);
ANN void gwfmt_union_def(Gwfmt *a, Union_Def b);
ANN void gwfmt_fptr_def(Gwfmt *a, Fptr_Def b);
ANN void gwfmt_type_def(Gwfmt *a, Type_Def b);
ANN void gwfmt_prim_def(Gwfmt *a, Prim_Def b);
ANN void gwfmt_ast(Gwfmt *a, Ast b);
ANN void gwfmt_exp(Gwfmt *a, const Exp* b);
ANN void gwfmt_func_def(Gwfmt *a, const Func_Def b);
ANN void gwfmt_class_def(Gwfmt *a, const Class_Def b);
ANN void gwfmt_enum_def(Gwfmt *a, const Enum_Def b);
ANN void gwfmt_union_def(Gwfmt *a, const Union_Def b);
ANN void gwfmt_fptr_def(Gwfmt *a, const Fptr_Def b);
ANN void gwfmt_type_def(Gwfmt *a, const Type_Def b);
ANN void gwfmt_prim_def(Gwfmt *a, const Prim_Def b);
ANN void gwfmt_ast(Gwfmt *a, const Ast b);
ANN void gwfmt_type_decl(Gwfmt *a, const Type_Decl *b);
ANN void gwfmt_variable(Gwfmt *a, const Variable *b);

Expand Down
100 changes: 50 additions & 50 deletions include/gwfmt_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,54 @@
#include <gwion_ast.h>
#include <gwfmt.h>

ANN static void gwfmt_symbol(Gwfmt *a, Symbol b);
ANN static void gwfmt_array_sub(Gwfmt *a, Array_Sub b);
ANN static void gwfmt_id_list(Gwfmt *a, ID_List b);
ANN static void gwfmt_tmplarg_list(Gwfmt *a, TmplArg_List b);
ANN static void gwfmt_tmpl(Gwfmt *a, Tmpl *b);
ANN static void gwfmt_range(Gwfmt *a, Range *b);
ANN static void gwfmt_prim_id(Gwfmt *a, Symbol *b);
ANN static void gwfmt_prim_num(Gwfmt *a, struct gwint *b);
ANN static void gwfmt_prim_float(Gwfmt *a, m_float *b);
ANN static void gwfmt_prim_str(Gwfmt *a, struct AstString *b);
ANN static void gwfmt_prim_array(Gwfmt *a, Array_Sub *b);
ANN static void gwfmt_prim_range(Gwfmt *a, Range **b);
ANN static void gwfmt_prim_hack(Gwfmt *a, Exp* *b);
ANN static void gwfmt_prim_interp(Gwfmt *a, Exp* *b);
ANN static void gwfmt_prim_char(Gwfmt *a, m_str *b);
ANN static void gwfmt_prim_nil(Gwfmt *a, void *b);
ANN static void gwfmt_prim(Gwfmt *a, Exp_Primary *b);
ANN static void gwfmt_symbol(Gwfmt *a, const Symbol b);
ANN static void gwfmt_array_sub(Gwfmt *a, const Array_Sub b);
ANN static void gwfmt_taglist(Gwfmt *a, const TagList *b);
ANN static void gwfmt_tmplarg_list(Gwfmt *a, const TmplArgList *b);
ANN static void gwfmt_tmpl(Gwfmt *a, const Tmpl *b);
ANN static void gwfmt_range(Gwfmt *a, const Range *b);
ANN static void gwfmt_prim_id(Gwfmt *a, const Symbol *b);
ANN static void gwfmt_prim_num(Gwfmt *a, const struct gwint *b);
ANN static void gwfmt_prim_float(Gwfmt *a, const m_float *b);
ANN static void gwfmt_prim_str(Gwfmt *a, const struct AstString *b);
ANN static void gwfmt_prim_array(Gwfmt *a, const Array_Sub *b);
ANN static void gwfmt_prim_range(Gwfmt *a, const Range **b);
ANN static void gwfmt_prim_hack(Gwfmt *a, const Exp* *b);
ANN static void gwfmt_prim_interp(Gwfmt *a, const Exp* *b);
ANN static void gwfmt_prim_char(Gwfmt *a, const m_str *b);
ANN static void gwfmt_prim_nil(Gwfmt *a, const void *b);
ANN static void gwfmt_prim(Gwfmt *a, const Exp_Primary *b);
ANN static void gwfmt_var_decl(Gwfmt *a, const Var_Decl *b);
ANN static void gwfmt_exp_decl(Gwfmt *a, Exp_Decl *b);
ANN static void gwfmt_exp_binary(Gwfmt *a, Exp_Binary *b);
ANN static void gwfmt_exp_unary(Gwfmt *a, Exp_Unary *b);
ANN static void gwfmt_exp_cast(Gwfmt *a, Exp_Cast *b);
ANN static void gwfmt_exp_post(Gwfmt *a, Exp_Postfix *b);
ANN static void gwfmt_exp_call(Gwfmt *a, Exp_Call *b);
ANN static void gwfmt_exp_array(Gwfmt *a, Exp_Array *b);
ANN static void gwfmt_exp_slice(Gwfmt *a, Exp_Slice *b);
ANN static void gwfmt_exp_if(Gwfmt *a, Exp_If *b);
ANN static void gwfmt_exp_dot(Gwfmt *a, Exp_Dot *b);
ANN static void gwfmt_exp_lambda(Gwfmt *a, Exp_Lambda *b);
ANN static void gwfmt_stmt_exp(Gwfmt *a, Stmt_Exp b);
ANN static void gwfmt_stmt_while(Gwfmt *a, Stmt_Flow b);
ANN static void gwfmt_stmt_until(Gwfmt *a, Stmt_Flow b);
ANN static void gwfmt_stmt_for(Gwfmt *a, Stmt_For b);
ANN static void gwfmt_stmt_each(Gwfmt *a, Stmt_Each b);
ANN static void gwfmt_stmt_loop(Gwfmt *a, Stmt_Loop b);
ANN static void gwfmt_stmt_if(Gwfmt *a, Stmt_If b);
ANN static void gwfmt_stmt_code(Gwfmt *a, Stmt_Code b);
ANN static void gwfmt_stmt_break(Gwfmt *a, Stmt_Index b);
ANN static void gwfmt_stmt_continue(Gwfmt *a, Stmt_Index b);
ANN static void gwfmt_stmt_return(Gwfmt *a, Stmt_Exp b);
ANN static void gwfmt_case_list(Gwfmt *a, Stmt_List b);
ANN static void gwfmt_stmt_match(Gwfmt *a, Stmt_Match b);
ANN static void gwfmt_stmt_case(Gwfmt *a, Stmt_Match b);
ANN static void gwfmt_stmt_pp(Gwfmt *a, Stmt_PP b);
ANN static void gwfmt_stmt_defer(Gwfmt *a, Stmt_Defer b);
ANN static void gwfmt_stmt(Gwfmt *a, Stmt* b);
ANN /*static */void gwfmt_arg_list(Gwfmt *a, Arg_List b, const bool);
ANN static void gwfmt_variable_list(Gwfmt *a, Variable_List b);
ANN static void gwfmt_stmt_list(Gwfmt *a, Stmt_List b);
ANN static void gwfmt_func_base(Gwfmt *a, Func_Base *b);
ANN static void gwfmt_section(Gwfmt *a, Section *b);
ANN static void gwfmt_exp_decl(Gwfmt *a, const Exp_Decl *b);
ANN static void gwfmt_exp_binary(Gwfmt *a, const Exp_Binary *b);
ANN static void gwfmt_exp_unary(Gwfmt *a, const Exp_Unary *b);
ANN static void gwfmt_exp_cast(Gwfmt *a, const Exp_Cast *b);
ANN static void gwfmt_exp_post(Gwfmt *a, const Exp_Postfix *b);
ANN static void gwfmt_exp_call(Gwfmt *a, const Exp_Call *b);
ANN static void gwfmt_exp_array(Gwfmt *a, const Exp_Array *b);
ANN static void gwfmt_exp_slice(Gwfmt *a, const Exp_Slice *b);
ANN static void gwfmt_exp_if(Gwfmt *a, const Exp_If *b);
ANN static void gwfmt_exp_dot(Gwfmt *a, const Exp_Dot *b);
ANN static void gwfmt_exp_lambda(Gwfmt *a, const Exp_Lambda *b);
ANN static void gwfmt_stmt_exp(Gwfmt *a, const Stmt_Exp b);
ANN static void gwfmt_stmt_while(Gwfmt *a, const Stmt_Flow b);
ANN static void gwfmt_stmt_until(Gwfmt *a, const Stmt_Flow b);
ANN static void gwfmt_stmt_for(Gwfmt *a, const Stmt_For b);
ANN static void gwfmt_stmt_each(Gwfmt *a, const Stmt_Each b);
ANN static void gwfmt_stmt_loop(Gwfmt *a, const Stmt_Loop b);
ANN static void gwfmt_stmt_if(Gwfmt *a, const Stmt_If b);
ANN static void gwfmt_stmt_code(Gwfmt *a, const Stmt_Code b);
ANN static void gwfmt_stmt_break(Gwfmt *a, const Stmt_Index b);
ANN static void gwfmt_stmt_continue(Gwfmt *a, const Stmt_Index b);
ANN static void gwfmt_stmt_return(Gwfmt *a, const Stmt_Exp b);
ANN static void gwfmt_case_list(Gwfmt *a, const StmtList *b);
ANN static void gwfmt_stmt_match(Gwfmt *a, const struct Match *b);
ANN static void gwfmt_stmt_case(Gwfmt *a, const struct Match *b);
ANN static void gwfmt_stmt_pp(Gwfmt *a, const Stmt_PP b);
ANN static void gwfmt_stmt_defer(Gwfmt *a, const Stmt_Defer b);
ANN static void gwfmt_stmt(Gwfmt *a, const Stmt* b);
ANN /*static */void gwfmt_arg_list(Gwfmt *a, const ArgList *b, const bool);
ANN static void gwfmt_variable_list(Gwfmt *a, const VariableList *b);
ANN static void gwfmt_stmt_list(Gwfmt *a, const StmtList *b);
ANN static void gwfmt_func_base(Gwfmt *a, const Func_Base *b);
ANN static void gwfmt_section(Gwfmt *a, const Section *b);
2 changes: 1 addition & 1 deletion src/gwion_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static bool init_gwion(Gwion gwion) {
}

static bool run(Gwion gwion, const char *filename) {
const bool ret = compile_filename(gwion, filename);
const bool ret = compile_filename(gwion, filename, NULL);
if(ret)
vm_force_run(gwion->vm);
return ret;
Expand Down
Loading

0 comments on commit 618c2c8

Please sign in to comment.