Skip to content

Commit

Permalink
Closer to what I want, but definitely not there yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
asoffer committed Mar 23, 2024
1 parent 91c7ae6 commit aac5a3f
Show file tree
Hide file tree
Showing 70 changed files with 1,917 additions and 1,614 deletions.
Binary file added a.out
Binary file not shown.
91 changes: 40 additions & 51 deletions common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,11 @@ cc_library(
name = "any_value",
hdrs = ["any_value.h"],
deps = [
":type",
"//type",
"@jasmin//jasmin/core:value",
],
)

cc_library(
name = "constants",
hdrs = [
"constants.h",
"identifier.h",
"integer.h",
"string_literal.h",
],
srcs = ["constants.cc"],
deps = [
":any_value",
":type",
":pattern",
":result",
":strong_identifier_type",
":to_bytes",
"//common/internal:component",
"//common/internal:constant_handle",
"//common/language:primitive_types",
"//common/language:type_kind",
"@com_google_absl//absl/container:flat_hash_map",
"@nth_cc//nth/container:flyweight_map",
"@nth_cc//nth/container:flyweight_set",
"@nth_cc//nth/io/deserialize",
"@nth_cc//nth/io/serialize",
"@nth_cc//nth/numeric:integer",
"@nth_cc//nth/utility:bytes",
],
)

cc_test(
name = "constants_test",
srcs = ["constants_test.cc"],
deps = [
":constants",
"@nth_cc//nth/test:main",
],
)

cc_library(
name = "debug",
hdrs = ["debug.h"],
Expand Down Expand Up @@ -85,9 +46,31 @@ cc_library(
],
)

alias(name = "integer", actual = ":constants")
alias(name = "identifier", actual = ":constants")
alias(name = "string_literal", actual = ":constants")
cc_library(
name = "identifier",
hdrs = ["identifier.h"],
srcs = ["identifier.cc"],
deps = [
"//common/internal:constant_handle",
"//common/internal:identifiers",
"@nth_cc//nth/container:flyweight_set",
],
)

cc_library(
name = "integer",
hdrs = ["integer.h"],
srcs = ["integer.cc"],
deps = [
"//common/constant:category",
"//common/constant:entry",
"//common/constant:manifest",
"//common/internal:constant_handle",
"//common/internal:integers",
"@nth_cc//nth/numeric:integer",
"@nth_cc//nth/container:flyweight_map",
],
)

