Batch compilation

9 views
Skip to first unread message

Albert Graef

unread,
Apr 8, 2018, 7:43:39 PM4/8/18
to pure...@googlegroups.com
Hi everybody,

I'm currently reviewing the way Pure does batch compilation (cf. https://agraef.github.io/pure-docs/pure.html#batch-compilation). Right now the batch compiler (`pure -c`) just executes the script, evaluating toplevel expressions and global variable definitions as usual, in order to support partial evaluation of a script at compile time (https://en.wikipedia.org/wiki/Partial_evaluation).

But that's simply too broad. E.g., if you compile a "Hello, world" script, it will print "Hello, world" also during batch compilation, which is not what you'd expect. There's the `compiling` variable to deal with this, but it's confusing and error-prone. It's really a kludge to tell the compiler something that it should handle on its own.

In order to make partial evaluation work, the only situation where code actually needs to be executed (rather than just generated) during batch compilation, are `const` definitions. So my plan is to confine execution during batch compilation to these, and get rid of the `compiling` variable. Of course, this implies that `const` definitions should only depend on other `const` values and can't be allowed to use values of `let`-bound global variables any more, but that seems like a good idea anyway.

This should make writing batch-compiled scripts much more straightforward, and it shouldn't limit the possibilities for partial evaluation. But of course it may well break some existing scripts.

Is anyone currently using the `compiling` variable at all? If not then I'll just go ahead and implement this, and fix up the affected scripts in the repository. Otherwise it would be interesting to see use cases which might become difficult with the changes sketched out above.

Albert

--
Dr. Albert Gr"af
Computer Music Research Group, JGU Mainz, Germany
Email:  agg...@gmail.com
WWW:    https://plus.google.com/+AlbertGraef

Eddie Rucker

unread,
Apr 9, 2018, 8:34:13 AM4/9/18
to pure...@googlegroups.com
I welcome the change. I only use the compiling variable to create executables after building a working script anyway. I comment out the "if compiling" lines during maintenance and bug fixes and then uncomment them again to make an executable to put out on the server.

Eddie Rucker

Director of Institutional Research
Blue Mountain College

________________________________________
From: pure...@googlegroups.com <pure...@googlegroups.com> on behalf of Albert Graef <agg...@gmail.com>
Sent: Sunday, April 8, 2018 6:43:38 PM
To: pure...@googlegroups.com
Subject: [pure-lang] Batch compilation
Email: agg...@gmail.com<mailto:agg...@gmail.com>
WWW: https://plus.google.com/+AlbertGraef

--
You received this message because you are subscribed to the Google Groups "pure-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pure-lang+...@googlegroups.com<mailto:pure-lang+...@googlegroups.com>.
To post to this group, send email to pure...@googlegroups.com<mailto:pure...@googlegroups.com>.
Visit this group at https://groups.google.com/group/pure-lang.
For more options, visit https://groups.google.com/d/optout.

Albert Graef

unread,
Apr 10, 2018, 4:29:37 PM4/10/18
to pure...@googlegroups.com
Hi Eddie,

thanks for your feedback! For better backward compatibility, I ended up just disabling toplevel expression execution during batch compilation for now. This already goes a long way, and most existing scripts should continue to work. The compiling variable is still supported, though you won't need it any more and the compiler warns about its uses with -w. All the gory details can be found in the docs (I gave the Batch Compilation section an overhaul), see https://agraef.github.io/pure-docs/pure.html#batch-compilation

If anyone wants to review my changes, you can find them here: https://github.com/agraef/pure-lang/pull/24

The AUR git packages will be updated in due course.

Albert

On Mon, Apr 9, 2018 at 2:34 PM, Eddie Rucker <eru...@bmc.edu> wrote:
I welcome the change. I only use the compiling variable to create executables after building a working script anyway. I comment out the "if compiling" lines during maintenance and bug fixes and then uncomment them again to make an executable to put out on the server.

Eddie Rucker

Director of Institutional Research
Blue Mountain College

________________________________________
From: pure...@googlegroups.com <pure...@googlegroups.com> on behalf of Albert Graef <agg...@gmail.com>
Sent: Sunday, April 8, 2018 6:43:38 PM
To: pure...@googlegroups.com
Subject: [pure-lang] Batch compilation

Hi everybody,

I'm currently reviewing the way Pure does batch compilation (cf. https://agraef.github.io/pure-docs/pure.html#batch-compilation). Right now the batch compiler (`pure -c`) just executes the script, evaluating toplevel expressions and global variable definitions as usual, in order to support partial evaluation of a script at compile time (https://en.wikipedia.org/wiki/Partial_evaluation).

But that's simply too broad. E.g., if you compile a "Hello, world" script, it will print "Hello, world" also during batch compilation, which is not what you'd expect. There's the `compiling` variable to deal with this, but it's confusing and error-prone. It's really a kludge to tell the compiler something that it should handle on its own.

In order to make partial evaluation work, the only situation where code actually needs to be executed (rather than just generated) during batch compilation, are `const` definitions. So my plan is to confine execution during batch compilation to these, and get rid of the `compiling` variable. Of course, this implies that `const` definitions should only depend on other `const` values and can't be allowed to use values of `let`-bound global variables any more, but that seems like a good idea anyway.

This should make writing batch-compiled scripts much more straightforward, and it shouldn't limit the possibilities for partial evaluation. But of course it may well break some existing scripts.

Is anyone currently using the `compiling` variable at all? If not then I'll just go ahead and implement this, and fix up the affected scripts in the repository. Otherwise it would be interesting to see use cases which might become difficult with the changes sketched out above.

Albert

--
Dr. Albert Gr"af
Computer Music Research Group, JGU Mainz, Germany

WWW:    https://plus.google.com/+AlbertGraef

--
You received this message because you are subscribed to the Google Groups "pure-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pure-lang+unsubscribe@googlegroups.com<mailto:pure-lang+unsubscribe@googlegroups.com>.
To post to this group, send email to pure...@googlegroups.com<mailto:pure-lang@googlegroups.com>.
--
You received this message because you are subscribed to the Google Groups "pure-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pure-lang+unsubscribe@googlegroups.com.
To post to this group, send email to pure...@googlegroups.com.



--
Dr. Albert Gr"af
Computer Music Research Group, JGU Mainz, Germany
Email:  agg...@gmail.com
Reply all
Reply to author
Forward
0 new messages