Skip to content

Commit

Permalink
Move from passing values to passing value pointers. Create class
Browse files Browse the repository at this point in the history
hierarchy for values.
  • Loading branch information
Jonny Arnold committed Mar 19, 2017
1 parent f9cb4ff commit f540b80
Show file tree
Hide file tree
Showing 17 changed files with 331 additions and 260 deletions.
2 changes: 1 addition & 1 deletion spec/e2e/bool.spec.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "spec/spec.h"

TEST_CASE("Boolean set/get") {
REQUIRE(resultOf("x = true; x").asBool() == true);
REQUIRE(resultOf("x = true; x")->asBool() == true);
}

// TEST_CASE("and") {
Expand Down
2 changes: 1 addition & 1 deletion spec/e2e/language.spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// }

TEST_CASE("Semicolons") {
REQUIRE(resultOf("x = true; x").asBool() == true);
REQUIRE(resultOf("x = true; x")->asBool() == true);
}

// TEST_CASE("Brackets") {
Expand Down
8 changes: 4 additions & 4 deletions spec/e2e/number.spec.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#include "spec/spec.h"

TEST_CASE("Positive integer set/get") {
REQUIRE(resultOf("x = 1; x").asNumber() == fn::Number(0, 1));
REQUIRE(resultOf("x = 1; x")->asNumber() == fn::Number(0, 1));
}

TEST_CASE("Negative integer set/get") {
REQUIRE(resultOf("x = -1; x").asNumber() == fn::Number(0, -1));
REQUIRE(resultOf("x = -1; x")->asNumber() == fn::Number(0, -1));
}

TEST_CASE("Positive decimal set/get") {
REQUIRE(resultOf("x = 1.23; x").asNumber() == fn::Number(-2, 123));
REQUIRE(resultOf("x = 1.23; x")->asNumber() == fn::Number(-2, 123));
}

TEST_CASE("Negative decimal set/get") {
REQUIRE(resultOf("x = -1.23; x").asNumber() == fn::Number(-2, -123));
REQUIRE(resultOf("x = -1.23; x")->asNumber() == fn::Number(-2, -123));
}

// TODO: Mathematical precedence
Expand Down
6 changes: 3 additions & 3 deletions spec/spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
// Include new test files in the Makefile.
// Include global helpers here.

vm::Value resultOf(bytecode::CodeBlob instructions) {
return (VM()).run(&instructions);
vm::Value* resultOf(bytecode::CodeBlob instructions) {
return (VM(true)).run(&instructions);
}

vm::Value resultOf(std::string code) {
vm::Value* resultOf(std::string code) {
return execCode(code);
}

Expand Down
6 changes: 3 additions & 3 deletions spec/spec.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "vendor/catch.h" // Needed by all specs.

Expand All @@ -9,5 +9,5 @@
using namespace fn;

// Get the value of a code listing.
vm::Value resultOf(bytecode::CodeBlob instructions);
vm::Value resultOf(std::string code);
vm::Value* resultOf(bytecode::CodeBlob instructions);
vm::Value* resultOf(std::string code);
44 changes: 22 additions & 22 deletions spec/vm/bool.spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,104 @@

TEST_CASE("BOOL false") {
bytecode::CodeBlob instructions = bytecode::iFalse();
REQUIRE(resultOf(instructions).asBool() == false);
REQUIRE(resultOf(instructions)->asBool() == false);
}

TEST_CASE("BOOL true") {
bytecode::CodeBlob instructions = bytecode::iTrue();
REQUIRE(resultOf(instructions).asBool() == true);
REQUIRE(resultOf(instructions)->asBool() == true);
}

TEST_CASE("AND true true") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iTrue(),
bytecode::iAnd(0, 0)
bytecode::iAnd(1, 1)
};

REQUIRE(resultOf(instructions).asBool() == true);
REQUIRE(resultOf(instructions)->asBool() == true);
}

TEST_CASE("AND true false") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iTrue(),
bytecode::iFalse(),
bytecode::iAnd(0, 1)
bytecode::iAnd(1, 2)
};

REQUIRE(resultOf(instructions).asBool() == false);
REQUIRE(resultOf(instructions)->asBool() == false);
}

TEST_CASE("AND false true") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iFalse(),
bytecode::iTrue(),
bytecode::iAnd(0, 1)
bytecode::iAnd(1, 2)
};

REQUIRE(resultOf(instructions).asBool() == false);
REQUIRE(resultOf(instructions)->asBool() == false);
}

TEST_CASE("AND false false") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iFalse(),
bytecode::iAnd(0, 0)
bytecode::iAnd(1, 1)
};

REQUIRE(resultOf(instructions).asBool() == false);
REQUIRE(resultOf(instructions)->asBool() == false);
}

TEST_CASE("OR true true") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iTrue(),
bytecode::iOr(0, 0)
bytecode::iOr(1, 1)
};

REQUIRE(resultOf(instructions).asBool() == true);
REQUIRE(resultOf(instructions)->asBool() == true);
}

TEST_CASE("OR true false") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iTrue(),
bytecode::iFalse(),
bytecode::iOr(0, 1)
bytecode::iOr(1, 2)
};

REQUIRE(resultOf(instructions).asBool() == true);
REQUIRE(resultOf(instructions)->asBool() == true);
}

TEST_CASE("OR false true") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iFalse(),
bytecode::iTrue(),
bytecode::iOr(0, 1)
bytecode::iOr(1, 2)
};

REQUIRE(resultOf(instructions).asBool() == true);
REQUIRE(resultOf(instructions)->asBool() == true);
}

TEST_CASE("OR false false") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iFalse(),
bytecode::iOr(0, 0)
bytecode::iOr(1, 1)
};

REQUIRE(resultOf(instructions).asBool() == false);
REQUIRE(resultOf(instructions)->asBool() == false);
}

TEST_CASE("NOT true") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iTrue(),
bytecode::iNot(0)
bytecode::iNot(1)
};

REQUIRE(resultOf(instructions).asBool() == false);
REQUIRE(resultOf(instructions)->asBool() == false);
}

TEST_CASE("NOT false") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iFalse(),
bytecode::iNot(0)
bytecode::iNot(1)
};

REQUIRE(resultOf(instructions).asBool() == true);
REQUIRE(resultOf(instructions)->asBool() == true);
}
6 changes: 3 additions & 3 deletions spec/vm/call.spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ TEST_CASE("CALL builtin") {
bytecode::iFalse()
};

REQUIRE(resultOf(instructions).asBool() == false);
REQUIRE(resultOf(instructions)->asBool() == false);
}

TEST_CASE("CALL def") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iDefHeader(2),
bytecode::iFalse(),
bytecode::iReturnLast(),
bytecode::iCall(0)
bytecode::iCall(1)
};

REQUIRE(resultOf(instructions).asBool() == false);
REQUIRE(resultOf(instructions)->asBool() == false);
}
4 changes: 2 additions & 2 deletions spec/vm/load.spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
TEST_CASE("LOAD") {
bytecode::CodeBlob instructions = bytecode::CodeBlob{
bytecode::iTrue(),
bytecode::iLoad(0)
bytecode::iLoad(1)
};

REQUIRE(resultOf(instructions).asBool() == true);
REQUIRE(resultOf(instructions)->asBool() == true);
}
Loading

0 comments on commit f540b80

Please sign in to comment.