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
+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=\ 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 - - 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) +