X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/020b9e2b4364c61a668d47c4c5405295349817d8..8b8a885a8072a8e840bf99f83ef78b769121dc4a:/doc/concepts.tex diff --git a/doc/concepts.tex b/doc/concepts.tex index b4e80ca..8067739 100644 --- a/doc/concepts.tex +++ b/doc/concepts.tex @@ -26,37 +26,6 @@ \chapter{Concepts} \label{ch:concepts} %%%-------------------------------------------------------------------------- -\section{Operational model} \label{sec:concepts.model} - -The Sod translator runs as a preprocessor, similar in nature to the -traditional Unix \man{lex}{1} and \man{yacc}{1} tools. The translator reads -a \emph{module} file containing class definitions and other information, and -writes C~source and header files. The source files contain function -definitions and static tables which are fed directly to a C~compiler; the -header files contain declarations for functions and data structures, and are -included by source files -- whether hand-written or generated by Sod -- which -makes use of the classes defined in the module. - -Sod is not like \Cplusplus: it makes no attempt to `enhance' the C language -itself. Sod module files describe classes, messages, methods, slots, and -other kinds of object-system things, and some of these descriptions need to -contain C code fragments, but this code is entirely uninterpreted by the Sod -translator.\footnote{% - As long as a code fragment broadly follows C's lexical rules, and properly - matches parentheses, brackets, and braces, the Sod translator will copy it - into its output unchanged. It might, in fact, be some other kind of C-like - language, such as Objective~C or \Cplusplus. Or maybe even - Objective~\Cplusplus, because if having an object system is good, then - having three must be really awesome.} % - -The Sod translator is not a closed system. It is written in Common Lisp, and -can load extension modules which add new input syntax, output formats, or -altered behaviour. The interface for writing such extensions is described in -\xref{p:lisp}. Extensions can change almost all details of the Sod object -system, so the material in this manual must be read with this in mind: this -manual describes the base system as provided in the distribution. - -%%%-------------------------------------------------------------------------- \section{Modules} \label{sec:concepts.modules} A \emph{module} is the top-level syntactic unit of input to the Sod @@ -303,6 +272,9 @@ to it in a slot. (This will also help preserve binary compatibility, because the private structure can grow more members as needed. See \xref{sec:fixme.compatibility} for more details. +\subsubsection{Vtables} + + \subsubsection{Class objects} In Sod's object system, classes are objects too. Therefore classes are themselves instances; the class of a class is called a \emph{metaclass}. The @@ -616,6 +588,36 @@ There is also a @|custom| aggregating method combination, which is described in \xref{sec:fixme.custom-aggregating-method-combination}. +\subsection{Sending messages in C} \label{sec:concepts.methods.c} + +Each instance is associated with its direct class [FIXME] + +The effective methods for each class are determined at translation time, by +the Sod translator. For each effective method, one or more \emph{method +entry functions} are constructed. A method entry function has three +responsibilities. +\begin{itemize} +\item It converts the receiver pointer to the correct type. Method entry + functions can perform these conversions extremely efficiently: there are + separate method entries for each chain of each class which can receive a + message, so method entry functions are in the privileged situation of + knowing the \emph{exact} class of the receiving object. +\item If the message accepts a variable-length argument tail, then two method + entry functions are created for each chain of each class: one receives a + variable-length argument tail, as intended, and captures it in a @|va_list| + object; the other accepts an argument of type @|va_list| in place of the + variable-length tail and arranges for it to be passed along to the direct + methods. +\item It invokes the effective method with the appropriate arguments. There + might or might not be an actual function corresponding to the effective + method itself: the translator may instead open-code the effective method's + behaviour into each method entry function; and the machinery for handling + `delegation chains', such as is used for @|around| methods and primary + methods in the standard method combination, is necessarily scattered among + a number of small functions. +\end{itemize} + + \subsection{Messages with keyword arguments} \label{sec:concepts.methods.keywords} @@ -898,6 +900,22 @@ determined using the \descref{SOD_INSTBASE}[macro]{mac}. %%%-------------------------------------------------------------------------- \section{Metaclasses} \label{sec:concepts.metaclasses} +%%%-------------------------------------------------------------------------- +\section{Compatibility considerations} \label{sec:concepts.compatibility} + +Sod doesn't make source-level compatibility especially difficult. As long as +classes, slots, and messages don't change names or dissappear, and slots and +messages retain their approximate types, everything will be fine. + +Binary compatibility is much more difficult. Unfortunately, Sod classes have +rather fragile binary interfaces.\footnote{% + Research suggestion: investigate alternative instance and vtable layouts + which improve binary compatibility, probably at the expense of instance + compactness, and efficiency of slot access and message sending. There may + be interesting trade-offs to be made.} % + +If instances are allocated [FIXME] + %%%----- That's all, folks -------------------------------------------------- %%% Local variables: