Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for tagged-literal #180

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

djblue
Copy link
Contributor

@djblue djblue commented Jan 24, 2025

Not done yet, but just wanted to put this up to make sure I was headed in the right direction.

@@ -499,6 +504,8 @@ jank_object_ptr jank_load_clojure_core_native()
intern_fn("hash-unordered-coll", static_cast<native_hash (*)(object const *)>(&hash::unordered));
intern_fn("read-string", &core_native::read_string);
intern_fn("jank-version", &core_native::jank_version);
intern_fn("tagged-literal", &core_native::tagged_literal);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where these two fns should live.


object base{ obj_type };

object_ptr tag;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically the tag should always be a symbol, but this was easier to get working for me.

return get(key, obj::nil::nil_const());
}

object_ptr tagged_literal::get_entry(object_ptr /*key*/) const
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think get_entry and contains are supported by tagged-literals on the jvm, so not sure what to do here.

}

auto const s(expect_object<tagged_literal>(&o));
return tag == s->tag && form == s->form;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to be working:

% ./build/jank repl             
Bottom of clojure.core
clojure.core=> (= (tagged-literal 'foo {}) (tagged-literal 'foo {}))
false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By looking at similar code, I'm guessing runtime::equal is more appropriate to compare tag and form as they are not interned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @frenchy64, that was it! I don't know why I assumed that == would be overloaded instead of providing reference equality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants