target-domain support for default arguments in pure.xdc function calls
diff --git a/packages/xdc/services/intern/gen/ImplC.java b/packages/xdc/services/intern/gen/ImplC.java
index 3994580..e82bb69 100644
--- a/packages/xdc/services/intern/gen/ImplC.java
+++ b/packages/xdc/services/intern/gen/ImplC.java
@@ -114,7 +114,7 @@
List<Expr> args = e.getArgs();
if (args != null) {
glob.out.print("(");
- genPathCallArgs(args, "");
+ genPathCallArgs(args, "", null);
glob.out.print(")");
}
}
@@ -290,26 +290,40 @@
glob.out.print("*");
}
genPath((Expr.Path)fxn.getObj(), chain, idx - 2);
- genPathCallArgs(e.getArgs(), ", ");
+ genPathCallArgs(e.getArgs(), ", ", fcat instanceof Cat.Fxn ? ((Cat.Fxn)fcat).getDecl() : null);
glob.out.print(")");
return;
}
}
+ Cat cat = chain.get(0).getCat();
+ Decl.Fxn fxn = cat instanceof Cat.Fxn ? ((Cat.Fxn)cat).getDecl() : null;
+
genPath((Expr.Path)e.getFxn(), chain, idx - 1);
glob.out.print("(");
- genPathCallArgs(e.getArgs(), "");
+ genPathCallArgs(e.getArgs(), "", fxn);
glob.out.print(")");
}
// genPathCallArgs
- private void genPathCallArgs( List<Expr> args, String sep )
+ private void genPathCallArgs( List<Expr> args, String sep, Decl.Fxn fxn )
{
for (Expr a : args) {
glob.out.print(sep);
genExpr(a);
sep = ", ";
}
+
+ if (fxn == null) {
+ return;
+ }
+
+ List<Decl.Arg> fargs = fxn.getArgs();
+ for (int k = fxn.isStruct() ? args.size() + 1 : args.size(); k < fargs.size(); k++) {
+ glob.out.print(sep);
+ genExpr(fargs.get(k).getInit());
+ sep = ", ";
+ }
}
// genPathIndex
diff --git a/packages/xdc/services/spec/Cat.java b/packages/xdc/services/spec/Cat.java
index f65a6d9..af375f3 100644
--- a/packages/xdc/services/spec/Cat.java
+++ b/packages/xdc/services/spec/Cat.java
@@ -52,8 +52,17 @@
// Cat.Fxn
public static class Fxn extends Cat
{
- private Fxn( String code, int ptrCnt ) { super(code, ptrCnt); }
+ private Decl.Fxn fxnDecl;
+
+ private Fxn( String code, int ptrCnt ) { this(code, ptrCnt, null); }
+ private Fxn( String code, int ptrCnt, Decl.Fxn fxnDecl )
+ {
+ super(code, ptrCnt);
+ this.fxnDecl = fxnDecl;
+ }
+
String code() { return "F!" + this.code; };
+ public Decl.Fxn getDecl() { return this.fxnDecl; }
Cat mkRetCat() { return (Cat.fromCode(this.code)); }
}
@@ -203,10 +212,10 @@
if (d instanceof Decl.Fxn) {
Decl.Fxn fxn = (Decl.Fxn)d;
if (fxn.getType() instanceof Type.Creator) {
- return new Cat.Fxn("o", 0);
+ return new Cat.Fxn("o", 0, fxn);
}
else {
- return new Cat.Fxn(Cat.recode(fxn.getType()), 0);
+ return new Cat.Fxn(Cat.recode(fxn.getType()), 0, fxn);
}
}
diff --git a/packages/xdc/services/spec/Decl.java b/packages/xdc/services/spec/Decl.java
index f6524de..12e2ed7 100644
--- a/packages/xdc/services/spec/Decl.java
+++ b/packages/xdc/services/spec/Decl.java
@@ -837,6 +837,7 @@
if (!(this.args.get(0).getType().tspec().getRef().getNode() instanceof Decl.Struct)) {
ses.msg.error(this.name, "qualified name does not reference a struct type");
}
+ this.minargc--;
}
Decl.checkSig(this);
diff --git a/packages/xdc/services/spec/Impl.java b/packages/xdc/services/spec/Impl.java
index b4c40fa..d80cce8 100644
--- a/packages/xdc/services/spec/Impl.java
+++ b/packages/xdc/services/spec/Impl.java
@@ -38,7 +38,7 @@
if (this.isAccum) {
Cat cat = this.lval.getCat();
if (!(cat instanceof Cat.Arr || cat.getCode().equals("n") || cat.getCode().equals("s"))) {
- Impl.ses.msg.error("lval must be an array, number, or string", ((Expr)this.lval).getAtom());
+ Impl.ses.msg.error(((Expr)this.lval).getAtom(), "lval must be an array, number, or string");
}
}
}
@@ -206,24 +206,30 @@
return;
}
- Impl.ses.msg.error("operator requires a struct field or array index", e.getAtom());
+ Impl.ses.msg.error(e.getAtom(), "operator requires a struct field or array index");
}
static void resolveCall( Expr.Call e )
{
- Expr fxn = e.getFxn();
+ Expr efxn = e.getFxn();
- fxn.resolve(Impl.unit);
+ efxn.resolve(Impl.unit);
for (Expr a : e.getArgs()) {
a.resolve(Impl.unit);
}
- Cat fxncat = ((Expr.Path)fxn).getCat();
+ Cat fxncat = ((Expr.Path)efxn).getCat();
if (!(fxncat instanceof Cat.Fxn)) {
- Impl.ses.msg.error("operand is not a function", e.getAtom());
+ Impl.ses.msg.error(e.getAtom(), "operand is not a function");
return;
}
+ Decl.Fxn fxn = ((Cat.Fxn)fxncat).getDecl();
+ if (fxn != null && e.getArgs().size() < fxn.getMinArgc()) {
+ Impl.ses.msg.error(fxn.getAtom(), "too few arguments");
+ return;
+ }
+
e.setCat(((Cat.Fxn)fxncat).mkRetCat());
// System.out.println("call: " + e.getCat().getCode());
}
@@ -237,12 +243,12 @@
Cat cat = ((Expr.Path)arr).getCat();
if (!(cat instanceof Cat.Indexed)) {
- Impl.ses.msg.error("operand of [] must be an array or map", e.getAtom());
+ Impl.ses.msg.error(e.getAtom(), "operand of [] must be an array or map");
return;
}
if (cat instanceof Cat.Map && !Impl.isMeta()) {
- Impl.ses.msg.error("maps can only be used in bindings or meta-functions", e.getAtom());
+ Impl.ses.msg.error(e.getAtom(), "maps can only be used in bindings or meta-functions");
return;
}