mirror of
https://github.com/janet-lang/janet
synced 2025-11-09 12:03:04 +00:00
Add highlight.janet tool which can highlight
janet source code and output html or terminal escaped code. Also made re entrant calls into the vm provide better error messages.
This commit is contained in:
@@ -92,7 +92,7 @@
|
||||
(defn function? "Check if x is a function (not a cfunction)." [x]
|
||||
(= (type x) :function))
|
||||
(defn cfunction? "Check if x a cfunction." [x] (= (type x) :cfunction))
|
||||
(defn table? "Check if x a table." [x] (= (type x) :table ))
|
||||
(defn table? "Check if x a table." [x] (= (type x) :table))
|
||||
(defn struct? "Check if x a struct." [x] (= (type x) :struct))
|
||||
(defn array? "Check if x is an array." [x] (= (type x) :array))
|
||||
(defn tuple? "Check if x is a tuple." [x] (= (type x) :tuple))
|
||||
|
||||
@@ -53,6 +53,7 @@ typedef enum {
|
||||
RULE_REPLACE, /* [rule, constant, tag] */
|
||||
RULE_MATCHTIME, /* [rule, constant, tag] */
|
||||
RULE_ERROR, /* [rule] */
|
||||
RULE_DROP, /* [rule] */
|
||||
} Opcode;
|
||||
|
||||
/* Hold captured patterns and match state */
|
||||
@@ -350,6 +351,17 @@ tail:
|
||||
return result;
|
||||
}
|
||||
|
||||
case RULE_DROP:
|
||||
{
|
||||
CapState cs = cap_save(s);
|
||||
down1(s);
|
||||
const uint8_t *result = peg_rule(s, s->bytecode + rule[1], text);
|
||||
up1(s);
|
||||
if (!result) return NULL;
|
||||
cap_load(s, cs);
|
||||
return result;
|
||||
}
|
||||
|
||||
case RULE_GROUP:
|
||||
{
|
||||
uint32_t tag = rule[2];
|
||||
@@ -750,6 +762,9 @@ static void spec_not(Builder *b, int32_t argc, const Janet *argv) {
|
||||
static void spec_error(Builder *b, int32_t argc, const Janet *argv) {
|
||||
spec_onerule(b, argc, argv, RULE_ERROR);
|
||||
}
|
||||
static void spec_drop(Builder *b, int32_t argc, const Janet *argv) {
|
||||
spec_onerule(b, argc, argv, RULE_DROP);
|
||||
}
|
||||
|
||||
/* Rule of the form [rule, tag] */
|
||||
static void spec_cap1(Builder *b, int32_t argc, const Janet *argv, uint32_t op) {
|
||||
@@ -854,6 +869,7 @@ static const SpecialPair specials[] = {
|
||||
{"choice", spec_choice},
|
||||
{"cmt", spec_matchtime},
|
||||
{"constant", spec_constant},
|
||||
{"drop", spec_drop},
|
||||
{"error", spec_error},
|
||||
{"group", spec_group},
|
||||
{"if", spec_if},
|
||||
|
||||
@@ -758,18 +758,30 @@ Janet janet_call(JanetFunction *fun, int32_t argc, const Janet *argv) {
|
||||
JanetFiber *fiber = janet_fiber(fun, 64, argc, argv);
|
||||
if (!fiber)
|
||||
janet_panic("arity mismatch");
|
||||
JanetFiber *old_fiber = janet_vm_fiber;
|
||||
janet_vm_fiber = fiber;
|
||||
janet_gcroot(janet_wrap_fiber(fiber));
|
||||
int32_t oldn = janet_vm_stackn++;
|
||||
int handle = janet_gclock();
|
||||
|
||||
JanetFiber *old_fiber = janet_vm_fiber;
|
||||
old_fiber->child = fiber;
|
||||
janet_vm_fiber = fiber;
|
||||
memcpy(fiber->buf, janet_vm_fiber->buf, sizeof(jmp_buf));
|
||||
run_vm(fiber, janet_wrap_nil(), JANET_STATUS_NEW);
|
||||
old_fiber->child = NULL;
|
||||
janet_vm_fiber = old_fiber;
|
||||
JanetSignal signal;
|
||||
if (setjmp(fiber->buf)) {
|
||||
signal = JANET_SIGNAL_ERROR;
|
||||
} else {
|
||||
signal = run_vm(fiber, janet_wrap_nil(), JANET_STATUS_NEW);
|
||||
}
|
||||
|
||||
janet_vm_stackn = oldn;
|
||||
janet_vm_fiber = old_fiber;
|
||||
Janet ret = fiber->data[fiber->stacktop - 1];
|
||||
janet_gcunroot(janet_wrap_fiber(fiber));
|
||||
janet_gcunlock(handle);
|
||||
return fiber->data[fiber->stacktop - 1];
|
||||
if (signal == JANET_SIGNAL_ERROR) {
|
||||
old_fiber->child = fiber;
|
||||
janet_fiber_set_status(fiber, signal);
|
||||
janet_panicv(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Enter the main vm loop */
|
||||
|
||||
Reference in New Issue
Block a user