diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..195424b --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +# Flags +CC = emcc +JSFLAGS += -Oz -s "EXTRA_EXPORTED_RUNTIME_METHODS=['lengthBytesUTF8','stringToUTF8']" -s "EXPORTED_FUNCTIONS=['_malloc','_free']" -s WASM=1 -s EXIT_RUNTIME=1 +CFLAGS += $(JSFLAGS) -std=gnu99 -Wall -pedantic +LFLAGS += -lm + +.PHONY: all +all: webdice.js + +webdice.js: js-api.c expression.o lex.yy.o parser.tab.o + $(CC) $^ $(CFLAGS) -o $@ $(LFLAGS) + +lex.yy.c lex.yy.h: lexer.l parser.tab.h expression.h + flex --header-file=lex.yy.h $< + +parser.tab.c parser.tab.h: parser.y expression.h + bison -d $< + +%.o: %.c + $(CC) $(CFLAGS) -c $< + +.PHONY: clean +clean: + rm -rf *.o {lex.yy,parser.tab}.{c,h} webdice.js diff --git a/expression.c b/expression.c index e5c353f..a79606d 100644 --- a/expression.c +++ b/expression.c @@ -68,7 +68,7 @@ struct expression_result resolve(union expression* root){ result.expected = (*root).constant.value; result.actual = (*root).constant.value; result.text = (char*) malloc(length * sizeof(char)); - sprintf(result.text, "%d",(*root).constant.value); + sprintf(result.text, "%lld",(*root).constant.value); break; case WEBDICE_ROLL: size = (*root).roll.count * ceill(15+log10l((*root).roll.count * (*root).roll.type)); @@ -82,11 +82,11 @@ struct expression_result resolve(union expression* root){ values[i] = 1 + (rand() % (*root).roll.type); total += values[i]; if (i == 0){ - sprintf(result.text,"%d", result.text, values[i], total); + sprintf(result.text,"%s%lld\">%lld", result.text, values[i], total); }else{ - sprintf(result.text,"%s%d,", result.text, values[i]); + sprintf(result.text,"%s%lld,", result.text, values[i]); } } free(values); diff --git a/index.html b/index.html new file mode 100644 index 0000000..728dd3a --- /dev/null +++ b/index.html @@ -0,0 +1,24 @@ + +
+ + + + + + + + + diff --git a/js-api.c b/js-api.c new file mode 100644 index 0000000..5d68901 --- /dev/null +++ b/js-api.c @@ -0,0 +1,50 @@ +#include "emscripten.h" +#include%s = %Lf
", result.text, result.min, result.expected, result.max, result.actual); + + output_print(out_block); + + free(out_block); + }else{ + output_print("Error!
"); + } + yylex_destroy(scanner); +} diff --git a/lexer.l b/lexer.l index 62489f5..db80f53 100644 --- a/lexer.l +++ b/lexer.l @@ -3,27 +3,34 @@ #include