static SymbolBase ParseLocField(string locField, ParsingStatus status) { if (locField == "") { return(null); } status.LineSection = LineSection.LocationField; var symbol = ValueSymbol.ParseDefinition(locField, 0, status); if (symbol == null) { status.ReportParsingError(0, locField.Length, "invalid symbol name"); return(null); } if (status.Symbols.Contains(symbol)) { symbol = status.Symbols[symbol.Name]; if (symbol.IsSymbolDefined && !symbol.IsMultiValuedSymbol) { status.ReportParsingError(0, locField.Length, "symbol already defined"); return(null); } return(symbol); } status.Symbols.Add(symbol); return(symbol); }
public override int GetHashCode() { return(Hash.Combine(ValueSymbol.GetHashCode(), Hash.Combine(ValueExpression.GetHashCode(), Hash.Combine(ValueDiagnostics.GetHashCode(), Hash.Combine(TypeExpression.GetHashCode(), TypeDiagnostics.GetHashCode()))))); }
public static void AddMethod( this IEnv env, ValueSymbol klass, string selectorName, Subr subrValue, int paramCount = 0, bool allowRest = false, bool allowKeys = false ) { string subrName = string.Format( "{0}:{1}", klass.Name.ToIdentifier(), selectorName.ToIdentifier() ); AddMethod( env, klass, selectorName, new ValueSubr( subrName, subrValue, paramCount, allowRest, allowKeys ) ); }
public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status) { if (text.Length == 0) { return(new NumberValue(0L)); } // it can be either a literal value... var value = ValueSymbol.ParseValue(text, sectionCharIndex, status); if (value != null) { return(value); } // ... a literal constant... value = LiteralConstantSymbol.ParseValue(text, sectionCharIndex, status); if (value != null) { return(value); } // ... or an expression return(ExpressionValue.ParseValue(text, sectionCharIndex, status)); }
public ExprGetMethod( IExpr klassExpr, ValueSymbol selector, SourceInfo info ) { KlassExpr = klassExpr; Selector = selector; mInfo = info; }
public static void AddMethod( this IEnv env, ValueSymbol klass, string selectorName, IValueFunc func ) { env.AddMethod( klass, ValueSymbol.Intern(selectorName), func ); }
public ExprSetMethod( IExpr klassExpr, ValueSymbol selector, IExpr valueExpr, SourceInfo info ) { mKlassExpr = klassExpr; mSelector = selector; mValueExpr = valueExpr; mInfo = info; }
void MSetButton_Click(object sender, EventArgs e) { if (mSymbols == null) { mSymbols = new SymbolCollection(); } string symbolName = mSymbolNameTextBox.Text; long symbolMagnitude = mSymbolValueTextBox.Magnitude; Word.Signs symbolSign = mSymbolValueTextBox.Sign; SymbolBase symbol = mSymbols[symbolName]; ValueSymbol valueSymbol = null; if (symbol != null) { valueSymbol = symbol as ValueSymbol; if (valueSymbol == null) { return; } valueSymbol.SetValue(symbolSign, symbolMagnitude); var valueText = symbolMagnitude.ToString(); if (symbolSign.IsNegative()) { valueText = '-' + valueText; } mListView.Items[symbolName].SubItems[valueFieldIndex].Text = valueText; } else { valueSymbol = ValueSymbol.ParseDefinition(symbolName) as ValueSymbol; if (valueSymbol == null) { return; } valueSymbol.SetValue(symbolSign, symbolMagnitude); mSymbols.Add(valueSymbol); ShowSymbol(valueSymbol); } SetEnabledStates(); }
private IValueSymbol GetIValueSymbol(ISymbolLoader loader, ValueSymbol symbol) { try { // get value symbol IValueSymbol valueSymbol = (IValueSymbol)loader.Symbols[symbol.InstancePath]; if (valueSymbol == null) { return(null); } // set the nofication valueSymbol.NotificationSettings = new NotificationSettings(AdsTransMode.OnChange, symbol.CycleTime, symbol.MaxDelay); return(valueSymbol); } catch (System.Exception) { return(null); } }
public static void DefineMethod( this IEnv env, ValueSymbol klass, ValueSymbol selector, IValueFunc func, SourceInfo info ) { /*if (env.ContainsMethod(klass, selector)) { throw new RheaException( string.Format( "method is already defined: {0}:{1}", klass.Name.ToIdentifier(), selector.Name.ToIdentifier() ), info ); } env.AddMethod(klass, selector, func);*/ env[klass, selector] = func; }
public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status) { IValue value = null; value = NumberValue.ParseValue(text, sectionCharIndex, status); if (value == null) { value = LocationCounterValue.ParseValue(text, sectionCharIndex, status); if (value != null) { return(value); } value = ValueSymbol.ParseValue(text, sectionCharIndex, status); if (value != null && !value.IsValueDefined(status.LocationCounter)) { status.ReportParsingError(sectionCharIndex, text.Length, "symbol " + text + " not defined"); } } return(value); }
void SetEnabledStates(bool updateSelectedItem) { string symbolName = mSymbolNameTextBox.Text; mSetButton.Enabled = ValueSymbol.IsValueSymbolName(symbolName) && mSymbolValueTextBox.TextLength > 0; mUnsetButton.Enabled = mSymbols != null && mSymbols.Contains(symbolName); if (updateSelectedItem) { if (mUnsetButton.Enabled) { ListViewItem symbolItem = mListView.Items[symbolName]; symbolItem.Selected = true; symbolItem.EnsureVisible(); } else { foreach (ListViewItem item in mListView.Items) { item.Selected = false; } } } }
public bool ContainsVariable(ValueSymbol symbol) { return mInnerEnv.ContainsVariable(symbol); }
public bool TryGetMethod(ValueSymbol klass, ValueSymbol selector, out IValueFunc func) { return mInnerEnv.TryGetMethod(klass, selector, out func); }
public void AddVariable(ValueSymbol symbol, IValue value) { mInnerEnv.AddVariable(symbol, value); }
public bool ContainsMethod(ValueSymbol klass, ValueSymbol selector) { return mInnerEnv.ContainsMethod(klass, selector); }
public IValueFunc this[ValueSymbol klass, ValueSymbol selector] { get { return mInnerEnv[klass, selector]; } set { mInnerEnv[klass, selector] = value; } }
public void AddMethod(ValueSymbol klass, ValueSymbol selector, IValueFunc func) { mInnerEnv.AddMethod(klass, selector, func); }
public static IValue GetVariable( this IEnv env, ValueSymbol symbol, SourceInfo info ) { IValue value; if (!LookupVariable(env, symbol, out value)) { throw new RheaException( string.Format( "variable is not defined: {0}", symbol.Name.ToIdentifier() ), info ); } return value; }
public static IValue SetVariable( this IEnv env, ValueSymbol symbol, IValue value, SourceInfo info ) { while (!env.IsGlobal()) { if (env.ContainsVariable(symbol)) { env[symbol] = value; return value; } env = env.OuterEnv; } if (env.ContainsVariable(symbol)) { env[symbol] = value; return value; } throw new RheaException( string.Format( "variable is not defined: {0}", symbol.Name.ToIdentifier() ), info ); }
public InsnDefMethod(ValueSymbol selector, SourceInfo info) { mSelector = selector; mInfo = info; }
public static bool LookupVariable( this IEnv env, ValueSymbol symbol, out IValue value ) { while (!env.IsGlobal()) { if (env.TryGetVariable(symbol, out value)) { return true; } env = env.OuterEnv; } if (env.TryGetVariable(symbol, out value)) { return true; } return false; }
public static IValue SetMethod( this IEnv env, ValueSymbol klass, ValueSymbol selector, IValueFunc func, SourceInfo info ) { while (!env.IsGlobal()) { if (env.ContainsMethod(klass, selector)) { env[klass, selector] = func; return func; } env = env.OuterEnv; } if (env.ContainsMethod(klass, selector)) { env[klass, selector] = func; return func; } throw new RheaException( string.Format( "method is not defined: {0}:{1}", klass.Name.ToIdentifier(), selector.Name.ToIdentifier() ), info ); }
public static void DefineVariable( this IEnv env, ValueSymbol symbol, IValue value, SourceInfo info ) { /*if (env.ContainsVariable(symbol)) { throw new RheaException( string.Format( "variable is already defined: {0}", symbol.Name.ToIdentifier() ), info ); } env.AddVariable(symbol, value);*/ env[symbol] = value; }
public abstract ValueSymbol GetValue(ValueSymbol val_1, ValueSymbol val_2);
public bool TryGetVariable(ValueSymbol symbol, out IValue value) { return mInnerEnv.TryGetVariable(symbol, out value); }
public IValue this[ValueSymbol symbol] { get { return mInnerEnv[symbol]; } set { mInnerEnv[symbol] = value; } }
public ExprDefVar(ValueSymbol symbol, IExpr valueExpr, SourceInfo info) { mSymbol = symbol; mValueExpr = valueExpr; mInfo = info; }
public static IValue GetMethod( this IEnv env, ValueSymbol klass, ValueSymbol selector, SourceInfo info ) { IValueFunc func; if (!LookupMethod(env, klass, selector, out func)) { throw new RheaException( string.Format( "method is not defined: {0}:{1}", klass.Name.ToIdentifier(), selector.Name.ToIdentifier() ), info ); } return func; }
public override ValueSymbol GetValue(ValueSymbol val_1, ValueSymbol val_2) { return(new ValueSymbol(val_1.GetValue() - val_2.GetValue())); }
public static bool LookupMethod( this IEnv env, ValueSymbol klass, ValueSymbol selector, out IValueFunc func ) { while (!env.IsGlobal()) { if (env.TryGetMethod(klass, selector, out func)) { return true; } env = env.OuterEnv; } if (env.TryGetMethod(klass, selector, out func)) { return true; } return false; }
public InsnDefVar(ValueSymbol symbol, SourceInfo info) { mSymbol = symbol; mInfo = info; }
public ExprGetVar(ValueSymbol symbol, SourceInfo info) { Symbol = symbol; mInfo = info; }