aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2025-09-01 09:41:58 -0500
committerCalvin Rose <calsrose@gmail.com>2025-09-01 09:43:27 -0500
commitae51434a05bbb4c58a2a35c1428a5053182eb1ca (patch)
treee5cf466891eb680ded060532464007f97d349dba
parentMerge pull request #1637 from jsks/spelling-fixes (diff)
Fix #1604 - Add JANET_DO_ERROR_* defines for failure flags from janet_dobytes.
-rw-r--r--src/core/ev.c2
-rw-r--r--src/core/run.c9
-rw-r--r--src/include/janet.h3
3 files changed, 9 insertions, 5 deletions
diff --git a/src/core/ev.c b/src/core/ev.c
index e63cb0ea..c71214c7 100644
--- a/src/core/ev.c
+++ b/src/core/ev.c
@@ -2175,7 +2175,7 @@ void janet_ev_post_event(JanetVM *vm, JanetCallback cb, JanetEVGenericMessage ms
event.cb = cb;
int fd = vm->selfpipe[1];
/* handle a bit of back pressure before giving up. */
- int tries = 4;
+ int tries = 20;
while (tries > 0) {
int status;
do {
diff --git a/src/core/run.c b/src/core/run.c
index 0be7f6db..b6a78847 100644
--- a/src/core/run.c
+++ b/src/core/run.c
@@ -26,7 +26,8 @@
#include "state.h"
#endif
-/* Run a string */
+/* Run a string of code. The return value is a set of error flags, JANET_DO_ERROR_RUNTIME, JANET_DO_ERROR_COMPILE, and JANET_DOR_ERROR_PARSE if
+ * any errors were encountered in those phases. More information is printed to stderr. */
int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char *sourcePath, Janet *out) {
JanetParser *parser;
int errflags = 0, done = 0;
@@ -55,7 +56,7 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char
JanetSignal status = janet_continue(fiber, janet_wrap_nil(), &ret);
if (status != JANET_SIGNAL_OK && status != JANET_SIGNAL_EVENT) {
janet_stacktrace_ext(fiber, ret, "");
- errflags |= 0x01;
+ errflags |= JANET_DO_ERROR_RUNTIME;
done = 1;
}
} else {
@@ -75,7 +76,7 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char
janet_eprintf("%s:%d:%d: compile error: %s\n", sourcePath,
line, col, (const char *)cres.error);
}
- errflags |= 0x02;
+ errflags |= JANET_DO_ERROR_COMPILE;
done = 1;
}
}
@@ -89,7 +90,7 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char
break;
case JANET_PARSE_ERROR: {
const char *e = janet_parser_error(parser);
- errflags |= 0x04;
+ errflags |= JANET_DO_ERROR_PARSE;
ret = janet_cstringv(e);
int32_t line = (int32_t) parser->line;
int32_t col = (int32_t) parser->column;
diff --git a/src/include/janet.h b/src/include/janet.h
index 7ac2fdd3..4d48de95 100644
--- a/src/include/janet.h
+++ b/src/include/janet.h
@@ -1616,6 +1616,9 @@ JANET_API JanetTable *janet_core_env(JanetTable *replacements);
JANET_API JanetTable *janet_core_lookup_table(JanetTable *replacements);
/* Execute strings */
+#define JANET_DO_ERROR_RUNTIME 0x01
+#define JANET_DO_ERROR_COMPILE 0x02
+#define JANET_DO_ERROR_PARSE 0x04
JANET_API int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char *sourcePath, Janet *out);
JANET_API int janet_dostring(JanetTable *env, const char *str, const char *sourcePath, Janet *out);