Skip to content

Commit 600766f

Browse files
authored
Merge pull request #596 from jscl-project/bootstrap
Bootstrap JSCL
2 parents 80c0cd6 + aae319c commit 600766f

93 files changed

Lines changed: 1975 additions & 1164 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy-preview.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ jobs:
2727
- name: Install SBCL
2828
run: sudo apt-get install sbcl
2929

30-
- name: Build JSCL
30+
# We publish the SBCL-built version until the bootstrap pipeline
31+
# is more mature. Once bootstrap is stable, we can switch to
32+
# ./bootstrap.sh to publish the self-hosted build.
33+
- name: Build JSCL with SBCL
3134
run: ./make.sh
3235

3336
- name: Deploy preview to Netlify

.github/workflows/pull-request.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ jobs:
2626
- name: Install SBCL
2727
run: sudo apt-get install sbcl
2828

29-
- name: Build JSCL
30-
run: ./make.sh
29+
- name: Bootstrap JSCL
30+
run: ./bootstrap.sh
3131

32-
- name: Run tests
33-
run: ./run-tests.sh
32+
- name: Run tests (SBCL)
33+
run: ./run-tests.sh --sbcl
3434

35+
- name: Run tests (Stage 0)
36+
run: ./run-tests.sh --jscl=out/jscl-node.js
37+
38+
- name: Run tests (Stage 1)
39+
run: ./run-tests.sh --jscl=dist/jscl-node.js

.github/workflows/release-latest.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ jobs:
2020
- name: Install SBCL
2121
run: sudo apt-get install sbcl
2222

23-
- name: Build
24-
run: npm run build
23+
# We publish the SBCL-built version until the bootstrap pipeline
24+
# is more mature. Once bootstrap is stable, we can switch to
25+
# ./bootstrap.sh to publish the self-hosted build.
26+
- name: Build JSCL with SBCL
27+
run: ./make.sh
2528
env:
2629
JSCL_RELEASE: true
2730

2831
- name: Run tests
29-
run: npm test
32+
run: ./run-tests.sh
3033

3134
- name: Deploy latest version
3235
uses: JamesIves/github-pages-deploy-action@v4

.github/workflows/release-npm.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ jobs:
2525
- name: Install SBCL
2626
run: sudo apt-get install sbcl
2727

28-
- name: Build
29-
run: npm run build
28+
# We publish the SBCL-built version until the bootstrap pipeline
29+
# is more mature. Once bootstrap is stable, we can switch to
30+
# ./bootstrap.sh to publish the self-hosted build.
31+
- name: Build JSCL with SBCL
32+
run: ./make.sh
3033
env:
3134
JSCL_RELEASE: true
3235

3336
- name: Run tests
34-
run: npm test
37+
run: ./run-tests.sh
3538

3639
- name: Publish to npm
3740
run: npm publish

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*.lib
77
\#*
88
jscl.js
9-
tests.js
109
.tmp/
1110

1211
/repl-node.js
@@ -15,3 +14,6 @@ tests.js
1514
/node_modules/
1615
/.jscl_test/
1716
/dist/
17+
/out/
18+
19+
tests/**/*.lisp.js

