Esempio n. 1
0
        public void fill_memory(byte[] b, ref int dynamic_memory_start)
        {
            int elements_struct_size = this.list.Sum(l => l.struct_size());

            this.pointer_to_list = DataExtensions.FirstAvailableSize(b, dynamic_memory_start, elements_struct_size);

            Binary.BigEndian.Set(this.list.Count, b, address.Value);
            Binary.BigEndian.Set(this.pointer_to_list, b, address.Value + 4);


            DataExtensions.FillBytes(b, this.pointer_to_list, this.pointer_to_list + elements_struct_size);

            int curr_address = this.pointer_to_list;

            foreach (var item in list)
            {
                item.address  = curr_address;
                curr_address += item.struct_size();
            }
            if (curr_address > dynamic_memory_start)
            {
                dynamic_memory_start = curr_address;
            }
            foreach (var item in list)
            {
                item.fill_memory(b, ref dynamic_memory_start);
            }
        }
Esempio n. 2
0
        public void allocate_struct(byte[] b, int start_address)
        {
            this.address = start_address;//DataExtensions.FirstAvailableSize(b, start_address, struct_size());
            int curr_address = address.Value;

            foreach (var prop in properties)
            {
                prop.allocate_struct(b, curr_address);
                curr_address += prop.struct_size();
            }
            DataExtensions.FillBytes(b, this.address.Value, curr_address);
        }
Esempio n. 3
0
        public void fill_memory(byte[] b, ref int dynamic_memory_start)
        {
            int aligned_char_length = Program.GetAligned_u32(value.Length + 1);

            this.pointer_to_string = DataExtensions.FirstAvailableSize(b, dynamic_memory_start, aligned_char_length);
            DataExtensions.FillBytes(b, this.pointer_to_string, this.pointer_to_string + aligned_char_length);
            for (int i = 0; i < value.Length; i++)
            {
                b[i + this.pointer_to_string] = (byte)this.value[i];
            }
            b[value.Length + this.pointer_to_string] = (byte)'\0';

            Binary.BigEndian.Set(this.pointer_to_string, b, address.Value);
        }
Esempio n. 4
0
        public void fill_memory(byte[] b, ref int dynamic_memory_start)
        {
            int curr_address = this.address.Value;

            foreach (var prop in this.properties)
            {
                prop.address  = curr_address;
                curr_address += prop.struct_size();
            }
            DataExtensions.FillBytes(b, this.address.Value, curr_address);
            if (curr_address > dynamic_memory_start)
            {
                dynamic_memory_start = curr_address;
            }
            //dynamic_memory_start = curr_address;
            foreach (var prop in this.properties)
            {
                prop.fill_memory(b, ref dynamic_memory_start);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Creates C_DataType based on object type
 /// </summary>
 public static C_DataType Create(object o)
 {
     if (o is JArray arr)
     {
         return(new ListProperty(arr));
     }
     else if (o is JProperty prop)
     {
         return(null);
     }
     else if (o is JObject obj)
     {
         return(new ObjectProperty(obj));
     }
     else if (o is KeyValuePair <string, JToken> objProp)
     {
         return(C_DataType_Helpers.Create(objProp.Value));
     }
     else if (o is JValue val)
     {
         if (val.Value is String strVal)
         {
             List <int> codeList;
             if (strVal.Length == 1)
             {
                 return(new CharProperty(strVal[0]));
             }
             else if (DataExtensions.IsCode(strVal, out codeList))
             {
                 return(new ListProperty(JArray.FromObject(codeList)));
             }
             else
             {
                 return(new StringProperty(strVal));
             }
         }
         else if (val.Value == null)
         {
             return(new IntProperty(0));
         }
         else if (val.Value is Int32 int32Val)
         {
             return(new IntProperty((int)int32Val));
         }
         else if (val.Value is Int64 int64Val)
         {
             return(new IntProperty((int)int64Val));
         }
         else if (val.Value is Double doubleVal)
         {
             return(new FloatProperty((float)doubleVal));
         }
         else if (val.Value is Boolean boolVal)
         {
             int boolValInt = boolVal ? 1 : 0;
             return(new IntProperty((int)boolValInt));
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
Esempio n. 6
0
 public void allocate_struct(byte[] b, int start_address)
 {
     this.address = start_address;
     DataExtensions.FillBytes(b, this.address.Value, this.address.Value + this.struct_size());
 }