-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
144 changed files
with
4,399 additions
and
4,543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
namespace Interpreter.Lib.BackEnd.Instructions | ||
namespace Interpreter.Lib.BackEnd.Instructions; | ||
|
||
public class BeginFunction : Instruction | ||
{ | ||
public class BeginFunction : Instruction | ||
{ | ||
private readonly FunctionInfo _function; | ||
private readonly FunctionInfo _function; | ||
|
||
public BeginFunction(int number, FunctionInfo function) : base(number) | ||
{ | ||
_function = function; | ||
} | ||
public BeginFunction(int number, FunctionInfo function) : base(number) | ||
{ | ||
_function = function; | ||
} | ||
|
||
public override int Execute(VirtualMachine vm) => Number + 1; | ||
public override int Execute(VirtualMachine vm) => Number + 1; | ||
|
||
protected override string ToStringRepresentation() => $"BeginFunction {_function.CallId()}"; | ||
} | ||
protected override string ToStringRepresentation() => $"BeginFunction {_function.CallId()}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,47 @@ | ||
namespace Interpreter.Lib.BackEnd.Instructions | ||
namespace Interpreter.Lib.BackEnd.Instructions; | ||
|
||
public class CallFunction : Simple | ||
{ | ||
public class CallFunction : Simple | ||
{ | ||
private readonly FunctionInfo _function; | ||
private readonly int _numberOfArguments; | ||
private readonly FunctionInfo _function; | ||
private readonly int _numberOfArguments; | ||
|
||
public CallFunction(FunctionInfo function, int number, int numberOfArguments, string left = null) : | ||
base(left, (null, null), "Call ", number) | ||
{ | ||
_function = function; | ||
_numberOfArguments = numberOfArguments + Convert.ToInt32(function.MethodOf != null); | ||
} | ||
public CallFunction(FunctionInfo function, int number, int numberOfArguments, string left = null) : | ||
base(left, (null, null), "Call ", number) | ||
{ | ||
_function = function; | ||
_numberOfArguments = numberOfArguments + Convert.ToInt32(function.MethodOf != null); | ||
} | ||
|
||
public override int Jump() => _function.Location; | ||
public override int Jump() => _function.Location; | ||
|
||
public override int Execute(VirtualMachine vm) | ||
{ | ||
var frame = new Frame(Number + 1, vm.Frames.Peek()); | ||
public override int Execute(VirtualMachine vm) | ||
{ | ||
var frame = new Frame(Number + 1, vm.Frames.Peek()); | ||
|
||
var i = 0; | ||
var args = new List<(string Id, object Value)>(); | ||
while (i < _numberOfArguments) | ||
{ | ||
args.Add(vm.Arguments.Pop()); | ||
frame[args[i].Id] = args[i].Value; | ||
i++; | ||
} | ||
var i = 0; | ||
var args = new List<(string Id, object Value)>(); | ||
while (i < _numberOfArguments) | ||
{ | ||
args.Add(vm.Arguments.Pop()); | ||
frame[args[i].Id] = args[i].Value; | ||
i++; | ||
} | ||
|
||
if (_function.MethodOf != null) | ||
if (_function.MethodOf != null) | ||
{ | ||
var obj = (Dictionary<string, object>) frame[_function.MethodOf]; | ||
foreach (var (key, value) in obj) | ||
{ | ||
var obj = (Dictionary<string, object>) frame[_function.MethodOf]; | ||
foreach (var (key, value) in obj) | ||
{ | ||
frame[key] = value; | ||
} | ||
frame[key] = value; | ||
} | ||
|
||
vm.CallStack.Push(new Call(Number, _function, args, Left)); | ||
vm.Frames.Push(frame); | ||
return _function.Location; | ||
} | ||
|
||
protected override string ToStringRepresentation() => Left == null | ||
? $"Call {_function}, {_numberOfArguments}" | ||
: $"{Left} = Call {_function}, {_numberOfArguments}"; | ||
vm.CallStack.Push(new Call(Number, _function, args, Left)); | ||
vm.Frames.Push(frame); | ||
return _function.Location; | ||
} | ||
|
||
protected override string ToStringRepresentation() => Left == null | ||
? $"Call {_function}, {_numberOfArguments}" | ||
: $"{Left} = Call {_function}, {_numberOfArguments}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
namespace Interpreter.Lib.BackEnd.Instructions | ||
namespace Interpreter.Lib.BackEnd.Instructions; | ||
|
||
public class CreateArray : Instruction | ||
{ | ||
public class CreateArray : Instruction | ||
{ | ||
private readonly string _id; | ||
private readonly int _size; | ||
private readonly string _id; | ||
private readonly int _size; | ||
|
||
public CreateArray(int number, string id, int size) : base(number) | ||
{ | ||
_id = id; | ||
_size = size; | ||
} | ||
|
||
public override int Execute(VirtualMachine vm) | ||
{ | ||
var frame = vm.Frames.Peek(); | ||
frame[_id] = new object[_size].ToList(); | ||
return Number + 1; | ||
} | ||
public CreateArray(int number, string id, int size) : base(number) | ||
{ | ||
_id = id; | ||
_size = size; | ||
} | ||
|
||
protected override string ToStringRepresentation() => $"array {_id} = [{_size}]"; | ||
public override int Execute(VirtualMachine vm) | ||
{ | ||
var frame = vm.Frames.Peek(); | ||
frame[_id] = new object[_size].ToList(); | ||
return Number + 1; | ||
} | ||
|
||
protected override string ToStringRepresentation() => $"array {_id} = [{_size}]"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
namespace Interpreter.Lib.BackEnd.Instructions | ||
namespace Interpreter.Lib.BackEnd.Instructions; | ||
|
||
public class CreateObject : Instruction | ||
{ | ||
public class CreateObject : Instruction | ||
{ | ||
private readonly string _id; | ||
private readonly string _id; | ||
|
||
public CreateObject(int number, string id) : base(number) | ||
{ | ||
_id = id; | ||
} | ||
|
||
public override int Execute(VirtualMachine vm) | ||
{ | ||
var frame = vm.Frames.Peek(); | ||
frame[_id] = new Dictionary<string, object>(); | ||
return Number + 1; | ||
} | ||
public CreateObject(int number, string id) : base(number) | ||
{ | ||
_id = id; | ||
} | ||
|
||
protected override string ToStringRepresentation() => $"object {_id} = {{}}"; | ||
public override int Execute(VirtualMachine vm) | ||
{ | ||
var frame = vm.Frames.Peek(); | ||
frame[_id] = new Dictionary<string, object>(); | ||
return Number + 1; | ||
} | ||
|
||
protected override string ToStringRepresentation() => $"object {_id} = {{}}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
using Interpreter.Lib.BackEnd.Values; | ||
|
||
namespace Interpreter.Lib.BackEnd.Instructions | ||
namespace Interpreter.Lib.BackEnd.Instructions; | ||
|
||
public class DotAssignment : Simple | ||
{ | ||
public class DotAssignment : Simple | ||
public DotAssignment(string left, (IValue left, IValue right) right, int number) : | ||
base(left, right, ".", number) | ||
{ | ||
public DotAssignment(string left, (IValue left, IValue right) right, int number) : | ||
base(left, right, ".", number) | ||
{ | ||
} | ||
|
||
public override int Execute(VirtualMachine vm) | ||
{ | ||
var frame = vm.Frames.Peek(); | ||
var obj = (Dictionary<string, object>) frame[Left]; | ||
var field = (string) right.left.Get(frame) ?? string.Empty; | ||
obj[field] = right.right.Get(frame); | ||
return Number + 1; | ||
} | ||
} | ||
|
||
protected override string ToStringRepresentation() => | ||
$"{Left}{@operator}{right.left} = {right.right}"; | ||
public override int Execute(VirtualMachine vm) | ||
{ | ||
var frame = vm.Frames.Peek(); | ||
var obj = (Dictionary<string, object>) frame[Left]; | ||
var field = (string) right.left.Get(frame) ?? string.Empty; | ||
obj[field] = right.right.Get(frame); | ||
return Number + 1; | ||
} | ||
|
||
protected override string ToStringRepresentation() => | ||
$"{Left}{@operator}{right.left} = {right.right}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
namespace Interpreter.Lib.BackEnd.Instructions | ||
namespace Interpreter.Lib.BackEnd.Instructions; | ||
|
||
public class Goto : Instruction | ||
{ | ||
public class Goto : Instruction | ||
{ | ||
protected int jump; | ||
protected int jump; | ||
|
||
public Goto(int jump, int number) : base(number) | ||
{ | ||
this.jump = jump; | ||
} | ||
public Goto(int jump, int number) : base(number) | ||
{ | ||
this.jump = jump; | ||
} | ||
|
||
public override int Jump() => jump; | ||
public override int Jump() => jump; | ||
|
||
public override int Execute(VirtualMachine vm) => Jump(); | ||
public override int Execute(VirtualMachine vm) => Jump(); | ||
|
||
public void SetJump(int newJump) => jump = newJump; | ||
public void SetJump(int newJump) => jump = newJump; | ||
|
||
protected override string ToStringRepresentation() => $"Goto {Jump()}"; | ||
} | ||
protected override string ToStringRepresentation() => $"Goto {Jump()}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
namespace Interpreter.Lib.BackEnd.Instructions | ||
namespace Interpreter.Lib.BackEnd.Instructions; | ||
|
||
public class Halt : Instruction | ||
{ | ||
public class Halt : Instruction | ||
public Halt(int number) : base(number) | ||
{ | ||
public Halt(int number) : base(number) | ||
{ | ||
} | ||
|
||
public override bool End() => true; | ||
} | ||
|
||
public override int Execute(VirtualMachine vm) | ||
{ | ||
vm.Frames.Pop(); | ||
return -3; | ||
} | ||
public override bool End() => true; | ||
|
||
protected override string ToStringRepresentation() => "End"; | ||
public override int Execute(VirtualMachine vm) | ||
{ | ||
vm.Frames.Pop(); | ||
return -3; | ||
} | ||
|
||
protected override string ToStringRepresentation() => "End"; | ||
} |
Oops, something went wrong.