Skip to content

Commit

Permalink
#15 - удалил концепцию метода из бекенда
Browse files Browse the repository at this point in the history
  • Loading branch information
Stepami committed Jul 18, 2024
1 parent 9820043 commit 4d86b41
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public CallFunction(
base(null, (null, null), "Call ")
{
_function = function;
_numberOfArguments = numberOfArguments + Convert.ToInt32(function.MethodOf != null);
_numberOfArguments = numberOfArguments;
_hasReturnValue = hasReturnValue;
}

Expand All @@ -38,15 +38,6 @@ public override IAddress Execute(VirtualMachine vm)
i++;
}

if (_function.MethodOf != null)
{
var obj = (Dictionary<string, object>)frame[_function.MethodOf];
foreach (var (key, value) in obj)
{
frame[key] = value;
}
}

vm.CallStack.Push(new Call(Address, _function, args, Left));
vm.Frames.Push(frame);
return _function.Start;
Expand Down
14 changes: 0 additions & 14 deletions HydraScript.Lib/BackEnd/Instructions/WithAssignment/Simple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,6 @@ public override IAddress Execute(VirtualMachine vm)
};
}

if (vm.CallStack.Any())
{
var call = vm.CallStack.Peek();
var methodOf = call.To.MethodOf;
if (methodOf != null)
{
var methodOwner = (Dictionary<string, object>)frame[methodOf];
if (methodOwner.ContainsKey(Left))
{
methodOwner[Left] = frame[Left];
}
}
}

return Address.Next;
}

Expand Down
11 changes: 2 additions & 9 deletions HydraScript.Lib/BackEnd/VirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,15 @@ public override string ToString() =>
$"{From} => {To.Start}: {To.Id}({string.Join(", ", Parameters.Select(x => $"{x.Id}: {x.Value}"))})";
}

public record FunctionInfo(string Id, string MethodOf = null)
public record FunctionInfo(string Id)
{
public Label Start =>
new($"Start_{this}");

public Label End =>
new($"End_{this}");

public string MethodOf { get; set; } = MethodOf;

private string CallId() =>
MethodOf == null
? Id
: $"{MethodOf}.{Id}";

public override string ToString() => CallId();
public override string ToString() => Id;
}

public class Frame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public class FunctionDeclaration : AfterTypesAreLoadedDeclaration
public List<PropertyTypeValue> Arguments { get; }
public BlockStatement Statements { get; }

public ObjectLiteral Object =>
Parent as ObjectLiteral;

public FunctionDeclaration(
IdentifierReference name,
TypeValue returnTypeValue,
Expand Down
5 changes: 2 additions & 3 deletions HydraScript.Lib/IR/Ast/Visitors/InstructionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ public AddressedInstructions Visit(FunctionDeclaration visitable)
{
if (!visitable.Statements.Any())
return new();

var objectId = visitable.Object?.Id;
var functionInfo = new FunctionInfo(visitable.Name, objectId);

var functionInfo = new FunctionInfo(visitable.Name);

var result = new AddressedInstructions
{
Expand Down
13 changes: 0 additions & 13 deletions HydraScript.Tests/Unit/BackEnd/FunctionInfoTests.cs

This file was deleted.

0 comments on commit 4d86b41

Please sign in to comment.