Skip to content

Commit

Permalink
Finish implementing embedded sys.f
Browse files Browse the repository at this point in the history
OK, this works... barely!

We have to omit the final newline in sys.f for it to work. We should probably
take another look at that.

But, it does technically work: We can now run just ./main, and the sys.f file
will be run automatically from inside the program. Very cool!
  • Loading branch information
Jonas committed Mar 8, 2020
1 parent c037ff9 commit bdf0f48
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion bootstrap.asm
Expand Up @@ -111,11 +111,13 @@ forth INTERPRET_STRING, 'INTERPRET-STRING'
;; Check if the buffer is-non-empty
;; [TODO] This probably won't work for strings with whitespace at the end.
dq INPUT_LENGTH, GET
dq ZBRANCH, 8 * 7 ; to EXIT
dq ZBRANCH, 8 * 5 ; to EXIT

dq READ_WORD

dq INTERPRET_WORD
dq BRANCH, -8 * 7 ; to INPUT-LENGTH @

dq LIT, 0, INPUT_BUFFER, PUT

dq EXIT
3 changes: 3 additions & 0 deletions impl.asm
Expand Up @@ -177,6 +177,9 @@ pop_word:
jmp .read_alpha

.end:
;; Finally, we want to skip one whitespace character after the word.
inc rsi
dec rcx

ret

Expand Down
4 changes: 0 additions & 4 deletions main.asm
Expand Up @@ -452,10 +452,6 @@ read_string_buffer:
;; We borrow READ_STRING's buffer. They won't mind.
mov [READ_STRING.length], 0

;; Skip space ([TODO]: Shouldn't we do this while parsing instead?)
inc [input_buffer]
dec [input_buffer_length]

.read_char:
mov rbx, [input_buffer]
mov al, [rbx]
Expand Down
2 changes: 2 additions & 0 deletions sys.f
Expand Up @@ -83,5 +83,7 @@
( Read a number from standard input. )
: READ-NUMBER READ-WORD PARSE-NUMBER ;

S" Ready." TELL NEWLINE

( vim: syntax=forth
)

0 comments on commit bdf0f48

Please sign in to comment.