Beispiel #1
0
        public CanCauseError <byte[]> GetData(IExpression <int>[] code, Func <string, int?> getSymbolValue, ScopeStructure <int> scope)
        {
            if (!canBeRepeated)
            {
                return(GetDataUnit(code, getSymbolValue, scope));
            }

            if (code.Length == 0)
            {
                return(CanCauseError <byte[]> .Error("Encountered {0} code with no parameters", Name));
            }

            List <byte> byteList = new List <byte>(code.Length * this.LengthInBytes);
            int         num      = code.Length / AmountOfParams;

            for (int index = 0; index < num; ++index)
            {
                CanCauseError <byte[]> dataUnit = GetDataUnit(new IExpression <int>[1] {
                    code[index]
                }, getSymbolValue, scope);

                if (dataUnit.CausedError)
                {
                    return(dataUnit.ConvertError <byte[]>());
                }

                byteList.AddRange(dataUnit.Result);
            }

            return((CanCauseError <byte[]>)byteList.ToArray());
        }
Beispiel #2
0
 public CanCauseError <byte[]> GetDataUnit(IExpression <int>[] parameters, Func <string, int?> getSymbolValue, ScopeStructure <int> scope)
 {
     byte[] code = this.baseData.Clone() as byte[];
     localLabels.Clear();
     externLabels.Clear();
     for (int index = 0; index < parameters.Length; ++index)
     {
         TemplateParameter paramTemp = this[index];
         if (paramTemp.lenght > 0)
         {
             if (scope.GetRegisteredASMCLabels().Exists(o => o == parameters[index].ToString()) && !scope.IsLocalLabelExisted(parameters[index].ToString()))
             {
                 paramTemp.InsertValues(new int [1], code);
                 AddExternLabel(paramTemp.position / 8, parameters[index].ToString());
             }
             else
             {
                 CanCauseError <int[]> values = CodeTemplate.GetValues(parameters[index], paramTemp, getSymbolValue, this.pointerMaker);
                 if (values.CausedError)
                 {
                     return(values.ConvertError <byte[]>());
                 }
                 paramTemp.InsertValues(values.Result, code);
                 if (scope.IsLocalLabelExisted(parameters[index].ToString()))
                 {
                     localLabels.Add(paramTemp.position / 8, parameters[index].ToString());
                 }
             }
         }
     }
     return((CanCauseError <byte[]>)code);
 }
        public CanCauseError <byte[]> GetData(IExpression <int>[] code, Func <string, int?> getSymbolValue)
        {
            List <byte> byteList = new List <byte>(this.GetLengthBytes(code));

            for (int index = 0; index < code.Length; ++index)
            {
                CanCauseError <int> aResult = Folding.TryFold(code[index], getSymbolValue);
                if (aResult.CausedError)
                {
                    return(aResult.ConvertError <byte[]>());
                }
                byteList.AddRange((IEnumerable <byte>)BitConverter.GetBytes((short)aResult.Result));
            }
            //int num = code.Length / this.AmountOfParams;
            return((CanCauseError <byte[]>)byteList.ToArray());
            //throw new NotImplementedException();
        }
        public CanCauseError <byte[]> GetData(IExpression <int>[] code, Func <string, int?> getSymbolValue, ScopeStructure <int> scope)
        {
            List <byte> byteList = new List <byte>(32);

            for (int index = 0; index < code.Length; ++index)
            {
                CanCauseError <int[]> values = CodeTemplate.GetValues(code[index], this.parameter, getSymbolValue, (IPointerMaker)null);
                if (values.CausedError)
                {
                    return(values.ConvertError <byte[]>());
                }
                byte[] code1 = new byte[this.parameter.LenghtInBytes];
                this.parameter.InsertValues(values.Result, code1);
                byteList.AddRange((IEnumerable <byte>)code1);
            }
            byteList.AddRange((IEnumerable <byte>) this.endingValue);
            return((CanCauseError <byte[]>)byteList.ToArray());
        }
Beispiel #5
0
        private CanCauseError <Code> GetCode(byte[] code, int currOffset, IEnumerable <Priority> prioritiesToUse)
        {
            CanCauseError <ICodeTemplate> template = this.codeStorage.FindTemplate(code, currOffset, prioritiesToUse);

            if (template.CausedError)
            {
                return(template.ConvertError <Code> ());
            }
            ICodeTemplate            result      = template.Result;
            int                      lengthBytes = result.GetLengthBytes(code, currOffset);
            CanCauseError <string[]> assembly    = result.GetAssembly(code, currOffset);

            if (assembly.CausedError)
            {
                return(assembly.ConvertError <Code> ());
            }
            return((CanCauseError <Code>) new Code(assembly.Result, result, lengthBytes, currOffset));
        }
 private CanCauseError <byte[]> GetDataUnit(IExpression <int>[] parameters, Func <string, int?> getSymbolValue)
 {
     byte[] code = this.baseData.Clone() as byte[];
     for (int index = 0; index < parameters.Length; ++index)
     {
         TemplateParameter paramTemp = this[index];
         if (paramTemp.lenght > 0)
         {
             CanCauseError <int[]> values = CodeTemplate.GetValues(parameters[index], paramTemp, getSymbolValue, this.pointerMaker);
             if (values.CausedError)
             {
                 return(values.ConvertError <byte[]>());
             }
             paramTemp.InsertValues(values.Result, code);
         }
     }
     return((CanCauseError <byte[]>)code);
 }
Beispiel #7
0
 internal static CanCauseError <int[]> GetValues(IExpression <int> parameter, TemplateParameter paramTemp, Func <string, int?> getSymbolValue, IPointerMaker pointerMaker)
 {
     int[] numArray;
     if (parameter is ExpressionList <int> )
     {
         ExpressionList <int> expressionList = parameter as ExpressionList <int>;
         numArray = new int[expressionList.ComponentCount];
         for (int index = 0; index < expressionList.ComponentCount; ++index)
         {
             CanCauseError <int> canCauseError = Folding.Fold(expressionList[index], getSymbolValue);
             if (canCauseError.CausedError)
             {
                 return(canCauseError.ConvertError <int[]>());
             }
             numArray[index] = canCauseError.Result;
         }
     }
     else
     {
         CanCauseError <int> canCauseError = Folding.Fold(parameter, getSymbolValue);
         if (canCauseError.CausedError)
         {
             return(canCauseError.ConvertError <int[]>());
         }
         if (paramTemp.pointer && pointerMaker != null)
         {
             numArray = new int[1]
             {
                 pointerMaker.MakePointer(canCauseError.Result)
             }
         }
         ;
         else
         {
             numArray = new int[1]
             {
                 canCauseError.Result
             }
         };
     }
     return((CanCauseError <int[]>)numArray);
 }