Fix type annotation for &mut properties in defnew
This commit is contained in:
@@ -84,11 +84,7 @@ class FieldForms {
|
||||
return {
|
||||
name: name,
|
||||
access: access,
|
||||
kind: FVar(switch (args[0].def) {
|
||||
case TypedExp(type, _):
|
||||
Helpers.parseComplexType(type, args[0]);
|
||||
default: null;
|
||||
}, if (args.length > 1) k.convert(args[1]) else null),
|
||||
kind: FVar(Helpers.explicitType(args[0]), if (args.length > 1) k.convert(args[1]) else null),
|
||||
pos: wholeExp.macroPos()
|
||||
};
|
||||
}
|
||||
@@ -103,7 +99,7 @@ class FieldForms {
|
||||
return {
|
||||
name: name,
|
||||
access: access,
|
||||
kind: FFun(Helpers.makeFunction(args[0], returnsValue, args[1], args.slice(2), k)),
|
||||
kind: FFun(Helpers.makeFunction(args[0], returnsValue, args[1], args.slice(2), k, formName)),
|
||||
pos: wholeExp.macroPos()
|
||||
};
|
||||
}
|
||||
|
@@ -59,33 +59,31 @@ class Helpers {
|
||||
};
|
||||
}
|
||||
|
||||
public static function varName(formName:String, nameExp:ReaderExp) {
|
||||
public static function explicitType(nameExp:ReaderExp):ComplexType {
|
||||
return switch (nameExp.def) {
|
||||
case MetaExp(_, innerExp):
|
||||
explicitType(innerExp);
|
||||
case TypedExp(type, _):
|
||||
Helpers.parseComplexType(type, nameExp);
|
||||
default: null;
|
||||
};
|
||||
}
|
||||
|
||||
public static function varName(formName:String, nameExp:ReaderExp, nameType="variable") {
|
||||
return switch (nameExp.def) {
|
||||
case Symbol(name):
|
||||
name;
|
||||
case MetaExp(_, nameExp) | TypedExp(_, nameExp):
|
||||
varName(formName, nameExp);
|
||||
default:
|
||||
throw CompileError.fromExp(nameExp, 'The first argument to $formName should be a variable name, :Typed variable name, and/or &meta variable name.');
|
||||
throw CompileError.fromExp(nameExp, 'The first argument to $formName should be a $nameType name, :Typed $nameType name, and/or &meta $nameType name.');
|
||||
};
|
||||
}
|
||||
|
||||
// TODO generic type parameter declarations
|
||||
public static function makeFunction(?name:ReaderExp, returnsValue:Bool, argList:ReaderExp, body:List<ReaderExp>, k:KissState):Function {
|
||||
if (name != null) {
|
||||
switch (name.def) {
|
||||
case MetaExp(_, name):
|
||||
return makeFunction(name, returnsValue, argList, body, k);
|
||||
default:
|
||||
}
|
||||
}
|
||||
public static function makeFunction(?name:ReaderExp, returnsValue:Bool, argList:ReaderExp, body:List<ReaderExp>, k:KissState, formName:String):Function {
|
||||
var funcName = if (name != null) {
|
||||
switch (name.def) {
|
||||
case Symbol(name) | TypedExp(_, {pos: _, def: Symbol(name)}):
|
||||
name;
|
||||
default:
|
||||
throw CompileError.fromExp(name, 'function name should be a symbol or :Typed symbol');
|
||||
};
|
||||
varName(formName, name, "function");
|
||||
} else {
|
||||
"";
|
||||
};
|
||||
@@ -129,6 +127,7 @@ class Helpers {
|
||||
++numArgs;
|
||||
}
|
||||
{
|
||||
// These could use varName() and explicitType() but so far there are no &meta annotations for function arguments
|
||||
name: switch (funcArg.def) {
|
||||
case Symbol(name) | TypedExp(_, {pos: _, def: Symbol(name)}):
|
||||
name;
|
||||
@@ -152,13 +151,10 @@ class Helpers {
|
||||
|
||||
// To make function args immutable by default, we would use (let...) instead of (begin...)
|
||||
// to make the body expression.
|
||||
// But setting default arguments is so common, and arguments are not settable references,
|
||||
// But setting null arguments to default values is so common, and arguments are not settable references,
|
||||
// so function args are not immutable.
|
||||
return {
|
||||
ret: if (name != null) switch (name.def) {
|
||||
case TypedExp(type, _): Helpers.parseComplexType(type, name);
|
||||
default: null;
|
||||
} else null,
|
||||
ret: if (name != null) Helpers.explicitType(name) else null,
|
||||
args: switch (argList.def) {
|
||||
case ListExp(funcArgs):
|
||||
funcArgs.map(makeFuncArg);
|
||||
|
@@ -534,10 +534,16 @@ class Macros {
|
||||
|
||||
// TODO allow &prop in the arg list to bind it directly to a same-named variable
|
||||
|
||||
var propertyDefs = [for (bindingPair in bindingPairs) {
|
||||
var b = bindingPair[0].expBuilder();
|
||||
b.call(b.symbol("defprop"), [bindingPair[0]]);
|
||||
}];
|
||||
var propertySetExps = [for (bindingPair in bindingPairs) {
|
||||
var b = bindingPair[1].expBuilder();
|
||||
b.call(b.symbol("set"), [b.symbol(Helpers.varName("a defprop property binding", bindingPair[0])), bindingPair[1]]);
|
||||
}];
|
||||
|
||||
var b = wholeExp.expBuilder();
|
||||
var propertyDefs = [for (bindingPair in bindingPairs) b.call(b.symbol("defprop"), [bindingPair[0]])];
|
||||
var propertySetExps = [for (bindingPair in bindingPairs)
|
||||
b.call(b.symbol("set"), [b.symbol(Helpers.varName("a defprop property binding", bindingPair[0])), bindingPair[1]])];
|
||||
return b.begin(propertyDefs.concat([
|
||||
b.call(b.symbol("defmethod"), [
|
||||
b.symbol("new"),
|
||||
|
@@ -193,7 +193,7 @@ class SpecialForms {
|
||||
default:
|
||||
true;
|
||||
}
|
||||
EFunction(FAnonymous, Helpers.makeFunction(null, returnsValue, args[0], args.slice(1), k)).withMacroPosOf(wholeExp);
|
||||
EFunction(FAnonymous, Helpers.makeFunction(null, returnsValue, args[0], args.slice(1), k, "lambda")).withMacroPosOf(wholeExp);
|
||||
};
|
||||
|
||||
function forExpr(formName:String, wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) {
|
||||
|
Reference in New Issue
Block a user