fix (load) bug

This commit is contained in:
2020-12-31 17:09:30 -07:00
parent 29f6f0ae0b
commit d91d15c102
5 changed files with 13 additions and 4 deletions

View File

@@ -78,11 +78,11 @@ class Kiss {
}
/**
Build a Haxe class from a corresponding .kiss file
Build macro: add fields to a class from a corresponding .kiss file
**/
public static function build(kissFile:String, ?k:KissState):Array<Field> {
public static function build(kissFile:String, ?k:KissState, useClassFields = true):Array<Field> {
return _try(() -> {
var classFields = Context.getBuildFields();
var classFields:Array<Field> = if (useClassFields) Context.getBuildFields() else [];
var stream = new Stream(kissFile);
// (load... ) relative to the original file
@@ -100,7 +100,7 @@ class Kiss {
case CallExp({pos: _, def: Symbol("load")}, [{pos: _, def: StrExp(otherKissFile)}]):
var filePath = Path.join([loadingDirectory, otherKissFile]);
if (!k.loadedFiles.exists(filePath)) {
var loadedFields = Kiss.build(filePath, k);
var loadedFields = Kiss.build(filePath, k, false);
for (field in loadedFields) {
classFields.push(field);
}

View File

@@ -175,6 +175,7 @@ class Reader {
/**
Read all the expressions in the given stream, processing them one by one while reading.
They can't be read all at once because some expressions change the Readtable state
**/
public static function readAndProcess(stream:Stream, k:KissState, process:(ReaderExp) -> Void) {
while (true) {

View File

@@ -261,6 +261,10 @@ class BasicTestCase extends Test {
function testCallAlias() {
_testCallAlias();
}
function testLoadedFunction() {
Assert.equals("loaded", BasicTestCase.loadedFunction());
}
}
class BasicObject {

View File

@@ -1,3 +1,6 @@
// (load) brings in the fields and compile-time definitions of another Kiss file
(load "BasicTestCaseExtra.kiss")
// (defvar) declares static variables
(defvar message "Howdy")

View File

@@ -0,0 +1 @@
(defun loadedFunction [] "loaded")