4th(1)
π 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 inPADποΈ line 15 becomes free because everything moves up 1 linen Eβ erase line n with blanks π«§n Iβ insert the text fromPADat line n, pushing the old line n and everything after it down π₯ line 15 gets lost in the shuffle πn Hβ hold line n atPAD(the system uses this more than you will, bestie) πn Rβ replace line n with the text inPADπ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 toPADπn P textβ puttextat 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 memoryn 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.FLUSHis 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 byCLEAR,FLUSHorLIST) βͺ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 afterFto back the cursor up by the length of the most recent text β©οΈC textβ copytextinto the cursor line at the cursor position πF textβ search forward from the cursor until the stringtextis 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 anFcommand βοΈTILL textβ delete on the cursor line, from the cursor until the end of the stringtextβοΈX textβ find and delete the next occurrence of the stringtextπ₯EXPORT fileβ saves the current contents of all screens to the text-filefileπ€ no flushing is doneWRITEβ saves the current contents of all screens to the block-file π no flushing is doneWQβ 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
- fedora 43: 4th 3.62.5-21.fc43 Β· GPL-3.0-or-later
- fedora 43: 4th 3.62.5-21.fc43 Β· GPL-3.0-or-later
- fedora 44: 4th 3.62.5-23.fc44 Β· GPL-3.0-or-later
- fedora 44: 4th 3.62.5-23.fc44 Β· GPL-3.0-or-later
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms