public static HashLookup <string> DebugSymbolsForBuiltIns() { var tmp = new HashLookup <string>(64); Action <string> add = name => { tmp.Add(NanTags.GetCrushedName(name), name); }; add("="); add("equals"); add(">"); add("<"); add("<>"); add("not-equal"); add("assert"); add("random"); add("eval"); add("call"); add("not"); add("or"); add("and"); add("readkey"); add("readline"); add("print"); add("substring"); add("length"); add("replace"); add("concat"); add("+"); add("-"); add("*"); add("/"); add("%"); add("()"); return(tmp); }
/// <summary> /// Create a new value scope, copying references from a parent scope /// </summary> public Scope(Scope parentScope) { PotentialGarbage = new HashSet <double>(); _scopes = new HashLookup <double> [128]; // recursion depth limit _currentScopeIdx = 0; var global = new HashLookup <double>(); foreach (var pair in parentScope.ListAllVisible()) { global.Add(pair); // all parent refs become globals, regardless of original hierarchy } _scopes[_currentScopeIdx] = global; }
private int HandleFunctionDefinition(ushort argCount, ushort tokenCount, int position, Stack <double> valueStack) { var functionNameHash = NanTags.DecodeVariableRef(valueStack.Pop()); if (Functions.ContainsKey(functionNameHash)) { throw new Exception("Function '" + functionNameHash + "' redefined at " + position + ". Original at " + Functions[functionNameHash]); } Functions.Add(functionNameHash, new FunctionDefinition { StartPosition = position, ParamCount = argCount }); return(position + tokenCount + 1); // + definition length + terminator }
/// <summary> /// Start a new inner-most scope. /// Parameters are specially named by index (like "__p0", "__p1"). The compiler must match this. /// </summary> public void PushScope(ICollection <double> parameters = null) { unchecked { var sd = new HashLookup <double>(); var i = 0; if (parameters != null) { foreach (var parameter in parameters) { sd.Add(posParamHash[i], parameter); i++; } } _currentScopeIdx++; // TODO: check for current > length _scopes[_currentScopeIdx] = sd; } }
/// <summary> /// Symbol mapping for built-in functions /// </summary> public static HashLookup <FunctionDefinition> BuiltInFunctionSymbols() { var tmp = new HashLookup <FunctionDefinition>(64); Action <string, FuncDef> add = (name, type) => { tmp.Add(NanTags.GetCrushedName(name), new FunctionDefinition { Kind = type }); }; add("=", FuncDef.Equal); add("equals", FuncDef.Equal); add(">", FuncDef.GreaterThan); add("<", FuncDef.LessThan); add("<>", FuncDef.NotEqual); add("not-equal", FuncDef.NotEqual); add("assert", FuncDef.Assert); add("random", FuncDef.Random); add("eval", FuncDef.Eval); add("call", FuncDef.Call); add("not", FuncDef.LogicNot); add("or", FuncDef.LogicOr); add("and", FuncDef.LogicAnd); add("readkey", FuncDef.ReadKey); add("readline", FuncDef.ReadLine); add("print", FuncDef.Print); add("substring", FuncDef.Substring); add("length", FuncDef.Length); add("replace", FuncDef.Replace); add("concat", FuncDef.Concat); add("+", FuncDef.MathAdd); add("-", FuncDef.MathSub); add("*", FuncDef.MathProd); add("/", FuncDef.MathDiv); add("%", FuncDef.MathMod); add("()", FuncDef.UnitEmpty); // empty value marker return(tmp); }