Commit Graph

100 Commits

Author SHA1 Message Date
Kartik Agaram
4d37fb5213 5409
Bugfix eleven: segment flags were incorrectly computed. examples/ex1 now
verified! Added to CI.
2019-07-17 00:29:52 -07:00
Kartik Agaram
c2a74205d6 5408
Bugfix ten: type error in `convert`. I was calling `rewind-stream` on a
`buffered-file`.

examples/ex1 is now just one nibble off the canonical.

I *have* found one missing feature in the self-hosted translator,
though: dquotes doesn't support newlines in strings, even though the C++
version does. dquotes parses them right, but the value initialized in
the data segment is wrong.
2019-07-16 23:40:25 -07:00
Kartik Agaram
70a999aaeb 5407
Bugfix nine: flush(out) after translation is done.

Still one remaining bug from comparing ELF binaries: emit-segments
prints nothing for some reason.
2019-07-15 17:03:39 -07:00
Kartik Agaram
5490993845 5406
Bugfix eight: incorrect segment count in ELF header.

The generated examples/ex1 is still not right. But it has the second
segment now. Or almost all of it. Final byte is missing for some reason.
2019-07-15 16:39:13 -07:00
Kartik Agaram
aef4efb959 5404 - subx/examples/ex1 now translating
The result isn't an identical binary to before, and it segfaults when
run. But it's bugfix seven.

A couple of places where we make .subx files a little more strict:

a) All .subx files must define a data segment. Even if they have no
data.

b) All .subx files must define an `Entry` label for the binary to start
at. Earlier we used to default to the start of the code label. That's
not too hard to add; we'd just need to:
  i) rename `get` to `get-or-abort`
  ii) clone a third variant of `get-or-insert` called `get` that returns
     null if the key is not found.
  iii) use `get` rather than `get-or-abort` when looking up the `Entry`
     label.
2019-07-15 12:26:41 -07:00
Kartik Agaram
c4412d299e . 2019-07-13 22:35:15 -07:00
Kartik Agaram
7f23be0107 .
Clean up.
2019-07-13 19:49:55 -07:00
Kartik Agaram
2773d5a48a survey.subx now passing all tests 2019-07-13 19:41:16 -07:00
Kartik Agaram
c6f91e15a4 test-convert-computes-addresses bugfix six
map of how far we've gotten by now (functions with '*' independently tested):
✓ compute-offsets*
✓ compute-addresses*
✓ emit-output
✓   emit-headers
✓     emit-elf-header
✓       emit-hex-array*
✓     first emit-elf-program-header-entry
✓       emit-hex-array*
?     second emit-elf-program-header-entry
        emit-hex-array*
    emit-segments*
2019-07-13 19:25:52 -07:00
Kartik Agaram
58c643c2c2 fixed fifth bug, hit sixth 2019-07-13 15:43:32 -07:00
Kartik Agaram
d30c716db2 .
Clean up.
2019-07-13 15:40:25 -07:00
Kartik Agaram
50ac5cab9c fixed fourth bug, hit fifth 2019-07-13 15:18:00 -07:00
Kartik Agaram
195a0d7d7d fixed third bug, hit fourth 2019-07-13 14:47:03 -07:00
Kartik Agaram
4c81119344 .
Clean up.
2019-07-13 12:30:38 -07:00
Kartik Agaram
a2593892de fixed second bug, hit third 2019-07-13 12:27:54 -07:00
Kartik Agaram
f518bd972e . 2019-07-13 08:56:15 -07:00
Kartik Agaram
fb935eaa7e fixed one bug, hit another
I carefully logged the segment a label is declared in but forgot to
actually save it in the table. This has been a theoretic concern for
some time, but I've never seen it actually happen until now. SubX is
just too low level.

Now I get past the first two phases but code generation fails to find
the 'Entry' label.
2019-07-12 23:41:23 -07:00
Kartik Agaram
8ba17d839e .
Snapshot at a random moment, showing a new debugging trick: hacking on
the C++ level to dump memory contents on specific labels.

