Skip to content

Commit

Permalink
Add default parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
praeclarum committed Jan 7, 2019
1 parent 5c128f1 commit 399dd22
Show file tree
Hide file tree
Showing 9 changed files with 882 additions and 807 deletions.
3 changes: 2 additions & 1 deletion CLanguage/Compiler/EmitContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ CType MakeCFunctionType (CType returnType, Declarator decl, Block block)
? MakeCType (pdecl.DeclarationSpecifiers, pdecl.Declarator, null, block)
: CBasicType.SignedInt;
if (!pt.IsVoid) {
ftype.AddParameter (pdecl.Name, pt);
var defaultValue = pdecl.DefaultValue == null ? null : (Value?)pdecl.DefaultValue.EvalConstant (this);
ftype.AddParameter (pdecl.Name, pt, defaultValue);
}
}

Expand Down
3 changes: 3 additions & 0 deletions CLanguage/Compiler/ExecutableContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ BaseFunction UnresolvedMethod (string typeName, string methodName) =>
var f = Executable.Functions[i];
if (f.Name == name && string.IsNullOrEmpty (f.NameContext)) {
var score = f.FunctionType.ScoreParameterTypeMatches (argTypes);
//if (!f.Name.StartsWith ("assert"))
//Console.WriteLine ($" {f.Name} {f.FunctionType} == {score}");
if (score > fs) {
ff = f;
fi = i;
Expand All @@ -66,6 +68,7 @@ BaseFunction UnresolvedMethod (string typeName, string methodName) =>
}
}
if (ff != null) {
//Console.WriteLine ($"= {name} {ff.FunctionType} == {fs}");
return new ResolvedVariable (ff, fi);
}

Expand Down
Loading

0 comments on commit 399dd22

Please sign in to comment.