
#ifndef LIBRARIES_INGCOMPMODULE_H
#define LIBRARIES_INGCOMPMODULE_H

/*
**  $VER: ingcompmodule.h 37.4 (10.12.2000)
**  (C) by Jens Tröger
**
*/

#include <exec/types.h>
#include <exec/lists.h>
#include <exec/nodes.h>
#include <utility/hooks.h>

// the minimum free amount of stack space
#define MINIMUM_FREE_STACKSPACE 10000

// this structure defines the environment for an arbitrary
// program, before it gets executed
struct CompilerModuleEnvironment
{
  struct TreeNode *cme_TreeRoot;  // the root node of the program
  struct List     *cme_OnErrors;  // the list of ONERROR trees; every ln_Name points to a TreeNode
  struct List     *cme_Procedures;  // the PROCEDURES; every ln_Name points to a TreeNode
  struct List     *cme_Effects;  // the EFFECTS (only 1st gets executed!); every ln_Name points to a TreeNode
  ULONG           *cme_GlobalEnvironment;  // the global environment of a program is just an ULONG[] (see <libraries/installergui.h>)
  APTR             cme_UserData;  // free for modules use
  struct Hook      cme_GetSymbolHook;  // use this hook to access a certain symbol from the symbol table
  APTR             cme_PoolHeader;  // a module may use this entry for installing custom memory pools
  APTR             cme_GiveAway;  // the value of this entry gets passed to the next module
};

// the structure of one node of the syntax tree, including
// its value-union
struct TreeNode
{
  struct Node         tn_Brothers;  // PRIVATE: do not touch
  struct TreeNode    *tn_Parent;  // the super node
  struct List         tn_Childs;  // the list of childs
  int                 tn_Type;  // type of the node (see below)
  int                 tn_SrcLine;  // number of source line
  int                 tn_SrcChar;  // number of source char
  union  // the values of the node, depending of tn_Type (see below)
  {
    int   tnv_FunID;
    char *tnv_IdentName;
    char *tnv_String;
    long  tnv_Number;
  }                   tn_Value;
  WORD                tn_MinNumArg;  // PRIVATE: do not touch
  WORD                tn_MaxNumArg;  // PRIVATE: do not touch
  APTR                tn_UserData;  // free for modules use
};

// the different function types (TreeNode->tn_Value.tnv_FundID if
// TreeNode->tn_Type==NODE_FUNIDENT)
enum { FUN_ABORT = 1, FUN_COMPLETE, FUN_COPYFILES, FUN_COPYLIB,
       FUN_DEBUG, FUN_DELETE, FUN_EXECUTE, FUN_EXIT, FUN_FOREACH,
       FUN_MAKEASSIGN, FUN_MAKEDIR, FUN_MESSAGE, FUN_ONERROR,
       FUN_PROCEDURE, FUN_PROTECT, FUN_RENAME, FUN_REXX, FUN_RUN,
       FUN_SET, FUN_STARTUP, FUN_TEXTFILE, FUN_TOOLTYPE, FUN_TRAP,
       FUN_USER, FUN_WELCOME, FUN_WORKING, FUN_IF, FUN_UNTIL,
       FUN_WHILE, FUN_EQU, FUN_NE, FUN_GT, FUN_GE, FUN_LT, FUN_LE,
       FUN_ADD, FUN_SUB, FUN_MUL, FUN_DIV, FUN_AND, FUN_OR, FUN_XOR,
       FUN_NOT, FUN_BITAND, FUN_BITOR, FUN_BITXOR, FUN_BITNOT,
       FUN_SHIFTLEFT, FUN_SHIFTRIGHT, FUN_IN, FUN_ASKDIR, FUN_ASKFILE,
       FUN_ASKSTRING, FUN_ASKNUMBER, FUN_ASKCHOICE, FUN_ASKOPTIONS,
       FUN_ASKBOOL, FUN_ASKDISK, FUN_CAT, FUN_DATABASE, FUN_EXISTS,
       FUN_EXPANDPATH, FUN_EARLIER, FUN_FILEONLY, FUN_GETASSIGN,
       FUN_GETDEVICE, FUN_GETDISKSPACE, FUN_GETENV, FUN_GETSIZE,
       FUN_GETSUM, FUN_GETVERSION, FUN_PATHONLY, FUN_PATMATCH, FUN_SELECT,
       FUN_STRLEN, FUN_SUBSTR, FUN_TRANSCRIPT, FUN_TACKON, FUN_ALL,
       FUN_APPEND, FUN_ASSIGNS, FUN_CHOICES, FUN_COMMAND, FUN_CONFIRM,
       FUN_DEFAULT, FUN_DELOPTS, FUN_DEST, FUN_DISK, FUN_FILES, FUN_FONTS,
       FUN_HELP, FUN_INCLUDE, FUN_INFOS, FUN_NEWNAME, FUN_NEWPATH,
       FUN_NOGAUGE, FUN_NOPOSITION, FUN_NOREQ, FUN_OPTIONAL, FUN_PATTERN,
       FUN_PROMPT, FUN_QUIET, FUN_RANGE, FUN_RESIDENT, FUN_SAFE,
       FUN_SETDEFAULTTOOL, FUN_SETSTACK, FUN_SETTOOLTYPE, FUN_SOURCE,
       FUN_SWAPCOLORS, FUN_SYMBOLSET, FUN_SYMBOLVAL, FUN_ICONINFO,
       FUN_SETPOSITION, FUN_GETTOOLTYPE, FUN_GETDEFAULTTOOL, FUN_GETSTACK,
       FUN_GETPOSITION, FUN_SIMULATE_ERROR, FUN_BEEP, FUN_COMPARE,
       FUN_FINDBOARD, FUN_LET, FUN_REBOOT, FUN_DELAY, FUN_SWING, FUN_RANDOM,
       FUN_PUT_PROPERTY, FUN_GET_PROPERTY, FUN_REMOVE_PROPERTY,
       FUN_SAVE_PROPERTY_OBJECT, FUN_READ_PROPERTY_OBJECT, FUN_CAST_INT,
       FUN_CAST_STRING, FUN_NOP, FUN_FLUSHLIBS, FUN_CURRENTDIR,
       FUN_CALLPLUGIN,

       // new with v44 of the C= installer
       FUN_EFFECT, FUN_SHOWMEDIA, FUN_SETMEDIA, FUN_CLOSEMEDIA, FUN_TRACE,
       FUN_RETRACE, FUN_QUERYDISPLAY, FUN_BACK, FUN_OPENWBOBJECT,
       FUN_SHOWWBOBJECT, FUN_CLOSEWBOBJECT,

       FUN_SETENV
     };

// the type definitions used by the installer (SymbolTableNode->sn_Type
enum { TYPE_BUILTIN_UNKNOWN = 0,
       TYPE_BUILTIN_NUMBER = 401,  // type number
       TYPE_BUILTIN_STRING,  // type string
       TYPE_BUILTIN_PARAMETER  // return-type of parameter functions
     };

// the different node types (TreeNode->tn_Type)
enum { NODE_ROOT = 500,  // the root of the main syntax tree
       NODE_FUNCTION,  // builtin functions, see tn_Value.tnv_FunID for further information
       NODE_IDENT,  // an identifier; tn_Value.tnv_IdentName holds its name, check the symtable!
       NODE_FUNIDENT,  // a user procedure; tn_Value.tnv_IdentName holds the name of the PROCEDURE
       NODE_STRING,  // a string, tn_Value.tnv_String holds the string value
       NODE_FORMATSTR,  // a format-string; tn_Value.tnv_String folds the template string
       NODE_NUMBER,  // a number; tn_Value.tnv_Number holds the number
       NODE_EXPRLIST,  // all childs of this nodes are the expressions of the expression list
       NODE_FIRSTEXPR  // PRIVATE: ignore
     };

// the symbol table is actually a hashtable; an entry is a structure like this
struct SymbolTableNode
{
  struct Node    sn_Node;  // PRIVATE: do not touch
  char           sn_Ident[32];  // the name of the ident
  long           sn_Value;  // idents value
  int            sn_Type;  // idents type
  BOOL           sn_Constant;  // TRUE if this ident is a constant
  BOOL           sn_LetLocal;  // PRIVATE: do not touch
  struct MinList sn_BindingStore;  // PRIVATE: do not touch
  struct MinList sn_Properties;  // PRIVATE: do not touch
  APTR           sn_UserData;  // free for modules use!
};

#endif



