fix an (if... ) bug
This commit is contained in:
@@ -7,6 +7,7 @@ import kiss.CompileError;
|
|||||||
import kiss.Types;
|
import kiss.Types;
|
||||||
|
|
||||||
using kiss.Reader;
|
using kiss.Reader;
|
||||||
|
using kiss.Helpers;
|
||||||
using StringTools;
|
using StringTools;
|
||||||
|
|
||||||
class Helpers {
|
class Helpers {
|
||||||
@@ -85,10 +86,7 @@ class Helpers {
|
|||||||
default:
|
default:
|
||||||
throw CompileError.fromExp(argList, 'expected an argument list');
|
throw CompileError.fromExp(argList, 'expected an argument list');
|
||||||
},
|
},
|
||||||
expr: {
|
expr: EReturn(convert(CallExp(Symbol("begin").withPos(body[0].pos), body).withPos(body[0].pos))).withContextPos()
|
||||||
pos: Context.currentPos(),
|
|
||||||
expr: EReturn(convert(CallExp(Symbol("begin").withPos(body[0].pos), body).withPos(body[0].pos)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -190,7 +190,13 @@ class SpecialForms {
|
|||||||
|
|
||||||
var condition = macro Prelude.truthy(${convert(args[0])});
|
var condition = macro Prelude.truthy(${convert(args[0])});
|
||||||
var thenExp = convert(args[1]);
|
var thenExp = convert(args[1]);
|
||||||
var elseExp = if (args.length > 2) convert(args[2]) else null;
|
var elseExp = if (args.length > 2) {
|
||||||
|
convert(args[2]);
|
||||||
|
} else {
|
||||||
|
// Kiss (if... ) expressions all need to generate a Haxe else block
|
||||||
|
// to make sure they always return something
|
||||||
|
macro null;
|
||||||
|
};
|
||||||
|
|
||||||
macro if ($condition)
|
macro if ($condition)
|
||||||
$thenExp
|
$thenExp
|
||||||
|
@@ -120,6 +120,8 @@ class BasicTestCase extends Test {
|
|||||||
Assert.equals(false, BasicTestCase.myIf8);
|
Assert.equals(false, BasicTestCase.myIf8);
|
||||||
Assert.equals(false, BasicTestCase.myIf9);
|
Assert.equals(false, BasicTestCase.myIf9);
|
||||||
Assert.equals(true, BasicTestCase.myIf10);
|
Assert.equals(true, BasicTestCase.myIf10);
|
||||||
|
Assert.equals(5, BasicTestCase.myIf11);
|
||||||
|
Assert.equals(null, BasicTestCase.myIf12);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testMacros() {
|
function testMacros() {
|
||||||
|
@@ -64,6 +64,8 @@
|
|||||||
(defvar myIf8 (if "" true false))
|
(defvar myIf8 (if "" true false))
|
||||||
(defvar myIf9 (if [] true false))
|
(defvar myIf9 (if [] true false))
|
||||||
(defvar myIf10 (if [1] true false))
|
(defvar myIf10 (if [1] true false))
|
||||||
|
(defvar myIf11 (if true 5))
|
||||||
|
(defvar myIf12 (if false 5))
|
||||||
|
|
||||||
(defvar :Int myInt 8)
|
(defvar :Int myInt 8)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user