%%% -*-latex-*-
%%%
%%% Translation-time metaobjects
%%%
%%% (c) 2015 Straylight/Edgeware
%%%

%%%----- Licensing notice ---------------------------------------------------
%%%
%%% This file is part of the Sensible Object Design, an object system for C.
%%%
%%% SOD is free software; you can redistribute it and/or modify
%%% it under the terms of the GNU General Public License as published by
%%% the Free Software Foundation; either version 2 of the License, or
%%% (at your option) any later version.
%%%
%%% SOD is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%%% GNU General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with SOD; if not, write to the Free Software Foundation,
%%% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

\chapter{Translation-time metaobjects} \label{ch:meta}

%%%--------------------------------------------------------------------------
\section{Base metaobject classes} \label{sec:meta.classes}

\begin{describe}{cls}
    {sod-class ()                                               \\ \ind
      \&key \=:name :nick :location :pset                     \+\\
              :superclasses :link :metaclass                    \\
              :slots :instance-initializers :class-initializers \\
              :initargs :initfrags :tearfrags                   \\
              :messages :methods}
\end{describe}

\begin{describe*}
    {\dhead{gf}{sod-class-name @<class> @> @<string>}
     \dhead{meth}{sod-class}{file-location (@<class> sod-class) @> @<floc>}
     \dhead{gf}{sod-class-nickname @<class> @> @<string>}
     \dhead{gf}{sod-class-direct-superclasses @<class> @> @<list>}
     \dhead{gf}{sod-class-chain-link @<class> @> @<class-or-nil>}
     \dhead{gf}{sod-class-metaclass @<class> @> @<metaclass>}
     \dhead{gf}{sod-class-slots @<class> @> @<list>}
     \dhead{gf}{setf (sod-class-slots @<class>) @<list>}
     \dhead{gf}{sod-class-instance-initializers @<class> @> @<list>}
     \dhead{gf}{setf (sod-class-instance-initializers @<class>) @<list>}
     \dhead{gf}{sod-class-class-initializers @<class> @> @<list>}
     \dhead{gf}{setf (sod-class-class-initializers @<class>) @<list>}
     \dhead{gf}{sod-class-initargs @<class> @> @<list>}
     \dhead{gf}{setf (sod-class-initargs @<class>) @<list>}
     \dhead{gf}{sod-class-initfrags @<class> @> @<list>}
     \dhead{gf}{setf (sod-class-initfrags @<class>) @<list>}
     \dhead{gf}{sod-class-tearfrags @<class> @> @<list>}
     \dhead{gf}{setf (sod-class-tearfrags @<class>) @<list>}
     \dhead{gf}{sod-class-messages @<class> @> @<list>}
     \dhead{gf}{setf (sod-class-messages @<class>) @<list>}
     \dhead{gf}{sod-class-methods @<class> @> @<list>}
     \dhead{gf}{setf (sod-class-methods @<class>) @<list>}}
\end{describe*}

\begin{describe}{fun}
    {make-sod-class @<name> @<superclasses> @<pset> \&key :location
      @> @<class>}
\end{describe}

\begin{describe}{fun}
    {find-superclass-by-nick @<class> @<nick> @> @<superclass>}
\end{describe}

\begin{describe}{ty}{inheritance-path-reporter-state}
\end{describe}

\begin{describe}{fun}{make-inheritance-path-reporter-state @> @<state>}
\end{describe}

\begin{describe}{fun}{report-inheritance-path @<state> @<super>}
\end{describe}

\begin{describe}{fun}
    {select-minimal-class-property
        \=@<supers> @<key> @<order> @<default> @<what> \\
        \>\&key :present :allow-empty
      \nlret @<object>}
\end{describe}

\begin{describe}{gf}{guess-metaclass @<class> @> @<metaclass>}
\end{describe}

\begin{describe}{fun}
    {sod-subclass-p @<class-a> @<class-b> @> @<generalized-boolean>}
\end{describe}

\begin{describe}{fun}{valid-name-p @<name> @> @<generalized-boolean>}
\end{describe}

\begin{describe}{fun}{find-root-superclass @<class> @> @<superclass>}
\end{describe}

\begin{describe}{fun}{find-root-metaclass @<class> @> @<metaclass>}
\end{describe}

\begin{describe}{cls}{sod-slot () \&key :name :location :pset :class :type}
\end{describe}

\begin{describe*}
    {\dhead{gf}{sod-slot-name @<slot> @> @<string>}
     \dhead{meth}{sod-slot}{file-location (@<slot> sod-slot) @> @<floc>}
     \dhead{gf}{sod-slot-class @<slot> @> @<class>}
     \dhead{gf}{sod-slot-type @<slot> @> @<c-type>}}
\end{describe*}

\begin{describe}{gf}
    {make-sod-slot @<class> @<name> @<type> @<pset> \&key :location
      @> @<slot>}
