// compile-h-s.txt
// header file for som-in-som project
//	public release som-v2 30 December 2004
//  som-v2.3  13 June 2006
//  public release som-v24 10 January 2007
//    Celebrating H.M.King 60 years accend to the throne.

// 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	// s-code
	1 icAdd icSub icMul icDiv icBand icBor icBxor
	icNot icEq icNe icLt icLe icGe icGt icShl icShr icMod
	icLdx icStx icRet icR1 icArray icEnd icGet icPut
	icLd icSt icJmp icJt icJf icLit icCall icR2
	icInc icDec icSys icCase icFun icCalli icAds 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 tyFULL
enum	// denote gvar arg for DS relocation
	0 VSCALAR VARRAY VSTRING
enum
	5678916 OBJ_SOM16

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

//  data segment is absolute M[]
//enum
//	2000 MAXDS		// size of data segment

enum
	20000 MAXCS		// size of code segment
enum
	2000 MACSIZE	// size of macro
enum
	2000 MAXYSTK	// size of parser stack
enum
	200  MAXCALLI	// size of calli list

to initSom | a =
	M = 0				// base of M, alias with C M[]
	CS = array MAXCS	// code segment
	CP = 3  			// code pointer
	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 MAXCALLI	// list of calli
	Ncall = 0			// no of calli
	CPX = MAXCS-MACSIZE	// immediate & macro code area
	exsym = array 500 	// export symbol
	nxsym = 0
	line = 0
	FI = 0				// input file
	FO = 1				// output file

: 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
