Skip to content
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
3 changes: 3 additions & 0 deletions src/bin/rsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

$(dirname $0)/../rsc.exe $@
2 changes: 1 addition & 1 deletion src/lib/r4rs/sys.scm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
(define-primitive
(##shell-cmd cmd)
(use js/node js/node/fs scm2list list2scm scm2str str2scm)
"prim1(cmd => str2scm(String(require('child_process').execSync(`sh -c '${scm2str(cmd)}'`)))),")
"prim1(cmd => str2scm((()=>{const r=(require('child_process').spawnSync(`${scm2str(cmd)}`,{shell:true}));return r.status!==0 ? `Error: ${String(r.stdout)}` : String(r.stdout);})())),")

(define (list-dir dir-name) (##list-dir dir-name))
(define (current-directory) (##current-directory)))
Expand Down
15 changes: 14 additions & 1 deletion src/lib/resource/http.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@
(##define-resource-reader
http
(lambda (resource-path)
(shell-cmd (string-append "curl --silent http://" resource-path))))
(let ((resource-path-real
(if (string-prefix? "http:/" resource-path)
(string-append "http://" (substring resource-path (string-length "http:/") (string-length resource-path)))
(string-append "http://" resource-path))))
(open-input-string (pipe-through (string-append "curl --silent " resource-path-real) "")))))

(##define-resource-reader
https
(lambda (resource-path)
(let ((resource-path-real
(if (string-prefix? "https:/" resource-path)
(string-append "https://" (substring resource-path (string-length "https:/") (string-length resource-path)))
(string-append "https://" resource-path))))
(open-input-string (pipe-through (string-append "curl --silent " resource-path-real) "")))))
2 changes: 1 addition & 1 deletion src/lib/resource/ipfs.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
(##define-resource-reader
ipfs
(lambda (resource-path)
(shell-cmd (string-append "ipfs cat " resource-path))))
(open-input-string (pipe-through (string-append "ipfs cat " resource-path) ""))))
2 changes: 2 additions & 0 deletions src/lib/resource/macros.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(##include-once (ribbit "define-macro"))

(define-macro
(##define-resource-reader name reader)
(add-resource-str-reader!
Expand Down
35 changes: 25 additions & 10 deletions src/rsc.scm
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,10 @@
(let ((path (string-replace (string-replace path "//" "/") "/./" "/")))
(if (string-prefix? "./" path)
(loop (substring path 2 (string-length path)))
(if (string-prefix? "../" path)
(loop (substring path 3 (string-length path)))
path)))))
path))))
;; (if (string-prefix? "../" path)
;; (loop (substring path 3 (string-length path)))
;; path)

(cond-expand

Expand Down Expand Up @@ -1828,7 +1829,7 @@
mtx)
#f))))

((eqv? first '##include-str)
((eqv? first '##include-string)
(expand-expr (read-str-resource (parse-resource (cadr expr))) mtx))

(else
Expand Down Expand Up @@ -2140,6 +2141,15 @@
((cadr reader) resource-path)
(error "No resource reader found for resource-type:" (resource-type resource)))))

(define (read-char-list input-port)
(let loop ((c (read-char input-port)))
(cond
((eof-object? c) '())
(else (cons c (loop (read-char input-port)))))))

(define (read-str-resource resource)
(list->string (read-char-list (get-resource-port resource))))

(define (expand-resource resource mtx)
(let ((old-current-resource current-resource))
(set! current-resource resource)
Expand Down Expand Up @@ -4040,8 +4050,9 @@
(define (read-library lib-path)
`((##include-once (ribbit ,lib-path))))

(define (read-program lib-path src-path)
(define (read-program lib-path src-path prefix-code)
(append (apply append (map read-library lib-path))
(if (not prefix-code) '() (read-from-file prefix-code))
(if (equal? src-path "-")
(read-all)
(read-from-file src-path))))
Expand Down Expand Up @@ -4729,6 +4740,7 @@

(define target "rvm")
(define (fancy-compiler src-path
prefix-code
output-path
exe-output-path
rvm-path
Expand Down Expand Up @@ -4759,9 +4771,7 @@
(let* ((vm-source
(if (equal? _target "rvm")
#f
(string-from-file
(path-expand rvm-path
(root-dir)))))
(string-from-file rvm-path)))
(host-file
(if (equal? _target "rvm")
#f
Expand Down Expand Up @@ -4798,7 +4808,7 @@
(program-read
(report-status
"Reading program source code"
(read-program lib-path src-path)))
(read-program lib-path src-path prefix-code)))

(program-compiled
(report-status
Expand Down Expand Up @@ -4902,6 +4912,7 @@ The output is written to output.c, with an executable compiled to run-output.exe
(let ((verbosity 0)
(debug-info '())
(target "rvm")
(prefix-code #f)
(input-path #f)
(output-path #f)
(exe-output-path #f)
Expand All @@ -4925,6 +4936,9 @@ The output is written to output.c, with an executable compiled to run-output.exe
((and (pair? rest) (member arg '("-i" "--input")))
(set! input-path (car rest))
(loop (cdr rest)))
((and (pair? rest) (member arg '("--prefix-code")))
(set! prefix-code (car rest))
(loop (cdr rest)))
((and (pair? rest) (member arg '("-o" "--output")))
(set! output-path (car rest))
(loop (cdr rest)))
Expand Down Expand Up @@ -5016,11 +5030,12 @@ The output is written to output.c, with an executable compiled to run-output.exe
(if (not src-path)

(begin
(display "*** a Scheme source file must be specified\n")
(error "*** a Scheme source file must be specified\n")
(exit-program-abnormally))

(fancy-compiler
src-path
prefix-code
(or output-path
(if (or (equal? src-path "-") (equal? target "rvm"))
"-"
Expand Down