\end{describe}

\begin{describe*}
    {\dhead{fun}
      {find-instance-slot-by-name @<class> @<super-nick> @<slot-name>
        @> @<slot>}
     \dhead{fun}
      {find-class-slot-by-name @<class> @<super-nick> @<slot-name>
        @> @<slot>}}
\end{describe*}

\begin{describe}{cls}
    {sod-class-slot (sod-slot)                                  \\ \ind
      \&key :name :location :pset :class :type
            :initializer-function :prepare-function}
\end{describe}

\begin{describe*}
    {\dhead{gf}{sod-slot-initializer-function @<slot> @> @<function>}
     \dhead{gf}{sod-slot-prepare-function @<slot> @> @<function>}}
\end{describe*}

\begin{describe*}
    {\dhead{cls}{sod-initializer ()
                  \&key :slot :location :class :value}
     \dhead{cls}{sod-instance-initializer (sod-initializer)
                  \&key :slot :location :class :value}
     \dhead{cls}{sod-class-initializer (sod-initializer)
                  \&key :slot :location :class :value}}
\end{describe*}

\begin{describe*}
    {\dhead{gf}{sod-initializer-slot @<init> @> @<slot>}
     \dhead{meth}{sod-initializer}
       {file-location (@<init> sod-initializer) @> @<floc>}
     \dhead{gf}{sod-initializer-value @<init> @> @<fragment>}
     \dhead{gf}{sod-initializer-class @<init> @> @<class>}}
\end{describe*}

\begin{describe*}
    {\dhead{gf}
      {make-sod-instance-initializer
          \=@<class> @<nick> @<name> @<value> @<pset> \\
          \>\&key :inhibit-initargs :location :add-to-class
        \nlret @<init>}
     \dhead{gf}
      {make-sod-class-initializer
          \=@<class> @<nick> @<name> @<value> @<pset> \\
          \>\&key :location :add-to-class
        \nlret @<init>}}
\end{describe*}

\begin{describe}{gf}
    {make-sod-initializer-using-slot
        @<class> @<slot> @<init-class> @<value> @<pset> @<floc>
      \nlret @<init>}
\end{describe}

\begin{describe*}
    {\dhead{cls}{sod-initarg () \&key :class :location :name :type}
     \dhead{cls}{sod-user-initarg (sod-initarg)
                  \&key :class :location :name :type :default}
     \dhead{cls}{sod-slot-initarg (sod-initarg)
                  \&key :class :location :name :type :slot}}
\end{describe*}

\begin{describe*}
    {\dhead{gf}{sod-initarg-class @<initarg> @> @<class>}
     \dhead{gf}{sod-initarg-name @<initarg> @> @<string>}
     \dhead{gf}{sod-initarg-type @<initarg> @> @<c-type>}
     \dhead{gf}{sod-initarg-default @<initarg> @> @<default>}
     \dhead{gf}{sod-initarg-slot @<initarg> @> @<slot>}}
\end{describe*}

\begin{describe}{gf}{sod-initarg-argument @<initarg> @> @<argument>}
\end{describe}

\begin{describe}{gf}
    {make-sod-user-initarg @<class> @<name> @<type> @<pset>
                           \&key :default :location
     \nlret @<initarg>}
\end{describe}

\begin{describe*}
    {\dhead{gf}
       {make-sod-slot-initarg @<class> @<name> @<nick> @<slot-name> @<pset>
                              \&key :location
        \nlret @<initarg>}
     \dhead{gf}
        {make-sod-slot-initarg-using-slot @<class> @<name> @<slot> @<pset>
                                          \&key :location
         \nlret @<initarg>}}
\end{describe*}

\begin{describe*}
    {\dhead{gf}{make-sod-class-initfrag @<class> @<frag> @<pset>
                                        \&key :location}
     \dhead{gf}{make-sod-class-tearfrag @<class> @<frag> @<pset>
                                        \&key :location}}
\end{describe*}

\begin{describe}{cls}
    {sod-message () \&key :name :location :readonly :class :type}
\end{describe}

\begin{describe*}
    {\dhead{gf}{sod-message-name @<message> @> @<string>}
     \dhead{meth}{sod-message}
       {file-location (@<message> sod-message) @> @<floc>}
     \dhead{gf}{sod-message-readonly-p @<message> @> @<generalized-boolean>}
     \dhead{gf}{sod-message-class @<message> @> @<class>}
     \dhead{gf}{sod-message-type @<message> @> @<c-type>}}
\end{describe*}

\begin{describe}{gf}
    {make-sod-message @<class> @<name> @<type> @<pset> \&key :location
      @> @<message>}
\end{describe}

\begin{describe}{gf}{check-message-type @<message> @<type>}
\end{describe}

