Closed gvwilson closed 2 years ago
I did a native implementation.
Honestly, I can't think of a way to implement arrays directly in Lox. Once you have arrays, you could implement dicts in lox the same way clox does in c.
I'd be very grateful for a pointer if you can share the code - thanks in advance.
I've made a number of changes, but it's base is clox: https://github.com/degustaf/xan
Basically, it's just a wrapper around the ValueArray that clox already has.
Thanks very much - I'll have a look tonight. From what I can tell, Wren implements arrays (and dicts) by having the compiler insert instructions to define a few built-in classes at the start of every program, then invoking the constructors of those classes in special cases like [1, 2, 3]
. I'm hoping something like that will work for Lox so that people will be able to derive their own classes from List and Dict.
Has anyone added arrays and dicts to Lox? If so, did you do a native implementation, or did you add List and Dict as classes and get the compiler to initialize instances of them?