aa
com.cliffc.aa.HM.HM1 Class Reference

Hindley-Milner typing. More...

Classes

class  Apply
 
class  Con
 
class  HMType
 
class  HMVar
 
class  Ident
 
class  Lambda
 
class  Lambda2
 
class  Let
 
class  Oper
 
class  Syntax
 

Static Public Member Functions

static HMType HM (Syntax prog)
 

Static Package Functions

static void reset ()
 

Detailed Description

Hindley-Milner typing.

A Java clone from: http://dysphoria.net/code/hindley-milner/HindleyMilner.scala Andrew Forrest Based heavily on Nikita Borisov's Perl implementation at http://web.archive.org/web/20050420002559/www.cs.berkeley.edu/~nikitab/courses/cs263/hm.html which in turn is based on the paper by Luca Cardelli at http://lucacardelli.name/Papers/BasicTypechecking.pdf

Complete stand-alone, for my research. MEETs base types, instead of declaring type error. Does standard lexical scoping, which is not needed for SSA form.

Definition at line 23 of file HM1.java.

Member Function Documentation

◆ HM()

static HMType com.cliffc.aa.HM.HM1.HM ( Syntax  prog)
static

Definition at line 24 of file HM1.java.

24  {
25  HashMap<String,HMType> env = new HashMap<>();
26  // Simple types
27  HMVar bool = new HMVar(TypeInt.BOOL);
28  HMVar int64 = new HMVar(TypeInt.INT64);
29  HMVar flt64 = new HMVar(TypeFlt.FLT64);
30  HMVar strp = new HMVar(TypeMemPtr.STRPTR);
31 
32  // Primitives
33  HMVar var1 = new HMVar();
34  HMVar var2 = new HMVar();
35  env.put("pair",Oper.fun(var1, Oper.fun(var2, new Oper("pair",var1,var2))));
36 
37  HMVar var3 = new HMVar();
38  env.put("if/else" ,Oper.fun(bool,Oper.fun(var3,Oper.fun(var3,var3))));
39  env.put("if/else3",Oper.fun(bool, var3, var3,var3 ));
40 
41  env.put("dec",Oper.fun(int64,int64));
42  env.put("*" ,Oper.fun(int64,Oper.fun(int64,int64)));
43  env.put("*2" ,Oper.fun(int64, int64,int64 ));
44  env.put("==0",Oper.fun(int64,bool));
45 
46  // Convert integer to a string; int->str
47  env.put("str",Oper.fun(int64,strp));
48  // Floating point Factor; sorta like {div/mod}
49  env.put("factor",Oper.fun(flt64,new Oper("pair",flt64,flt64)));
50 
51  return prog.hm(env, new HashSet<>());
52  }

References com.cliffc.aa.type.TypeInt.BOOL, com.cliffc.aa.type.TypeFlt.FLT64, com.cliffc.aa.HM.HM1.Oper.fun(), com.cliffc.aa.HM.HM1.Syntax.hm(), com.cliffc.aa.type.TypeInt.INT64, and com.cliffc.aa.type.TypeMemPtr.STRPTR.

Referenced by com.cliffc.aa.HM.TestHM1.test0(), com.cliffc.aa.HM.TestHM1.test1(), com.cliffc.aa.HM.TestHM1.test10(), com.cliffc.aa.HM.TestHM1.test13(), com.cliffc.aa.HM.TestHM1.test17(), com.cliffc.aa.HM.TestHM1.test18(), com.cliffc.aa.HM.TestHM1.test2(), com.cliffc.aa.HM.TestHM1.test20(), com.cliffc.aa.HM.TestHM1.test23(), com.cliffc.aa.HM.TestHM1.test3(), com.cliffc.aa.HM.TestHM1.test4(), com.cliffc.aa.HM.TestHM1.test5(), com.cliffc.aa.HM.TestHM1.test6(), com.cliffc.aa.HM.TestHM1.test7(), and com.cliffc.aa.HM.TestHM1.test8().

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

◆ reset()

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

Definition at line 53 of file HM1.java.

53 { HMVar.reset(); }

References com.cliffc.aa.HM.HM1.HMVar.reset().

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

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

The documentation for this class was generated from the following file:
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.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