###############################################################################
#
#	File:     globals_init.icn
#
#	Subject:  russell language globals initialization routine
#
#	Author:   Dennis J Darland
#
#	Date:     October - Novmber, 2015
#
###############################################################################
#
# Copyright 1986-1989 Hans-Juergen Boehm, Alan J. Demers, Kumar Srikantan,
# Vernon Lee, and Lucy Hederman.
# Copyright Digital Equipment Corporation & INRIA 1988, 1989.
# Copyright (c) 1990-1993 by Xerox Corporation.  All rights reserved.
#
# This material is provided as is, with no warranty expressed or implied.
# Any use is at your own risk.
# 
# Permission is hereby granted to copy this compiler for any non-commercial
# purpose, provided the above notices are retained on all copies.  Further
# restrictions apply to the DEC/INRIA BigNum package.  These are stated in
# the file runtime/BigNum/doc/bnbody.tex.
#
# This work uses the BigNum package developed jointly by INRIA and
# Digital PRL.  It has been modified by Hans-J. Boehm in August 1990
# and February 1993 at Xerox PARC.  When you receive this software,
# please send mail to librarian@prl.dec.com to inform them that you
# have a copy of the package.
###############################################################################
#
#   NOTE From Dennis J. Darland (11/2/2015)
#
#   I obtained the "c" language source code for "russell" copyrighted above
#   in the 1990's. I have made efforts to get it to work over the years, but
#   always failed. It has many hardware and OS dependancies. Now (October 2015
#   forward, I am tring to port to the language "Unicon". Practically every
#   line of code will need to be changed, as someing as simple as the
#   assignment operator is different. Also I will not use the BigNum package
#   mentioned above. Also I am doing this not for profit, and am sharing
#   freely. I am not at all confident that I will get it working well, but
#   believe in open source, so am sharing my work as I make progress.
#   Unicon is also much more portable.
#
###############################################################################

#DJDSTART
$include "defs.icn"
$include "global_vars.icn"
procedure globals_init()
# next mine
    open_my_files()
    rpt_lvl := 4
# following from main
    BADflag := 0
    yydebug := 0
    initflag := TRUE
    dloadflag := FALSE
    aflag := FALSE
    Mflag := FALSE
    cflag := FALSE
    pflag := FALSE
    Lflag := FALSE
    Pflag := FALSE
    Tflag := FALSE
    Gflag := FALSE
    Vflag := FALSE
    Nflag := FALSE
    fflag := FALSE
    Fflag := FALSE
    Rflag := FALSE
    OOOflag := FALSE
    OOflag := FALSE
    Oflag := FALSE
    Xflag := FALSE
    xflag := FALSE
    hflag := FALSE

# following from pass1/stt/stt
    stt_table := table(0)
    stt_unique_cnt := 0
    stt_reference_cnt := 0
    reverse_stt := []

# following from my stats
    line_cnt := 0 
    char_cnt := 0 
    token_cnt := 0 
    reserved_id_cnt := 0 
    reserved_op_cnt := 0 
    defined_id_cnt := 0 
    defined_op_cnt := 0   
    seperator_cnt := 0 
    stt_unique_cnt := 0 
    stt_reference_cnt := 0
    numeral_cnt := 0 
    nodes_total_cnt := 0 
    lists_total_cnt := 0 
    nodes_made_cnt := 0 
    lists_made_cnt := 0 
    comments_cnt := 0 
    sing_quoted_cnt := 0 
    dbl_quoted_cnt := 0 
    yyn_switches_cnt := 0 
    yyn_compute_cnt := 0 
    newstate_cnt := 0 
    setstate_cnt := 0 
    backup_cnt := 0 
    default_cnt := 0 
    reduce_cnt := 0 
    errlab_cnt := 0 
    errlab1_cnt := 0
    RIC_op_code_cnt := 0
    RIC_table_entry_cnt := 0


# following from pass1/parser/initids
    pend := list(NLEVELS + 1) # first used in pass1/parser/initids

# following for grammar.y

#DJDSTOP
 #  stop symbols for parameter error recovery 
  paramstop := [  
    ';',
          ']',
          '{',
          VAR,
          VAL,
          FUNC,
	  TYPE,
	  SIGNATURE,
	  EOF,
	  LIST_END     ]
  # stop symbols for statement list error recovery 
  denseqstop  := [   
     ';',
	  '#',
	  ELSIF,
	  ELSE,
          FI,
          OD,
          ')',
          NI,
          '}',
          IF,
          DO,
          LET,
          FUNC,
          '(',
          WITH,
          IN,
	  EOF,
	  LIST_END       ]

      # stop symbols for error recovery in various 
     #  conditional constructs                   

  condstop := [     
     OD,
           FI,
           RIGHT_ARROW,
           '#',
           ';',
           LET,
           DO,
	   IF,
	   THEN,
	   ELSE,
           '(',
	   EOF,
	   LIST_END      ]
     # stop symbols for error recovery in declarations  
  declstop := [     
     EQUALS_EQUALS,
	  EQUALS_EQUALS_EQUALS,
          ';',
          '}',
          IN,
          NI,
          IF,
          DO,
          LET,
          '(',
	  EOF,
	  LIST_END        ]
#DJDSTART
# for parser


# for scanner
    
    restab := table(-1)

 
    restab["cand"] :=          CAND
    restab["characters"] :=    CHARACTERS
    restab["constants"] :=     CONSTANTS
    restab["cor"] :=           COR
    restab["do"] :=            DO
    restab["else"] :=          ELSE
    restab["elsif"] :=         ELSIF
    restab["enum"] :=          ENUM
    restab["export"] :=        EXPORT
    restab["extend"] :=        EXTEND
    restab["extern"] :=        EXTERN
    restab["fi"] :=            FI
    restab["field"] :=         FIELD
    restab["func"] :=          FUNC
    restab["hide"] :=          HIDE
    restab["if"] :=            IF
    restab["in"] :=            IN
    restab["let"] :=           LET
    restab["ni"] :=            NI
    restab["od"] :=            OD
    restab["prod"] :=          PROD
    restab["readonly"] :=      READONLY
    restab["record"] :=        RECORD
    restab["signature"] :=     SIGNATURE
    restab["then"] :=          THEN
    restab["type"] :=          TYPE
    restab["union"] :=         UNION
    restab["use"] :=           USE
    restab["val"] :=           VAL
    restab["var"] :=           VAR
    restab["with"] :=          WITH
 
 
 
    restab[":"] :=             COLON
    restab["<<"] :=            LEFT_ANGLE_BRACKET
    restab["=="] :=            EQUALS_EQUALS
    restab["==="] :=           EQUALS_EQUALS_EQUALS
    restab["==>"] :=           RIGHT_ARROW
    restab[">>"] :=            RIGHT_ANGLE_BRACKET

