wren-lang / wren

The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.
http://wren.io
MIT License
6.9k stars 552 forks source link

A hash protocol #824

Open ChayimFriedman2 opened 4 years ago

ChayimFriedman2 commented 4 years ago

We already have an iterator protocol, so why not have a hash protocol, say a method hash()? All we need to change is this:

https://github.com/wren-lang/wren/blob/45c67fae0c2fbe78b608d372d0951ffe05f02690/src/vm/wren_value.c#L410-L412

Then we can simplify the code and just let the builtins have hash() method, but I'll not sure if this will degrade performance.

mhermier commented 4 years ago

I have a patch for that, that introduce *::hash getter. There is one major issue with it, because of the lack of reentracy, you can't expect internal Map to use the getter. So you end up having to recreate an external HashMap class.

ChayimFriedman2 commented 4 years ago

Why? most languages do that.

mhermier commented 4 years ago

Reentracy is required to do that.

ChayimFriedman2 commented 4 years ago

But we need it reentrant anyway. So when we'll have a solution...

mhermier commented 4 years ago

It can be introduced with that reentracy limit, till it gets fixed.

ChayimFriedman2 commented 4 years ago

It can, but I think it's confusing. However we can tell reentrancy is a bug then it's OK 😄.