// 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
//  public release som v4.1   9 Aug 2008 (Birthday)

// 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	// 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

//  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

//  1..80 tokstring
//  101  mode
//  102  tokvalue
//  103  tokcol
//  104  line

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
	M[104] = 0			// line
	FI = 0				// input file
	FO = 1				// output file
	vrec = array MAXLV
	vsp = 0				// vrec sp
//	jplis = array 1000	// ads of icJmp
//	relis = array (MAXCS/4) // reloc list
	lastCP = 0

: line = M[104]
: setline n = M[104] = n

: 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
