Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
Simplify cons and some related functions.
Browse files Browse the repository at this point in the history
This seems to be about a 10% performance improvement:

    Compiling stage1 compiler...
      Time: 76.345 s

    Compiling stage2 compiler...
      Time: 78.045 s

    Compiling stage3 compiler...
      Time: 69.783 s

    Percent change (1 -> 3): -9%
    Percent change (2 -> 3): -11%
  • Loading branch information
eholk committed Jul 6, 2019
1 parent 502b6f9 commit 5c85ce7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions run-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Error.stackTraceLimit = 20;
async function runTest(name, compile = compileWithHostScheme) {
const bytes = fs.readFileSync(name);
const file = await compile(bytes);
fs.writeFileSync('test.wasm', file);

const engine = new Schism.Engine;
const wasm = await engine.loadWasmModule(file);
Expand Down
18 changes: 8 additions & 10 deletions schism/compiler.ss
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@
;; we skip the base air.
(%set-tag (+ allocation 1) tag))))
(define (cons a d)
(init-pair (%alloc ,(pair-tag) 2) a d))
(let ((p (%alloc ,(pair-tag) 2)))
(begin
(%set-car! p a)
(%set-cdr! p d)
p)))
(define (set-car! p a)
(if (pair? p)
(%set-car! p a)
Expand All @@ -143,17 +147,13 @@
(if (pair? p)
(%set-cdr! p d)
(error 'set-cdr! "set-cdr!: not a pair")))
(define (init-pair p a d)
(set-car! p a)
(set-cdr! p d)
p)
(define (car p)
(if (pair? p)
(read-ptr p 0)
(%read-mem (%as-fixnum p) 0)
(error 'car "car: not a pair")))
(define (cdr p)
(if (pair? p)
(read-ptr p ,(word-size))
(%read-mem (%as-fixnum p) ,(word-size))
(error 'cdr "cdr: not a pair")))
(define (caar p) (car (car p)))
(define (cadr p) (car (cdr p)))
Expand Down Expand Up @@ -191,8 +191,6 @@
(list-ref (cdr list) (- n 1))))
(define (append a b)
(if (null? a) b (cons (car a) (append (cdr a) b))))
(define (read-ptr p offset)
(%read-mem (%as-fixnum p) offset))
(define (char->integer c) (%as-fixnum c)) ;; TODO: check tag
(define (integer->char c) (%set-tag c ,(char-tag)))
(define (char-between c c1 c2) ;; inclusive
Expand Down Expand Up @@ -785,7 +783,7 @@
(define (bind-free-vars closure free-vars index)
(if (null? free-vars)
'()
(cons `(,(car free-vars) (call read-ptr (var ,closure) (number ,(* index (word-size)))))
(cons `(,(car free-vars) (%read-mem (%as-fixnum (var ,closure)) (number ,(* index (word-size)))))
(bind-free-vars closure (cdr free-vars) (+ 1 index)))))


Expand Down

0 comments on commit 5c85ce7

Please sign in to comment.