mirror of
https://github.com/janet-lang/janet
synced 2024-11-24 01:17:16 +00:00
Fix 'if' special form.
This commit is contained in:
parent
3d7e574e05
commit
715c239fc1
@ -878,7 +878,7 @@ static Slot CompileIf(Compiler * c, FormOptions opts, Array * form) {
|
||||
BufferPushUInt16(gc, buffer, condition.index);
|
||||
BufferPushUInt32(gc, buffer, 0);
|
||||
/* Compile true path */
|
||||
left = CompileValue(c, resOpts, form->data[1]);
|
||||
left = CompileValue(c, resOpts, form->data[2]);
|
||||
if (opts.isTail && !left.isDud) {
|
||||
BufferPushUInt16(gc, buffer, VM_OP_RET);
|
||||
BufferPushUInt16(gc, buffer, left.index);
|
||||
@ -899,7 +899,7 @@ static Slot CompileIf(Compiler * c, FormOptions opts, Array * form) {
|
||||
buffer->count = countAfterFirstBranch;
|
||||
/* Compile false path */
|
||||
if (form->count == 4) {
|
||||
right = CompileValue(c, resOpts, form->data[1]);
|
||||
right = CompileValue(c, resOpts, form->data[3]);
|
||||
if (opts.isTail && !right.isDud) {
|
||||
BufferPushUInt16(gc, buffer, VM_OP_RET);
|
||||
BufferPushUInt16(gc, buffer, right.index);
|
||||
|
22
value.c
22
value.c
@ -6,6 +6,20 @@
|
||||
#include "value.h"
|
||||
#include "buffer.h"
|
||||
|
||||
/* Print the bytecode for a FuncDef */
|
||||
static void FuncDefBytecodePrint(FuncDef * def) {
|
||||
uint32_t count, i;
|
||||
count = def->byteCodeLen;
|
||||
printf("(bytecode)[");
|
||||
if (count) {
|
||||
for (i = 0; i < count - 1; ++i) {
|
||||
printf("%04x ", def->byteCode[i]);
|
||||
}
|
||||
printf("%04x", def->byteCode[i]);
|
||||
}
|
||||
printf("]");
|
||||
}
|
||||
|
||||
/* Print a value recursively. Used for debugging */
|
||||
void ValuePrint(Value * x, uint32_t indent) {
|
||||
uint32_t i;
|
||||
@ -41,7 +55,9 @@ void ValuePrint(Value * x, uint32_t indent) {
|
||||
printf("<cfunction>");
|
||||
break;
|
||||
case TYPE_FUNCTION:
|
||||
printf("<function>");
|
||||
printf("<function ");
|
||||
FuncDefBytecodePrint(x->data.func->def);
|
||||
printf(">");
|
||||
break;
|
||||
case TYPE_DICTIONARY:
|
||||
printf("<dictionary>");
|
||||
@ -50,7 +66,9 @@ void ValuePrint(Value * x, uint32_t indent) {
|
||||
printf("<bytebuffer>");
|
||||
break;
|
||||
case TYPE_FUNCDEF:
|
||||
printf("<funcdef>");
|
||||
printf("<funcdef ");
|
||||
FuncDefBytecodePrint(x->data.funcdef);
|
||||
printf(">");
|
||||
break;
|
||||
case TYPE_FUNCENV:
|
||||
printf("<funcenv>");
|
||||
|
Loading…
Reference in New Issue
Block a user