cc_test(
name = "integer_test",
Expand Down Expand Up @@ -157,6 +140,7 @@ cc_library(
hdrs = ["strong_index_type.h"],
)


cc_library(
name = "resources",
hdrs = ["resources.h"],
Expand All @@ -169,6 +153,8 @@ cc_library(
name = "result",
hdrs = ["result.h"],
deps = [
"@nth_cc//nth/base:configuration",
"@nth_cc//nth/debug",
"@nth_cc//nth/utility:early_exit",
],
)
Expand All @@ -179,16 +165,19 @@ cc_library(
)

cc_library(
name = "to_bytes",
hdrs = ["to_bytes.h"],
)

cc_library(
name = "type",
hdrs = ["type.h"],
name = "string_literal",
hdrs = ["string_literal.h"],
srcs = ["string_literal.cc"],
deps = [
"//common/constant:category",
"//common/constant:entry",
"//common/constant:manifest",
"//common/internal:constant_handle",
"//common/language:type_kind",
"//common/internal:strings",
],
)

cc_library(
name = "to_bytes",
hdrs = ["to_bytes.h"],
)
2 changes: 1 addition & 1 deletion common/any_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <memory>
#include <utility>

#include "common/type.h"
#include "jasmin/core/value.h"
#include "type/type.h"

namespace ic {

Expand Down
48 changes: 48 additions & 0 deletions common/constant/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "category",
hdrs = ["category.h"],
deps = [
"//common/language:type_kind",
],
)

cc_library(
name = "component",
hdrs = ["component.h"],
deps = [
":category",
"//common:result",
"@nth_cc//nth/debug",
"@nth_cc//nth/io/deserialize",
"@nth_cc//nth/io/serialize",
"@nth_cc//nth/utility:bytes",
],
)

cc_library(
name = "entry",
hdrs = ["entry.h"],
deps = [],
)

cc_library(
name = "manifest",
hdrs = ["manifest.h"],
srcs = ["manifest.cc"],
deps = [
":category",
":component",
"//common:result",
"//common/internal:functions",
"//common/internal:identifiers",
"//common/internal:integers",
"//common/internal:parameters",
"//common/internal:strings",
"@com_google_absl//absl/container:flat_hash_map",
"@nth_cc//nth/debug",
"@nth_cc//nth/io/deserialize",
"@nth_cc//nth/io/serialize",
],
)
18 changes: 18 additions & 0 deletions common/constant/category.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef ICARUS_COMMON_CONSTANT_CATEGORY_H
#define ICARUS_COMMON_CONSTANT_CATEGORY_H

#include <cstdint>

namespace ic {

enum class ConstantCategory : uint8_t {
#define IC_XMACRO_TYPE_KIND(kind) kind##Type,
#include "common/language/type_kind.xmacro.h"
Followup,
Integer,
String,
};

} // namespace ic

#endif // ICARUS_COMMON_CONSTANT_CATEGORY_H
40 changes: 40 additions & 0 deletions common/constant/component.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef ICARUS_COMMON_CONSTANT_COMPONENT_H
#define ICARUS_COMMON_CONSTANT_COMPONENT_H

#include <cstdint>

#include "common/constant/category.h"
#include "common/result.h"
#include "nth/io/deserialize/deserialize.h"
#include "nth/io/serialize/serialize.h"
#include "nth/utility/bytes.h"

namespace ic {

struct ConstantComponent {
ConstantComponent() = default;
explicit constexpr ConstantComponent(ConstantCategory category, uint32_t value)
: value_(value), category_(static_cast<uint8_t>(category)) {}

friend Result NthSerialize(auto& s, ConstantComponent const& c) {
return s.write(nth::bytes(c));
}
friend Result NthDeserialize(auto& d, ConstantComponent& c) {
return d.read(nth::bytes(c));
}

[[nodiscard]] constexpr ConstantCategory category() const {
return static_cast<ConstantCategory>(category_);
}
[[nodiscard]] constexpr uint32_t value() const { return value_; }

private:
// `value_` stores the width for categories that have variable-length widths
// and an actual value for categories with a fixed-length width.
uint32_t value_ : 24;
uint32_t category_ : 8;
};

} // namespace ic

#endif // ICARUS_COMMON_CONSTANT_COMPONENT_H
20 changes: 20 additions & 0 deletions common/constant/entry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef ICARUS_COMMON_CONSTANT_ENTRY_H
#define ICARUS_COMMON_CONSTANT_ENTRY_H

#include <cstdint>

namespace ic {

struct Constant {
constexpr uint32_t value() const { return value_; }

private:
friend struct ConstantManifest;
constexpr Constant(uint32_t index) : value_(index) {}

uint32_t value_;
};

} // namespace ic

#endif // ICARUS_COMMON_CONSTANT_ENTRY_H
42 changes: 42 additions & 0 deletions common/constant/manifest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "common/constant/manifest.h"

#include "common/internal/functions.h"
#include "common/internal/parameters.h"
#include "nth/debug/debug.h"
#include "nth/utility/no_destructor.h"

namespace ic {
namespace {

nth::NoDestructor<ConstantManifest> global_manifest_;

} // namespace

ConstantManifest const& ConstantManifest::Global() {
[[maybe_unused]] static const bool init = [&] {
internal_common::InitializeParameters(global_manifest_->table());
internal_common::InitializeFunctions(global_manifest_->table());
return false;
}();
return *global_manifest_;
}

ConstantManifest& ConstantManifest::MutableGlobal() {
return *global_manifest_;
}

Constant ConstantManifest::NextSlot() const {
return Constant(components_.size());
}

ConstantComponent const& ConstantManifest::operator[](size_t n) const {
NTH_REQUIRE((v.harden), n < components_.size());
return components_[n];
}

void InsertIntoGlobalConstantManifest(ConstantCategory category, uint32_t n) {
global_manifest_->components_.emplace_back(category, n);
NTH_LOG("{} INserting. size is now {}")<<={category, global_manifest_->components_.size()};
}

} // namespace ic
Loading

0 comments on commit aac5a3f

Please sign in to comment.