Made this

This commit is contained in:
retropikzel 2024-12-23 22:01:08 +02:00
commit 0fbf04cb88
11 changed files with 332 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.swp
*.c
*.o
*.so
META-INF

21
Makefile Normal file
View File

@ -0,0 +1,21 @@
PREFIX=/usr/local
build:
@echo "No need to build, just run make install"
install:
mkdir -p ${PREFIX}/bin
install compile-r7rs ${PREFIX}/bin/compile-r7rs
run-test:
@cd test && ../compile-r7rs -D ./libs -D ./libs2 main.scm
clean:
find . -name "*.c*" -delete
find . -name "*.o*" -delete
find . -name "*.so*" -delete
find . -name "*.import.scm" -delete
find . -name "*.link" -delete
find . -name "*.class" -delete
find . -name "META-INF" -exec rm -rf {} \;
find . -not -name "kawa.jar" -name "*.jar" -delete
rm -rf test/main

70
README.md Normal file
View File

@ -0,0 +1,70 @@
Non implementation specific implementation of [SRFI-138](https://srfi.schemers.org/srfi-138/srfi-138.html).
## Dependencies
For scripts:
apt install sharutils
For binaries:
apt install build-essential
For jar:
apt install default-jdk
## Installing
- Download the scman script
- Place it in ${HOME}/.local/bin
- Add ${HOME}/.local/bin to the PATH
- For example add to your .bashrc: export PATH="${HOME}/.local/bin:${PATH}"
- Make the script runnable
- chmod -x ${HOME}/.local/bin/scman
## Usage
The environment variable SCC must be set to the same value as the implementations command.
The command is the first word on the list. So for example guile for Guile, csi for Chicken
interpreter, csc for Chicken compiler.
## Outputs
### Self contained, self extracting and runnable shell script
Requires the Scheme implementation to be installed to run.
- chibi-scheme
- csi (Chicken)
- icyc (Cyclone)
- gsi (Gambit)
- gosh (Gauche)
- guile
- mosh
- sash
- stklos
- skint
- tr7i (tr7)
- ypsilon
### Static binary executable
Requires nothing to be installed to run.
- csc (Chicken)
- racket (Racket)
### Java ARchive (JAR)
Only requires Java to be installed to run.
- kawa
- The build folder needs to contain kawa.jar
## How it works
The scripts searches for .sld files in given paths, compiles them if needed and combines them with
the main script to form something that can be run on it's own. Meaning that the only thing the
person running the things needs, might be, the Scheme implementation.

209
compile-r7rs Executable file
View File

@ -0,0 +1,209 @@
#!/bin/sh
CC=gcc
if [ "" = "${CC}" ]
then
CC=${CC}
fi
output="a.out"
libdirs=""
while getopts "D:o:" flag
do
case $flag in
o) output="${OPTARG}";;
D) libdirs="$libdirs ${OPTARG}";;
esac
done
for main; do true; done # Get the last argument
if [ ! "" = "${main}" ]; then output="${main%.*}"; fi
#tmpdir="${HOME}/.cache/compile-r7rs/$(md5sum $main)/"
tmpdir="${HOME}/.cache/compile-r7rs/test"
case ${SCC} in
chibi-scheme)
paths="-I $tmpdir"
for dir in $libdirs
do
paths="$paths -I $tmpdir/${dir#./}"
done
scm_cmd="chibi-scheme $paths"
;;
csi)
paths="-I $tmpdir/*"
for dir in $libdirs
do
paths="$paths -I $tmpdir/${dir#./}/*"
done
scm_cmd="csi -b -R r7rs $paths -script"
;;
csc)
paths="-I $tmpdir"
objects=""
for dir in $libdirs
do
paths="$paths -I $tmpdir/${dir#./}"
for lib in $(find "$dir" -name "*.sld")
do
echo "Compiling $lib"
csc -X r7rs -R r7rs -c -J -unit ${lib%.sld} "$lib"
objects="$objects ${lib%.sld}.o"
done
done
csc -X r7rs -R r7rs -static $objects -o $output $main
chmod +x "$output"
exit 0
;;
icyc)
paths="-I $tmpdir"
for dir in $libdirs
do
paths="$paths -I $tmpdir/${dir#./}"
done
scm_cmd="icyc $paths -s"
;;
gsi)
paths="${tmpdir%/}/" # / is needed
for dir in $libdirs
do
paths="$paths $tmpdir/${dir#./}/" # / is needed
done
scm_cmd="gsi -:s $paths"
;;
gosh)
paths="-I $tmpdir"
for dir in $libdirs
do
paths="$paths -I $tmpdir/${dir#./}"
done
scm_cmd="gosh -r7 $paths"
;;
gxi) # FIXME
paths=""
for dir in $libdirs
do
paths="$paths :module $tmpdir/${dir#./}"
done
scm_cmd="gxi --lang r7rs"
;;
gxc) # FIXME
echo "(prelude: :scheme/r7rs)" > gerbil.pkg
paths=""
libs=""
for dir in $libdirs
do
paths="$paths ${dir#./}"
for lib in $(find "$dir" -name "*.sld")
do
libs="$libs $lib"
done
done
gxc -o $output -static $libs $main
rm -rf gerbil.pkg
exit
;;
guile)
paths="-L $tmpdir"
for dir in $libdirs
do
paths="$paths -L $tmpdir/${dir#./}"
done
scm_cmd="guile --r7rs $paths -s"
;;
kawa)
jar xf kawa.jar
paths=""
for dir in $libdirs
do
paths="$paths $dir"
for lib in $(find "$dir" -name "*.sld")
do
kawa -C $lib
done
done
{
echo "Main-Class: main"
echo "Class-Path: . gnu kawa $paths"
} > /tmp/compile-r7rs-MANIFEST.mf
kawa --main -C $main
classfiles=$(find .- name "*.class")
jar cvfm "${output}.jar" /tmp/compile-r7rs-MANIFEST.mf kawa gnu $classfiles
rm -rf gnu kawa
rm -rf META-INF
exit
;;
mosh)
paths="$tmpdir"
for dir in $libdirs
do
paths="$paths:$tmpdir/${dir#./}"
done
scm_cmd="mosh --loadpath=$paths"
;;
sash)
paths="-L $tmpdir"
for dir in $libdirs
do
paths="$paths -L $tmpdir/${dir#./}"
done
scm_cmd="sash -r7 $paths"
;;
stklos)
paths="-I $tmpdir"
for dir in $libdirs
do
paths="$paths -I $tmpdir/${dir#./}"
done
scm_cmd="stklos $paths"
;;
skint)
paths="-I ${tmpdir%/}/"
for dir in $libdirs
do
dir1=${dir#./}
paths="$paths -I $tmpdir/${dir1%/}/" # / is needed
done
scm_cmd="skint $paths"
;;
tr7i)
paths="$tmpdir"
for dir in $libdirs
do
paths="$paths:$tmpdir/${dir%./}/" # / is needed
done
scm_cmd="TR7_LIB_PATH=\"$paths:${TR7_LIB_PATH}\" tr7i"
;;
ypsilon)
paths="${tmpdir}/"
for dir in $libdirs
do
paths="$paths:$tmpdir/${dir#./}"
done
scm_cmd="ypsilon --r7rs $paths --top-level-program"
;;
*)
echo "Unsupported SCC (SCheme Compiler) implementation or environment value not set."
exit 1
esac
command="$scm_cmd $tmpdir/$main"
rm -rf "$output"
{
echo "#!/bin/sh"
echo "mkdir -p $tmpdir"
echo 'CURDIR=${PWD}'
echo "cd $tmpdir"
echo "{"
shar -M --quiet-unshar --no-check-existing --no-timestamp $main $libdirs | grep -v "exit 0"
echo "} > /dev/null"
echo 'cd ${CURDIR}'
echo "$command"
} > "$output"
chmod +x "$output"
echo "Command: $command"

1
configure vendored Normal file
View File

@ -0,0 +1 @@
echo "No need to configure, just run make"

BIN
test/kawa.jar Normal file

Binary file not shown.

1
test/libs/hello.scm Normal file
View File

@ -0,0 +1 @@
(define hello "Hello")

6
test/libs/hello.sld Normal file
View File

@ -0,0 +1,6 @@
(define-library
(libs hello)
(import (scheme base)
(scheme write))
(export hello)
(include "hello.scm"))

1
test/libs2/world.scm Normal file
View File

@ -0,0 +1 @@
(define world "world.")

6
test/libs2/world.sld Normal file
View File

@ -0,0 +1,6 @@
(define-library
(libs2 world)
(import (scheme base)
(scheme write))
(export world)
(include "world.scm"))

12
test/main.scm Normal file
View File

@ -0,0 +1,12 @@
(import (scheme base)
(scheme write)
(libs hello)
(libs2 world))
(display hello)
(display " ")
(display world)
(newline)
(exit 0)