#cs (module minijava-explore mzscheme (require (lib "generator.ss" "reduction-semantics") (lib "helper.ss" "reduction-semantics") (lib "list.ss") "minijava.ss" "minijava-run.ss" "minijava-check.ss") ;; This module attempts to test the MiniJava by generating all ;; possible MiniJava programs, type-checking them, and then running ;; those with a type to make sure they don't get stuck. ;; In practice, this exploration is not particularly useful. ;; Interesting programs are too large, so that they live in an ;; enourmous space or boring programs. I've only run it on the first ;; 3 million programs or so, which takes a few hours. ;; 30 is huge! (define explore-limit 30) (define gens (lang->generator-table minijava-grammar '(1) '(x) null '(- * sub1 pickyfish otherfish dietfish eat grow color) 5)) (define dots 0) (define tried 0) (define skipped 0) (let loop ([n 0]) (unless (n . > . explore-limit) (for-each-generated/size (lambda (revP size) (set! tried (add1 tried)) (let* ([P (append (cdr revP) (list (car revP)))] [type (:-p P)]) (if type (begin (when (positive? dots) (newline)) (set! dots 0) (printf ">> ~s : ~s~n" P type) (let ([r (function-reduce* (:->mj P) (list (car (last-pair P)) null) (lambda (x) (result? (car x))) 10)]) (let ([last (last-pair r)]) (cond [(result? (caar last)) (printf " :->* ~e~n" (car last))] [(not (eq? last (member (car last) r))) (printf " :->* LOOPS~n")] [else (printf " :->* ~e STUCK !!~n" (car last))])))) (begin (set! skipped (add1 skipped)) (when (= skipped 10000) (when (positive? dots) (newline)) (printf "Still searching at size ~a: ~e~n" size P) (set! dots 0) (set! skipped 0)) (when (= dots 60) (printf "~a~n" tried) (set! dots 0)) (display ".") (set! dots (add1 dots)))))) gens n n 'revP) (loop (add1 n)))) (when (positive? dots) (newline)))