## 
          cctab := table()
	  
    cctab[char(0)] := BADCC
    cctab[char(1)] := BADCC
    cctab[char(2)] := SEPCC
    cctab[char(3)] := BADCC
    cctab[char(4)] := BADCC
    cctab[char(5)] := BADCC
    cctab[char(6)] := BADCC
    cctab[char(7)] := BADCC
    cctab[char(8)] := OPRCC
    cctab[char(9)] := WHTCC
    cctab[char(10)] := WHTCC
    cctab[char(11)] := BADCC
    cctab[char(12)] := WHTCC
    cctab[char(13)] := WHTCC
    cctab[char(14)] := BADCC
    cctab[char(15)] := BADCC
    cctab[char(16)] := BADCC
    cctab[char(17)] := BADCC
    cctab[char(18)] := BADCC
    cctab[char(19)] := BADCC
    cctab[char(20)] := BADCC
    cctab[char(21)] := BADCC
    cctab[char(22)] := BADCC
    cctab[char(23)] := BADCC
    cctab[char(24)] := BADCC
    cctab[char(25)] := BADCC
    cctab[char(26)] := BADCC
    cctab[char(27)] := BADCC
    cctab[char(28)] := BADCC
    cctab[char(29)] := BADCC
    cctab[char(30)] := BADCC
    cctab[char(31)] := BADCC
    cctab[char(32)] := WHTCC
    cctab[char(33)] := OPRCC
    cctab[char(34)] := DQUCC
    cctab[char(35)] := SEPCC
    cctab[char(36)] := SEPCC
    cctab[char(37)] := OPRCC
    cctab[char(38)] := OPRCC
    cctab[char(39)] := SQUCC
    cctab[char(40)] := SEPCC
    cctab[char(41)] := SEPCC
    cctab[char(42)] := OPRCC
    cctab[char(43)] := OPRCC
    cctab[char(44)] := SEPCC
    cctab[char(45)] := OPRCC
    cctab[char(46)] := OPRCC
    cctab[char(47)] := OPRCC
    cctab[char(48)] := DIGCC
    cctab[char(49)] := DIGCC
    cctab[char(50)] := DIGCC
    cctab[char(51)] := DIGCC
    cctab[char(52)] := DIGCC
    cctab[char(53)] := DIGCC
    cctab[char(54)] := DIGCC
    cctab[char(55)] := DIGCC
    cctab[char(56)] := DIGCC
    cctab[char(57)] := DIGCC
    cctab[char(58)] := OPRCC
    cctab[char(59)] := SEPCC
    cctab[char(60)] := OPRCC
    cctab[char(61)] := OPRCC
    cctab[char(62)] := OPRCC
    cctab[char(63)] := OPRCC
    cctab[char(64)] := OPRCC
    cctab[char(65)] := LETCC
    cctab[char(66)] := LETCC
    cctab[char(67)] := LETCC
    cctab[char(68)] := LETCC
    cctab[char(69)] := LETCC
    cctab[char(70)] := LETCC
    cctab[char(71)] := LETCC
    cctab[char(72)] := LETCC
    cctab[char(73)] := LETCC
    cctab[char(74)] := LETCC
    cctab[char(75)] := LETCC
    cctab[char(76)] := LETCC
    cctab[char(77)] := LETCC
    cctab[char(78)] := LETCC
    cctab[char(79)] := LETCC
    cctab[char(80)] := LETCC
    cctab[char(81)] := LETCC
    cctab[char(82)] := LETCC
    cctab[char(83)] := LETCC
    cctab[char(84)] := LETCC
    cctab[char(85)] := LETCC
    cctab[char(86)] := LETCC
    cctab[char(87)] := LETCC
    cctab[char(88)] := LETCC
    cctab[char(89)] := LETCC
    cctab[char(90)] := LETCC
    cctab[char(91)] := SEPCC
    cctab[char(92)] := OPRCC
    cctab[char(93)] := SEPCC
    cctab[char(94)] := OPRCC
    cctab[char(95)] := LETCC
    cctab[char(96)] := OPRCC
    cctab[char(97)] := LETCC
    cctab[char(98)] := LETCC
    cctab[char(99)] := LETCC
    cctab[char(100)] := LETCC
    cctab[char(101)] := LETCC
    cctab[char(102)] := LETCC
    cctab[char(103)] := LETCC
    cctab[char(104)] := LETCC
    cctab[char(105)] := LETCC
    cctab[char(106)] := LETCC
    cctab[char(107)] := LETCC
    cctab[char(108)] := LETCC
    cctab[char(109)] := LETCC
    cctab[char(110)] := LETCC
    cctab[char(111)] := LETCC
    cctab[char(112)] := LETCC
    cctab[char(113)] := LETCC
    cctab[char(114)] := LETCC
    cctab[char(115)] := LETCC
    cctab[char(116)] := LETCC
    cctab[char(117)] := LETCC
    cctab[char(118)] := LETCC
    cctab[char(119)] := LETCC
    cctab[char(120)] := LETCC
    cctab[char(121)] := LETCC
    cctab[char(122)] := LETCC
    cctab[char(123)] := SEPCC
    cctab[char(124)] := OPRCC
    cctab[char(125)] := SEPCC
    cctab[char(126)] := OPRCC
    cctab[char(127)] := BADCC
#DJDSTOP
    tab_chr = 9
    white_chrs = 9 10 12 13 32 
    skip_wht = SPAN(white_chrs)
    skip_wht_nl = (SPAN(white_chrs) | '')
#DJDSTART


# for scanner
stktop := -1
scansavc := "\n" # n.b. preprocessor line number scan 
yyline := 0
yyvline := 0
linebuf := ""

parser_actions_cnt := 0


# for sigio
decl_num := 0  #   last number assigned to a declaration 
decl_num_in := 0

sig_table := table()

argcnt_from_kind := list(DCSEXCEPTION + 1)

