Commit Graph

922 Commits

Author SHA1 Message Date
Virgil Dupras
6487c713ef forth: fix prompt in QUIT conditions 2020-03-21 15:22:37 -04:00
Virgil Dupras
9791c0957d forth: make readline skip prompt when appropriate 2020-03-21 14:59:12 -04:00
Virgil Dupras
b47a3ee234 forth: add words "AND", "OR", "XOR" 2020-03-21 14:47:38 -04:00
Virgil Dupras
c1ece95089 forth: implement readline in Forth
The commit ended up being much bigger than anticipated. This was a long thread
of underlying complexities. This lead to the creation of interesting concepts
such as (sysv).
2020-03-21 12:57:49 -04:00
Virgil Dupras
2feb246334 forth: give WORD its own buffer
You'll soon see where I'm going with this...
2020-03-19 21:56:53 -04:00
Virgil Dupras
61abafbc1a forth: a little housekeeping 2020-03-19 21:45:27 -04:00
Virgil Dupras
abb84b01db forth: Word-ify "readword" 2020-03-19 21:40:35 -04:00
Virgil Dupras
5458a1f7ff forth: a little housekeeping 2020-03-19 17:39:44 -04:00
Virgil Dupras
cf95bbcace forth: inline kernel/stdio 2020-03-19 17:26:45 -04:00
Virgil Dupras
6134694513 forth: put all ASM code in the same file 2020-03-19 17:01:15 -04:00
Virgil Dupras
f420db135d forth: a little house cleaning 2020-03-19 16:36:54 -04:00
Virgil Dupras
af5a97243a forth: implement "0b" number parsing 2020-03-19 16:03:35 -04:00
Virgil Dupras
f0cbda1f2e tests: add Forth tests
Modest first step
2020-03-19 15:43:48 -04:00
Virgil Dupras
b335e538b4 Move "forth" folder to project's root folder
It's not really an App.
2020-03-18 22:25:44 -04:00
Virgil Dupras
ae6334906c forth: inline kernel's core and str units 2020-03-18 22:18:07 -04:00
Virgil Dupras
548facac0b forth: Implement "(parseh)" 2020-03-18 21:52:55 -04:00
Virgil Dupras
d874f20278 forth: Add "DO" and "LOOP"
Also, un-IMMEDIATE "LITN" it didn't make any sense.
2020-03-18 20:04:44 -04:00
Virgil Dupras
587d1d0d69 forth: add word "UNTIL" 2020-03-18 16:39:22 -04:00
Virgil Dupras
1df9c4fc1b forth: split forth source into multiple files 2020-03-17 21:44:32 -04:00
Virgil Dupras
9451c599e0 forth: Make (parse) indirect and Forth-ify (parsec) 2020-03-17 21:19:56 -04:00
Virgil Dupras
4212d5161f forth: Word-ify number parsing 2020-03-17 17:46:58 -04:00
Virgil Dupras
707f1dbae1 forth: Word-ify "[COMPILE]" 2020-03-17 17:29:03 -04:00
Virgil Dupras
b72901175e forth: Word-ify "[']" and "'" 2020-03-17 16:17:51 -04:00
Virgil Dupras
d91af99fde forth: make "'" push 0 when not finding a word 2020-03-17 15:54:17 -04:00
Virgil Dupras
3a70dff53d forth: add word 'ABORT"' 2020-03-17 15:31:15 -04:00
Virgil Dupras
25b6e75cf7 forth: add words "."" and "(print)" 2020-03-17 15:22:13 -04:00
Virgil Dupras
a40926d710 forth: check PS everywhere
It turns out we have to...
2020-03-17 14:56:08 -04:00
Virgil Dupras
6314c60ede forth: add word ".X" 2020-03-17 14:05:53 -04:00
Virgil Dupras
549cf74e9d forth: inline code from "apps/lib"
Forth-ification of Collapse OS goes forward. What will happen is that assembly
code in apps/ will become Forth code. The concept of an assembler code library
will become obsolete.

However, Forth's core use some of that code. To facilitate the transition, I'm
inlining that code directly in Forth's code.
2020-03-17 12:49:06 -04:00
Virgil Dupras
017a469d9c forth: Forth-ify "." 2020-03-17 12:26:28 -04:00
Virgil Dupras
839d7097e7 forth: add words "MOD" and "/MOD" 2020-03-16 22:36:29 -04:00
Virgil Dupras
5d5517ac44 forth: allow DEFINE's ";" to be at the start of a newline
Previous to this commit, DEFINE's algo would miss a ";" right after a newline.

This allows for a much nicer formatting+comment of core.fs.
2020-03-16 22:09:23 -04:00
Virgil Dupras
aec98a7a3a forth: separate COMPILE and [COMPILE] 2020-03-16 21:31:43 -04:00
Virgil Dupras
f404c2f4d0 forth: TIL forth source file extension is "fs" 2020-03-16 19:51:10 -04:00
Virgil Dupras
80ab395823 forth: Simplify execution model
Change the mainloop so that words are executed immediately after they're read.
This greatly simplifies execution model and allow the "DEFINE" word to become
an IMMEDIATE and stop its "copy from compiled words" scheme.

The downside to this is that flow control words no longer work when being used
directly in the input buffer. They only work as part of a definition.

It also broke "RECURSE", but I've replaced it with "BEGIN" and "AGAIN".

Another effect of this change is that definitions can now span multiple lines.

All in all, it feels good to get rid of that COMPBUF...
2020-03-15 22:46:17 -04:00
Virgil Dupras
7befe56597 forth: improve input flow
Readline, instead of being triggered by the end of execution of the last
compiled line is now triggered "just in time", by "WORD".

This allows IMMEDIATE words reading input buffer to span multiple lines
( comments for example, but colon definitions will soon follow ).
2020-03-14 19:10:39 -04:00
Virgil Dupras
e1f815baeb forth: Forth-ify main loop a bit
Add words "COMPILE" and "DROP". The goal is to soon make "DEFINE" immediate
and have it compile from input directly. This whole "main loop compiles
everything and DEFINE picks up compiled atoms" is a bit messy.
2020-03-14 17:48:24 -04:00
Virgil Dupras
764b2222c7 forth: replace (fbr?) by SKIP?
This will allow us to support backward branching with just one new (bbr) word.
Also, this allow us to have "(" word sooned in core.fth and thus allow for
earlier commenting.
2020-03-14 09:23:58 -04:00
Virgil Dupras
94166186eb forth: fix DOES> bad exec offset 2020-03-13 21:27:19 -04:00
Virgil Dupras
5b1ca474d4 forth: Add word "("
Also, fix "RECURSE" in IMMEDIATE contexts.
2020-03-13 19:33:16 -04:00
Virgil Dupras
d60ea4cb30 forth: Forth-ify RECURSE
This comes with RS-modifying words. Also, this commit separates ";" from "EXIT",
allowing EXIT to be used in definitions (was needed for RECURSE).
2020-03-13 16:40:55 -04:00
Virgil Dupras
c3838714d5 forth: improve execution model
My approach with RS was slightly wrong: RS' TOP was always containing current
IP. It worked, but it was problematic when came the time to introduce
RS-modifying words: it's impossible to modify RS in a word without immediately
messing your flow.

Therefore, what used to be RS' TOS has to be a variable that isn't changed
midway by RS-modifying words. I guess that's why RS is called *return* stack...
2020-03-13 16:01:09 -04:00
Virgil Dupras
d0d92a4559 forth: Forth-ify IF and ELSE
Now, I really need comments...
2020-03-12 21:49:10 -04:00
Virgil Dupras
d5a7d5faf8 forth: add words "(fbr)", "(fbr?)", "'", "[']" 2020-03-12 21:16:20 -04:00
Virgil Dupras
fb54fd51af forth: implement THEN in Forth
Also, add "," and "C,"
2020-03-12 13:52:27 -04:00
Virgil Dupras
3819dbc083 forth: remove CMPDST
We now always do ","-style writes in (HERE), even in IMMEDIATE mode. Simplifies
things and paves the way for compiling words in Forth.
2020-03-12 13:08:11 -04:00
Virgil Dupras
ff281f69a8 forth: add "UNWORD" flag
Also, reorder word fields so that the flag field is more easily accessible.
2020-03-12 11:39:27 -04:00
Virgil Dupras
a8e573c84a forth: add bin dict compilation stage!
Big one.

This allows us to write higher order words directly in Forth, which is much
more convenient than writing post-immediate (see "NOT" structure in diff if
you want to see what I mean) structures in ASM.

These structures can then be written to ROM (rather than loaded in RAM for
definitions loaded at run-time).

That's quite a bit of tooling that was added, 2 compilations stages, but I
think it's well worth it.
2020-03-12 00:14:44 -04:00
Virgil Dupras
f89e7bd503 forth: add words "C@" and "C!" 2020-03-11 22:11:54 -04:00
Virgil Dupras
80f63cd185 forth: add words "2DUP", "2SWAP", "2OVER" 2020-03-11 21:58:16 -04:00