Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Gerbil Scheme #314

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ matrix:
- {env: IMPL=scheme scheme_MODE=sagittarius, services: [docker]}
- {env: IMPL=scheme scheme_MODE=cyclone, services: [docker]}
# - {env: IMPL=scheme scheme_MODE=foment, services: [docker]}
- {env: IMPL=scheme scheme_MODE=gerbil, services: [docker]}
- {env: IMPL=skew, services: [docker]}
- {env: IMPL=swift NO_DOCKER=1, os: osx, osx_image: xcode7.3}
- {env: IMPL=swift3, services: [docker]}
Expand Down
13 changes: 13 additions & 0 deletions scheme/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,17 @@ RUN cd /tmp && git clone https://github.com/leftmike/foment \
&& cd foment/unix && make && cp release/foment /usr/bin/foment \
&& rm -rf /tmp/foment

# Gerbil
RUN apt-get -y install openssl libssl-dev sqlite3 libsqlite3-dev
RUN cd /tmp && git clone https://github.com/gambit/gambit && cd gambit \
&& ./configure --prefix=/opt/gambit --enable-single-host && make && make install \
&& rm -rf /tmp/gambit
ENV PATH "$PATH:/opt/gambit/bin"
RUN cd /tmp && git clone https://github.com/vyzo/gerbil \
&& cd gerbil/src && ./build.sh \
&& mkdir /opt/gerbil && mv /tmp/gerbil/bin /opt/gerbil && mv /tmp/gerbil/lib /opt/gerbil \
&& rm -rf /tmp/gerbil
ENV PATH "$PATH:/opt/gerbil/bin"
ENV GERBIL_HOME /opt/gerbil

ENV HOME /mal
8 changes: 7 additions & 1 deletion scheme/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ CLASSSTEPS = out/step0_repl.class out/step1_read_print.class \
out/step3_env.class out/step4_if_fn_do.class out/step5_tco.class \
out/step6_file.class out/step7_quote.class out/step8_macros.class \
out/step9_try.class out/stepA_mal.class
GXCSTEPS = gxc.out
STEPS = $(if $(filter kawa,$(scheme_MODE)),$(CLASSSTEPS),\
$(if $(filter chicken,$(scheme_MODE)),$(BINS),\
$(if $(filter cyclone,$(scheme_MODE)),$(BINS))))
$(if $(filter cyclone,$(scheme_MODE)),$(BINS),\
$(if $(filter gerbil,$(scheme_MODE)),$(GXCSTEPS)))))

KAWA_STEP1_DEPS = out/lib/util.class out/lib/reader.class \
out/lib/printer.class out/lib/types.class
Expand Down Expand Up @@ -69,6 +71,9 @@ eggs/r7rs.so:
chicken-install -init eggs
CHICKEN_REPOSITORY=$(CURDIR)/eggs chicken-install r7rs

gxc.out:
./gerbil-build.sh

lib/%.scm: lib/%.sld
$(SYMLINK) $< $@

