Skip to content

Commit

Permalink
Update version of nth and remove serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
asoffer committed Aug 13, 2024
1 parent 4aebef8 commit a3912c5
Show file tree
Hide file tree
Showing 26 changed files with 41 additions and 634 deletions.
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bazel_dep(name = "abseil-cpp", repo_name = "com_google_absl", version = "20230125.1")
bazel_dep(name = "bazel_skylib", repo_name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "nth-cc", repo_name = "nth_cc", version = "20240602.00")
bazel_dep(name = "abseil-cpp", repo_name = "com_google_absl", version = "20240116.2")
bazel_dep(name = "bazel_skylib", repo_name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "nth-cc", repo_name = "nth_cc", version = "20240812.00")
22 changes: 0 additions & 22 deletions examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,3 @@ cc_binary(
"@nth_cc//nth/container:stack",
],
)


cc_binary(
name = "serialization",
srcs = ["serialization.cc"],
deps = [
"//jasmin/core:instruction",
"//jasmin/core:function",
"//jasmin/core:function_registry",
"//jasmin/core:program_fragment",
"//jasmin/instructions:arithmetic",
"//jasmin/instructions:compare",
"//jasmin/instructions:common",
"@nth_cc//nth/debug",
"@nth_cc//nth/debug/log:stderr_log_sink",
"@nth_cc//nth/io/deserialize",
"@nth_cc//nth/io/serialize",
"@nth_cc//nth/io/reader:string",
"@nth_cc//nth/io/writer:string",
"@com_google_absl//absl/container:flat_hash_set",
],
)
2 changes: 1 addition & 1 deletion examples/brainfuck/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::string LoadFileContentsOrDie(std::string_view path) {
std::string contents(file->size(), '\0');
std::span<char const> data = file->read_into(contents);
if (not file->close()) { std::abort(); }
NTH_REQUIRE((v.debug), data.size() == contents.size());
NTH_REQUIRE((debug), data.size() == contents.size());
return contents;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/brainfuck/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "nth/debug/log/stderr_log_sink.h"

int main(int argc, char* argv[]) {
nth::RegisterLogSink(nth::stderr_log_sink);
nth::register_log_sink(nth::stderr_log_sink);

if (argc != 2) { return 1; }
std::string contents = bf::LoadFileContentsOrDie(argv[1]);
Expand Down
131 changes: 0 additions & 131 deletions examples/serialization.cc

This file was deleted.

1 change: 1 addition & 0 deletions jasmin/compile/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"@nth_cc//nth/debug",
"@nth_cc//nth/memory:bytes",
],
)
6 changes: 3 additions & 3 deletions jasmin/compile/compiled_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
#include <span>

#include "nth/debug/debug.h"
#include "nth/memory/bytes.h"

namespace jasmin {

CompiledFunction::operator std::span<std::byte const>() const {
return std::span<std::byte const>(
reinterpret_cast<std::byte const *>(content_.data()), content_.size());
return nth::byte_range(content_);
}

void CompiledFunction::write(std::initializer_list<uint8_t> instructions) {
for (char c : instructions) { content_.push_back(c); }
}

void CompiledFunction::write_at_impl(size_t offset, uint32_t n) {
NTH_REQUIRE((v.harden), n + sizeof(uint32_t) <= content_.size());
NTH_REQUIRE((harden), n + sizeof(uint32_t) <= content_.size());
std::memcpy(content_.data() + offset, &n, sizeof(n));
}

Expand Down
26 changes: 3 additions & 23 deletions jasmin/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ cc_library(
"//jasmin/core/internal:function_base",
"//jasmin/core/internal:function_forward",
"//jasmin/core/internal:instruction_traits",
"@nth_cc//nth/format",
"@nth_cc//nth/container:interval",
"@nth_cc//nth/io/deserialize",
"@nth_cc//nth/io/serialize",
],
)

Expand All @@ -51,10 +50,6 @@ cc_library(
deps = [
"//jasmin/core/internal:function_forward",
"@nth_cc//nth/debug",
"@nth_cc//nth/io/deserialize",
"@nth_cc//nth/io/reader",
"@nth_cc//nth/io/serialize",
"@nth_cc//nth/io/writer",
],
)

Expand Down Expand Up @@ -139,7 +134,7 @@ cc_library(
"//jasmin/core/internal:instruction_traits",
"@com_google_absl//absl/container:flat_hash_map",
"@nth_cc//nth/debug",
"@nth_cc//nth/utility:no_destructor",
"@nth_cc//nth/base:indestructible",
],
)

Expand Down Expand Up @@ -182,26 +177,11 @@ cc_library(
":instruction",
":value",
"@nth_cc//nth/debug",
"@nth_cc//nth/io/deserialize",
"@nth_cc//nth/io/serialize",
"@nth_cc//nth/format",
"@nth_cc//nth/utility:iterator_range",
],
)

cc_test(
name = "serialization_test",
srcs = ["serialization_test.cc"],
deps = [
":function",
":function_registry",
":program_fragment",
"//jasmin/instructions:common",
"@nth_cc//nth/io/reader:string",
"@nth_cc//nth/io/writer:string",
"@nth_cc//nth/test:main",
],
)

