mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 09:47:17 +00:00
Address #950 - add defn suggestion on bad def.
While generally we are not in the business of making a very chatty compiler, this is a simple improvement that involves compiling metadata before the binding, as well as adding a suggestion for `defn` in case the compiler encounters an unexpected tuple.
This commit is contained in:
parent
726d35c766
commit
b4ec168401
@ -305,6 +305,9 @@ static JanetTable *handleattr(JanetCompiler *c, int32_t argn, const Janet *argv)
|
|||||||
for (i = 1; i < argn - 1; i++) {
|
for (i = 1; i < argn - 1; i++) {
|
||||||
Janet attr = argv[i];
|
Janet attr = argv[i];
|
||||||
switch (janet_type(attr)) {
|
switch (janet_type(attr)) {
|
||||||
|
case JANET_TUPLE:
|
||||||
|
janetc_cerror(c, "unexpected form - did you intend to use defn?");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
janetc_cerror(c, "could not add metadata to binding");
|
janetc_cerror(c, "could not add metadata to binding");
|
||||||
break;
|
break;
|
||||||
@ -390,10 +393,11 @@ static int varleaf(
|
|||||||
static JanetSlot janetc_var(JanetFopts opts, int32_t argn, const Janet *argv) {
|
static JanetSlot janetc_var(JanetFopts opts, int32_t argn, const Janet *argv) {
|
||||||
JanetCompiler *c = opts.compiler;
|
JanetCompiler *c = opts.compiler;
|
||||||
Janet head;
|
Janet head;
|
||||||
|
JanetTable *attr_table = handleattr(c, argn, argv);
|
||||||
JanetSlot ret = dohead(c, opts, &head, argn, argv);
|
JanetSlot ret = dohead(c, opts, &head, argn, argv);
|
||||||
if (c->result.status == JANET_COMPILE_ERROR)
|
if (c->result.status == JANET_COMPILE_ERROR)
|
||||||
return janetc_cslot(janet_wrap_nil());
|
return janetc_cslot(janet_wrap_nil());
|
||||||
destructure(c, argv[0], ret, varleaf, handleattr(c, argn, argv));
|
destructure(c, argv[0], ret, varleaf, attr_table);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,10 +443,11 @@ static JanetSlot janetc_def(JanetFopts opts, int32_t argn, const Janet *argv) {
|
|||||||
JanetCompiler *c = opts.compiler;
|
JanetCompiler *c = opts.compiler;
|
||||||
Janet head;
|
Janet head;
|
||||||
opts.flags &= ~JANET_FOPTS_HINT;
|
opts.flags &= ~JANET_FOPTS_HINT;
|
||||||
|
JanetTable *attr_table = handleattr(c, argn, argv);
|
||||||
JanetSlot ret = dohead(c, opts, &head, argn, argv);
|
JanetSlot ret = dohead(c, opts, &head, argn, argv);
|
||||||
if (c->result.status == JANET_COMPILE_ERROR)
|
if (c->result.status == JANET_COMPILE_ERROR)
|
||||||
return janetc_cslot(janet_wrap_nil());
|
return janetc_cslot(janet_wrap_nil());
|
||||||
destructure(c, argv[0], ret, defleaf, handleattr(c, argn, argv));
|
destructure(c, argv[0], ret, defleaf, attr_table);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user