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

Classes

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

Static Public Member Functions

static T2 hm (Syntax prog)
 

Static Package Functions

static void reset ()
 

Static Package Attributes

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

Detailed Description

Definition at line 19 of file HM4.java.

Member Function Documentation

◆ hm()

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

Definition at line 22 of file HM4.java.

22  {
23  Ary<Syntax> work = new Ary<>(Syntax.class);
24 
25  // Simple types
26  T2 bool = T2.base(TypeInt.BOOL);
27  T2 int64 = T2.base(TypeInt.INT64);
28  T2 flt64 = T2.base(TypeFlt.FLT64);
29  T2 strp = T2.base(TypeMemPtr.STRPTR);
30 
31  // Primitives
32  T2 var1 = T2.tnew();
33  T2 var2 = T2.tnew();
34 
35  PRIMS.put("pair" ,T2.fresh("TOP",T2.fun(var1, T2.fun(var2, T2.prim("pair" ,var1,var2)))));
36  PRIMS.put("pair2",T2.fresh("TOP",T2.fun(var1, var2, T2.prim("pair2",var1,var2) )));
37 
38  //PRIMS.put("if/else" ,new HMT(T2.fun(bool,T2.fun(var1,T2.fun(var1,var1)))));
39  PRIMS.put("if/else3",T2.fresh("TOP",T2.fun(bool,var1,var1,var1)));
40 
41  PRIMS.put("dec",T2.fresh("TOP",T2.fun(int64,int64)));
42  PRIMS.put("*" ,T2.fresh("TOP",T2.fun(int64,T2.fun(int64,int64))));
43  PRIMS.put("*2" ,T2.fresh("TOP",T2.fun(int64,int64,int64)));
44  PRIMS.put("==0",T2.fresh("TOP",T2.fun(int64,bool)));
45  PRIMS.put("isempty",T2.fresh("TOP",T2.fun(strp,bool)));
46 
47  // Print a string; int->str
48  PRIMS.put("str",T2.fresh("TOP",T2.fun(int64,strp)));
49  // Factor; FP div/mod-like operation
50  PRIMS.put("factor",T2.fresh("TOP",T2.fun(flt64,T2.prim("divmod",flt64,flt64))));
51 
52  // Prep for SSA: pre-gather all the (unique) ids
53  prog.prep_tree(null,work);
54 
55  int cnt=0;
56  while( !work.isEmpty() ) { // While work
57  Syntax syn = work.del(cnt%work._len); // Get work
58  T2 t = syn.hm(work); // Get work results
59  T2 tsyn = syn.find();
60  if( t!=tsyn ) { // Progress?
61  assert !t.progress(tsyn); // monotonic: unifying with the result is no-progress
62  syn._t=t; // Progress!
63  if( syn._par !=null ) work.push(syn._par); // Parent updates
64  }
65  // VERY EXPENSIVE ASSERT: O(n^2). Every Syntax that makes progress is on the worklist
66  //assert prog.more_work(work);
67  cnt++;
68  }
69  assert prog.more_work(work);
70  return prog._t;
71  }

References com.cliffc.aa.util.Ary< E >._len, com.cliffc.aa.HM.HM4.Syntax._par, com.cliffc.aa.HM.HM4.Syntax._t, com.cliffc.aa.HM.HM4.T2.base(), com.cliffc.aa.type.TypeInt.BOOL, com.cliffc.aa.util.Ary< E >.del(), com.cliffc.aa.HM.HM4.Syntax.find(), com.cliffc.aa.type.TypeFlt.FLT64, com.cliffc.aa.HM.HM4.T2.fresh(), com.cliffc.aa.HM.HM4.T2.fun(), com.cliffc.aa.HM.HM4.Syntax.hm(), com.cliffc.aa.type.TypeInt.INT64, com.cliffc.aa.util.Ary< E >.isEmpty(), com.cliffc.aa.HM.HM4.Syntax.more_work(), com.cliffc.aa.HM.HM4.Syntax.prep_tree(), com.cliffc.aa.HM.HM4.T2.prim(), com.cliffc.aa.HM.HM4.PRIMS, com.cliffc.aa.HM.HM4.T2.progress(), com.cliffc.aa.util.Ary< E >.push(), com.cliffc.aa.type.TypeMemPtr.STRPTR, and com.cliffc.aa.HM.HM4.T2.tnew().

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

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

◆ reset()

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

Definition at line 72 of file HM4.java.

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

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

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

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

Member Data Documentation

◆ PRIMS

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

The documentation for this class was generated from the following file:
com.cliffc.aa.util.Ary.push
E push(E e)
Add element in amortized constant time.
Definition: Ary.java:58
com.cliffc.aa.util.Ary.isEmpty
boolean isEmpty()
Definition: Ary.java:20
com.cliffc.aa.type.TypeInt
Definition: TypeInt.java:9
com.cliffc.aa.type.TypeFlt
Definition: TypeFlt.java:9
com.cliffc.aa.util.Ary
Definition: Ary.java:11
com.cliffc.aa.util.Ary._len
int _len
Definition: Ary.java:13
com.cliffc.aa.type.TypeInt.INT64
static final TypeInt INT64
Definition: TypeInt.java:39
com.cliffc.aa.util.Ary.del
E del(int i)
Fast, constant-time, element removal.
Definition: Ary.java:78
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
com.cliffc.aa.HM.HM4.PRIMS
static final HashMap< String, T2 > PRIMS
Definition: HM4.java:20