Amiga TagList

From Lazarus wiki
Revision as of 19:45, 10 January 2016 by Chain-Q (talk | contribs) (very early taglist support draft. WIP. Ignore.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Problem:

The Amiga API contains a heavy number of varargs functions. These are essentially just C wrappers to underlying library functions which accept a pointer to a so-called taglist. An Amiga taglist is essentially and array of tagitems, which are basically key-value pairs. To keep it simple and fast, an Amiga tag is defined as follows:

  type
    TTagItem = record
      ti_Tag: PtrUInt;
      ti_Data: PtrUInt;
    end;

Basically it's just two pointer-sized field, where the first one determines the content of the second one. Currently, AROS, Amiga and MorphOS port addresses these problems with various array of const (TVarRec) and array of PtrUInt based solutions, neither of which is ideal, the first one requires Object Pascal mode, and involves reference counting, the second one without compiler help requires casting everything to PtrUInt manually, which is very tedious and ugly and not very effective runtime.

Proposal:

  • much like the compiler knows how to assemble C-style varargs, it ideally should know how to assemble Amiga-style taglists too. This job is heavily macroed with a C compiler, which makes reproducing it in Pascal without compiler help is incredibly ineffective and tedious.
  function sometaglistfunction(a: longint; b: longint; const tags: array of const): longint; taglist;

On the callee side, the array of const would 'turn' into an array of ttagitem.