예제 #1
0
        public void SetValue(Romulus.StringSection name, LiteralValue value, bool isFixed, out Error error)
        {
            error = Error.None;

            if (assembler.CurrentPass == null)
            {
                throw new InvalidOperationException("Can only access variables when assembler is running a pass.");
            }

            bool isDollar = Romulus.StringSection.Compare(name, "$", true) == 0;

            if (isDollar)
            {
                assembler.CurrentPass.SetAddress(value.Value);
            }

            string nameString = name.ToString();
            //assembler.CurrentPass.Values.Remove(nameString);
            //assembler.CurrentPass.Values.Add(nameString, value);
            bool fixedValueError;

            assembler.CurrentPass.Values.SetValue(nameString, value, isFixed, out fixedValueError);
            if (fixedValueError)
            {
                // Todo: replace this with assembler value, or return fixedValueError somehow.
                //throw new Exception("Attempted to assign to a fixed value. This exception should be replaced with an appropriate assembler error.");
                error = new Error(ErrorCode.Value_Already_Defined, string.Format(Error.Msg_ValueAlreadyDefined_name, nameString));
            }
        }
예제 #2
0
        public bool TryGetValue(Romulus.StringSection name, out LiteralValue result)
        {
            bool isDollar = Romulus.StringSection.Compare(name, "$", true) == 0;

            if (isDollar)
            {
                result = new LiteralValue((ushort)assembler.CurrentPass.CurrentAddress, false);
                return(true);
            }

            var value = assembler.CurrentPass.Values.TryGetValue(name.ToString());

            result = value.HasValue ? value.Value : default(LiteralValue);
            return(value.HasValue);
        }
예제 #3
0
        public LiteralValue GetValue(Romulus.StringSection name)
        {
            bool isDollar = Romulus.StringSection.Compare(name, "$", true) == 0;

            if (isDollar)
            {
                return(new LiteralValue((ushort)assembler.CurrentPass.CurrentAddress, false));
            }

            LiteralValue?result;

            if (null == (result = assembler.CurrentPass.Values.TryGetValue(name.ToString())))
            {
                throw new Exception(); // Todo: Must be more specific, and handled!
            }
            return(result.Value);
        }