Skip to content

Commit

Permalink
chore: update fmt to 11.0.2 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrzlgnm authored Dec 14, 2024
1 parent 5921416 commit 3404a25
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmake/fmt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include(FetchContent)

FetchContent_Declare(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 8.1.1
GIT_TAG 11.0.2
)

FetchContent_MakeAvailable(fmt)
Expand Down
1 change: 1 addition & 0 deletions source/ast/callable_expression.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "callable_expression.hpp"

#include <fmt/format.h>
#include <fmt/ranges.h>

callable_expression::callable_expression(std::vector<std::string> params)
: parameters {std::move(params)}
Expand Down
1 change: 1 addition & 0 deletions source/ast/function_expression.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "function_expression.hpp"

#include <fmt/format.h>
#include <fmt/ranges.h>

function_expression::function_expression(std::vector<std::string>&& parameters, statement* body)
: callable_expression(std::move(parameters))
Expand Down
1 change: 1 addition & 0 deletions source/ast/hash_literal_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "hash_literal_expression.hpp"

#include <fmt/format.h>
#include <fmt/ranges.h>

auto hash_literal_expression::string() const -> std::string
{
Expand Down
1 change: 1 addition & 0 deletions source/ast/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vector>

#include <fmt/format.h>
#include <fmt/ranges.h>

template<typename Expression>
auto join(const std::vector<Expression*>& nodes, std::string_view sep = {}) -> std::string
Expand Down
5 changes: 5 additions & 0 deletions source/code/code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ enum class opcodes : uint8_t

auto operator<<(std::ostream& ostream, opcodes opcode) -> std::ostream&;

template<>
struct fmt::formatter<opcodes> : ostream_formatter
{
};

using operands = std::vector<size_t>;
using instructions = std::vector<uint8_t>;

Expand Down
2 changes: 2 additions & 0 deletions source/compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <chungus.hpp>
#include <code/code.hpp>
#include <doctest/doctest.h>
#include <fmt/ranges.h>
#include <overloaded.hpp>
#include <parser/parser.hpp>

#include "eval/object.hpp"
Expand Down
11 changes: 8 additions & 3 deletions source/compiler/symbol_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ auto operator<<(std::ostream& ost, symbol_scope scope) -> std::ostream&
return ost;
}

template<>
struct fmt::formatter<symbol_scope> : ostream_formatter
{
};

auto operator<<(std::ostream& ost, const symbol& sym) -> std::ostream&
{
return ost << fmt::format("symbol{{{}, {}, {}}}", sym.name, sym.scope, sym.index);
}

symbol_table::symbol_table(symbol_table* outer)
: m_parent(std::move(outer))
: m_parent(outer)
{
}

Expand All @@ -44,7 +49,7 @@ auto symbol_table::define(const std::string& name) -> symbol
using enum symbol_scope;
return m_store[name] = symbol {
.name = name,
.scope = m_parent ? local : global,
.scope = (m_parent != nullptr) ? local : global,
.index = m_defs++,
};
}
Expand Down Expand Up @@ -73,7 +78,7 @@ auto symbol_table::resolve(const std::string& name) -> std::optional<symbol>
if (m_store.contains(name)) {
return m_store[name];
}
if (m_parent) {
if (m_parent != nullptr) {
auto maybe_symbol = m_parent->resolve(name);
if (!maybe_symbol.has_value()) {
return maybe_symbol;
Expand Down
5 changes: 4 additions & 1 deletion source/eval/ast_eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include <ast/unary_expression.hpp>
#include <chungus.hpp>
#include <doctest/doctest.h>
#include <fmt/ranges.h>
#include <lexer/token_type.hpp>
#include <overloaded.hpp>
#include <parser/parser.hpp>

#include "environment.hpp"
Expand Down Expand Up @@ -364,7 +366,8 @@ const builtin_function_expression builtin_len {
}
return make_error("argument of type {} to len() is not supported", maybe_string_or_array->type());
}};
const builtin_function_expression builtin_puts {{"puts"},

const builtin_function_expression builtin_puts {"puts",
{"str"},
[](const array_object::array& arguments) -> const object*
{
Expand Down
8 changes: 3 additions & 5 deletions source/eval/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <ast/callable_expression.hpp>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
#include <overloaded.hpp>

auto operator<<(std::ostream& ostrm, object::object_type type) -> std::ostream&
{
Expand Down Expand Up @@ -57,7 +59,7 @@ auto integer_object::hash_key() const -> hash_key_type

auto builtin_object::inspect() const -> std::string
{
return fmt::format("builtin {}(){{...}}", builtin->name);
return fmt::format("builtin {}({}){{...}}", builtin->name, fmt::join(builtin->parameters, ", "));
}

auto function_object::inspect() const -> std::string
Expand All @@ -80,8 +82,6 @@ auto array_object::inspect() const -> std::string
return strm.str();
}

namespace
{
auto operator<<(std::ostream& strm, const hashable_object::hash_key_type& t) -> std::ostream&
{
std::visit(
Expand All @@ -94,8 +94,6 @@ auto operator<<(std::ostream& strm, const hashable_object::hash_key_type& t) ->
return strm;
}

} // namespace

auto hash_object::inspect() const -> std::string
{
std::stringstream strm;
Expand Down
16 changes: 7 additions & 9 deletions source/eval/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@

#include "eval/environment.hpp"

// helper type for std::visit
template<typename... T>
struct overloaded : T...
{
using T::operator()...;
};
template<class... T>
overloaded(T...) -> overloaded<T...>;

struct object
{
enum class object_type : std::uint8_t
Expand Down Expand Up @@ -71,6 +62,11 @@ struct object

auto operator<<(std::ostream& ostrm, object::object_type type) -> std::ostream&;

template<>
struct fmt::formatter<object::object_type> : ostream_formatter
{
};

struct hashable_object : object
{
using hash_key_type = std::variant<int64_t, std::string, bool>;
Expand All @@ -80,6 +76,8 @@ struct hashable_object : object
[[nodiscard]] virtual auto hash_key() const -> hash_key_type = 0;
};

auto operator<<(std::ostream& strm, const hashable_object::hash_key_type& t) -> std::ostream&;

struct integer_object : hashable_object
{
explicit integer_object(int64_t val)
Expand Down
8 changes: 7 additions & 1 deletion source/lexer/token_type.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once

#include <cstdint>
#include <ostream>

#include <fmt/ostream.h>

enum class token_type
enum class token_type : std::uint8_t
{
// special tokens
illegal,
Expand Down Expand Up @@ -56,3 +57,8 @@ enum class token_type
};

auto operator<<(std::ostream& ostream, token_type type) -> std::ostream&;

template<>
struct fmt::formatter<token_type> : ostream_formatter
{
};
10 changes: 10 additions & 0 deletions source/overloaded.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

// helper type for std::visit
template<typename... T>
struct overloaded : T...
{
using T::operator()...;
};
template<class... T>
overloaded(T...) -> overloaded<T...>;
2 changes: 2 additions & 0 deletions source/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include <doctest/doctest.h>
#include <eval/object.hpp>
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <lexer/token.hpp>
#include <overloaded.hpp>

namespace
{
Expand Down
2 changes: 2 additions & 0 deletions source/vm/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <doctest/doctest.h>
#include <eval/object.hpp>
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <overloaded.hpp>
#include <parser/parser.hpp>

vm::vm(frames frames, const constants* consts, constants* globals)
Expand Down

0 comments on commit 3404a25

Please sign in to comment.