@@ -27,6 +27,42 @@ namespace whisker {
2727
2828namespace {
2929
30+ /* *
31+ * A class representing the bag of properties at the global scope (even before
32+ * the root scope).
33+ *
34+ * This is a bespoke implementation primarily for debugging purposes.
35+ */
36+ class global_scope_object : public map {
37+ public:
38+ explicit global_scope_object (map::raw properties)
39+ : properties_(std::move(properties)) {}
40+
41+ std::optional<object> lookup_property (
42+ std::string_view identifier) const override {
43+ if (auto property = properties_.find (identifier);
44+ property != properties_.end ()) {
45+ return property->second ;
46+ }
47+ return std::nullopt ;
48+ }
49+
50+ void print_to (tree_printer::scope& scope, const object_print_options& options)
51+ const override {
52+ scope.print (" <global scope> (size={})" , properties_.size ());
53+ for (const auto & [key, value] : properties_) {
54+ whisker::print_to (value, scope.make_child (" '{}' → " , key), options);
55+ }
56+ }
57+
58+ private:
59+ map::raw properties_;
60+ };
61+
62+ } // namespace
63+
64+ namespace detail {
65+
3066std::optional<object> find_property (
3167 diagnostics_engine& diags,
3268 const object& self,
@@ -65,46 +101,14 @@ std::optional<object> find_property(
65101 });
66102}
67103
68- /* *
69- * A class representing the bag of properties at the global scope (even before
70- * the root scope).
71- *
72- * This is a bespoke implementation primarily for debugging purposes.
73- */
74- class global_scope_object : public map {
75- public:
76- explicit global_scope_object (map::raw properties)
77- : properties_(std::move(properties)) {}
78-
79- std::optional<object> lookup_property (
80- std::string_view identifier) const override {
81- if (auto property = properties_.find (identifier);
82- property != properties_.end ()) {
83- return property->second ;
84- }
85- return std::nullopt ;
86- }
87-
88- void print_to (tree_printer::scope& scope, const object_print_options& options)
89- const override {
90- scope.print (" <global scope> (size={})" , properties_.size ());
91- for (const auto & [key, value] : properties_) {
92- whisker::print_to (value, scope.make_child (" '{}' → " , key), options);
93- }
94- }
95-
96- private:
97- map::raw properties_;
98- };
99-
100- } // namespace
104+ } // namespace detail
101105
102106std::optional<object> eval_context::lexical_scope::lookup_property (
103107 diagnostics_engine& diags, const ast::identifier& identifier) {
104108 if (auto local = locals_.find (identifier.name ); local != locals_.end ()) {
105109 return local->second ;
106110 }
107- return find_property (diags, this_ref_, identifier);
111+ return detail:: find_property (diags, this_ref_, identifier);
108112}
109113
110114eval_context::eval_context (diagnostics_engine& diags, object globals)
@@ -221,7 +225,7 @@ eval_context::look_up_object(const ast::variable_lookup& lookup) {
221225 ++component) {
222226 try {
223227 std::optional<object> next =
224- find_property (diags_, *current, component->property );
228+ detail:: find_property (diags_, *current, component->property );
225229 if (!next.has_value ()) {
226230 return unexpected (eval_property_lookup_error (
227231 *current, /* missing_from */
0 commit comments