-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow expressions to be functions Fix return value of functions to always be added to operation stack Add array and len functions
- Loading branch information
1 parent
ba0c693
commit 5cc0ffd
Showing
7 changed files
with
71 additions
and
8 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
using EOBot.Interpreter.States; | ||
using EOBot.Interpreter.Variables; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace EOBot.Interpreter | ||
{ | ||
public class BuiltInIdentifierConfigurator | ||
{ | ||
public void SetupBuiltInFunctions(ProgramState input) | ||
{ | ||
var function = new VoidFunctionRef<string>(PredefinedIdentifiers.PRINT_FUNC, param1 => ConsoleHelper.WriteMessage(ConsoleHelper.Type.None, param1)); | ||
input.SymbolTable[PredefinedIdentifiers.PRINT_FUNC] = function; | ||
var printFunc = new VoidFunctionRef<object>(PredefinedIdentifiers.PRINT_FUNC, param1 => ConsoleHelper.WriteMessage(ConsoleHelper.Type.None, param1.ToString())); | ||
input.SymbolTable[PredefinedIdentifiers.PRINT_FUNC] = printFunc; | ||
|
||
var lenFunc = new FunctionRef<ArrayVariable, int>(PredefinedIdentifiers.LEN_FUNC, param1 => param1.Value.Count); | ||
input.SymbolTable[PredefinedIdentifiers.LEN_FUNC] = lenFunc; | ||
|
||
var arrayFunc = new FunctionRef<int, List<IVariable>>(PredefinedIdentifiers.ARRAY_FUNC, | ||
param1 => Enumerable.Repeat(UndefinedVariable.Instance, param1).Cast<IVariable>().ToList()); | ||
input.SymbolTable.Add(PredefinedIdentifiers.ARRAY_FUNC, arrayFunc); | ||
} | ||
|
||
public void SetupBuiltInVariables(ArgumentsParser parsedArgs) | ||
public void SetupBuiltInVariables(ProgramState input, ArgumentsParser parsedArgs) | ||
{ | ||
input.SymbolTable[PredefinedIdentifiers.HOST] = new StringVariable(parsedArgs.Host); | ||
input.SymbolTable[PredefinedIdentifiers.PORT] = new IntVariable(parsedArgs.Port); | ||
input.SymbolTable[PredefinedIdentifiers.ARGS] = new ArrayVariable( | ||
parsedArgs.UserArgs.Select(x => new StringVariable(x)).Cast<IVariable>().ToList()); | ||
|
||
input.SymbolTable[PredefinedIdentifiers.RESULT] = UndefinedVariable.Instance; | ||
input.SymbolTable[PredefinedIdentifiers.ACCOUNT] = UndefinedVariable.Instance; | ||
input.SymbolTable[PredefinedIdentifiers.CHARACTER] = UndefinedVariable.Instance; | ||
input.SymbolTable[PredefinedIdentifiers.MAPSTATE] = UndefinedVariable.Instance; | ||
} | ||
} | ||
} |
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