Turn on -Weverything and eliminate all warnings
diff --git a/Makefile.in b/Makefile.in
index 76a19aa..987809e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -122,17 +122,17 @@
$(HOSTCC) $(CFLAGS) -o $(GEN_EXEC) $(GEN_C)
$(BC_LIB_C): $(GEN_EXEC) $(BC_LIB)
- $(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc_lib_name $(BC_ENABLED_NAME) 1
+ $(GEN_EMU) $(GEN_EXEC) $(BC_LIB) $(BC_LIB_C) bc_lib bc.h bc_lib_name $(BC_ENABLED_NAME) 1
$(BC_LIB2_C): $(GEN_EXEC) $(BC_LIB2)
- $(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) bc_lib2 bc_lib2_name \
+ $(GEN_EMU) $(GEN_EXEC) $(BC_LIB2) $(BC_LIB2_C) bc_lib2 bc.h bc_lib2_name \
"$(BC_ENABLED_NAME) && $(BC_ENABLE_EXTRA_MATH_NAME)" 1
$(BC_HELP_C): $(GEN_EXEC) $(BC_HELP)
- $(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help "" $(BC_ENABLED_NAME)
+ $(GEN_EMU) $(GEN_EXEC) $(BC_HELP) $(BC_HELP_C) bc_help bc.h "" $(BC_ENABLED_NAME)
$(DC_HELP_C): $(GEN_EXEC) $(DC_HELP)
- $(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help "" $(DC_ENABLED_NAME)
+ $(GEN_EMU) $(GEN_EXEC) $(DC_HELP) $(DC_HELP_C) dc_help dc.h "" $(DC_ENABLED_NAME)
make_bin:
$(MKDIR) -p $(BIN)
diff --git a/gen/strgen.c b/gen/strgen.c
index 7af310d..e08951f 100644
--- a/gen/strgen.c
+++ b/gen/strgen.c
@@ -34,43 +34,45 @@
"// Licensed under the 0-clause BSD license.\n"
"// *** AUTOMATICALLY GENERATED FROM %s. DO NOT MODIFY. ***\n";
+static const char* const bc_gen_include = "#include <%s>\n\n";
static const char* const bc_gen_label = "const char *%s = \"%s\";\n\n";
static const char* const bc_gen_ifdef = "#if %s\n";
static const char* const bc_gen_endif = "#endif // %s\n";
static const char* const bc_gen_name = "const char %s[] = {\n";
#define INVALID_PARAMS (1)
-#define MALLOC_FAIL (2)
-#define INVALID_INPUT_FILE (3)
-#define INVALID_OUTPUT_FILE (4)
-#define INVALID_HEADER_FILE (5)
-#define IO_ERR (6)
+#define INVALID_INPUT_FILE (2)
+#define INVALID_OUTPUT_FILE (3)
+#define IO_ERR (4)
#define MAX_WIDTH (74)
int main(int argc, char *argv[]) {
FILE *in, *out;
- char *label, *define, *name;
+ char *label, *define, *name, *include;
int c, count, err, slashes;
bool has_label, has_define, remove_tabs;
err = 0;
- if (argc < 4) {
- printf("usage: gen input output name [label [define [remove_tabs]]]\n");
+ if (argc < 5) {
+ printf("usage: %s input output name header [label [define [remove_tabs]]]\n", argv[0]);
return INVALID_PARAMS;
}
name = argv[3];
+ include = argv[4];
- has_label = argc > 4 && strcmp("", argv[4]);
- label = has_label ? argv[4] : "";
+ printf("Header: %s\n", include);
- has_define = argc > 5 && strcmp("", argv[5]);
- define = has_define ? argv[5] : "";
+ has_label = argc > 5 && strcmp("", argv[5]);
+ label = has_label ? argv[5] : "";
- remove_tabs = argc > 6;
+ has_define = argc > 6 && strcmp("", argv[6]);
+ define = has_define ? argv[6] : "";
+
+ remove_tabs = argc > 7;
in = fopen(argv[1], "r");
@@ -93,6 +95,11 @@
goto error;
}
+ if (fprintf(out, bc_gen_include, include) < 0) {
+ err = IO_ERR;
+ goto error;
+ }
+
if (has_label && fprintf(out, bc_gen_label, label, argv[1]) < 0) {
err = IO_ERR;
goto error;
diff --git a/include/bc.h b/include/bc.h
index d8ee7e0..89563c0 100644
--- a/include/bc.h
+++ b/include/bc.h
@@ -37,6 +37,10 @@
int bc_main(int argc, char **argv);
extern const char bc_help[];
+extern const char bc_lib[];
+extern const char* bc_lib_name;
+extern const char bc_lib2[];
+extern const char* bc_lib2_name;
// ** Busybox exclude end. **
// ** Exclude end. **
@@ -109,7 +113,7 @@
((e5) << 3) | ((e6) << 2) | ((e7) << 1) | ((e8) << 0))
#define BC_PARSE_EXPR(i) \
- (bc_parse_exprs[(((i) & ~(0x07)) >> 3)] & (1 << (7 - ((i) & 0x07))))
+ (bc_parse_exprs[(((i) & (uchar) ~(0x07)) >> 3)] & (1 << (7 - ((i) & 0x07))))
#define BC_PARSE_TOP_OP(p) (*((BcLexType*) bc_vec_top(&(p)->ops)))
#define BC_PARSE_LEAF(prev, bin_last, rparen) \
@@ -132,11 +136,7 @@
// ** Exclude end. **
BcStatus bc_parse_parse(BcParse *p);
-
-BcStatus bc_parse_expr_error(BcParse *p, uint8_t flags, BcParseNext next);
BcStatus bc_parse_expr_status(BcParse *p, uint8_t flags, BcParseNext next);
-BcStatus bc_parse_else(BcParse *p);
-BcStatus bc_parse_stmt(BcParse *p);
#if BC_ENABLE_SIGNALS
extern const char bc_sig_msg[];
diff --git a/include/history.h b/include/history.h
index a5bb864..5fa3201 100644
--- a/include/history.h
+++ b/include/history.h
@@ -190,9 +190,9 @@
extern const char *bc_history_bad_terms[];
extern const char bc_history_ctrlc[];
-extern const unsigned long bc_history_wchars[][2];
+extern const uint32_t bc_history_wchars[][2];
extern const size_t bc_history_wchars_len;
-extern const unsigned long bc_history_combo_chars[];
+extern const uint32_t bc_history_combo_chars[];
extern const size_t bc_history_combo_chars_len;
#ifndef NDEBUG
extern FILE *bc_history_debug_fp;
diff --git a/include/num.h b/include/num.h
index 13936fc..0e6a0c7 100644
--- a/include/num.h
+++ b/include/num.h
@@ -114,9 +114,6 @@
BcNum *restrict base, size_t base_t, bool letter);
BcStatus bc_num_print(BcNum *restrict n, BcNum *restrict base,
size_t base_t, bool newline);
-#ifndef NDEBUG
-void bc_num_printDecimal(const BcNum *restrict n);
-#endif // NDEBUG
#if DC_ENABLED
BcStatus bc_num_stream(BcNum *restrict n, BcNum *restrict base);
#endif // DC_ENABLED
diff --git a/include/parse.h b/include/parse.h
index 80ecc17..2bec97c 100644
--- a/include/parse.h
+++ b/include/parse.h
@@ -94,7 +94,6 @@
void bc_parse_addId(BcParse *p, uchar inst);
void bc_parse_updateFunc(BcParse *p, size_t fidx);
-size_t bc_parse_addFunc(BcParse *p, char *name);
void bc_parse_pushName(BcParse* p, char *name);
void bc_parse_pushIndex(BcParse* p, size_t idx);
BcStatus bc_parse_text(BcParse *p, const char *text);
diff --git a/include/vm.h b/include/vm.h
index 01f857d..c554f87 100644
--- a/include/vm.h
+++ b/include/vm.h
@@ -154,7 +154,7 @@
// ** Exclude start. **
void bc_vm_info(const char* const help);
BcStatus bc_vm_boot(int argc, char *argv[], const char *env_len);
-void bc_vm_shutdown();
+void bc_vm_shutdown(void);
// ** Exclude end. **
// ** Busybox exclude start. **
@@ -189,7 +189,7 @@
extern const char* const bc_err_line;
extern const char *bc_errs[];
extern const char bc_err_ids[];
-extern const char *bc_err_msgs[];
+extern const char* const bc_err_msgs[];
// ** Exclude end. **
// ** Busybox exclude end. **
diff --git a/release.sh b/release.sh
index d1e7bd2..ff2d866 100755
--- a/release.sh
+++ b/release.sh
@@ -283,7 +283,9 @@
runtests "$minsize" "$CC" "$run_tests"
}
-cflags="-Wall -Wextra -pedantic -std=c99"
+cflags="-Weverything -Wno-padded -Wno-switch-enum -Wno-format-nonliteral"
+cflags="$cflags -Wno-cast-align -Wno-missing-noreturn -Wno-disabled-macro-expansion"
+cflags="$cflags -Wall -Wextra -pedantic -std=c99"
debug="$cflags -g -O0 -fno-omit-frame-pointer"
release="$cflags -DNDEBUG -O3"
diff --git a/src/args.c b/src/args.c
index 82a8db8..3d8d8c7 100644
--- a/src/args.c
+++ b/src/args.c
@@ -52,12 +52,12 @@
static const char* const bc_args_opt = "e:f:hilqsvVwx";
-void bc_args_exprs(BcVec *exprs, const char *str) {
+static void bc_args_exprs(BcVec *exprs, const char *str) {
bc_vec_concat(exprs, str);
bc_vec_concat(exprs, "\n");
}
-BcStatus bc_args_file(BcVec *exprs, const char *file) {
+static BcStatus bc_args_file(BcVec *exprs, const char *file) {
BcStatus s;
char *buf;
@@ -74,8 +74,7 @@
BcStatus bc_args(int argc, char *argv[]) {
BcStatus s = BC_STATUS_SUCCESS;
- int c, i;
- char err = 0;
+ int c, i, err = 0;
bool do_exit = false;
i = optind = 0;
@@ -176,7 +175,7 @@
if (err && !s) {
for (i = 0; bc_args_lopt[i].name; ++i) {
- if (bc_args_lopt[i].val == (int) err) break;
+ if (bc_args_lopt[i].val == err) break;
}
s = bc_vm_verr(BC_ERROR_VM_OPTION, err, bc_args_lopt[i].name);
diff --git a/src/bc/bc.c b/src/bc/bc.c
index 4f76077..1660267 100644
--- a/src/bc/bc.c
+++ b/src/bc/bc.c
@@ -30,17 +30,21 @@
int bc_main(int argc, char **argv) {
+ BcStatus s;
+
vm->read_ret = BC_INST_RET;
vm->help = bc_help;
#if BC_ENABLE_SIGNALS
vm->sig_msg = bc_sig_msg;
- vm->sig_len = strlen(vm->sig_msg);
+ vm->sig_len = (uchar) strlen(vm->sig_msg);
#endif // BC_ENABLE_SIGNALS
vm->next = bc_lex_token;
vm->parse = bc_parse_parse;
vm->expr = bc_parse_expr;
- return (int) bc_vm_boot(argc, argv, "BC_LINE_LENGTH");
+ s = bc_vm_boot(argc, argv, "BC_LINE_LENGTH");
+
+ return (int) s;
}
#endif // BC_ENABLED
diff --git a/src/bc/lex.c b/src/bc/lex.c
index 1b4a99a..c8d4a07 100644
--- a/src/bc/lex.c
+++ b/src/bc/lex.c
@@ -30,7 +30,7 @@
#include <bc.h>
#include <vm.h>
-BcStatus bc_lex_identifier(BcLex *l) {
+static BcStatus bc_lex_identifier(BcLex *l) {
BcStatus s;
size_t i;
@@ -64,7 +64,7 @@
return s;
}
-BcStatus bc_lex_string(BcLex *l) {
+static BcStatus bc_lex_string(BcLex *l) {
size_t len, nlines = 0, i = l->i;
const char *buf = l->buf;
@@ -92,7 +92,7 @@
return BC_STATUS_SUCCESS;
}
-void bc_lex_assign(BcLex *l, BcLexType with, BcLexType without) {
+static void bc_lex_assign(BcLex *l, BcLexType with, BcLexType without) {
if (l->buf[l->i] == '=') {
++l->i;
l->t = with;
diff --git a/src/bc/parse.c b/src/bc/parse.c
index 87ba60c..f65c917 100644
--- a/src/bc/parse.c
+++ b/src/bc/parse.c
@@ -32,7 +32,11 @@
#include <bc.h>
#include <vm.h>
-bool bc_parse_inst_isLeaf(BcInst t) {
+static BcStatus bc_parse_else(BcParse *p);
+static BcStatus bc_parse_stmt(BcParse *p);
+static BcStatus bc_parse_expr_err(BcParse *p, uint8_t flags, BcParseNext next);
+
+static bool bc_parse_inst_isLeaf(BcInst t) {
return (t >= BC_INST_NUM && t <= BC_INST_SQRT) ||
#if BC_ENABLE_EXTRA_MATH
t == BC_INST_TRUNC ||
@@ -40,7 +44,7 @@
t == BC_INST_INC_POST || t == BC_INST_DEC_POST;
}
-size_t bc_parse_addFunc(BcParse *p, char *name) {
+static size_t bc_parse_addFunc(BcParse *p, char *name) {
size_t idx = bc_program_insertFunc(p->prog, name);
@@ -50,7 +54,8 @@
return idx;
}
-void bc_parse_operator(BcParse *p, BcLexType type, size_t start, size_t *nexprs)
+static void bc_parse_operator(BcParse *p, BcLexType type,
+ size_t start, size_t *nexprs)
{
BcLexType t;
uchar l, r = BC_PARSE_OP_PREC(bc_parse_ops[type - BC_LEX_OP_INC]);
@@ -72,7 +77,7 @@
bc_vec_push(&p->ops, &type);
}
-BcStatus bc_parse_rightParen(BcParse *p, size_t ops_bgn, size_t *nexs) {
+static BcStatus bc_parse_rightParen(BcParse *p, size_t ops_bgn, size_t *nexs) {
BcLexType top;
@@ -93,7 +98,7 @@
return bc_lex_next(&p->l);
}
-BcStatus bc_parse_params(BcParse *p, uint8_t flags) {
+static BcStatus bc_parse_params(BcParse *p, uint8_t flags) {
BcStatus s;
bool comma = false;
@@ -122,7 +127,7 @@
return BC_STATUS_SUCCESS;
}
-BcStatus bc_parse_call(BcParse *p, char *name, uint8_t flags) {
+static BcStatus bc_parse_call(BcParse *p, char *name, uint8_t flags) {
BcStatus s;
BcId id, *id_ptr;
@@ -160,7 +165,7 @@
return s;
}
-BcStatus bc_parse_name(BcParse *p, BcInst *type, uint8_t flags) {
+static BcStatus bc_parse_name(BcParse *p, BcInst *type, uint8_t flags) {
BcStatus s;
char *name;
@@ -226,7 +231,7 @@
return s;
}
-BcStatus bc_parse_read(BcParse *p) {
+static BcStatus bc_parse_read(BcParse *p) {
BcStatus s;
@@ -243,8 +248,8 @@
return bc_lex_next(&p->l);
}
-BcStatus bc_parse_builtin(BcParse *p, BcLexType type,
- uint8_t flags, BcInst *prev)
+static BcStatus bc_parse_builtin(BcParse *p, BcLexType type,
+ uint8_t flags, BcInst *prev)
{
BcStatus s;
@@ -268,7 +273,7 @@
return bc_lex_next(&p->l);
}
-BcStatus bc_parse_scale(BcParse *p, BcInst *type, uint8_t flags) {
+static BcStatus bc_parse_scale(BcParse *p, BcInst *type, uint8_t flags) {
BcStatus s;
@@ -296,7 +301,8 @@
return bc_lex_next(&p->l);
}
-BcStatus bc_parse_incdec(BcParse *p, BcInst *prev, size_t *nexs, uint8_t flags)
+static BcStatus bc_parse_incdec(BcParse *p, BcInst *prev,
+ size_t *nexs, uint8_t flags)
{
BcStatus s;
BcLexType type;
@@ -364,8 +370,8 @@
return s;
}
-BcStatus bc_parse_minus(BcParse *p, BcInst *prev, size_t ops_bgn,
- bool rparen, bool bin_last, size_t *nexprs)
+static BcStatus bc_parse_minus(BcParse *p, BcInst *prev, size_t ops_bgn,
+ bool rparen, bool bin_last, size_t *nexprs)
{
BcStatus s;
BcLexType type;
@@ -384,13 +390,13 @@
return s;
}
-BcStatus bc_parse_str(BcParse *p, char inst) {
+static BcStatus bc_parse_str(BcParse *p, char inst) {
bc_parse_string(p);
bc_parse_push(p, inst);
return bc_lex_next(&p->l);
}
-BcStatus bc_parse_delimiter(BcParse *p) {
+static BcStatus bc_parse_delimiter(BcParse *p) {
BcStatus s = BC_STATUS_SUCCESS;
@@ -418,7 +424,7 @@
return s;
}
-BcStatus bc_parse_print(BcParse *p) {
+static BcStatus bc_parse_print(BcParse *p) {
BcStatus s;
BcLexType t;
@@ -452,7 +458,7 @@
return bc_parse_delimiter(p);
}
-BcStatus bc_parse_return(BcParse *p) {
+static BcStatus bc_parse_return(BcParse *p) {
BcStatus s;
BcLexType t;
@@ -472,7 +478,7 @@
if (BC_PARSE_VALID_END_TOKEN(t)) bc_parse_push(p, inst);
else {
- s = bc_parse_expr_error(p, 0, bc_parse_next_expr);
+ s = bc_parse_expr_err(p, 0, bc_parse_next_expr);
if (s && s != BC_STATUS_EMPTY_EXPR) return s;
else if (s == BC_STATUS_EMPTY_EXPR) {
bc_parse_push(p, inst);
@@ -493,7 +499,7 @@
return bc_parse_delimiter(p);
}
-BcStatus bc_parse_endBody(BcParse *p, bool brace) {
+static BcStatus bc_parse_endBody(BcParse *p, bool brace) {
BcStatus s = BC_STATUS_SUCCESS;
bool has_brace, new_else = false;
@@ -571,14 +577,14 @@
return s;
}
-void bc_parse_startBody(BcParse *p, uint16_t flags) {
+static void bc_parse_startBody(BcParse *p, uint16_t flags) {
assert(flags);
flags |= (BC_PARSE_TOP_FLAG(p) & (BC_PARSE_FLAG_FUNC | BC_PARSE_FLAG_LOOP));
flags |= BC_PARSE_FLAG_BODY;
bc_vec_push(&p->flags, &flags);
}
-void bc_parse_noElse(BcParse *p) {
+static void bc_parse_noElse(BcParse *p) {
BcInstPtr *ip;
size_t *label;
@@ -595,7 +601,7 @@
bc_vec_pop(&p->exits);
}
-BcStatus bc_parse_if(BcParse *p) {
+static BcStatus bc_parse_if(BcParse *p) {
BcStatus s;
BcInstPtr ip;
@@ -625,7 +631,7 @@
return BC_STATUS_SUCCESS;
}
-BcStatus bc_parse_else(BcParse *p) {
+static BcStatus bc_parse_else(BcParse *p) {
BcInstPtr ip;
@@ -646,7 +652,7 @@
return bc_lex_next(&p->l);
}
-BcStatus bc_parse_while(BcParse *p) {
+static BcStatus bc_parse_while(BcParse *p) {
BcStatus s;
BcInstPtr ip;
@@ -682,7 +688,7 @@
return BC_STATUS_SUCCESS;
}
-BcStatus bc_parse_for(BcParse *p) {
+static BcStatus bc_parse_for(BcParse *p) {
BcStatus s;
BcInstPtr ip;
@@ -766,7 +772,7 @@
return s;
}
-BcStatus bc_parse_loopExit(BcParse *p, BcLexType type) {
+static BcStatus bc_parse_loopExit(BcParse *p, BcLexType type) {
BcStatus s;
size_t i;
@@ -799,7 +805,7 @@
return bc_parse_delimiter(p);
}
-BcStatus bc_parse_func(BcParse *p) {
+static BcStatus bc_parse_func(BcParse *p) {
BcStatus s;
bool comma = false, voidfn;
@@ -909,7 +915,7 @@
return s;
}
-BcStatus bc_parse_auto(BcParse *p) {
+static BcStatus bc_parse_auto(BcParse *p) {
BcStatus s;
bool comma, one;
@@ -967,7 +973,7 @@
return s;
}
-BcStatus bc_parse_body(BcParse *p, bool brace) {
+static BcStatus bc_parse_body(BcParse *p, bool brace) {
BcStatus s = BC_STATUS_SUCCESS;
uint16_t *flag_ptr = BC_PARSE_TOP_FLAG_PTR(p);
@@ -1002,7 +1008,7 @@
return s;
}
-BcStatus bc_parse_stmt(BcParse *p) {
+static BcStatus bc_parse_stmt(BcParse *p) {
BcStatus s = BC_STATUS_SUCCESS;
@@ -1195,8 +1201,8 @@
return s;
}
-BcStatus bc_parse_expr_error(BcParse *p, uint8_t flags, BcParseNext next) {
-
+static BcStatus bc_parse_expr_err(BcParse *p, uint8_t flags, BcParseNext next)
+{
BcStatus s = BC_STATUS_SUCCESS;
BcInst prev = BC_INST_PRINT;
BcLexType top, t = p->l.t;
@@ -1489,7 +1495,7 @@
BcStatus bc_parse_expr_status(BcParse *p, uint8_t flags, BcParseNext next) {
- BcStatus s = bc_parse_expr_error(p, flags, next);
+ BcStatus s = bc_parse_expr_err(p, flags, next);
if (s == BC_STATUS_EMPTY_EXPR) s = bc_parse_err(p, BC_ERROR_PARSE_EMPTY_EXPR);
diff --git a/src/data.c b/src/data.c
index 5095957..0605430 100644
--- a/src/data.c
+++ b/src/data.c
@@ -20,11 +20,14 @@
*
*/
+#include <args.h>
#include <lex.h>
#include <parse.h>
#include <bc.h>
+#include <dc.h>
#include <num.h>
#include <program.h>
+#include <vm.h>
// clang-format off
diff --git a/src/dc/dc.c b/src/dc/dc.c
index fdbc490..9215938 100644
--- a/src/dc/dc.c
+++ b/src/dc/dc.c
@@ -30,17 +30,21 @@
int dc_main(int argc, char **argv) {
+ BcStatus s;
+
vm->read_ret = BC_INST_POP_EXEC;
vm->help = dc_help;
#if BC_ENABLE_SIGNALS
vm->sig_msg = dc_sig_msg;
- vm->sig_len = strlen(vm->sig_msg);
+ vm->sig_len = (uchar) strlen(vm->sig_msg);
#endif // BC_ENABLE_SIGNALS
vm->next = dc_lex_token;
vm->parse = dc_parse_parse;
vm->expr = dc_parse_expr;
- return (int) bc_vm_boot(argc, argv, "DC_LINE_LENGTH");
+ s = bc_vm_boot(argc, argv, "DC_LINE_LENGTH");
+
+ return (int) s;
}
#endif // DC_ENABLED
diff --git a/src/dc/lex.c b/src/dc/lex.c
index efce87c..3373a39 100644
--- a/src/dc/lex.c
+++ b/src/dc/lex.c
@@ -29,7 +29,7 @@
#include <dc.h>
#include <vm.h>
-BcStatus dc_lex_register(BcLex *l) {
+static BcStatus dc_lex_register(BcLex *l) {
BcStatus s = BC_STATUS_SUCCESS;
@@ -40,7 +40,7 @@
}
else {
bc_vec_npop(&l->str, l->str.len);
- bc_vec_pushByte(&l->str, l->buf[l->i - 1]);
+ bc_vec_pushByte(&l->str, (uchar) l->buf[l->i - 1]);
bc_vec_pushByte(&l->str, '\0');
l->t = BC_LEX_NAME;
}
@@ -48,7 +48,7 @@
return s;
}
-BcStatus dc_lex_string(BcLex *l) {
+static BcStatus dc_lex_string(BcLex *l) {
size_t depth = 1, nls = 0, i = l->i;
char c;
diff --git a/src/dc/parse.c b/src/dc/parse.c
index aec23e3..2b8bef8 100644
--- a/src/dc/parse.c
+++ b/src/dc/parse.c
@@ -32,7 +32,7 @@
#include <program.h>
#include <vm.h>
-BcStatus dc_parse_register(BcParse *p) {
+static BcStatus dc_parse_register(BcParse *p) {
BcStatus s;
@@ -45,7 +45,7 @@
return s;
}
-BcStatus dc_parse_string(BcParse *p) {
+static BcStatus dc_parse_string(BcParse *p) {
BcFunc f;
@@ -55,7 +55,7 @@
return bc_lex_next(&p->l);
}
-BcStatus dc_parse_mem(BcParse *p, uchar inst, bool name, bool store) {
+static BcStatus dc_parse_mem(BcParse *p, uchar inst, bool name, bool store) {
BcStatus s;
@@ -74,7 +74,7 @@
return bc_lex_next(&p->l);
}
-BcStatus dc_parse_cond(BcParse *p, uchar inst) {
+static BcStatus dc_parse_cond(BcParse *p, uchar inst) {
BcStatus s;
@@ -97,7 +97,7 @@
return s;
}
-BcStatus dc_parse_token(BcParse *p, BcLexType t, uint8_t flags) {
+static BcStatus dc_parse_token(BcParse *p, BcLexType t, uint8_t flags) {
BcStatus s = BC_STATUS_SUCCESS;
uchar inst;
@@ -112,7 +112,7 @@
case BC_LEX_OP_REL_LT:
case BC_LEX_OP_REL_GT:
{
- s = dc_parse_cond(p, t - BC_LEX_OP_REL_EQ + BC_INST_REL_EQ);
+ s = dc_parse_cond(p, (uchar) (t - BC_LEX_OP_REL_EQ + BC_INST_REL_EQ));
break;
}
@@ -177,7 +177,7 @@
case BC_LEX_STORE_OBASE:
case BC_LEX_STORE_SCALE:
{
- inst = t - BC_LEX_STORE_IBASE + BC_INST_IBASE;
+ inst = (uchar) (t - BC_LEX_STORE_IBASE + BC_INST_IBASE);
s = dc_parse_mem(p, inst, false, true);
break;
}
diff --git a/src/history/history.c b/src/history/history.c
index b11c05a..9492738 100644
--- a/src/history/history.c
+++ b/src/history/history.c
@@ -206,11 +206,11 @@
/**
* Convert UTF-8 to Unicode code point.
*/
-static size_t bc_history_codePoint(const char *s, size_t len, unsigned int *cp)
-{
+static size_t bc_history_codePoint(const char *s, size_t len, uint32_t *cp) {
+
if (len) {
- unsigned char byte = s[0];
+ uchar byte = (uchar) s[0];
if ((byte & 0x80) == 0) {
*cp = byte;
@@ -219,27 +219,27 @@
else if ((byte & 0xE0) == 0xC0) {
if (len >= 2) {
- *cp = (((unsigned long) (s[0] & 0x1F)) << 6) |
- ((unsigned long) (s[1] & 0x3F));
+ *cp = (((uint32_t) (s[0] & 0x1F)) << 6) |
+ ((uint32_t) (s[1] & 0x3F));
return 2;
}
}
else if ((byte & 0xF0) == 0xE0) {
if (len >= 3) {
- *cp = (((unsigned long) (s[0] & 0x0F)) << 12) |
- (((unsigned long) (s[1] & 0x3F)) << 6) |
- ((unsigned long) (s[2] & 0x3F));
+ *cp = (((uint32_t) (s[0] & 0x0F)) << 12) |
+ (((uint32_t) (s[1] & 0x3F)) << 6) |
+ ((uint32_t) (s[2] & 0x3F));
return 3;
}
}
else if ((byte & 0xF8) == 0xF0) {
if (len >= 4) {
- *cp = (((unsigned long) (s[0] & 0x07)) << 18) |
- (((unsigned long) (s[1] & 0x3F)) << 12) |
- (((unsigned long) (s[2] & 0x3F)) << 6) |
- ((unsigned long) (s[3] & 0x3F));
+ *cp = (((uint32_t) (s[0] & 0x07)) << 18) |
+ (((uint32_t) (s[1] & 0x3F)) << 12) |
+ (((uint32_t) (s[2] & 0x3F)) << 6) |
+ ((uint32_t) (s[3] & 0x3F));
return 4;
}
}
@@ -257,8 +257,8 @@
/**
* Get length of next grapheme.
*/
-size_t bc_history_nextLen(const char *buf, size_t buf_len,
- size_t pos, size_t *col_len)
+static size_t bc_history_nextLen(const char *buf, size_t buf_len,
+ size_t pos, size_t *col_len)
{
unsigned int cp;
size_t beg = pos;
@@ -288,8 +288,8 @@
/**
* Get length of previous grapheme.
*/
-size_t bc_history_prevLen(const char* buf, size_t pos, size_t *col_len)
-{
+static size_t bc_history_prevLen(const char *buf, size_t pos, size_t *col_len) {
+
size_t end = pos;
while (pos > 0) {
@@ -313,8 +313,8 @@
/**
* Read a Unicode code point from a file.
*/
-BcStatus bc_history_readCode(int fd, char *buf, size_t buf_len,
- unsigned int *cp, size_t *nread)
+static BcStatus bc_history_readCode(int fd, char *buf, size_t buf_len,
+ uint32_t *cp, size_t *nread)
{
BcStatus s = BC_STATUS_EOF;
ssize_t n;
@@ -324,7 +324,7 @@
n = read(fd, buf, 1);
if (n <= 0) goto err;
- unsigned char byte = buf[0];
+ uchar byte = (uchar) buf[0];
if ((byte & 0x80) != 0) {
@@ -355,7 +355,7 @@
err:
if (n < 0) s = bc_vm_err(BC_ERROR_VM_IO_ERR);
- else *nread = n;
+ else *nread = (size_t) n;
return s;
}
@@ -416,14 +416,14 @@
// Input modes: no break, no CR to NL, no parity check, no strip char,
// no start/stop output control.
- raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ raw.c_iflag &= (unsigned int) (~(BRKINT | ICRNL | INPCK | ISTRIP | IXON));
// Control modes - set 8 bit chars.
raw.c_cflag |= (CS8);
// Local modes - choing off, canonical off, no extended functions,
// no signal chars (^Z,^C).
- raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
+ raw.c_lflag &= (unsigned int) (~(ECHO | ICANON | IEXTEN | ISIG));
// Control chars - set return condition: min number of bytes and timer.
// We want read to give every single byte, w/o timeout (1 byte, no timer).
@@ -614,8 +614,9 @@
/**
* Insert the character 'c' at cursor current position.
*/
-BcStatus bc_history_edit_insert(BcHistory *h, const char *cbuf, size_t clen) {
-
+static BcStatus bc_history_edit_insert(BcHistory *h, const char *cbuf,
+ size_t clen)
+{
BcStatus s = BC_STATUS_SUCCESS;
bc_vec_expand(&h->buf, h->buf.len + clen);
@@ -661,7 +662,7 @@
/**
* Move cursor to the left.
*/
-BcStatus bc_history_edit_left(BcHistory *h) {
+static BcStatus bc_history_edit_left(BcHistory *h) {
if (h->pos <= 0) return BC_STATUS_SUCCESS;
@@ -673,7 +674,7 @@
/**
* Move cursor on the right.
*/
-BcStatus bc_history_edit_right(BcHistory *h) {
+static BcStatus bc_history_edit_right(BcHistory *h) {
if (h->pos == BC_HISTORY_BUF_LEN(h)) return BC_STATUS_SUCCESS;
@@ -685,7 +686,7 @@
/**
* Move cursor to the end of the current word.
*/
-BcStatus bc_history_edit_wordEnd(BcHistory *h) {
+static BcStatus bc_history_edit_wordEnd(BcHistory *h) {
size_t len = BC_HISTORY_BUF_LEN(h);
@@ -703,7 +704,7 @@
/**
* Move cursor to the start of the current word.
*/
-BcStatus bc_history_edit_wordStart(BcHistory *h) {
+static BcStatus bc_history_edit_wordStart(BcHistory *h) {
size_t len = BC_HISTORY_BUF_LEN(h);
@@ -723,7 +724,7 @@
/**
* Move cursor to the start of the line.
*/
-BcStatus bc_history_edit_home(BcHistory *h) {
+static BcStatus bc_history_edit_home(BcHistory *h) {
if (!h->pos) return BC_STATUS_SUCCESS;
@@ -735,7 +736,7 @@
/**
* Move cursor to the end of the line.
*/
-BcStatus bc_history_edit_end(BcHistory *h) {
+static BcStatus bc_history_edit_end(BcHistory *h) {
if (h->pos == BC_HISTORY_BUF_LEN(h)) return BC_STATUS_SUCCESS;
@@ -748,7 +749,7 @@
* Substitute the currently edited line with the next or previous history
* entry as specified by 'dir' (direction).
*/
-BcStatus bc_history_edit_next(BcHistory *h, bool dir) {
+static BcStatus bc_history_edit_next(BcHistory *h, bool dir) {
char* dup;
@@ -761,7 +762,7 @@
bc_vec_replaceAt(&h->history, h->history.len - 1 - h->idx, &dup);
// Show the new entry.
- h->idx += (dir == BC_HISTORY_PREV ? 1 : -1);
+ h->idx += (unsigned int) (dir == BC_HISTORY_PREV ? 1 : -1);
if (h->idx == SIZE_MAX) {
h->idx = 0;
@@ -784,7 +785,7 @@
* Delete the character at the right of the cursor without altering the cursor
* position. Basically this is what happens with the "Delete" keyboard key.
*/
-BcStatus bc_history_edit_delete(BcHistory *h) {
+static BcStatus bc_history_edit_delete(BcHistory *h) {
size_t chlen, len = BC_HISTORY_BUF_LEN(h);
@@ -800,7 +801,7 @@
return bc_history_refresh(h);
}
-BcStatus bc_history_edit_backspace(BcHistory *h) {
+static BcStatus bc_history_edit_backspace(BcHistory *h) {
size_t chlen, len = BC_HISTORY_BUF_LEN(h);
@@ -821,7 +822,7 @@
* Delete the previous word, maintaining the cursor at the start of the
* current word.
*/
-BcStatus bc_history_edit_deletePrevWord(BcHistory *h) {
+static BcStatus bc_history_edit_deletePrevWord(BcHistory *h) {
size_t diff, old_pos = h->pos;
@@ -839,7 +840,7 @@
/**
* Delete the next word, maintaining the cursor at the same position.
*/
-BcStatus bc_history_edit_deleteNextWord(BcHistory *h) {
+static BcStatus bc_history_edit_deleteNextWord(BcHistory *h) {
size_t next_end = h->pos, len = BC_HISTORY_BUF_LEN(h);
@@ -853,7 +854,7 @@
return bc_history_refresh(h);
}
-BcStatus bc_history_swap(BcHistory *h) {
+static BcStatus bc_history_swap(BcHistory *h) {
BcStatus s = BC_STATUS_SUCCESS;
size_t pcl, ncl;
@@ -1037,13 +1038,13 @@
return BC_STATUS_SUCCESS;
}
-static BcStatus bc_history_printCtrl(BcHistory *h, char c) {
+static BcStatus bc_history_printCtrl(BcHistory *h, unsigned int c) {
BcStatus s;
char str[3] = "^A";
const char newline[2] = "\n";
- str[1] = c + 'A' - 1;
+ str[1] = (char) (c + 'A' - BC_ACTION_CTRL_A);
bc_vec_concat(&h->buf, str);
diff --git a/src/main.c b/src/main.c
index f1ca8e9..39b235e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -41,7 +41,7 @@
setlocale(LC_ALL, "");
vm = calloc(1, sizeof(BcVm));
- if (!vm) return bc_vm_err(BC_ERROR_VM_ALLOC_ERR);
+ if (!vm) return (int) bc_vm_err(BC_ERROR_VM_ALLOC_ERR);
name = strrchr(argv[0], '/');
vm->name = !name ? argv[0] : name + 1;
diff --git a/src/num.c b/src/num.c
index 130e920..793134d 100644
--- a/src/num.c
+++ b/src/num.c
@@ -32,14 +32,14 @@
#include <num.h>
#include <vm.h>
-void bc_num_setToZero(BcNum *restrict n, size_t scale) {
+static void bc_num_setToZero(BcNum *restrict n, size_t scale) {
assert(n);
n->len = 0;
n->neg = false;
n->rdx = scale;
}
-void bc_num_zero(BcNum *restrict n) {
+static void bc_num_zero(BcNum *restrict n) {
bc_num_setToZero(n, 0);
}
@@ -57,13 +57,13 @@
n->num[1] = 1;
}
-size_t bc_num_log10(size_t i) {
+static size_t bc_num_log10(size_t i) {
size_t len;
for (len = 1; i; i /= 10, ++len);
return len;
}
-BcStatus bc_num_subArrays(BcDig *restrict a, const BcDig *restrict b, size_t len)
+static BcStatus bc_num_subArrays(BcDig *restrict a, const BcDig *restrict b, size_t len)
{
size_t i, j;
for (i = 0; !BC_SIGNAL && i < len; ++i) {
@@ -76,8 +76,7 @@
return BC_SIGNAL ? BC_STATUS_SIGNAL : BC_STATUS_SUCCESS;
}
-ssize_t bc_num_compare(const BcDig *restrict a, const BcDig *restrict b,
- size_t len)
+static ssize_t bc_num_compare(const BcDig *restrict a, const BcDig *restrict b, size_t len)
{
size_t i;
int c = 0;
@@ -147,7 +146,7 @@
}
}
-void bc_num_extend(BcNum *restrict n, size_t places) {
+static void bc_num_extend(BcNum *restrict n, size_t places) {
size_t len = n->len + places;
@@ -163,13 +162,13 @@
n->rdx += places;
}
-void bc_num_clean(BcNum *restrict n) {
+static void bc_num_clean(BcNum *restrict n) {
while (BC_NUM_NONZERO(n) && !n->num[n->len - 1]) --n->len;
if (BC_NUM_ZERO(n)) n->neg = false;
else if (n->len < n->rdx) n->len = n->rdx;
}
-void bc_num_retireMul(BcNum *restrict n, size_t scale, bool neg1, bool neg2) {
+static void bc_num_retireMul(BcNum *restrict n, size_t scale, bool neg1, bool neg2) {
if (n->rdx < scale) bc_num_extend(n, scale - n->rdx);
else bc_num_truncate(n, n->rdx - scale);
@@ -178,7 +177,7 @@
if (BC_NUM_NONZERO(n)) n->neg = (!neg1 != !neg2);
}
-void bc_num_split(const BcNum *restrict n, size_t idx, BcNum *restrict a, BcNum *restrict b) {
+static void bc_num_split(const BcNum *restrict n, size_t idx, BcNum *restrict a, BcNum *restrict b) {
if (idx < n->len) {
@@ -196,7 +195,7 @@
bc_num_clean(a);
}
-BcStatus bc_num_shift(BcNum *restrict n, size_t places) {
+static BcStatus bc_num_shift(BcNum *restrict n, size_t places) {
if (!places || BC_NUM_ZERO(n)) return BC_STATUS_SUCCESS;
if (places + n->len > BC_MAX_NUM)
@@ -213,7 +212,7 @@
return BC_STATUS_SUCCESS;
}
-BcStatus bc_num_inv(BcNum *a, BcNum *b, size_t scale) {
+static BcStatus bc_num_inv(BcNum *a, BcNum *b, size_t scale) {
BcNum one;
BcDig num[2];
@@ -226,8 +225,8 @@
}
#if BC_ENABLE_EXTRA_MATH
-BcStatus bc_num_intop(const BcNum *a, const BcNum *b, BcNum *restrict c,
- unsigned long *v)
+static BcStatus bc_num_intop(const BcNum *a, const BcNum *b, BcNum *restrict c,
+ unsigned long *v)
{
if (b->rdx) return bc_vm_err(BC_ERROR_MATH_NON_INTEGER);
bc_num_copy(c, a);
@@ -235,7 +234,7 @@
}
#endif // BC_ENABLE_EXTRA_MATH
-BcStatus bc_num_a(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub) {
+static BcStatus bc_num_a(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub) {
BcDig *ptr, *ptr_a, *ptr_b, *ptr_c;
size_t i, max, min_rdx, min_int, diff, a_int, b_int;
@@ -310,7 +309,7 @@
return BC_SIGNAL ? BC_STATUS_SIGNAL : BC_STATUS_SUCCESS;
}
-BcStatus bc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub) {
+static BcStatus bc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub) {
BcStatus s;
ssize_t cmp;
@@ -373,7 +372,7 @@
return s;
}
-BcStatus bc_num_k(const BcNum *a, const BcNum *b, BcNum *restrict c) {
+static BcStatus bc_num_k(const BcNum *a, const BcNum *b, BcNum *restrict c) {
BcStatus s;
size_t max = BC_MAX(a->len, b->len), max2 = (max + 1) / 2;
@@ -407,7 +406,7 @@
carry = 0;
for (j = 0; !BC_SIGNAL && j < a->len; ++j) {
- unsigned int in = c->num[i + j];
+ unsigned int in = (uchar) c->num[i + j];
in += ((unsigned int) a->num[j]) * ((unsigned int) b->num[i]);
in += carry;
carry = in / 10;
@@ -479,7 +478,7 @@
return s;
}
-BcStatus bc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
+static BcStatus bc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
BcStatus s;
BcNum cpa, cpb;
@@ -521,7 +520,7 @@
return s;
}
-BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
+static BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
BcStatus s = BC_STATUS_SUCCESS;
BcDig *n, *p, q;
@@ -585,8 +584,8 @@
return s;
}
-BcStatus bc_num_r(BcNum *a, BcNum *b, BcNum *restrict c,
- BcNum *restrict d, size_t scale, size_t ts)
+static BcStatus bc_num_r(BcNum *a, BcNum *b, BcNum *restrict c,
+ BcNum *restrict d, size_t scale, size_t ts)
{
BcStatus s;
BcNum temp;
@@ -620,7 +619,7 @@
return s;
}
-BcStatus bc_num_rem(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
+static BcStatus bc_num_rem(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
BcStatus s;
BcNum c1;
@@ -633,7 +632,7 @@
return s;
}
-BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
+static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
BcStatus s = BC_STATUS_SUCCESS;
BcNum copy;
@@ -717,7 +716,7 @@
}
#if BC_ENABLE_EXTRA_MATH
-BcStatus bc_num_place(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
+static BcStatus bc_num_place(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
BcStatus s = BC_STATUS_SUCCESS;
unsigned long val = 0;
@@ -733,7 +732,7 @@
return s;
}
-BcStatus bc_num_left(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
+static BcStatus bc_num_left(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
BcStatus s = BC_STATUS_SUCCESS;
unsigned long val = 0;
@@ -748,7 +747,7 @@
return s;
}
-BcStatus bc_num_right(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
+static BcStatus bc_num_right(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) {
BcStatus s = BC_STATUS_SUCCESS;
unsigned long val = 0;
@@ -778,8 +777,8 @@
}
#endif // BC_ENABLE_EXTRA_MATH
-BcStatus bc_num_binary(BcNum *a, BcNum *b, BcNum *c, size_t scale,
- BcNumBinaryOp op, size_t req)
+static BcStatus bc_num_binary(BcNum *a, BcNum *b, BcNum *c, size_t scale,
+ BcNumBinaryOp op, size_t req)
{
BcStatus s;
BcNum num2, *ptr_a, *ptr_b;
@@ -817,7 +816,7 @@
}
#ifndef NDEBUG
-bool bc_num_strValid(const char *val) {
+static bool bc_num_strValid(const char *val) {
bool radix = false;
size_t i, len = strlen(val);
@@ -843,7 +842,7 @@
}
#endif // NDEBUG
-unsigned long bc_num_parseChar(char c, size_t base_t) {
+static unsigned long bc_num_parseChar(char c, size_t base_t) {
if (isupper(c)) {
c = BC_NUM_NUM_LETTER(c);
@@ -854,7 +853,7 @@
return (unsigned long) (uchar) c;
}
-void bc_num_parseDecimal(BcNum *restrict n, const char *restrict val) {
+static void bc_num_parseDecimal(BcNum *restrict n, const char *restrict val) {
size_t len, i;
const char *ptr;
@@ -889,11 +888,12 @@
}
}
-BcStatus bc_num_parseBase(BcNum *restrict n, const char *restrict val, BcNum *restrict base, size_t base_t) {
-
- BcStatus s;
+static BcStatus bc_num_parseBase(BcNum *restrict n, const char *restrict val,
+ BcNum *restrict base, size_t base_t)
+{
+ BcStatus s = BC_STATUS_SUCCESS;
BcNum temp, mult, result;
- BcDig c;
+ BcDig c = 0;
bool zero = true;
unsigned long v;
size_t i, digits, len = strlen(val);
@@ -952,7 +952,7 @@
return s;
}
-void bc_num_printNewline() {
+static void bc_num_printNewline() {
if (vm->nchars >= (size_t) (vm->line_len - 1)) {
bc_vm_putchar('\\');
bc_vm_putchar('\n');
@@ -961,16 +961,15 @@
}
#if DC_ENABLED
-void bc_num_printChar(size_t n, size_t len, bool rdx)
-{
+static void bc_num_printChar(size_t n, size_t len, bool rdx) {
BC_UNUSED(rdx);
bc_vm_putchar((uchar) n);
vm->nchars += len;
}
#endif // DC_ENABLED
-void bc_num_printDigits(size_t n, size_t len, bool rdx)
-{
+static void bc_num_printDigits(size_t n, size_t len, bool rdx) {
+
size_t exp, pow;
bc_num_printNewline();
@@ -989,7 +988,7 @@
}
}
-void bc_num_printHex(size_t n, size_t len, bool rdx) {
+static void bc_num_printHex(size_t n, size_t len, bool rdx) {
assert(len == 1);
@@ -1004,7 +1003,7 @@
vm->nchars += len;
}
-void bc_num_printDecimal(const BcNum *restrict n) {
+static void bc_num_printDecimal(const BcNum *restrict n) {
size_t i, rdx = n->rdx - 1;
@@ -1015,7 +1014,8 @@
bc_num_printHex((size_t) n->num[i], 1, i == rdx);
}
-BcStatus bc_num_printNum(BcNum *restrict n, BcNum *restrict base, size_t len, BcNumDigitOp print)
+static BcStatus bc_num_printNum(BcNum *restrict n, BcNum *restrict base,
+ size_t len, BcNumDigitOp print)
{
BcStatus s;
BcVec stack;
@@ -1079,7 +1079,7 @@
return s;
}
-BcStatus bc_num_printBase(BcNum *restrict n, BcNum *restrict base, size_t base_t) {
+static BcStatus bc_num_printBase(BcNum *restrict n, BcNum *restrict base, size_t base_t) {
BcStatus s;
size_t width;
@@ -1279,7 +1279,7 @@
BcStatus bc_num_sqrt(BcNum *restrict a, BcNum *restrict b, size_t scale) {
- BcStatus s;
+ BcStatus s = BC_STATUS_SUCCESS;
BcNum num1, num2, half, f, fprime, *x0, *x1, *temp;
size_t pow, len, digs, digs1, resrdx, req, times = 0;
ssize_t cmp = 1, cmp1 = SSIZE_MAX, cmp2 = SSIZE_MAX;
diff --git a/src/program.c b/src/program.c
index 66665fd..9a8a4d2 100644
--- a/src/program.c
+++ b/src/program.c
@@ -41,12 +41,12 @@
}
#endif // BC_PROG_NO_STACK_CHECK
-BcStatus bc_program_type_num(BcResult *r, BcNum *n) {
+static BcStatus bc_program_type_num(BcResult *r, BcNum *n) {
if (!BC_PROG_NUM(r, n)) return bc_vm_err(BC_ERROR_EXEC_TYPE);
return BC_STATUS_SUCCESS;
}
-BcStatus bc_program_type_match(BcResult *r, BcType t) {
+static BcStatus bc_program_type_match(BcResult *r, BcType t) {
#if DC_ENABLED
if (r->t == BC_RESULT_STR) return bc_vm_err(BC_ERROR_EXEC_TYPE);
#endif // DC_ENABLED
@@ -54,7 +54,7 @@
return BC_STATUS_SUCCESS;
}
-char* bc_program_str(BcProgram *p, size_t idx, bool str) {
+static char* bc_program_str(BcProgram *p, size_t idx, bool str) {
BcFunc *f;
BcVec *v;
@@ -72,7 +72,7 @@
return *((char**) bc_vec_item(v, idx));
}
-size_t bc_program_index(const char *restrict code, size_t *restrict bgn) {
+static size_t bc_program_index(const char *restrict code, size_t *restrict bgn) {
uchar amt = (uchar) code[(*bgn)++], i = 0;
size_t res = 0;
@@ -85,7 +85,7 @@
return res;
}
-char* bc_program_name(const char *restrict code, size_t *restrict bgn) {
+static char* bc_program_name(const char *restrict code, size_t *restrict bgn) {
size_t i;
uchar c;
@@ -94,9 +94,10 @@
assert(ptr);
- s = bc_vm_malloc(ptr - str + 1);
+ s = bc_vm_malloc(((unsigned long) ptr) - ((unsigned long) str) + 1);
- for (i = 0; (c = code[(*bgn)++]) && c != BC_PARSE_STREND; ++i) s[i] = c;
+ for (i = 0; (c = (uchar) code[(*bgn)++]) && c != BC_PARSE_STREND; ++i)
+ s[i] = (char) c;
s[i] = '\0';
@@ -104,7 +105,7 @@
}
#if BC_ENABLE_REFERENCES
-BcVec* bc_program_dereference(BcProgram *p, BcVec *vec) {
+static BcVec* bc_program_dereference(BcProgram *p, BcVec *vec) {
BcVec *v;
size_t vidx, nidx, i = 0;
@@ -123,7 +124,7 @@
}
#endif // BC_ENABLE_REFERENCES
-BcVec* bc_program_search(BcProgram *p, char *id, BcType type) {
+static BcVec* bc_program_search(BcProgram *p, char *id, BcType type) {
BcId e, *ptr;
BcVec *v, *map;
@@ -149,7 +150,7 @@
return bc_vec_item(v, ptr->idx);
}
-BcStatus bc_program_num(BcProgram *p, BcResult *r, BcNum **num) {
+static BcStatus bc_program_num(BcProgram *p, BcResult *r, BcNum **num) {
BcStatus s = BC_STATUS_SUCCESS;
@@ -232,24 +233,15 @@
s = bc_vm_err(BC_ERROR_EXEC_VOID_VAL);
break;
}
-
#endif // BC_ENABLED
-#ifndef NDEBUG
- default:
- {
- bc_vm_shutdown();
- assert(false);
- exit(BC_STATUS_ERROR);
- break;
- }
-#endif // NDEBUG
}
return s;
}
-BcStatus bc_program_operand(BcProgram *p, BcResult **r, BcNum **n, size_t idx) {
-
+static BcStatus bc_program_operand(BcProgram *p, BcResult **r,
+ BcNum **n, size_t idx)
+{
#ifndef BC_PROG_NO_STACK_CHECK
BcStatus s = bc_program_checkStack(&p->results, idx + 1);
@@ -261,8 +253,8 @@
return bc_program_num(p, *r, n);
}
-BcStatus bc_program_binPrep(BcProgram *p, BcResult **l, BcNum **ln,
- BcResult **r, BcNum **rn)
+static BcStatus bc_program_binPrep(BcProgram *p, BcResult **l, BcNum **ln,
+ BcResult **r, BcNum **rn)
{
BcStatus s;
BcResultType lt;
@@ -290,8 +282,8 @@
return s;
}
-BcStatus bc_program_binOpPrep(BcProgram *p, BcResult **l, BcNum **ln,
- BcResult **r, BcNum **rn)
+static BcStatus bc_program_binOpPrep(BcProgram *p, BcResult **l, BcNum **ln,
+ BcResult **r, BcNum **rn)
{
BcStatus s;
@@ -304,8 +296,8 @@
return bc_program_type_num(*r, *rn);
}
-BcStatus bc_program_assignPrep(BcProgram *p, BcResult **l, BcNum **ln,
- BcResult **r, BcNum **rn)
+static BcStatus bc_program_assignPrep(BcProgram *p, BcResult **l, BcNum **ln,
+ BcResult **r, BcNum **rn)
{
BcStatus s;
bool good = false;
@@ -334,14 +326,14 @@
return s;
}
-void bc_program_binOpRetire(BcProgram *p, BcResult *r) {
+static void bc_program_binOpRetire(BcProgram *p, BcResult *r) {
r->t = BC_RESULT_TEMP;
bc_vec_pop(&p->results);
bc_vec_pop(&p->results);
bc_vec_push(&p->results, r);
}
-BcStatus bc_program_prep(BcProgram *p, BcResult **r, BcNum **n) {
+static BcStatus bc_program_prep(BcProgram *p, BcResult **r, BcNum **n) {
BcStatus s;
@@ -357,13 +349,13 @@
return bc_program_type_num(*r, *n);
}
-void bc_program_retire(BcProgram *p, BcResult *r, BcResultType t) {
+static void bc_program_retire(BcProgram *p, BcResult *r, BcResultType t) {
r->t = t;
bc_vec_pop(&p->results);
bc_vec_push(&p->results, r);
}
-BcStatus bc_program_op(BcProgram *p, uchar inst) {
+static BcStatus bc_program_op(BcProgram *p, uchar inst) {
BcStatus s;
BcResult *opd1, *opd2, res;
@@ -384,7 +376,7 @@
return s;
}
-BcStatus bc_program_read(BcProgram *p) {
+static BcStatus bc_program_read(BcProgram *p) {
BcStatus s;
BcParse parse;
@@ -441,14 +433,14 @@
return s;
}
-void bc_program_printChars(const char *str) {
+static void bc_program_printChars(const char *str) {
const char *nl;
vm->nchars += bc_vm_printf("%s", str);
nl = strrchr(str, '\n');
if (nl) vm->nchars = strlen(nl + 1);
}
-void bc_program_printString(const char *restrict str) {
+static void bc_program_printString(const char *restrict str) {
size_t i, len = strlen(str);
@@ -486,7 +478,7 @@
}
}
-BcStatus bc_program_print(BcProgram *p, uchar inst, size_t idx) {
+static BcStatus bc_program_print(BcProgram *p, uchar inst, size_t idx) {
BcStatus s = BC_STATUS_SUCCESS;
BcResult *r;
@@ -522,8 +514,9 @@
}
else {
- size_t idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : n->rdx;
- str = bc_program_str(p, idx, true);
+ size_t i = (r->t == BC_RESULT_STR) ? r->d.id.idx : n->rdx;
+
+ str = bc_program_str(p, i, true);
if (inst == BC_INST_PRINT_STR) bc_program_printChars(str);
else {
@@ -556,7 +549,7 @@
}
#endif // BC_ENABLE_EXTRA_MATH
-BcStatus bc_program_unary(BcProgram *p, uchar inst) {
+static BcStatus bc_program_unary(BcProgram *p, uchar inst) {
BcStatus s;
BcResult res, *ptr;
@@ -572,7 +565,7 @@
return s;
}
-BcStatus bc_program_logical(BcProgram *p, uchar inst) {
+static BcStatus bc_program_logical(BcProgram *p, uchar inst) {
BcStatus s;
BcResult *opd1, *opd2, res;
@@ -647,7 +640,7 @@
}
#if DC_ENABLED
-BcStatus bc_program_assignStr(BcProgram *p, BcResult *r, BcVec *v, bool push) {
+static BcStatus bc_program_assignStr(BcProgram *p, BcResult *r, BcVec *v, bool push) {
BcNum n2;
BcResult res;
@@ -674,8 +667,9 @@
}
#endif // DC_ENABLED
-BcStatus bc_program_copyToVar(BcProgram *p, char *name, BcType t, bool last) {
-
+static BcStatus bc_program_copyToVar(BcProgram *p, char *name,
+ BcType t, bool last)
+{
BcStatus s = BC_STATUS_SUCCESS;
BcResult *ptr, r;
BcVec *vec;
@@ -773,7 +767,7 @@
return s;
}
-BcStatus bc_program_assign(BcProgram *p, uchar inst) {
+static BcStatus bc_program_assign(BcProgram *p, uchar inst) {
BcStatus s;
BcResult *left, *right, res;
@@ -838,8 +832,8 @@
return s;
}
-BcStatus bc_program_pushVar(BcProgram *p, const char *restrict code,
- size_t *restrict bgn, bool pop, bool copy)
+static BcStatus bc_program_pushVar(BcProgram *p, const char *restrict code,
+ size_t *restrict bgn, bool pop, bool copy)
{
BcStatus s = BC_STATUS_SUCCESS;
BcResult r;
@@ -883,8 +877,8 @@
return s;
}
-BcStatus bc_program_pushArray(BcProgram *p, const char *restrict code,
- size_t *restrict bgn, uchar inst)
+static BcStatus bc_program_pushArray(BcProgram *p, const char *restrict code,
+ size_t *restrict bgn, uchar inst)
{
BcStatus s = BC_STATUS_SUCCESS;
BcResult r;
@@ -921,7 +915,7 @@
}
#if BC_ENABLED
-BcStatus bc_program_incdec(BcProgram *p, uchar inst) {
+static BcStatus bc_program_incdec(BcProgram *p, uchar inst) {
BcStatus s;
BcResult *ptr, res, copy;
@@ -952,8 +946,8 @@
return s;
}
-BcStatus bc_program_call(BcProgram *p, const char *restrict code,
- size_t *restrict idx)
+static BcStatus bc_program_call(BcProgram *p, const char *restrict code,
+ size_t *restrict idx)
{
BcStatus s = BC_STATUS_SUCCESS;
BcInstPtr ip;
@@ -1020,7 +1014,7 @@
return BC_STATUS_SUCCESS;
}
-BcStatus bc_program_return(BcProgram *p, uchar inst) {
+static BcStatus bc_program_return(BcProgram *p, uchar inst) {
BcStatus s;
BcResult res;
@@ -1085,7 +1079,7 @@
return len;
}
-BcStatus bc_program_builtin(BcProgram *p, uchar inst) {
+static BcStatus bc_program_builtin(BcProgram *p, uchar inst) {
BcStatus s;
BcResult *opnd;
@@ -1132,7 +1126,7 @@
}
#if DC_ENABLED
-BcStatus bc_program_divmod(BcProgram *p) {
+static BcStatus bc_program_divmod(BcProgram *p) {
BcStatus s;
BcResult *opd1, *opd2, res, res2;
@@ -1159,7 +1153,7 @@
return s;
}
-BcStatus bc_program_modexp(BcProgram *p) {
+static BcStatus bc_program_modexp(BcProgram *p) {
BcStatus s;
BcResult *r1, *r2, *r3, res;
@@ -1201,7 +1195,7 @@
return s;
}
-void bc_program_stackLen(BcProgram *p) {
+static void bc_program_stackLen(BcProgram *p) {
BcResult res;
size_t len = p->results.len;
@@ -1213,7 +1207,7 @@
bc_vec_push(&p->results, &res);
}
-BcStatus bc_program_asciify(BcProgram *p) {
+static BcStatus bc_program_asciify(BcProgram *p) {
BcStatus s;
BcResult *r, res;
@@ -1274,7 +1268,7 @@
return s;
}
-BcStatus bc_program_printStream(BcProgram *p) {
+static BcStatus bc_program_printStream(BcProgram *p) {
BcStatus s;
BcResult *r;
@@ -1292,7 +1286,7 @@
return s;
}
-BcStatus bc_program_nquit(BcProgram *p) {
+static BcStatus bc_program_nquit(BcProgram *p) {
BcStatus s;
BcResult *opnd;
@@ -1315,8 +1309,8 @@
return s;
}
-BcStatus bc_program_execStr(BcProgram *p, const char *restrict code,
- size_t *restrict bgn, bool cond)
+static BcStatus bc_program_execStr(BcProgram *p, const char *restrict code,
+ size_t *restrict bgn, bool cond)
{
BcStatus s = BC_STATUS_SUCCESS;
BcResult *r;
@@ -1333,7 +1327,9 @@
if (cond) {
- char *name, *then_name = bc_program_name(code, bgn), *else_name = NULL;
+ char *name = NULL, *then_name, *else_name = NULL;
+
+ then_name = bc_program_name(code, bgn);
if (((uchar) code[*bgn]) == BC_PARSE_STREND) (*bgn) += 1;
else else_name = bc_program_name(code, bgn);
@@ -1408,7 +1404,7 @@
}
#endif // DC_ENABLED
-void bc_program_pushGlobal(BcProgram *p, uchar inst) {
+static void bc_program_pushGlobal(BcProgram *p, uchar inst) {
BcResult res;
unsigned long val;
@@ -1568,6 +1564,9 @@
BcFunc *func = bc_vec_item(&p->fns, ip->func);
char *code = func->code.v;
bool cond = false;
+#if BC_ENABLED
+ BcNum *num;
+#endif // BC_ENABLED
while (!s && ip->idx < func->code.len) {
@@ -1576,8 +1575,6 @@
switch (inst) {
#if BC_ENABLED
- BcNum *num;
-
case BC_INST_JUMP_ZERO:
{
s = bc_program_prep(p, &ptr, &num);
@@ -1894,20 +1891,20 @@
#ifndef NDEBUG
#if BC_ENABLED && DC_ENABLED
-void bc_program_printIndex(const char *restrict code, size_t *restrict bgn) {
+static void bc_program_printIndex(const char *restrict code, size_t *restrict bgn) {
- uchar byte, i, bytes = code[(*bgn)++];
+ uchar byte, i, bytes = (uchar) code[(*bgn)++];
unsigned long val = 0;
for (byte = 1, i = 0; byte && i < bytes; ++i) {
- byte = code[(*bgn)++];
+ byte = (uchar) code[(*bgn)++];
if (byte) val |= ((unsigned long) byte) << (CHAR_BIT * i);
}
bc_vm_printf(" (%lu) ", val);
}
-void bc_program_printName(const char *restrict code, size_t *restrict bgn) {
+static void bc_program_printName(const char *restrict code, size_t *restrict bgn) {
uchar byte;
@@ -1921,7 +1918,7 @@
bc_vm_printf(") ");
}
-void bc_program_printStr(BcProgram *p, const char *restrict code,
+static void bc_program_printStr(BcProgram *p, const char *restrict code,
size_t *restrict bgn)
{
size_t idx = bc_program_index(code, bgn);
diff --git a/src/read.c b/src/read.c
index fa09a46..b8b5716 100644
--- a/src/read.c
+++ b/src/read.c
@@ -38,7 +38,7 @@
#include <program.h>
#include <vm.h>
-bool bc_read_binary(const char *buf, size_t size) {
+static bool bc_read_binary(const char *buf, size_t size) {
size_t i;
diff --git a/src/vector.c b/src/vector.c
index 50e4453..e372d37 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -29,7 +29,7 @@
#include <lang.h>
#include <vm.h>
-void bc_vec_grow(BcVec *restrict v, size_t n) {
+static void bc_vec_grow(BcVec *restrict v, size_t n) {
size_t cap = v->cap * 2;
while (cap < v->len + n) cap *= 2;
v->v = bc_vm_realloc(v->v, v->size * cap);
@@ -94,7 +94,7 @@
bc_vec_npush(v, amt, nums);
}
-void bc_vec_pushAt(BcVec *restrict v, const void *data, size_t idx) {
+static void bc_vec_pushAt(BcVec *restrict v, const void *data, size_t idx) {
assert(v && data && idx <= v->len);
@@ -184,7 +184,7 @@
free(v->v);
}
-size_t bc_map_find(const BcVec *restrict v, const BcId *restrict ptr) {
+static size_t bc_map_find(const BcVec *restrict v, const BcId *restrict ptr) {
size_t low = 0, high = v->len;
diff --git a/src/vm.c b/src/vm.c
index e3122a7..50f8479 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -50,7 +50,7 @@
#if BC_ENABLE_SIGNALS
#ifndef _WIN32
-void bc_vm_sig(int sig) {
+static void bc_vm_sig(int sig) {
int err = errno;
if (sig == SIGINT) {
size_t len = vm->sig_len;
@@ -60,7 +60,7 @@
errno = err;
}
#else // _WIN32
-BOOL WINAPI bc_vm_sig(DWORD sig) {
+static BOOL WINAPI bc_vm_sig(DWORD sig) {
if (sig == CTRL_C_EVENT) bc_vm_puts(vm->sig_msg, stderr);
vm->sig = (uchar) sig;
return TRUE;
@@ -74,8 +74,9 @@
if (help) bc_vm_printf(help, vm->name);
}
-void bc_vm_printError(BcError e, const char* const fmt, size_t line, va_list args) {
-
+static void bc_vm_printError(BcError e, const char* const fmt,
+ size_t line, va_list args)
+{
// Make sure all of stdout is written first.
fflush(stdout);
@@ -130,7 +131,7 @@
return (!!p) ? BC_STATUS_ERROR : BC_STATUS_SUCCESS;
}
-BcStatus bc_vm_envArgs() {
+static BcStatus bc_vm_envArgs(void) {
BcStatus s;
BcVec v;
@@ -165,7 +166,7 @@
}
#endif // BC_ENABLED
-size_t bc_vm_envLen(const char *var) {
+static size_t bc_vm_envLen(const char *var) {
char *lenv = getenv(var);
size_t i, len = BC_NUM_PRINT_WIDTH;
@@ -185,7 +186,7 @@
return len;
}
-void bc_vm_exit(BcError e) {
+static void bc_vm_exit(BcError e) {
BcStatus s = bc_vm_err(e);
bc_vm_shutdown();
exit((int) s);
@@ -235,7 +236,7 @@
if (fflush(f) == EOF || ferror(f)) bc_vm_exit(BC_ERROR_VM_IO_ERR);
}
-void bc_vm_clean() {
+static void bc_vm_clean() {
BcProgram *prog = &vm->prog;
BcVec *fns = &prog->fns;
@@ -285,7 +286,7 @@
}
}
-BcStatus bc_vm_process(const char *text, bool is_stdin) {
+static BcStatus bc_vm_process(const char *text, bool is_stdin) {
BcStatus s;
@@ -310,7 +311,7 @@
return s == BC_STATUS_QUIT || !BC_I || !is_stdin ? s : BC_STATUS_SUCCESS;
}
-BcStatus bc_vm_file(const char *file) {
+static BcStatus bc_vm_file(const char *file) {
BcStatus s;
char *data;
@@ -332,7 +333,7 @@
return s;
}
-BcStatus bc_vm_stdin() {
+static BcStatus bc_vm_stdin(void) {
BcStatus s = BC_STATUS_SUCCESS;
BcVec buf, buffer;
@@ -365,7 +366,7 @@
for (i = 0; i < len; ++i) {
bool notend = len > i + 1;
- uchar c = str[i];
+ uchar c = (uchar) str[i];
if (!comment && (i - 1 > len || str[i - 1] != '\\')) {
if (BC_IS_BC) string ^= c == '"';
@@ -417,7 +418,7 @@
}
#if BC_ENABLED
-BcStatus bc_vm_load(const char *name, const char *text) {
+static BcStatus bc_vm_load(const char *name, const char *text) {
BcStatus s;
@@ -430,7 +431,7 @@
}
#endif // BC_ENABLED
-BcStatus bc_vm_exec() {
+static BcStatus bc_vm_exec(void) {
BcStatus s = BC_STATUS_SUCCESS;
size_t i;
@@ -462,7 +463,7 @@
return s;
}
-void bc_vm_shutdown() {
+void bc_vm_shutdown(void) {
#if BC_ENABLE_HISTORY
// This must always run to ensure that the terminal is back to normal.
bc_history_free(&vm->history);
@@ -495,7 +496,7 @@
#endif // _WIN32
#endif // BC_ENABLE_SIGNALS
- vm->line_len = bc_vm_envLen(env_len);
+ vm->line_len = (uint16_t) bc_vm_envLen(env_len);
bc_vec_init(&vm->files, sizeof(char*), NULL);
bc_vec_init(&vm->exprs, sizeof(uchar), NULL);