aa
com.cliffc.aa.HM.HM5 Class Reference
Collaboration diagram for com.cliffc.aa.HM.HM5:
[legend]

Classes

class  Apply
 
class  Con
 
class  Ident
 
class  Lambda
 
class  Lambda2
 
class  Let
 
class  Syntax
 
class  T2
 
class  VStack
 
class  Worklist
 

Static Public Member Functions

static T2 hm (Syntax prog)
 

Static Package Functions

static void reset ()
 

Static Package Attributes

static boolean DEBUG_LEAKS =false
 
static final HashMap< String, T2PRIMS = new HashMap<>()
 

Detailed Description

Definition at line 23 of file HM5.java.

Member Function Documentation

◆ hm()

static T2 com.cliffc.aa.HM.HM5.hm ( Syntax  prog)
static

Definition at line 27 of file HM5.java.

27  {
28  Worklist work = new Worklist();
29 
30  // Simple types
31  T2 bool = T2.make_base(TypeInt.BOOL);
32  T2 int64 = T2.make_base(TypeInt.INT64);
33  T2 flt64 = T2.make_base(TypeFlt.FLT64);
34  T2 strp = T2.make_base(TypeMemPtr.STRPTR);
35 
36  // Primitives
37  T2 var1 = T2.make_leaf();
38  T2 var2 = T2.make_leaf();
39 
40  PRIMS.put("pair1",T2.make_fun(var1, T2.make_fun(var2, T2.prim("pair",var1,var2) )));
41  PRIMS.put("pair",T2.make_fun(var1, var2, T2.prim("pair",var1,var2) ));
42 
43  PRIMS.put("if/else",T2.make_fun(bool,var1,var1,var1));
44 
45  PRIMS.put("dec",T2.make_fun(int64,int64));
46  PRIMS.put("*" ,T2.make_fun(int64,int64,int64));
47  PRIMS.put("==0",T2.make_fun(int64,bool));
48  PRIMS.put("isempty",T2.make_fun(strp,bool));
49 
50  // Print a string; int->str
51  PRIMS.put("str",T2.make_fun(int64,strp));
52  // Factor; FP div/mod-like operation
53  PRIMS.put("factor",T2.make_fun(flt64,T2.prim("divmod",flt64,flt64)));
54 
55  // Prep for SSA: pre-gather all the (unique) ids
56  int cnt_syns = prog.prep_tree(null,null,work);
57  int init_T2s = T2.CNT;
58 
59  int cnt=0, DEBUG_CNT=-1;
60  while( work.len()>0 ) { // While work
61  int oldcnt = T2.CNT; // Used for cost-check when no-progress
62  Syntax syn = work.pop(); // Get work
63  T2 old = syn._t; // Old value for progress assert
64  if( cnt==DEBUG_CNT )
65  System.out.println("break here");
66  if( syn.hm(work) ) { // Compute a new HM type and check for progress
67  assert !syn.debug_find().unify(old.find(),null);// monotonic: unifying with the result is no-progress
68  syn.add_kids(work); // Push children on worklist
69  syn.add_occurs(work); // Push occurs-check ids on worklist
70  if( syn._par !=null ) work.push(syn._par); // Parent updates
71  } else {
72  assert !DEBUG_LEAKS || oldcnt==T2.CNT; // No-progress consumes no-new-T2s
73  }
74  // VERY EXPENSIVE ASSERT: O(n^2). Every Syntax that makes progress is on the worklist
75  //assert prog.more_work(work);
76  cnt++;
77  }
78  assert prog.more_work(work);
79 
80  //System.out.println("Initial T2s: "+init_T2s+", Prog size: "+cnt_syns+", worklist iters: "+cnt+", T2s: "+T2.CNT);
81  return prog._t;
82  }

