Skip to content
This repository was archived by the owner on Nov 11, 2021. It is now read-only.

Conversation

@scgilardi
Copy link
Contributor

  • print1 - an example with native code to print an integer via write to stdout

    • equivalent to the built-in print, but written in porth
    • with the advantage of printing negative integers with a leading minus when compiled just like when simulated
  • includes an additional stack word rot because without it, using the 3rd item on the stack is inconvenient

  • implemented as an example because perhaps we don't want to expand print inline on every use.

    • maybe porth will support a callable procedure abstraction at some point
  • includes signmag that converts an integer to sign-magnitude form

    • possibly useful for std.porth at some point

- improves on the built-in print by handling negative integers in compiled
  code "properly" -- with a leading minus sign the same as in the simulator.
- currently expands inline due to macros being the only code abstraction
  we have
- perhaps useful as a basis of a native print written in porth at some point
  - the built-in print is derived from compiling a similar conversion in C
- uses a temporary area within mem (32 bytes) to accumulate the characters
  of the output string from back to front.
  - a scratch buffer like this might make sense as a peer to mem, str, argv
  - alternatively, being able to allocate this temp buffer on the stack seems
    like it would be useful in avoiding contention for a global buffer
- uses `rot` which is a basic stack word from ANS forth
  - without it, it was not convenient to use the third item on the stack
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant