Example #1
0
        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);
        }
Example #2
0
 public override int GetHashCode()
 {
     return(Hash.Combine(ValueSymbol.GetHashCode(),
                         Hash.Combine(ValueExpression.GetHashCode(),
                                      Hash.Combine(ValueDiagnostics.GetHashCode(),
                                                   Hash.Combine(TypeExpression.GetHashCode(), TypeDiagnostics.GetHashCode())))));
 }
Example #3
0
File: Env.cs Project: takuto-h/rhea
 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
         )
     );
 }
Example #4
0
        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));
        }
Example #5
0
 public ExprGetMethod(
     IExpr klassExpr,
     ValueSymbol selector,
     SourceInfo info
 )
 {
     KlassExpr = klassExpr;
     Selector = selector;
     mInfo = info;
 }
Example #6
0
File: Env.cs Project: takuto-h/rhea
 public static void AddMethod(
     this IEnv env,
     ValueSymbol klass,
     string selectorName,
     IValueFunc func
 )
 {
     env.AddMethod(
         klass, ValueSymbol.Intern(selectorName), func
     );
 }
Example #7
0
 public ExprSetMethod(
     IExpr klassExpr,
     ValueSymbol selector,
     IExpr valueExpr,
     SourceInfo info
 )
 {
     mKlassExpr = klassExpr;
     mSelector = selector;
     mValueExpr = valueExpr;
     mInfo = info;
 }
Example #8
0
        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();
        }
Example #9
0
        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);
            }
        }
Example #10
0
File: Env.cs Project: takuto-h/rhea
 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;
 }
Example #11
0
        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);
        }
Example #12
0
        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;
                    }
                }
            }
        }
Example #13
0
 public bool ContainsVariable(ValueSymbol symbol)
 {
     return mInnerEnv.ContainsVariable(symbol);
 }
Example #14
0
 public bool TryGetMethod(ValueSymbol klass, ValueSymbol selector, out IValueFunc func)
 {
     return mInnerEnv.TryGetMethod(klass, selector, out func);
 }
Example #15
0
 public void AddVariable(ValueSymbol symbol, IValue value)
 {
     mInnerEnv.AddVariable(symbol, value);
 }
Example #16
0
 public bool ContainsMethod(ValueSymbol klass, ValueSymbol selector)
 {
     return mInnerEnv.ContainsMethod(klass, selector);
 }
Example #17
0
 public IValueFunc this[ValueSymbol klass, ValueSymbol selector]
 {
     get { return mInnerEnv[klass, selector]; }
     set { mInnerEnv[klass, selector] = value; }
 }
Example #18
0
 public void AddMethod(ValueSymbol klass, ValueSymbol selector, IValueFunc func)
 {
     mInnerEnv.AddMethod(klass, selector, func);
 }
Example #19
0
File: Env.cs Project: takuto-h/rhea
 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;
 }
Example #20
0
File: Env.cs Project: takuto-h/rhea
 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
     );
 }
Example #21
0
 public InsnDefMethod(ValueSymbol selector, SourceInfo info)
 {
     mSelector = selector;
     mInfo = info;
 }
Example #22
0
File: Env.cs Project: takuto-h/rhea
 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;
 }
Example #23
0
File: Env.cs Project: takuto-h/rhea
 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
     );
 }
Example #24
0
File: Env.cs Project: takuto-h/rhea
 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;
 }
Example #25
0
 public abstract ValueSymbol GetValue(ValueSymbol val_1, ValueSymbol val_2);
Example #26
0
 public bool TryGetVariable(ValueSymbol symbol, out IValue value)
 {
     return mInnerEnv.TryGetVariable(symbol, out value);
 }
Example #27
0
 public IValue this[ValueSymbol symbol]
 {
     get { return mInnerEnv[symbol]; }
     set {  mInnerEnv[symbol] = value; }
 }
Example #28
0
 public ExprDefVar(ValueSymbol symbol, IExpr valueExpr, SourceInfo info)
 {
     mSymbol = symbol;
     mValueExpr = valueExpr;
     mInfo = info;
 }
Example #29
0
File: Env.cs Project: takuto-h/rhea
 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;
 }
Example #30
0
 public override ValueSymbol GetValue(ValueSymbol val_1, ValueSymbol val_2)
 {
     return(new ValueSymbol(val_1.GetValue() - val_2.GetValue()));
 }
Example #31
0
File: Env.cs Project: takuto-h/rhea
 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;
 }
Example #32
0
 public InsnDefVar(ValueSymbol symbol, SourceInfo info)
 {
     mSymbol = symbol;
     mInfo = info;
 }
Example #33
0
 public ExprGetVar(ValueSymbol symbol, SourceInfo info)
 {
     Symbol = symbol;
     mInfo = info;
 }