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