4th(1)

πŸ“¦
version 3.62.5 Β· 2 versions
, in fedora 43, fedora 44

πŸ’– 4th(1) Β· General Commands Manual πŸ’–

okay bestie, the 4th(1) manual is here and it is SO good 🧚 it's a menu-driven bytecode compiler, VM, decompiler, line editor, RPN calculator, and C-source generator all in one tiny program πŸ’…


✨ NAME ✨

4th, a portable Forth compiler that supports a (modified) subset of ANS-Forth 🌸

✨ SYNTAX ✨

4th [options] [file] [file | argument .. argument]

4thx [file] [argument .. argument]

✨ DESCRIPTION ✨

okay so 4th is giving everything πŸ”₯ it's a menu-driven bytecode compiler, virtual machine, decompiler, line editor, RPN calculator, and C-source generator rolled into one small program πŸ‘‘

you can use it to make portable bytecode programs, standalone executables, or a scripting language, or to translate Forth into C πŸ¦‹ for the full details, go read the manual, it's literally right there πŸ’œ

✨ OPTIONS ✨

  • m β€” enter interactive mode πŸŽ€
  • e β€” edit a 4tH screenfile 🌈
  • c β€” load a sourcefile (.4th) and compile it πŸ’–
  • l β€” load an objectfile (.hx) 🫢
  • d β€” decompile a 4tH program πŸ”
  • g β€” generate a C sourcefile (default: out.c) πŸ“
  • s β€” save a 4tH program (default: out.hx) ✨
  • x β€” execute a 4tH program πŸ”₯
  • v β€” enter verbose mode πŸ“’
  • q β€” suppress the copyright message 🀫

✨ EDITOR ✨

the editor is a whole vibe πŸ’… here's every command, no cap:

  • n D β€” delete line n but hold it in PAD πŸ—‘οΈ line 15 becomes free because everything moves up 1 line
  • n E β€” erase line n with blanks 🫧
  • n I β€” insert the text from PAD at line n, pushing the old line n and everything after it down πŸ“₯ line 15 gets lost in the shuffle 😭
  • n H β€” hold line n at PAD (the system uses this more than you will, bestie) πŸ™ˆ
  • n R β€” replace line n with the text in PAD πŸ”
  • n S β€” spread at line n 🌸 line n and the ones after it move down 1 line, line n becomes blank, and line 15 is lost πŸ’€
  • n T β€” display line n and copy it to PAD πŸ‘€
  • n P text β€” put text at line n, overwriting whatever was there before πŸ–ŠοΈ
  • n LIST β€” list screen n and select it for editing πŸ“œ if screen n isn't the current screen, it'll ask to load it from memory
  • n CLEAR β€” clear screen n with blanks and select it for editing 🧹
  • n INSERT β€” insert screen n 🧚 the current screen n and every screen after it move down, the last screen is lost, screen n gets cleared with blanks and selected for editing. FLUSH is used at the end of an editing session to save the current screen to memory πŸ’Ύ
  • UNDO β€” reloads the current screen, undoing all changes since the last flush (triggered by CLEAR, FLUSH or LIST) βͺ
  • FLUSH β€” write the updated screen to memory πŸ’Ύ
  • L β€” list the current screen πŸ“– the cursor line gets relisted after the screen listing so you can see where you are πŸ“
  • n M β€” move the cursor by n characters and the cursor line πŸƒβ€β™€οΈ the cursor's position on its line is shown by a ^ (caret) πŸ”Ί
  • n W β€” wipe n characters to the left of the cursor 🧽
  • TOP β€” position the cursor at the start of the screen ⬆️
  • B β€” used after F to back the cursor up by the length of the most recent text ↩️
  • C text β€” copy text into the cursor line at the cursor position πŸ“
  • F text β€” search forward from the cursor until the string text is found πŸ”Ž the cursor is left at the end of the string and the cursor line gets printed. if the string isn't found, you get an error message and the cursor jumps back to the top of the screen 😬
  • N β€” find the next occurrence of the string found by an F command ⏭️
  • TILL text β€” delete on the cursor line, from the cursor until the end of the string text βœ‚οΈ
  • X text β€” find and delete the next occurrence of the string text πŸ’₯
  • EXPORT file β€” saves the current contents of all screens to the text-file file πŸ“€ no flushing is done
  • WRITE β€” saves the current contents of all screens to the block-file πŸ“ no flushing is done
  • WQ β€” flushes the current screen, then saves the current contents of all screens to the block-file πŸŽ€
  • Q β€” quits the editor without saving πŸšͺ bye!! πŸ‘‹

✨ FILES ✨

the files you'll be dealing with, iykyk πŸ¦‹

  • *.4th; β€” text files containing 4tH source (script) πŸ“
  • *.scr; β€” block files containing 4tH source (script) 🧩
  • *.hx; β€” Hcode eXecutables (bytecode) ⚑
  • *.c; β€” C source files 🌈

✨ ENVIRONMENT VARIABLES ✨

  • DIR4TH β€” if it's non-null, it holds the full pathname (including the trailing slash) for the 4tH root directory πŸ—ΊοΈ only the compiler uses it 🫢

✨ EXAMPLES ✨

okay the examples are my favorite part, literally copy-paste energy πŸ’–

To compile a 4tH program and save the object code:

4th csv source.4th [object.hx]

To compile a 4tH program and execute it:

4th cx source.4th

To decompile object code:

4th ld object.hx

To convert object code to C source:

4th lg object.hx [source.c]

To load and execute object code:

4th lx object.hx [arguments]

To load and execute object code without arguments:

4th object.hx

To edit a 4tH screenfile:

4th e source.scr

To enter interactive mode:

4th m source.scr

To enter interactive mode (without a screenfile):

4th

✨ AUTHORS ✨

4tH was written by Hans Bezemer <the.beez.speaks@gmail.com> πŸ‘‘ queen behavior 🫢

✨ SEE ALSO ✨

  • gforth(1) β€” the sibling you should check out next 🌸

bye bestie, that's the whole thing πŸ¦‹ written by Hans Bezemer, version 3.61.2, page 4th(1) πŸ’–βœ¨

πŸ“¦ where this page comes from