simon-git: spigot (master): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Sat Mar 31 16:29:57 BST 2018
TL;DR:
96edf7f Move spigot_identity into unary.cpp.
3c9df5a Distributed registration for operators and functions.
6862c7d Add a system of debug-mode-only functions.
e39374e Make most spigot_foo() functions static.
Repository: https://git.tartarus.org/simon/spigot.git
On the web: https://git.tartarus.org/?p=simon/spigot.git
Branch updated: master
Committer: Simon Tatham <anakin at pobox.com>
Date: 2018-03-31 16:29:57
commit 96edf7f1275012818cd15af605fb7c00b3fb888e
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=96edf7f1275012818cd15af605fb7c00b3fb888e;hp=b3859967233ef43e8f5554f5ebfefdec904f13cb
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Mar 31 15:37:03 2018 +0100
Move spigot_identity into unary.cpp.
Previously it was a trivial helper function that I used inside
trig.cpp as a thing to point a function pointer at. Now I'm about to
need it for a similar purpose in another module, so let's move it to a
more sensible place and declare it in funcs.h.
funcs.h | 1 +
trig.cpp | 5 -----
unary.cpp | 5 +++++
3 files changed, 6 insertions(+), 5 deletions(-)
commit 3c9df5aa71dce53b53695bbfe424acb674ef8996
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=3c9df5aa71dce53b53695bbfe424acb674ef8996;hp=96edf7f1275012818cd15af605fb7c00b3fb888e
Author: Simon Tatham <anakin at pobox.com>
Date: Mon Mar 26 20:15:49 2018 +0100
Distributed registration for operators and functions.
One of the annoying things about adding a new function in spigot is
that I have to plumb it through tediously from its home source file to
the expression system - define it in whatever.cpp, declare it in
funcs.h, add a line in the list macro in expr.cpp.
It would be nicer if I could just write a function in any old source
file and add a marker beside it saying ' ... and also register this in
the expression parsing system as <name>'.
In this commit, I make that happen, by completely removing the old
list macro and all the assorted arrays and enums and helper functions
it generated, and replacing the whole edifice with an entirely new
edifice that is equally hideous and complicated but in a C++ rather
than cpp sort of way.
The basic idea is inspired by LLVM's command-line parsing system. For
each function name and each infix, prefix or suffix operator that I
want expr.cpp's parser to accept, I declare a file-scope C++ object of
a class whose constructor has the side effect of registering it in a
centralised list. All those constructors run before main() begins - or
when the .so is loaded, in the case where all this code is compiled
into a native-code Python module - and so by the time expr.cpp is
actually trying to parse anything, it has a collection of vectors and
maps fully populated with all the expression elements I wanted, and
ready to consult.
(I don't even have to declare those file-scope objects with external
linkage - making them file-scope statics works just fine.)
Of course, this doesn't _completely_ centralise the work of adding a
new function into just the source file where it's defined. There's
still documentation to be added (in three places - the main Halibut
manual, the cut-down summary in the Halibut man _page_, and api.rst
plus docstring in __init__.py for the Python docs), and tests in
test.sh and the Python test suite. All I've done here is to reduce by
a _little_ the number of places to edit. But I think it's an
improvement, even so.
algebraic.cpp | 3 +
consts.cpp | 12 +
erf.cpp | 18 ++
exp.cpp | 30 +++
expint.cpp | 15 ++
expr.cpp | 717 +++++++++++++++++++++++++++++++++++++---------------------
funcs.h | 140 ++++++++++++
gamma.cpp | 7 +
hypergeom.cpp | 8 +
lambertw.cpp | 4 +
sqrt.cpp | 6 +
trig.cpp | 41 ++++
trigint.cpp | 16 ++
unary.cpp | 10 +
zeta.cpp | 2 +
15 files changed, 770 insertions(+), 259 deletions(-)
commit 6862c7db3d1d6fed83e6bfc83f5ff800101a129d
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=6862c7db3d1d6fed83e6bfc83f5ff800101a129d;hp=3c9df5aa71dce53b53695bbfe424acb674ef8996
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Mar 31 14:36:09 2018 +0100
Add a system of debug-mode-only functions.
These functions give me direct access to some of spigot's internal
classes, such as ErfBaseRational or LowerGammaBaseRational, which
compute primitives that the top-level functions such as erf and gamma
are then written in terms of.
The idea is that if I find a bug in a top-level function which I can
trace to a particular instance of one of those classes behaving badly,
then I should be able to pull just that one class instance's
parameters out of the overall computation, with no more effort than
(as it might be) seeing a refinement-check internal fault, checking
the debug messages for the failing class and finding out that it was
an instantiation of FooBaseRational with a particular numerator and
denominator, and then re-running spigot telling it directly to
instantiate that same primitive class on that rational. Then I can
debug it easily, and also add a regression test directly testing _that
class_ with confidence that it will carry on testing the right thing
even if I later rewrite the top-level function so that it handles the
original input value in some totally different way.
The usefulness of these functions to an end user is not great. Also, I
don't really want to have to document all their limitations - most of
them have implicit limits on the acceptable input values, which they
will generally trust their caller not to violate and won't diagnose
them in a nice user-friendly way. So they're not part of the main
expression language as presented by the ordinary spigot command line
or by the Python eval function. Instead, you can only get at them by
using the undocumented --debug-fns option.
(One possible exception is the hypergeometric primitive. So many other
functions are special cases of the generalised hypergeometric function
that it might actually be worth exposing and documenting properly -
but first I'd have to come up with a less awful syntax for it...)
erf.cpp | 6 ++++++
exp.cpp | 4 ++++
expint.cpp | 11 +++++++++++
expr.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++-------
expr.h | 2 ++
funcs.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
gamma.cpp | 23 +++++++++++++++++++++++
hypergeom.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
main.cpp | 2 ++
trig.cpp | 15 +++++++++++++++
trigint.cpp | 9 +++++++++
zeta.cpp | 10 +++++++++-
12 files changed, 225 insertions(+), 8 deletions(-)
commit e39374ec226a4fcae6abd8c246f1858f360c5c29
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=e39374ec226a4fcae6abd8c246f1858f360c5c29;hp=6862c7db3d1d6fed83e6bfc83f5ff800101a129d
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Mar 31 14:44:43 2018 +0100
Make most spigot_foo() functions static.
There's no longer any need to declare every single one of them in
funcs.h, now that exposing a function in the expression language
doesn't require expr.cpp to be able to see its declaration. So I'm
tidying up; now funcs.h lists only the spigot_foo() functions that
functions in other files need to use as subroutines. Anything whose
purpose is _only_ to be made available to the user is now declared
'static', visible only inside its own source file, and exported to
expr.cpp via the new registration-constructor wrapper mechanism.
algebraic.cpp | 2 +-
consts.cpp | 8 +++----
erf.cpp | 12 +++++-----
exp.cpp | 22 ++++++++---------
expint.cpp | 12 +++++-----
funcs.h | 76 -----------------------------------------------------------
gamma.cpp | 4 ++--
hypergeom.cpp | 10 ++++----
lambertw.cpp | 4 ++--
sqrt.cpp | 4 ++--
trig.cpp | 34 +++++++++++++-------------
trigint.cpp | 16 ++++++-------
unary.cpp | 8 +++----
zeta.cpp | 2 +-
14 files changed, 70 insertions(+), 144 deletions(-)
More information about the tartarus-commits
mailing list