profile
viewpoint

eholk/harlan 1127

A language for GPU computing.

brson/miri 202

An experimental compiler from Rust to WebAssembly (inactive - do not use)

eholk/Boot2Rust 200

EFI applications in Rust

eholk/elegant-weapons 103

An R6RS framework for creating compilers that target C.

eholk/Arduino-Pong 11

A simple Pong game for the Arduino which uses one of the OLED displays from Adafruit.

eholk/bench-dot-product 10

Several variations of a dot product benchmark.

eholk/llvm 4

Temporary fork of LLVM for Rust

eholk/coq-stlc 2

Proof of type safety for Simply Typed Lambda Calculus in Coq.

eholk/hexlife 2

Conway's Game of Life on a hexagonal grid.

push eventgoogle/schism

Eric Holk

commit sha 032b278044a3c83f0f4102d568991622a1bff97d

Update introduction in README (#93)

view details

Eric Holk

commit sha 7fbb9ce0f663ddef76c36cde27fa3326c080beb7

Merge pull request #100 from eholk/update-readme Update introduction in README (#93)

view details

push time in 2 months

PR merged google/schism

Update introduction in README (#93)

We discussed how to improve the first sentence on #93, but I never made the change. This PR fixes that.

+5 -2

1 comment

1 changed file

eholk

pr closed time in 2 months

push eventgoogle/schism

jitwit

commit sha de4da1571744c796925fe15f7c8af0a90f96a317

add list functions to rnrs.ss

view details

jitwit

commit sha c50decdf8cac2d7144d77e91dd418f47e2159178

add tests for added rnrs functions

view details

Eric Holk

commit sha 7a17c5c0465eb93caad0dff5d5f254ce407679d1

Merge pull request #114 from jitwit/rnrs-list add list functions to rnrs.ss

view details

push time in 2 months

PR merged google/schism

add list functions to rnrs.ss
  • Adds rnrs list functions filter, find, assoc, member, remove, remq, remp, and reverse to rnrs.ss
  • Replaces uses of filter-out with remp
  • Add comment about memp while parsing variable definitions
  • Update readme to reflect added define forms
  • Rewrite quadratic fold-left with append as fold-right in parse-libraries

I'm supposing it'd be best to add tests for the added functions? One test per function or would it be ok to group them together in something like test/rnrs-list-functions.ss?

+318 -21

3 comments

14 changed files

jitwit

pr closed time in 2 months

pull request commentgoogle/schism

add list functions to rnrs.ss

Thanks for adding the tests, and I'm glad they actually caught a bug!

Since the standard library is getting bigger, maybe it's worth scaling up the testing system some too. I opened #115 with some ideas.

jitwit

comment created time in 2 months

issue openedgoogle/schism

Allow multiple tests per test file

We have quite a few tests now and there is a lot of essentially fixed overhead per file we compile, meaning the test suite takes awhile to run. Parallelizing would help somewhat (#51), but we can also improve the tests and test runner to allow more tests in a single file.

They key thing would be to make sure each test in a file could succeed or fail independently.

I'm actually not sure if there are Scheme unit testing frameworks where it would make sense to adopt their API. Another option might be to make the tests write out their results as a TAP stream.

created time in 2 months

pull request commentgoogle/schism

add list functions to rnrs.ss

Thanks for the change! This looks good, but I agree that adding tests would be good.

I think one test per function is better, although that's annoying because it requires a lot of new files. The advantage of one test per function is that it's easier to tell which function broke when the tests start failing.

Maybe we need a way to independently report failures when we want to have multiple tests per file...

jitwit

comment created time in 3 months

push eventgoogle/schism

jitwit

commit sha 056cefe5fb64c835e9cd8c21cfe6efe5ed2851b3

add support for top level variables

view details

jitwit

commit sha 837abbfc0a76969aaf73979b5c0a8c68a820fe66

update snapshot

view details

jitwit

commit sha ea2dcc0cce5ce883b90a2f982df1e0b0ab14dd48

rewrite runtime-imports and intrinsics with variables

view details

Eric Holk

commit sha f6e9f0da762fae9e787f2599b0165264dbad643c

Merge pull request #113 from jitwit/top-level-variables add support for top level variables

view details

push time in 3 months

PR merged google/schism

add support for top level variables

ability to define top level variables

+157 -96

1 comment

4 changed files

jitwit

pr closed time in 3 months

Pull request review commentgoogle/schism

add support for top level variables

            (imports (runtime-imports))            (env (add-intrinsics (intrinsics)                                 (add-imports imports (empty-env))))-           (body-env (add-imported-                      ;; every library implicitly imports itself-                      (cons (cadr lib) library-imports)-                      import-envs-                      env))-           (body-env (add-top-levels-filter-                      ;; Filter out names that are exported, since-                      ;; those have already been included.-                      (lambda (def)-                        (let ((name (definition-name def)))-                          (and name (not (memq name exports)))))-                      defs-                      body-env)))+           (body-env (add-imported library-imports import-envs env))+           (body-env (add-top-levels defs body-env)))       (cons exports

So we end up with the same definition in the environment twice for imports? I think that's okay.

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

add support for top level variables

   (define (parse-body body env)     (unless (pair? body) (error 'parse-body "Empty body"))     (parse-begin (parse-expr (car body) env) (cdr body) env))-  (define (parse-function function env)-    (let* ((name (definition-name function))-           (args (function-formals function))+  ;; help parse definitions+  ;; def = (define (name args ...) body)+  ;;     | (define name body?)+  (define (definition-name def)+    (and (pair? def)+         (eq? (car def) 'define)+         (pair? (cdr def))+         (if (pair? (cadr def))+             (caadr def)+             (cadr def))))+  (define (function-definition? def)+    (and (pair? def)+         (eq? (car def) 'define)+         (pair? (cdr def))+         (or (pair? (cadr def))+             (and (pair? (cddr def))+                  (pair? (caddr def))+                  (eq? 'lambda (caaddr def))))))+  (define (function-formals def)+    (if (pair? (cadr def))+        (cdadr def)+        (let ((def* (caddr def)))+          (unless (eq? (car def*) 'lambda)+            (trace-and-error def 'function-formals "expected lambda at caaddr"))+          (cadr def*))))+  (define (function-body def)+    (if (pair? (cadr def))+        (cddr def)+        (let ((def* (caddr def)))+          (unless (eq? (car def*) 'lambda)+            (trace-and-error def 'function-formals "expected lambda at caaddr"))+          (cddr def*))))+  (define (define-function def env)+    (let* ((name (definition-name def))+           (args (function-formals def))            (args* (map rename-var args))-           (body (parse-body (function-body function)+           (body (parse-body (function-body def)                              (add-lexicals args args* env))))       `(,(cons name args*) ,body)))-  (define (parse-functions definitions env)-    (map (lambda (fn) (parse-function fn env)) definitions))+  (define (define-value def env)+    (let* ((name (definition-name def))+           (env (memp (lambda (n.d) (eq? name (car n.d))) env))

Makes sense. It wouldn't hurt to leave this as a comment in the code.

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

add support for top level variables

             (set-diff (cdr set) sub)             (cons (car set) (set-diff (cdr set) sub))))) -  (define (runtime-imports)+  (define runtime-imports

This is cool to be able to do this as a variable now instead of having to call a function!

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

define variables

   (define (parse-body body env)     (unless (pair? body) (error 'parse-body "Empty body"))     (parse-begin (parse-expr (car body) env) (cdr body) env))-  (define (parse-function function env)-    (let* ((name (definition-name function))-           (args (function-formals function))+  (define (define-function def env)+    (let* ((name (definition-name def))+           (args (function-formals def))            (args* (map rename-var args))-           (body (parse-body (function-body function)+           (body (parse-body (function-body def)                              (add-lexicals args args* env))))       `(,(cons name args*) ,body)))-  (define (parse-functions definitions env)-    (map (lambda (fn) (parse-function fn env)) definitions))+  (define (define-value def env)+    (let ((body (if (null? (cddr def))+                    `(const ,(void))+                    (parse-expr (caddr def) env))))+      `(define ,(definition-name def) ,body)))+  (define (parse-definition def env)+    (if (function-definition? def)+        (define-function def env)+        (define-value def env)))

This is the line where I'd deal with the environment problem for top-level values. Basically, for the call to define-function, we want to pass the whole top level environment. For the call to define-value, we need to pass the environment only up to the current definition. Then any unbound variables in the right hand side expression will trigger errors.

jitwit

comment created time in 3 months

pull request commentgoogle/schism

define variables

I'd probably do the checking in the parsing phase, where we're adding a variable to the environment. It looks like we'll need some way to split the bodies of top-level function from the top-level values, since the environment is different for those two cases. The bodies of top-level functions can see all the top level defines, but the top-level values can only see the defines that have come earlier.

jitwit

comment created time in 3 months

push eventgoogle/schism

jitwit

commit sha f5fc7df606b3a8ee1cbf109f6b8d5c89aa1b5ca6

update snapshot

view details

Eric Holk

commit sha 07da8eaa03dfa7be55c7089a47fd246041f346e0

Merge pull request #111 from jitwit/snapshot update snapshot

view details

push time in 3 months

PR merged google/schism

update snapshot
+0 -0

1 comment

1 changed file

jitwit

pr closed time in 3 months

pull request commentgoogle/schism

update snapshot

Thanks!

jitwit

comment created time in 3 months

pull request commentgoogle/schism

define variables

prints out (y . 12) instead of ("abc" . 12), when x's definition appears before y's.

Ah, so that looks like it's illegal. Just to make sure, I ran it in Chez Scheme and it throws an exception when you try to define x saying that y is not bound. I think we need to be sure to do something similar here.

jitwit

comment created time in 3 months

pull request commentgoogle/schism

parse define

Thanks for the other PR with support for define. I think the top tag works okay.

On Fri, May 15, 2020 at 5:51 PM jitwit notifications@github.com wrote:

I thought a bit more about this today. Before doing constants I realized that defines in inner bodies won't work either. I think what can be done there is:

  • split the body by (0+) definitions and (1+) expressions and add lexicals for the defined names before running parse-body
  • add a clause in parse-expr for definitions to parse them

What I've hit is in simplify-expr, an error for unrecognized expr. It seems like the next step is adding a tag and a way to simplify the definitions? Is this the right approach?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/google/schism/pull/107#issuecomment-629563710, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZ2JVW3ANDDEGUQVBSVKTRRXPQBANCNFSM4M7KAKZA .

jitwit

comment created time in 3 months

pull request commentgoogle/schism

define variables

My feeling is that the top tag shouldn't be necessary, but it seems to keep things simple, so I'd go ahead and keep it.

When the define bodies reference earlier ones, the symbol of the referenced variable is what appears in the result.

For the symbol of the referenced variable, do you mean the global variable index?

Do you have an example of what could go wrong?

If it's something like

(define foo (cons (lambda () (bar 'foo)) '()))

(define bar (lambda (foo) foo))

that shouldn't be a problem, since we have defined all our variables before anyone made a call to bar.

If it's something like

(define a (cons 'a b))

(define b (cons 'b a))

then I'm pretty sure that's not allowed in Scheme.

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

define variables

+;; Copyright 2020 Google LLC+;;+;; Licensed under the Apache License, Version 2.0 (the License);+;; you may not use this file except in compliance with the License.+;; You may obtain a copy of the License at+;;+;;     http://www.apache.org/licenses/LICENSE-2.0+;;+;; Unless required by applicable law or agreed to in writing, software+;; distributed under the License is distributed on an AS IS BASIS,+;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+;; See the License for the specific language governing permissions and+;; limitations under the License.++(library (define-top)+  (export do-test)+  (import (rnrs))++  (define f cons)+  (define y "abc")+  (define x (f y 12))+  ;;  (define w (let ((a 12)) (let* ((z (lambda (y) (f y y)))) (z (cons a a)))))

Does this one work? It looks like it would.

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

define variables

         `(,tag ,(cadr expr) . ,(annotate-free-vars-expr* (cddr expr) bodies)))        ((eq? tag 'apply-procedure)         `(apply-procedure . ,(annotate-free-vars-expr* (cdr expr) bodies)))-       ((or (eq? tag 'var) (eq? tag 'nop) (eq? tag 'i32) (eq? tag 'const))+       ((memq tag '(top var nop i32 const))

Nice cleanup!

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

define variables

            (nglobals 0)            (start #f)            (env (cons cache (cons nglobals (cons start '()))))+           (dfs (filter definition? fns))+           (fns (filter-out definition? fns))+           (dfs (map (lambda (df) (lower-literals-in-variable df env)) dfs))            (fns (map (lambda (fn) (lower-literals-in-function fn env)) fns))            (cache (car env))            (nglobals (cadr env))-           (start (caddr env))+           (start (fold-left (lambda (start def)

Huh, I forgot Schism already had a start function!

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

define variables

            (fns (cdr exports+fns))            (imports (filter wasm-import? fns))            (fns (filter-out wasm-import? fns))-           (fns (simplify-functions fns))+           (fns (simplify-definitions fns))            (fns (convert-closures fns))            (fns+globals+start (lower-literals-in-functions fns))            (fns (car fns+globals+start))+           ;; (dfs (map trace-value (cadr fns+dfs+globals+start)))

Could you remove this line?

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

define variables

   (define (parse-body body env)     (unless (pair? body) (error 'parse-body "Empty body"))     (parse-begin (parse-expr (car body) env) (cdr body) env))-  (define (parse-function function env)-    (let* ((name (definition-name function))-           (args (function-formals function))-           (args* (map rename-var args))-           (body (parse-body (function-body function)-                             (add-lexicals args args* env))))-      `(,(cons name args*) ,body)))-  (define (parse-functions definitions env)-    (map (lambda (fn) (parse-function fn env)) definitions))+  (define (parse-definition def env)+    (let ((name (definition-name def)))+      (if (function-definition? def)+          (let* ((args (function-formals def))+                (args* (map rename-var args))+                (body (parse-body (function-body def)+                                  (add-lexicals args args* env))))+            `(,(cons name args*) ,body))+          `(define ,name ,(parse-expr (caddr def) env)))))

To make it a little clearer which kind of define we're using, I'd consider parsing these into define-function and define-value. It's up to you though.

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

define variables

         `(lambda ,(cadr expr) ,(simplify-expr (caddr expr))))        (else         (trace-and-error expr 'simplify-expr "unrecognized expr")))))-  (define (simplify-function fn)-    `(,(car fn) ,(simplify-expr (cadr fn))))-  (define (simplify-functions functions)-    (map simplify-function functions))+  (define (simplify-definition def)+    (let ((tag (car def)))+      (if (eq? tag 'define)+          `(define ,(cadr def) ,(simplify-expr (caddr def)))+          `(,(car def) ,(simplify-expr (cadr def))))))

Can you use tag here instead of (car def)?

jitwit

comment created time in 3 months

push eventgoogle/schism

jitwit

commit sha 67494ecad4f532a5889c1c5354bc28ca0aae2853

remove list-all-eq? & add test for equal?

view details

jitwit

commit sha e1e1a71530d974498cbfecc1512403370b5c1fbe

do todo. move memq to rnrs

view details

jitwit

commit sha e4ce98958d76e5e1d3485fa3db7b9385b61a8aea

equal test file

view details

Eric Holk

commit sha 98d142b64fcc12b85034dfbe261e5cfd400fa164

Merge pull request #108 from jitwit/equal Equal

view details

push time in 3 months

PR merged google/schism

Equal

Remove list-all-eq?, add test for equal?, move memq to rnrs.ss

Figured I would do this in the meantime of figuring out how to do the define forms. Two questions:

The equal? doesn't handle cyclic structures or procedures properly, would you want this before merging? It seems hard to do the cyclic structure check efficiently without hashtables.

Would you want other functions that are in rnrs.ss like filter to also move to the library?

+93 -33

0 comment

9 changed files

jitwit

pr closed time in 3 months

Pull request review commentgoogle/schism

Equal

   (define (cadadr p) (car (cdadr p)))   (define (cadddr p) (car (cdddr p)))   (define (cdaddr p) (cdr (caddr p)))+  (define (memq x ls)

It'd be good to go ahead and remove this from compiler.ss, but that'll need a new snapshot first. Probably good for a follow up PR.

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

Equal

+;; Copyright 2020 Google LLC+;;+;; Licensed under the Apache License, Version 2.0 (the License);+;; you may not use this file except in compliance with the License.+;; You may obtain a copy of the License at+;;+;;     http://www.apache.org/licenses/LICENSE-2.0+;;+;; Unless required by applicable law or agreed to in writing, software+;; distributed under the License is distributed on an AS IS BASIS,+;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+;; See the License for the specific language governing permissions and+;; limitations under the License.++(library (equal)+  (export do-test)+  (import (rnrs) (rnrs mutable-pairs))++  (define (do-test)+    (and+     ;; from r6rs 11.5+     (equal? 'a 'a)+     (equal? '(a) '(a))+     (equal? '(a (b) c)+             '(a (b) c))+     (equal? "abc" "abc")+     (equal? 2 2)+     (let* ((x '(a))+            (y '(a))+            (z `(,x ,y)))+       (and (equal? z `(,y ,x))+            (equal? z `(,x ,x))))+     ;; from https://scheme.com/tspl4/objects.html#./objects:h2+     (not (equal? 'a 3))+     (not (equal? #t 't))+     (not (equal? "abc" 'abc))+     (not (equal? "hi" '(hi)))+     (let ((x (* 123456789 2)))+       (equal? x x))+     (equal? #t #t)+     (equal? #f #f)+     (not (equal? #t #f))+     (equal? (null? '()) #t)+     (equal? (null? '(a)) #f)+     (equal? (cdr '(a)) '())+     (equal? 'a 'a)+     (not (equal? 'a 'b))+     (equal? 'a (string->symbol "a"))+     (not (equal? '(a) '(b)))+     (equal? '(a) '(a))+     (let ((x '(a . b))) (equal? x x))+     (let ((x (cons 'a 'b))) (equal? x x))+     (equal? (cons 'a 'b) (cons 'a 'b))+     (equal? (string->list "abc") (string->list "abc"))+     (not (equal? "abc" "cba"))+     (equal? "abc" "abc")+     (let ((x "hi")) (equal? x x))+     ;; vector/(string ...)/set!/generic numbers left out for time being+     ;; (equal? car car)+     ;; (not (equal? car cdr))+     ;; fixme - infinite loop:+     ;; (equal?+     ;;  (let ((x (cons 'x 'x)))+     ;;    (set-car! x x)+     ;;    (set-cdr! x x)+     ;;    x)+     ;;  (let ((x (cons 'x 'x)))+     ;;    (set-car! x x)+     ;;    (set-cdr! x x)+     ;;    (cons x x)))

Thanks for adding test cases we don't support yet!

jitwit

comment created time in 3 months

Pull request review commentgoogle/schism

Equal

         ;; calling error here can lead to an infinite loop, so we         ;; generate an unreachable instead.         (%unreachable)))+  ;; doesn't handle procedure or cyclic structure equivalence

I opened #110 for adding support for cyclic structures. For completeness, it's probably good to go ahead and support that, even if it's a bit slow without hash tables.

jitwit

comment created time in 3 months

issue openedgoogle/schism

equal? should handle cyclic structures

We can get an infinite loop (or more likely, a stack overflow) if we call equal? on cyclic data structures. Fortunately, these structures don't occur often, if at all, in the programs we've written in Schism so far.

This would be more efficient with a hash table, but we can make due for now with searching through a list.

created time in 3 months

pull request commentgoogle/schism

parse define

Oh, good point, there might be some trickiness around making sure each initializer runs in the right environment, to make sure they don't refer to things that aren't defined yet.

I forgot that Schism already supports the global.get and global.set instructions. It looks like we use them for interning constants. That's related to top-level defines, so looking at the way we do interning already might be helpful.

jitwit

comment created time in 3 months

push eventgoogle/schism

jitwit

commit sha 550edba615f4b54bdb8844a8c8681d59894762e0

allow (define f (lambda (as ...) b))

view details

jitwit

commit sha 5d80568db8a2a7d8ba55f6b3bae571373effa8c0

add test

view details

jitwit

commit sha 44d05390cc6132fcc2266f485c363b79d02d2031

add checks for lambda

view details

Eric Holk

commit sha 15042251d65659f84686420a46a43baf09d8637b

Merge pull request #107 from jitwit/define parse define

view details

push time in 3 months

PR merged google/schism

parse define

Adds parsing for functions defined like (define f (lambda (x ...) b)).

I wanted to add non-function definitions, too, but wasn't successful. I'm guessing they should be added to the export environment with add-top-level. I got things like (define a 0) to work but not (define b (cons a a)). How might I get them to work?

+80 -26

1 comment

2 changed files

jitwit

pr closed time in 3 months

Pull request review commentgoogle/schism

parse define

         (trace-and-error name 'lookup "unbound identifier"))       ((cdr pair)))) +  ;; parse+  ;; def == (define (name args ...) body)+  ;;      | (define name body)+  ;; or return false+  (define (definition-name def)+    (and (pair? def)+         (eq? (car def) 'define)+         (pair? (cdr def))+         (if (pair? (cadr def))+             (caadr def)+             (cadr def))))+  (define (function-definition? def)+    (and (pair? def)+         (eq? (car def) 'define)+         (pair? (cdr def))+         (or (pair? (cadr def))+             (and (pair? (cddr def))+                  (pair? (caddr def))+                  (eq? 'lambda (caaddr def))))))+  (define (function-formals def)+    (if (pair? (cadr def))+        (cdadr def)+        (car (cdaddr def))))

Looks good!

jitwit

comment created time in 3 months

more