-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed some stuff that didn't work correctly
- Loading branch information
TheUnlocked
committed
Mar 17, 2018
1 parent
2e9a17b
commit d3cc492
Showing
7 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using FAILang.Types; | ||
|
||
namespace FAILang.Builtins | ||
{ | ||
class CollectionBuiltinProvider : IBuiltinProvider | ||
{ | ||
private static ExternalFunction ValidateType<T>(Func<T, IType> f, Func<IType, IType> fail) where T : IType | ||
{ | ||
return x => | ||
{ | ||
if (x[0] is T t) | ||
return f.Invoke(t); | ||
return fail.Invoke(x[0]); | ||
}; | ||
} | ||
|
||
private static ExternFunction LENGTH = new ExternFunction(ValidateType<IIndexable>( | ||
x => new Number(x.Length), | ||
x => new Error("WrongType", $"{x} has no length")), | ||
"c"); | ||
|
||
public (string, ExternFunction)[] GetBuiltins() => new(string, ExternFunction)[] { | ||
("length", LENGTH) | ||
}; | ||
|
||
public string[] GetReservedNames() => new string[] { | ||
"length" | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters