public override SValue Evaluate(ExecEnvironment env) { SValue v = varValue.Evaluate(env); SValue ret = v; if (!makeImmutable && v.Immutable) { ret = v.Clone(); ret.Immutable = false; } if (makeImmutable) { ret.Immutable = true; } ret.RefDict = null; ret.RefList = null; if (env.ContainsKey(varName) && env[varName].Immutable) { throw new VMException(varName + ": variable is immutable", headAtom); } env.NewVar(varName, ret); return(ret); }
public override SValue Evaluate(ExecEnvironment env) { SValue v = varValue.Evaluate(env); SValue ret = v; if (!makeImmutable && v.Immutable) { ret = v.Clone(); ret.Immutable = false; } if (makeImmutable) { ret.Immutable = true; } ret.RefDict = null; ret.RefList = null; if (nameExpr == null) { if (env.ContainsKey(varName) && env[varName].Immutable) { throw new VMException(varName + ": variable is immutable", headAtom); } if (makeImmutable) { env.NewVar(varName, ret); } else { env[varName] = ret; } } else { var n = nameExpr.Evaluate(env); if (n.RefDict?.Immutable == true || n.RefList?.Immutable == true) { throw new VMException(varName + ": variable is immutable", headAtom); } if (n.RefDict != null) { n.RefDict.Get <Dictionary <string, SValue> >()[n.RefDictKey] = ret; } else if (n.RefList != null) { n.RefList.Get <List <SValue> >()[n.RefListIndex] = ret; } else { throw new VMException("invalid variable setting", headAtom); } } return(ret); }