$define LISTHEADER 0
$define VALSIGNATURE 5
$define LETTERID 32


global nodes_created_trace_file, nodeTypeName, id_Boolean, id_Void, id_Integer
global id_put, id_ValueOf, id_New, id_size, id_Null, id_times, id_plus

procedure dump_info(it)
if type(it) == "integer" then return it
else if type(it) == "string"then return it
else if type(it) == "real" then return it
else return type(it)
end
# lock is dummy function
procedure lock(it)
    return  it
end

class Node(kind,vlineno,pre_num,post_num)
method trace_node()

if \kind & integer(kind) then
writes(nodes_created_trace_file, left(nodeTypeName[kind + 1],20), right(dump_info(kind),9), right(dump_info(vlineno),8), right(dump_info(pre_num),7 ), right(dump_info(post_num),6 ))
else
writes(nodes_created_trace_file,left("BAD KIND",20),right(dump_info(kind),10),right(dump_info(vlineno),10),right(dump_info(pre_num),10 ),right(dump_info(post_num),10 ))

end
end
class ConsNode(unique_id,cn_hd_field,cn_tl_field)
method trace_node()

writes(nodes_created_trace_file,right(dump_info(self.unique_id),12),right(dump_info(self.cn_hd_field),20),right(dump_info(self.cn_tl_field),20))

end
end
class  ListHeaderNode: Node : ConsNode (lh_first,lh_last)
method trace_node()
self$Node.trace_node()
self$ConsNode.trace_node()
write(nodes_created_trace_file,right(dump_info(lh_first),12),right(dump_info(lh_last),12))

end
end
class LetterId : Node : ConsNode(signature,sig_done,sel_type,id_str_table_index,id_use_list,id_last_definition,id_def_found,sel_index,id_appl,id_forward_ref)
method trace_node()
self$Node.trace_node()
self$ConsNode.trace_node()
write(nodes_created_trace_file," ")
end
end
class ValSignature  : Node : ConsNode(signature,sig_done,val_denotation)
method trace_node()
self$Node.trace_node()
self$ConsNode.trace_node()
write(nodes_created_trace_file," ")
end
end

procedure mknode(va_alist)
# yyvline is a global
    local i,arg,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19,arg20,ret,kind,pre_num,post_num,cn_tl_field,cn_hd_field
    
    cn_tl_field := cn_hd_field := pre_num := post_num := arg1 := arg2 := arg3 := arg4 := arg5 := arg6 := arg7 := arg8 := arg9 := arg10 := arg11 := arg12 := arg13 := arg14 := arg15 := arg16 := arg17 := arg18 := arg19 := arg20 := nil
    i := 1
    every (arg := !va_alist) do {
	case i of {
	    1: arg1 := arg
	    2: arg2 := arg
	    3: arg3 := arg
	    4: arg4 := arg
	    5: arg5 := arg
	    6: arg6 := arg
	    7: arg7 := arg
	    8: arg8 := arg
	    9: arg9 := arg
	    10: arg10 := arg
	    11: arg11 := arg
	    12:  arg12 := arg
	    13: arg13 := arg
	    14: arg14 := arg
	    15: arg15 := arg
	    16: arg16 := arg
	    17: arg17 := arg
	    18: arg18 := arg
	    19: arg19 := arg
	    20: arg20 := arg
	    default: write("mknode no of args not implemented")
	}
	i +:= 1
    }

    case arg1 of {
	VALSIGNATURE: ret :=  ValSignature(arg2,arg3,arg4,arg1,yyvline,pre_num,post_num,nil,nil,nil) 
	LISTHEADER: ret :=  ListHeaderNode(arg2,arg3,arg1,yyvline,pre_num,post_num,nil,nil,nil) 
	LETTERID: ret :=  LetterId(arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg1,yyvline,pre_num,post_num,nil,nil,nil)
	default: write("mknode not implemented dump_info(arg1) = " || dump_info(arg1))
    }
#    rpt_node("mkode return",ret)
    write(nodes_created_trace_file, arg1)
    ret.trace_node()
    return ret
end
procedure main()
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"]
    if not(nodes_created_trace_file := open("sample01.tmp","w")) then stop("cannot open nodes_created_trace.tmp")
    writes(nodes_created_trace_file,left("NodeTypeName",20),right("kind",10),right("vlineno",10),right("pre_num",10 ),right("post_num",10 ))
    writes(nodes_created_trace_file,right("unique_id",12),right("cn_hd_field",20),right("cn_tl_field",20))
    write(nodes_created_trace_file,right("lh_first",12),right("lh_last",12))
        id_Boolean := mknode([LETTERID, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])
        id_Void := mknode([LETTERID, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])
	id_Integer := mknode([LETTERID, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])
	id_put := mknode([LETTERID, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])
	id_ValueOf := mknode([LETTERID, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])
	id_New := mknode([LETTERID, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])
	id_size := mknode([LETTERID, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])
	id_Null := mknode([LETTERID, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])
	id_times := mknode([LETTERID, 1 , id_Null , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])
	id_plus := mknode([LETTERID, 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10])

#     initialize default signatures 
#         Note that since these can and will be shared they should not 
#        be touched by the symbol table routine 
        val_Boolean := lock( mknode([VALSIGNATURE,1,2,3])
                          )
	val_Integer := lock( mknode([VALSIGNATURE,1,2,3])
			  )
        val_Void    := lock( mknode([VALSIGNATURE,1,2,3])
                          )
end
