Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ScriptEngine/Machine/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public struct TypeDescriptor : IEquatable<TypeDescriptor>
{
public int ID;
public string Name;
public string AlterName;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Везде в программе используем для англ. синонима термин Alias. Предлагаю сделать единообразно и в этом случае.


public override string ToString()
{
Expand Down
46 changes: 45 additions & 1 deletion src/ScriptEngine/Machine/MachineInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,51 @@ private void NewInstance(int argCount)
argValues[i] = BreakVariableLink(argValue);
}

var typeName = _operationStack.Pop().AsString();
var varType = _operationStack.Pop();
var typeName = varType.AsString();

// "Type 2" ctor args unboxing subroutine
do
{
if (varType.DataType != DataType.Type && varType.DataType != DataType.String)
{
break;
}

if (argValues.Count() > 1)
{
break;
}

if (varType.DataType == DataType.Type)
{
var typeVariable = (TypeTypeValue)((Variable)varType).Value;
typeName = typeVariable.Value.Name;
}

if (argValues.Count() == 0)
{
break;
}

if ((argValues[0] is IEnumerable<IValue>) == false)
{
break;
}

IEnumerable<IValue> boxedArgs = argValues[0] as IEnumerable<IValue>;
int argsCount = boxedArgs.Count();
IValue[] unboxedArgs = new IValue[argsCount];
int i = 0;
foreach (IValue item in boxedArgs)
{
unboxedArgs[i++] = item;
}

argValues = unboxedArgs;

} while (false);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не совсем понятна магия с do.. while(false). Для чего нужен однопроходный цикл?
И второе - не лучше ли вынесли вот этот type 2 subroutine в отдельный метод? Код вызова конструктора и так переусложнен, его неплохо бы порефакторить.


var clrType = TypeManager.GetFactoryFor(typeName);

var ctors = clrType.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public)
Expand Down
15 changes: 14 additions & 1 deletion src/ScriptEngine/Machine/TypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,33 @@ public StandartTypeManager()
foreach (var item in Enum.GetValues(typeof(DataType)))
{
DataType typeEnum = (DataType)item;
string alias;
string alias = String.Empty;
string alterAlias = String.Empty;
switch (typeEnum)
{
case DataType.Undefined:
alias = "Неопределено";
alterAlias = "Undefined";
break;
case DataType.Boolean:
alias = "Булево";
alterAlias = "Boolean";
break;
case DataType.String:
alias = "Строка";
alterAlias = "String";
break;
case DataType.Date:
alias = "Дата";
alterAlias = "Date";
break;
case DataType.Number:
alias = "Число";
alterAlias = "Number";
break;
case DataType.Type:
alias = "Тип";
alterAlias = "Type";
break;
case DataType.Object:
alias = "Object";
Expand All @@ -74,6 +81,7 @@ public StandartTypeManager()
var td = new TypeDescriptor()
{
Name = alias,
AlterName = alterAlias,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поменять на термин "Alias" (см. выше)

ID = (int)typeEnum
};

Expand Down Expand Up @@ -142,6 +150,11 @@ public TypeDescriptor RegisterType(string name, Type implementingClass)
private void RegisterType(TypeDescriptor td, Type implementingClass)
{
_knownTypesIndexes.Add(td.Name, td.ID);
if (td.AlterName != null && td.AlterName != String.Empty)
{
_knownTypesIndexes.Add(td.AlterName, td.ID);
}

_knownTypes.Add(new KnownType()
{
Descriptor = td,
Expand Down