Skip to content

Commit

Permalink
Added brun & test
Browse files Browse the repository at this point in the history
  • Loading branch information
kev committed Jan 27, 2024
1 parent 0db26aa commit 6cb40ce
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CLVMDotNet/src/CLVM/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static Tuple<BigInteger, SExp> RunProgram(SExp program, SExp args, BigInt
Stack<Func<Stack<SExp>, BigInteger>> opStack = new Stack<Func<Stack<SExp>, BigInteger>>();

var valueStack = new Stack<SExp>();
valueStack.Push(args);
valueStack.Push(prog.Cons(args));
opStack.Push(stack => EvalOp(opStack, valueStack));

BigInteger cost = 0;
Expand Down
4 changes: 0 additions & 4 deletions CLVMDotNet/src/CLVMDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
<Folder Include="Tools\Stages\Stage2\" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions CLVMDotNet/src/Tools/IR/BinUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static SExp AssembleFromIR(SExp ir_sexp)

// handle "q"
var first = Utils.IrFirst(ir_sexp);
var keyword2 = Utils.IrAsSymbol(first) as string;
if (keyword2 == "q")
keyword = Utils.IrAsSymbol(first) as string;
if (keyword == "q")
{
// TODO: note that any symbol is legal after this point
}
Expand Down
3 changes: 2 additions & 1 deletion CLVMDotNet/src/Tools/IR/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public static BigInteger ConvertToBase256(string s)
{
if (irSexp.Listp() && IrType(irSexp) == IRType.SYMBOL)
{
return Encoding.UTF8.GetString(IrAsSexp(irSexp).AsAtom());
var sexp = IrAsSexp(irSexp);
return Encoding.UTF8.GetString(sexp.AsAtom());

Check warning on line 29 in CLVMDotNet/src/Tools/IR/Utils.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference argument for parameter 'bytes' in 'string Encoding.GetString(byte[] bytes)'.
}

return null;
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions CLVMDotNet/src/Tools/Stages/Stage2/Bindings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using CLVMDotNet.CLVM;
using CLVMDotNet.Tools.IR;

namespace CLVMDotNet.Tools.Stages.Stage2;

public static class Bindings
{
public static SExp Brun => BinUtils.Assemble("(a 2 3)");

public static SExp Run => BinUtils.Assemble("(a (opt (com 2)) 3)");
}
6 changes: 6 additions & 0 deletions CLVMDotNet/src/Tools/Stages/Stage2/Compile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tools.Stages.Stage2;

public class Compile
{

}
6 changes: 6 additions & 0 deletions CLVMDotNet/src/Tools/Stages/Stage2/Defaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tools.Stages.Stage2;

public class Defaults
{

}
6 changes: 6 additions & 0 deletions CLVMDotNet/src/Tools/Stages/Stage2/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tools.Stages.Stage2;

public class Helpers
{

}
6 changes: 6 additions & 0 deletions CLVMDotNet/src/Tools/Stages/Stage2/Mod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tools.Stages.Stage2;

public class Mod
{

}
6 changes: 6 additions & 0 deletions CLVMDotNet/src/Tools/Stages/Stage2/Operators.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tools.Stages.Stage2;

public class Operators
{

}
9 changes: 9 additions & 0 deletions CLVMDotNet/src/Tools/Stages/Stage2/Optimize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using CLVMDotNet.CLVM;
using CLVMDotNet.Tools.IR;

namespace CLVMDotNet.Tools.Stages.Stage2;

public class Optimize
{

}
6 changes: 6 additions & 0 deletions CLVMDotNet/tests/Tools/Stages/Stage0/Stage0.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tests.Tools.Stages.Stage0;

public class Stage0
{

}
49 changes: 49 additions & 0 deletions CLVMDotNet/tests/Tools/Stages/Stage2/BindingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using CLVMDotNet.Tools.Stages.Stage2;
using Xunit;

namespace CLVMDotNet.Tests.Tools.Stages.Stage2;

public class BindingTests
{
[Fact]
public void TestBrun()
{
// Arrange

// Act
var brun = Bindings.Brun;

// Assert
Assert.Null(brun.Atom);
Assert.NotNull(brun.Pair);
Assert.True(brun.AsPair().Item1.AsAtom().SequenceEqual(new byte[] { 0x02 }));
Assert.Null(brun.AsPair().Item1.Pair);
Assert.Null(brun.AsPair().Item2.Atom);
Assert.NotNull(brun.AsPair().Item2.Pair);
Assert.True(brun.AsPair().Item2.AsPair().Item1.AsAtom().SequenceEqual(new byte[] { 0x02}));
Assert.Null(brun.AsPair().Item2.AsPair().Item2.Atom);
Assert.NotNull(brun.AsPair().Item2.AsPair().Item2.Pair);
Assert.True(brun.AsPair().Item2.AsPair().Item2.AsPair().Item1.AsAtom().SequenceEqual(new byte []{ 0x03}));
Assert.Empty(brun.AsPair().Item2.AsPair().Item2.AsPair().Item2.AsAtom());
}

[Fact(Skip = "Skipping for now")]
public void TestRun()
{
// Arrange

// Act
var run = Bindings.Run;

// Assert
Assert.Null(run.Atom);
Assert.True(run.AsPair().Item1.AsAtom().SequenceEqual(new byte[] { 0x02 }));
Assert.Null(run.AsPair().Item1.Pair);
Assert.Null(run.AsPair().Item2.Atom);
Assert.NotNull(run.AsPair().Item2.Pair);
Assert.NotNull(run.AsPair().Item2.AsPair().Item2);
Assert.NotNull(run.AsPair().Item2.AsPair().Item1);


}
}
6 changes: 6 additions & 0 deletions CLVMDotNet/tests/Tools/Stages/Stage2/CompileTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tests.Tools.Stages.Stage2;

public class CompileTests
{

}
6 changes: 6 additions & 0 deletions CLVMDotNet/tests/Tools/Stages/Stage2/DefaultsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tests.Tools.Stages.Stage2;

public class DefaultsTests
{

}
6 changes: 6 additions & 0 deletions CLVMDotNet/tests/Tools/Stages/Stage2/HelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tests.Tools.Stages.Stage2;

public class HelperTests
{

}
6 changes: 6 additions & 0 deletions CLVMDotNet/tests/Tools/Stages/Stage2/ModTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tests.Tools.Stages.Stage2;

public class ModTests
{

}
6 changes: 6 additions & 0 deletions CLVMDotNet/tests/Tools/Stages/Stage2/OperatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tests.Tools.Stages.Stage2;

public class OperatorTests
{

}
6 changes: 6 additions & 0 deletions CLVMDotNet/tests/Tools/Stages/Stage2/OptimizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CLVMDotNet.Tests.Tools.Stages.Stage2;

public class OptimizeTests
{

}

0 comments on commit 6cb40ce

Please sign in to comment.