예제 #1
0
파일: Parser.cs 프로젝트: arlm/MixEmul
        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);
        }
예제 #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())))));
 }
예제 #3
0
파일: Env.cs 프로젝트: 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
         )
     );
 }
예제 #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));
        }
예제 #5
0
 public ExprGetMethod(
     IExpr klassExpr,
     ValueSymbol selector,
     SourceInfo info
 )
 {
     KlassExpr = klassExpr;
     Selector = selector;
     mInfo = info;
 }
예제 #6
0
파일: Env.cs 프로젝트: takuto-h/rhea
 public static void AddMethod(
     this IEnv env,
     ValueSymbol klass,
     string selectorName,
     IValueFunc func
 )
 {
     env.AddMethod(
         klass, ValueSymbol.Intern(selectorName), func
     );
 }
예제 #7
0
 public ExprSetMethod(
     IExpr klassExpr,
     ValueSymbol selector,
     IExpr valueExpr,
     SourceInfo info
 )
 {
     mKlassExpr = klassExpr;
     mSelector = selector;
     mValueExpr = valueExpr;
     mInfo = info;
 }
예제 #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();
        }
예제 #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);
            }
        }
예제 #10
0
파일: Env.cs 프로젝트: 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;
 }
예제 #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);
        }
예제 #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;
                    }
                }
            }
        }
예제 #13
0
파일: EnvLocal.cs 프로젝트: takuto-h/rhea
 public bool ContainsVariable(ValueSymbol symbol)
 {
     return mInnerEnv.ContainsVariable(symbol);
 }
예제 #14
0
파일: EnvLocal.cs 프로젝트: takuto-h/rhea
 public bool TryGetMethod(ValueSymbol klass, ValueSymbol selector, out IValueFunc func)
 {
     return mInnerEnv.TryGetMethod(klass, selector, out func);
 }
예제 #15
0
파일: EnvLocal.cs 프로젝트: takuto-h/rhea
 public void AddVariable(ValueSymbol symbol, IValue value)
 {
     mInnerEnv.AddVariable(symbol, value);
 }
예제 #16
0
파일: EnvLocal.cs 프로젝트: takuto-h/rhea
 public bool ContainsMethod(ValueSymbol klass, ValueSymbol selector)
 {
     return mInnerEnv.ContainsMethod(klass, selector);
 }
예제 #17
0
파일: EnvLocal.cs 프로젝트: takuto-h/rhea
 public IValueFunc this[ValueSymbol klass, ValueSymbol selector]
 {
     get { return mInnerEnv[klass, selector]; }
     set { mInnerEnv[klass, selector] = value; }
 }
예제 #18
0
파일: EnvLocal.cs 프로젝트: takuto-h/rhea
 public void AddMethod(ValueSymbol klass, ValueSymbol selector, IValueFunc func)
 {
     mInnerEnv.AddMethod(klass, selector, func);
 }
예제 #19
0
파일: Env.cs 프로젝트: 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;
 }
예제 #20
0
파일: Env.cs 프로젝트: 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
     );
 }
예제 #21
0
 public InsnDefMethod(ValueSymbol selector, SourceInfo info)
 {
     mSelector = selector;
     mInfo = info;
 }
예제 #22
0
파일: Env.cs 프로젝트: 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;
 }
예제 #23
0
파일: Env.cs 프로젝트: 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
     );
 }
예제 #24
0
파일: Env.cs 프로젝트: 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;
 }
예제 #25
0
 public abstract ValueSymbol GetValue(ValueSymbol val_1, ValueSymbol val_2);
예제 #26
0
파일: EnvLocal.cs 프로젝트: takuto-h/rhea
 public bool TryGetVariable(ValueSymbol symbol, out IValue value)
 {
     return mInnerEnv.TryGetVariable(symbol, out value);
 }
예제 #27
0
파일: EnvLocal.cs 프로젝트: takuto-h/rhea
 public IValue this[ValueSymbol symbol]
 {
     get { return mInnerEnv[symbol]; }
     set {  mInnerEnv[symbol] = value; }
 }
예제 #28
0
파일: ExprDefVar.cs 프로젝트: takuto-h/rhea
 public ExprDefVar(ValueSymbol symbol, IExpr valueExpr, SourceInfo info)
 {
     mSymbol = symbol;
     mValueExpr = valueExpr;
     mInfo = info;
 }
예제 #29
0
파일: Env.cs 프로젝트: 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;
 }
예제 #30
0
 public override ValueSymbol GetValue(ValueSymbol val_1, ValueSymbol val_2)
 {
     return(new ValueSymbol(val_1.GetValue() - val_2.GetValue()));
 }
예제 #31
0
파일: Env.cs 프로젝트: 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;
 }
예제 #32
0
파일: InsnDefVar.cs 프로젝트: takuto-h/rhea
 public InsnDefVar(ValueSymbol symbol, SourceInfo info)
 {
     mSymbol = symbol;
     mInfo = info;
 }
예제 #33
0
파일: ExprGetVar.cs 프로젝트: takuto-h/rhea
 public ExprGetVar(ValueSymbol symbol, SourceInfo info)
 {
     Symbol = symbol;
     mInfo = info;
 }