Ejemplo n.º 1
0
        public void InitializeCustumTypeVariable(RefType customType, string name)
        {
            if (!(customType is RefType type))
            {
                throw new ArgumentException($"{nameof(customType)} needs to be a reference type");
            }

            if (!DataTypes.Types[DataTypes.customTypes].Any(x => x.Name == customType.Name))
            {
                throw new InvalidOperationException($"{customType.Name} is in an array type.");
            }

            if (!Types.Any(x => x.Name == type.Name))
            {
                throw new InvalidOperationException($"{customType.Name} is not in the list of available types.");
            }

            if (Variables.Any(x => x.Name == name))
            {
                throw new InvalidOperationException($"Variable with name {name} already exists");
            }

            var variable = new Variable
            {
                Name  = name,
                Type  = customType,
                Value = NextAvailableHeap.ToString()
            };

            foreach (var property in customType.Properties)
            {
                var variableOnHeap = new Variable
                {
                    Name   = $"{name}.{property.Name}",
                    Type   = property.Type,
                    Value  = property.Type.Defaultvalue,
                    Parent = variable
                };

                variable.Variables.Add(variableOnHeap);

                Ram.SetVariable(NextAvailableHeap, variableOnHeap);
                NextAvailableHeap++;
            }

            Ram.SetVariable(NextAvailableStack, variable);

            Variables.Add(variable);

            NextAvailableStack++;

            SourceCode.Add($"{customType.Name} {name} = new {customType.Name}();");
        }
Ejemplo n.º 2
0
        public void InitializeValueVariable(DataType dataType, string name, string value)
        {
            if (!(dataType is ValueType type))
            {
                throw new ArgumentException($"{nameof(dataType)} needs to be a value type");
            }

            if (!Types.Any(x => x.Name == type.Name))
            {
                throw new InvalidOperationException($"{dataType.Name} is not in the list of available types.");
            }

            if (Variables.Any(x => x.Name == name))
            {
                throw new InvalidOperationException($"Variable with name {name} already exists");
            }

            var variable = new Variable
            {
                Name  = name,
                Type  = dataType,
                Value = value == string.Empty ? dataType.Defaultvalue : value
            };

            Ram.SetVariable(NextAvailableStack, variable);

            Variables.Add(variable);

            NextAvailableStack++;

            if (dataType.Equals(DataTypes.String))
            {
                SourceCode.Add($"{dataType.Name} {name} = \"{value}\";");
            }
            else if (dataType.Equals(DataTypes.Bool))
            {
                SourceCode.Add($"{dataType.Name} {name} = {(value == "0" ? "false" : "true")};");
            }
            else
            {
                SourceCode.Add($"{dataType.Name} {name} = {value};");
            }
        }
Ejemplo n.º 3
0
        public void SetValueOfVariable(Variable variable, string value)
        {
            variable.LastChanged = true;
            LastVariableChanged  = variable;

            variable.Value = value;

            if (variable.Type.Equals(DataTypes.String))
            {
                SourceCode.Add($"{variable.Name} = \"{value}\";");
            }
            else if (variable.Type.Equals(DataTypes.Bool))
            {
                SourceCode.Add($"{variable.Name} = {(value == "0" ? "false" : "true")};");
            }
            else
            {
                SourceCode.Add($"{variable.Name} = {value};");
            }
        }
Ejemplo n.º 4
0
 public CompilationRequest WithSourceFile(string fileName, string code)
 {
     SourceCode.Add(fileName, code);
     return(this);
 }