argcnt_from_kind[DECLARATION + 1] :=  16 
argcnt_from_kind[PARAMETER + 1] := 8
argcnt_from_kind[RECORDELEMENT + 1] := 6
argcnt_from_kind[VARSIGNATURE + 1] := 4
argcnt_from_kind[VALSIGNATURE + 1] := 4
argcnt_from_kind[FUNCSIGNATURE + 1] := 10
argcnt_from_kind[TYPESIGNATURE + 1] := 12
argcnt_from_kind[TSCOMPONENT + 1] :=  3
argcnt_from_kind[DEFCHARSIGS + 1] := 6
argcnt_from_kind[LISTHEADER + 1] :=  3
argcnt_from_kind[SIGNATURESIG + 1] := 3
argcnt_from_kind[BLOCKDENOTATION + 1] := 10
argcnt_from_kind[USELIST + 1] := 7
argcnt_from_kind[APPLICATION + 1] := 6
argcnt_from_kind[ENUMERATION + 1] := 4
argcnt_from_kind[EXTENSION + 1] := 6
argcnt_from_kind[PRODCONSTRUCTION + 1] := 6
argcnt_from_kind[RECORDCONSTRUCTION + 1] := 5
argcnt_from_kind[UNIONCONSTRUCTION + 1] := 6
argcnt_from_kind[WITHLIST + 1] := 4
argcnt_from_kind[MODPRIMARY + 1] :=  11
argcnt_from_kind[EXPORTLIST + 1] := 4
argcnt_from_kind[HIDELIST + 1] := 4
argcnt_from_kind[EXPORTELEMENT + 1] := 4
argcnt_from_kind[ALLCONSTANTS + 1] := 0
argcnt_from_kind[WORDELSE + 1] := 3
argcnt_from_kind[WORDCAND + 1] :=  0
argcnt_from_kind[WORDCOR + 1] :=  0
argcnt_from_kind[GUARDEDLIST + 1] := 4
argcnt_from_kind[LOOPDENOTATION + 1] := 4
argcnt_from_kind[OPRID + 1] := 11
argcnt_from_kind[LETTERID + 1] := 11
argcnt_from_kind[QSTR + 1] := 7
argcnt_from_kind[UQSTR + 1] := 7
argcnt_from_kind[FUNCCONSTR + 1] := 11
argcnt_from_kind[FREEVARNODE + 1] := 5
argcnt_from_kind[EXTERNDEF + 1] := 2
argcnt_from_kind[REXTERNDEF + 1] := 4
argcnt_from_kind[DCSEXCEPTION + 1] :=  5

unique_node_id := 0
dump__tree_depth := 0
trash_id := 0
next_pre := 0
next_post := 0

# pass5d
Gfc_list:= nil
Glevel := -1;   # current static nesting level 

finished_accessible := FALSE;    # Finished BOTH accessibility    

usl_ptr := nil
fn_count := 0
curr_void_decl := nil
curr_sig_transp := nil
in_loop := FALSE
curr_tsig := nil;
err_node := nil
outer_fc := nil
Vstatic_level := -1

 n_addr_regs := 0      # Number of virtual registers allocated to 
 n_int_regs := 0       # variables so far.                        
Vcurrent_blocks := nil
avail_loc := 0
compile_fcs := TRUE
sl_available := TRUE

fld_table := table(FALSE)
fld_table["signature"] := TRUE
fld_table["decl_signature"] := TRUE
fld_table["decl_done"] := TRUE
fld_table["decl_previous_definition"] := TRUE
fld_table["par_signature"] := TRUE
fld_table["par_previous_definition"] := TRUE
fld_table["var_denotation"] := TRUE
fld_table["val_denotation"] := TRUE
fld_table["fsig_param"] := TRUE
fld_table["fsig_result_sig"] := TRUE
fld_table["ts_clist"] := TRUE
fld_table["ts_previous_definition"] := TRUE
fld_table["tsc_id"] := TRUE
fld_table["tsc_signature"] := TRUE
fld_table["dcsexceptions"] := TRUE
fld_table["bld_decaration_list"] := TRUE
fld_table["bld_den_seq"] := TRUE
fld_table["usl_type_list"] := TRUE
fld_table["usl_den_seq"] := TRUE
fld_table["ap_operator"] := TRUE
fld_table["ap_args"] := TRUE
fld_table["enum_id_list"] := TRUE
fld_table["ex_denotation"] := TRUE
fld_table["prod_local_type"] := TRUE
fld_table["prod_components"] := TRUE
fld_table["rec_component_list"] := TRUE
fld_table["prod_local_type"] := TRUE
fld_table["prod_components"] := TRUE
fld_table["wl_local_type"] := TRUE
fld_table["wl_component_list"] := TRUE
fld_table["mp_primary"] := TRUE
fld_table["mp_type_modifier"] := TRUE
fld_table["el_local_type_id"] := TRUE
fld_table["el_export_element_list"] := TRUE
fld_table["ee_id"] := TRUE
fld_table["ee_signature"] := TRUE
fld_table["ee_export_list"] := TRUE
fld_table["gl_list"] := TRUE
fld_table["ge_guard"] := TRUE
fld_table["ge_element"] := TRUE
fld_table["sel_type"] := TRUE
fld_table["id_use_list"] := TRUE
fld_table["str_use_list"] := TRUE
fld_table["fc_complexity"] := TRUE