\begin{describe}{fun}
    {find-message-by-name @<class> @<super-nick> @<message-name>
      @> @<message>}
\end{describe}

\begin{describe}{cls}
    {sod-method () \&key :message :location :class :type :body}
\end{describe}

\begin{describe*}
    {\dhead{gf}{sod-method-message @<method> @> @<message>}
     \dhead{meth}{sod-method}
       {file-location (@<method> sod-method) @> @<floc>}
     \dhead{gf}{sod-method-class @<method> @> @<class>}
     \dhead{gf}{sod-method-type @<method> @> @<c-type>}
     \dhead{gf}{sod-method-body @<method> @> @<fragment-or-nil>}}
\end{describe*}

\begin{describe}{gf}
    {make-sod-method
        \=@<class> @<nick> @<name> @<type> @<body>            \+\\
          @<pset> \&key :location                             \-
      \nlret @<method>}
\end{describe}

\begin{describe}{gf}
    {make-sod-method-using-message
        \=@<message> @<class>
          @<type> @<body>                                     \+\\
          @<pset> \&key :location                             \-
      \nlret @<method>}
\end{describe}

\begin{describe}{gf}
    {sod-message-method-class @<message> @<class> @<pset> @> @<method-class>}
\end{describe}

\begin{describe}{gf}{check-method-type @<method> @<message> @<type>}
\end{describe}

\begin{describe}{fun}
    {argument-lists-compatible-p @<message-args> @<method-args>
      @> @<generalized-boolean>}
\end{describe}

\begin{describe}{fun}{check-method-return-type @<method-type> @<return-type>}
\end{describe}

\begin{describe}{fun}
    {check-method-return-type-against-message @<method-type> @<message-type>}
\end{describe}

\begin{describe}{fun}
    {check-method-argument-lists @<method-type> @<message-type>}
\end{describe}

%%%--------------------------------------------------------------------------
\section{Class finalization protocol} \label{sec:meta.finalization}

\begin{describe}{mac}
    {finalization-error (@<token> @<arg>^*) \\ \ind
      @<declaration>^* \\
      @<form>^* \-
     \nlret @<value>^*}
\end{describe}

\begin{describe}{fun}{finalization-failed}
\end{describe}

\begin{describe*}
    {\dhead{gf}{sod-class-precedence-list @<class> @> @<list>}
     \dhead{gf}{sod-class-type @<class> @> @<c-type>}
     \dhead{gf}{sod-class-chain-head @<class> @> @<class>}
     \dhead{gf}{sod-class-chain @<class> @> @<list>}
     \dhead{gf}{sod-class-chains @<class> @> @<list>}
     \dhead{gf}{sod-class-state @<class> @> @<state>}}
\end{describe*}

\begin{describe}{gf}{compute-cpl @<class> @> @<list>}
\end{describe}

\begin{describe}{fun}
    {report-class-list-merge-error @<class> @<lists> @<error>}
\end{describe}

\begin{describe}{fun}{merge-class-lists @<class> @<lists> @<pick> @> @<list>}
\end{describe}

\begin{describe}{gf}{compute-chains @<class> @> @<list>}
\end{describe}

\begin{describe}{gf}{check-class-initializer @<slot> @<class>}
  \begin{describe}{meth}{effective-slot,sod-class}
      {check-class-initializer (@<slot> effective-slot) (@<class> sod-class)}
  \end{describe}
  \begin{describe}{meth}{sod-class-effective-slot,sod-class}
      {check-class-initializer (@<slot> sod-class-effective-slot)
                               (@<class> sod-class)}
  \end{describe}
\end{describe}

\begin{describe}{gf}{check-sod-class @<class>}
\end{describe}

\begin{describe}{gf}{finalize-sod-class @<class> @> @<generalized-boolean>}
  \begin{describe}{meth}{sod-class}
      {finalize-sod-class (@<class> sod-class)}
  \end{describe}
  \begin{describe}{ar-meth}{sod-class}
      {finalize-sod-class (@<class> sod-class) @> @<generalized-boolean>}
  \end{describe}
\end{describe}

\begin{describe}{fun}{clos-cpl @<class> @> @<list>}
\end{describe}

\begin{describe}{fun}{dylan-cpl @<class> @> @<list>}
\end{describe}

\begin{describe}{fun}{c3-cpl @<class> @> @<list>}
\end{describe}

\begin{describe}{fun}{flavors-cpl @<class> @> @<list>}
\end{describe}

\begin{describe}{fun}{python-cpl @<class> @> @<list>}
\end{describe}

\begin{describe}{fun}{l*loops-cpl @<class> @> @<list>}
\end{describe}

%%%----- That's all, folks --------------------------------------------------

%%% Local variables:
%%% mode: LaTeX
%%% TeX-master: "sod.tex"
%%% TeX-PDF-mode: t
%%% End:
