Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to support labels as imm32 arguments to opcodes #19

Merged
merged 1 commit into from
Apr 19, 2019

Conversation

charles-l
Copy link
Collaborator

Add support to move label address into register. Useful for higher-order functions and such.

@akkartik
Copy link
Owner

Thanks! Looks good.

BTW, I emailed you to show you the LoC your previous PR saved: 0b91d25. However, the email bounced. So thank you :)

@akkartik akkartik merged commit c1bde77 into master Apr 19, 2019
@charles-l
Copy link
Collaborator Author

Oh cool! Glad that helped simplify some stuff :)

Yeah my email server isn’t quite configured properly on my site yet. Thanks for the reminder - I’ve let that sit broken for too long :P

@charles-l charles-l deleted the label-imm32-arg branch April 19, 2019 11:47
@akkartik
Copy link
Owner

@charles-l I'm curious if you're working on something in particular that requires label addresses. If so I'd love to hear more details about your project.

Also let me know if you're looking for opportunities to program on SubX. I've been working on the bootstrap SubX translator in SubX, and would love to get any help.

@charles-l
Copy link
Collaborator Author

charles-l commented Apr 24, 2019

@akkartik yeah, I'm (very slowly) working on implementing a forth in assembly based on jonesForth. The pre-subx, half-finished implementation is here: https://git.sr.ht/~nch/onward/tree/master/onward.s

I'm working on porting it to subx before finishing it off. One of the advantages of subx (that I didn't really have with a normal x86 assembler) is being able to control every byte that goes into the binary. I wanted to sort of demoscene the implementation and build a really tiny forth binary at the end of it. The constraints of subx actually make that more straightforward :)

I'd love to help bootstrap subx! Getting foundational code right (like having properly auditable seed binaries) is something I'm very interested in.

@akkartik
Copy link
Owner

akkartik commented Apr 24, 2019

@charles-l: Excellent. I'm not sure what you may be interested in, so I'll just throw out a brain dump of the current state, see if anything catches your fancy.

I'm basically building a SubX translator using 3 syscalls: read, write and exit. It's going to read from stdin and write the final binary to stdout. The plan is to divide up the work into the following phases:

$ cat file1.subx file2.subx ... |dquotes |assort |pack |survey |hex > a.out

Each phase is an ELF binary constructed out of a corresponding .subx file.

  • hex.subx converts a sequence of bytes in hex into a binary. (done)
  • survey.subx will turn labels into addresses, and also slap on ELF headers. It's called 'survey' because the act of imposing a coordinate system on a program feels somewhat like surveying terrain and determining various distances and heights. (not started)
  • pack.subx converts bitfields in instructions into whole bytes in the right order. For example, 0/mod 1/rm32 1/r32 is turned into the single byte 08. (done)
  • assort.subx just reads in many segments starting with == and containing lines of code or data, and concatenates all segments with the same name. (done)
  • dquotes.subx moves string literals in the code segment to the data segment. (in progress)

(Since the translator isn't fully assembled yet, the ground truth for building each phase is currently in test_apps.)

(There's zero plans for error-checking at the moment. That's still left to the C++ implementation.)

(Hmm, as I write this out I realize I probably need another phase, to generate run-tests which calls all the test-* functions.)

Basically, I think ergonomic programming has certain prerequisites that are more fundamental than high-level syntax:

  1. Comments.
  2. Freedom to organize code and data as people wish, rather than to suit the computer. (assort)
  3. A test harness that doesn't require registering every. single. test.
  4. Literals. Particularly string literals.

Anyway, I'm starting to ramble :) As you can see, I've been working on dquotes.subx, support for string literals. Most recently that involved building a function to convert integers to string. You can sort of see a sketch of what's left to do in dquotes.subx. Alternatively we could start on survey.subx, which honestly scares me the most.

Maybe a first step would be just to get the current state building and running its tests. I'm hoping everything 'just works' for you. Try running test_apps and let me know?

@charles-l
Copy link
Collaborator Author

Maybe a first step would be just to get the current state building and running its tests. I'm hoping everything 'just works' for you. Try running test_apps and let me know?

Looks good -- everything seemed to work! :)

dquotes.subx seems like it'll have some approachable, defined tasks (which might be easier to coordinate for now), but survey.subx definitely interests me a lot.

What features still need to be implemented for dquotes? It looks like string literals are lifted into the data section, and you mentioned numerical literals are in place. Do you have a list of functionality (or test case that fails) that needs to be implemented next?

@akkartik
Copy link
Owner

I just remembered that test_apps stops at the first failure and unfortunately sometimes failures are silent. Now fixed. Could you do a git pull and rerun test_apps?

"test case that fails" is a good idea. I'm going to stop writing code for a bit and focus exclusively on writing test cases. I'll make each failing test a branch/PR that you can add code to.

I'm kinda sick for the last couple of days, though. While I think about the right sequence of tests, do you want to try reimplementing something I recently built for dquotes, both as an exercise and to see if maybe my approach wasn't the best? It's a function to print an integer to a byte stream: #20. That PR has some instructions and hints.

It's kind of an involved example, so here are a couple of simpler exercises that will hopefully help build out prerequisites:

Totally optional and for your own benefit; if you want to just work on #20 that's totally fine.

@charles-l
Copy link
Collaborator Author

charles-l commented Apr 26, 2019

Cool -- thanks for the clear writeup. I'll get cracking :)

BTW -- test_apps still works (it didn't fail silently before), so no worries there.

akkartik added a commit that referenced this pull request Apr 26, 2019
I'm switching to a more exposed working dynamic after chatting with Charles
Saternos (#19). From now on I'll start
a new branch for big features. Branches won't always pass all their tests.

Phases have gone weeks in the past before being committed all at once.
Developing in a branch gives others the opportunity to see more current
progress and jump in more easily.

Some 'kata' branches for new contributors to start at:
  * add two numbers: #21
  * write a string to a byte stram: #22
  * print a number in decimal to a byte stream: #20
akkartik added a commit that referenced this pull request Apr 27, 2019
I'm switching to a more exposed working dynamic after chatting with Charles
Saternos (#19). From now on I'll start
a new branch for big features. Branches won't always pass all their tests.

Phases have gone weeks in the past before being committed all at once.
Developing in a branch gives others the opportunity to see more current
progress and jump in more easily.

Some 'kata' branches for new contributors to start at:
  * add two numbers: #21
  * write a string to a byte stram: #22
  * print a number in decimal to a byte stream: #20
akkartik added a commit that referenced this pull request Apr 27, 2019
I'm switching to a more exposed working dynamic after chatting with Charles
Saternos (#19). From now on I'll start
a new branch for big features. Branches won't always pass all their tests.

Phases have gone weeks in the past before being committed all at once.
Developing in a branch gives others the opportunity to see more current
progress and jump in more easily.

Some 'kata' branches for new contributors to start at:
  * add two numbers: #21
  * write a string to a byte stram: #22
  * print a number in decimal to a byte stream: #20
akkartik added a commit that referenced this pull request Apr 27, 2019
I'm switching to a more exposed working dynamic after chatting with Charles
Saternos (#19). From now on I'll start
a new branch for big features. Branches won't always pass all their tests.

Phases have gone weeks in the past before being committed all at once.
Developing in a branch gives others the opportunity to see more current
progress and jump in more easily.

Some 'kata' branches for new contributors to start at:
  * add two numbers: #21
  * write a string to a byte stram: #22
  * print a number in decimal to a byte stream: #20
akkartik added a commit that referenced this pull request Apr 29, 2019
I'm switching to a more exposed working dynamic after chatting with Charles
Saternos (#19). From now on I'll start
a new branch for big features. Branches won't always pass all their tests.

Phases have gone weeks in the past before being committed all at once.
Developing in a branch gives others the opportunity to see more current
progress and jump in more easily.

Some 'kata' branches for new contributors to start at:
  * add two numbers: #21
  * write a string to a byte stram: #22
  * print a number in decimal to a byte stream: #20
@akkartik
Copy link
Owner

I've written some tests for the remaining work in dquotes.subx. The main branch is #23, and there are two sub-goals: #26 and #27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants