chiark / gitweb /
sod
7 years agodebian/libsod-dev.install: Fix name of manpage.
Mark Wooding [Sun, 29 May 2016 15:32:47 +0000 (16:32 +0100)]
debian/libsod-dev.install: Fix name of manpage.

7 years agotest/Makefile.am: Distribute the test program source.
Mark Wooding [Sun, 29 May 2016 15:30:23 +0000 (16:30 +0100)]
test/Makefile.am: Distribute the test program source.

7 years agoMerge branches 'mdw/kwargs' and 'mdw/c11'
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
Merge branches 'mdw/kwargs' and 'mdw/c11'

* mdw/kwargs: (29 commits)
  New feature: initialization keyword arguments.
  src/method-{proto,impl}.lisp: New `method-keyword-argument-lists' protocol.
  New feature: proper object lifecycle protocol; init and teardown fragments.
  src/builtin.lisp: Bind `me' around slot initializers, and define the order.
  Replace the `init' class-slot function with an `init' message.
  Compatibility: the `init' function no longer calls `imprint' for you.
  src/method-{proto,impl}.lisp: Introduce `effective-method-live-p' protocol.
  doc/runtime.tex, lib/sod.3: Restructure the runtime library reference.
  doc/concepts.tex: Reorganize the instance lifecycle material.
  doc/: Miscellaneous clarifications and rewordings.
  doc/concepts.tex: Don't highlight `primary' as literal, because it's not.
  src/: Abolish the distinction between different kinds of initializers.
  src/method-{proto,impl}.lisp: Abolish `sod-message-no-varargs-tail'.
  New feature: messages with keyword arguments!
  lib/: Pure C machinery for handling `keyword arguments' to functions.
  doc/runtime.tex: Demote the object-system support stuff to a section.
  src/c-types-*.lisp: New type for functions which take keyword arguments.
  src/c-types-parse.lisp (parse-declarator): Refactor argument list parsing.
  src/c-types-parse.lisp (parse-declarator): Explain how it works.
  src/: New function `reify-variable-argument-tail'.
  ...

* mdw/c11:
  src/c-types-impl.lisp, src/c-types-parse.lisp: Support C11 `_Alignas'.
  src/c-types-{proto,impl,parse}.lisp: Add `storage specifiers' to the model.
  src/c-types-{impl,parse}.lisp: Support C11 `_Atomic'.
  src/c-types-{impl,parse}.tex: Support `_Atomic' types.
  src/c-types-parse.lisp: Introduce a pluggable parser for declspecs.
  src/c-types-parse.lisp: Hoist up the `ds-FOO' methods for raw types.
  src/c-types-parse.lisp: Improve handling of compatibility keywords.
  src/final.lisp: Add function for interactively testing type parsing.
  src/c-types-proto.lisp, src/c-types-impl.lisp: Qualifier name protocol.
  src/module-parse.lisp (parse-raw-class-item): Commit after declarator.
  Add a new class slot `align', holding the instance layout alignment.
  src/c-types-impl.lisp (make-or-intern-c-type): Pull out useful function.
  src/c-types-parse.lisp, src/c-types-proto.lisp: Some minor cleanups.
  src/parser/parser-proto.lisp: Add functions returning standard parsers.
  src/parser/: Allow parsers to commit to a parse while peeking.
  doc/clang.tex: Improve documentation of C type spec expansion.

Conflicts:
doc/SYMBOLS (regenerated)
doc/syntax.tex (hand-merge; extra parameter to <declarator>)
lib/sod.h (simple hand-merge)
src/sod-module.5 (extra parameter to <declarator>, added by hand)

7 years agosrc/c-types-impl.lisp, src/c-types-parse.lisp: Support C11 `_Alignas'.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/c-types-impl.lisp, src/c-types-parse.lisp: Support C11 `_Alignas'.

7 years agosrc/c-types-{proto,impl,parse}.lisp: Add `storage specifiers' to the model.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/c-types-{proto,impl,parse}.lisp: Add `storage specifiers' to the model.

A slightly unusual kind of thing.  This is intended to capture things
like storage classes and similar which are determinedly `top level',
unlike qualifiers which stay attached to the base type in the presence
of declarator operators.

Storage specifiers are attached to a special carrier type
`c-storage-specifiers-type' (with all of the necessary trimmings), and
there is new machinery (`wrap-c-type') to arrange that this stays at the
outermost level when deriving new types from existing ones.

There is a pile of additional protocol, mostly mirroring the main types
protocol, for dealing with storage-specifier syntax, in both Lisp and C.

7 years agosrc/c-types-{impl,parse}.lisp: Support C11 `_Atomic'.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/c-types-{impl,parse}.lisp: Support C11 `_Atomic'.

This change adds support for both the `_Atomic' type qualifier and the
`_Atomic(...)' type specifier.

7 years agoNew feature: initialization keyword arguments.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
New feature: initialization keyword arguments.

Initialization keyword arguments can now be declared in class
definitions.  They become additional keyword arguments accepted by the
object's `init' effective method.  The initialization arguments are
available for use (by name) within slot initializer expressions and
initialization fragments.

  * `User' initargs are otherwise passive.  They may usefully have a
    default value, which is used if the argument is
    omitted.  (Alternatively, user code can test the `suppliedp' flag
    and behave accordingly.)

  * `Slot' initargs are associated with an effective slot.  If one of a
    slot's initargs is provided in the `init' message, then its value is
    used to initialize the slot, instead of the slot initializer.  If
    more than one applicable initarg is provided, then priority is given
    to the initargs defined in more specific superclasses; if this
    doesn't disambiguate, then one of the initargs is chosen
    arbitrarily (this situation is likely an error).

7 years agosrc/method-{proto,impl}.lisp: New `method-keyword-argument-lists' protocol.
Mark Wooding [Tue, 5 Jan 2016 22:43:47 +0000 (22:43 +0000)]
src/method-{proto,impl}.lisp: New `method-keyword-argument-lists' protocol.

In case method classes want to introduce keyword arguments from
somewhere other than the obvious direct methods, there's now a separate
bit of protocol for determining the lists of keyword arguments which
need to be merged together.

7 years agoNew feature: proper object lifecycle protocol; init and teardown fragments.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
New feature: proper object lifecycle protocol; init and teardown fragments.

A class definition may contain fragments of C code for initialization
and teardown.  Initialization fragments are invoked from the default
`init' message behaviour, in least-to-most specific order, immediately
after initializing the corresponding class's direct slots (if any);
teardown fragments are included in the default behaviour of a new
`teardown' message, in most-to-least specific order.

Now that we have initialization and teardown, we can implement more
useful object lifecycle functionality around them, e.g., dealing with
dynamically allocated objects.  Appropriate new definitions have been
added to the library.

7 years agosrc/builtin.lisp: Bind `me' around slot initializers, and define the order.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
src/builtin.lisp: Bind `me' around slot initializers, and define the order.

Previously, the `init' method kernel (and the `init' class-slot function
before that) initialized one chain at a time, then down the chains,
because this made for a convenient traversal of the class layout.  But
it sucks for users.

Make this better.  Bind `me' around slot initializers -- to the type of
the direct slot.  This means that initializers can compute their values
based on other previously initialized slots, which is useful because
subclasses can override initializers for their superclasses.

The `me' pointer has the type of the class owning the direct slots being
initialized, which means that referring to substructure belonging to
classes other than the superclasses of the slot owner is hard, even if
the initializer can be sure (because it was defined on some subclass)
that those other classes are available.  This is nonetheless the right
thing because (a) it means that the `me' pointer has a reliable type,
and (b) the slots belonging any other classes which might be of interest
won't have been initialized by this point.

Take the opportunity to clarify the documentation regarding slot
initialization generally.

7 years agoReplace the `init' class-slot function with an `init' message.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
Replace the `init' class-slot function with an `init' message.

The `SodObject' class now defines an `init' message.  This message takes
keywords, which can be collected by methods and used to set up objects
in interesting ways.

The `init' message's default behaviour (unless overridden by a primary
or around method) is to initialize the instance's slots using the most
specific applicable initializers, just as the old `init' function used
to do.

Obviously, one can send an `init' message to an instance before it's
been imprinted, so that has to be done as a separate step now.  The
`SOD_DECL' macro has been adjusted to cope.  It also takes an additional
argument containing keyword arguments to be passed with the `init'
message (which constitutes an additional compatibility break).

The library has grown a new pair of functions `sod_init' and `sod_initv'
which wrap up the initialization protocol, and a macro `SOD_INIT' which
improves type safety a little.

(Some of the new code in `src/builtin.lisp' is a little odd.  This is
intended to accommodate future changes better.)

7 years agoCompatibility: the `init' function no longer calls `imprint' for you.
Mark Wooding [Sat, 7 May 2016 13:45:18 +0000 (14:45 +0100)]
Compatibility: the `init' function no longer calls `imprint' for you.

It will make much less sense later.

7 years agosrc/method-{proto,impl}.lisp: Introduce `effective-method-live-p' protocol.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
src/method-{proto,impl}.lisp: Introduce `effective-method-live-p' protocol.

Previously, the `compute-method-entry-functions' method defined on
`simple-effective-method' would bail out early if there were no primary
methods.  This is unsatisfactory: subclasses of `simple-effective-
method' might want to introduce more complicated method combination
machinery.

Make this a proper part of the protocol: introduce `effective-method-
live-p', which gets to decide whether to make method-entry functions or
just leave the vtable pointers null.  Now `simple-effective-method' can
decide, in the same way, to suppress the method entries based on the
existence of primary methods, but subclasses can apply more (or less)
subtle policy.

7 years agodoc/runtime.tex, lib/sod.3: Restructure the runtime library reference.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
doc/runtime.tex, lib/sod.3: Restructure the runtime library reference.

Reorder the descriptions of the various macros and functions along more
useful thematic lines.  Some of the sections are currently a bit thin
but they'll fill out later.

Mostly this is just moving text about, but some edits have been made.
Most significantly, `SOD_CONVERT' and `sod_convert' are now discussed
together rather than separately.

7 years agodoc/concepts.tex: Reorganize the instance lifecycle material.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
doc/concepts.tex: Reorganize the instance lifecycle material.

Promote it to its own section and overhaul the text ready for further
improvements.

7 years agodoc/: Miscellaneous clarifications and rewordings.
Mark Wooding [Sat, 7 May 2016 14:32:51 +0000 (15:32 +0100)]
doc/: Miscellaneous clarifications and rewordings.

7 years agodoc/concepts.tex: Don't highlight `primary' as literal, because it's not.
Mark Wooding [Sat, 7 May 2016 09:56:54 +0000 (10:56 +0100)]
doc/concepts.tex: Don't highlight `primary' as literal, because it's not.

7 years agosrc/: Abolish the distinction between different kinds of initializers.
Mark Wooding [Tue, 5 Jan 2016 19:18:55 +0000 (19:18 +0000)]
src/: Abolish the distinction between different kinds of initializers.

It made parsing difficult, both because the kind and value needed to be
carted about together, and just technically because of `scan-c-fragment'
interacts badly with token-level lookahead.

Against that, the formatting benefits are very slim, and more so when
one considers that there are ugly `#line' markers around the value
fragment.

So, the distinction is gone; there are no more `value-kind' slots or
arguments; and the `value-form' is now just plain `value'.

This is a fairly straightforward change (except for the radical
simplification of the `parse-initializer' function, which hardly needs
to exist any more), but somewhat far-reaching.

7 years agosrc/method-{proto,impl}.lisp: Abolish `sod-message-no-varargs-tail'.
Mark Wooding [Wed, 16 Dec 2015 10:43:47 +0000 (10:43 +0000)]
src/method-{proto,impl}.lisp: Abolish `sod-message-no-varargs-tail'.

This was promised earlier.  All but one of the callers of this method
were lost during the introduction of keyword-argument messages, and it
doesn't seem worth keeping this corner of the method protocol just for
that.

7 years agoNew feature: messages with keyword arguments!
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
New feature: messages with keyword arguments!

Let's start with the new functionality.

You can define messages which are meant to be given keyword arguments,
and methods which retrieve and (presumably) act on those keywords.  The
behaviour is as in Common Lisp: the acceptable keywords for a message
sent to an object are precisely those keywords acceptable to any
applicable method, and those listed in the message definition itself.

The Sod translator takes care of picking keyword argument lists apart
and passing actual arguments to the direct methods; arguments can have
default values (and each direct method can have different defaults),
and/or find out whether a keyword was actually provided.  The only picky
rule is that if two methods (or a method and the message itself) each
define an argument with the same keyword, then those arguments must also
have the same type.

The new code -- and there's quite a lot of it -- mostly concerns itself
with coping with messages and methods which accept keyword arguments,
and generating the proper functions and instructions for gathering them
and passing them about.  This is rather annoying and fiddly.

In particular, it seems as if I ought to be able to have factored the
existing machinery much better than I actually did if only I were more
clever, so that this new stuff could slot in neatly; instead, it looks
as if I just turned the program upside-down and shook hard, which is
pretty accurate really.

7 years agolib/: Pure C machinery for handling `keyword arguments' to functions.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
lib/: Pure C machinery for handling `keyword arguments' to functions.

The new `keyword.h' header file defines a bunch of (somewhat nasty)
macros which allow one to define, parse, pass, and access things which
look a bit like Common Lisp's keyword arguments.  There are a few
support functions, mostly for reporting errors.

7 years agodoc/runtime.tex: Demote the object-system support stuff to a section.
Mark Wooding [Sat, 2 Jan 2016 15:29:23 +0000 (15:29 +0000)]
doc/runtime.tex: Demote the object-system support stuff to a section.

There will be more sections later.

7 years agosrc/c-types-*.lisp: New type for functions which take keyword arguments.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
src/c-types-*.lisp: New type for functions which take keyword arguments.

This commit introduces a new `c-keyword-function-type', including
printing and parsing the things, and some utilities for working with
keyword argument lists (most notably merging them while providing useful
diagnostics about type mismatches).  This involves enhancing the
`argument' type to include an optional default value.

The surface syntax uses a `?' to separate the preceding mandatory
positional arguments from the following optional keyword arguments.  I'm
not completely thrilled by this choice, but I can't see many better
options.  The corresponding use of a `:keys' marker in the S-expression
syntax is also somewhat ugly (especially the way that `make-function-
type' acts on it), but better choices seemed thin on the ground.

An earlier experiment introduced a `keyword-argument' subclass, rather
than enhancing the existing `argument' structure, but it made many
things (e.g., commentifying argument lists) unnecessarily painful for
little benefit -- especially when I realised that it's important to
distinguish an ordinary function from one which notionally accepts
keyword arguments but doesn't actually define any (yet).

7 years agosrc/c-types-parse.lisp (parse-declarator): Refactor argument list parsing.
Mark Wooding [Wed, 16 Dec 2015 05:57:20 +0000 (05:57 +0000)]
src/c-types-parse.lisp (parse-declarator): Refactor argument list parsing.

The `argument-list' parser is now less monolithic: the work of parsing
individual arguments is given to new functions `arg-decl' and
`argument'.

Also, the interface between `argument-list' and its parent
`postfix-lparen' is changed.  Instead of simply returning its argument
list, `argument-list' now returns a function which can be applied to a
base type to produce the appropriate function type.

None of this changes any externally observable behaviour.

7 years agosrc/c-types-parse.lisp (parse-declarator): Explain how it works.
Mark Wooding [Wed, 16 Dec 2015 05:49:38 +0000 (05:49 +0000)]
src/c-types-parse.lisp (parse-declarator): Explain how it works.

It's a little confusing, even to me.

7 years agosrc/: New function `reify-variable-argument-tail'.
Mark Wooding [Wed, 16 Dec 2015 04:03:46 +0000 (04:03 +0000)]
src/: New function `reify-variable-argument-tail'.

This does the work behind `sod-message-no-varargs-tail' (only I've
simplified it by using `substitute' rather than pointlessly doing the
work by hand like an idiot).

Heads up: `sod-message-no-varargs-tail' is going to be abolished
entirely soon.

7 years agosrc/: Factor out common machinery in `check-method-type' methods.
Mark Wooding [Wed, 16 Dec 2015 02:18:38 +0000 (02:18 +0000)]
src/: Factor out common machinery in `check-method-type' methods.

The checking logic and error messages were partially duplicated in the
various methods.  Clean this mess up because that's just bad form (and
because it's about to change).

This also clears up a minor bug in the method on `aggregating-message',
which used to report a confusing error message if the method return type
wasn't what it was expecting.

7 years agosrc/method-impl.lisp: Abolish the `emf-entry-tail' variable.
Mark Wooding [Tue, 15 Dec 2015 17:13:38 +0000 (17:13 +0000)]
src/method-impl.lisp: Abolish the `emf-entry-tail' variable.

It's not different from `entry-args'.

7 years agosrc/: Make pretty-printing better at handling tight margins.
Mark Wooding [Tue, 15 Dec 2015 18:31:42 +0000 (18:31 +0000)]
src/: Make pretty-printing better at handling tight margins.

Insert some more newlines, and make existing ones less miserly.  Also,
make sure margins are set before the newlines, rather than after.

Printing for `var' is lightly hacked to allow a break before the
initializer.

7 years agosrc/c-types-impl.lisp: Refactor pretty-printing of function types.
Mark Wooding [Tue, 15 Dec 2015 18:29:49 +0000 (18:29 +0000)]
src/c-types-impl.lisp: Refactor pretty-printing of function types.

This will pay off later.  Even now, it's a bit easier to read.

If you pay attention, you'll notice that there's an extra logical block
around the argument list which doesn't seem to do anything very useful.
That too will pay off later.  Nothing else has actually changed yet.

7 years agosrc/codegen-proto.lisp: New instruction types `cond' and `for',
Mark Wooding [Wed, 16 Dec 2015 07:39:30 +0000 (07:39 +0000)]
src/codegen-proto.lisp: New instruction types `cond' and `for',

The `cond' instruction makes a ternary conditional expression of the
`COND ? CONSEQ : ALT' variety.

The `for' instruction makes one of C's fancy loops.

Maybe the format strings are interesting.

7 years agosrc/: Add commentary to the generated code.
Mark Wooding [Tue, 5 Jan 2016 21:55:24 +0000 (21:55 +0000)]
src/: Add commentary to the generated code.

Introduce a new `banner' instruction whose purpose is to act as section
heading in the code: a blank line is left (except at the head of a
block, hence the earlier expansion of the `format' string) and the
banner text written as a beautifully formatted comment.

The new `format' string, in `format-banner-comment', is just about
interesting enough to make up for the loss of the `block' printer.

7 years agosrc/codegen-proto.lisp: Rewrite `block' printing longhand.
Mark Wooding [Tue, 5 Jan 2016 21:52:36 +0000 (21:52 +0000)]
src/codegen-proto.lisp: Rewrite `block' printing longhand.

There are going to be some changes made to it, so it has to be written
out suitably.  Nothing should be very different.  The way newlines are
handled is a little tricksy.

A shame, really, because the old `format' string was quite fun.

7 years agodoc/sod.sty, doc/structures.tex: Use non-indenting variant of `prog'.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
doc/sod.sty, doc/structures.tex: Use non-indenting variant of `prog'.

Otherwise space is wasted when program fragments are shown in floats.

7 years agodoc/sod.sty, doc/*.tex: New notation for line control in `prog'.
Mark Wooding [Sat, 2 Jan 2016 15:37:03 +0000 (15:37 +0000)]
doc/sod.sty, doc/*.tex: New notation for line control in `prog'.

By default, breaks are no longer allowed between lines in a `prog'
environment.  `\\+' introduces some vertical whitespace and allows a
break.  `\\-' introduces a little space, but doesn't allow a break.

7 years agosrc/c-types-{impl,parse}.tex: Support `_Atomic' types.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/c-types-{impl,parse}.tex: Support `_Atomic' types.

blah blah

7 years agosrc/c-types-parse.lisp: Introduce a pluggable parser for declspecs.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/c-types-parse.lisp: Introduce a pluggable parser for declspecs.

  * Rename `scan-declspec' to `scan-simple-declspec'.

  * Have `scan-and-merge-declspec' try the new pluggable parser
    `complex-declspec' before giving up and trying the simple version.

  * Have `parse-declarator' use the correct name when picking out
    qualifiers.

7 years agosrc/c-types-parse.lisp: Hoist up the `ds-FOO' methods for raw types.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/c-types-parse.lisp: Hoist up the `ds-FOO' methods for raw types.

Having them just after the definition of `declspecs' doesn't seem to
make a great deal of sense.

7 years agosrc/c-types-parse.lisp: Improve handling of compatibility keywords.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/c-types-parse.lisp: Improve handling of compatibility keywords.

Newer C standards tend to introduce new keywords in the reserved space,
as `_Shiny', and possibly add a macro, tucked away in some header file,
for `shiny'.  We already deal with this for `_Bool', `_Complex', and so
on, but adding more is annoying.  Add a `:compat' keyword so that the
table initialization machinery can do the work for us.

7 years agosrc/final.lisp: Add function for interactively testing type parsing.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/final.lisp: Add function for interactively testing type parsing.

I end up writing this a lot at the REPL, so it's useful to have it
wrapped up somewhere.

7 years agosrc/c-types-proto.lisp, src/c-types-impl.lisp: Qualifier name protocol.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/c-types-proto.lisp, src/c-types-impl.lisp: Qualifier name protocol.

Add a new generic function `c-qualifier-keyword' to convert a Lisp
qualifier (confusingly, a Lisp keyword) into its C equivalent.
Currently, this just lowercases the name, but future keywords won't
necessarily have such simple mappings.

Also add `c-type-qualifier-keywords' to collect and convert the list of
keywords attached to a type, and use it in the type printing functions.
Take the opportunity to add more discretionary newlines in the pretty-
printing.

7 years agosrc/module-parse.lisp (parse-raw-class-item): Commit after declarator.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/module-parse.lisp (parse-raw-class-item): Commit after declarator.

Once we've parsed declaration specifiers and a declarator, commit to the
current parse before dispatching.

7 years agoAdd a new class slot `align', holding the instance layout alignment.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
Add a new class slot `align', holding the instance layout alignment.

Or at least a conservative approximation of it.

7 years agosrc/c-types-impl.lisp (make-or-intern-c-type): Pull out useful function.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/c-types-impl.lisp (make-or-intern-c-type): Pull out useful function.

There's a recurring pattern whether a subtype is interned and using that
to decide whether to intern the derived type.  Pull it out into its own
function.  We'll want it more later; but even now it simplifies a couple
of call sites.

7 years agosrc/c-types-parse.lisp, src/c-types-proto.lisp: Some minor cleanups.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/c-types-parse.lisp, src/c-types-proto.lisp: Some minor cleanups.

  * Reformat some documentation comments.

  * Use `&body' rather than `&rest' to mark the body argument of
    `define-c-type-syntax'.

  * Fix documentation comments to refer to `expand-c-type-spec' rather
    than `expand-c-type'.

7 years agosrc/parser/parser-proto.lisp: Add functions returning standard parsers.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/parser/parser-proto.lisp: Add functions returning standard parsers.

Return always-successful and always-failing parsers, with tunable
output.

7 years agosrc/parser/: Allow parsers to commit to a parse while peeking.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/parser/: Allow parsers to commit to a parse while peeking.

There is a new parser macro `commit' which may be used lexically within
the body of `peek' to commit to the current parse: if a failure is
encountered once the parse is committed, then the entire `peek' fails
having consumed input, rather than rewinding to the start.  This allows
parsers to limit the amount of lookahead they use once the ambiguity is
resolved.

Technically, the changes are as follows.

  * The `peek' parser macro introduces a new lexically-scoped macro into
    its body which releases its captured place and sets the
    corresponding variable to `nil'.

  * The `with-parser-place' and `with-scanner-place' macros don't try to
    release their captured places on unwind if they've been set to
    `nil'.  (It's not necessary to have changed `with-scanner-place'
    here, but it improves symmetry.)

  * There's a new `commit' parser macro which just invokes the magic
    macro introduced by `peek' and succeeds.

  * There's a top-level function with the same name as the local macro,
    to report errors in a slightly less confusing way.

7 years agodoc/clang.tex: Improve documentation of C type spec expansion.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
doc/clang.tex: Improve documentation of C type spec expansion.

Show that `expand-c-type-spec' is a generic function.  Document
`expand-c-type-form', since it's exported.

7 years agodoc/sod.sty, doc/*.tex: New command to reference `describe' environments.
Mark Wooding [Sat, 2 Jan 2016 15:33:19 +0000 (15:33 +0000)]
doc/sod.sty, doc/*.tex: New command to reference `describe' environments.

7 years agoMerge branches 'mdw/kwargs-fixes' and 'mdw/c11-fixes'
Mark Wooding [Sun, 29 May 2016 13:46:52 +0000 (14:46 +0100)]
Merge branches 'mdw/kwargs-fixes' and 'mdw/c11-fixes'

* mdw/kwargs-fixes: (53 commits)
  src/module-output.lisp: Set right margin to 77 characters.
  src/codegen-proto.lisp: Fix printing of `if`/`else if' ladders.
  src/: Write `NULL' for a null pointer, rather than plain `0'.
  src/: Enhance `definst' to allow general BVL syntax.
  src/codegen-{proto,impl}.lisp: Gather `definst' forms together.
  src/: Abolish the special `va-*' instructions.
  src/: Introduce `deliver-call' to abbreviate function calls.
  Improve checking for C99-style varargs macros.
  src/output-impl.lisp: Add a debugging dump of the known constraints.
  src/class-output.lisp, src/output-impl.lisp: Warn about unused items.
  src/frontend.lisp: Add `--backtrace' option to expose error context.
  src/final.lisp: Add convenient macro for testing parsers at the REPL.
  test/test.sod: New file containing miscellaneous tests.
  src/module-parse.lisp: Support multi-word item names in fragment syntax.
  src/module-parse.lisp: Frob `_' to `-' in item names.
  test/chimaera.{sod,ref}: Make `Chimaera' less tolerant of tickling.
  test/chimaera.sod: Make `Serpent' tickle tolerance be a slot.
  test/chimaera.sod: Reformatting.
  lib/Makefile.am: Associate man pages with the code where possible.
  lib/Makefile.am: List headers before sources.
  ...

* mdw/c11-fixes:
  doc/clang.tex: Fix terrible English in description of pointer types.
  doc/syntax.tex, src/sod-module.5: Typeset `<qualifier>s' properly.
  doc/clang.tex: Missing return type in `format-qualifiers' synopsis.
  doc/layout.tex, doc/meta.tex: Move some `sod-class-...' descriptions.
  doc/*.tex: Whitespace hacking.
  doc/list-exports.lisp: Make executable with `cl-launch' header.
  doc/list-exports.lisp: Ignore generic functions with strange names.
  doc/list-exports.lisp: Support use of CMUCL MOP.
  src/class-finalize-impl.lisp: Reorder `flet'/`macrolet'.
  src/method-proto.lisp: Fix boneheaded `:keyword' as a type.
  src/class-make-impl.lisp: Don't store `nil' in the `metaclass' slot.
  src/pset-proto.lisp (default-slot-from-property): Maybe leave slot unbound.
  src/*.lisp: Fix declared slot types.
  src/parser/package.lisp: Do better at finding Gray streams on CMUCL.
  src/*.asd.in: Load `auto.lisp' explicitly relative to `*load-pathname*'.

Conflicts:
doc/SYMBOLS (recreate using list-exports.lisp)
doc/list-exports.lisp (trivial hand-merge; leave executable)

7 years agosrc/module-output.lisp: Set right margin to 77 characters.
Mark Wooding [Tue, 15 Dec 2015 18:32:22 +0000 (18:32 +0000)]
src/module-output.lisp: Set right margin to 77 characters.

This is my usual target width.

7 years agosrc/codegen-proto.lisp: Fix printing of `if`/`else if' ladders.
Mark Wooding [Sat, 9 Jan 2016 20:41:01 +0000 (20:41 +0000)]
src/codegen-proto.lisp: Fix printing of `if`/`else if' ladders.

Should be in a nice column, rather than marching across to the right
margin like a mad thing.

7 years agosrc/: Write `NULL' for a null pointer, rather than plain `0'.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
src/: Write `NULL' for a null pointer, rather than plain `0'.

This isn't my usual style, but others may like it more.  The output is
controlled by a new variable `*null-pointer*'.  Maybe it will be
configurable later.

7 years agosrc/: Enhance `definst' to allow general BVL syntax.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
src/: Enhance `definst' to allow general BVL syntax.

Allow the `alt' argument for `if' to be &optional, and omit it when it's
not interesting.

Allow the `init' argument for `var' to be &optional, and omit it when
it's not interesting.

Make the `args' argument for `call' be &rest.  This isn't a win right
now, but it will be later.

7 years agosrc/codegen-{proto,impl}.lisp: Gather `definst' forms together.
Mark Wooding [Wed, 16 Dec 2015 03:35:50 +0000 (03:35 +0000)]
src/codegen-{proto,impl}.lisp: Gather `definst' forms together.

Having some of the definitions in the `proto' file and some in the
`impl' file doesn't make a great deal of sense.  I think that the ones
in the `impl' file were meant to be the ones which depend on the
`format-compound-statement' macro, but that's a terrible reason.

Hoist this macro above the `definst' forms, gather them all together as
part of the protocol, and sort them out a bit better.

Nothing observable has actually changed.

7 years agosrc/: Abolish the special `va-*' instructions.
Mark Wooding [Tue, 15 Dec 2015 17:19:30 +0000 (17:19 +0000)]
src/: Abolish the special `va-*' instructions.

They can be built easily enough using `call', and `deliver-call' makes
it easier on the fingers than the dedicated instructions.

7 years agosrc/: Introduce `deliver-call' to abbreviate function calls.
Mark Wooding [Thu, 7 Jan 2016 19:33:52 +0000 (19:33 +0000)]
src/: Introduce `deliver-call' to abbreviate function calls.

This will turn out to be more useful soon.

7 years agoImprove checking for C99-style varargs macros.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
Improve checking for C99-style varargs macros.

This is a rather sad story.  C99 introduced `variadic macros'
(gratuitously incompatible with GCC's better thought-out existing
feature for doing the same thing).  GCC implements the feature, and
enables it by default.  Unfortunately, GCC doesn't declare conformance
with C99 by default (by defining `__STDC_VERSION__' appropriately), so
the naïve test doesn't actually work unless you give GCC some extra
options.

Now that we have a place for `preliminary utilities' in the header file,
define a new macro `SOD__HAVE_VARARGS_MACROS' to report the feature's
availability to generated code, and use this to guard definitions which
make use of the feature.

Apparently (https://gcc.gnu.org/c99status.html) the feature was added to
GCC in version 2.95; I'm testing for version three or later because it's
easy.  But this isn't enough.  If GCC isn't fully committed to the C99
feature set, then `-pedantic' mode will issue warnings about the use of
variadic macros.  Normally we could suppress these with some hacking
involving `__extension__' or `#pragma GCC diagnostic', but GCC's
preprocessor isn't clever enough to deal with any of that.  Instead, we
reach for the big hammer and have header files declare themselves to be
`system headers', which means that GCC stops trying to warn about them
at all.

This is really quite a long way from being an ideal situation.

7 years agosrc/output-impl.lisp: Add a debugging dump of the known constraints.
Mark Wooding [Tue, 5 Jan 2016 19:29:59 +0000 (19:29 +0000)]
src/output-impl.lisp: Add a debugging dump of the known constraints.

It's disabled, but the format string is quite hairy, and this rune can
make confusing bugs a little easier to track down so I'm committing it.

7 years agosrc/class-output.lisp, src/output-impl.lisp: Warn about unused items.
Mark Wooding [Wed, 30 Dec 2015 00:34:15 +0000 (00:34 +0000)]
src/class-output.lisp, src/output-impl.lisp: Warn about unused items.

After an output run, report warnings about all of the items which didn't
get output (because they're not named in any constraints).

Unfortunately, this reports a whole bunch of internally generated items
which (harmlessly) never actually reach the output, so arrange not to
make those items in the first place.

7 years agosrc/frontend.lisp: Add `--backtrace' option to expose error context.
Mark Wooding [Tue, 15 Dec 2015 15:44:25 +0000 (15:44 +0000)]
src/frontend.lisp: Add `--backtrace' option to expose error context.

Skips the usual fancy error reporting.  Useful when debugging.

7 years agosrc/final.lisp: Add convenient macro for testing parsers at the REPL.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
src/final.lisp: Add convenient macro for testing parsers at the REPL.

Nothing especially awesome.

7 years agotest/test.sod: New file containing miscellaneous tests.
Mark Wooding [Tue, 5 Jan 2016 17:20:55 +0000 (17:20 +0000)]
test/test.sod: New file containing miscellaneous tests.

Currently there's just a tidied-up version of the aggregating method
combination tests I was using during development.

7 years agosrc/module-parse.lisp: Support multi-word item names in fragment syntax.
Mark Wooding [Tue, 5 Jan 2016 17:05:59 +0000 (17:05 +0000)]
src/module-parse.lisp: Support multi-word item names in fragment syntax.

A sequence of identifiers can be written in parentheses.  There's still
no way to refer to items whose names contain objects such as classes or
methods.  This probably isn't too disastrous.

7 years agosrc/module-parse.lisp: Frob `_' to `-' in item names.
Mark Wooding [Tue, 5 Jan 2016 17:02:17 +0000 (17:02 +0000)]
src/module-parse.lisp: Frob `_' to `-' in item names.

This was just a stupid bug.

7 years agotest/chimaera.{sod,ref}: Make `Chimaera' less tolerant of tickling.
Mark Wooding [Tue, 5 Jan 2016 17:19:11 +0000 (17:19 +0000)]
test/chimaera.{sod,ref}: Make `Chimaera' less tolerant of tickling.

Just happens to demonstrate inheritance of slot initializers.

7 years agotest/chimaera.sod: Make `Serpent' tickle tolerance be a slot.
Mark Wooding [Tue, 5 Jan 2016 17:18:27 +0000 (17:18 +0000)]
test/chimaera.sod: Make `Serpent' tickle tolerance be a slot.

No observable change (because nothing writes the slot).

7 years agotest/chimaera.sod: Reformatting.
Mark Wooding [Tue, 5 Jan 2016 17:17:40 +0000 (17:17 +0000)]
test/chimaera.sod: Reformatting.

Takes up less space now.

7 years agolib/Makefile.am: Associate man pages with the code where possible.
Mark Wooding [Tue, 29 Dec 2015 15:49:17 +0000 (15:49 +0000)]
lib/Makefile.am: Associate man pages with the code where possible.

7 years agolib/Makefile.am: List headers before sources.
Mark Wooding [Wed, 16 Dec 2015 03:59:33 +0000 (03:59 +0000)]
lib/Makefile.am: List headers before sources.

The header file works as a sort of natural stanza heading to categorize
the immediately following source files.

7 years agosrc/class-make-impl.lisp: Freeze file locations at object-creation time.
Mark Wooding [Tue, 5 Jan 2016 18:50:12 +0000 (18:50 +0000)]
src/class-make-impl.lisp: Freeze file locations at object-creation time.

A couple got missed.

7 years agosrc/class-make-proto.lisp: Remove `define-sod-class'.
Mark Wooding [Tue, 5 Jan 2016 18:42:53 +0000 (18:42 +0000)]
src/class-make-proto.lisp: Remove `define-sod-class'.

Nobody's using it, and it's out of date.

7 years agosrc/classes.lisp: Fix `print-object' on `sod-initializer'.
Mark Wooding [Tue, 5 Jan 2016 17:50:13 +0000 (17:50 +0000)]
src/classes.lisp: Fix `print-object' on `sod-initializer'.

Would have recursed forever.

Also use `with-slots' to make the whole thing rather shorter: I think
it's allowed here.

7 years agosrc/output-impl.lisp: No need to use `equal' on items rather than names.
Mark Wooding [Tue, 5 Jan 2016 19:28:14 +0000 (19:28 +0000)]
src/output-impl.lisp: No need to use `equal' on items rather than names.

7 years agosrc/: Style cleanup: use constant names for types where available.
Mark Wooding [Wed, 16 Dec 2015 05:25:51 +0000 (05:25 +0000)]
src/: Style cleanup: use constant names for types where available.

For example, say `c-type-int' rather than `(c-type int)'.

7 years agosrc/c-types-{proto,impl}.lisp: Add `:export' parameter to `defctype'.
Mark Wooding [Wed, 16 Dec 2015 06:15:06 +0000 (06:15 +0000)]
src/c-types-{proto,impl}.lisp: Add `:export' parameter to `defctype'.

Similar to `definst' (changed in 418752c), have `defctype' optionally
export its type name and variable.  Use this to (a) eliminate the
enormous explicit export list, and (b) actually export the variable
names.

Also change `define-simple-c-type' to match.

And document these changes.

7 years agosrc/{module-impl,utilities}.lisp: Make `#line' work when pretty-printing.
Mark Wooding [Tue, 5 Jan 2016 16:31:09 +0000 (16:31 +0000)]
src/{module-impl,utilities}.lisp: Make `#line' work when pretty-printing.

The `pprint-logical-block' macro interposes a `pretty-printing stream'
between its body and the underlying stream.  This makes using fancy
functionality of the underlying stream (e.g., having it keep track of
the current cursor position) rather tricky.

It would (just about) be possible to introduce a wrapper around
`pprint-logical-block' which keeps track of the mapping between
pretty-printing and plain streams; but that requires that the macro is
actually used everywhere, which is difficult because pretty-printing can
also be initiated using the `format' `~<...~:>' command.

So instead I introduce a system-specific hack `print-ugly-stuff' which
knows how to extract and expose the underlying stream to its caller, and
synchronize things so that nothing gets lost (on SBCL and CMUCL, at
least; on others, it just passes back the pretty-printing stream).  The
function `output-c-excursion' now uses this to do its thing.

7 years agosrc/module-impl.lisp (output-c-excursion): Remove redundant `~&'.
Mark Wooding [Tue, 5 Jan 2016 16:29:45 +0000 (16:29 +0000)]
src/module-impl.lisp (output-c-excursion): Remove redundant `~&'.

There's no need to have both an explicit call to `fresh-line' and `~&'
on the front of the following `format' string.  The `fresh-line' call is
the right one to leave: otherwise the new line (if any) is started after
we've called `position-aware-stream-line', which will therefore give us
the wrong answer.

7 years agosrc/builtin.lisp (class-slot "init"): Fix declaration of temporaries.
Mark Wooding [Wed, 16 Dec 2015 01:24:16 +0000 (01:24 +0000)]
src/builtin.lisp (class-slot "init"): Fix declaration of temporaries.

Each slot initializer is first used to initialize a temporary of the
correct type, which is then assigned to the slot's structure
member.  (This was introduced in commit 1d8206e.)  Unfortunately, the
temporary was declared naïvely, as `TYPE NAME', which works when TYPE
involves only declaration specifiers and pointer declarator operators,
but not otherwise.

Fix this, by using the `pprint-c-type' function like it was meant to be.

7 years agosrc/c-types-impl.lisp (arguments-lists-equal-p): Fix stupid bug.
Mark Wooding [Wed, 16 Dec 2015 07:20:53 +0000 (07:20 +0000)]
src/c-types-impl.lisp (arguments-lists-equal-p): Fix stupid bug.

If some ARG-B is `:ellipsis', but the corresponding ARG-A is a proper
argument object, then we'd have a type error applying `argument-type' to
ARG-B.  Make sure this doesn't happen.

7 years agosrc/method-impl.lisp (compute-method-entry-functions): Fix varargs handling.
Mark Wooding [Tue, 15 Dec 2015 17:04:00 +0000 (17:04 +0000)]
src/method-impl.lisp (compute-method-entry-functions): Fix varargs handling.

The `convert-stmts' in `finish-entry' didn't cover the trailing
`va_end', with the possible result of a premature return.

7 years agosrc/c-types-impl.lisp: Fix mis-spelled function name.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
src/c-types-impl.lisp: Fix mis-spelled function name.

7 years agosrc/c-types-parse.lisp: Cope if `*module-type-map*' is unbound.
Mark Wooding [Wed, 16 Dec 2015 03:17:49 +0000 (03:17 +0000)]
src/c-types-parse.lisp: Cope if `*module-type-map*' is unbound.

This is useful for testing parsing outside of the context of a module
file.

7 years agodoc/list-exports.lisp: Don't report gensyms as leaked slot names.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
doc/list-exports.lisp: Don't report gensyms as leaked slot names.

7 years agodoc/: Use the correct notation for `->' arrows.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
doc/: Use the correct notation for `->' arrows.

I'm still not entirely sure I want to get into this pretty-printing
game, but this way I can at least make the decision in a single place.

7 years agodoc/sod.sty: Make the `->' operator look like its component characters.
Mark Wooding [Sat, 7 May 2016 11:49:24 +0000 (12:49 +0100)]
doc/sod.sty: Make the `->' operator look like its component characters.

Using an actual arrow is pretty, but it's not C.

7 years agodoc/sod.sty: Add a `describe' category for messages.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
doc/sod.sty: Add a `describe' category for messages.

7 years agodoc/syntax.tex: Give the syntax chapter a little love.
Mark Wooding [Tue, 15 Dec 2015 19:15:23 +0000 (19:15 +0000)]
doc/syntax.tex: Give the syntax chapter a little love.

7 years agodoc/syntax.tex, src/sod-module.5: Document new C99 types.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
doc/syntax.tex, src/sod-module.5: Document new C99 types.

7 years agodoc/syntax.tex: Refactor the <class-definition> syntax.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
doc/syntax.tex: Refactor the <class-definition> syntax.

  * Attach the semicolon terminators to the individual <...-item>
    syntaxes rather than including them in <class-item>.

  * Conversely, pull the property sets out of the individual items and
    into the top-level syntax, on the grounds that all class items have
    property sets as a fundamental part of the high-level syntax.

7 years agodoc/syntax.tex: Fix up the syntax notation.
Mark Wooding [Sun, 10 Jan 2016 13:51:04 +0000 (13:51 +0000)]
doc/syntax.tex: Fix up the syntax notation.

Also correct some pieces which are badly out of date.

  * Fix typesetting of concrete parameters to parametrized nonterminals.

  * Now that <foo-list> isn't reserved, use it for <argument-list>.

  * Fix the <message-item> and <method-item> syntaxes to use the correct
    declarator nonterminals.

7 years agodoc/clang.tex: Fix terrible English in description of pointer types.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
doc/clang.tex: Fix terrible English in description of pointer types.

7 years agodoc/syntax.tex, src/sod-module.5: Typeset `<qualifier>s' properly.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
doc/syntax.tex, src/sod-module.5: Typeset `<qualifier>s' properly.

In `doc/syntax.tex', the plural `s' was mistakenly included as part of
the nonterminal name.  In `src/sod-module.5', the nonterminal didn't
have distinctive typesetting at all.

7 years agodoc/clang.tex: Missing return type in `format-qualifiers' synopsis.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
doc/clang.tex: Missing return type in `format-qualifiers' synopsis.

7 years agodoc/layout.tex, doc/meta.tex: Move some `sod-class-...' descriptions.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
doc/layout.tex, doc/meta.tex: Move some `sod-class-...' descriptions.

I left a comment saying that `sod-class-ilayout', `-vtables', and
`-effective-methods' were really layout functions, but didn't move
them.  This is now done.

7 years agodoc/*.tex: Whitespace hacking.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
doc/*.tex: Whitespace hacking.

7 years agodoc/list-exports.lisp: Make executable with `cl-launch' header.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
doc/list-exports.lisp: Make executable with `cl-launch' header.

7 years agodoc/list-exports.lisp: Ignore generic functions with strange names.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
doc/list-exports.lisp: Ignore generic functions with strange names.

CMUCL introduces functions `(pcl:class-predicate CLASS)' for its own
internal purposes, and it's not interesting to list them.

7 years agodoc/list-exports.lisp: Support use of CMUCL MOP.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
doc/list-exports.lisp: Support use of CMUCL MOP.

7 years agosrc/class-finalize-impl.lisp: Reorder `flet'/`macrolet'.
Mark Wooding [Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)]
src/class-finalize-impl.lisp: Reorder `flet'/`macrolet'.

The `macrolet' macro expansion explicitly references the function
defined in the `flet' form, so probably they should be the other way
out.