References com.cliffc.aa.HM.HM5.Syntax._par, com.cliffc.aa.HM.HM5.Syntax._t, com.cliffc.aa.HM.HM5.Syntax.add_kids(), com.cliffc.aa.HM.HM5.Syntax.add_occurs(), com.cliffc.aa.type.TypeInt.BOOL, com.cliffc.aa.HM.HM5.T2.CNT, com.cliffc.aa.HM.HM5.Syntax.debug_find(), com.cliffc.aa.HM.HM5.DEBUG_LEAKS, com.cliffc.aa.HM.HM5.T2.find(), com.cliffc.aa.type.TypeFlt.FLT64, com.cliffc.aa.HM.HM5.Syntax.hm(), com.cliffc.aa.type.TypeInt.INT64, com.cliffc.aa.HM.HM5.Worklist.len(), com.cliffc.aa.HM.HM5.T2.make_base(), com.cliffc.aa.HM.HM5.T2.make_fun(), com.cliffc.aa.HM.HM5.T2.make_leaf(), com.cliffc.aa.HM.HM5.Syntax.more_work(), com.cliffc.aa.HM.HM5.Worklist.pop(), com.cliffc.aa.HM.HM5.Syntax.prep_tree(), com.cliffc.aa.HM.HM5.T2.prim(), com.cliffc.aa.HM.HM5.PRIMS, com.cliffc.aa.HM.HM5.Worklist.push(), com.cliffc.aa.type.TypeMemPtr.STRPTR, and com.cliffc.aa.HM.HM5.T2.unify().

Referenced by com.cliffc.aa.HM.TestHM5.test00(), com.cliffc.aa.HM.TestHM5.test01(), com.cliffc.aa.HM.TestHM5.test02(), com.cliffc.aa.HM.TestHM5.test03(), com.cliffc.aa.HM.TestHM5.test04(), com.cliffc.aa.HM.TestHM5.test05(), com.cliffc.aa.HM.TestHM5.test06(), com.cliffc.aa.HM.TestHM5.test07(), com.cliffc.aa.HM.TestHM5.test08(), com.cliffc.aa.HM.TestHM5.test09(), com.cliffc.aa.HM.TestHM5.test10(), com.cliffc.aa.HM.TestHM5.test11(), com.cliffc.aa.HM.TestHM5.test12(), com.cliffc.aa.HM.TestHM5.test13(), com.cliffc.aa.HM.TestHM5.test14(), com.cliffc.aa.HM.TestHM5.test15(), com.cliffc.aa.HM.TestHM5.test16(), com.cliffc.aa.HM.TestHM5.test17(), com.cliffc.aa.HM.TestHM5.test18(), com.cliffc.aa.HM.TestHM5.test19(), com.cliffc.aa.HM.TestHM5.test20(), com.cliffc.aa.HM.TestHM5.test21(), com.cliffc.aa.HM.TestHM5.test22(), and com.cliffc.aa.HM.TestHM5.test23().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

static void com.cliffc.aa.HM.HM5.reset ( )
staticpackage

Definition at line 83 of file HM5.java.

83 { PRIMS.clear(); T2.reset(); }

References com.cliffc.aa.HM.HM5.PRIMS, and com.cliffc.aa.HM.HM5.T2.reset().

Referenced by com.cliffc.aa.HM.TestHM5.reset().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ DEBUG_LEAKS

boolean com.cliffc.aa.HM.HM5.DEBUG_LEAKS =false
staticpackage

Definition at line 25 of file HM5.java.

Referenced by com.cliffc.aa.HM.HM5.T2.fresh_unify(), and com.cliffc.aa.HM.HM5.hm().

◆ PRIMS

final HashMap<String,T2> com.cliffc.aa.HM.HM5.PRIMS = new HashMap<>()
staticpackage

The documentation for this class was generated from the following file:
com.cliffc.aa.HM.HM5.PRIMS
static final HashMap< String, T2 > PRIMS
Definition: HM5.java:24
com.cliffc.aa.type.TypeInt
Definition: TypeInt.java:9
com.cliffc.aa.type.TypeFlt
Definition: TypeFlt.java:9
com.cliffc.aa.type.TypeInt.INT64
static final TypeInt INT64
Definition: TypeInt.java:39
com.cliffc.aa.HM.HM5.DEBUG_LEAKS
static boolean DEBUG_LEAKS
Definition: HM5.java:25
com.cliffc.aa.type.TypeMemPtr.STRPTR
static final TypeMemPtr STRPTR
Definition: TypeMemPtr.java:97
com.cliffc.aa.type.TypeInt.BOOL
static final TypeInt BOOL
Definition: TypeInt.java:43
com.cliffc.aa.type.TypeMemPtr
Definition: TypeMemPtr.java:14
com.cliffc.aa.type.TypeFlt.FLT64
static final TypeFlt FLT64
Definition: TypeFlt.java:38