-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Factor BBHW with Linux run scripts and README
- Loading branch information
1 parent
cdf3c0b
commit 124daf1
Showing
5 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bbhw/bbhw | ||
factor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Factor | ||
|
||
From [Factor's homepage]: | ||
|
||
> The Factor programming language is a concatenative, | ||
> stack-based programming language with high-level features including dynamic types, | ||
> extensible syntax, macros, and garbage collection. | ||
> On a practical side, Factor has a full-featured library, | ||
> supports many different platforms, and has been extensively documented. | ||
> | ||
> The implementation is fully compiled for performance, | ||
> while still supporting interactive development. | ||
> Factor applications are portable between all common platforms. | ||
> Factor can deploy stand-alone applications on all platforms. | ||
> Full source code for the Factor project is available under a BSD license. | ||
--- | ||
|
||
If Factor is already installed and its `factor` in your path, | ||
`run` will use the fast, non-optimizing compiler to run `bbhw.factor`, | ||
and `run-optimized` will use the slow, optimizing compiler to build `bbhw` | ||
from `bbhw.factor` and run that. | ||
|
||
If Factor is not found, | ||
either of those scripts will first download and build Factor itself. | ||
|
||
[Factor's homepage]: https://factorcode.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
USING: calendar combinators.short-circuit.smart command-line | ||
interpolate io kernel math math.parser namespaces ranges | ||
sequences threads ; | ||
IN: bbhw | ||
|
||
: ask-n ( -- str ) | ||
"countdown: " write flush | ||
readln ; | ||
|
||
: initial-n ( -- str ) | ||
command-line get | ||
[ ask-n ] [ first ] if-empty ; | ||
|
||
: valid-n? ( str -- ? ) | ||
string>number | ||
{ [ ] [ integer? ] [ 0 > ] } && ; | ||
|
||
: say-bye-bye ( n -- ) | ||
"World, Hello..." write | ||
1 [a..b] [ | ||
I"${}..." write flush | ||
1 seconds sleep | ||
] each | ||
"Bye Bye." print ; | ||
|
||
: main ( -- ) | ||
initial-n | ||
[ dup valid-n? ] [ | ||
I"Invalid countdown ${}, try again..." print | ||
ask-n | ||
] until | ||
string>number say-bye-bye ; | ||
|
||
MAIN: main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh -e | ||
PATH_HERE=$(pwd)/$(dirname "$0") | ||
|
||
FACTOR=$(which factor) | ||
# This is usually an irrelevant prime factors tool that we ignore: | ||
if [ -x "$FACTOR" ]; then | ||
if $FACTOR --help 2>&1 | grep -q 'prime factors'; then | ||
FACTOR="" | ||
fi | ||
fi | ||
|
||
# If not found, build Factor from source: | ||
if [ "$FACTOR" = "" ]; then | ||
PATH_REPO="$PATH_HERE/factor" | ||
FACTOR="$PATH_REPO/factor" | ||
|
||
if [ ! -x "$FACTOR" ]; then | ||
if [ ! -d "$PATH_REPO" ]; then | ||
git clone -v --depth=1 [email protected]:factor/factor | ||
fi | ||
cd "$PATH_REPO" | ||
git checkout master | ||
git pull | ||
./build.sh net-bootstrap | ||
fi | ||
fi | ||
|
||
# Use the fast, non-optimizing compiler to run bbhw: | ||
$FACTOR "$PATH_HERE/bbhw/bbhw.factor" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/sh -e | ||
PATH_HERE=$(pwd)/$(dirname "$0") | ||
|
||
FACTOR=$(which factor) | ||
# This is usually an irrelevant prime factors tool that we ignore: | ||
if [ -x "$FACTOR" ]; then | ||
if $FACTOR --help 2>&1 | grep -q 'prime factors'; then | ||
FACTOR="" | ||
fi | ||
fi | ||
|
||
# If not found, build Factor from source: | ||
if [ "$FACTOR" = "" ]; then | ||
PATH_REPO="$PATH_HERE/factor" | ||
FACTOR="$PATH_REPO/factor" | ||
|
||
if [ ! -x "$FACTOR" ]; then | ||
if [ ! -d "$PATH_REPO" ]; then | ||
git clone -v --depth=1 [email protected]:factor/factor | ||
fi | ||
cd "$PATH_REPO" | ||
git checkout master | ||
git pull | ||
./build.sh net-bootstrap | ||
fi | ||
fi | ||
|
||
# Use the slow, optimizing compiler to build bbhw: | ||
BIN="$PATH_HERE"/bbhw/bbhw | ||
if [ ! -x "$BIN" ]; then | ||
$FACTOR -roots="$PATH_HERE" -e='"bbhw" deploy' | ||
mv "$($FACTOR -e='deploy-directory get absolute-path print')/bbhw/bbhw" "$BIN" | ||
fi | ||
|
||
# Run it: | ||
$BIN "$@" |