I’m getting stuck in how to implement assignment operations. Specifically, things like m[0][1] = abc, things like that. The way I have it now, I would be copying multiple instances of m onto the stack, then having the [] operators write their part, then copy all of ‘m’ back, which is a complete waste. What if ‘m’ is some huge 2D array? Beginning with ‘m’, that should return a reference, not a value.
How do I encode this using the existing type system?
spa::Value can have a boolean ‘ref’. If its true, then it doesn’t own its own data. spa::Value has the option to do a deep copy, which would mean owning its own data if necessary.
Got the 2nd proof of concept working! (The first proof of concept being the failed design I gave up on…) The simple example I started on works! Advantages to doing a proper code flattening: faster, easier to debug, can save out a pre-compiled script, also easier to do things like throw-catch, easier to look at the run process.
Now I’m left with having to implement the script commands for all existing funct types.
Crud… this is going to take a while… and even longer to completely debug….
Also, going to have to find some trickery to get references of subTypes. Previously, I was copying it, but with references, its trickier. ValueCon<> is a subclass of ValueImp, I could try creating ValueConPt<>, which would point to its data, but not own it. That will work… Also, that means that I have an implicit pointer implementation. Whoa… With pointers, I can randomly access packed arrays of data, which is kind of what the bracket operator does. So its actually more of a reference than a pointer. BUT, what if I allowed pointers to alloc/dealloc their own memory? That could be really cool, or get very confusing. A scripting language with its own heap space. Would that be a first? Also, I don’t know how the type system would handle it. It would be cool if I could keep chaining pointer modifiers, like int****, but not possible, and completely unecessary. So at the most, any value could be a reference/pointer.
Ok, this is definitely a diversion, but I would need to really test this stuff before I break everything.
Change of plan, not going to do it. Just going to keep the existing reference method in place. All bracket operators will copy the contents of the slice on the stack. If its too slow, I’ll deal with it later. Maybe have to create an iterator class to deal with this. The method I mentioned above is too much of a hack.
This is the most fragmented blog entry. I decided not to erase my train of thought. So here is the latest attempt. Using the Type mechanism, I’m going to try to make a reference type. So we can do Ref or Ref or anything. Hopefully, I can find an easy way to make it work…
Another interesting thing. The bracket operator has different meaning depending on when its part of a lhs expression or a rhs expression. In a rhs expression, its read-only, so the value can be copied. For the lhs expression, that’s when we need the reference functionality. So we need to be able to flag whether we’re in a lhs or rhs…..