-- This package defines a function type MY_FUNCTION (note that "function" -- is a reserved word), list types list_of_symbols, list_of_lists, -- list_of_functions, list_of_offsets, and list_of_encodings, pointer -- types for each of these types, and array types as appropriate. with FUNDAMENTALS; use FUNDAMENTALS; package funct is type my_function; type function_ptr is access my_function; type list_of_symbols; type list_of_symbols_ptr is access list_of_symbols; type list_of_lists; type list_of_lists_ptr is access list_of_lists; type list_of_functions; type list_of_functions_ptr is access list_of_functions; type list_of_offsets; type list_of_offsets_ptr is access list_of_offsets; type list_of_encodings; type list_of_encodings_ptr is access list_of_encodings; type symbol_array is array(0..LIST_SIZE-1) of symbol_type_ptr; type symbol_list_array is array(0..LIST_SIZE-1) of list_of_symbols_ptr; type function_array is array(0..LIST_SIZE-1) of function_ptr; type offset_array is array(0..LIST_SIZE-1) of offset_ptr; type offset_list_array is array(0..LIST_SIZE-1) of list_of_offsets_ptr; type int_array is array(0..LIST_SIZE-1) of integer; ------------------------- The list classes ----------------------------- -- All list types are implemented in terms of arrays, indexed from 0 -- All have an extra integer component giving the size of the list -- All have an INSERT function that inserts something of the -- appropriate element type at the end of the list -- Most have a SEARCH function that takes a list pointer and an element -- pointer and returns the position of the element in the list -- All have a GET_SIZE function that returns the number of elements -- in the list -- Most have another GET function takes a list and an integer -- and return the element stored at that position in the list -- a list of symbols -- used e.g. for source language calls -- only the functions listed above are defined for this type type list_of_symbols is record size:integer:=0; symbol:symbol_array; end record; procedure insert(ls:list_of_symbols_ptr; sym:symbol_type_ptr); function search(ls:list_of_symbols_ptr; sym:symbol_type_ptr) return integer; function get_symbol(ls:list_of_symbols_ptr; i:integer) return symbol_type_ptr; function get_size(ls:list_of_symbols_ptr) return integer; -- A type for lists of lists of symbols -- i.e., the member type is (a pointer to) a list of symbols -- Only the functions listed above are defined for this type type list_of_lists is record size:integer:=0; symbols:symbol_list_array; end record; procedure insert(ll:list_of_lists_ptr; sym:list_of_symbols_ptr); function get_symbols(ll:list_of_lists_ptr; i:integer) return list_of_symbols_ptr; function get_size(ll:list_of_lists_ptr) return integer; -- A type for lists of functions -- Only the functions listed above are defined for this type type list_of_functions is record size:integer:=0; funct:function_array; end record; procedure insert(lf:list_of_functions_ptr; f:function_ptr); function search(lf:list_of_functions_ptr; s:symbol_type_ptr) return integer; function get_funct(lf:list_of_functions_ptr; i:integer) return function_ptr; function get_size(lf:list_of_functions_ptr) return integer; -- A class for lists of offset pairs. -- In addition to the functions given above for general lists -- a special constructor is defined that takes a list of symbols pointer -- and a function pointer (representing a parameter list and a function -- block) and returns a list of the corresponding encodings. -- The result may be interpreted as the translation of the function -- call into a target language. type list_of_offsets is record size:integer:=0; offsets:offset_array; end record; function build_list_of_offsets(ls:list_of_symbols_ptr; f:function_ptr) return list_of_offsets_ptr; procedure insert(lo:list_of_offsets_ptr; o:offset_ptr); function get_offsets(lo:list_of_offsets_ptr; i:integer) return offset_ptr; function get_size(lo:list_of_offsets_ptr) return integer; -- The member objects for a list of this class are objects of the -- class defined above. They may be interpreted as function bodies -- (i.e., lists of function calls) in the target language. -- A special constructor is defined for this type that takes a function -- pointer as an argument and returns a list of encodings representing -- the translation of the function body into the target language. type list_of_encodings is record size:integer:=0; code:offset_list_array; end record; function get_size(le:list_of_encodings_ptr) return integer; function get_code(le:list_of_encodings_ptr; i:integer) return list_of_offsets_ptr; function build_list_of_encodings(f:function_ptr) return list_of_encodings_ptr; ---------------------- the type MY_FUNCTION -------------------------- -- For representation of functions. The parameters, subroutine -- names (i.e., names of other functions defined in the current -- function's block) and instructions (i.e., the list of calls -- making up the function body) are represented as lists of -- symbols in the source language -- as lists of lists of -- symbols in the latter case. The environment pointer -- "ep" is represented at compile time simply as a pointer -- to the calling function. -- Components needed at run time are the translated body, -- which is stored as the value of the "code" member object, -- and information about the function's subroutines. This -- latter information is stored simply as a list of objects -- of type MY_FUNCTION. -- Functions defined for this type are SEARCH_F and SEARCH_V -- which return offset pairs representing a function and a variable -- respectively, given a function (i.e., a function block) and a name. -- The first of these takes an integer representing the length -- of the function call, which must match the arity of the function -- found. The functions GET_NAME and GET_EP are selectors, returning -- the NAME and EP of the function respectively. type my_function is record name:symbol_type_ptr; -- the name of the function ep:function_ptr; -- the environment pointer parameter:list_of_symbols_ptr:=new list_of_symbols; subr_names:list_of_symbols_ptr:=new list_of_symbols; subroutines:list_of_functions_ptr:=new list_of_functions; instrs:list_of_lists_ptr:=new list_of_lists; code:list_of_encodings_ptr:=new list_of_encodings; end record; function search_v(f:function_ptr; s:symbol_type_ptr) return offset_ptr; function search_f(f:function_ptr; s:symbol_type_ptr; k:integer) return offset_ptr; function get_name(f:function_ptr) return symbol_type_ptr; function get_ep(f:function_ptr) return function_ptr; end funct;