home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / COMPILER / AM.SA < prev    next >
Text File  |  1995-02-13  |  31KB  |  859 lines

  1. -- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
  2. -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
  3. -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
  4. -- the file "Doc/License" of the Sather distribution.  The license is also   --
  5. -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
  6. --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
  7.  
  8. -- am.sa: An abstract machine representation for Sather programs.
  9. -------------------------------------------------------------------
  10. -- $AM: Supertype of everything in abstract machine representation.
  11. -- AM: Implementation to be included by $AM nodes.
  12. --
  13. -- AM_OB_DEF: The layout of objects of a particular type. 
  14. -- AM_ROUT_DEF: A function definition representing a routine or iter.
  15. --
  16. -- $AM_STMT: Supertype of statement-like components.
  17. -- AM_STMT: Implementation to be included by $AM_STMT nodes. 
  18. -- AM_ASSIGN_STMT: Assignment statment.
  19. -- AM_IF_STMT: Conditional statement.
  20. -- AM_LOOP_STMT: Loop statement.
  21. -- AM_BREAK_STMT: Exit the innermost loop.
  22. -- AM_RETURN_STMT: Return statement.
  23. -- AM_YIELD_STMT: Yield statement.
  24. -- AM_CASE_STMT: Multi-way branch statement.
  25. -- AM_TYPECASE_STMT: Typecase statement.
  26. -- AM_PRE_STMT: Statement representing a precondition.
  27. -- AM_POST_STMT: Statement representing a postcondition.   
  28. -- AM_INITIAL_STMT: Statement with initial code for a postcondition.
  29. -- AM_ASSERT_STMT: Assert statement.
  30. -- AM_INVARIANT_STMT: Statement representing an invariant check.   
  31. -- AM_PROTECT_STMT: Protect statement.
  32. -- AM_RAISE_STMT: Raise statement.
  33. -- AM_EXPR_STMT: An expression used for side-effect
  34. --
  35. -- $AM_EXPR: Supertype of expression-like components.
  36. -- AM_EXPR: Implementation to be included by $AM_EXPR nodes. 
  37. -- AM_LOCAL_EXPR: Local variable expression.
  38. -- AM_ARRAY_EXPR: An array creation expression.
  39. -- AM_BND_CREATE_EXPR: Bound routine and iter creation expression.
  40. -- AM_IF_EXPR: Conditional expression.
  41. -- AM_NEW_EXPR: New expression.
  42. -- AM_IS_VOID_EXPR: Test for "void".
  43. -- AM_GLOBAL_EXPR: Global variable expression.
  44. -- AM_ATTR_EXPR: An expression referencing an attribute of an object.
  45. -- AM_ARR_EXPR: An expression referencing an array element of an object.
  46. -- AM_VATTR_ASSIGN_EXPR: Assignment to an attribute of a value object.
  47. -- AM_VARR_ASSIGN_EXPR: Assignment to an array element of a value object.   
  48. -- AM_EXCEPT_EXPR: An expression referring to the exception global.
  49. -- AM_STMT_EXPR: An expression with embedded statements.
  50. -- 
  51. -- $AM_CALL_EXPR: Supertype for calls.
  52. -- AM_CALL_EXPR: Implementation to be included by $AM_CALL_EXPR nodes.
  53. -- AM_ROUT_CALL_EXPR: Routine call expression.
  54. -- AM_ITER_CALL_EXPR: Iter call expression.
  55. -- AM_BND_ROUT_CALL_EXPR: Bound routine call expression.
  56. -- AM_BND_ITER_CALL_EXPR: Bound iter call expression.
  57. -- AM_EXT_CALL_EXPR: An external function call expression.
  58. --
  59. -- $AM_CONST: Supertype for compiler constants.
  60. -- AM_CONST: Implementation to be included by $AM_CONST nodes.
  61. -- AM_VOID_CONST: Representation of "void".
  62. -- AM_ARR_CONST: Representation of constant ARRAY{T} objects.
  63. -- AM_BOOL_CONST: Representation of constant BOOL's.
  64. -- AM_CHAR_CONST: Representation of constant CHAR objects. 
  65. -- AM_STR_CONST: Representation of constant strings. 
  66. -- AM_INT_CONST: Representation of constant INT objects. 
  67. -- AM_INTI_CONST: Representation of constant INTI objects.
  68. -- AM_FLT_CONST: Representation of constant FLT objects. 
  69. -- AM_FLTD_CONST: Representation of constant FLTD objects.
  70. -- AM_FLTX_CONST: Representation of constant FLTX objects.
  71. -- AM_FLTDX_CONST: Representation of constant FLTDX.
  72. -- AM_FLTI_CONST: Representation of constant FLTI objects.
  73. --
  74. -- Related classes: 
  75. -- PROG: Info about a program.
  76. -- $TP: A Sather type.
  77. -- SIG: Signature of a routine or iter (used to refer to them).
  78. -------------------------------------------------------------------
  79. type $AM < $PROG_ERR is
  80.    -- Supertype of everything in abstract machine representation.
  81.    
  82.    source:SFILE_ID;        -- The origin of a node in a Sather 
  83.       -- source file.
  84. end;
  85.    
  86. -------------------------------------------------------------------
  87. class AM is
  88.    -- Supertype of everything in abstract machine representation.
  89.    
  90.    attr source:SFILE_ID; -- Information identifying the 
  91.       -- origin of a node in Sather source. It encodes the file and
  92.       -- the character offset of the originating construct.   
  93.    
  94.    create(source:SFILE_ID):SAME is
  95.       -- A new object for the location `source' with default 
  96.       -- initialization.
  97.       r::=new; r.source:=source; return r end;
  98. end;
  99.  
  100. -------------------------------------------------------------------   
  101. class AM_OB_DEF < $AM is
  102.    -- The layout of a particular object type. 
  103.    include AM;
  104.    
  105.    attr tp:$TP;            -- The type this represents.
  106.    attr at:FMAP{IDENT,$TP};    -- Maps from attribute names to types.
  107.    attr arr:$TP;        -- The type of the array elements, if any.
  108.    attr asize:INT;        -- The size of the array portion if it
  109.       -- is constant. -1 for variable sized arrays. 
  110.  
  111. end;
  112.  
  113. -------------------------------------------------------------------      
  114. class AM_ROUT_DEF <$AM is
  115.    -- The definition of a function representing Sather routines and iters.
  116.    include AM create->;
  117.    include ARRAY{AM_LOCAL_EXPR}; -- An array of the argument local
  118.       -- variables in order. The first is `self'.   
  119.    
  120.    attr sig:SIG;        -- The signature of the routine.
  121.    attr is_abstract:BOOL;    -- True for an abstract routine, in 
  122.       -- this case none of the below are defined.
  123.    attr calls:FLIST{$AM_EXPR};  -- The calls that occur in the 
  124.       -- body of this routine or iter.
  125.    attr locals:FLIST{AM_LOCAL_EXPR}; -- The list of local variables. 
  126.    attr rres:AM_LOCAL_EXPR;    -- The result local variable if used.
  127.    attr code:$AM_STMT;        -- Code to execute when called.
  128.    attr is_external:BOOL;    -- True if this is an external routine
  129.       -- with a body, i.e. it is defined in Sather but callable from an
  130.       -- external language. We don't generate an AM_ROUT_DEF for
  131.       -- routines defined in the external language.
  132.    attr is_clean:BOOL;        -- True if known to not affect existing 
  133.       -- state.
  134.    attr num_yields:INT;        -- The number of yields in the body.
  135.    attr srcsig:SIG;        -- The signature of this routine or iter
  136.       -- in the class it originally came from. Used to detect built-in ops.
  137.    
  138.    create(nargs:INT, source:SFILE_ID):SAME is
  139.       -- A new definition for a routine or iter with `nargs' arguments
  140.       -- (including self).
  141.       r::=new(nargs); r.source:=source; return r end;
  142.  
  143.    calls_size:INT is
  144.       if void(calls) then return 0 end;
  145.       return calls.size end;
  146.    
  147.    is_iter:BOOL is
  148.       -- True if an iter.
  149.       return sig.is_iter end;
  150.  
  151.    name:IDENT is
  152.       -- The Sather name.
  153.       return sig.name end;
  154.    
  155.    number_of_args:INT is
  156.       -- The number of arguments for this routine or iter 
  157.       -- (including self).
  158.       return size end;
  159.  
  160.    self_local:AM_LOCAL_EXPR is
  161.       -- The local variable representing self.
  162.       return [0] end;
  163.  
  164.    local_is_hot(l:AM_LOCAL_EXPR):BOOL is
  165.       -- True if `l' is a hot argument to an iter.
  166.       if ~is_iter or void(sig.hot) then return false end;
  167.       i:INT:=0;
  168.       loop while!(i<asize); 
  169.      if SYS::ob_eq([i],l) then return sig.hot[i] end;
  170.      i:=i+1 end;
  171.       return false end;
  172.       
  173.    arg_local(i:INT):AM_LOCAL_EXPR is
  174.       -- The local variable for the `i'th argument. 0 is self, the rest
  175.       -- follow in order.
  176.       return [i] end;
  177. end;
  178.    
  179. -------------------------------------------------------------------      
  180. type $AM_STMT < $AM, $NEXT{$AM_STMT} is
  181.    -- Supertype of statement-like components.
  182. end;
  183.    
  184. -------------------------------------------------------------------      
  185. class AM_STMT is
  186.    include AM;
  187.    include NEXT{$AM_STMT};    -- The next pointer represents the
  188.       -- next statement in the list, if any.   
  189. end;
  190.    
  191. -------------------------------------------------------------------      
  192. class AM_ASSIGN_STMT < $AM_STMT is
  193.    -- Assignment statment.
  194.    include AM_STMT;
  195.    
  196.    attr dest:$AM_EXPR;        -- The destination expression.
  197.       -- This must be AM_LOCAL_EXPR, AM_GLOBAL_EXPR, AM_ATTR_EXPR,
  198.       -- or AM_ARR_EXPR. 
  199.    attr src:$AM_EXPR;        -- The source expression.
  200. end;
  201.    
  202. -------------------------------------------------------------------      
  203. class AM_IF_STMT < $AM_STMT is
  204.    -- Conditional statement.
  205.    include AM_STMT;
  206.    
  207.    attr test:$AM_EXPR;        -- Boolean test expression.
  208.    attr if_true:$AM_STMT;    -- Statements for true branch.
  209.    attr if_false:$AM_STMT;    -- Statements for false branch.
  210. end;
  211.    
  212. -------------------------------------------------------------------   
  213. class AM_LOOP_STMT < $AM_STMT is
  214.    -- Loop statement.
  215.    include AM_STMT;
  216.    
  217.    attr its:FLIST{AM_ITER_CALL_EXPR}; -- A list of the enclosed iters 
  218.       -- which must be initialized when the loop is entered. 
  219.    attr bits:FLIST{AM_BND_ITER_CALL_EXPR}; -- A list of the enclosed bound
  220.       -- iter calls which must be initialized when the loop is entered.
  221.    attr has_yield:BOOL;        -- True if there is a "yield" in the
  222.       -- loop body (or a nested loop body). 
  223.    attr body:$AM_STMT;          -- The body of the loop.
  224. end;
  225.  
  226. ------------------------------------------------------------------- 
  227. class AM_BREAK_STMT < $AM_STMT is
  228.    -- Exit the innermost loop. while!, until! and break! get 
  229.    -- transformed into this.
  230.    include AM_STMT;
  231. end;
  232.    
  233. -------------------------------------------------------------------      
  234. class AM_RETURN_STMT < $AM_STMT is
  235.    -- Return statement.
  236.    include AM_STMT;
  237.    
  238.    attr val:$AM_EXPR;        -- The return value, if any.
  239. end;
  240.    
  241. -------------------------------------------------------------------      
  242. class AM_YIELD_STMT < $AM_STMT is
  243.    -- Yield statement.
  244.    include AM_STMT;
  245.    
  246.    attr ret:INT;        -- -1 for quit or the index of the
  247.       -- branch to take next. 
  248.    attr val:$AM_EXPR;        -- The return value, if any.
  249. end;
  250.    
  251. -------------------------------------------------------------------      
  252. class AM_CASE_STMT < $AM_STMT is
  253.    -- Multi-way branch statement.
  254.    include AM_STMT;
  255.    
  256.    attr test:$AM_EXPR;        -- Expression to test.
  257.    attr tgts:FLIST{FLIST{$AM_CONST}}; -- The target values. Each entry is
  258.       -- an array of the targets for the corresponding statement list.
  259.    attr stmts:FLIST{$AM_STMT};    -- The statement lists.
  260.    attr else_stmts:$AM_STMT;    -- The else statements.
  261.    attr no_else:BOOL;        -- True if there is no "else" part.
  262. end;
  263.    
  264. -------------------------------------------------------------------   
  265. class AM_TYPECASE_STMT < $AM_STMT is
  266.    -- Typecase statement.
  267.    include AM_STMT;
  268.    
  269.    attr test:AM_LOCAL_EXPR;    -- Local variable to test.
  270.    attr tgts:FLIST{$TP};    -- The target types.
  271.    attr stmts:FLIST{$AM_STMT};    -- The statement lists.
  272.    attr else_stmts:$AM_STMT;    -- The else statements.
  273.    attr has_void_stmts:BOOL;    -- True if has void stmts.
  274.    attr void_stmts:$AM_STMT;    -- Statements to execute if void.
  275.    attr no_else:BOOL;        -- True if there is no "else" part.
  276. end;
  277.  
  278. -------------------------------------------------------------------   
  279. class AM_PRE_STMT < $AM_STMT is
  280.    -- Statement representing a precondition.
  281.    include AM_STMT;
  282.    
  283.    attr tp:$TP;            -- The type which this is from.
  284.    attr test:$AM_EXPR;        -- Expression to test.
  285. end;
  286.  
  287. -------------------------------------------------------------------   
  288. class AM_POST_STMT < $AM_STMT is
  289.    -- Statement representing a postcondition.   
  290.    include AM_STMT;
  291.    
  292.    attr tp:$TP;            -- The type which this is from.   
  293.    attr test:$AM_EXPR;        -- Expression to test.
  294. end;
  295.  
  296. -------------------------------------------------------------------   
  297. class AM_INITIAL_STMT < $AM_STMT is
  298.    -- Statement with initial code for a postcondition.
  299.    include AM_STMT;
  300.    
  301.    attr tp:$TP;            -- The type which this is from.   
  302.    attr stmts:$AM_STMT;        -- Statements to execute.
  303. end;
  304.    
  305. -------------------------------------------------------------------   
  306. class AM_INVARIANT_STMT < $AM_STMT is
  307.    -- Statement representing an invariant check. (If present, this
  308.    -- type must define "invariant:BOOL").
  309.    include AM_STMT;
  310.    
  311.    attr sig:SIG;        -- Signature of the invariant.   
  312. end;
  313.  
  314. -------------------------------------------------------------------   
  315. class AM_ASSERT_STMT < $AM_STMT is
  316.    -- Assert statement.
  317.    include AM_STMT;
  318.    
  319.    attr tp:$TP;            -- The type which this is from.      
  320.    attr test:$AM_EXPR;        -- Expression to test.
  321. end;
  322.    
  323. -------------------------------------------------------------------      
  324. class AM_PROTECT_STMT < $AM_STMT is
  325.    -- Protect statement.
  326.    include AM_STMT;
  327.    
  328.    attr body:$AM_STMT;        -- The body of the protect.
  329.    attr tgts:FLIST{$TP};    -- The target types for the "whens".
  330.    attr stmts:FLIST{$AM_STMT};    -- The statement lists.
  331.    attr else_stmts:$AM_STMT;    -- The else statements.
  332.    attr no_else:BOOL;        -- True if there is no "else" part.
  333. end;
  334.    
  335. -------------------------------------------------------------------   
  336. class AM_RAISE_STMT < $AM_STMT is
  337.    -- Raise statement.
  338.    include AM_STMT;
  339.    
  340.    attr val:$AM_EXPR;        -- The exception object.
  341. end;
  342.    
  343. -------------------------------------------------------------------      
  344. class AM_EXPR_STMT < $AM_STMT is 
  345.    -- An expression used for side-effect.
  346.    include AM_STMT;
  347.    
  348.    attr expr:$AM_EXPR;        -- The expression to evaluate.
  349. end;
  350.    
  351. -------------------------------------------------------------------      
  352. type $AM_EXPR < $AM is
  353.    -- Supertype of expression-like components.
  354.    
  355.    tp:$TP;            -- The type of the expression.
  356. end;
  357.    
  358. -------------------------------------------------------------------      
  359. class AM_EXPR is
  360.    -- Supertype of expression-like components.
  361.    include AM;
  362. end;
  363.    
  364. -------------------------------------------------------------------      
  365. class AM_LOCAL_EXPR < $AM_EXPR is
  366.    -- Local variable expression.
  367.    include AM_EXPR;
  368.    
  369.    attr is_volatile:BOOL;       -- True if the variable must be declared
  370.       -- "volatile". This is necessary in protect statments because
  371.       -- otherwise longjmp will incorrectly restore the values of locals
  372.       -- which happen to be held in registers.
  373.    attr name:IDENT;        -- The name of the local in the Sather
  374.       -- program, if any.
  375.    attr tp_at:$TP;        -- The declared type of the variable.
  376.    attr needs_init:BOOL;    -- True if this local must be initialized
  377.       -- to 0 at the start of the routine. 
  378.    attr no_assign:BOOL;        -- True if this variable may not be
  379.       -- assigned to because it is currently being typecased on.
  380.       -- (Used internally). 
  381.    
  382.    create(src:SFILE_ID, name:IDENT, tp:$TP):SAME is
  383.       r::=new; r.source:=src; r.name:=name; r.tp_at:=tp;
  384.       return r end;
  385.    
  386.    is_named:BOOL is
  387.       -- True if this is a named local variable.
  388.       return ~void(name) end;
  389.  
  390.    tp:$TP is return tp_at end;
  391. end;
  392.    
  393. -------------------------------------------------------------------      
  394. class AM_ARRAY_EXPR < $AM_EXPR is
  395.    -- An array creation expression.
  396.    include AM_EXPR create->;
  397.    include ARRAY{$AM_EXPR};    -- An array of the expressions 
  398.       -- specifying the values of the array entries. These must be
  399.       -- evaluated left to right. The number specifies the size of
  400.       -- the created array.
  401.    attr tp_at:$TP;            -- The type of the array.
  402.    
  403.    create(nargs:INT, source:SFILE_ID):SAME is
  404.       -- A new definition for a routine or iter with `nargs' arguments
  405.       -- (including self).
  406.       r::=new(nargs); r.source:=source; return r end;
  407.    
  408.    tp:$TP is return tp_at end;   
  409. end;
  410.    
  411. -------------------------------------------------------------------      
  412. class AM_BND_CREATE_EXPR < $AM_EXPR is
  413.    -- Bound routine or iter creation expression.
  414.    include AM_EXPR create->;
  415.    include ARRAY{$AM_EXPR}; -- An array of expressions for the
  416.       -- bound up arguments in order.
  417.    
  418.    attr fun:SIG;        -- The routine to bind up.
  419.    attr bnd_args:ARRAY{INT};    -- The indices of the arguments 
  420.       -- which are bound up in order. 0 is self.
  421.    attr unbnd_args:ARRAY{INT};    -- The indices of the arguments 
  422.       -- which are not bound in order. 0 is self.   
  423.    attr tp_at:$TP;            -- The type of the bound expression.
  424.    
  425.    create(nargs:INT, source:SFILE_ID):SAME is
  426.       -- A new definition for a routine or iter with `nargs' arguments
  427.       -- (including self).
  428.       r::=new(nargs); r.source:=source; return r end;
  429.    
  430.    tp:$TP is return tp_at end;   
  431. end;
  432.    
  433. -------------------------------------------------------------------      
  434. class AM_IF_EXPR < $AM_EXPR is
  435.    -- Conditional expression. Only one of the two branches will be
  436.    -- executed.
  437.    include AM_EXPR;
  438.    
  439.    attr test:$AM_EXPR;        -- The boolean expression to test.
  440.    attr if_true:$AM_EXPR;    -- Expression with result if true.
  441.    attr if_false:$AM_EXPR;    -- Expression with result if false.      
  442.    attr tp_at:$TP;            -- The type. 
  443.    
  444.    tp:$TP is return tp_at end;   
  445. end;
  446.    
  447. -------------------------------------------------------------------      
  448. class AM_NEW_EXPR < $AM_EXPR is
  449.    -- New expression.
  450.    include AM_EXPR;
  451.    
  452.    attr tp_at:$TP;        -- The type of object to allocate. 
  453.    attr asz:$AM_EXPR;        -- Number of array elements to 
  454.       -- allocate for array descendants. 
  455.    
  456.    tp:$TP is return tp_at end;
  457. end;
  458.    
  459. -------------------------------------------------------------------
  460. class AM_IS_VOID_EXPR < $AM_EXPR is
  461.    -- Test for "void".
  462.    include AM_EXPR;
  463.    attr tp_at:$TP;        -- The type BOOL.
  464.    
  465.    attr arg:$AM_EXPR;        -- Expression to test for void.
  466.    
  467.    tp:$TP is return tp_at end;   
  468. end;
  469.    
  470. -------------------------------------------------------------------      
  471. class AM_GLOBAL_EXPR < $AM_EXPR is
  472.    -- Global variable expression.
  473.    include AM_EXPR;
  474.    
  475.    attr tp_at:$TP;        -- The declared type of the global.
  476.    attr name:IDENT;        -- The Sather name, if any.
  477.    attr class_tp:$TP;        -- The class this came from.
  478.    attr init:$AM_EXPR;        -- The initialization expression, if
  479.       -- any. This must consist of only the expression components
  480.       -- which are legal for constant initializers.
  481.    attr is_const:BOOL;        -- True if this is a constant.
  482.    
  483.    tp:$TP is return tp_at end;   
  484. end;
  485.    
  486. -------------------------------------------------------------------      
  487. class AM_ATTR_EXPR < $AM_EXPR is
  488.    -- An expression referencing an attribute of an object.
  489.    include AM_EXPR;
  490.    
  491.    attr ob:$AM_EXPR;    -- The object.
  492.    attr self_tp:$TP;    -- The type of self, perhaps different from ob.tp
  493.             -- after inlining.
  494.    attr at:IDENT;    -- The name of the attribute.   
  495.    attr tp_at:$TP;    -- The type. 
  496.    
  497.    tp:$TP is return tp_at end;
  498. end;
  499.    
  500. -------------------------------------------------------------------      
  501. class AM_ARR_EXPR < $AM_EXPR is
  502.    -- An expression referencing an array element of an object.
  503.    include AM_EXPR;
  504.    
  505.    attr ob:$AM_EXPR;        -- The object.
  506.    attr ind:$AM_EXPR;        -- The array index.
  507.    attr tp_at:$TP;        -- The type.    
  508.    
  509.    tp:$TP is return tp_at end;
  510. end;
  511.    
  512. -------------------------------------------------------------------      
  513. class AM_VATTR_ASSIGN_EXPR < $AM_EXPR is
  514.    -- Assignment to an attribute of a value object.
  515.    include AM_EXPR;
  516.  
  517.    attr ob:$AM_EXPR;        -- The value object.
  518.    attr at:IDENT;        -- The name of the attribute.   
  519.    attr val:$AM_EXPR;           -- The new value.
  520.    
  521.    tp:$TP is return ob.tp end; -- Returns the object, so has same type.
  522.  
  523. end;
  524.    
  525. -------------------------------------------------------------------      
  526. class AM_VARR_ASSIGN_EXPR < $AM_EXPR is
  527.    -- Assignment to an array element of a value object.
  528.    include AM_EXPR;
  529.  
  530.    attr ob:$AM_EXPR;        -- The value object.
  531.    attr ind:$AM_EXPR;        -- The index of the array element.   
  532.    attr val:$AM_EXPR;           -- The new value.
  533.    
  534.    tp:$TP is return ob.tp end; -- Returns the object, so has same type.
  535.  
  536. end;
  537.    
  538. -------------------------------------------------------------------     
  539. class AM_EXCEPT_EXPR < $AM_EXPR is
  540.    -- An expression referring to the exception global.
  541.    include AM_EXPR;
  542.    
  543.    attr tp_at:$TP;        -- The type.
  544.    
  545.    create(tp:$TP):SAME is
  546.       r::=new; r.tp_at:=tp; return r end;
  547.    
  548.    tp:$TP is return tp_at end;   
  549.    
  550. end;
  551.    
  552. -------------------------------------------------------------------        
  553. class AM_STMT_EXPR < $AM_EXPR is
  554.    -- An expression with embedded statements.   
  555.    include AM_EXPR;
  556.    
  557.    attr stmts:$AM_STMT;        -- The statements to execute.
  558.    attr expr:$AM_EXPR;        -- The expression.
  559.    
  560.    tp:$TP is 
  561. --    if void(expr) then return void else return expr.tp end end;               -- NLP
  562.       if void(expr) then return void; end; return expr.tp; end;                 -- NLP
  563. end;
  564.    
  565. -------------------------------------------------------------------     
  566. type $AM_CALL_EXPR < $AM_EXPR is
  567.    -- Supertype for calls.
  568.    
  569.    create(nargs:INT, source:SFILE_ID):$AM_CALL_EXPR;
  570.       -- A new definition for a routine or iter with `nargs' arguments
  571.       -- (including self).
  572.  
  573.    asize:INT;                   -- number of args
  574.    aget(i:INT):$AM_EXPR;        -- argument expressions
  575. end;
  576.  
  577. -------------------------------------------------------------------  
  578. class AM_CALL_EXPR is
  579.    -- Supertype for calls.
  580.    include AM_EXPR create->;
  581.    include ARRAY{$AM_EXPR};
  582.      -- An array of argument expressions. These must be evaluated left
  583.      -- to right.    
  584.       
  585.    create(nargs:INT, source:SFILE_ID):SAME is
  586.       -- A new definition for a routine or iter with `nargs' arguments
  587.       -- (including self).
  588.       r::=new(nargs); r.source:=source; return r end;      
  589. end;
  590.    
  591. -------------------------------------------------------------------      
  592. class AM_ROUT_CALL_EXPR < $AM_CALL_EXPR is
  593.    -- Routine call expression. 
  594.    include AM_CALL_EXPR;
  595.    
  596.    attr fun:SIG;        -- The signature to call.
  597.  
  598.    tp:$TP is
  599.       -- The return type of this routine. Void if no return value.
  600.       return fun.ret end;
  601. end;
  602.    
  603. -------------------------------------------------------------------      
  604. class AM_ITER_CALL_EXPR < $AM_CALL_EXPR is
  605.    -- Iter call expression.
  606.    include AM_CALL_EXPR;
  607.    
  608.    attr fun:SIG;        -- The signature to call.
  609.    attr init:$AM_STMT;        -- Code to execute the first time 
  610.       -- through (ie. to compute self and the once args).
  611.    attr lp:AM_LOOP_STMT;    -- The enclosing loop.
  612.    
  613.    tp:$TP is
  614.       -- The return type of this iter. Void if no return value.
  615.       return fun.ret end;
  616.    
  617. end;
  618.  
  619. -------------------------------------------------------------------      
  620. class AM_BND_ROUT_CALL_EXPR < $AM_CALL_EXPR is
  621.    -- Bound routine call expression.
  622.    include AM_CALL_EXPR;
  623.    
  624.    attr br:$AM_EXPR;        -- The bound routine to call.
  625.  
  626.    tp:$TP is
  627.       -- The return type of the bound routine. Void if none.
  628.       brtp::=br.tp;
  629. --    typecase brtp when TP_ROUT then return brtp.ret end end;                  -- NLP
  630.       typecase brtp when TP_ROUT then return brtp.ret; end; return void; end;   -- NLP
  631.    
  632. end;
  633.    
  634. -------------------------------------------------------------------      
  635. class AM_BND_ITER_CALL_EXPR < $AM_CALL_EXPR is
  636.    -- Bound iter call expression.
  637.    include AM_CALL_EXPR;
  638.    
  639.    attr bi:$AM_EXPR;        -- The bound iter to call.
  640.       -- Only evaluated the first time through the loop. 
  641.    attr init:$AM_STMT;        -- Code to execute the first time 
  642.       -- through (ie. to compute self and the once args).
  643.    attr lp:AM_LOOP_STMT;    -- The enclosing loop.   
  644.    
  645.    tp:$TP is
  646.       -- The return type of the bound iter. Void if none.
  647.       bitp::=bi.tp;
  648. --    typecase bitp when TP_ITER then return bitp.ret end end;                  -- NLP
  649.       typecase bitp when TP_ITER then return bitp.ret; end; return void; end;   -- NLP
  650.    
  651. end;
  652.    
  653. -------------------------------------------------------------------   
  654. class AM_EXT_CALL_EXPR < $AM_CALL_EXPR is
  655.    -- A call on a function defined in an external language. These
  656.    -- are the signatures in an external class with no body.
  657.    -- Does assignment of the result to a local. Target is void
  658.    -- for calls with no return value. 
  659.    include AM_CALL_EXPR;
  660.  
  661.    attr fun:SIG;        -- The signature to call.
  662.    attr nm:IDENT;        -- The name of the routine
  663.  
  664.    create(nargs:INT, source:SFILE_ID, nm:IDENT):SAME is
  665.        r::=create(nargs,source);
  666.        r.nm:=nm;
  667.        return r;
  668.    end;
  669.  
  670.    ext_tp:$TP is
  671.       -- The class containing this routine.
  672.       return fun.tp end;
  673.    
  674.    tp:$TP is
  675.       -- The return type of this routine. Void if no return value.
  676.       return fun.ret end;
  677.  
  678. end;
  679.    
  680. -------------------------------------------------------------------  
  681. type $AM_CONST < $AM_EXPR is
  682.    -- Supertype for compiler constants.
  683. end;
  684.  
  685. -------------------------------------------------------------------
  686. class AM_CONST < $AM_CONST is
  687.    -- Implementation to be included by $AM_CONST nodes.   
  688.    include AM_EXPR;
  689.  
  690.    attr tp_at:$TP;      
  691.    
  692.    tp:$TP is return tp_at end;   
  693. end;
  694.  
  695. -------------------------------------------------------------------
  696. class AM_VOID_CONST < $AM_CONST is
  697.    -- Representation of "void".
  698.    include AM_CONST;
  699. end;
  700.    
  701. -------------------------------------------------------------------
  702. class AM_ARR_CONST < $AM_CONST is
  703.    -- Representation of constant ARRAY{T} objects.
  704.    include AM_CONST;
  705.    
  706.    attr elt_tp:TP_CLASS;    -- The type of the contained elements.
  707.    attr elts:ARRAY{$AM_CONST};    -- The array elements.
  708. end;
  709.  
  710. -------------------------------------------------------------------
  711. class AM_BOOL_CONST < $AM_CONST is
  712.    -- Representation of constant BOOL's.
  713.    include AM_CONST;
  714.    
  715.    attr val:BOOL;        -- The boolean value.
  716.    
  717.    create(src:SFILE_ID):SAME is
  718.       -- Create a new boolean constant with source `src'.
  719.       r::=new; r.source:=src; return r end;
  720. end;   
  721.  
  722. -------------------------------------------------------------------
  723. class AM_CHAR_CONST < $AM_CONST is
  724.    -- Representation of constant CHAR objects. Uses `bval' if the program 
  725.    -- being compiled uses the same sized characters as the compiler, 
  726.    -- val otherwise. Can tell by checking whether `val' is void.
  727.    include AM_CONST;
  728.    
  729.    attr bval:CHAR;        -- The character, if the compiled
  730.       -- program uses the same representation as the compiler.
  731.    attr val:INTI;        -- The value of the char, if non-void.
  732.    
  733.    create(t:TR_CHAR_LIT_EXPR):SAME is
  734.       -- Create a new character constant for the tree form `t'. Must 
  735.       -- change this if the target has a different format.
  736.       r::=new; r.source:=t.source; r.bval:=t.val.char; return r end;
  737. end;
  738.  
  739. -------------------------------------------------------------------   
  740. class AM_STR_CONST < $AM_CONST is
  741.    -- Representation of constant strings. 
  742.    include AM_CONST;
  743.    
  744.    attr bval:STR;        -- The string if the compiler's are 
  745.       -- the same as the compiled program.
  746.  
  747.    create:SAME is return new; end;
  748.    
  749.    create(t:TR_STR_LIT_EXPR):SAME is 
  750.       -- Create a string constant for tree form `t'. Must change this
  751.       -- if the target has a different format.
  752.       r::=new; r.source:=t.source; r.bval:=t.s; return r end;
  753.    
  754.    create_from_str(src:SFILE_ID, str:STR):SAME is 
  755.       -- Create a string constant for tree form `t'. Must change this
  756.       -- if the target has a different format.
  757.       r::=new; r.source:=src; r.bval:=str; return r end;
  758. end;
  759.    
  760. -------------------------------------------------------------------
  761. class AM_INT_CONST < $AM_CONST is
  762.    -- Representation of constant INT objects. Uses `bval' if the program 
  763.    -- being compiled uses the same sized integers as the compiler, 
  764.    -- val otherwise. Can tell by checking whether `val' is void.
  765.    include AM_CONST;
  766.    
  767.    attr val:INTI;        -- The bits of the integer, if non-void.
  768.  
  769.    create(t:TR_INT_LIT_EXPR):SAME is
  770.       -- Create a new integer constant for the tree form `t'. Must 
  771.       -- change this is the target has a different format.
  772.       r::=new; r.source:=t.source; r.val:=t.val; return r end;
  773. end;
  774.  
  775. -------------------------------------------------------------------
  776. class AM_INTI_CONST < $AM_CONST is
  777.    -- Representation of constant INTI objects.
  778.    include AM_CONST;
  779.    
  780.    attr val:INTI;        -- The integer.
  781.    
  782.    create(t:TR_INT_LIT_EXPR):SAME is
  783.       -- Create a new infinite precision integer constant for the
  784.       -- tree form `t'
  785.       r::=new; r.source:=t.source; r.val:=t.val; return r end;
  786. end;
  787.    
  788. -------------------------------------------------------------------
  789. class AM_FLT_CONST < $AM_CONST is
  790.    -- Representation of constant FLT objects. 
  791.    include AM_CONST;
  792.  
  793.    attr val:RAT;        -- The value.
  794.    
  795.    create(t:TR_FLT_LIT_EXPR):SAME is
  796.       -- Create a new floating point constant for the tree form `t'. 
  797.       r::=new; r.source:=t.source; r.val:=t.val;
  798.       return r end;
  799. end;
  800.  
  801. -------------------------------------------------------------------
  802. class AM_FLTD_CONST < $AM_CONST is
  803.    -- Representation of constant FLTD objects.
  804.    include AM_CONST;
  805.    
  806.    attr val:RAT;        -- The value.
  807.    
  808.    create(t:TR_FLT_LIT_EXPR):SAME is
  809.       -- Create a new floating point constant for the tree form `t'. 
  810.       r::=new; r.source:=t.source; r.val:=t.val;
  811.       return r end;
  812. end;
  813.  
  814. -------------------------------------------------------------------
  815. class AM_FLTX_CONST < $AM_CONST is
  816.    -- Representation of constant FLTX objects by their mantissa and 
  817.    -- exponent.
  818.    include AM_CONST;
  819.    
  820.    attr val:RAT;        -- The value.
  821.    
  822.    create(t:TR_FLT_LIT_EXPR):SAME is
  823.       -- Create a new floating point constant for the tree form `t'. 
  824.       r::=new; r.source:=t.source; r.val:=t.val;
  825.       return r end;
  826. end;
  827.  
  828. -------------------------------------------------------------------
  829. class AM_FLTDX_CONST < $AM_CONST is
  830.    -- Representation of constant FLTDX objects by their mantissa and 
  831.    -- exponent.
  832.    include AM_CONST;
  833.  
  834.    attr val:RAT;        -- The value.
  835.    
  836.    create(t:TR_FLT_LIT_EXPR):SAME is
  837.       -- Create a new floating point constant for the tree form `t'. 
  838.       r::=new; r.source:=t.source; r.val:=t.val;
  839.       return r end;
  840. end;
  841.    
  842. -------------------------------------------------------------------
  843. class AM_FLTI_CONST < $AM_CONST is
  844.    -- Representation of constant FLTI objects by their mantissa and 
  845.    -- exponent.
  846.    include AM_CONST;
  847.  
  848.    attr val:RAT;        -- The value.
  849.    
  850.    create(t:TR_FLT_LIT_EXPR):SAME is
  851.       -- Create a new floating point constant for the tree form `t'. 
  852.       r::=new; r.source:=t.source; r.val:=t.val;
  853.       return r end;
  854. end;
  855.    
  856. -------------------------------------------------------------------
  857.  
  858.  
  859.