// compile-h-s.txt
// header file for som-in-som project
//  public release som-v24 10 January 2007
//    Celebrating H.M.King 60 years accend to the throne.
//  public release som v3.0 5 March 2007 (Maka-bucha day)
//  public release som v3.1 19 Aug 2007  (Draft vote day)
//  public release som v4.0 2 July 2008

// sequence of loading files
//
// lib.som
// string-s.txt
// compile-h-s.txt
// list-s.txt
// symtab-s.txt
// token-s.txt
// parse-h-s.txt
// stmt-s.txt
// parse.som
// icode-s.txt
// gencode-s.txt
// macro-s.txt
// main-s.txt

enum	// marker
    0 NIL MARK BMARK
enum	// atom
    0 SP OPER NUM GNAME LNAME CNAME STRING ADS
enum	// u-code
    1 icAdd icSub icMul icDiv icBand
    icBor icBxor icMod icEq icNe
    icLt icLe icGt icGe icAddi
    icSubi icShli icShri icInc icDec
    icLit icAds icSys icNot icPush
    icPusha icGet icPut icLd icSt
    icCall icRet icCallt icJmp icJt
    icJf icJle icCase icLdx icStx
    icLdy icSty icFun  // 43
enum
    43 EOC

enum	// token type
    14 tkIDEN tkNUMBER tkSTRING tkEOF tkERROR
enum	// token
    50 tkSTAR tkSLASH tkMINUS tkPLUS tkEQ tkEQEQ
    tkAND tkBAR tkCARET tkMOD tkNOT tkNE tkLT tkLE
    tkLTLT tkGT tkGE tkGTGT tkCOLON tkLPAREN tkRPAREN
    tkLBRACKET tkRBRACKET tkBB tkBE tkTO tkIF tkELSE
    tkWHILE tkFOR tkBREAK tkARRAY tkCASE tkENUM tkSYSCALL
enum	// symbol type
    6 tyFUNC tyLOCAL tyGVAR tyENUM tyKEY tyNEW tyMAC
enum	// denote gvar arg for DS relocation
    0 VSCALAR VARRAY VSTRING
enum
    5678940 OBJ_SOM40
enum	// bop type for gencode
    50 xLV xGV xLIT xEX xCM xLG xSH xUD
enum	// op format
    60 mV mG mC mJ mW mY mF

//  memory model
//  M [ MAXMEM  ]		 declared in C
//  M[1..MAXSYS]  		 system area
//	CS[MAXCS]			 code segment
//       ^
//       CP
//  ystack[MAXYSTK]		 parser stack
//           ^
//          ysp
//  cell[MAXCELL]		 store list (parse-tree)
//  data segment is absolute M[]

enum
    20000 MAXCS		// size of code segment
enum
    1000 MACSIZE	// size of macro
enum
    2000 MAXYSTK	// size of parser stack
enum
    200  MAXCALL	// size of call forward list
enum
    100  MAXLV		// size of lv table

//  system area  1 .. MAXSYS-1
enum
    101 mode_ads

to initSom | a =
    M = 0				// base of M, alias with C M[]
    CP = 6  			// code pointer
    CS = array MAXCS
    ystack = array MAXYSTK  // parser stack
    ysp = 0
    currentf = 0		// current fn idx
    nenum = 0			// enum number
    verbose = 1			// control compiler message
    cmode = 0			// compile mode, 0 def, 1 im, 2 rep
    callis = array MAXCALL	// list of call forward
    CPX = MAXCS-MACSIZE	// immediate & macro code area
    exsym = array 500 	// export symbol
    nxsym = 0
    line = 0
    FI = 0				// input file
    FO = 1				// output file
    vrec = array MAXLV
    vsp = 0				// vrec sp
    jplis = array 1000	// ads of icJmp
    lastCP = 0

: fspace = fprintc FO 32
: fnl = fprintc FO 10

// when no line number is available (gencode, eval, etc.)
to error x =
    prints "error: " prints x nl
    exit

// error during parsing
to seterror s =
    prints "line " print line space
    prints s nl
    exit

to warning nm mess =
    if verbose
        prints "Warning: "
        if nm != 0
            prints nm space
        prints mess nl

// End
