Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluator 12: IlExpression #42

Merged
merged 1 commit into from
Oct 18, 2022
Merged
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
46 changes: 46 additions & 0 deletions Compiler/IlExpressions/AddIlExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

/*
* MetaphysicsIndustries.Solus
* Copyright (C) 2006-2021 Metaphysics Industries, Inc., Richard Sartor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
*/

using System;
using System.Collections.Generic;

namespace MetaphysicsIndustries.Solus.Compiler.IlExpressions
{
public class AddIlExpression : IlExpression
{
public AddIlExpression(IlExpression left, IlExpression right)
{
Left = left ?? throw new ArgumentNullException(nameof(left));
Right = right ?? throw new ArgumentNullException(nameof(right));
}

public IlExpression Left { get; }
public IlExpression Right { get; }

public override void GetInstructions(IList<Instruction> instructions)
{
Left.GetInstructions(instructions);
Right.GetInstructions(instructions);
instructions.Add(Instruction.Add());
}
}
}
46 changes: 46 additions & 0 deletions Compiler/IlExpressions/AndIlExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

/*
* MetaphysicsIndustries.Solus
* Copyright (C) 2006-2021 Metaphysics Industries, Inc., Richard Sartor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
*/

using System;
using System.Collections.Generic;

namespace MetaphysicsIndustries.Solus.Compiler.IlExpressions
{
public class AndIlExpression : IlExpression
{
public AndIlExpression(IlExpression left, IlExpression right)
{
Left = left ?? throw new ArgumentNullException(nameof(left));
Right = right ?? throw new ArgumentNullException(nameof(right));
}

public IlExpression Left { get; }
public IlExpression Right { get; }

public override void GetInstructions(IList<Instruction> instructions)
{
Left.GetInstructions(instructions);
Right.GetInstructions(instructions);
instructions.Add(Instruction.And());
}
}
}
55 changes: 55 additions & 0 deletions Compiler/IlExpressions/CallIlExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

/*
* MetaphysicsIndustries.Solus
* Copyright (C) 2006-2021 Metaphysics Industries, Inc., Richard Sartor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
*/

using System;
using System.Collections.Generic;
using System.Reflection;

namespace MetaphysicsIndustries.Solus.Compiler.IlExpressions
{
public class CallIlExpression : IlExpression
{
public CallIlExpression(MethodInfo method, params IlExpression[] args)
{
Method = method ??
throw new ArgumentNullException(nameof(method));
Args = args ?? throw new ArgumentNullException(nameof(args));
}
public CallIlExpression(Delegate @delegate,
params IlExpression[] args)
: this(@delegate?.Method, args)
{
}

public MethodInfo Method { get; }
public IlExpression[] Args { get; }

public override void GetInstructions(IList<Instruction> instructions)
{
// TODO: check args against method signature?
int i;
for (i = 0; i < Args.Length; i++)
Args[i].GetInstructions(instructions);
instructions.Add(Instruction.Call(Method));
}
}
}
47 changes: 47 additions & 0 deletions Compiler/IlExpressions/CompareEqualIlExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

/*
* MetaphysicsIndustries.Solus
* Copyright (C) 2006-2021 Metaphysics Industries, Inc., Richard Sartor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
*/

using System;
using System.Collections.Generic;

namespace MetaphysicsIndustries.Solus.Compiler.IlExpressions
{
public class CompareEqualIlExpression : IlExpression
{
public CompareEqualIlExpression(IlExpression left,
IlExpression right)
{
Left = left ?? throw new ArgumentNullException(nameof(left));
Right = right ?? throw new ArgumentNullException(nameof(right));
}

public IlExpression Left { get; }
public IlExpression Right { get; }

public override void GetInstructions(IList<Instruction> instructions)
{
Left.GetInstructions(instructions);
Right.GetInstructions(instructions);
instructions.Add(Instruction.CompareEqual());
}
}
}
47 changes: 47 additions & 0 deletions Compiler/IlExpressions/CompareGreaterThanIlExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

/*
* MetaphysicsIndustries.Solus
* Copyright (C) 2006-2021 Metaphysics Industries, Inc., Richard Sartor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
*/

using System;
using System.Collections.Generic;

namespace MetaphysicsIndustries.Solus.Compiler.IlExpressions
{
public class CompareGreaterThanIlExpression : IlExpression
{
public CompareGreaterThanIlExpression(IlExpression left,
IlExpression right)
{
Left = left ?? throw new ArgumentNullException(nameof(left));
Right = right ?? throw new ArgumentNullException(nameof(right));
}

public IlExpression Left { get; }
public IlExpression Right { get; }

public override void GetInstructions(IList<Instruction> instructions)
{
Left.GetInstructions(instructions);
Right.GetInstructions(instructions);
instructions.Add(Instruction.CompareGreaterThan());
}
}
}
47 changes: 47 additions & 0 deletions Compiler/IlExpressions/CompareLessThanIlExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

/*
* MetaphysicsIndustries.Solus
* Copyright (C) 2006-2021 Metaphysics Industries, Inc., Richard Sartor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
*/

using System;
using System.Collections.Generic;

namespace MetaphysicsIndustries.Solus.Compiler.IlExpressions
{
public class CompareLessThanIlExpression : IlExpression
{
public CompareLessThanIlExpression(IlExpression left,
IlExpression right)
{
Left = left ?? throw new ArgumentNullException(nameof(left));
Right = right ?? throw new ArgumentNullException(nameof(right));
}

public IlExpression Left { get; }
public IlExpression Right { get; }

public override void GetInstructions(IList<Instruction> instructions)
{
Left.GetInstructions(instructions);
Right.GetInstructions(instructions);
instructions.Add(Instruction.CompareLessThan());
}
}
}
44 changes: 44 additions & 0 deletions Compiler/IlExpressions/ConvertI4IlExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

/*
* MetaphysicsIndustries.Solus
* Copyright (C) 2006-2021 Metaphysics Industries, Inc., Richard Sartor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
*/

using System;
using System.Collections.Generic;

namespace MetaphysicsIndustries.Solus.Compiler.IlExpressions
{
public class ConvertI4IlExpression : IlExpression
{
public ConvertI4IlExpression(IlExpression argument)
{
Argument = argument ??
throw new ArgumentNullException(nameof(argument));
}

public IlExpression Argument { get; }

public override void GetInstructions(IList<Instruction> instructions)
{
Argument.GetInstructions(instructions);
instructions.Add(Instruction.ConvertI4());
}
}
}
44 changes: 44 additions & 0 deletions Compiler/IlExpressions/ConvertR4IlExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

/*
* MetaphysicsIndustries.Solus
* Copyright (C) 2006-2021 Metaphysics Industries, Inc., Richard Sartor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
*/

using System;
using System.Collections.Generic;

namespace MetaphysicsIndustries.Solus.Compiler.IlExpressions
{
public class ConvertR4IlExpression : IlExpression
{
public ConvertR4IlExpression(IlExpression argument)
{
Argument = argument ??
throw new ArgumentNullException(nameof(argument));
}

public IlExpression Argument { get; }

public override void GetInstructions(IList<Instruction> instructions)
{
Argument.GetInstructions(instructions);
instructions.Add(Instruction.ConvertR4());
}
}
}
Loading