public static ICASMExecutionResult LoadAndExecute(string path) { if (!new FileInfo(path).Exists) { throw new FileNotFoundException("File not found - " + path); } TextReader treader = new StreamReader(path); string[] statements = treader.ReadToEnd().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); return(ICASMInterpreter.Execute("/", statements)); }
private Variable ICASMFunction_ExecuteFunction(Function _executing_function, Address _destination_address, params Address[] _parameter_addresses) { ICASMFunction func = (ICASMFunction)_executing_function; string[] statements = func.ExecutionQueue.ToArray(); for (int i = 0; i < statements.Length; i++) { for (int j = 0; j < _parameter_addresses.Length; j++) { statements[i] = statements[i].Replace("[" + j + "]", _parameter_addresses[j].FullPath); } } Scope _functionScope = new Scope("/" + func.Name); ICASMExecutionResult result = ICASMInterpreter.Execute(_functionScope, statements); Variable result_variable = null; if (result.Data.ContainsKey("ReturnDirective")) { result_variable = RuntimeEngine.GetVariable((Address)result.Data["ReturnDirective"]); RuntimeEngine.PutVariable(_destination_address, result_variable); } return(result_variable); }
public static ICASMDirective ParseDirective(Scope _currentScope, string statement) { statement = statement.Trim(); LiteralGrammarElement lge = new LiteralGrammarElement("import", "reflect", "ewfc", "+var", "-var", "+pool", "-pool", "+fields", "+field", "-field", "-fields", "+typespace", "-typespace", "+type", "-type", "-all", "+function", "-function", "call", "assign", "jump", "return", "clear", "if", "elseif", "else", "while", "repeat", "end+"); TestResult <bool> directiveKeywordResult = lge.Validate(ref statement, true); string directiveKeyword = (string)directiveKeywordResult["Symbol"]; statement = statement.Trim(); ICASMDirectiveType type = ICASMDirective.GetTypeFromString(directiveKeyword); ICASMTagType tag = ICASMTagType.None; if (statement.StartsWith("-")) { LiteralGrammarElement tagChecker = new LiteralGrammarElement("-help", "-path", "-none", "-suppress", "-temporary", "-random", "-report", "-variable", "-pool", "-type", "-typespace"); TestResult <bool> tagKeywordResult = tagChecker.Validate(ref statement, true); if (tagKeywordResult.Result) { string tagKeyword = (string)tagKeywordResult["Symbol"]; tag = ICASMDirective.GetTagTypeFromString(tagKeyword); } } string innerstatement = null; statement = statement.Trim(); if (type == ICASMDirectiveType.AssignDirective && statement.StartsWith("(")) { innerstatement = statement.Trim().Substring(1, statement.LastIndexOf(')') - 1).Trim(); statement = statement.Substring(statement.LastIndexOf(')') + 1).Trim(); ICASMDirective innerdirective = ICASMInterpreter.ParseDirective(_currentScope, innerstatement); ICASMExecutionResult innerresult = ICASMInterpreter.Execute(_currentScope, innerdirective); if (innerresult.Data.ContainsKey("CallDirective")) { statement = ((Address)innerresult.Data["CallDirective"]).FullPath + " " + statement; } } string[] paramstrs = statement.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); ICASMDirectiveParameters parameters = new ICASMDirectiveParameters(); string str = ""; bool stringopen = false; foreach (string param in paramstrs) { ICASMValue value = null; if (!stringopen && param.StartsWith("\"") && !param.EndsWith("\"")) { stringopen = true; str = param + " "; } else if (stringopen || (param.StartsWith("\"") && param.EndsWith("\""))) { str = str + param + " "; if (param.EndsWith("\"")) { stringopen = false; value = ICASMValue.ParseValue(str.Trim()); str = ""; } } else { value = ICASMValue.ParseValue(param); } if (value != null) { parameters.Add(value); } } return(new ICASMDirective(type, tag, parameters)); }