[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [xsmith-dev] Random Function Name Generate Question
On Tue, Apr 14, 2020 at 07:41:34PM +0000, TUO ZHAO wrote:
I'm trying to use XSmith to generate functions with different function names.
From `3.6 Another Small Example With Variables` in the XSmith Doc, I think I need to use:
[Decl #f (name type)]
First impression, your `Decl` node should have some kind of right-hand
side - eg. an expression or something.
There are a few ways you could encode this situation. The basic
approach I would recommend is to say the RHS of a Decl is an
Expression, and then add some kind of Lambda/Function expression to
your language. If your language does not actually have a lambda form,
just restrict it so that it can only be generated as the RHS of a
Decl. Even if your language has special syntax for defining a
function vs some other kind of value (which they generally do), you
could just have your printer check whether the RHS of the definition
is a function or something else, and print accordingly.
But I still don't understand how to `access` this `name`
To be able to get the value of the name field of a node `n`, you can use
`(ast-child 'name n)`.
To set a value when the node is being generated, you could put
something in `fresh`, probably using `fresh-var-name`. But I suggest
you simply allow the automatic lifting mechanism to generate
definitions when needed.
In other words, if you give `Decl` the `binder-info` property from the
example you reference, and then give a `Reference` node the
`reference-info` property, then when a reference is generated, it can
automatically create a valid definition if there isn't already one
there for it to use. Also, to have a place where these auto-generated
definitions can be put, you'll need to give your program node a field
for a list of Decls, eg.
[Program Node ([decls : Decl *] <other-fields> ...)]
An example that would show this more clearly might be Schemely in the
xsmith-examples directory. Look at how Definition, Application, and
Lambda are defined.
Or better yet, you might use the brand-new `add-basic-expressions` and
`add-basic-statements` forms that were just added to the
`xsmith/canned-components` module to get a quick-start for your
language. They are a little under-documented, but they are certainly
the quickest way to get a fuzzer going quickly.
Does that make sense, and is that helpful? Feel free to follow up.