special form macroExpanders, (object) implementation
This commit is contained in:
@@ -46,6 +46,7 @@ typedef KissState = {
|
|||||||
endOfFileReadTable:ReadTable,
|
endOfFileReadTable:ReadTable,
|
||||||
fieldForms:Map<String, FieldFormFunction>,
|
fieldForms:Map<String, FieldFormFunction>,
|
||||||
specialForms:Map<String, SpecialFormFunction>,
|
specialForms:Map<String, SpecialFormFunction>,
|
||||||
|
specialFormMacroExpanders:Map<String, MacroFunction>,
|
||||||
macros:Map<String, MacroFunction>,
|
macros:Map<String, MacroFunction>,
|
||||||
formDocs:Map<String, FormDoc>,
|
formDocs:Map<String, FormDoc>,
|
||||||
doc:(String, Null<Int>, Null<Int>, ?String, ?String)->Void,
|
doc:(String, Null<Int>, Null<Int>, ?String, ?String)->Void,
|
||||||
@@ -100,6 +101,7 @@ class Kiss {
|
|||||||
endOfFileReadTable: new ReadTable(),
|
endOfFileReadTable: new ReadTable(),
|
||||||
fieldForms: new Map(),
|
fieldForms: new Map(),
|
||||||
specialForms: null,
|
specialForms: null,
|
||||||
|
specialFormMacroExpanders: null,
|
||||||
macros: null,
|
macros: null,
|
||||||
formDocs: new Map(),
|
formDocs: new Map(),
|
||||||
doc: null,
|
doc: null,
|
||||||
@@ -215,6 +217,7 @@ class Kiss {
|
|||||||
|
|
||||||
FieldForms.addBuiltins(k);
|
FieldForms.addBuiltins(k);
|
||||||
k.specialForms = SpecialForms.builtins(k, context);
|
k.specialForms = SpecialForms.builtins(k, context);
|
||||||
|
k.specialFormMacroExpanders = SpecialForms.builtinMacroExpanders(k, context);
|
||||||
k.macros = Macros.builtins(k);
|
k.macros = Macros.builtins(k);
|
||||||
|
|
||||||
return k;
|
return k;
|
||||||
@@ -620,6 +623,7 @@ class Kiss {
|
|||||||
var macros = k.macros;
|
var macros = k.macros;
|
||||||
var fieldForms = k.fieldForms;
|
var fieldForms = k.fieldForms;
|
||||||
var specialForms = k.specialForms;
|
var specialForms = k.specialForms;
|
||||||
|
var specialFormMacroExpanders = k.specialFormMacroExpanders;
|
||||||
var formDocs = k.formDocs;
|
var formDocs = k.formDocs;
|
||||||
|
|
||||||
// Bind the table arguments of this function for easy recursive calling/passing
|
// Bind the table arguments of this function for easy recursive calling/passing
|
||||||
@@ -735,6 +739,9 @@ class Kiss {
|
|||||||
case CallExp({pos: _, def: Symbol(specialForm)}, args) if (specialForms.exists(specialForm) && !macroExpandOnly):
|
case CallExp({pos: _, def: Symbol(specialForm)}, args) if (specialForms.exists(specialForm) && !macroExpandOnly):
|
||||||
checkNumArgs(specialForm);
|
checkNumArgs(specialForm);
|
||||||
Right(Kiss.measure(specialForm, ()->specialForms[specialForm](exp, args.copy(), k), true));
|
Right(Kiss.measure(specialForm, ()->specialForms[specialForm](exp, args.copy(), k), true));
|
||||||
|
case CallExp({pos: _, def: Symbol(specialForm)}, args) if (specialFormMacroExpanders.exists(specialForm) && macroExpandOnly):
|
||||||
|
checkNumArgs(specialForm);
|
||||||
|
Left(specialFormMacroExpanders[specialForm](exp, args.copy(), k));
|
||||||
case CallExp({pos: _, def: Symbol(alias)}, args) if (k.callAliases.exists(alias)):
|
case CallExp({pos: _, def: Symbol(alias)}, args) if (k.callAliases.exists(alias)):
|
||||||
convert(CallExp(k.callAliases[alias].withPosOf(exp), args).withPosOf(exp));
|
convert(CallExp(k.callAliases[alias].withPosOf(exp), args).withPosOf(exp));
|
||||||
case CallExp(func, args):
|
case CallExp(func, args):
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import kiss.Reader;
|
|||||||
import kiss.ReaderExp;
|
import kiss.ReaderExp;
|
||||||
import uuid.Uuid;
|
import uuid.Uuid;
|
||||||
import kiss.Kiss;
|
import kiss.Kiss;
|
||||||
|
import kiss.Macros;
|
||||||
|
|
||||||
using uuid.Uuid;
|
using uuid.Uuid;
|
||||||
using kiss.Reader;
|
using kiss.Reader;
|
||||||
@@ -649,6 +650,21 @@ class SpecialForms {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function builtinMacroExpanders(k:KissState, ?context:FrontendContext) {
|
||||||
|
var map:Map<String, MacroFunction> = [];
|
||||||
|
|
||||||
|
// when macroExpanding an (object) expression, don't apply aliases to the field names
|
||||||
|
map["object"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
||||||
|
var b = wholeExp.expBuilder();
|
||||||
|
var pairs = Lambda.flatten([for (pair in args.groups(2)) {
|
||||||
|
[pair[0], Kiss.macroExpand(pair[1], k)];
|
||||||
|
}]);
|
||||||
|
b.callSymbol("object", pairs);
|
||||||
|
};
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
public static function caseOr(wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState):Expr {
|
public static function caseOr(wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState):Expr {
|
||||||
wholeExp.checkNumArgs(2, null, "(or <pattern1> <pattern2> <patterns...>)");
|
wholeExp.checkNumArgs(2, null, "(or <pattern1> <pattern2> <patterns...>)");
|
||||||
var b = wholeExp.expBuilder();
|
var b = wholeExp.expBuilder();
|
||||||
|
|||||||
Reference in New Issue
Block a user