From 8853ed5c5cc4c03a87ec067ece43bc0a19ee6329 Mon Sep 17 00:00:00 2001 From: retropikzel Date: Fri, 7 Nov 2025 12:18:32 +0200 Subject: [PATCH] Making a manual page and renaming the program --- .gitignore | 2 +- Makefile | 78 ++++----- README.md | 210 +++---------------------- compile-r7rs.bat | 3 - compile-r7rs.scm => compile-scheme.scm | 46 ++++-- doc/HACKING.md | 39 +++++ doc/INSTALL.md | 12 ++ doc/compile-scheme.1 | 82 ++++++++++ old-README.md | 200 +++++++++++++++++++++++ 9 files changed, 430 insertions(+), 242 deletions(-) delete mode 100644 compile-r7rs.bat rename compile-r7rs.scm => compile-scheme.scm (89%) create mode 100644 doc/HACKING.md create mode 100644 doc/INSTALL.md create mode 100644 doc/compile-scheme.1 create mode 100644 old-README.md diff --git a/.gitignore b/.gitignore index 264c275..8c029f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ *.swp *.swo *.link -compile-r7rs +compile-scheme test-r7rs test *.c diff --git a/Makefile b/Makefile index f49e5c7..31ca66d 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SCHEME=chibi VERSION=1.0.0 R6RSTMP=tmp/${SCHEME}-r6rs R7RSTMP=tmp/${SCHEME}-r7rs -DOCKERTAG=compile-r7rs-test-${SCHEME} +DOCKERTAG=compile-scheme-test-${SCHEME} DOCKERIMG=${SCHEME}:head ifeq "${SCHEME}" "chicken" DOCKERIMG="chicken:5" @@ -15,10 +15,14 @@ STATIC_LIBS=libs.util.a libs.library-util.a libs.data.a libs.srfi-64-util.a all: build-chibi +readme: manpage.1 + printf "
\n$$(MANWIDTH=80 man -l doc/compile-scheme.1)\n
" > README.md + cat README.md > README.html + build-chibi: - echo "#!/bin/sh" > compile-r7rs - echo "chibi-scheme -A ${PREFIX}/lib/compile-r7rs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\"" >> compile-r7rs - chmod +x compile-r7rs + echo "#!/bin/sh" > compile-scheme + echo "chibi-scheme -A ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme + chmod +x compile-scheme build-chicken: csc -R r7rs -X r7rs -static -c -J -unit libs.util -o libs.util.o libs/util.sld @@ -28,70 +32,70 @@ build-chicken: csc -R r7rs -X r7rs -static -c -J -unit libs.data -o libs.data.o libs/data.sld ar rcs libs.data.a libs.data.o csc -R r7rs -X r7rs -static \ - -o compile-r7rs \ + -o compile-scheme \ -uses libs.util \ -uses libs.library-util \ -uses libs.data \ -uses foreign.c \ -uses srfi-170 \ - compile-r7rs.scm + compile-scheme.scm deb: build-chicken mkdir -p deb/bin - cp compile-r7rs deb/bin/ + cp compile-scheme deb/bin/ mkdir -p deb/DEBIAN - printf "Package: compile-r7rs\nArchitecture: amd64\nVersion: ${VERSION}\nSection: misc\nMaintainer: Retropikzel \nDescription: SRFI 138: Compiling Scheme programs to executables - Implementation" \ + printf "Package: compile-scheme\nArchitecture: amd64\nVersion: ${VERSION}\nSection: misc\nMaintainer: Retropikzel \nDescription: SRFI 138: Compiling Scheme programs to executables - Implementation" \ > deb/DEBIAN/control dpkg-deb -b deb # FIXME #build-gauche: - #echo "#!/bin/sh" > compile-r7rs - #echo "gosh -r -I ${PREFIX}/lib/compile-r7rs -I ${PREFIX}/lib/compile-r7rs/libs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\"" >> compile-r7rs - #chmod +x compile-r7rs + #echo "#!/bin/sh" > compile-scheme + #echo "gosh -r -I ${PREFIX}/lib/compile-scheme -I ${PREFIX}/lib/compile-scheme/libs ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compilescheme- + #chmod +x compile-scheme build-guile: - echo "#!/bin/sh" > compile-r7rs - echo "guile --r7rs --auto-compile -I -q -L ${PREFIX}/lib/compile-r7rs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\"" >> compile-r7rs - chmod +x compile-r7rs + echo "#!/bin/sh" > compile-scheme + echo "guile --r7rs --auto-compile -I -q -L ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme + chmod +x compile-scheme # FIXME #build-kawa: - #echo "#!/bin/sh" > compile-r7rs - #echo "kawa -J--add-exports=java.base/jdk.internal.foreign.abi=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign.layout=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign=ALL-UNNAMED -J--enable-native-access=ALL-UNNAMED -Dkawa.import.path=/usr/local/share/kawa/lib/*.sld:${PREFIX}/lib/compile-r7rs/*.sld --r7rs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\" 2> /dev/null" >> compile-r7rs - #chmod +x compile-r7rs + #echo "#!/bin/sh" > compile-scheme + #echo "kawa -J--add-exports=java.base/jdk.internal.foreign.abi=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign.layout=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign=ALL-UNNAMED -J--enable-native-access=ALL-UNNAMED -Dkawa.import.path=/usr/local/share/kawa/lib/*.sld:${PREFIX}/lib/compile-scheme/*.sld --r7rs ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\" 2> /dev/null" >> compile-scheme + #chmod +x compile-scheme # FIXME #build-racket: - #echo "#!/bin/sh" > compile-r7rs - #echo "racket -I r7rs -S ${PREFIX}/lib/compile-r7rs --script ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\"" >> compile-r7rs + #echo "#!/bin/sh" > compile-scheme + #echo "racket -I r7rs -S ${PREFIX}/lib/compile-scheme --script ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme build-sagittarius: - echo "#!/bin/sh" > compile-r7rs - echo "sash -A ${PREFIX}/lib/compile-r7rs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\"" >> compile-r7rs - chmod +x compile-r7rs + echo "#!/bin/sh" > compile-scheme + echo "sash -A ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme + chmod +x compile-scheme build-stklos: - echo "#!/bin/sh" > compile-r7rs - echo "stklos -I ${PREFIX}/lib/compile-r7rs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\"" >> compile-r7rs - chmod +x compile-r7rs + echo "#!/bin/sh" > compile-scheme + echo "stklos -I ${PREFIX}/lib/compile-scheme ${PREFIX}/lib/compile-scheme/compile-scheme.scm \"\$$@\"" >> compile-scheme + chmod +x compile-scheme install: mkdir -p ${PREFIX}/bin - mkdir -p ${PREFIX}/lib/compile-r7rs - cp -r libs ${PREFIX}/lib/compile-r7rs/ - cp compile-r7rs.scm ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm - install compile-r7rs ${PREFIX}/bin/compile-r7rs + mkdir -p ${PREFIX}/lib/compile-scheme + cp -r libs ${PREFIX}/lib/compile-scheme/ + cp compile-scheme.scm ${PREFIX}/lib/compile-scheme/compile-scheme.scm + install compile-scheme ${PREFIX}/bin/compile-scheme uninstall: - rm -rf ${PREFIX}/lib/compile-r7rs - rm -rf ${PREFIX}/bin/compile-r7rs + rm -rf ${PREFIX}/lib/compile-scheme + rm -rf ${PREFIX}/bin/compile-scheme test-r6rs: rm -rf ${R6RSTMP} mkdir -p ${R6RSTMP} cp -r r6rs-testfiles/* ${R6RSTMP}/ - cd ${R6RSTMP} && COMPILE_R7RS=${SCHEME} compile-r7rs -I ./libs -o main main.sps + cd ${R6RSTMP} && COMPILE_R7RS=${SCHEME} compile-scheme -I ./libs -o main main.sps cd ${R6RSTMP} && ./main 1 2 3 > test-result.txt @grep "Test successfull (\"1\" \"2\" \"3\")" ${R6RSTMP}/test-result.txt || (echo "Test failed, output: " && cat ${R6RSTMP}/test-result.txt && exit 1) @@ -103,7 +107,7 @@ test-r6rs-php: rm -rf ${R6RSTMP} mkdir -p ${R6RSTMP} cp -r r6rs-php-testfiles/* ${R6RSTMP}/ - cd ${R6RSTMP} && COMPILE_R7RS=${SCHEME} COMPILE_R7RS_TARGET=php compile-r7rs -o main.php main.sps + cd ${R6RSTMP} && COMPILE_R7RS=${SCHEME} compile-scheme -t php -o main.php main.sps -cd ${R6RSTMP} && php main.php > test-result.txt 2>&1 @grep "Test successfull" ${R6RSTMP}/test-result.txt || (echo "Test failed, output: " && cat ${R6RSTMP}/test-result.txt && exit 1) @@ -115,7 +119,7 @@ test-r7rs: rm -rf ${R7RSTMP} mkdir -p ${R7RSTMP} cp -r r7rs-testfiles/* ${R7RSTMP}/ - cd ${R7RSTMP} && COMPILE_R7RS=${SCHEME} compile-r7rs -I ./libs -o main main.scm + cd ${R7RSTMP} && COMPILE_R7RS=${SCHEME} compile-scheme -I ./libs main.scm -cd ${R7RSTMP} && ./main 1 2 3 > test-result.txt 2>&1 @grep "Test successfull (\"1\" \"2\" \"3\")" ${R7RSTMP}/test-result.txt || (echo "Test failed, output: " && cat ${R7RSTMP}/test-result.txt && exit 1) @@ -127,7 +131,7 @@ test-r7rs-wine: rm -rf ${R7RSTMP} mkdir -p ${R7RSTMP} cp -r r7rs-testfiles/* ${R7RSTMP}/ - cd ${R7RSTMP} && COMPILE_R7RS=${SCHEME} COMPILE_R7RS_TARGET=windows compile-r7rs -I ./libs -o main.bat main.scm + cd ${R7RSTMP} && COMPILE_R7RS=${SCHEME} COMPILE_R7RS_TARGET=windows compile-scheme -I ./libs -o main.bat main.scm -cd ${R7RSTMP} && wine main.bat 1 2 3 > test-result.txt 2>&1 @grep "Test successfull (\"1\" \"2\" \"3\")" ${R7RSTMP}/test-result.txt || (echo "Test failed, output: " && cat ${R7RSTMP}/test-result.txt && exit 1) @@ -139,7 +143,7 @@ test-r7rs-php: rm -rf ${R7RSTMP} mkdir -p ${R7RSTMP} cp -r r7rs-php-testfiles/* ${R7RSTMP}/ - cd ${R7RSTMP} && COMPILE_R7RS=${SCHEME} COMPILE_R7RS_TARGET=php compile-r7rs -o main.php main.scm + cd ${R7RSTMP} && COMPILE_R7RS=${SCHEME} COMPILE_R7RS_TARGET=php compile-scheme -o main.php main.scm -cd ${R7RSTMP} && php main.php > test-result.txt 2>&1 @grep "Test successfull" ${R7RSTMP}/test-result.txt || (echo "Test failed, output: " && cat ${R7RSTMP}/test-result.txt && exit 1) @@ -149,7 +153,7 @@ test-r7rs-php-docker: clean: rm -rf test-r7rs - rm -rf compile-r7rs + rm -rf compile-scheme find . -name "*.so" -delete find . -name "*.o*" -delete find . -name "*.a*" -delete diff --git a/README.md b/README.md index a67c7d5..fba653f 100644 --- a/README.md +++ b/README.md @@ -1,197 +1,31 @@ -compile-r7rs is a tool to compile Scheme programs, it aims for compability -with [SRFI-138](https://srfi.schemers.org/srfi-138/srfi-138.html). +
+compile-r7rs(1)             General Commands Manual             compile-r7rs(1)
 
