codereport / jsource

J Language Source Code. Livestream links ⬇️
https://www.youtube.com/playlist?list=PLVFrD1dmDdvfVhYLU_iKkV67X9XqCJLWe
Other
38 stars 20 forks source link

WIP: Restructure constants in j.c #183

Open herwinw opened 3 years ago

herwinw commented 3 years ago

Well, it works, but we should merge #178 first to prevent a conflict hell, and finish this one.

herwinw commented 3 years ago

Well, the more you learn, the more you realize the thing you're trying to do won't work.

The AD struct has a number of fields, this refactor relates mainly to 3 of them:

The complete structure is of a size of 64 bits, but this is just the header. The contents of the array itself are appended after this struct, unless we're dealing with an atom of certain types. The structure is visualized in these slides at the first three slides.The red part in these visualizations are the 64 bits allocated for the struct. The I s[1] for the shape is very misleading. The actual memory layout is like this:

Looking at the slides again, the second visualization shows an integer atom. This one has rank=0, which means the entry at s[1] is actually not a shape, but the integer value. This one fits in the 64 bits of AD, and this is what the Bnum array and the booleans use. The first visualization is a larger, we have a rank of two, which means the shape array actually contains 2 items, and using the value ofs[1]returns a byte outside theAD` struct. And there are 4 more bytes trailing this datastructure.

Back to my original statement: converting I[8] to AD. This works, but next you're getting to the macros CREBLOCKVEC1I and CREBLOCKVEC2I that allocate I[9].

This files also shows an atom for an imaginary number, where the shape is empty, and the items are two floats. This is stored in the struct Bd2, that consists of a header of 56 bits, and two floats (with the first float located at the memory index where AD stores an integer). With my current knowledge, this looks like a start for the desired direction: remove the shape array from the AD struct, which makes AD an actual header. Use structs to combine the header with the shape and the actual data if these values are static. Make the values in kchain/k depend on the size of the header instead of hardcoded values. And finally, we're allowed to touch the internals of AD.