#quichelang — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #quichelang, aggregated by home.social.
-
The caller has to copy the data into the correct stack location. The challenge is that the caller is not in the function's stack frame, so it's need to calculate where data must go as an offset from the current SP. And that offset will depend on how many parameters are still to be pushed on the stack.
The code here isn't actually very complex, but it's a mind freak.
Here's the function dispatch which generates IL for the copies. V is the callees variable.
-
Last up is value parameters for 'pointered types' (those which are passed via pointers rather than in registers). The function needs to be able to modify the data without affecting the original value. That means a 'hidden' copy of the data (the array) into the function's static variable space. No data need be passed in registers - the function can use the static address of the variable/data.
-
That wasn't too difficult to get working. The atomic unit of expressions is the TExprSlug, either for the result of an expression, sub-expression or function. The slug then gets assigned to a variable.
I added a field to the Slug to point to the location in the IL which loads the pointer before the call - the pointer to where to store the result data. Then updated the write-slug-to-variable code to detect this field.
The code shows nested calls with a temp var.
-
Moving on to the scenario where the function return value is a pass by reference. To do this the caller needs to pass a pointer to the data location so the function can write to it.
Currently the expression parser has no knowledge of where a function result will be assigned. I’ll probably end up checking if the result is pass by reference and, if so, find or create the target variable and pass it into the function dispatcher.
-
I'm doing the detailed work on access specifiers and parameter passing.
Today's update is CONST arguments. Variable data now has an IsConst field and there's an assertion when incrementing the 'write version' of the variable - which aids testing and helps track down code which needs updating.
Writing to a CONST variable now fails, as does passing to as a VAR or OUT argument.
-
The first working test of pass-by-reference for arrays in register calling convention. Each variable has an addressing mode. The parameters use vaStaticRef - a static variable with a reference to the actual data address.
The code generator knows how to get from the addressing mode to the required data.
-
Bounds checking added to array indexing. Surprisingly easy - I just needed to add a call to the GenRangeCheck function, passing in the register, plus from- and to-types.
And a few edge case glitches solved largely around primitive selection, which was affecting the register in which the index was being passed.
-
Array support in Quiche is progressing nicely. I've added support functions Low High, Sizeof and Length, and now code to adjust for non-zero lower bounds when dereferencing an element.
Currently only for static array variables - pointer based derefencing will be the next step.
Images show the source and assembly code. I've hand added comments to the assembly. Plenty of room for optimisation here.