###############################################################################
#
#	File:     sigids_opr_let.inc.icn
#
#	Subject:  russell language support procedures - include segment
#
#	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.
#
###############################################################################

$ifdef NOT_NOT
procedure fool_emacs()
$endif
    if (\( p . sel_type) ) then {
    p . id_last_definition := nil
    p . id_def_found := TRUE
    sigids( p . sel_type)
} else if (insig) then {
    if (\ (p . signature) & (p . sig_done ~= SIG_DONE)) then {
	# user specifed signature 
	errmsg0(p,
		"Warning - signatures in signatures are ignored")
	yynerrs -:= 1
    }
    if ( \curr_sig_transp) &
	( \ (p . id_last_definition)) then {
	    def := p . id_last_definition
	    imid := curr_sig_transp . decl_innermost_id

	    # Update innermost id of curr_sig_transp 
	    if (def . kind = DECLARATION)  then {
		# Check that it's not a forward reference 
		if (def . post_num >= p . post_num) then {
		    rpt_err("Forward reference to in === declaration" || getname(p . id_str_table_index))
		}
		if (def . decl_sig_transp) then {
		    id_def := def . decl_innermost_id
		} else {
		    id_def := def
		}
	    }
	}
    if (\id_def  &
	(/imid |
	 is_descendant(id_def, imid . decl_scope))) then {
	     curr_sig_transp . decl_innermost_id := id_def
	 }
}

    # MAY NEED TO BE SMARTER EVENTUALLY 
    if (/ (p . id_last_definition) &
	p . id_str_table_index ~= -1) then {
    # This hopefully excludes defining instances 
    usl := p . id_use_list
    while (\usl) do {
	fixed_it := FALSE
	temp := usl.usl_type_list.lh_first
	while \temp  & fixed_it = FALSE do {
	    s := temp.cn_hd_field
	    if ((s . kind ~= LETTERID & s . kind != OPRID) |
		\ (s . signature) |
		\ ( s . sel_type)) then {
		    p . sel_type :=  s
		    fixed_it := TRUE
		    break
		} else {
		    def := s . id_last_definition
		    if (/def) |
			(def . kind ~= DECLARATION &
			 def . kind ~= PARAMETER) |
			(def . kind = DECLARATION &
			 / (def .decl_signature)) then {
			     p . sel_type := s
			     fixed_it := TRUE
			     break
			 }
		    if def.kind = PARAMETER then 
			sig := def. par_signature
		    else
			sig := def. decl_signature
		    if (sig . kind = TYPESIGNATURE &
			hascomp(sig, p . id_str_table_index)) then {
			    p . sel_type := s
			    fixed_it := TRUE
			    break
			}
		}
	    temp := temp.cn_tl_field
	}
	if fixed_it = FALSE then
	    usl := usl . usl_previous_list
    }
    if fixed_it = FALSE then {
	rpt_err("undeclared" || getname(p . id_str_table_index))
	# make sure the next pass doesn't run into it again 
	p . signature := ERR_SIG
	p . sig_done := SIG_DONE
    }
    p . id_def_found := TRUE
    sigids(p . sel_type)
}
    check_sig(p . signature)
    sigids( p . signature )

$ifdef NOT_NOT
end
$endif
