public override void Add(SymbolId key, object value) { lock (this) { EnsureData(); _data[key] = value; } }
protected override Slot CreateSlot(SymbolId name, Type type) { FieldBuilder fb = _typeGen.TypeBuilder.DefineField(SymbolTable.IdToString( name), type, FieldAttributes.Assembly | FieldAttributes.Static); return new StaticFieldSlot(fb); }
public override bool Contains(SymbolId key) { if (_data == null) return false; lock (this) { return _data.ContainsKey(key); } }
public void Define(SymbolId name, Definition definition) { if (name != SymbolTable.Empty) { current.Define(name, definition); } }
public ComparisonPattern(SymbolId symbol, object testedValue) { if (!(testedValue is IComparable)) throw new ArgumentException("testedValue must be IComparable", "testedValue"); this.ParameterName = symbol; this.TestedValue = testedValue; }
public PythonGlobal(CodeContext/*!*/ context, SymbolId name) { Assert.NotNull(context); _value = Uninitialized.Instance; _context = context; _name = name; }
public PythonTypeChangedEventArgs(CodeContext context, SymbolId changed, ChangeType type, object previous, object newValue) { _context = context; _changed = changed; _type = type; _previous = previous; _newValue = newValue; }
public BonsaiPrototypeFunction(SymbolId? name = null, BonsaiPrototypeFunction prototype = null) : base(null) { if (name.HasValue) this.Name = name.Value; else this.Name = "«unnamed»".ToSymbol(); if (prototype == null) { foreach (MethodInfo method in this.GetType().GetMethods( BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static )) { var attrs = method.GetCustomAttributes(typeof(MapsToSymbolAttribute), false); foreach (MapsToSymbolAttribute mapper in attrs) { this.Dict.Add( mapper.Symbol, new DelegateBonsaiFunction((Func<object[], object>)Delegate.CreateDelegate( typeof(Func<object[], object>), method.IsStatic ? null : this, method))); } } } else { this.Dict = new SortedList<SymbolId, object>(prototype.Dict); } }
protected override bool TryGetExtraValue(SymbolId key, out object value) { if (key == _viewSymbol) { value = _view; return true; } var property = _viewType.GetProperty(key.ToString()); if (property != null) { value = property.GetValue(_view, null); return true; } var field = _viewType.GetField(key.ToString()); if (field != null) { value = field.GetValue(_view); return true; } if (_view.TryGetViewData(key.ToString(), out value)) return true; value = null; return false; }
public PythonVariable(SymbolId name, Type/*!*/ type, VariableKind kind, ScopeStatement/*!*/ scope) { Assert.NotNull(type, scope); _name = name; _type = type; _kind = kind; _scope = scope; }
public MemberTracker TryGetPackageLazy(SymbolId name) { MemberTracker ret; if (_dict.TryGetValue(SymbolTable.IdToString(name), out ret)) { return ret; } return null; }
public static object Method(object[] args) { Debug.Assert(args.Length >= 3, "A call to «method» should have at least two parameters: the name of the method and its block"); Debug.Assert(args[0] is DictionaryBonsaiFunction); for (int i = 1; i < args.Length - 1; i++) Debug.Assert(args[i] is SymbolId, "Argument " + i + " should be a SymbolId"); Debug.Assert(args[args.Length - 1] is BlockBonsaiFunction, "The last arguments should be a block"); var scope = (DictionaryBonsaiFunction)args[0]; var name = (SymbolId)args[1]; var block = (BlockBonsaiFunction)args[args.Length - 1]; var self = (BonsaiPrototypeFunction)scope["self"]; var parameters = new SymbolId[args.Length - 3]; for (int i = 2; i < args.Length - 1; i++) parameters[i - 2] = (SymbolId)args[i]; self[name] = new DelegateBonsaiFunction(callArgs => { Debug.Assert(callArgs.Length - 1 == parameters.Length, "The number of arguments should equal the number of parameters"); var blockLocalVariables = new DictionaryBonsaiFunction(); for (int i = 0; i < parameters.Length; i++) { blockLocalVariables[parameters[i]] = callArgs[i + 1]; } var callSelf = ((DictionaryBonsaiFunction)callArgs[0])["self"]; blockLocalVariables["self"] = callSelf; return block.Invoke(blockLocalVariables); }); return self[name]; }
protected override bool TryGetExtraValue(SymbolId key, out object value) { var property = _viewType.GetProperty(key.ToString()); if (property != null) { value = property.GetValue(_view, null); return true; } var field = _viewType.GetField(key.ToString()); if (field != null) { value = field.GetValue(_view); return true; } var method = _viewType.GetMethod(key.ToString()); if (method != null) { var parameterTypes = method.GetParameters().Select(p => p.ParameterType).ToList(); parameterTypes.Add(method.ReturnType); value = Delegate.CreateDelegate( CompilerHelpers.MakeCallSiteDelegateType(parameterTypes.ToArray()), _view, key.ToString()); return true; } if (_view.TryGetViewData(key.ToString(), out value)) return true; value = null; return false; }
public ParameterWrapper(ActionBinder binder, ParameterInfo info) : this(binder, info.ParameterType) { _name = SymbolTable.StringToId(info.Name ?? "<unknown>"); _isParams = info.IsDefined(typeof(ParamArrayAttribute), false); }
public NamespaceTracker TryGetPackage(SymbolId name) { NamespaceTracker pm = TryGetPackageAny(name) as NamespaceTracker; if (pm != null) { return pm; } return null; }
public MemberTracker TryGetPackageAny(SymbolId name) { MemberTracker ret; if (TryGetValue(name, out ret)) { return ret; } return null; }
public FromImportStatement(ModuleName root, SymbolId[] names, SymbolId[] asNames, bool fromFuture, bool forceAbsolute) { _root = root; _names = names; _asNames = asNames; _fromFuture = fromFuture; _forceAbsolute = forceAbsolute; }
internal VariableInfo(SymbolId symbol, Type type, bool parameter, bool hidden, bool strongBoxed) : this(symbol, type, parameter, hidden, strongBoxed, Int32.MaxValue, Int32.MaxValue) { _symbol = symbol; _type = type; _parameter = parameter; _hidden = hidden; _strongBoxed = strongBoxed; }
public override bool Contains(SymbolId key) { foreach (Scope scope in GetVisibleScopes()) { if (scope.ContainsVariable(key)) { return true; } } return false; }
public override bool Contains(SymbolId key) { int ikey = FindKey(key); if (ikey != -1) { return _values[ikey] != Uninitialized.Instance; } return base.Contains(key); }
public static void SetPropertyHelper(object prop, object instance, object newValue, SymbolId name) { PythonTypeSlot desc = prop as PythonTypeSlot; if (desc == null) { throw PythonOps.TypeError("Expected settable property for {0}, but found {1}", name.ToString(), DynamicHelpers.GetPythonType(prop).Name); } desc.TrySetValue(DefaultContext.Default, instance, DynamicHelpers.GetPythonType(instance), newValue); }
public CustomOldClassDictionaryStorage(SymbolId[] extraKeys, int keyVersion) { _extraKeys = extraKeys; _keyVersion = keyVersion; _values = new object[extraKeys.Length]; for (int i = 0; i < _values.Length; i++) { _values[i] = Uninitialized.Instance; } }
public ClassEnvironmentReference(Type storageType, SymbolId name, Type type) { Debug.Assert(storageType != null); _storageType = storageType; _name = name; _type = type; }
public ParamsDictArgBuilder(ParameterInfo info, int argIndex, SymbolId[] names, int[] nameIndexes) : base(info) { Assert.NotNull(names, nameIndexes); _argIndex = argIndex; _names = names; _nameIndexes = nameIndexes; }
public override void Add(SymbolId key, object value) { int ikey = FindKey(key); if (ikey != -1) { _values[ikey] = value; } else { base.Add(key, value); } }
protected override bool TrySetExtraValue(SymbolId key, object value) { for (int i = 0; i < _args.Length; i++) { if (_args[i] == key) { _boxes[i].Value = value; return true; } } return false; }
public void TestAdd () { JSObject o = new JSObject (null); SymbolId si = new SymbolId (0); o.Add (si, 1); Assert.AreEqual (1, o.Count, "A1"); Assert.IsTrue (o.ContainsKey (si), "A2"); }
internal Node Scalar(MutableString taguri, MutableString value, SymbolId style) { return Scalar( taguri != null ? taguri.ConvertToString() : "", value != null ? value.ConvertToString() : "", //It's not clear what style argument really means, it seems to be always :plain //for now we are ignoring it, defaulting to \0 (see Representer class) '\0' ); }
internal static Expression GetExpression(SymbolId value) { if (value == SymbolId.Empty) { return _SymbolIdEmpty; } else if (value == SymbolId.Invalid) { return _SymbolIdInvalid; } else { return Expression.New(_SymbolIdCtor, Expression.Constant(value.Id)); } }
private int _globalIndex; // Index within the combined list internal VariableInfo(SymbolId symbol, Type type, bool parameter, bool hidden, bool strongBoxed, int localIndex, int globalIndex) { _symbol = symbol; _type = type; _parameter = parameter; _hidden = hidden; _strongBoxed = strongBoxed; _localIndex = localIndex; _globalIndex = globalIndex; }
public void Add(SymbolId symbol, RxNode <TLetter> regex) { this.tokens.Add(symbol, regex); }
public static SymbolId ToSymbol(SymbolId self) { return(self); }
public static MutableString /*!*/ ToString(SymbolId self) { return(MutableString.Create(SymbolTable.IdToString(self))); }
protected SingleSymbolEffect(SymbolId symbolId, Func <int, int> effectApplication) { SymbolId = symbolId; this.effectApplication = PreconditionUtils.EnsureNotNull(effectApplication, "effectApplication"); }
protected internal abstract bool TryGetExtraValue(SymbolId key, out object value);
/// <summary> /// Called from generated code, helper to do name assignment /// </summary> public static object SetName(CodeContext context, SymbolId name, object value) { context.LanguageContext.SetName(context, name, value); return(value); }
// throws SerializationException public virtual bool TryGetVariable(IScriptEngine engine, SymbolId name, out object value) { Debug.Assert(_remoteHost != null); return(_remoteHost.TryGetVariable(RemoteWrapper.WrapRemotable <IScriptEngine>(engine), name, out value)); }
public SetFalse(SymbolId symbolId) : base(symbolId, (initialValue) => 0) { }
private IList <Inferred> InferBuiltin(SymbolId name) { return(module.InferBuiltin(name, this)); }
public static IList <FunctionInfo> InferMethods(Module module, SymbolId name, Scope scope) { return(new Engine(module, false).InferMethods(name, scope)); }
public IsInRange(SymbolId symbolId, ValueRange range) { this.symbolId = symbolId; this.range = range; }
public static UnboundAssignment Assign(SymbolId name, Expression value) { Contract.Requires(!name.IsEmpty && !name.IsInvalid, "name", "Invalid or empty name is not allowed"); Contract.RequiresNotNull(value, "value"); return(new UnboundAssignment(name, value)); }
internal UnboundAssignment(SymbolId name, Expression /*!*/ value) : base(AstNodeType.UnboundAssignment) { _name = name; _value = value; }
public static UnboundExpression Read(SymbolId name) { Contract.Requires(!name.IsInvalid && !name.IsEmpty, "name", "Invalid or empty name is not allowed"); return(new UnboundExpression(name)); }
internal UnboundExpression(SymbolId name) : base(AstNodeType.UnboundExpression) { _name = name; }
public IsFalse(SymbolId symbolId) //: base(symbolId, (value) => value == 0, (value) => (value != 0) ? 1.0 : 0.0) : base(symbolId, ValueRange.Exactly(0)) { }
public void Add(SymbolId symbol, RangeSet <TLetter> matchSet) { this.Add(symbol, new RxMatch <TLetter>(matchSet)); }
public static OldSetMemberAction Make(ActionBinder binder, SymbolId name) { ContractUtils.RequiresNotNull(binder, "binder"); return(new OldSetMemberAction(binder, name)); }
/// <summary> /// Called from generated code, helper to do name lookup /// </summary> public static object LookupName(CodeContext context, SymbolId name) { return(context.LanguageContext.LookupName(context, name)); }
private OldSetMemberAction(ActionBinder binder, SymbolId name) : base(binder, name) { }
public override Expression Generate(object args, CodeBlock c) { var ns = ClrGenerator.SaveReferences(); Cons name = (args as Cons).car as Cons; bool isprogram = name == null; string[] fullname = Array.ConvertAll <object, string>(Builtins.ListToVector(name), SymbolToString); string n = string.Join(".", fullname); NameHint = SymbolTable.StringToId(n); CodeBlock cb = Ast.CodeBlock(SpanHint, GetLambdaName(c)); cb.IsGlobal = true; List <SymbolId> vars = new List <SymbolId>(); List <Variable> locals = new List <Variable>(); List <Expression> assignments = new List <Expression>(); List <object> defs = new List <object>(); List <object> bodies = new List <object>(); List <object> sources = new List <object>(); args = (args as Cons).cdr; Cons a = (args as Cons).car as Cons; while (a != null) { Cons d = a.car as Cons; SymbolId v = (SymbolId)d.car; SymbolId l = (SymbolId)((Cons)d.cdr).car; vars.Add(l); locals.Add(Create(v, cb, typeof(object))); defs.Add(((Cons)((Cons)d.cdr).cdr).car); a = a.cdr as Cons; } #if DONE // pass 0 - record defs for (int i = 0; i < vars.Count; i++) { if (IsMakeRecord(defs[i])) { //Debugger.Break(); Type type = CreateRecordType(defs[i] as Cons); if (type != null) { ClrGenerator.AddCompileTimeType(type); } } } #endif List <Statement> stmts = new List <Statement>(); // pass 1 for (int i = 0; i < vars.Count; i++) { sources.Add(null); bool annotated, typed; if (IsLambda(defs[i], out annotated, out typed)) { Cons cl = defs[i] as Cons; sources[i] = Copy(cl); int depth = GetDepth(sources[i]); if (depth > 10) { sources[i] = null; } if (annotated) { cl = cl.cdr as Cons; } if (cl.cdr != null) { if (((Cons)cl.cdr).cdr == null) { Cons bh = (Cons)((Cons)cl.cdr).car; if (typed) { bh = bh.cdr as Cons; } Cons b = bh.cdr as Cons; bh.cdr = new Cons(Builtins.FALSE); bodies.Add(b); } else { List <Cons> cbs = new List <Cons>(); Cons cc = cl.cdr as Cons; while (cc != null) { Cons bh = (Cons)cc.car; if (typed) { bh = bh.cdr as Cons; } Cons b = bh.cdr as Cons; bh.cdr = new Cons(Builtins.FALSE); cbs.Add(b); cc = cc.cdr as Cons; } bodies.Add(cbs); } } else { bodies.Add(null); } } else { bodies.Add(null); } VarHint = locals[i].Name; VarHint2 = vars[i]; NameHint = SymbolTable.StringToId(n + "::" + Builtins.UnGenSymInternal(vars[i])); Expression e = GetAst(defs[i], cb); VarHint = VarHint2 = SymbolId.Empty; if (e is UnaryExpression && e.NodeType == AstNodeType.Convert && e.Type != typeof(object)) { locals[i].Type = e.Type; } else if (e.Type.IsValueType) { e = Ast.ConvertHelper(e, typeof(object)); } assignments.Add(e); if (e is MethodCallExpression) { MethodCallExpression mce = e as MethodCallExpression; if (mce.Method == Closure_Make) { var cbe = mce.Arguments[0] as CodeBlockExpression; cbe.Block.Source = sources[i]; libraryglobals.Add(locals[i].Name, cbe); libraryglobals.Add(vars[i], cbe); } else if (mce.Method == Closure_MakeVarArgsX) { libraryglobalsX.Add(locals[i].Name, mce.Arguments[0] as CodeBlockExpression); libraryglobalsX.Add(vars[i], mce.Arguments[0] as CodeBlockExpression); } else if (mce.Method == Closure_MakeCase) { NewArrayExpression tcs = mce.Arguments[0] as NewArrayExpression; List <CodeBlockDescriptor> cdbs = new List <CodeBlockDescriptor>(); foreach (CodeBlockExpression tc in tcs.Expressions) { //where do we clean this up?? cdbs.Add(descriptorshack[tc]); } libraryglobalsN.Add(locals[i].Name, cdbs.ToArray()); libraryglobalsN.Add(vars[i], cdbs.ToArray()); } else if (mce.Method == Closure_MakeTypedCase) { NewArrayExpression tcs = mce.Arguments[0] as NewArrayExpression; List <CodeBlockDescriptor> cdbs = new List <CodeBlockDescriptor>(); foreach (Expression tc in tcs.Expressions) { //where do we clean this up?? cdbs.Add(descriptorshack2[tc]); } libraryglobalsN.Add(locals[i].Name, cdbs.ToArray()); libraryglobalsN.Add(vars[i], cdbs.ToArray()); } } else if (e is NewExpression) { NewExpression ne = e as NewExpression; if (typeof(ITypedCallable).IsAssignableFrom(e.Type)) { libraryglobals.Add(locals[i].Name, ne.Arguments[0] as CodeBlockExpression); libraryglobals.Add(vars[i], ne.Arguments[0] as CodeBlockExpression); } } } // pass 2, expand lambda bodies for (int i = 0; i < vars.Count; i++) { Expression e = assignments[i]; NameHint = SymbolTable.StringToId(n + "::" + Builtins.UnGenSymInternal(vars[i])); if (bodies[i] != null) { CodeBlockDescriptor[] cbds; CodeBlockExpression cbe; if (libraryglobals.TryGetValue(locals[i].Name, out cbe)) { Cons b = bodies[i] as Cons; CodeBlock cbody = cbe.Block; cbody.Body = null; FillBody(cbody, new List <Statement>(), b, true); } else if (libraryglobalsX.TryGetValue(locals[i].Name, out cbe)) { Cons b = bodies[i] as Cons; CodeBlock cbody = cbe.Block; cbody.Body = null; FillBody(cbody, new List <Statement>(), b, true); } else if (libraryglobalsN.TryGetValue(locals[i].Name, out cbds)) { List <Cons> b = bodies[i] as List <Cons>; for (int j = 0; j < b.Count; j++) { CodeBlock cbody = cbds[j].codeblock.Block; cbody.Body = null; FillBody(cbody, new List <Statement>(), b[j], true); } } } stmts.Add(Ast.Write(locals[i], e)); // needed indeed if (!isprogram) { stmts.Add(Ast.Statement(Ast.SimpleCallHelper(SetSymbolValue, Ast.Constant(vars[i]), Ast.Read(locals[i])))); } } Cons body = Builtins.Cdr(args) as Cons; FillBody(cb, stmts, body, true); cb.ExplicitCodeContextExpression = Ast.CodeContext(); #if OPTIMIZATIONS Expression ex = InlineCall(c, Ast.CodeBlockExpression(cb, false)); #else Expression ex = Ast.SimpleCallHelper(MakeClosure(cb, false), GetCallable(0)); #endif NameHint = SymbolId.Invalid; ClrGenerator.ResetReferences(ns); return(ex); }
public void Add(SymbolId symbol, params TLetter[] matchSet) { this.Add(symbol, new RxMatch <TLetter>(matchSet)); }
public static MutableString /*!*/ Inspect(SymbolId self) { var str = SymbolTable.IdToString(self); // simple cases: if ( Tokenizer.IsMethodName(str) || Tokenizer.IsConstantName(str) || Tokenizer.IsInstanceVariableName(str) || Tokenizer.IsClassVariableName(str) || Tokenizer.IsGlobalVariableName(str) ) { return(MutableString.CreateMutable(":", 1 + str.Length).Append(str)); } // TODO: this is neither efficient nor complete. // Any string that parses as 'sym' should not be quoted. switch (str) { case null: // Ruby doesn't allow empty symbols, we can get one from outside though: return(MutableString.Create(":\"\"")); case "|": case "^": case "&": case "<=>": case "==": case "===": case "=~": case ">": case ">=": case "<": case "<=": case "<<": case ">>": case "+": case "-": case "*": case "/": case "%": case "**": case "~": case "+@": case "-@": case "[]": case "[]=": case "`": case "$!": case "$@": case "$,": case "$;": case "$/": case "$\\": case "$*": case "$$": case "$?": case "$=": case "$:": case "$\"": case "$<": case "$>": case "$.": case "$~": case "$&": case "$`": case "$'": case "$+": return(MutableString.CreateMutable(":", 1 + str.Length).Append(str)); } return(MutableString.CreateMutable(":\"", 3 + str.Length).Append(str).Append('"')); }
public static int ToInteger(SymbolId self) { return(self.Id); }
public static string ToClrString(SymbolId self) { return(SymbolTable.IdToString(self)); }
public override bool TryGetItem(SymbolId name, out object value) { return(base.TryGetItem(name, out value)); }
protected override void TokenAction(SymbolId symbolId, Capture <TLetter> value) { this.tokenAction?.Invoke(symbolId, value); }
public IsTrue(SymbolId symbolId) : base(symbolId, ValueRange.Exactly(True)) { }
public ArgumentDefinition(SymbolId name, FoxPro.Compiler.Ast.FunctionDefinition function, int argument) { this.name = name; this.function = function; this.argument = argument; }
public void Add(SymbolId symbol, string regex, bool caseSensitive = true) { this.Add(symbol, RegexParser.Parse(regex, symbol).ToInvariant(this.mapper, this.provider, caseSensitive)); }