(load [file])

This commit is contained in:
2020-12-09 19:04:11 -07:00
parent cfd3147337
commit 1a5eb07d48
3 changed files with 32 additions and 24 deletions

View File

@@ -4,6 +4,7 @@ package kiss;
import haxe.Exception;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.io.Path;
import kiss.Stream;
import kiss.Reader;
import kiss.FieldForms;
@@ -58,6 +59,8 @@ class Kiss {
try {
var classFields = Context.getBuildFields();
var stream = new Stream(kissFile);
// (load... ) relative to the original file
var loadingDirectory = Path.directory(kissFile);
if (k == null)
k = defaultKissState();
@@ -66,6 +69,15 @@ class Kiss {
#if test
Sys.println(nextExp.def.toString());
#end
switch (nextExp.def) {
// (load... ) is the specialest of forms because it calls build() again and those fields need to be merged
case CallExp({pos: _, def: Symbol("load")}, [{pos: _, def: StrExp(otherKissFile)}]):
var filePath = Path.join([loadingDirectory, otherKissFile]);
var loadedFields = Kiss.build(filePath, k);
for (field in loadedFields) {
classFields.push(field);
}
default:
var field = readerExpToField(nextExp, k);
if (field != null) {
#if test
@@ -78,6 +90,7 @@ class Kiss {
#end
classFields.push(field);
}
}
});
return classFields;
@@ -128,12 +141,6 @@ class Kiss {
specialForms[specialForm](exp, args, k);
case CallExp(func, args):
ECall(convert(func), [for (argExp in args) convert(argExp)]).withMacroPosOf(exp);
/*
// Typed expressions in the wild become casts:
case TypedExp(type, innerExp):
ECast(convert(innerExp), if (type.length > 0) Helpers.parseComplexType(type, exp) else null).withMacroPosOf(wholeExp);
*/
case ListExp(elements):
var isMap = false;
var arrayDecl = EArrayDecl([

View File

@@ -0,0 +1,7 @@
(defprop &mut accumulator 0)
(defmethod setBreakPoint [] (addBreakPoint instructionPointer))
(defmethod nop [v] (setBreakPoint))
(defmethod acc [v] (setBreakPoint) (set accumulator (+ accumulator v)))
(defmethod jmp [v] (setBreakPoint) (set instructionPointer (+ instructionPointer (- v 1))))

View File

@@ -1,10 +1,4 @@
(defprop &mut accumulator 0)
(defmethod setBreakPoint [] (addBreakPoint instructionPointer))
(defmethod nop [v] (setBreakPoint))
(defmethod acc [v] (setBreakPoint) (set accumulator (+ accumulator v)))
(defmethod jmp [v] (setBreakPoint) (set instructionPointer (+ instructionPointer (- v 1))))
(load "BootCodeCommon.kiss")
(defreadermacro "" [stream] #| ReaderExp.CallExp(
{