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 >
Wrap
Text File
|
1995-02-13
|
31KB
|
859 lines
-- Copyright (C) International Computer Science Institute, 1994. COPYRIGHT --
-- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
-- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in --
-- the file "Doc/License" of the Sather distribution. The license is also --
-- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA. --
--------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
-- am.sa: An abstract machine representation for Sather programs.
-------------------------------------------------------------------
-- $AM: Supertype of everything in abstract machine representation.
-- AM: Implementation to be included by $AM nodes.
--
-- AM_OB_DEF: The layout of objects of a particular type.
-- AM_ROUT_DEF: A function definition representing a routine or iter.
--
-- $AM_STMT: Supertype of statement-like components.
-- AM_STMT: Implementation to be included by $AM_STMT nodes.
-- AM_ASSIGN_STMT: Assignment statment.
-- AM_IF_STMT: Conditional statement.
-- AM_LOOP_STMT: Loop statement.
-- AM_BREAK_STMT: Exit the innermost loop.
-- AM_RETURN_STMT: Return statement.
-- AM_YIELD_STMT: Yield statement.
-- AM_CASE_STMT: Multi-way branch statement.
-- AM_TYPECASE_STMT: Typecase statement.
-- AM_PRE_STMT: Statement representing a precondition.
-- AM_POST_STMT: Statement representing a postcondition.
-- AM_INITIAL_STMT: Statement with initial code for a postcondition.
-- AM_ASSERT_STMT: Assert statement.
-- AM_INVARIANT_STMT: Statement representing an invariant check.
-- AM_PROTECT_STMT: Protect statement.
-- AM_RAISE_STMT: Raise statement.
-- AM_EXPR_STMT: An expression used for side-effect
--
-- $AM_EXPR: Supertype of expression-like components.
-- AM_EXPR: Implementation to be included by $AM_EXPR nodes.
-- AM_LOCAL_EXPR: Local variable expression.
-- AM_ARRAY_EXPR: An array creation expression.
-- AM_BND_CREATE_EXPR: Bound routine and iter creation expression.
-- AM_IF_EXPR: Conditional expression.
-- AM_NEW_EXPR: New expression.
-- AM_IS_VOID_EXPR: Test for "void".
-- AM_GLOBAL_EXPR: Global variable expression.
-- AM_ATTR_EXPR: An expression referencing an attribute of an object.
-- AM_ARR_EXPR: An expression referencing an array element of an object.
-- AM_VATTR_ASSIGN_EXPR: Assignment to an attribute of a value object.
-- AM_VARR_ASSIGN_EXPR: Assignment to an array element of a value object.
-- AM_EXCEPT_EXPR: An expression referring to the exception global.
-- AM_STMT_EXPR: An expression with embedded statements.
--
-- $AM_CALL_EXPR: Supertype for calls.
-- AM_CALL_EXPR: Implementation to be included by $AM_CALL_EXPR nodes.
-- AM_ROUT_CALL_EXPR: Routine call expression.
-- AM_ITER_CALL_EXPR: Iter call expression.
-- AM_BND_ROUT_CALL_EXPR: Bound routine call expression.
-- AM_BND_ITER_CALL_EXPR: Bound iter call expression.
-- AM_EXT_CALL_EXPR: An external function call expression.
--
-- $AM_CONST: Supertype for compiler constants.
-- AM_CONST: Implementation to be included by $AM_CONST nodes.
-- AM_VOID_CONST: Representation of "void".
-- AM_ARR_CONST: Representation of constant ARRAY{T} objects.
-- AM_BOOL_CONST: Representation of constant BOOL's.
-- AM_CHAR_CONST: Representation of constant CHAR objects.
-- AM_STR_CONST: Representation of constant strings.
-- AM_INT_CONST: Representation of constant INT objects.
-- AM_INTI_CONST: Representation of constant INTI objects.
-- AM_FLT_CONST: Representation of constant FLT objects.
-- AM_FLTD_CONST: Representation of constant FLTD objects.
-- AM_FLTX_CONST: Representation of constant FLTX objects.
-- AM_FLTDX_CONST: Representation of constant FLTDX.
-- AM_FLTI_CONST: Representation of constant FLTI objects.
--
-- Related classes:
-- PROG: Info about a program.
-- $TP: A Sather type.
-- SIG: Signature of a routine or iter (used to refer to them).
-------------------------------------------------------------------
type $AM < $PROG_ERR is
-- Supertype of everything in abstract machine representation.
source:SFILE_ID; -- The origin of a node in a Sather
-- source file.
end;
-------------------------------------------------------------------
class AM is
-- Supertype of everything in abstract machine representation.
attr source:SFILE_ID; -- Information identifying the
-- origin of a node in Sather source. It encodes the file and
-- the character offset of the originating construct.
create(source:SFILE_ID):SAME is
-- A new object for the location `source' with default
-- initialization.
r::=new; r.source:=source; return r end;
end;
-------------------------------------------------------------------
class AM_OB_DEF < $AM is
-- The layout of a particular object type.
include AM;
attr tp:$TP; -- The type this represents.
attr at:FMAP{IDENT,$TP}; -- Maps from attribute names to types.
attr arr:$TP; -- The type of the array elements, if any.
attr asize:INT; -- The size of the array portion if it
-- is constant. -1 for variable sized arrays.
end;
-------------------------------------------------------------------
class AM_ROUT_DEF <$AM is
-- The definition of a function representing Sather routines and iters.
include AM create->;
include ARRAY{AM_LOCAL_EXPR}; -- An array of the argument local
-- variables in order. The first is `self'.
attr sig:SIG; -- The signature of the routine.
attr is_abstract:BOOL; -- True for an abstract routine, in
-- this case none of the below are defined.
attr calls:FLIST{$AM_EXPR}; -- The calls that occur in the
-- body of this routine or iter.
attr locals:FLIST{AM_LOCAL_EXPR}; -- The list of local variables.
attr rres:AM_LOCAL_EXPR; -- The result local variable if used.
attr code:$AM_STMT; -- Code to execute when called.
attr is_external:BOOL; -- True if this is an external routine
-- with a body, i.e. it is defined in Sather but callable from an
-- external language. We don't generate an AM_ROUT_DEF for
-- routines defined in the external language.
attr is_clean:BOOL; -- True if known to not affect existing
-- state.
attr num_yields:INT; -- The number of yields in the body.
attr srcsig:SIG; -- The signature of this routine or iter
-- in the class it originally came from. Used to detect built-in ops.
create(nargs:INT, source:SFILE_ID):SAME is
-- A new definition for a routine or iter with `nargs' arguments
-- (including self).
r::=new(nargs); r.source:=source; return r end;
calls_size:INT is
if void(calls) then return 0 end;
return calls.size end;
is_iter:BOOL is
-- True if an iter.
return sig.is_iter end;
name:IDENT is
-- The Sather name.
return sig.name end;
number_of_args:INT is
-- The number of arguments for this routine or iter
-- (including self).
return size end;
self_local:AM_LOCAL_EXPR is
-- The local variable representing self.
return [0] end;
local_is_hot(l:AM_LOCAL_EXPR):BOOL is
-- True if `l' is a hot argument to an iter.
if ~is_iter or void(sig.hot) then return false end;
i:INT:=0;
loop while!(i<asize);
if SYS::ob_eq([i],l) then return sig.hot[i] end;
i:=i+1 end;
return false end;
arg_local(i:INT):AM_LOCAL_EXPR is
-- The local variable for the `i'th argument. 0 is self, the rest
-- follow in order.
return [i] end;
end;
-------------------------------------------------------------------
type $AM_STMT < $AM, $NEXT{$AM_STMT} is
-- Supertype of statement-like components.
end;
-------------------------------------------------------------------
class AM_STMT is
include AM;
include NEXT{$AM_STMT}; -- The next pointer represents the
-- next statement in the list, if any.
end;
-------------------------------------------------------------------
class AM_ASSIGN_STMT < $AM_STMT is
-- Assignment statment.
include AM_STMT;
attr dest:$AM_EXPR; -- The destination expression.
-- This must be AM_LOCAL_EXPR, AM_GLOBAL_EXPR, AM_ATTR_EXPR,
-- or AM_ARR_EXPR.
attr src:$AM_EXPR; -- The source expression.
end;
-------------------------------------------------------------------
class AM_IF_STMT < $AM_STMT is
-- Conditional statement.
include AM_STMT;
attr test:$AM_EXPR; -- Boolean test expression.
attr if_true:$AM_STMT; -- Statements for true branch.
attr if_false:$AM_STMT; -- Statements for false branch.
end;
-------------------------------------------------------------------
class AM_LOOP_STMT < $AM_STMT is
-- Loop statement.
include AM_STMT;
attr its:FLIST{AM_ITER_CALL_EXPR}; -- A list of the enclosed iters
-- which must be initialized when the loop is entered.
attr bits:FLIST{AM_BND_ITER_CALL_EXPR}; -- A list of the enclosed bound
-- iter calls which must be initialized when the loop is entered.
attr has_yield:BOOL; -- True if there is a "yield" in the
-- loop body (or a nested loop body).
attr body:$AM_STMT; -- The body of the loop.
end;
-------------------------------------------------------------------
class AM_BREAK_STMT < $AM_STMT is
-- Exit the innermost loop. while!, until! and break! get
-- transformed into this.
include AM_STMT;
end;
-------------------------------------------------------------------
class AM_RETURN_STMT < $AM_STMT is
-- Return statement.
include AM_STMT;
attr val:$AM_EXPR; -- The return value, if any.
end;
-------------------------------------------------------------------
class AM_YIELD_STMT < $AM_STMT is
-- Yield statement.
include AM_STMT;
attr ret:INT; -- -1 for quit or the index of the
-- branch to take next.
attr val:$AM_EXPR; -- The return value, if any.
end;
-------------------------------------------------------------------
class AM_CASE_STMT < $AM_STMT is
-- Multi-way branch statement.
include AM_STMT;
attr test:$AM_EXPR; -- Expression to test.
attr tgts:FLIST{FLIST{$AM_CONST}}; -- The target values. Each entry is
-- an array of the targets for the corresponding statement list.
attr stmts:FLIST{$AM_STMT}; -- The statement lists.
attr else_stmts:$AM_STMT; -- The else statements.
attr no_else:BOOL; -- True if there is no "else" part.
end;
-------------------------------------------------------------------
class AM_TYPECASE_STMT < $AM_STMT is
-- Typecase statement.
include AM_STMT;
attr test:AM_LOCAL_EXPR; -- Local variable to test.
attr tgts:FLIST{$TP}; -- The target types.
attr stmts:FLIST{$AM_STMT}; -- The statement lists.
attr else_stmts:$AM_STMT; -- The else statements.
attr has_void_stmts:BOOL; -- True if has void stmts.
attr void_stmts:$AM_STMT; -- Statements to execute if void.
attr no_else:BOOL; -- True if there is no "else" part.
end;
-------------------------------------------------------------------
class AM_PRE_STMT < $AM_STMT is
-- Statement representing a precondition.
include AM_STMT;
attr tp:$TP; -- The type which this is from.
attr test:$AM_EXPR; -- Expression to test.
end;
-------------------------------------------------------------------
class AM_POST_STMT < $AM_STMT is
-- Statement representing a postcondition.
include AM_STMT;
attr tp:$TP; -- The type which this is from.
attr test:$AM_EXPR; -- Expression to test.
end;
-------------------------------------------------------------------
class AM_INITIAL_STMT < $AM_STMT is
-- Statement with initial code for a postcondition.
include AM_STMT;
attr tp:$TP; -- The type which this is from.
attr stmts:$AM_STMT; -- Statements to execute.
end;
-------------------------------------------------------------------
class AM_INVARIANT_STMT < $AM_STMT is
-- Statement representing an invariant check. (If present, this
-- type must define "invariant:BOOL").
include AM_STMT;
attr sig:SIG; -- Signature of the invariant.
end;
-------------------------------------------------------------------
class AM_ASSERT_STMT < $AM_STMT is
-- Assert statement.
include AM_STMT;
attr tp:$TP; -- The type which this is from.
attr test:$AM_EXPR; -- Expression to test.
end;
-------------------------------------------------------------------
class AM_PROTECT_STMT < $AM_STMT is
-- Protect statement.
include AM_STMT;
attr body:$AM_STMT; -- The body of the protect.
attr tgts:FLIST{$TP}; -- The target types for the "whens".
attr stmts:FLIST{$AM_STMT}; -- The statement lists.
attr else_stmts:$AM_STMT; -- The else statements.
attr no_else:BOOL; -- True if there is no "else" part.
end;
-------------------------------------------------------------------
class AM_RAISE_STMT < $AM_STMT is
-- Raise statement.
include AM_STMT;
attr val:$AM_EXPR; -- The exception object.
end;
-------------------------------------------------------------------
class AM_EXPR_STMT < $AM_STMT is
-- An expression used for side-effect.
include AM_STMT;
attr expr:$AM_EXPR; -- The expression to evaluate.
end;
-------------------------------------------------------------------
type $AM_EXPR < $AM is
-- Supertype of expression-like components.
tp:$TP; -- The type of the expression.
end;
-------------------------------------------------------------------
class AM_EXPR is
-- Supertype of expression-like components.
include AM;
end;
-------------------------------------------------------------------
class AM_LOCAL_EXPR < $AM_EXPR is
-- Local variable expression.
include AM_EXPR;
attr is_volatile:BOOL; -- True if the variable must be declared
-- "volatile". This is necessary in protect statments because
-- otherwise longjmp will incorrectly restore the values of locals
-- which happen to be held in registers.
attr name:IDENT; -- The name of the local in the Sather
-- program, if any.
attr tp_at:$TP; -- The declared type of the variable.
attr needs_init:BOOL; -- True if this local must be initialized
-- to 0 at the start of the routine.
attr no_assign:BOOL; -- True if this variable may not be
-- assigned to because it is currently being typecased on.
-- (Used internally).
create(src:SFILE_ID, name:IDENT, tp:$TP):SAME is
r::=new; r.source:=src; r.name:=name; r.tp_at:=tp;
return r end;
is_named:BOOL is
-- True if this is a named local variable.
return ~void(name) end;
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_ARRAY_EXPR < $AM_EXPR is
-- An array creation expression.
include AM_EXPR create->;
include ARRAY{$AM_EXPR}; -- An array of the expressions
-- specifying the values of the array entries. These must be
-- evaluated left to right. The number specifies the size of
-- the created array.
attr tp_at:$TP; -- The type of the array.
create(nargs:INT, source:SFILE_ID):SAME is
-- A new definition for a routine or iter with `nargs' arguments
-- (including self).
r::=new(nargs); r.source:=source; return r end;
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_BND_CREATE_EXPR < $AM_EXPR is
-- Bound routine or iter creation expression.
include AM_EXPR create->;
include ARRAY{$AM_EXPR}; -- An array of expressions for the
-- bound up arguments in order.
attr fun:SIG; -- The routine to bind up.
attr bnd_args:ARRAY{INT}; -- The indices of the arguments
-- which are bound up in order. 0 is self.
attr unbnd_args:ARRAY{INT}; -- The indices of the arguments
-- which are not bound in order. 0 is self.
attr tp_at:$TP; -- The type of the bound expression.
create(nargs:INT, source:SFILE_ID):SAME is
-- A new definition for a routine or iter with `nargs' arguments
-- (including self).
r::=new(nargs); r.source:=source; return r end;
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_IF_EXPR < $AM_EXPR is
-- Conditional expression. Only one of the two branches will be
-- executed.
include AM_EXPR;
attr test:$AM_EXPR; -- The boolean expression to test.
attr if_true:$AM_EXPR; -- Expression with result if true.
attr if_false:$AM_EXPR; -- Expression with result if false.
attr tp_at:$TP; -- The type.
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_NEW_EXPR < $AM_EXPR is
-- New expression.
include AM_EXPR;
attr tp_at:$TP; -- The type of object to allocate.
attr asz:$AM_EXPR; -- Number of array elements to
-- allocate for array descendants.
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_IS_VOID_EXPR < $AM_EXPR is
-- Test for "void".
include AM_EXPR;
attr tp_at:$TP; -- The type BOOL.
attr arg:$AM_EXPR; -- Expression to test for void.
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_GLOBAL_EXPR < $AM_EXPR is
-- Global variable expression.
include AM_EXPR;
attr tp_at:$TP; -- The declared type of the global.
attr name:IDENT; -- The Sather name, if any.
attr class_tp:$TP; -- The class this came from.
attr init:$AM_EXPR; -- The initialization expression, if
-- any. This must consist of only the expression components
-- which are legal for constant initializers.
attr is_const:BOOL; -- True if this is a constant.
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_ATTR_EXPR < $AM_EXPR is
-- An expression referencing an attribute of an object.
include AM_EXPR;
attr ob:$AM_EXPR; -- The object.
attr self_tp:$TP; -- The type of self, perhaps different from ob.tp
-- after inlining.
attr at:IDENT; -- The name of the attribute.
attr tp_at:$TP; -- The type.
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_ARR_EXPR < $AM_EXPR is
-- An expression referencing an array element of an object.
include AM_EXPR;
attr ob:$AM_EXPR; -- The object.
attr ind:$AM_EXPR; -- The array index.
attr tp_at:$TP; -- The type.
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_VATTR_ASSIGN_EXPR < $AM_EXPR is
-- Assignment to an attribute of a value object.
include AM_EXPR;
attr ob:$AM_EXPR; -- The value object.
attr at:IDENT; -- The name of the attribute.
attr val:$AM_EXPR; -- The new value.
tp:$TP is return ob.tp end; -- Returns the object, so has same type.
end;
-------------------------------------------------------------------
class AM_VARR_ASSIGN_EXPR < $AM_EXPR is
-- Assignment to an array element of a value object.
include AM_EXPR;
attr ob:$AM_EXPR; -- The value object.
attr ind:$AM_EXPR; -- The index of the array element.
attr val:$AM_EXPR; -- The new value.
tp:$TP is return ob.tp end; -- Returns the object, so has same type.
end;
-------------------------------------------------------------------
class AM_EXCEPT_EXPR < $AM_EXPR is
-- An expression referring to the exception global.
include AM_EXPR;
attr tp_at:$TP; -- The type.
create(tp:$TP):SAME is
r::=new; r.tp_at:=tp; return r end;
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_STMT_EXPR < $AM_EXPR is
-- An expression with embedded statements.
include AM_EXPR;
attr stmts:$AM_STMT; -- The statements to execute.
attr expr:$AM_EXPR; -- The expression.
tp:$TP is
-- if void(expr) then return void else return expr.tp end end; -- NLP
if void(expr) then return void; end; return expr.tp; end; -- NLP
end;
-------------------------------------------------------------------
type $AM_CALL_EXPR < $AM_EXPR is
-- Supertype for calls.
create(nargs:INT, source:SFILE_ID):$AM_CALL_EXPR;
-- A new definition for a routine or iter with `nargs' arguments
-- (including self).
asize:INT; -- number of args
aget(i:INT):$AM_EXPR; -- argument expressions
end;
-------------------------------------------------------------------
class AM_CALL_EXPR is
-- Supertype for calls.
include AM_EXPR create->;
include ARRAY{$AM_EXPR};
-- An array of argument expressions. These must be evaluated left
-- to right.
create(nargs:INT, source:SFILE_ID):SAME is
-- A new definition for a routine or iter with `nargs' arguments
-- (including self).
r::=new(nargs); r.source:=source; return r end;
end;
-------------------------------------------------------------------
class AM_ROUT_CALL_EXPR < $AM_CALL_EXPR is
-- Routine call expression.
include AM_CALL_EXPR;
attr fun:SIG; -- The signature to call.
tp:$TP is
-- The return type of this routine. Void if no return value.
return fun.ret end;
end;
-------------------------------------------------------------------
class AM_ITER_CALL_EXPR < $AM_CALL_EXPR is
-- Iter call expression.
include AM_CALL_EXPR;
attr fun:SIG; -- The signature to call.
attr init:$AM_STMT; -- Code to execute the first time
-- through (ie. to compute self and the once args).
attr lp:AM_LOOP_STMT; -- The enclosing loop.
tp:$TP is
-- The return type of this iter. Void if no return value.
return fun.ret end;
end;
-------------------------------------------------------------------
class AM_BND_ROUT_CALL_EXPR < $AM_CALL_EXPR is
-- Bound routine call expression.
include AM_CALL_EXPR;
attr br:$AM_EXPR; -- The bound routine to call.
tp:$TP is
-- The return type of the bound routine. Void if none.
brtp::=br.tp;
-- typecase brtp when TP_ROUT then return brtp.ret end end; -- NLP
typecase brtp when TP_ROUT then return brtp.ret; end; return void; end; -- NLP
end;
-------------------------------------------------------------------
class AM_BND_ITER_CALL_EXPR < $AM_CALL_EXPR is
-- Bound iter call expression.
include AM_CALL_EXPR;
attr bi:$AM_EXPR; -- The bound iter to call.
-- Only evaluated the first time through the loop.
attr init:$AM_STMT; -- Code to execute the first time
-- through (ie. to compute self and the once args).
attr lp:AM_LOOP_STMT; -- The enclosing loop.
tp:$TP is
-- The return type of the bound iter. Void if none.
bitp::=bi.tp;
-- typecase bitp when TP_ITER then return bitp.ret end end; -- NLP
typecase bitp when TP_ITER then return bitp.ret; end; return void; end; -- NLP
end;
-------------------------------------------------------------------
class AM_EXT_CALL_EXPR < $AM_CALL_EXPR is
-- A call on a function defined in an external language. These
-- are the signatures in an external class with no body.
-- Does assignment of the result to a local. Target is void
-- for calls with no return value.
include AM_CALL_EXPR;
attr fun:SIG; -- The signature to call.
attr nm:IDENT; -- The name of the routine
create(nargs:INT, source:SFILE_ID, nm:IDENT):SAME is
r::=create(nargs,source);
r.nm:=nm;
return r;
end;
ext_tp:$TP is
-- The class containing this routine.
return fun.tp end;
tp:$TP is
-- The return type of this routine. Void if no return value.
return fun.ret end;
end;
-------------------------------------------------------------------
type $AM_CONST < $AM_EXPR is
-- Supertype for compiler constants.
end;
-------------------------------------------------------------------
class AM_CONST < $AM_CONST is
-- Implementation to be included by $AM_CONST nodes.
include AM_EXPR;
attr tp_at:$TP;
tp:$TP is return tp_at end;
end;
-------------------------------------------------------------------
class AM_VOID_CONST < $AM_CONST is
-- Representation of "void".
include AM_CONST;
end;
-------------------------------------------------------------------
class AM_ARR_CONST < $AM_CONST is
-- Representation of constant ARRAY{T} objects.
include AM_CONST;
attr elt_tp:TP_CLASS; -- The type of the contained elements.
attr elts:ARRAY{$AM_CONST}; -- The array elements.
end;
-------------------------------------------------------------------
class AM_BOOL_CONST < $AM_CONST is
-- Representation of constant BOOL's.
include AM_CONST;
attr val:BOOL; -- The boolean value.
create(src:SFILE_ID):SAME is
-- Create a new boolean constant with source `src'.
r::=new; r.source:=src; return r end;
end;
-------------------------------------------------------------------
class AM_CHAR_CONST < $AM_CONST is
-- Representation of constant CHAR objects. Uses `bval' if the program
-- being compiled uses the same sized characters as the compiler,
-- val otherwise. Can tell by checking whether `val' is void.
include AM_CONST;
attr bval:CHAR; -- The character, if the compiled
-- program uses the same representation as the compiler.
attr val:INTI; -- The value of the char, if non-void.
create(t:TR_CHAR_LIT_EXPR):SAME is
-- Create a new character constant for the tree form `t'. Must
-- change this if the target has a different format.
r::=new; r.source:=t.source; r.bval:=t.val.char; return r end;
end;
-------------------------------------------------------------------
class AM_STR_CONST < $AM_CONST is
-- Representation of constant strings.
include AM_CONST;
attr bval:STR; -- The string if the compiler's are
-- the same as the compiled program.
create:SAME is return new; end;
create(t:TR_STR_LIT_EXPR):SAME is
-- Create a string constant for tree form `t'. Must change this
-- if the target has a different format.
r::=new; r.source:=t.source; r.bval:=t.s; return r end;
create_from_str(src:SFILE_ID, str:STR):SAME is
-- Create a string constant for tree form `t'. Must change this
-- if the target has a different format.
r::=new; r.source:=src; r.bval:=str; return r end;
end;
-------------------------------------------------------------------
class AM_INT_CONST < $AM_CONST is
-- Representation of constant INT objects. Uses `bval' if the program
-- being compiled uses the same sized integers as the compiler,
-- val otherwise. Can tell by checking whether `val' is void.
include AM_CONST;
attr val:INTI; -- The bits of the integer, if non-void.
create(t:TR_INT_LIT_EXPR):SAME is
-- Create a new integer constant for the tree form `t'. Must
-- change this is the target has a different format.
r::=new; r.source:=t.source; r.val:=t.val; return r end;
end;
-------------------------------------------------------------------
class AM_INTI_CONST < $AM_CONST is
-- Representation of constant INTI objects.
include AM_CONST;
attr val:INTI; -- The integer.
create(t:TR_INT_LIT_EXPR):SAME is
-- Create a new infinite precision integer constant for the
-- tree form `t'
r::=new; r.source:=t.source; r.val:=t.val; return r end;
end;
-------------------------------------------------------------------
class AM_FLT_CONST < $AM_CONST is
-- Representation of constant FLT objects.
include AM_CONST;
attr val:RAT; -- The value.
create(t:TR_FLT_LIT_EXPR):SAME is
-- Create a new floating point constant for the tree form `t'.
r::=new; r.source:=t.source; r.val:=t.val;
return r end;
end;
-------------------------------------------------------------------
class AM_FLTD_CONST < $AM_CONST is
-- Representation of constant FLTD objects.
include AM_CONST;
attr val:RAT; -- The value.
create(t:TR_FLT_LIT_EXPR):SAME is
-- Create a new floating point constant for the tree form `t'.
r::=new; r.source:=t.source; r.val:=t.val;
return r end;
end;
-------------------------------------------------------------------
class AM_FLTX_CONST < $AM_CONST is
-- Representation of constant FLTX objects by their mantissa and
-- exponent.
include AM_CONST;
attr val:RAT; -- The value.
create(t:TR_FLT_LIT_EXPR):SAME is
-- Create a new floating point constant for the tree form `t'.
r::=new; r.source:=t.source; r.val:=t.val;
return r end;
end;
-------------------------------------------------------------------
class AM_FLTDX_CONST < $AM_CONST is
-- Representation of constant FLTDX objects by their mantissa and
-- exponent.
include AM_CONST;
attr val:RAT; -- The value.
create(t:TR_FLT_LIT_EXPR):SAME is
-- Create a new floating point constant for the tree form `t'.
r::=new; r.source:=t.source; r.val:=t.val;
return r end;
end;
-------------------------------------------------------------------
class AM_FLTI_CONST < $AM_CONST is
-- Representation of constant FLTI objects by their mantissa and
-- exponent.
include AM_CONST;
attr val:RAT; -- The value.
create(t:TR_FLT_LIT_EXPR):SAME is
-- Create a new floating point constant for the tree form `t'.
r::=new; r.source:=t.source; r.val:=t.val;
return r end;
end;
-------------------------------------------------------------------