Expand Down Expand Up @@ -104,6 +109,7 @@ clean:
$(RM) lib/*.scm lib/*.so lib/*.c lib/*.o lib/*.meta
$(RM) lib.*.scm *.so *.c *.o $(BINS)
$(RM) eggs/*
$(RM) -rf gxc.out
$(RMR) out

stats: $(SOURCES)
Expand Down
9 changes: 9 additions & 0 deletions scheme/gerbil-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

export GERBIL_LOADPATH=gxc.out

mkdir -p gxc.out/bin
gxc -d gxc.out -O lib/util.sld lib/types.sld lib/env.sld lib/reader.sld lib/printer.sld lib/core.sld
for x in step0_repl step1_read_print step2_eval step3_env step4_if_fn_do step5_tco step6_file step7_quote step8_macros step9_try stepA_mal; do
gxc -d gxc.out -O -exe -o gxc.out/bin/$x $x.scm
done
1 change: 1 addition & 0 deletions scheme/gerbil.pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(prelude: :scheme/r7rs)
1 change: 1 addition & 0 deletions scheme/run
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ case ${scheme_MODE:-chibi} in
sagittarius) exec $sagittarius -n -L$basedir $basedir/$step.scm "${@}" ;;
cyclone) exec $basedir/$step "${@}" ;;
foment) exec foment $basedir/$step.scm "${@}" ;;
gerbil) GERBIL_LOADPATH=$basedir/gxc.out exec $basedir/gxc.out/bin/$step "${@}" ;;
*) echo "Invalid scheme_MODE: ${scheme_MODE}"; exit 2 ;;
esac
6 changes: 5 additions & 1 deletion scheme/step0_repl.scm
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@
(loop))))
(newline))

(main)
(cond-expand
(gerbil
(export main))
(else
(main)))
6 changes: 5 additions & 1 deletion scheme/step1_read_print.scm
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
(loop))))
(newline))

(main)
(cond-expand
(gerbil
(export main))
(else
(main)))
6 changes: 5 additions & 1 deletion scheme/step2_eval.scm
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@
(loop))))
(newline))

(main)
(cond-expand
(gerbil
(export main))
(else
(main)))
6 changes: 5 additions & 1 deletion scheme/step3_env.scm
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@
(loop))))
(newline))

(main)
(cond-expand
(gerbil
(export main))
(else
(main)))
6 changes: 5 additions & 1 deletion scheme/step4_if_fn_do.scm
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,8 @@
(loop))))
(newline))

(main)
(cond-expand
(gerbil
(export main))
(else
(main)))
6 changes: 5 additions & 1 deletion scheme/step5_tco.scm
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,8 @@
(loop))))
(newline))

(main)
(cond-expand
(gerbil
(export main))
(else
(main)))
16 changes: 12 additions & 4 deletions scheme/step6_file.scm
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
(rep "(def! not (fn* (a) (if a false true)))")
(rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))")

(define (main)
(define (interactive-main)
(let loop ()
(let ((input (readline "user> ")))
(when input
Expand All @@ -122,6 +122,14 @@
(loop))))
(newline))

(if (null? args)
(main)
(rep (string-append "(load-file \"" (car args) "\")")))
(cond-expand
(gerbil
(export main)
(define (main . args)
(if (null? args)
(interactive-main)
(rep (string-append "(load-file \"" (car args) "\")")))))
(else
(if (null? args)
(interactive-main)
(rep (string-append "(load-file \"" (car args) "\")")))))
16 changes: 12 additions & 4 deletions scheme/step7_quote.scm
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
(rep "(def! not (fn* (a) (if a false true)))")
(rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))")

(define (main)
(define (interactive-main)
(let loop ()
(let ((input (readline "user> ")))
(when input
Expand All @@ -150,6 +150,14 @@
(loop))))
(newline))

(if (null? args)
(main)
(rep (string-append "(load-file \"" (car args) "\")")))
(cond-expand
(gerbil
(export main)
(define (main . args)
(if (null? args)
(interactive-main)
(rep (string-append "(load-file \"" (car args) "\")")))))
(else
(if (null? args)
(interactive-main)
(rep (string-append "(load-file \"" (car args) "\")")))))
16 changes: 12 additions & 4 deletions scheme/step8_macros.scm
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
(rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))")


(define (main)
(define (interactive-main)
(let loop ()
(let ((input (readline "user> ")))
(when input
Expand All @@ -191,6 +191,14 @@
(loop))))
(newline))

(if (null? args)
(main)
(rep (string-append "(load-file \"" (car args) "\")")))
(cond-expand
(gerbil
(export main)
(define (main . args)
(if (null? args)
(interactive-main)
(rep (string-append "(load-file \"" (car args) "\")")))))
(else
(if (null? args)
(interactive-main)
(rep (string-append "(load-file \"" (car args) "\")")))))
16 changes: 12 additions & 4 deletions scheme/step9_try.scm
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
(rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))")


(define (main)
(define (interactive-main)
(let loop ()
(let ((input (readline "user> ")))
(when input
Expand All @@ -207,6 +207,14 @@
(loop))))
(newline))

(if (null? args)
(main)
(rep (string-append "(load-file \"" (car args) "\")")))
(cond-expand
(gerbil
(export main)
(define (main . args)
(if (null? args)
(interactive-main)
(rep (string-append "(load-file \"" (car args) "\")")))))
(else
(if (null? args)
(interactive-main)
(rep (string-append "(load-file \"" (car args) "\")")))))
16 changes: 12 additions & 4 deletions scheme/stepA_mal.scm
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
(rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))")
(rep "(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))")

(define (main)
(define (interactive-main)
(rep "(println (str \"Mal [\" *host-language* \"]\"))")
(let loop ()
(let ((input (readline "user> ")))
Expand All @@ -212,6 +212,14 @@
(loop))))
(newline))

(if (null? args)
(main)
(rep (string-append "(load-file \"" (car args) "\")")))
(cond-expand
(gerbil
(export main)
(define (main . args)
(if (null? args)
(interactive-main)
(rep (string-append "(load-file \"" (car args) "\")")))))
(else
(if (null? args)
(interactive-main)
(rep (string-append "(load-file \"" (car args) "\")")))))