cc_library(
name = "value",
hdrs = ["value.h"],
Expand Down
2 changes: 1 addition & 1 deletion jasmin/core/debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Debugger::set_function_breakpoint(std::string name,
auto &f = program_.function(name);
auto [iter, inserted] = breakpoint_functions_.try_emplace(
std::move(name), nullptr, std::move(response));
NTH_REQUIRE((v.harden), inserted);
NTH_REQUIRE((harden), inserted);
iter->second.first = std::exchange(f, nullptr);
auto fn = std::make_unique<Function<DebuggerInstructions>>(0, 0);
f.raw_append(DebugImpl);
Expand Down
2 changes: 1 addition & 1 deletion jasmin/core/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void Debugger<Set>::set_function_breakpoint(std::string name,
auto [iter, inserted] = breakpoint_functions_.try_emplace(
std::move(name), Function<Set>(f.parameter_count(), f.return_count()),
std::move(response));
NTH_REQUIRE((v.harden), inserted);
NTH_REQUIRE((harden), inserted);
iter->second.first = std::move(f);
f = Function<Set>(0, 0);
f.raw_append(internal::DebugImpl<Set>);
Expand Down
9 changes: 5 additions & 4 deletions jasmin/core/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "jasmin/core/internal/instruction_traits.h"
#include "jasmin/core/metadata.h"
#include "nth/container/interval.h"
#include "nth/format/format.h"
#include "nth/io/serialize/serialize.h"
#include "nth/meta/type.h"

Expand Down Expand Up @@ -104,10 +105,10 @@ struct Function : Function<> {
friend nth::io::serializer_result_type<S> NthSerialize(S &s,
Function const &fn) {
using result_type = nth::io::serializer_result_type<S>;
if (not nth::io::write_integer(s, fn.parameter_count())) {
if (not nth::format_integer(s, fn.parameter_count())) {
return result_type(false);
}
if (not nth::io::write_integer(s, fn.return_count())) {
if (not nth::format_integer(s, fn.return_count())) {
return result_type(false);
}
auto const &set_metadata = Metadata<Set>();
Expand All @@ -124,7 +125,7 @@ struct Function : Function<> {

while (not insts.empty()) {
uint16_t index = set_metadata.opcode(insts[0]);
if (not nth::io::write_fixed(s, index)) { return result_type(false); }
if (not nth::format_fixed(s, index)) { return result_type(false); }
auto immediate_value_count =
set_metadata.metadata(index).immediate_value_count;
result_type result =
Expand Down Expand Up @@ -303,7 +304,7 @@ InstructionSerializer(
} else if constexpr (nth::type<I> == nth::type<Call>) {
return nth::io::serialize(s, v[0].as<InstructionSpecification>());
} else if constexpr (nth::any_of<I, Jump, JumpIf, JumpIfNot>) {
return result_type(nth::io::write_integer(s, v[0].as<ptrdiff_t>()));
return result_type(nth::format_integer(s, v[0].as<ptrdiff_t>()));
} else {
constexpr auto params = [] {
if constexpr (requires { I::execute; }) {
Expand Down
28 changes: 0 additions & 28 deletions jasmin/core/function_identifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#include <limits>

#include "jasmin/core/internal/function_forward.h"
#include "nth/io/deserialize/deserialize.h"
#include "nth/io/reader/reader.h"
#include "nth/io/serialize/serialize.h"
#include "nth/io/writer/writer.h"

namespace jasmin {

Expand All @@ -19,30 +15,6 @@ struct FunctionIdentifier {
constexpr FunctionIdentifier() = default;
static constexpr FunctionIdentifier Invalid() { return FunctionIdentifier(); }

template <typename S>
friend nth::io::serializer_result_type<S> NthSerialize(
S& s, FunctionIdentifier id) {
using result_type = nth::io::serializer_result_type<S>;
if (id == Invalid()) { return result_type(false); }
if (not nth::io::write_integer(s, id.fragment_)) {
return result_type(false);
}
if (not nth::io::write_integer(s, id.index_)) { return result_type(false); }
return result_type(true);
}

template <typename D>
friend nth::io::deserializer_result_type<D> NthDeserialize(
D& d, FunctionIdentifier& id) {
using result_type = nth::io::deserializer_result_type<D>;
if (not nth::io::read_integer(d, id.fragment_)) {
return result_type(false);
}
if (not nth::io::read_integer(d, id.index_)) { return result_type(false); }
if (id == Invalid()) { return result_type(false); }
return result_type(true);
}

friend bool operator==(FunctionIdentifier, FunctionIdentifier) = default;
friend bool operator!=(FunctionIdentifier, FunctionIdentifier) = default;

Expand Down
1 change: 1 addition & 0 deletions jasmin/core/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ cc_library(
"//jasmin/core:input",
"//jasmin/core:output",
"//jasmin/core:value",
"@nth_cc//nth/format",
"@nth_cc//nth/meta:concepts",
"@nth_cc//nth/meta:type",
"@nth_cc//nth/io/deserialize",
Expand Down
3 changes: 1 addition & 2 deletions jasmin/core/internal/function_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ struct FunctionBase {
// overwrite any such `Value`.
void set_value(nth::interval<InstructionIndex> range,
InstructionIndex::difference_type index, Value value) {
NTH_REQUIRE((v.when(internal::harden)), index + 1 < range.length())
.Log<"Index larger than range">();
NTH_REQUIRE((harden), index + 1 < range.length());
instructions_[range.lower_bound().value() + index + 1] = value;
}

Expand Down
Loading

0 comments on commit a3912c5

Please sign in to comment.