summaryrefslogtreecommitdiff
path: root/include/vm.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/vm.h')
-rw-r--r--include/vm.h59
1 files changed, 47 insertions, 12 deletions
diff --git a/include/vm.h b/include/vm.h
index 0ca20047b824a..7f4359c640d34 100644
--- a/include/vm.h
+++ b/include/vm.h
@@ -1,9 +1,9 @@
/*
* *****************************************************************************
*
- * Copyright (c) 2018-2020 Gavin D. Howard and contributors.
+ * SPDX-License-Identifier: BSD-2-Clause
*
- * All rights reserved.
+ * Copyright (c) 2018-2020 Gavin D. Howard and contributors.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -91,28 +91,64 @@
#define isatty _isatty
#endif // _WIN32
+#if DC_ENABLED
#define DC_FLAG_X (UINTMAX_C(1)<<0)
+#endif // DC_ENABLED
+
+#if BC_ENABLED
#define BC_FLAG_W (UINTMAX_C(1)<<1)
#define BC_FLAG_S (UINTMAX_C(1)<<2)
-#define BC_FLAG_Q (UINTMAX_C(1)<<3)
-#define BC_FLAG_L (UINTMAX_C(1)<<4)
-#define BC_FLAG_I (UINTMAX_C(1)<<5)
-#define BC_FLAG_G (UINTMAX_C(1)<<6)
+#define BC_FLAG_L (UINTMAX_C(1)<<3)
+#define BC_FLAG_G (UINTMAX_C(1)<<4)
+#endif // BC_ENABLED
+
+#define BC_FLAG_Q (UINTMAX_C(1)<<5)
+#define BC_FLAG_I (UINTMAX_C(1)<<6)
#define BC_FLAG_P (UINTMAX_C(1)<<7)
#define BC_FLAG_TTYIN (UINTMAX_C(1)<<8)
#define BC_FLAG_TTY (UINTMAX_C(1)<<9)
#define BC_TTYIN (vm.flags & BC_FLAG_TTYIN)
#define BC_TTY (vm.flags & BC_FLAG_TTY)
+#if BC_ENABLED
+
#define BC_S (BC_ENABLED && (vm.flags & BC_FLAG_S))
#define BC_W (BC_ENABLED && (vm.flags & BC_FLAG_W))
#define BC_L (BC_ENABLED && (vm.flags & BC_FLAG_L))
-#define BC_I (vm.flags & BC_FLAG_I)
#define BC_G (BC_ENABLED && (vm.flags & BC_FLAG_G))
-#define DC_X (DC_ENABLED && (vm.flags & DC_FLAG_X))
+
+#endif // BC_ENABLED
+
+#if DC_ENABLED
+#define DC_X (vm.flags & DC_FLAG_X)
+#endif // DC_ENABLED
+
+#define BC_I (vm.flags & BC_FLAG_I)
#define BC_P (vm.flags & BC_FLAG_P)
+#if BC_ENABLED
+
+#define BC_IS_POSIX (BC_S || BC_W)
+
+#if DC_ENABLED
+#define BC_IS_BC (vm.name[0] != 'd')
+#define BC_IS_DC (vm.name[0] == 'd')
+#else // DC_ENABLED
+#define BC_IS_BC (1)
+#define BC_IS_DC (0)
+#endif // DC_ENABLED
+
+#else // BC_ENABLED
+#define BC_IS_POSIX (0)
+#define BC_IS_BC (0)
+#define BC_IS_DC (1)
+#endif // BC_ENABLED
+
+#if BC_ENABLED
#define BC_USE_PROMPT (!BC_P && BC_TTY && !BC_IS_POSIX)
+#else // BC_ENABLED
+#define BC_USE_PROMPT (!BC_P && BC_TTY)
+#endif // BC_ENABLED
#define BC_MAX(a, b) ((a) > (b) ? (a) : (b))
#define BC_MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -131,9 +167,6 @@
#define BC_MAX_EXP ((ulong) (BC_NUM_BIGDIG_MAX))
#define BC_MAX_VARS ((ulong) (SIZE_MAX - 1))
-#define BC_IS_BC (BC_ENABLED && (!DC_ENABLED || vm.name[0] != 'd'))
-#define BC_IS_POSIX (BC_S || BC_W)
-
#if BC_DEBUG_CODE
#define BC_VM_JMP bc_vm_jmp(__func__)
#else // BC_DEBUG_CODE
@@ -234,7 +267,9 @@
#define BC_VM_BUF_SIZE (1<<12)
#define BC_VM_STDOUT_BUF_SIZE (1<<11)
#define BC_VM_STDERR_BUF_SIZE (1<<10)
-#define BC_VM_STDIN_BUF_SIZE BC_VM_STDERR_BUF_SIZE
+#define BC_VM_STDIN_BUF_SIZE (BC_VM_STDERR_BUF_SIZE - 1)
+
+#define BC_VM_SAFE_RESULT(r) ((r)->t >= BC_RESULT_TEMP)
#define bc_vm_err(e) (bc_vm_error((e), 0))
#define bc_vm_verr(e, ...) (bc_vm_error((e), 0, __VA_ARGS__))