From 702235f9529f43d8a265faf0717fb82f61e15f10 Mon Sep 17 00:00:00 2001 From: Bahman Movaqar Date: Wed, 25 Dec 2024 20:18:16 -0800 Subject: [PATCH 1/5] Add `.` word to print a number --- bjforth/src/main/forth/bjForth.forth | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bjforth/src/main/forth/bjForth.forth b/bjforth/src/main/forth/bjForth.forth index 0024e37a..e088c926 100644 --- a/bjforth/src/main/forth/bjForth.forth +++ b/bjforth/src/main/forth/bjForth.forth @@ -206,7 +206,7 @@ ################################################################################################### -: NUMBER->STR # ( x width -- ) +: NUM->STR # ( x width -- ) DUP 0<> IF SWAP @@ -227,3 +227,8 @@ ################################################################################################### +: . ( x -- ) + 0 + NUM->STR + SPACE +; From 1921f73da63030716d3096f6e206aa7f047ba513 Mon Sep 17 00:00:00 2001 From: Bahman Movaqar Date: Wed, 25 Dec 2024 20:18:37 -0800 Subject: [PATCH 2/5] Include the bjForth library in E2E tests --- Makefile | 3 ++- bjforth/src/test/e2e/e2e-test-runner.pl | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a2c7790d..584e0ef0 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,8 @@ e2e-test : package @bjforth/src/test/e2e/e2e-test-runner.pl \ bjforth/build/libs/bjForth-$(VERSION).jar \ bjforth/src/test/e2e/e2e-expected-output.txt \ - bjforth/src/test/e2e/e2e-tests.forth + bjforth/src/test/e2e/e2e-tests.forth \ + bjforth/src/main/forth/bjForth.forth #################################################################################################### diff --git a/bjforth/src/test/e2e/e2e-test-runner.pl b/bjforth/src/test/e2e/e2e-test-runner.pl index 4db86a03..7dc8487e 100755 --- a/bjforth/src/test/e2e/e2e-test-runner.pl +++ b/bjforth/src/test/e2e/e2e-test-runner.pl @@ -12,6 +12,7 @@ my $jarFile = shift or die("Path to JAR file not provided."); my $expectedOutputFile = shift or die("Path to expected output file not provided."); my $testCodeFile = shift or die("Path to test code not provided."); +my $libraryFile = shift or die("Path to bjForth.forth not provided."); open(my $fh, '<', $expectedOutputFile) or die("open(): $!"); my $expectedOutput = do { local($/); <$fh> }; @@ -19,10 +20,10 @@ ### End of stream should mean a graceful exit -my $actualOutput = qx/java -jar ${jarFile} 2>&1 < ${testCodeFile}/; +my $actualOutput = qx/cat ${libraryFile} ${testCodeFile} | java -jar ${jarFile} 2>&1/; if ($actualOutput eq $expectedOutput) { exit 0; } else { die("E2E tests failed.\nActual output is\n\n${actualOutput}"); -} \ No newline at end of file +} From 41c44b1f8df00e86c8e246f2c9d2ec8e82d6b685 Mon Sep 17 00:00:00 2001 From: Bahman Movaqar Date: Wed, 25 Dec 2024 20:18:51 -0800 Subject: [PATCH 3/5] Add tests to cover printing numbers --- bjforth/src/test/e2e/e2e-expected-output.txt | 2 +- bjforth/src/test/e2e/e2e-tests.forth | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bjforth/src/test/e2e/e2e-expected-output.txt b/bjforth/src/test/e2e/e2e-expected-output.txt index 1a9dd10c..cac7d8c8 100644 --- a/bjforth/src/test/e2e/e2e-expected-output.txt +++ b/bjforth/src/test/e2e/e2e-expected-output.txt @@ -9,4 +9,4 @@ Hello, world Hello, world 24 Hello, world -BYE +00000019 220 BYE diff --git a/bjforth/src/test/e2e/e2e-tests.forth b/bjforth/src/test/e2e/e2e-tests.forth index b263ee9c..35452a9b 100644 --- a/bjforth/src/test/e2e/e2e-tests.forth +++ b/bjforth/src/test/e2e/e2e-tests.forth @@ -62,3 +62,10 @@ PRINT-ME ; ." Hello, world ". NEW-STRING + +################################################################################################### +# Printing numbers +################################################################################################### + +25 8 HEX NUM->STR +220 . From 6ecd93afe82ee4df1b3874c4b4e39333605a0e94 Mon Sep 17 00:00:00 2001 From: Bahman Movaqar Date: Wed, 25 Dec 2024 20:20:44 -0800 Subject: [PATCH 4/5] Remove the extra whitespac --- bjforth/src/main/forth/bjForth.forth | 1 - 1 file changed, 1 deletion(-) diff --git a/bjforth/src/main/forth/bjForth.forth b/bjforth/src/main/forth/bjForth.forth index e088c926..1035ec93 100644 --- a/bjforth/src/main/forth/bjForth.forth +++ b/bjforth/src/main/forth/bjForth.forth @@ -230,5 +230,4 @@ : . ( x -- ) 0 NUM->STR - SPACE ; From 5425cf73907987c91d38f35e9b53ba7b038e608a Mon Sep 17 00:00:00 2001 From: Bahman Movaqar Date: Wed, 25 Dec 2024 20:21:11 -0800 Subject: [PATCH 5/5] Remove the extra whitespace --- bjforth/src/test/e2e/e2e-expected-output.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bjforth/src/test/e2e/e2e-expected-output.txt b/bjforth/src/test/e2e/e2e-expected-output.txt index cac7d8c8..18155acd 100644 --- a/bjforth/src/test/e2e/e2e-expected-output.txt +++ b/bjforth/src/test/e2e/e2e-expected-output.txt @@ -9,4 +9,4 @@ Hello, world Hello, world 24 Hello, world -00000019 220 BYE +00000019 220 BYE