git.iko.soy/rowtype-yoga/purescm
on bytevector help sign in
Initial commit
commit1a80d9c7540e5b8945082708b63765b97297b246 authorpurefunctor <purefunctor@pm.me> dateThu 9 Mar 2023, 15:09 (4 years ago)
6 files changed+73
.gitignore+1 README.md+1 examples/01-hello-world/README.md+1 examples/01-hello-world/build-and-run.sh+48 examples/01-hello-world/src/fac.ss+11 examples/01-hello-world/src/main.ss+11
.gitignorenew file+1
@@ -0,0 +1 @@
1+examples/**/out
README.mdnew file+1
@@ -0,0 +1 @@
1+# purs-backend-chez
examples/01-hello-world/README.mdnew file+1
@@ -0,0 +1 @@
1+# 01-hello-world
examples/01-hello-world/build-and-run.shnew file+48
@@ -0,0 +1,48 @@
1+#!/usr/bin/env sh
2+
3+SRC_DIR="src"
4+OUT_DIR="out"
5+
6+set -e
7+
8+if [[ -z "${SCHEME}" ]]; then
9+ SCHEME="chez"
10+else
11+ SCHEME="${SCHEME}"
12+fi
13+
14+if [ ! -d "${OUT_DIR}" ]; then
15+ mkdir -p "${OUT_DIR}"
16+fi
17+
18+# Building
19+
20+echo | $SCHEME --libdirs $SRC_DIR -q << EOF
21+; setup compiler flags...
22+(generate-covin-files #f)
23+(compile-profile #f)
24+(debug-level 0)
25+(cp0-effort-limit 1)
26+(cp0-score-limit 1)
27+(cp0-outer-unroll-limit 1)
28+(compile-interpret-simple #f)
29+(enable-cross-library-optimization #t)
30+(generate-inspector-information #f)
31+(generate-procedure-source-information #t)
32+(generate-interrupt-trap #t)
33+
34+; compile the program
35+(compile-library "${SRC_DIR}/fac.ss" "${OUT_DIR}/fac.so")
36+(compile-program "${SRC_DIR}/main.ss" "${OUT_DIR}/main.so")
37+EOF
38+
39+# Running
40+
41+$SCHEME --libdirs $OUT_DIR --program ./out/main.so
42+
43+# Note how in both building and running, we specified the libdirs parameter.
44+#
45+# For distributing binaries, we would want to do the following:
46+#
47+# 1. Install built objects somewhere, usually this would be `$PREFIX/lib/`
48+# 2. Generate a shell script that passes libdirs, this would be in `$PREFIX/bin`
examples/01-hello-world/src/fac.ssnew file+11
@@ -0,0 +1,11 @@
1+(library (fac)
2+ (export factorial)
3+ (import (chezscheme))
4+
5+ (define factorial
6+ (lambda (n)
7+ (if (= n 0)
8+ 1
9+ (* n (factorial (- n 1))))))
10+
11+ )
examples/01-hello-world/src/main.ssnew file+11
@@ -0,0 +1,11 @@
1+(import (chezscheme) (fac))
2+
3+(display "This is a top-level program!")
4+
5+(newline)
6+
7+(display "(factorial 5) = ")
8+
9+(display (factorial 5))
10+
11+(newline)