Skip to content

Commit

Permalink
Change visitor method name back to visit
Browse files Browse the repository at this point in the history
The fact that our MarkingVisitor uses a stack is an implementation
detail.
  • Loading branch information
seven1m committed Nov 14, 2024
1 parent b12699c commit d0329e6
Show file tree
Hide file tree
Showing 48 changed files with 164 additions and 169 deletions.
2 changes: 1 addition & 1 deletion include/natalie/abstract_method_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AbstractMethodObject : public Object {

virtual void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
visitor.enqueue(m_method);
visitor.visit(m_method);
}

virtual void gc_inspect(char *buf, size_t len) const override {
Expand Down
2 changes: 1 addition & 1 deletion include/natalie/array_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class ArrayObject : public Object {
virtual void visit_children(Visitor &visitor) const override final {
Object::visit_children(visitor);
for (auto val : m_vector) {
visitor.enqueue(val);
visitor.visit(val);
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/natalie/array_packer/float_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ArrayPacker {
String pack(Env *env);

virtual void visit_children(Visitor &visitor) const override {
visitor.enqueue(m_source);
visitor.visit(m_source);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion include/natalie/array_packer/integer_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ArrayPacker {
String pack(Env *env);

virtual void visit_children(Visitor &visitor) const override {
visitor.enqueue(m_source);
visitor.visit(m_source);
}

private:
Expand Down
4 changes: 2 additions & 2 deletions include/natalie/array_packer/packer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace ArrayPacker {
StringObject *pack(Env *env, StringObject *buffer);

virtual void visit_children(Visitor &visitor) const override {
visitor.enqueue(m_source);
visitor.enqueue(m_encoding);
visitor.visit(m_source);
visitor.visit(m_encoding);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion include/natalie/array_packer/string_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ArrayPacker {
using PackHandlerFn = void (StringHandler::*)();

virtual void visit_children(Visitor &visitor) const override {
visitor.enqueue(m_string_object);
visitor.visit(m_string_object);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion include/natalie/binding_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BindingObject : public Object {

virtual void visit_children(Visitor &visitor) const override final {
Object::visit_children(visitor);
visitor.enqueue(&m_env);
visitor.visit(&m_env);
}

Value source_location() const;
Expand Down
6 changes: 3 additions & 3 deletions include/natalie/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class Block : public Cell {
void copy_fn_pointer_to_method(Method *);

virtual void visit_children(Visitor &visitor) const override final {
visitor.enqueue(m_env);
visitor.enqueue(m_calling_env);
visitor.enqueue(m_self);
visitor.visit(m_env);
visitor.visit(m_calling_env);
visitor.visit(m_self);
}

virtual void gc_inspect(char *buf, size_t len) const override {
Expand Down
4 changes: 2 additions & 2 deletions include/natalie/complex_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ComplexObject : public Object {

virtual void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
visitor.enqueue(m_real);
visitor.enqueue(m_imaginary);
visitor.visit(m_real);
visitor.visit(m_imaginary);
}

private:
Expand Down
4 changes: 2 additions & 2 deletions include/natalie/dir_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class DirObject : public Object {

virtual void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
visitor.enqueue(m_path);
visitor.enqueue(m_encoding);
visitor.visit(m_path);
visitor.visit(m_encoding);
}

static Value size_fn(Env *env, Value self, Args, Block *) {
Expand Down
6 changes: 3 additions & 3 deletions include/natalie/enumerator/arithmetic_sequence_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class Enumerator::ArithmeticSequenceObject : public Object {

virtual void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
visitor.enqueue(m_begin);
visitor.enqueue(m_end);
visitor.enqueue(m_step);
visitor.visit(m_begin);
visitor.visit(m_end);
visitor.visit(m_step);
}

private:
Expand Down
4 changes: 2 additions & 2 deletions include/natalie/gc/cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Cell {

class Visitor {
public:
virtual void enqueue(const Cell *cell) = 0;
void enqueue(Value);
virtual void visit(const Cell *cell) = 0;
void visit(Value);
};

virtual void visit_children(Visitor &) const {
Expand Down
7 changes: 1 addition & 6 deletions include/natalie/gc/marking_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
#include "tm/vector.hpp"
#include <stack>

// time boardslam.rb 3 5 1
// 1.656 using C stack
// 1.692 using std::stack
// 2.847 using std::queue

namespace Natalie {

class MarkingVisitor : public Cell::Visitor {
public:
virtual void enqueue(const Cell *cell) override final {
virtual void visit(const Cell *cell) override final {
if (!cell || cell->is_marked()) return;
m_stack.push(cell);
}
Expand Down
8 changes: 4 additions & 4 deletions include/natalie/hash_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class HashObject : public Object {
bool removed { false };

virtual void visit_children(Visitor &visitor) const override final {
visitor.enqueue(prev);
visitor.enqueue(next);
visitor.enqueue(key);
visitor.enqueue(val);
visitor.visit(prev);
visitor.visit(next);
visitor.visit(key);
visitor.visit(val);
}
};

Expand Down
6 changes: 3 additions & 3 deletions include/natalie/io_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class IoObject : public Object {

virtual void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
visitor.enqueue(m_external_encoding);
visitor.enqueue(m_internal_encoding);
visitor.enqueue(m_path);
visitor.visit(m_external_encoding);
visitor.visit(m_internal_encoding);
visitor.visit(m_path);
}

static Value size_fn(Env *env, Value self, Args, Block *) {
Expand Down
2 changes: 1 addition & 1 deletion include/natalie/managed_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ManagedVector : public Cell, public TM::Vector<T> {

virtual void visit_children(Visitor &visitor) const override final {
for (auto it = TM::Vector<T>::begin(); it != TM::Vector<T>::end(); ++it) {
visitor.enqueue(*it);
visitor.visit(*it);
}
}

Expand Down
4 changes: 2 additions & 2 deletions include/natalie/match_data_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class MatchDataObject : public Object {

virtual void visit_children(Visitor &visitor) const override final {
Object::visit_children(visitor);
visitor.enqueue(m_string);
visitor.enqueue(m_regexp);
visitor.visit(m_string);
visitor.visit(m_regexp);
}

virtual String dbg_inspect() const override;
Expand Down
8 changes: 4 additions & 4 deletions include/natalie/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ class Method : public Cell {
const Optional<size_t> &get_line() const { return m_line; }

virtual void visit_children(Visitor &visitor) const override final {
visitor.enqueue(m_owner);
visitor.enqueue(m_env);
visitor.enqueue(m_self);
visitor.enqueue(m_original_method);
visitor.visit(m_owner);
visitor.visit(m_env);
visitor.visit(m_self);
visitor.visit(m_original_method);
}

virtual void gc_inspect(char *buf, size_t len) const override {
Expand Down
6 changes: 3 additions & 3 deletions include/natalie/method_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class MethodObject : public AbstractMethodObject {

virtual void visit_children(Visitor &visitor) const override final {
AbstractMethodObject::visit_children(visitor);
visitor.enqueue(m_object);
visitor.enqueue(m_method);
visitor.enqueue(m_method_missing_name);
visitor.visit(m_object);
visitor.visit(m_method);
visitor.visit(m_method_missing_name);
}

virtual void gc_inspect(char *buf, size_t len) const override {
Expand Down
2 changes: 1 addition & 1 deletion include/natalie/proc_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ProcObject : public Object {

virtual void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
visitor.enqueue(m_block);
visitor.visit(m_block);
}

virtual void gc_inspect(char *buf, size_t len) const override {
Expand Down
4 changes: 2 additions & 2 deletions include/natalie/range_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class RangeObject : public Object {

virtual void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
visitor.enqueue(m_begin);
visitor.enqueue(m_end);
visitor.visit(m_begin);
visitor.visit(m_end);
}

virtual String dbg_inspect() const override;
Expand Down
4 changes: 2 additions & 2 deletions include/natalie/rational_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class RationalObject : public Object {

virtual void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
visitor.enqueue(m_numerator);
visitor.enqueue(m_denominator);
visitor.visit(m_numerator);
visitor.visit(m_denominator);
}

virtual void gc_inspect(char *buf, size_t len) const override {
Expand Down
2 changes: 1 addition & 1 deletion include/natalie/regexp_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class RegexpObject : public Object {
void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
if (m_pattern)
visitor.enqueue(m_pattern);
visitor.visit(m_pattern);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion include/natalie/string_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class StringObject : public Object {

virtual void visit_children(Visitor &visitor) const override final {
Object::visit_children(visitor);
visitor.enqueue(m_encoding.ptr());
visitor.visit(m_encoding.ptr());
}

virtual void gc_inspect(char *buf, size_t len) const override {
Expand Down
6 changes: 3 additions & 3 deletions include/natalie/string_unpacker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class StringUnpacker : public Cell {
Value unpack1(Env *env);

virtual void visit_children(Visitor &visitor) const override {
visitor.enqueue(m_source);
visitor.enqueue(m_unpacked_value);
visitor.enqueue(m_unpacked_array);
visitor.visit(m_source);
visitor.visit(m_unpacked_value);
visitor.visit(m_unpacked_array);
}

private:
Expand Down
6 changes: 3 additions & 3 deletions include/natalie/symbol_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class SymbolObject : public Object {

virtual void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
visitor.enqueue(m_string);
visitor.enqueue(m_encoding);
visitor.visit(m_string);
visitor.visit(m_encoding);
}

virtual void gc_inspect(char *buf, size_t len) const override {
Expand All @@ -91,7 +91,7 @@ class SymbolObject : public Object {

static void visit_all_symbols(Visitor &visitor) {
for (auto pair : s_symbols) {
visitor.enqueue(pair.second);
visitor.visit(pair.second);
}
}

Expand Down
4 changes: 2 additions & 2 deletions include/natalie/time_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class TimeObject : public Object {

virtual void visit_children(Visitor &visitor) const override {
Object::visit_children(visitor);
visitor.enqueue(m_integer);
visitor.enqueue(m_subsec);
visitor.visit(m_integer);
visitor.visit(m_subsec);
}

virtual void gc_inspect(char *buf, size_t len) const override {
Expand Down
4 changes: 2 additions & 2 deletions include/natalie/unbound_method_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class UnboundMethodObject : public AbstractMethodObject {

virtual void visit_children(Visitor &visitor) const override final {
AbstractMethodObject::visit_children(visitor);
visitor.enqueue(m_module_or_class);
visitor.enqueue(m_method);
visitor.visit(m_module_or_class);
visitor.visit(m_method);
}

virtual void gc_inspect(char *buf, size_t len) const override {
Expand Down
6 changes: 3 additions & 3 deletions src/constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ void Constant::autoload(Env *env, Value self) {
}

void Constant::visit_children(Visitor &visitor) const {
visitor.enqueue(m_name);
visitor.enqueue(m_value);
visitor.enqueue(m_autoload_path);
visitor.visit(m_name);
visitor.visit(m_value);
visitor.visit(m_autoload_path);
}

}
20 changes: 10 additions & 10 deletions src/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,15 @@ Env *Env::non_block_env() {
}

void Env::visit_children(Visitor &visitor) const {
visitor.enqueue(m_vars);
visitor.enqueue(m_outer);
visitor.enqueue(m_block);
visitor.enqueue(m_this_block);
visitor.enqueue(m_caller);
visitor.enqueue(m_method);
visitor.enqueue(m_module);
visitor.enqueue(m_match);
visitor.enqueue(m_exception);
visitor.enqueue(m_catch);
visitor.visit(m_vars);
visitor.visit(m_outer);
visitor.visit(m_block);
visitor.visit(m_this_block);
visitor.visit(m_caller);
visitor.visit(m_method);
visitor.visit(m_module);
visitor.visit(m_match);
visitor.visit(m_exception);
visitor.visit(m_catch);
}
}
10 changes: 5 additions & 5 deletions src/exception_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ bool ExceptionObject::is_local_jump_error_with_break_point(nat_int_t match_break

void ExceptionObject::visit_children(Visitor &visitor) const {
Object::visit_children(visitor);
visitor.enqueue(m_message);
visitor.enqueue(m_backtrace);
visitor.enqueue(m_backtrace_value);
visitor.enqueue(m_backtrace_locations);
visitor.enqueue(m_cause);
visitor.visit(m_message);
visitor.visit(m_backtrace);
visitor.visit(m_backtrace_value);
visitor.visit(m_backtrace_locations);
visitor.visit(m_cause);
}

}
2 changes: 1 addition & 1 deletion src/false_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Value FalseObject::to_s(const Env *env) const {
void FalseObject::visit_children(Visitor &visitor) const {
Object::visit_children(visitor);
if (s_string)
visitor.enqueue(s_string);
visitor.visit(s_string);
}

}
Loading

0 comments on commit d0329e6

Please sign in to comment.