surr_loop := callcc_call := FALSE



stplinks := [ 
 0,
 0   + ishift(1, 27)  + ishift(1, 26)    + ishift(1, 23),
 0   + ishift(1, 27)   + ishift(1, 26),
 0   + ishift(1, 27)   + ishift(1, 26),
 0     + ishift(1, 27)   + ishift(1, 25),
 0     + ishift(1, 27)   + ishift(1, 25),
 0     + ishift(1, 27)    + ishift(1, 21)   + ishift(1, 20),
 0     + ishift(1, 27)   + ishift(1, 24)    + ishift(1, 23),
 0   + ishift(1, 27)   + ishift(1, 26),
 0    + ishift(1, 23),
 0     + ishift(1, 27),
 0     + ishift(1, 27)    + ishift(1, 22)    + ishift(1, 21),
 0     + ishift(1, 27)    + ishift(1, 25)    + ishift(1, 24),
 0     + ishift(1, 27)   + ishift(1, 25)    + ishift(1, 24),
 0     + ishift(1, 27)    + ishift(1, 25),
 0     + ishift(1, 27)   + ishift(1, 25),
 0     + ishift(1, 27)   + ishift(1, 25)    + ishift(1, 24) ,
 0     + ishift(1, 27)    + ishift(1, 25),
 0    + ishift(1, 27)   + ishift(1, 25)    + ishift(1, 24) ,
 0   + ishift(1, 27)    + ishift(1, 26),
 0     + ishift(1, 27)   + ishift(1, 23)   + ishift(1, 22)  ,
 0   + ishift(1, 27)    + ishift(1, 26),
 0  + ishift(1, 27)    + ishift(1, 26),
 0   + ishift(1, 27)   + ishift(1, 26)   + ishift(1, 25),
 0,
 0     + ishift(1, 27),
 0,
 0,
 0     + ishift(1, 27)   + ishift(1, 25),
 0     + ishift(1, 27)   + ishift(1, 25),
 0   + ishift(1, 27)   + ishift(1, 26),
 0     + ishift(1, 27)   + ishift(1, 25) ,
 0     + ishift(1, 27)    + ishift(1, 25)    + ishift(1, 19),
 0     + ishift(1, 27)    + ishift(1, 25)    + ishift(1, 22),
 0     + ishift(1, 27)    + ishift(1, 25)    + ishift(1, 22),
 0   + ishift(1, 27)    + ishift(1, 22),
 0,
 0,
 0    + ishift(1, 27),
 0,
0
]

NodeTypeName := ["LISTHEADER",
"DECLARATION",
"PARAMETER",
"RECORDELEMENT",
"VARSIGNATURE",
"VALSIGNATURE",
"FUNCSIGNATURE",
"TYPESIGNATURE",
"TSCOMPONENT",
"DEFCHARSIGS",
"SIGNATURESIG",
"BLOCKDENOTATION",
"USELIST",
"APPLICATION",
"ENUMERATION",
"EXTENSION",
"PRODCONSTRUCTION",
"RECORDCONSTRUCTION",
"UNIONCONSTRUCTION",
"WITHLIST",
"MODPRIMARY",
"EXPORTLIST",
"HIDELIST",
"EXPORTELEMENT",
"ALLCONSTANTS",
"WORDELSE",
"WORDCAND",
"WORDCOR",
"GUARDEDLIST",
"LOOPDENOTATION",
"GUARDEDELEMENT",
"OPRID",
"LETTERID",
"QSTR",
"UQSTR",
"FUNCCONSTR",
"FREEVARNODE",
"EXTERNDEF",
"REXTERNDEF",
"DCSEXCEPTION"]



node_tree_fd_stack := []



htable := table(-1)
avail_loc := 0
return TRUE
end
#DJDSTOP