HACKING.org

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
** Newbie guide
33
- Load slime from the root directory.
44
- C-c C-l jscl.lisp to load the whole project
5-
- =(jscl:bootstrap)= will generate jscl.js
5+
- =(jscl-xc:bootstrap "out/" "jscl")= will generate out/jscl.js
66
- Add tests
77
- Open tests.html in your browser to see your failed tests
88
** Code organization, style, etc.
@@ -16,7 +16,7 @@
1616
** Hacking the compiler
1717
*** Interactive development
1818
- Load slime and bootstrap JSCL as explained in the newbie guide.
19-
- Work in package JSCL with =(in-package #:jscl)=.
19+
- Work in package JSCL-XC with =(in-package #:jscl-xc)=.
2020
- Use the =compile-toplevel= function to prepare the JavaSript code
2121
associated to a S-expression SEXP, compiled as a toplevel form.
2222
- Use the =process-toplevel= function to prepare the JavaScript
@@ -25,10 +25,10 @@
2525

2626

2727
#+BEGIN_EXAMPLE
28-
JSCL> (process-toplevel '(+ 1 2))
28+
JSCL-XC> (process-toplevel '(+ 1 2))
2929
(PROGN (SELFCALL (PROGN) (RETURN (+ 1 2))))
3030

31-
JSCL> (compile-toplevel '(+ 1 2))
31+
JSCL-XC> (compile-toplevel '(+ 1 2))
3232
"(function(){return 1+2;
3333
})();
3434
"
@@ -49,7 +49,7 @@ the =*js-output*= output channel, which can be set to =t= to target
4949
stdout. For instance
5050

5151
#+BEGIN_EXAMPLE
52-
JSCL> (js '(+ 1 2))
52+
JSCL-XC> (js '(+ 1 2))
5353
1+2;
5454
#+END_EXAMPLE
5555

@@ -58,21 +58,21 @@ calls and =named-function= to distinguish function expressions
5858
featuring a function name.
5959

6060
#+BEGIN_EXAMPLE
61-
JSCL> (js '(call (property |console| "log") "A message."))
61+
JSCL-XC> (js '(call (property |console| "log") "A message."))
6262
console['log']('A message.');
6363

64-
JSCL> (js '(call (get |console| |log|) "A message."))
64+
JSCL-XC> (js '(call (get |console| |log|) "A message."))
6565
console.log('A message.');
6666

67-
JSCL> (js '(call (get |console| "log") "A message."))
67+
JSCL-XC> (js '(call (get |console| "log") "A message."))
6868
console.log('A message.');
6969

7070

71-
JSCL> (js '(function (a b) (return (+ a b))))
71+
JSCL-XC> (js '(function (a b) (return (+ a b))))
7272
(function(A,B){return A+B;
7373
});
7474

75-
JSCL> (js '(named-function "add2" (a b) (return (+ a b))))
75+
JSCL-XC> (js '(named-function "add2" (a b) (return (+ a b))))
7676
(function add2(A,B){return A+B;
7777
});
7878
#+END_EXAMPLE
@@ -102,13 +102,13 @@ generate. Compiler macros should not be mistaken for host Common Lisp
102102
macros.
103103

104104
#+BEGIN_EXAMPLE
105-
JSCL> (define-builtin mod (x y)
105+
JSCL-XC> (define-builtin mod (x y)
106106
`(selfcall
107107
(if (== ,y 0)
108108
(throw "Division by zero in mod"))
109109
(return (% ,x ,y))))
110110

111-
JSCL> (with-compilation-environment (process-toplevel '(mod 7 2)))
111+
JSCL-XC> (with-compilation-environment (process-toplevel '(mod 7 2)))
112112
(PROGN
113113
(SELFCALL
114114
(IF (== 2 0)

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ If you want to hack JSCL, you will have to download the repository
2929

3030
git clone https://github.com/jscl-project/jscl.git
3131

32-
Run `npm install` under the `jscl` directory. Then *load* `jscl.lisp`
33-
in your Lisp, and call the build-all function to compile the
34-
implementation itself:
32+
Run `npm install` under the `jscl` directory, then run the build
33+
script:
3534

36-
(jscl:build-all)
35+
./make.sh
3736

38-
It will generate a `jscl.js` file in the `jscl/dist` directory. Now
39-
you can open `dist/index.html` in your browser and use it. To use in Node,
40-
`node dist/jscl-node.js`; to use in Deno,
41-
`deno --allow-env --allow-read dist/jscl-deno.js`.
37+
It will generate `jscl.js` and the rest of the distribution files in
38+
the `jscl/dist` directory. Now you can open `dist/index.html` in your
39+
browser and use it. To use in Node, `node dist/jscl-node.js`; to use
40+
in Deno, `deno --allow-env --allow-read dist/jscl-deno.js`.
4241

4342

4443
## Status

bootstrap.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
set -e
3+
4+
BASE=$(dirname "$0")
5+
cd "$BASE"
6+
7+
echo "=== Stage 0: SBCL compiles cross-compiler ===" >&2
8+
./make.sh --sbcl -o out/
9+
10+
echo "=== Stage 1: Cross-compiler compiles JSCL ===" >&2
11+
./make.sh --jscl=out/jscl-node.js -o dist/
12+
13+
echo "=== Build complete ===" >&2

deno/build.lisp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
;;; deno/build.lisp — Build the Deno REPL
2+
;;;
3+
;;; This file is loaded by jscl-node.js to compile the Deno REPL.
4+
5+
(defun build-deno-repl (output-directory)
6+
"Build Deno REPL into OUTPUT-DIRECTORY."
7+
(jscl:compile-application (list "deno/repl.lisp")
8+
(concatenate 'string output-directory "jscl-deno.js")))

deno/repl.lisp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,47 @@
1111
;; You should have received a copy of the GNU General Public License
1212
;; along with JSCL. If not, see <http://www.gnu.org/licenses/>.
1313

14-
(/debug "loading deno/repl.lisp!")
14+
(defpackage :jscl/deno-repl (:use :cl :jscl/ffi))
15+
(in-package :jscl/deno-repl)
1516

1617
(defvar *rl*)
1718

1819
(defun start-repl ()
19-
(welcome-message)
20+
(jscl::welcome-message)
2021
(setq *rl* (#j:readline:createInterface #j:process:stdin #j:process:stdout))
2122
(let ((input-buffer (make-string-output-stream))
2223
(linecont-prompt nil))
2324
(flet ((set-prompt ()
24-
(let ((name (package-name-for-prompt *package*)))
25-
((oget *rl* "setPrompt") (jsstring (format nil "~a> " name)))
25+
(let ((prompt (jscl::get-repl-prompt)))
26+
((oget *rl* "setPrompt") (jsstring prompt))
2627
(setq linecont-prompt
27-
(concat (make-string (1+ (length name)) :initial-element #\.) " ")))))
28+
(concatenate 'string (make-string (1- (length prompt)) :initial-element #\.) " ")))))
2829
(set-prompt)
2930
((oget *rl* "prompt"))
3031
((oget *rl* "on") #j"line"
3132
(lambda (line)
3233
(write-line (clstring line) input-buffer)
33-
(let ((input (stream-data input-buffer)))
34-
(if (%sexpr-incomplete input)
34+
(let ((input (jscl::stream-data input-buffer)))
35+
(if (jscl::%sexpr-incomplete input)
3536
((oget *rl* "setPrompt") (jsstring linecont-prompt))
3637
(progn
37-
(with-toplevel-eval ()
38-
(eval-interactive-input input))
39-
(setf (fill-pointer (stream-data input-buffer)) 0)
38+
(jscl::with-toplevel-eval ()
39+
(jscl::eval-interactive-input input))
40+
(setf (fill-pointer (jscl::stream-data input-buffer)) 0)
4041
;; Update prompt
4142
(set-prompt))))
4243
;; Continue
4344
((oget *rl* "prompt")))))))
4445

4546
(defun deno-init ()
4647
(setq *standard-output*
47-
(make-stream
48+
(jscl::make-stream
4849
:write-fn (lambda (string)
4950
(#j:process:stdout:write (jsstring string))))
5051
*error-output* *standard-output*
51-
*trace-output* *standard-output*)
52-
(let ((args (mapcar #'clstring (vector-to-list (subseq #j:process:argv 2)))))
52+
*trace-output* *standard-output*
53+
*package* (find-package "CL-USER"))
54+
(let ((args (mapcar #'clstring (jscl::vector-to-list (subseq #j:process:argv 2)))))
5355
(cond
5456
((null args)
5557
(start-repl))

0 commit comments

Comments
 (0)