Beispiel #1
0
        private void Load(StructureValueCollection values, ushort index, StringTableReader stringReader, int stringTableSize)
        {
            Index        = new DatumIndex((ushort)values.GetInteger("datum index salt"), index);
            Opcode       = (ushort)values.GetInteger("opcode");
            ReturnType   = (ushort)values.GetInteger("value type");
            Type         = (ScriptExpressionType)values.GetInteger("expression type");
            Next         = new DatumIndex(values.GetInteger("next expression index"));
            StringOffset = (uint)values.GetIntegerOrDefault("string table offset", 0);
            Value        = new LongExpressionValue((uint)values.GetInteger("value"));
            LineNumber   = (short)values.GetIntegerOrDefault("source line", 1);

            if (StringOffset < stringTableSize)
            {
                stringReader.RequestString(StringOffset);
            }
        }
Beispiel #2
0
        private bool IsGlobalsReference(string expectedType, ParserRuleContext context)
        {
            string text = context.GetTextSanitized();
            GlobalInfo globalInfo = _opcodes.GetGlobalInfo(text);
            IExpressionValue value;

            // Engine global.
            if(globalInfo != null)
            {
                //ushort[] arr = { 0xFFFF, globalInfo.MaskedOpcode };
                value = new LongExpressionValue(0xFFFF, globalInfo.MaskedOpcode);
            }
            // Map global.
            else if(_mapGlobalsLookup.ContainsKey(text))
            {
                globalInfo = _mapGlobalsLookup[text];
                value = new LongExpressionValue(globalInfo.Opcode);
            }
            // Not a global...
            else if (expectedType == TypeHelper.GlobalsReference)
            {
                throw new CompilerException($"A global reference was expected, but no global with the name \"{text}\" could be found.", context);
            }
            else
            {
                return false;
            }

            string returnType = DetermineReturnType(globalInfo, expectedType, context);
            ushort returnTypeOpcode = _opcodes.GetTypeInfo(returnType).Opcode;
            ushort opcode = GetGlobalOpCode(returnTypeOpcode, context);
            var expression = new ScriptExpression
            {
                Index = _currentIndex,
                Opcode = opcode,
                ReturnType = returnTypeOpcode,
                Type = ScriptExpressionType.GlobalsReference,
                Next = DatumIndex.Null,
                StringOffset = _strings.Cache(text),
                Value = value,
                LineNumber = GetLineNumber(context)
            };
            OpenDatumAddExpressionIncrement(expression);

            return true;
        }
Beispiel #3
0
 // Tag
 public ScriptExpression(DatumIndex index, ushort opcode, ushort valType, ScriptExpressionType expType,
                         uint strOffset, short line, ITag value) : this(index, opcode, valType, expType, strOffset, line)
 {
     Value = new LongExpressionValue(value);
 }