Skip to content

Commit

Permalink
Merge pull request #42 from metaindu/evaluator-12-compile
Browse files Browse the repository at this point in the history
Evaluator 12: IlExpression
  • Loading branch information
izrik authored Oct 18, 2022
2 parents 3d3d05f + 574645e commit 3837f33
Show file tree
Hide file tree
Showing 56 changed files with 3,355 additions and 1 deletion.
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

0 comments on commit 3837f33

Please sign in to comment.