Skip to content

Commit

Permalink
Export toplevel [IF] [ELSE] [THEN]
Browse files Browse the repository at this point in the history
  • Loading branch information
tkers committed May 9, 2024
1 parent b6dcc8e commit 4a4c9b5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/user.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ require ./compiler/cross.fs
: [host] forth ; immediate
: [target] gbforth-user ; immediate

: [if] if else [char] ] parse drop drop then ; immediate

\
\ Expose words into the GBFORTH-USER vocabulary. Available within
\ [TARGET] in interpreting mode.
Expand All @@ -44,16 +42,17 @@ also gbforth
' [host] alias [host] immediate
' [target] alias [target] immediate

' [if] alias [if] immediate
' [then] alias [then] immediate

export ( immediate \ )
export \ immediate
export ==>
export include
export require
export [asm]
export [endasm]
export [if]
export [else]
export [then]
export [endif]

This comment has been minimized.

Copy link
@lf94

lf94 Jul 9, 2024

Contributor

So these were already implemented right? Nice!

This comment has been minimized.

Copy link
@tkers

tkers Jul 10, 2024

Author Member

These are just the words as defined by gforth :) export simply makes them available to the user without having to switch dictionaries (same for words like require and ( exported above).

This comment has been minimized.

Copy link
@lf94

lf94 Jul 10, 2024

Contributor

Aaaah! That's even nicer :D Nice to know if I need more gforth power at the top level :D

This comment has been minimized.

Copy link
@tkers

tkers Jul 10, 2024

Author Member

Also FYI there are the [HOST] and [TARGET] words that switch between dictionaries, so you have access to every gforth definition if needed. We exported some commonly used words by default to make code more readable / less annoying to write, but rather keep that set small to avoid confusion.


export main:

Expand Down
28 changes: 28 additions & 0 deletions test/compiler/test-bracket-if.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
true [if]
: foo 1 ; \ foo
[then]

false [if]
: foo 2 ;
[endif]

true [if]
: bar 3 ; \ bar
[else]
: bar 4 ;
[then]

false [if]
: baz 5 ;
[else]
: baz 6 ; \ baz
[endif]

true [if]
false [if]
: main baz bar foo ;
[else]
true [if] : main foo bar baz ; [then] \ main
false [if] : main bar foo baz ; [then]
[endif]
[endif]
6 changes: 6 additions & 0 deletions test/compiler/test-bracket-if.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const gb = require('../gbtest')(__filename)

test('bracket-if', () => {
gb.run()
expect(gb.stack).toEqual([1, 3, 6])
})

0 comments on commit 4a4c9b5

Please sign in to comment.