-Despite it's name it also supports R6RS. Schemers, unite! <3
+NAME
+       compile-r7rs - a tool to compile R6RS and R7RS Scheme programs
 
-[Jenkins](https://jenkins.scheme.org/job/retropikzel/job/compile-r7rs/)
+ENVIRONMENT
+       COMPILE_R7RS  environment variable must be set to the name of the imple‐
+       mentation as specified in the support list.   **This  differs  from  the
+       SRFI** as the SRFI excepts a path.
 
-## Notes
+SYNOPSIS
+       compile-r7rs [-n BITS] [--bits BITS] file...  compile-r7rs
 
-- No support for -D flag yet.
-- Not all implementations support adding to beginning or end o load path so
--I and -A might work the same
+DESCRIPTION
+       compile-r7rs
 
-## Build and install
+       It  aims  to support Scheme SRFI-138 - Compiling Scheme programs to exe‐
+       cutables.
 
-You can run compile-r7rs on Chibi, Chicken, Gauche, Guile, Kawa, Sagittarius or
-STklos.
+CAVEATS
+       -      No support for -D flag.
 
-    snow-chibi --impls=SCHEME "(foreign c)"
-    snow-chibi --impls=SCHEME "(srfi 170)"
-    make build-SCHEME
-    make install
-
-## Usage
-
-### R6RS
-
-Replace the .scm file with .sps file in the next section.
-
-### R7RS
-
-You need to install each Scheme implementation yourself.
-
-The environment variable COMPILE\_R7RS must be set to the **name** of the
-implementation as specified in the support list.
-**This differs from the SRFI** as the SRFI excepts a path.
-
-To get the list of supported R6RS implementations run:
-
-    compile-r7rs --list-r6rs-schemes
-
-To get the list of supported R7RS implementations run:
-
-    compile-r7rs --list-r7rs-schemes
-
-To get the list of all supported implementations run:
-
-    compile-r7rs --list-schemes
-
-Then run it with the .scm file for R7RS, or .sps file for R6RS.
-
-    COMPILE_R7RS= compile-r7rs -I . -o main main.scm
-
-Which produces file called main, which you can run. Note that when given Scheme
-is interpreter the file contains commands that run the script, and even when
-the file is combiled binary it might need the compiled libraries.
-
-No other file suffixes are supported at the moment.
-
-Setting value of COMPILE\_R7RS to implementation name that supports only r7rs
-and input file to .sps file and other way around is undefined behaviour.
-
-### Environment variables
-
-- COMPILE\_R7RS
-    - **Name** of the implementation you want to compile with
-    - **This differs from the SRFI** as it excepts a path
-- COMPILE\_R7RS\_SCHEME_NAME
-    - Additional string to insert right after the command and it's arguments
-    can be used for example to pass C compiler flags on implementations that
-    compile to C or anything or otherwise as backdoor
-    - For example for Chicken to link with libcurl you would set
-    COMPILE\_R7RS\_CHICKEN="-L -lcurl"
-    - If implementation has - it is changed to \_, for example mit-scheme ->
-    MIT\_SCHEME
-    - **This differs from the SRFI** as it's not in there
-
-## Supported implementations
-
-Some implementations support both compiling and interpreting, in that
-case only the compiler functionality is used and the implementation is marked
-as compiler.
-
-- chezscheme
-    - interpreter
-    - R6RS
-- chibi
-    - interpreter
-    - R7RS
-- chicken
-    - compiler
-    - R7RS
-- cyclone
-    - compiler
-    - R7RS
-- foment
-    - interpreter
-    - R7RS
-- gauche
-    - interpreter
-    - R7RS
-- guile
-    - interpreter
-    - R6RS
-    - R7RS
-        - Has include bug https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66046
-        but for some reason it seems to work for me atleast sometimes
-- ikarus
-    - interpreter
-    - R6RS
-- ironscheme
-    - interpreter
-    - R6RS
-- kawa
-    - interpreter
-    - R7RS
-    - Native access is enabled by default so pffi can work
-- larceny
-    - interpreter
-    - R6RS
-    - R7RS
-- loko
-    - compiler
-    - R6RS
-    - R7RS
-- meevax
-    - r7rs
-- mit-scheme
-    - interpreter
-    - R7RS
-- mosh
-    - interpreter
-    - R6RS
-    - R7RS
-- racket
-    - interpreter
-        - Has compiling capabilities but I havent got them to work yet
-    - r6rs
-    - r7rs
-- sagittarius
-    - interpreter
-    - R6RS
-    - R7RS
-- skint
-    - interpreter
-    - R7RS
-- stklos
-    - interpreter
-    - R7RS
-- tr7
-    - interpreter
-    - R7RS
-- ypsilon
-    - interpreter
-    - R6RS
-    - R7RS
-
-## Roadmap
-
-- Support for more implementations
-    - gambit
-    - husk
-        - Dont know how to add directories to load path yet, might not be
-        implemented
-        - r7rs
-    - picrin
-        - Might not be possible, seems to not have (include...) that works like
-        others
-        - r7rs
-    - scheme-rs
-        - Waiting for implementation support
-        - r6rs
-        - r7rs
-    - stak
-        - Waiting for implementation support https://github.com/raviqqe/stak/issues/2355
-        - r7rs
-    - vicare
-        - So old that I have problems compiling it in Docker, so testing is
-        hard but I expect it to work once I get it to compile as it is R6RS
-        implementation
-        - r6rs
-- Better and tested support for Windows
-    - Right now there is support for running this but I can not quarantee it
-    works on all if any cases
-- Support for -D
-    - Most implementations dont have this or equivalent flag, but it would be
-    really nice feature to have so filing issues and implementing it myself is
-    something I would like to do
-- Ask implementations to support adding to the front and back of load path, or
-    implement this onto implementations myself
-    - This might not be as important, but it would be nice to go towards SRFI-138
-    conformaty
-- Environment variable to force the target operating system
-    - Since for example for interpreters the program produces .bat file with
-    command to run the interpreter "cross compiling" is easy.
+       -      Not all implementations support adding to  beginning  or  end  of
+              load path so -I and -A might work the same
 
+OPTIONS
+       -n, --bits=BITS Set the number of bits to modify.  Default is one bit.
 
+                                                                compile-r7rs(1)
+
\ No newline at end of file diff --git a/compile-r7rs.bat b/compile-r7rs.bat deleted file mode 100644 index 523608c..0000000 --- a/compile-r7rs.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off -set "PFFI_LOAD_PATH=%PROGRAMFILES%/compile-r7rs/snow/srfi" -sash.exe -r7 -L "%PROGRAMFILES%/compile-r7rs/snow" -L "%PROGRAMFILES%/compile-r7rs" "%PROGRAMFILES%/compile-r7rs/main.scm" %* diff --git a/compile-r7rs.scm b/compile-scheme.scm similarity index 89% rename from compile-r7rs.scm rename to compile-scheme.scm index 4bd66e3..6b31452 100644 --- a/compile-r7rs.scm +++ b/compile-scheme.scm @@ -21,34 +21,35 @@ (newline) (exit 0)) -(when (or (member "--list" (command-line)) +(when (or (member "--list-all" (command-line)) (member "--list-schemes" (command-line))) (for-each (lambda (scheme) (display scheme) (display " ")) all-schemes) (newline) (exit 0)) -(define scheme (if (get-environment-variable "COMPILE_R7RS") - (string->symbol (get-environment-variable "COMPILE_R7RS")) - #f)) +(define scheme + (cond + ((get-environment-variable "COMPILE_R7RS") + (string->symbol (get-environment-variable "COMPILE_R7RS"))) + ((get-environment-variable "COMPILE_SCHEME") + (string->symbol (get-environment-variable "COMPILE_SCHEME"))) + (else #f))) (when (not scheme) - (display "Environment variable COMPILE_R7RS not set." (current-error-port)) + (display "Either environment variable COMPILE_R7RS or COMPILE_SCHEME is not set." (current-error-port)) (newline (current-error-port)) (exit 1)) (when (not (assoc scheme data)) (error "Unsupported implementation" scheme)) -(define compilation-target - (if (get-environment-variable "COMPILE_R7RS_TARGET") - (string->symbol (get-environment-variable "COMPILE_R7RS_TARGET")) - (cond-expand (windows 'windows) - (else 'unix)))) (define input-file (let ((input-file #f)) (for-each (lambda (item) - (when (or (string-ends-with? item ".scm") - (string-ends-with? item ".sps")) + (if (or (string-ends-with? item ".scm") + (string-ends-with? item ".sps")) (set! input-file item))) (list-tail (command-line) 1)) + (when (not input-file) + (error "The intput-file must be either .scm (R7RS) or .sps (R6RS)")) input-file)) (define single-library-input-file @@ -70,7 +71,7 @@ (define scheme-type (cdr (assoc 'type (cdr (assoc scheme data))))) -(define output-file +(define compilation-target (let ((outfile (if (member "-o" (command-line)) (cadr (member "-o" (command-line))) (if input-file @@ -81,6 +82,25 @@ (string-append outfile ".bin") outfile))) +(define compilation-target + (cond + ((member "-t" (command-line)) + (cadr (member "-t" (command-line)))) + (else + (cond-expand (windows 'windows) + (else 'unix))))) + +(define output-file + (let ((outfile + (cond + ((member "-o" (command-line)) + (cadr (member "-o" (command-line)))) + (input-file (string-cut-from-end input-file 4))))) + (if (and (symbol=? scheme-type 'compiler) + (symbol=? compilation-target 'php)) + (string-append outfile ".bin") + outfile))) + (define prepend-directories (letrec ((looper (lambda (rest result) (if (null? rest) diff --git a/doc/HACKING.md b/doc/HACKING.md new file mode 100644 index 0000000..709458a --- /dev/null +++ b/doc/HACKING.md @@ -0,0 +1,39 @@ +## Roadmap + +- Support for more implementations + - gambit + - Adding paths to compiled executable is such a pain that no support yet + - husk + - Dont know how to add directories to load path yet, might not be + implemented + - r7rs + - picrin + - Might not be possible, seems to not have (include...) that works like + others + - r7rs + - scheme-rs + - Waiting for implementation support + - r6rs + - r7rs + - stak + - Waiting for implementation support https://github.com/raviqqe/stak/issues/2355 + - r7rs + - vicare + - So old that I have problems compiling it in Docker, so testing is + hard but I expect it to work once I get it to compile as it is R6RS + implementation + - r6rs +- Better and tested support for Windows + - Right now there is support for running this but I can not quarantee it + works on all if any cases +- Support for -D + - Most implementations dont have this or equivalent flag, but it would be + really nice feature to have so filing issues and implementing it myself is + something I would like to do +- Ask implementations to support adding to the front and back of load path, or + implement this onto implementations myself + - This might not be as important, but it would be nice to go towards SRFI-138 + conformaty +- Environment variable to force the target operating system + - Since for example for interpreters the program produces .bat file with + command to run the interpreter "cross compiling" is easy. diff --git a/doc/INSTALL.md b/doc/INSTALL.md new file mode 100644 index 0000000..649d77d --- /dev/null +++ b/doc/INSTALL.md @@ -0,0 +1,12 @@ +## Build and install + +You will need to have snow-chibi installed, it comes with Chibi Scheme. + +You can run compile-r7rs on Chibi, Chicken, Gauche, Guile, Kawa, Sagittarius or +STklos. + + snow-chibi --impls=SCHEME "(foreign c)" + snow-chibi --impls=SCHEME "(srfi 170)" + make build-SCHEME + make install + diff --git a/doc/compile-scheme.1 b/doc/compile-scheme.1 new file mode 100644 index 0000000..ed39018 --- /dev/null +++ b/doc/compile-scheme.1 @@ -0,0 +1,82 @@ +.TH compile-scheme 1 +.SH NAME +compile-scheme \- Compiling Scheme programs to executables +.SH SYNOPSIS +\fBcompile-scheme\fR { [\fB-A\fR \fIpath\fR] [\fB-I\fR \fIpath\fR] [\fB-o\fR \fIpath\fR] [\fB-t\fR \fItarget\fR] input-file\fI{.scm | .sps}\fR | \fIlong-options...\fR } +.SH DESCRIPTION +.P +\fBcompile-scheme\fR is a tool to compile R6RS and R7RS Scheme programs. +It supports most of SRFI-138 but also adds more features. +.P +The program \fIinput-file\fR is compiled into an executable file. +The resulting executable file is written to file specified by the \fB-o\fR \fIpath\fR (if present) or to the file named same as \fIinput-file\fR but without the .scm or .sps suffix. +On Windows either .bat or .exe is appended to the output name. +.SS SUPPORT LIST +.P +Some implementations support both compiling and interpreting, in that +case only the compiler functionality is used and the implementation is marked +as compiler. +.IP "R6RS Compilers" +loko +.IP "R6RS Interpreters" +chezscheme guile ikarus ironscheme mosh racket sagittarius ypsilon +.IP "R7RS Compilers" +chicken cyclone loko +.IP "R7RS Interpreters" +chibi foment gauche guile kawa larceny meevax mit-scheme mosh racket sagittarius skint stklos tr7 ypsilon +.SH OPTIONS +.P +\fB\-A\fR \fIpath\fR +Append path to the list of directories that are searched in order to locate imported libraries. +.P +\fB\-I\fR \fIpath\fR +Prepend directory to the list of directories that are searched in order to locate imported libraries. +.P +\fB-o\fR \fIoutput-file\fR +Use the \fIoutput-file\fR file, instead of the default deducted from input-file, for the executable file produced. +.P +Multiple instances of the -A, and -I options can be specified. +.P +\fB\-t\fR { \fIunix\fR | \fIwindows\fR | \fIphp\fR } +Set the compilation target. +This is not needed if you are compiling for the target OS you are running. +Cross compilation is only supported in following cases: +.IP +From \fIunix\fR host to \fIphp\fR target when chosen implementation is interpreter. +.IP +From \fIunix\fR host to \fIwindows\fR target when chosen implementation is interpreter. +.P +.B \-\-list-r6rs +List supported R6RS implementations. +.P +.B \-\-list-r7rs +List supported R7RS implementations. +.P +.B \-\-list-all +List all supported implementations. +.P +\fB\-\-list-targets\fR +List all supported compilation targets. +.SH ENVIRONMENT +.P +\fBCOMPILE_R7RS/COMPILE_SCHEME\fR +.IP +This environment variable \fBmust\fR be set. Set it to the \fBname\fR of the implementation as specified in the support list. +\fBThis differs from SRFI-138\fR as the SRFI excepts a path. +.SH STANDARDS +.P +SRFI 138: Compiling Scheme programs to executables. +https://srfi.schemers.org/srfi-138/srfi-138.html +.SH CAVEATS +.P +Differences from SRFI-138 +.IP +No support for -D flag. +.IP +Not all implementations support adding to beginning or end of load path so -I and -A might work the same +.IP +Only supports one input-file. +.SH EXAMPLES + + + diff --git a/old-README.md b/old-README.md new file mode 100644 index 0000000..a1633c0 --- /dev/null +++ b/old-README.md @@ -0,0 +1,200 @@ +compile-r7rs is a tool to compile R6RS and R7RS Scheme programs + +It aims for compability +with [SRFI-138](https://srfi.schemers.org/srfi-138/srfi-138.html). + +Despite it's name it also supports R6RS. Schemers, unite! <3 + +[Jenkins](https://jenkins.scheme.org/job/retropikzel/job/compile-r7rs/) + +## Notes + +- No support for -D flag yet. +- Not all implementations support adding to beginning or end o load path so +-I and -A might work the same + +## Build and install + +You can run compile-r7rs on Chibi, Chicken, Gauche, Guile, Kawa, Sagittarius or +STklos. + + snow-chibi --impls=SCHEME "(foreign c)" + snow-chibi --impls=SCHEME "(srfi 170)" + make build-SCHEME + make install + +## Usage + +### R6RS + +Replace the .scm file with .sps file in the next section. + +### R7RS + +You need to install each Scheme implementation yourself. + +The environment variable COMPILE\_R7RS must be set to the **name** of the +implementation as specified in the support list. +**This differs from the SRFI** as the SRFI excepts a path. + +To get the list of supported R6RS implementations run: + + compile-r7rs --list-r6rs-schemes + +To get the list of supported R7RS implementations run: + + compile-r7rs --list-r7rs-schemes + +To get the list of all supported implementations run: + + compile-r7rs --list-schemes + +Then run it with the .scm file for R7RS, or .sps file for R6RS. + + COMPILE_R7RS= compile-r7rs -I . -o main main.scm + +Which produces file called main, which you can run. Note that when given Scheme +is interpreter the file contains commands that run the script, and even when +the file is combiled binary it might need the compiled libraries. + +No other file suffixes are supported at the moment. + +Setting value of COMPILE\_R7RS to implementation name that supports only r7rs +and input file to .sps file and other way around is undefined behaviour. + +### Environment variables + +- COMPILE\_R7RS + - **Name** of the implementation you want to compile with + - **This differs from the SRFI** as it excepts a path +- COMPILE\_R7RS\_SCHEME_NAME + - Additional string to insert right after the command and it's arguments + can be used for example to pass C compiler flags on implementations that + compile to C or anything or otherwise as backdoor + - For example for Chicken to link with libcurl you would set + COMPILE\_R7RS\_CHICKEN="-L -lcurl" + - If implementation has - it is changed to \_, for example mit-scheme -> + MIT\_SCHEME + - **This differs from the SRFI** as it's not in there + +## Supported implementations + +Some implementations support both compiling and interpreting, in that +case only the compiler functionality is used and the implementation is marked +as compiler. + +- chezscheme + - interpreter + - R6RS +- chibi + - interpreter + - R7RS +- chicken + - compiler + - R7RS +- cyclone + - compiler + - R7RS +- foment + - interpreter + - R7RS +- gauche + - interpreter + - R7RS +- guile + - interpreter + - R6RS + - R7RS + - Has include bug https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66046 + but for some reason it seems to work for me atleast sometimes +- ikarus + - interpreter + - R6RS +- ironscheme + - interpreter + - R6RS +- kawa + - interpreter + - R7RS + - Native access is enabled by default so pffi can work +- larceny + - interpreter + - R6RS + - R7RS +- loko + - compiler + - R6RS + - R7RS +- meevax + - r7rs +- mit-scheme + - interpreter + - R7RS +- mosh + - interpreter + - R6RS + - R7RS +- racket + - interpreter + - Has compiling capabilities but I havent got them to work yet + - r6rs + - r7rs +- sagittarius + - interpreter + - R6RS + - R7RS +- skint + - interpreter + - R7RS +- stklos + - interpreter + - R7RS +- tr7 + - interpreter + - R7RS +- ypsilon + - interpreter + - R6RS + - R7RS + +## Roadmap + +- Support for more implementations + - gambit + - Adding paths to compiled executable is such a pain that no support yet + - husk + - Dont know how to add directories to load path yet, might not be + implemented + - r7rs + - picrin + - Might not be possible, seems to not have (include...) that works like + others + - r7rs + - scheme-rs + - Waiting for implementation support + - r6rs + - r7rs + - stak + - Waiting for implementation support https://github.com/raviqqe/stak/issues/2355 + - r7rs + - vicare + - So old that I have problems compiling it in Docker, so testing is + hard but I expect it to work once I get it to compile as it is R6RS + implementation + - r6rs +- Better and tested support for Windows + - Right now there is support for running this but I can not quarantee it + works on all if any cases +- Support for -D + - Most implementations dont have this or equivalent flag, but it would be + really nice feature to have so filing issues and implementing it myself is + something I would like to do +- Ask implementations to support adding to the front and back of load path, or + implement this onto implementations myself + - This might not be as important, but it would be nice to go towards SRFI-138 + conformaty +- Environment variable to force the target operating system + - Since for example for interpreters the program produces .bat file with + command to run the interpreter "cross compiling" is easy. + +