From 4a4c9b5d7b5bfe407edb81096ab2e10fdd68b77b Mon Sep 17 00:00:00 2001 From: Tijn Kersjes Date: Fri, 10 May 2024 00:30:11 +0200 Subject: [PATCH] Export toplevel [IF] [ELSE] [THEN] --- src/user.fs | 9 ++++----- test/compiler/test-bracket-if.fs | 28 ++++++++++++++++++++++++++++ test/compiler/test-bracket-if.js | 6 ++++++ 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 test/compiler/test-bracket-if.fs create mode 100644 test/compiler/test-bracket-if.js diff --git a/src/user.fs b/src/user.fs index e6266c4..13c6901 100644 --- a/src/user.fs +++ b/src/user.fs @@ -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. @@ -44,9 +42,6 @@ also gbforth ' [host] alias [host] immediate ' [target] alias [target] immediate -' [if] alias [if] immediate -' [then] alias [then] immediate - export ( immediate \ ) export \ immediate export ==> @@ -54,6 +49,10 @@ export include export require export [asm] export [endasm] +export [if] +export [else] +export [then] +export [endif] export main: diff --git a/test/compiler/test-bracket-if.fs b/test/compiler/test-bracket-if.fs new file mode 100644 index 0000000..77da756 --- /dev/null +++ b/test/compiler/test-bracket-if.fs @@ -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] \ No newline at end of file diff --git a/test/compiler/test-bracket-if.js b/test/compiler/test-bracket-if.js new file mode 100644 index 0000000..eaca38c --- /dev/null +++ b/test/compiler/test-bracket-if.js @@ -0,0 +1,6 @@ +const gb = require('../gbtest')(__filename) + +test('bracket-if', () => { + gb.run() + expect(gb.stack).toEqual([1, 3, 6]) +})