For some reason label 'x' doesn't have a segment assigned by the time we
get to compute-addresses.
2019-07-12 23:14:13 -07:00
Kartik Agaram
f0eb631428 compute-offsets test now passing
The final integration test-convert-computes-addresses is still failing.
2019-07-12 11:39:35 -07:00
Kartik Agaram
e150e6e46e the pseudocode is pretty long, so add an outline 2019-07-12 11:26:50 -07:00
Kartik Agaram
38a314d320 rearrange compute-offsets cases
Now they're in the order you expect to see them at runtime: first you
see a segment header, then you see labels.
2019-07-12 11:23:23 -07:00
Kartik Agaram
0be794d440 .
move trace dump to before checks
2019-07-12 11:17:00 -07:00
Kartik Agaram
022075e59e . 2019-07-11 23:45:03 -07:00
Kartik Agaram
a0c877f8cc one failure remaining in test-compute-offsets
'curr-segment-name' is now a string, and it's stored in a register
rather than a global.

Paradoxically, this leaks *less* than before. Before, every call to
`get-or-insert-slice` leaked memory. Now we leak one string for every
new segment. Which is trivial.
2019-07-11 23:41:37 -07:00
Kartik Agaram
7fed7232c4 . 2019-07-11 22:27:01 -07:00
Kartik Agaram
2c45de094b .
Pseudocode is a little more truthful now about what variables are on the
stack.
2019-07-11 21:52:56 -07:00
Kartik Agaram
98994d5bcc the problem: curr-segment-name is stale
It's a slice into the 'line' stream. But we want to preserve the current
segment name across lines.

Let's leak some memory.
2019-07-11 21:47:00 -07:00
Kartik Agaram
bbfa2acaca .
Make the trace a little more consistent.
2019-07-11 21:42:54 -07:00
Kartik Agaram
554bd09968 label offset computation still has a bug
I changed the test a little to make it obvious.
Basically there's no way we can compute the segment offset correctly
without knowing the segment name in the previous assertion.
2019-07-11 21:38:25 -07:00
Kartik Agaram
be995e2193 revert compute-offsets to segment-relative offsets
The pseudocode was a mess here :/ I was saving the segment-offset but
tracing the file-offset.

Segments need file offsets (to tweak their starting address).
Labels need segment offsets (to add to segment starting address).
2019-07-11 21:31:00 -07:00
Kartik Agaram
f57a458e7b . 2019-07-11 21:24:09 -07:00
nc
3a3e7a90d7 move discard instruction to correct spot 2019-07-11 22:31:56 -04:00
nc
2805308785 updated test so 'x' is relative to file-offset not segment offset 2019-07-11 22:21:32 -04:00
nc
c2725b65b3 made test 2 pass 2019-07-11 22:13:03 -04:00
Kartik Agaram
538f24c296 . 2019-07-10 11:57:08 -07:00
Kartik Agaram
c5f7d9dd57 .
I think we're calling the wrong variant here.
2019-07-10 11:38:24 -07:00
Kartik Agaram
304bce5895 start distinguishing table lookups from inserts 2019-07-10 11:32:46 -07:00
Kartik Agaram
84aa2fad2d .
Fix infinite loop in the 2 remaining failing tests; now it's a segfault.
2019-07-10 09:39:38 -07:00
Kartik Agaram
7e9cdf3c7a . 2019-07-10 09:35:24 -07:00
Kartik Agaram
48aabc860a mostly done with emit-output
Some nooks and crannies will need light final debugging with xxd, but
emit-hex-output covers most of the logic.
2019-07-09 23:41:32 -07:00
Kartik Agaram
20a527702b done with emit-segments
Only failures now are the first two tests in survey.subx.
2019-07-09 22:11:44 -07:00
Kartik Agaram
7bc9240c3c . 2019-07-09 17:50:22 -07:00
Kartik Agaram
4a739023d9 . 2019-07-09 17:41:52 -07:00
Kartik Agaram
c7564b7688 . 2019-07-09 16:55:57 -07:00
Kartik Agaram
b14457a4cb . 2019-07-09 16:55:57 -07:00
Kartik Agaram
5821a0f612 clean up after a few calls 2019-07-09 16:55:55 -07:00
Kartik Agaram
f6ea25613f preserve truthiness of non-booleans
Everywhere we check if something is true, we check it by comparing
against 0, not 1.
2019-07-09 16:55:37 -07:00
Kartik Agaram
7a752f8d3d this looks like a bug
But of course the test is still infinite-looping so we can't be sure.
I'm still just reading the code.
2019-07-09 16:55:13 -07:00
Kartik Agaram
ca32bfbed8 . 2019-07-09 16:54:48 -07:00
Kartik Agaram
d6c6aebef4 . 2019-07-09 16:37:01 -07:00