civboot / fngi

a readable language that grows from the silicon
The Unlicense
59 stars 3 forks source link

debug locations #16

Open vitiral opened 1 year ago

vitiral commented 1 year ago

There are a lot of possible ways to find the location of an instruction in a source file. You could:

  1. Have an instruction for updating the position (U2). This has cost: both in code size AND in execution time (bad!)
  2. Keep some kind of detailed token map with pointers to the code. This would be pretty bloated
  3. Have a byte array which maps 1:1 with the function body. To find the position, add bytes until you get to the same offset. This will be called posData (positional data)

The latter one has several benefits:

The basic implementation:

Option 3 doesn't work with text macros. Let's go with Option 2

How do I design a text macro system that works well with this? I would like to be able to view the expansions of text macros when compilation fails

Well, I think it's fairly obvious isn't it? Compile text macros to a file... then parse them! In fact: compile all text macros to an append-only file. Don't use memory for text macros, as that could quickly explode our available memory.

This leaves us with (2) -- but we have a secret weapon: our debug symbols can also be stored in a file, aka they will be byte-serialized to a file. This will happen eventually: for now, they will be malloc'd to aid in simplicity.

So when walking the debug symbols: