diff --git a/src/dstr.c b/src/dstr.c index 48183d1..a65cb95 100644 --- a/src/dstr.c +++ b/src/dstr.c @@ -8,7 +8,7 @@ Dstr* dstr_init(void) { Dstr* dstr = malloc(sizeof(Dstr)); - dstr->bufsz = DSTR_INITSZ; + dstr->sz = DSTR_INITSZ; dstr->buf = malloc(DSTR_INITSZ); *dstr->buf = '\0'; dstr->ln = 0; @@ -23,13 +23,13 @@ void dstr_destroy(Dstr* dstr) { // Check whether the buffer is overflowing and resize it if necessary. void check_resz(Dstr* dstr, size_t ln) { - while (dstr->ln + ln + 1 > dstr->bufsz) { + while (dstr->ln + ln + 1 > dstr->sz) { // Double the buffer size when overflown. - dstr->bufsz *= 2; - dstr->buf = realloc(dstr->buf, dstr->bufsz); + dstr->sz *= 2; + dstr->buf = realloc(dstr->buf, dstr->sz); log_dbgf( - "dstr @ %p doubled from %ld to %ld", dstr, dstr->bufsz / 2, - dstr->bufsz + "dstr @ %p doubled from %ld to %ld", dstr, dstr->sz / 2, + dstr->sz ); } } diff --git a/src/exec.c b/src/exec.c index f251093..38b1831 100644 --- a/src/exec.c +++ b/src/exec.c @@ -8,7 +8,7 @@ extern AST* root; -ASTNumData exec_expr(AST* ast) { +ASTNumData exec_exp(AST* ast) { log_dbg("Started execution."); switch (ast->type) { case AST_TYPE_CALL: return exec_call(ast); @@ -23,42 +23,42 @@ ASTNumData exec_call(AST* ast) { ASTCallData* calldata = (ASTCallData*)ast->data; if (calldata->argc >= 1) { if (!strcmp(calldata->to, "sum")) { - double total = exec_expr(calldata->argv[0]); + double total = exec_exp(calldata->argv[0]); for ( size_t i = 1; i < calldata->argc; - total += exec_expr(calldata->argv[i++]) + total += exec_exp(calldata->argv[i++]) ); return total; } else if (!strcmp(calldata->to, "sub")) { - double total = exec_expr(calldata->argv[0]); + double total = exec_exp(calldata->argv[0]); for ( size_t i = 1; i < calldata->argc; - total -= exec_expr(calldata->argv[i++]) + total -= exec_exp(calldata->argv[i++]) ); return total; } else if (!strcmp(calldata->to, "mul")) { - double total = exec_expr(calldata->argv[0]); + double total = exec_exp(calldata->argv[0]); for ( size_t i = 1; i < calldata->argc; - total *= exec_expr(calldata->argv[i++]) + total *= exec_exp(calldata->argv[i++]) ); return total; } else if (!strcmp(calldata->to, "div")) { - double total = exec_expr(calldata->argv[0]); + double total = exec_exp(calldata->argv[0]); for ( size_t i = 1; i < calldata->argc; - total /= exec_expr(calldata->argv[i++]) + total /= exec_exp(calldata->argv[i++]) ); return total; diff --git a/src/grammar.y b/src/grammar.y index d34cf02..4e50a75 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -39,7 +39,6 @@ %left MULT DIV %precedence NEG -%type num; %type exp; %% diff --git a/src/include/dstr.h b/src/include/dstr.h index 2dfdb97..0fcfceb 100644 --- a/src/include/dstr.h +++ b/src/include/dstr.h @@ -7,7 +7,7 @@ typedef struct { char* buf; // The buffer containing the string. - size_t bufsz; // The size of the buffer. + size_t sz; // The size of the buffer. size_t ln; // The number of characters in the buffer. } Dstr; diff --git a/src/include/exec.h b/src/include/exec.h index 7848443..53ee7df 100644 --- a/src/include/exec.h +++ b/src/include/exec.h @@ -3,7 +3,7 @@ #include "ast.h" -ASTNumData exec_expr(AST* ast); +ASTNumData exec_exp(AST* ast); ASTNumData exec_call(AST* ast); void exec_print(double n); diff --git a/src/main.c b/src/main.c index a56a0ba..3596755 100644 --- a/src/main.c +++ b/src/main.c @@ -21,7 +21,7 @@ int main(int argc, char** argv) { if (argc - 1 && strlen(argv[1]) > 0 && (inp = argv[1]) && !yyparse()) { log_dbg("Parsed successfully!\n"); - exec_print(exec_expr(root)); + exec_print(exec_exp(root)); exit(0); } @@ -52,7 +52,7 @@ int main(int argc, char** argv) { log_dbg("Parsed successfully!\n"); } else printf("Parse error.\n"); - exec_print(exec_expr(root)); + exec_print(exec_exp(root)); #ifdef DBG ast_print(root); #endif