mirror of https://github.com/tbklang/tlang.git
Array support #81
Labels
No Label
dependency
emit
hashmapper
lebanonmapper
lexer
meta
needsfix
parser
qol
question
resolution
typing
No Milestone
No project
No Assignees
1 Participants
Notifications
Total Time Spent: 2 days 19 hours
Due Date
deavmi
2 days 19 hours
Depends on
You do not have permission to read 2 dependencies
Reference: tlang/tlang#81
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What is to be done?
Add support for arrays to TLang, this means both stack allocated arrays and also the syntax to use them as pointer types interchangeably. You know all that good stuff.
Roadmap
There are a few things that need to be considered.
Handling of
int[]
✅Something like
int[]
should automatically just be converted toint*
as that makes life easier for us - it lessens the amount of work required.Therefore we should be looking at updating the following code in
symbols/typing/builtins.d
'sgetBuiltInType()
:To return
new Pointer(<...>, <...>)
instead ofnew Array(<...>, <...>)
Status: Added as of commit
2ea4a3791290c1555d695101182426a443e91b1d
on thearrays
branchHandling of
int[<numeric>]
🤔To be discussed, this will need more work. See issue #102
Handling of
int[]*[]*
✅This isn't a hard problem, the recursive nature would make it work, but the usage of
lastIndexOf
in the code below results in us skipping certain things:Sub-issue 3 (
int*[]
andint[]*
) solution ✅Here is the solution:
Status: Fixed as of
32993900b592e4b4dd9680d873ee508821df83a6
on thearrays
branch ✅Okay this needs to be continually worked on - including today.
For non-stack arrays (effectively sugar pointer syntax) I produce a
PointerDereferenceAssignmentInstruction
using data popped off from the code queue.Lesser todos 🥥
These are some todo items that are of less importance and are to be finished later:
index
fields of any array-related things for pointer and stack-based arrays from theValue
instruction type to theIntegerLiteral
(or whatever it is called) instruction typeCodegen + emit ✅
On commit
98b3ab42848e940ef60a21f2755178148338ba6f
we have the following apparently working:🏖️ Not-so-lesser todos
<compType>*
when passed into function argumentscast()
support for array types 🚧Testing 🚧
We should setup some semantic tests, seeing as manual tests have passed, namely:
Semantic tests
simple_stack_arrays4.t
simple_stack_array_coerce.t
simple_stack_array_coerce_ptr_syntax.t
complex_stack_array_coerce.t
simple_pointer_array_syntax.t
(blocked by #80)Typechecks
simple_stack_array_coerce_wrong.t
Just emit
complex_stack_arrays1.t
simple_arrays.t
simple_arrays2.t
simple_arrays4.t
simple_stack_arrays2.t
complex_stack_arrays1.t
Typechecking 🚧
ArrayAssignment
andArrayIndex
nodesUpdate for stack-based arrays
I'm busy working on coercing a type like
<compType>[<size>]
(the argument type) to<compType>*
(the parameter type) right now on thearrays
branch.Casting syntax ✅
As of commit
58a4374f9e97ff3372aa548d9ced6e3e674cbc53
(at most, probs earlier) we defs have casting working as the following works:And outputs the following C code:
I think coercion is broken in how we check for it in
canCoerceStackArray
as the code below successfully coerces when it shouldn't:The output we are getting is:
This could possibly be in
isSameType
asint**
andint*
are not the same, so it seems it coerced correctly but thereturn isSameType(Type, Type)
is wrong. See #80 for this fix.Currently
simple_stack_array_coerce_wrong.t
doesn't fail but with new code frompointers
it shouldOther todos
Merge seems fine, preliminary CI too
Pointer "array-syntax"
simple_pointer_array_syntax.t
Works ✅
simple_stack_array_coerce_ptr_syntax.t
works ✅simple_stack_array_coerce_wrong.t
works (it fails with a type mismatch error as it should) ✅Everything is almost done, just maybe some other tests here and there but honestly this looks good.
I have done this with
complex_stack_array_coerce.t
✅This is done as of commit
e4c0f08b3654d50cb2af3aed6de92ceb75eb60e0
, I added many:Test cases
complex_stack_array_coerce_permutation_good.t
which has a lot of different ways to writeint**
(thinkint*[]
etc)complex_stack_array_coerce_bad1.t
,complex_stack_array_coerce_bad2.t
andcomplex_stack_array_coerce_bad3.t
CI passes ✅
I'm gonna merge now rather than later, pretty sure most TODOs are done anyways - if not we can always open a branch for type checking again but it seems the typechecking is suprisingly solid - most likely resulting from that new code in
pointers
which updatedisSameType(Type t1, Type t2)
to check pointers correctly.All looks good, going to do a squash merge in a minute.
Closing