###############################################################################
#
#	File:     initids.icn
#
#	Subject:  russell language support procedures
#
#	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.
#
###############################################################################

#DJDSTOP
# include "parm.h"
# include "stree/ststructs.mh"
# include "../stt/sttdefs.h"

# include "../applinfer/precedence.h"
#DJDSTART
$include "defs.icn"
$include "global_vars.icn"
# $include 
procedure initids()
    
    local    var_param, val_param, as_params, two_params, al_params
    
    yyvline := 9999
    
# initialize string table indicees 
    stt_enter("?",2)   # Make sure index 0 is not used 
    indx_passign := stt_enter("+=",3)
    indx_massign := stt_enter("-=",3)
    indx_assign := pend[1 + 0] := stt_enter(":=",3)
    indx_or := pend[1 + 1] := pend[1 + 2] := pend[1 + 3] := pend[1 + 4] := stt_enter("or",3)
    indx_and := pend[1 + 5] := stt_enter("and",4)
    indx_not := pend[1 + 6] := stt_enter("not",4)
    indx_equals := stt_enter(":=",2)
    indx_less := stt_enter("<",2)
    indx_le := stt_enter("<:=",3)
    indx_ge := stt_enter(">:=",3)
    indx_ne := stt_enter("<>",3)
    indx_greater := pend[1 + 7] := stt_enter(">",2)
    indx_plus := stt_enter("+",2)
    indx_minus := pend[1 + 8] := stt_enter("-",2)
    indx_times := stt_enter("*",2)
    indx_divide := stt_enter("/",2)
    indx_mod := pend[1 + 9] := stt_enter("%",2)
    indx_pconc := stt_enter("^+",3)
    indx_sconc := pend[1 + 10] := stt_enter("^*",3)
    indx_exp := pend[1 + 11] := stt_enter("**",3)
    indx_deref := pend[1 + 12] := stt_enter("^",2)
    indx_subscr := pend[1 + 13] := stt_enter(".",2)
    indx_New := stt_enter("New",4)
    indx_ptr_New := stt_enter("ptr_New",8)
    indx_init_New := stt_enter("init_New",9)
    indx_ValueOf := stt_enter("V",2)
    indx_First := stt_enter("First",6)
    indx_Last := stt_enter("Last",5)
    indx_Pred := stt_enter("Pred",5)
    indx_Succ := stt_enter("Succ",5)
    indx_Ord := stt_enter("Ord",4)
    indx_OrdInv := stt_enter("OrdInv",7)
    indx_Card := stt_enter("Card",5)
    indx_In := stt_enter("In",3)
    indx_Out := stt_enter("Out",4)
    indx_Boolean := stt_enter("Boolean",8)
    indx_true := stt_enter("True",5)
    indx_false := stt_enter("False",6)
    indx_Integer := stt_enter("Short",6)
    indx_Void := stt_enter("Void",5)
    indx_Array := stt_enter("Array",6)
    indx_put := stt_enter("put",4)
    indx_Callcc := stt_enter("Callcc",7)
    indx_size := stt_enter("size", 5)
    indx_empty := stt_enter("''",3)
    indx_simple := stt_enter("simple",7)
    indx_standard := stt_enter("standard",9)
    indx_inline := stt_enter("inline",7)
    indx_Mk := stt_enter("Mk",3)
    indx_Null := stt_enter("Null",5)
    id_Boolean := mknode([LETTERID, indx_Boolean])
    id_Void := mknode([LETTERID, indx_Void])
    id_Integer := mknode([LETTERID, indx_Integer])
    id_put := mknode([LETTERID, indx_put])
    id_ValueOf := mknode([LETTERID, indx_ValueOf])
    id_New := mknode([LETTERID, indx_New])
    id_size := mknode([LETTERID, indx_size])
    id_Null := mknode([LETTERID, indx_Null])
    id_times := mknode([LETTERID, indx_times])
    id_plus := mknode([LETTERID, indx_plus])
    
#     initialize default signatures 
#         Note that since these can and will be shared they should not 
#        be touched by the symbol table routine 
    trace_note("initids")
    val_Boolean := lock (mknode([VALSIGNATURE,
				 id_Boolean, nil , nil])
			)
    val_Integer := lock( mknode([VALSIGNATURE,
				 id_Integer, nil , nil])
			)
    val_Void    := lock( mknode([VALSIGNATURE,
				 id_Void, nil , nil])
			)
    var_Void    := lock( mknode([VARSIGNATURE,
				 id_Void])
			)
    
    val_param := lock( mknode([PARAMETER,
			       nil,
			       mknode([VALSIGNATURE,
				       mknode([LETTERID])
                                       ])
			       ]) )
    
    var_param := lock( mknode([PARAMETER,
			       0,
			       mknode([VARSIGNATURE,
				       mknode([LETTERID])
                                       ])
			       ]) )
    
    as_params := lock( mklist([var_param, val_param]) )
    two_params := lock( mklist([val_param, val_param]) )
    al_params := lock(mklist([var_param, var_param]) )
    
    sig_assign := lock( mknode([FUNCSIGNATURE, nil, as_params,
				val_param.par_signature]) )
    
    sig_pconc :=
	sig_sconc :=
	lock( mknode([FUNCSIGNATURE, nil, two_params,
		      val_param . par_signature]))
    
    sig_equals :=
        sig_less :=
        sig_greater :=
	lock( mknode([FUNCSIGNATURE, nil, two_params,val_Boolean]) )
    sig_New := lock( mknode([FUNCSIGNATURE, nil, emptylist(),
			     var_param . par_signature]) )
    sig_const := lock( mknode([FUNCSIGNATURE, nil, emptylist(),
			       val_param . par_signature]) )
    sig_ValueOf := lock( mknode([FUNCSIGNATURE, nil,
				 mklist([var_param]),
				 val_param . par_signature]) )
    sig_Signature := lock(mknode([SIGNATURESIG]))
    
    sel_true := mknode([LETTERID,indx_true])
    sel_true.sel_type := id_Boolean
    sel_true := mknode([APPLICATION, sel_true, emptylist()])
    lock( sel_true )
    
    sel_false := mknode([LETTERID,indx_false])
    sel_false.sel_type := id_Boolean
    sel_false := mknode([APPLICATION, sel_false, emptylist()])
    lock( sel_false )
    
    appl_Null := mknode([APPLICATION, id_Null, emptylist()])
    
    yyvline := 0
    return TRUE
end
