From 856e443181b77c796947f78cd3a6f04c801a9db4 Mon Sep 17 00:00:00 2001 From: Scarlett Date: Fri, 2 May 2025 12:47:22 -0400 Subject: [PATCH] raaahhhhhh --- Makefile | 5 +++-- src/grammar.y | 2 +- src/intermediate_code.c | 5 +++++ src/runner.c | 2 +- tests/sprint1/test/sp1_simple_alpha.alpha | 6 ++++++ 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 tests/sprint1/test/sp1_simple_alpha.alpha diff --git a/Makefile b/Makefile index 6a8e88d..794b839 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ CC := gcc FLEX := flex BISON = bison -CFLAGS := -ggdb +CFLAGS := -ggdb -g -O0 #-fsanitize=address +# LDFLAGS := -fsanitize=address BISONFLAGS := -d -Wcounterexamples LEX := src/lexicalStructure.lex @@ -24,7 +25,7 @@ TESTS-S4 := $(wildcard tests/sprint4/test/*.alpha) all: compiler compiler: clean tmp $(OBJS) - $(CC) $(CFLAGS) -o $(EXE) $(OBJS) + $(CC) $(CFLAGS) -o $(EXE) $(OBJS) $(LDFLAGS) clean: rm -f $(EXE) diff --git a/src/grammar.y b/src/grammar.y index 8a287d2..20888a6 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -633,7 +633,7 @@ simple_statement: | RETURN expression { $$ = getTypeEntry((TableNode*)$2); emit_return(tn_or_const(NODE,(TableNode*)$2));} - |simple_statement error {yyerrok; printdebug("error in simple statement");} + |simple_statement error {yyerrok; yyclearin; printdebug("error in simple statement");} ; diff --git a/src/intermediate_code.c b/src/intermediate_code.c index aee5862..dc79abf 100644 --- a/src/intermediate_code.c +++ b/src/intermediate_code.c @@ -349,6 +349,11 @@ int label_gen(){ } void emit_as_file(FILE * out_file, Instruction * i){ + if (out_file == NULL){ + fprintf(stderr, "Error: output file is NULL\n"); + return; + } + if(i == NULL){ return; } diff --git a/src/runner.c b/src/runner.c index c134dc4..2616e01 100644 --- a/src/runner.c +++ b/src/runner.c @@ -192,7 +192,7 @@ int new_file(char *arg, char *alpha) { mkdir("./out", 0777); - char *new_basename = calloc(strlen(basename) + 5, sizeof(char)); + char *new_basename = calloc(strlen(basename) + 7, sizeof(char)); strcpy(new_basename, "./out/"); strcat(new_basename, basename); basename = new_basename; diff --git a/tests/sprint1/test/sp1_simple_alpha.alpha b/tests/sprint1/test/sp1_simple_alpha.alpha new file mode 100644 index 0000000..719384b --- /dev/null +++ b/tests/sprint1/test/sp1_simple_alpha.alpha @@ -0,0 +1,6 @@ +type main: string -> integer +function entry: main + +entry(arg) := { + return 0; +} \ No newline at end of file