[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [xsmith-dev] Examples



Uh oh - sorry for this. I just noticed I installed xsmith from raco pkg which installs the very old 1.0 release and was trying to run the examples from the master branch. All good now...

Maybe it's time for a new minor release?

Paulo Matos

On 24 March 2020 15:50:06 CET, Paulo Matos <pmatos@linki.tools> wrote:
Hi,

I am playing with XSmith to try to create a simple fuzzer for a simple
scheme. Initially I thought I would go for r7rs but I can see it's not
as straightforward as I initially thought.

Of course, with the schemely example things were going to be much quick
but not only I cannot run the schemely example, I get:

$ raco make schemely.rkt
/home/pmatos/dev/xsmith/xsmith-examples/schemely/schemely.rkt:219.0: define-generic-type: expected identifier
at: (type covariant)
in: (define-generic-type list-type ((type covariant)))
compilation context...:
/home/pmatos/dev/xsmith/xsmith-examples/schemely/schemely.rkt
context...:
.../private/runtime-report.rkt:731:0: error/report
.../private/runtime-report.rkt:28:0: call-current-failure-handler
call-in-empty-metacontinuation-frame
apply-transformer
dispatch-transformer
do-local-expand
.../syntax/wrap-modbeg.rkt:46:4
call-in-empty-metacontinuation-frame
apply-transformer
dispatch-transformer
loop
finish
[repeats 37 more times]
pass-1-and-2-loop
module-begin-k
expand-module

My example stands as:
#lang racket/base

(require xsmith
racr
xsmith/racr-convenience
racket/pretty
racket/random
racket/list
racket/class
racket/string
racket/port)

;; XSMITH-based fuzzer for R7RS - following Rattle's
;; support for R7RS

(define-spec-component r7rs-core)

(add-to-grammar
r7rs-core

[_expression_ #f ()
#:prop may-be-generated #f]

[Let _expression_ ([definitions : Definition * = 0 #;(random 3)]
[body : DefinitionContext])
#:prop strict-child-order? #t]

[LiteralBool _expression_ ([v = (even? (random 2))])]
[LiteralNumber _expression_ (v) #:prop may-be-generated #f]
[LiteralInt LiteralNumber ()]

[Not _expression_ ([_expression_])]

[If _expression_ ([test : _expression_] [then : _expression_] [else : _expression_])
#:prop strict-child-order? #t]

)

(add-prop r7rs-core fresh
[LiteralInt (hash 'v (* (random 1000000)
(if (equal? 0 (random 2)) -1 1)))])

;; helper for render-node-info
;(define (->se sym . children-refs)
; (lambda (n)
; `(,sym ,@(map (lambda (x) (render-node (ast-child x n)))
; children-refs))))
;
;(define (->se* sym children-ref)
; (lambda (n)
; `(,sym ,@(map (lambda (x) (render-node x))
; (ast-children (ast-child children-ref n))))))

(add-prop
r7rs-core
render-node-info

[Let (lambda (n) `(let (,@(map (lambda (d) `(,(string->symbol (ast-child 'name d))
,(render-node (ast-child '_expression_ d))))
(ast-children (ast-child 'definitions n))))
,@(render-node (ast-child 'body n))))]

[LiteralBool (lambda (n) (ast-child 'v n))]
[LiteralNumber (lambda (n) (ast-child 'v n))])

;(add-prop
; r7rs-core
; render-hole-info
; [#f (lambda (h) (list 'HOLE (ast-node-type h)))])

;; Types
(define number (base-type 'number))
(define int (base-type 'int number))
(define bool (base-type 'bool))

(define (type-thunks-for-concretization)
(list (lambda () int)
(lambda () bool)))

(add-prop
r7rs-core
type-info

[Let [(fresh-type-variable) (lambda (n t)
(hash 'body t
'definitions (lambda (c) (fresh-type-variable))))]]

[LiteralBool [bool (no-child-types)]]
[LiteralInt [int (no-child-types)]]

[If [(fresh-type-variable)
(lambda (n t)
(hash 'test bool 'then t 'else t))]])

(assemble-spec-components
r7rs
r7rs-core)

(define (r7rs-generate)
(parameterize ([current-xsmith-type-constructor-thunks
(type-thunks-for-concretization)])
(r7rs-generate-ast '_expression_)))

(define (r7rs-format-render forms)
(with-output-to-string
(lambda ()
(define (pp x)
(pretty-print x (current-output-port) 1))
(for ([form forms])
(pp form)))))

(module+ main
(xsmith-command-line
r7rs-generate
#:format-render r7rs-format-render))
but I am getting:
render-node-info: Identifier not defined as a property. in: render-node-info

Can someone provide some hints on how to get this to work? I am not sure
I completely understand why this is happening. `add-prop` is supposed to
add a new property with the name `render-node-info`, so getting that
error is confusing me. Xsmith seems to expect the identifier
`render-node-info` to have been previously marked as a property or
something or the sort.

Kind regards,

Paulo Matos

--
Sent from my Android device with K-9 Mail. Please excuse my brevity.