aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Howard <yzena.tech@gmail.com>2021-03-31 11:17:36 -0600
committerGavin Howard <yzena.tech@gmail.com>2021-03-31 11:17:36 -0600
commitec26fd2f11e7676d65d62097fef26cb6eb57f7c8 (patch)
treebbc51cc46d6ae7eb70da8b58f11d57f07faa36fe
parent7378a7abe1ec13adbb01212dff12346f2eff003d (diff)
downloadbc-ec26fd2f11e7676d65d62097fef26cb6eb57f7c8.tar.gz
Fix a lot of compile errors from the changes in last commit
-rw-r--r--include/file.h15
-rw-r--r--include/vm.h4
-rw-r--r--src/data.c2
-rw-r--r--src/file.c29
-rw-r--r--src/history.c4
-rw-r--r--src/num.c19
-rw-r--r--src/program.c8
-rw-r--r--src/vm.c14
8 files changed, 57 insertions, 38 deletions
diff --git a/include/file.h b/include/file.h
index 95d1f643..fbd4b9b9 100644
--- a/include/file.h
+++ b/include/file.h
@@ -51,6 +51,7 @@ typedef struct BcFile {
} BcFile;
+#if BC_ENABLE_HISTORY
typedef enum BcFlushType {
BC_FLUSH_NO_EXTRAS_NO_CLEAR,
@@ -59,6 +60,13 @@ typedef enum BcFlushType {
BC_FLUSH_SAVE_EXTRAS_CLEAR,
} BcFlushType;
+#else // BC_ENABLE_HISTORY
+#define bc_file_putchar(f, t, c) bc_file_putchar(f, c)
+#define bc_file_flushErr(f, t) bc_file_flushErr(f)
+#define bc_file_flush(f, t) bc_file_flush(f)
+#define bc_file_write(f, t, b, n) bc_file_write(f, b, n)
+#define bc_file_puts(f, t, s) bc_file_puts(f, s)
+#endif // BC_ENABLE_HISTORY
void bc_file_init(BcFile *f, int fd, char *buf, size_t cap);
void bc_file_free(BcFile *f);
@@ -68,13 +76,14 @@ BcStatus bc_file_flushErr(BcFile *restrict f, BcFlushType type);
void bc_file_flush(BcFile *restrict f, BcFlushType type);
void bc_file_write(BcFile *restrict f, BcFlushType type,
const char *buf, size_t n);
-void bc_file_printf(BcFile *restrict f, BcFlushType type, const char *fmt, ...);
-void bc_file_vprintf(BcFile *restrict f, BcFlushType type,
- const char *fmt, va_list args);
+void bc_file_printf(BcFile *restrict f, const char *fmt, ...);
+void bc_file_vprintf(BcFile *restrict f, const char *fmt, va_list args);
void bc_file_puts(BcFile *restrict f, BcFlushType type, const char *str);
+#if BC_ENABLE_HISTORY
extern const BcFlushType bc_flush_none;
extern const BcFlushType bc_flush_err;
extern const BcFlushType bc_flush_save;
+#endif // BC_ENABLE_HISTORY
#endif // BC_FILE_H
diff --git a/include/vm.h b/include/vm.h
index 23844d4b..8a949c3d 100644
--- a/include/vm.h
+++ b/include/vm.h
@@ -423,6 +423,10 @@ void bc_vm_init(void);
void bc_vm_shutdown(void);
void bc_vm_freeTemps(void);
+#if !BC_ENABLE_HISTORY
+#define bc_vm_putchar(c, t) bc_vm_putchar(c)
+#endif // !BC_ENABLE_HISTORY
+
void bc_vm_printf(const char *fmt, ...);
void bc_vm_putchar(int c, BcFlushType type);
size_t bc_vm_arraySize(size_t n, size_t size);
diff --git a/src/data.c b/src/data.c
index 993c8937..7611d4f0 100644
--- a/src/data.c
+++ b/src/data.c
@@ -172,9 +172,11 @@ const char* const bc_err_msgs[] = {
};
+#if BC_ENABLE_HISTORY
const BcFlushType bc_flush_none = BC_FLUSH_NO_EXTRAS_NO_CLEAR;
const BcFlushType bc_flush_err = BC_FLUSH_NO_EXTRAS_CLEAR;
const BcFlushType bc_flush_save = BC_FLUSH_SAVE_EXTRAS_CLEAR;
+#endif // BC_ENABLE_HISTORY
#if BC_ENABLE_HISTORY
const char *bc_history_bad_terms[] = { "dumb", "cons25", "emacs", NULL };
diff --git a/src/file.c b/src/file.c
index 7175d791..aa5307b9 100644
--- a/src/file.c
+++ b/src/file.c
@@ -88,6 +88,7 @@ BcStatus bc_file_flushErr(BcFile *restrict f, BcFlushType type)
if (f->len) {
+#if BC_ENABLE_HISTORY
if (f->buf[f->len - 1] != '\n' &&
(type == BC_FLUSH_SAVE_EXTRAS_CLEAR ||
type == BC_FLUSH_SAVE_EXTRAS_NO_CLEAR))
@@ -102,6 +103,7 @@ BcStatus bc_file_flushErr(BcFile *restrict f, BcFlushType type)
}
else if (type >= BC_FLUSH_NO_EXTRAS_CLEAR)
bc_vec_popAll(&vm.history.extras);
+#endif // BC_ENABLE_HISTORY
s = bc_file_output(f->fd, f->buf, f->len);
f->len = 0;
@@ -140,18 +142,17 @@ void bc_file_write(BcFile *restrict f, BcFlushType type,
}
}
-void bc_file_printf(BcFile *restrict f, BcFlushType type, const char *fmt, ...)
+void bc_file_printf(BcFile *restrict f, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
- bc_file_vprintf(f, type, fmt, args);
+ bc_file_vprintf(f, fmt, args);
va_end(args);
}
-void bc_file_vprintf(BcFile *restrict f, BcFlushType type,
- const char *fmt, va_list args)
-{
+void bc_file_vprintf(BcFile *restrict f, const char *fmt, va_list args) {
+
char *percent;
const char *ptr = fmt;
char buf[BC_FILE_ULL_LENGTH];
@@ -162,7 +163,7 @@ void bc_file_vprintf(BcFile *restrict f, BcFlushType type,
if (percent != ptr) {
size_t len = (size_t) (percent - ptr);
- bc_file_write(f, type, ptr, len);
+ bc_file_write(f, bc_flush_none, ptr, len);
}
c = percent[1];
@@ -171,13 +172,13 @@ void bc_file_vprintf(BcFile *restrict f, BcFlushType type,
uchar uc = (uchar) va_arg(args, int);
- bc_file_putchar(f, type, uc);
+ bc_file_putchar(f, bc_flush_none, uc);
}
else if (c == 's') {
char *s = va_arg(args, char*);
- bc_file_puts(f, type, s);
+ bc_file_puts(f, bc_flush_none, s);
}
#if BC_DEBUG_CODE
else if (c == 'd') {
@@ -185,14 +186,14 @@ void bc_file_vprintf(BcFile *restrict f, BcFlushType type,
int d = va_arg(args, int);
if (d < 0) {
- bc_file_putchar(f, '-');
+ bc_file_putchar(f, bc_flush_none, '-');
d = -d;
}
- if (!d) bc_file_putchar(f, '0');
+ if (!d) bc_file_putchar(f, bc_flush_none, '0');
else {
bc_file_ultoa((unsigned long long) d, buf);
- bc_file_puts(f, buf);
+ bc_file_puts(f, bc_flush_none, buf);
}
}
#endif // BC_DEBUG_CODE
@@ -205,17 +206,17 @@ void bc_file_vprintf(BcFile *restrict f, BcFlushType type,
if (c == 'z') ull = (unsigned long long) va_arg(args, size_t);
else ull = (unsigned long long) va_arg(args, unsigned long);
- if (!ull) bc_file_putchar(f, type, '0');
+ if (!ull) bc_file_putchar(f, bc_flush_none, '0');
else {
bc_file_ultoa(ull, buf);
- bc_file_puts(f, type, buf);
+ bc_file_puts(f, bc_flush_none, buf);
}
}
ptr = percent + 2 + (c == 'l' || c == 'z');
}
- if (ptr[0]) bc_file_puts(f, type, ptr);
+ if (ptr[0]) bc_file_puts(f, bc_flush_none, ptr);
}
void bc_file_puts(BcFile *restrict f, BcFlushType type, const char *str) {
diff --git a/src/history.c b/src/history.c
index 8acf2cc9..c0d54fe3 100644
--- a/src/history.c
+++ b/src/history.c
@@ -563,7 +563,7 @@ static size_t bc_history_columns(void) {
// Restore position.
if (cols > start) {
- bc_file_printf(&vm.fout, bc_flush_none, "\x1b[%zuD", cols - start);
+ bc_file_printf(&vm.fout, "\x1b[%zuD", cols - start);
bc_file_flush(&vm.fout, bc_flush_none);
}
@@ -670,7 +670,7 @@ static void bc_history_refresh(BcHistory *h) {
// Move cursor to original position.
colpos = bc_history_colPos(buf, len, pos) + h->pcol;
- if (colpos) bc_file_printf(&vm.fout, bc_flush_none, "\r\x1b[%zuC", colpos);
+ if (colpos) bc_file_printf(&vm.fout, "\r\x1b[%zuC", colpos);
bc_file_flush(&vm.fout, bc_flush_none);
}
diff --git a/src/num.c b/src/num.c
index a7ab282a..2bf93c15 100644
--- a/src/num.c
+++ b/src/num.c
@@ -2908,11 +2908,11 @@ err:
#if BC_DEBUG_CODE
void bc_num_printDebug(const BcNum *n, const char *name, bool emptyline) {
- bc_file_puts(&vm.fout, name);
- bc_file_puts(&vm.fout, ": ");
+ bc_file_puts(&vm.fout, bc_flush_none, name);
+ bc_file_puts(&vm.fout, bc_flush_none, ": ");
bc_num_printDecimal(n);
- bc_file_putchar(&vm.fout, '\n');
- if (emptyline) bc_file_putchar(&vm.fout, '\n');
+ bc_file_putchar(&vm.fout, bc_flush_err, '\n');
+ if (emptyline) bc_file_putchar(&vm.fout, bc_flush_err, '\n');
vm.nchars = 0;
}
@@ -2923,13 +2923,13 @@ void bc_num_printDigs(const BcDig *n, size_t len, bool emptyline) {
for (i = len - 1; i < len; --i)
bc_file_printf(&vm.fout, " %lu", (unsigned long) n[i]);
- bc_file_putchar(&vm.fout, '\n');
- if (emptyline) bc_file_putchar(&vm.fout, '\n');
+ bc_file_putchar(&vm.fout, bc_flush_err, '\n');
+ if (emptyline) bc_file_putchar(&vm.fout, bc_flush_err, '\n');
vm.nchars = 0;
}
void bc_num_printWithDigs(const BcNum *n, const char *name, bool emptyline) {
- bc_file_puts(&vm.fout, name);
+ bc_file_puts(&vm.fout, bc_flush_none, name);
bc_file_printf(&vm.fout, " len: %zu, rdx: %zu, scale: %zu\n",
name, n->len, BC_NUM_RDX_VAL(n), n->scale);
bc_num_printDigs(n->num, n->len, emptyline);
@@ -2944,7 +2944,8 @@ void bc_num_dump(const char *varname, const BcNum *n) {
for (i = n->len - 1; i < n->len; --i) {
- if (i + 1 == BC_NUM_RDX_VAL(n)) bc_file_puts(&vm.ferr, ". ");
+ if (i + 1 == BC_NUM_RDX_VAL(n))
+ bc_file_puts(&vm.ferr, bc_flush_none, ". ");
if (scale / BC_BASE_DIGS != BC_NUM_RDX_VAL(n) - i - 1)
bc_file_printf(&vm.ferr, "%lu ", (unsigned long) n->num[i]);
@@ -2967,5 +2968,7 @@ void bc_num_dump(const char *varname, const BcNum *n) {
bc_file_printf(&vm.ferr, "(%zu | %zu.%zu / %zu) %lu\n",
n->scale, n->len, BC_NUM_RDX_VAL(n), n->cap,
(unsigned long) (void*) n->num);
+
+ bc_file_flush(&vm.ferr, bc_flush_err);
}
#endif // BC_DEBUG_CODE
diff --git a/src/program.c b/src/program.c
index 5e65804d..91989bf4 100644
--- a/src/program.c
+++ b/src/program.c
@@ -2268,9 +2268,9 @@ void bc_program_exec(BcProgram *p) {
#if BC_DEBUG_CODE
#if BC_ENABLED && DC_ENABLED
void bc_program_printStackDebug(BcProgram *p) {
- bc_file_puts(&vm.fout, "-------------- Stack ----------\n");
+ bc_file_puts(&vm.fout, bc_flush_err, "-------------- Stack ----------\n");
bc_program_printStack(p);
- bc_file_puts(&vm.fout, "-------------- Stack End ------\n");
+ bc_file_puts(&vm.fout, bc_flush_err, "-------------- Stack End ------\n");
}
static void bc_program_printIndex(const char *restrict code,
@@ -2324,7 +2324,7 @@ void bc_program_printInst(const BcProgram *p, const char *restrict code,
if (inst == BC_INST_CALL) bc_program_printIndex(code, bgn);
}
- bc_vm_putchar('\n');
+ bc_vm_putchar('\n', bc_flush_err);
}
void bc_program_code(const BcProgram* p) {
@@ -2344,7 +2344,7 @@ void bc_program_code(const BcProgram* p) {
bc_vm_printf("func[%zu]:\n", ip.func);
while (ip.idx < f->code.len) bc_program_printInst(p, code, &ip.idx);
- bc_file_puts(&vm.fout, "\n\n");
+ bc_file_puts(&vm.fout, bc_flush_err, "\n\n");
}
}
#endif // BC_ENABLED && DC_ENABLED
diff --git a/src/vm.c b/src/vm.c
index 942cbbc6..0d2a0bf2 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -76,9 +76,9 @@ BC_NORETURN void bc_vm_jmp(void) {
BC_SIG_MAYLOCK;
#if BC_DEBUG_CODE
- bc_file_puts(&vm.ferr, "Longjmp: ");
- bc_file_puts(&vm.ferr, f);
- bc_file_putchar(&vm.ferr, '\n');
+ bc_file_puts(&vm.ferr, bc_flush_none, "Longjmp: ");
+ bc_file_puts(&vm.ferr, bc_flush_none, f);
+ bc_file_putchar(&vm.ferr, bc_flush_none, '\n');
bc_file_flush(&vm.ferr, bc_flush_none);
#endif // BC_DEBUG_CODE
@@ -131,7 +131,7 @@ void bc_vm_info(const char* const help) {
if (help) {
bc_file_putchar(&vm.fout, bc_flush_none, '\n');
- bc_file_printf(&vm.fout, bc_flush_none, help, vm.name, vm.name);
+ bc_file_printf(&vm.fout, help, vm.name, vm.name);
}
bc_file_flush(&vm.fout, bc_flush_err);
@@ -203,7 +203,7 @@ void bc_vm_handleError(BcErr e, size_t line, ...) {
bc_file_putchar(&vm.ferr, bc_flush_none, '\n');
bc_file_puts(&vm.ferr, bc_flush_none, err_type);
bc_file_putchar(&vm.ferr, bc_flush_none, ' ');
- bc_file_vprintf(&vm.ferr, bc_flush_none, vm.err_msgs[e], args);
+ bc_file_vprintf(&vm.ferr, vm.err_msgs[e], args);
va_end(args);
if (BC_NO_ERR(vm.file)) {
@@ -213,7 +213,7 @@ void bc_vm_handleError(BcErr e, size_t line, ...) {
if (line) {
bc_file_puts(&vm.ferr, bc_flush_none, "\n ");
bc_file_puts(&vm.ferr, bc_flush_none, vm.file);
- bc_file_printf(&vm.ferr, bc_flush_none, bc_err_line, line);
+ bc_file_printf(&vm.ferr, bc_err_line, line);
}
else {
@@ -446,7 +446,7 @@ void bc_vm_printf(const char *fmt, ...) {
BC_SIG_LOCK;
va_start(args, fmt);
- bc_file_vprintf(&vm.fout, bc_flush_none, fmt, args);
+ bc_file_vprintf(&vm.fout, fmt, args);
va_end(args);
vm.nchars = 0;