The HackC API

Table of contents.

Introduction

The HackC C API is part of the HackC language. HackC can be extended in either C, using the API, or through HackC files. Even when extended through HackC files, these get turned into C, and then linked into the HackC API.

Data Access

The C interface file listed here is not a formal definition the API, but while that API is in flux, I'm simply going to post header files here. The following code is generated with the "New C" DataDraw code generator, and should be very consistent, and high-performance.

/*-----------------------------------------------------------------------------
Module header file for: z module
-----------------------------------------------------------------------------*/

#ifndef ZDDR_H
#define ZDDR_H

#ifndef UTIL_H
#include "util.h"
#endif

#ifndef Z_TYPEDEF_H
#include "ztypedef.h"
#endif

/*-----------------------------------------------------------------------------
Typedefs, constants, and enums here.
-----------------------------------------------------------------------------*/
typedef struct _zList *zList;
typedef struct _zIdent *zIdent;
typedef struct _zScope *zScope;
typedef struct _zAtom *zAtom;

/*----------------------------------------------------------------------------
List methods.
----------------------------------------------------------------------------*/
#define zListNull ((zList)(NULL))
#define zListAlloc() utNew(struct _zList)
#define zListFree(List) utDelete(List)
extern void zListDestroy(zList List);
#define zListGetAtom(List) ((List)->_Atom)
#define zListSetAtom(List, __Atom) ((List)->_Atom = (__Atom))
#define zListGetfirstList(List) ((List)->firstList)
#define zListSetfirstList(List, _List) ((List)->firstList = (_List))
extern void zListInsertList(zList List, zList _List);
extern void zListRemoveList(zList List, zList _List);
#define zForeachListList(List, _List) \
for(_List = zListGetfirstList(List); _List != zListNull; \
_List = zListGetnextListList(_List))
#define zEndForeachListList
#define zSafeForeachListList(List, _List) {\
zList _nextList;\
for(_List = zListGetfirstList(List); _List != zListNull; \
_List = _nextList) {\
_nextList = zListGetnextListList(_List);
#define zEndSafeForeachListList }}
#define zListGetlastList(List) ((List)->lastList)
#define zListSetlastList(List, _List) ((List)->lastList = (_List))
extern void zListAppendList(zList List, zList _List);
#define zListGetOwningList(List) ((List)->_OwningList)
#define zListSetOwningList(List, __List) ((List)->_OwningList = (__List))
#define zListGetnextListList(List) ((List)->nextListList)
#define zListSetnextListList(List, nextList) ((List)->nextListList = (nextList))
#define zListGetprevListList(List) ((List)->prevListList)
#define zListSetprevListList(List, prevList) ((List)->prevListList = (prevList))

/*----------------------------------------------------------------------------
Ident methods.
----------------------------------------------------------------------------*/
#define zIdentNull ((zIdent)(NULL))
#define zIdentAlloc() utNew(struct _zIdent)
#define zIdentFree(Ident) utDelete(Ident)
extern void zIdentDestroy(zIdent Ident);
#define zIdentIsTypeValid(Ident) ((Ident)->_TypeValid)
#define zIdentSetTypeValid(Ident, __TypeValid) ((Ident)->_TypeValid = (__TypeValid))
#define zIdentGetChildScope(Ident) ((Ident)->_ChildScope)
#define zIdentSetChildScope(Ident, __Scope) ((Ident)->_ChildScope = (__Scope))
#define zIdentGetTypeList(Ident) ((Ident)->_TypeList)
#define zIdentSetTypeList(Ident, __List) ((Ident)->_TypeList = (__List))
#define zIdentGetOwningScope(Ident) ((Ident)->_OwningScope)
#define zIdentSetOwningScope(Ident, __Scope) ((Ident)->_OwningScope = (__Scope))
#define zIdentGetSym(Ident) ((Ident)->h.Sym)
#define zIdentSetSym(Ident, _sym) ((Ident)->h.Sym = (_sym))
#define zIdentGetnextScopeIdent(Ident) ((zIdent)((Ident)->h.nEntry))

/*----------------------------------------------------------------------------
Scope methods.
----------------------------------------------------------------------------*/
#define zScopeNull ((zScope)(NULL))
extern zScope zScopeAlloc(void);
extern void zScopeFree(zScope Scope);
extern void zScopeDestroy(zScope Scope);
extern void zScopeInsertIdent(zScope Scope, zIdent _Ident);
extern void zScopeRemoveIdent(zScope Scope, zIdent _Ident);
#define zScopeFindIdent(Scope, name) (zIdent)utqEntryHtblSym(&(Scope)->Idents, name)
#define zScopeGetnumIdents(Scope) ((Scope)->Idents.count)
#define zScopeGetIdents(Scope) (&(Scope)->Idents)
#define zScopeGetfirstIdent(Scope) ((zIdent)(utfHtblEntry(zScopeGetIdents(Scope))))
#define zForeachScopeIdent(Scope, _Ident) for(_Ident = zScopeGetfirstIdent(Scope); \
_Ident != zIdentNull; _Ident = zIdentGetnextScopeIdent(_Ident))
#define zEndForeachScopeIdent
#define zSafeForeachScopeIdent(Scope, _Ident) {\
zIdent _nextIdent;\
for(_Ident = zScopeGetfirstIdent(Scope); \
_Ident != zIdentNull; _Ident = _nextIdent) {\
_nextIdent = zIdentGetnextScopeIdent(_Ident);
#define zEndSafeForeachScopeIdent }}
#define zScopeGetOwningIdent(Scope) ((Scope)->_OwningIdent)
#define zScopeSetOwningIdent(Scope, __Ident) ((Scope)->_OwningIdent = (__Ident))

/*----------------------------------------------------------------------------
Atom methods.
----------------------------------------------------------------------------*/
#define zAtomNull ((zAtom)(NULL))
#define zAtomAlloc() utNew(struct _zAtom)
#define zAtomFree(Atom) utDelete(Atom)
extern void zAtomDestroy(zAtom Atom);
#define zAtomGetValue(Atom) ((Atom)->_Value)
#define zAtomSetValue(Atom, __Value) ((Atom)->_Value = (__Value))

/*----------------------------------------------------------------------------
Package level routines.
----------------------------------------------------------------------------*/
extern void zDDRStart(void);
#define zDDRStop()

/*----------------------------------------------------------------------------
Structure definitions.
----------------------------------------------------------------------------*/
struct _zList {
zAtom _Atom;
zList firstList;
zList lastList;
zList _OwningList;
zList nextListList;
zList prevListList;
};

struct _zIdent {
struct _utEntry h;
zScope _ChildScope;
zList _TypeList;
zScope _OwningScope;
bool _TypeValid:2;
};

struct _zScope {
struct _utHtbl Idents;
zIdent _OwningIdent;
};

struct _zAtom {
zValue _Value;
};

#endif

Additional Definitions

The C interface file listed here is not a formal definition the API, but while that API is in flux, I'm simply going to post header files here. This code is hand written, and should only contain higher-level functions, or simple functions that DataDraw doesn't currently generate.

#include "zddr.h"

extern bool zReadSourceFile(const char *fileName);
extern void zBindIdentifiers(void);
extern void zBindTypes(void);
extern void zWriteCFiles(void);
extern void zStripUnusedFunctions();
extern void zSemanticCheck(void);

extern void zError(const char *message, ...);
extern void zWarning(const char *message, ...);
extern void zPrint(const char *format, ...);
extern void zIndentPrint(const char *format, ...);
extern void zIndent(void);

#define DEFAULT_INT_WIDTH 32

/* List manipulation */
extern zList zCatLists(zList list, zList lastItem);
extern zList zMergeLists(zList list1, zList last2);
extern zList zSetListAttom(zList list, zList atom);
extern zList zListCreate(U32 numLists, ...);
extern zList zListSetName(zList list, const char *name);
extern zList zEmptyListCreate(void);
extern zList zIntListCreate(S32 value);
extern zList zStringListCreate(const char *value);
extern zList zCharListCreate(char value);
extern zList zSymListCreate(utSymRef value);
extern zList zDoubleListCreate(double value);
extern char *zListGetName(zList list);
extern utSymRef zListGetSym(zList list);
extern bool zListWriteToFile(zList list, const char *fileName);
extern bool zListDump(zList list);
/* A list iterator that finds lists with the given name */
extern zList zFindFirstMatchingList(zList rootList, utSymRef sym);
extern zList zFindNextMatchingList(zList rootList, zList prevList, utSymRef sym);
extern bool zListMatchesSym(zList list, utSymRef sym);
extern U32 zListCountLists(zList list);
#define zForeachMatchingList(rootList, sym, list) \
for((list) = zFindFirstMatchingList((rootList), (sym)); list != zListNull; \
(list) = zFindNextMatchingList((rootList), (list), (sym)))
#define zEndForeachMatchingList

/* Atom manipulation */
extern zAtom zIntAtomCreate(S32 value);
extern zAtom zStringAtomCreate(const char *value);
extern zAtom zCharAtomCreate(char value);
extern zAtom zSymAtomCreate(utSymRef sym);
extern zAtom zDoubleAtomCreate(double value);
#define zAtomGetIntValue(atom) zValueGetInt(zAtomGetValue(atom))
#define zAtomGetStringValue(atom) zValueGetString(zAtomGetValue(atom))
#define zAtomGetCharValue(atom) zValueGetChar(zAtomGetValue(atom))
#define zAtomGetSymValue(atom) zValueGetSym(zAtomGetValue(atom))
#define zAtomGetDoubleValue(atom) zValueGetDouble(zAtomGetValue(atom))
#define zAtomGetIntValue(atom) zValueGetInt(zAtomGetValue(atom))
#define zAtomGetType(atom) zValueGetType(zAtomGetValue(atom))

/* Scope manipulation */
zScope zScopeCreate(zIdent ident);

/* The two main globals */
extern zList zParseTree;
extern zScope zRootScope;

/* Some global symbols used a lot */
utSymRef zTrueSym, zFalseSym;

/* Lex, yacc stuff */
extern FILE *zFile;
extern utSymRef zFileSym;
extern U32 zLineNum;
extern U32 zDepth;
extern UTINT zparse();
extern UTINT zlex();
extern void zerror(char *message, ...);
extern void zwarn(char *message, ...);

Last changed: 04/06/2003, 20:59:25