aa
TypeFunSig.java
Go to the documentation of this file.
1 package com.cliffc.aa.type;
2 
3 import com.cliffc.aa.util.SB;
4 import com.cliffc.aa.util.Util;
5 import com.cliffc.aa.util.VBitSet;
6 import static com.cliffc.aa.AA.*;
7 
8 // Function signatures: formal arguments (and return) used to type-check. This
9 // is NOT any "code pointer" or "function index" or "fidx"; see TypeFunPtr.
10 public final class TypeFunSig extends Type<TypeFunSig> {
11  // Formal 0 is the Memory type, using TypeObj.ISUSED for ignored memory state.
12  // Formal 1 is the Display pointer.
13  // Formals 2-N are the normal arguments.
14  public String[] _args; // " mem", "^", ....
15  public TypeTuple _formals; // Control0, Memory1, Display2, Arg3, Arg4, ...
16  public TypeTuple _ret; // Control0, Memory1, Result2
17 
18  private TypeFunSig init (String[] args, TypeTuple formals, TypeTuple ret ) {
19  super.init(TFUNSIG,"");
20  assert args.length>=formals.len();
21  assert (args[CTL_IDX]==null || Util.eq(args[CTL_IDX]," ctl")) && (formals.at(CTL_IDX)==Type.CTRL || formals.at(CTL_IDX)==Type.XCTRL);
22  assert (args[MEM_IDX]==null || Util.eq(args[MEM_IDX]," mem")) && (formals.at(MEM_IDX) instanceof TypeMem || formals.at(MEM_IDX)==Type.ALL || formals.at(MEM_IDX)==Type.ANY);
23  assert (args[DSP_IDX]==null || Util.eq(args[DSP_IDX],"^" )) && formals.at(DSP_IDX).is_display_ptr();
24  assert ret.len()==3 && ret.at(MEM_IDX) instanceof TypeMem;
25  _args=args;
26  _formals=formals;
27  _ret=ret;
28  return this;
29  }
30  @Override int compute_hash() {
31  assert _formals._hash != 0;
32  int hash=TFUNSIG + _formals._hash + _ret._hash;
33  for( int i=0; i<_args.length; i++ ) i+=_args[i].hashCode();
34  return hash==0 ? 3 : hash;
35  }
36 
37  @Override public boolean equals( Object o ) {
38  if( this==o ) return true;
39  if( !(o instanceof TypeFunSig) ) return false;
40  TypeFunSig tf = (TypeFunSig)o;
41  if( _formals!=tf._formals || _ret!=tf._ret || _args.length!=tf._args.length ) return false;
42  if( _args == tf._args ) return true;
43  for( int i=0; i<_args.length; i++ )
44  if( !Util.eq(_args[i],tf._args[i]) )
45  return false;
46  return true;
47  }
48  @Override public boolean cycle_equals( Type o ) { return equals(o); }
49 
50  @Override public SB str( SB sb, VBitSet dups, TypeMem mem, boolean debug ) {
51  if( debug ) sb.p('_').p(_uid);
52  sb.p(_name);
53  sb.p('{');
54  boolean field_sep=false;
55  for( int i=0; i<nargs(); i++ ) {
56  if( !debug && i==CTL_IDX && Util.eq(_args[CTL_IDX]," ctl") ) continue; // Do not print the Control
57  if( !debug && i==MEM_IDX && Util.eq(_args[MEM_IDX]," mem") ) continue; // Do not print the memory
58  if( !debug && i==DSP_IDX && Util.eq(_args[DSP_IDX],"^" ) ) continue; // Do not print the ever-present display
59  sb.p(_args[i]);
60  if( arg(i) != Type.SCALAR )
61  arg(i).str(sb.p(':'),dups,mem,debug);
62  sb.p(" "); field_sep=true;
63  }
64  if( field_sep ) sb.unchar();
65  sb.p(" -> ");
66  if( _ret != Type.SCALAR ) _ret.str(sb,dups,mem,debug);
67  return sb.p('}');
68  }
69 
70  static { new Pool(TFUNSIG,new TypeFunSig()); }
71  public static TypeFunSig make( String[] args, TypeTuple formals, TypeTuple ret ) {
72  TypeFunSig t1 = POOLS[TFUNSIG].malloc();
73  return t1.init(args,formals,ret).hashcons_free();
74  }
75 
76  public static TypeFunSig make( TypeTuple ret, Type[] ts ) { return make(func_names,TypeTuple.make_args(ts),ret); }
77  public static TypeFunSig make( TypeTuple ret, TypeMemPtr disp, Type arg1 ) { return make(ret,Types.ts(disp,arg1)); }
78  public static TypeFunSig make( TypeTuple ret, TypeMemPtr disp, Type arg1, Type arg2 ) { return make(ret,Types.ts(disp,arg1,arg2)); }
79  public static TypeFunSig make( TypeTuple ret, TypeTuple formals ) { return make(func_names,formals,ret); }
80  public TypeFunSig make_from_arg( int idx, Type arg ) { return make(_args,_formals.make_from_arg(idx,arg),_ret); }
81 
82  public static final String[] func_names = new String[]{" ctl", " mem", "^" , "arg3", "arg4", "arg5" }; // TODO: Extend as needed
83 
85  static final TypeFunSig[] TYPES = new TypeFunSig[]{II_I};
86 
87  public int nargs() { return _formals._ts.length; }
88  public Type arg(int idx) { return _formals._ts[idx]; }
89  public Type display() { return arg(DSP_IDX); }
90 
91  @Override protected TypeFunSig xdual() { return new TypeFunSig().init(_args,_formals.dual(),_ret.dual()); }
92  @Override protected Type xmeet( Type t ) {
93  switch( t._type ) {
94  case TFUNSIG: break;
95  case TFUNPTR:
96  return ALL; // Not supposed to mix TypeFunPtr and TypeFunSig
97  case TARY:
98  case TFLT:
99  case TINT:
100  case TLIVE:
101  case TMEM:
102  case TMEMPTR:
103  case TOBJ:
104  case TRPC:
105  case TSTR:
106  case TSTRUCT:
107  case TTUPLE:
108  return ALL;
109  default: throw typerr(t); // All else should not happen
110  }
111  TypeFunSig tf = (TypeFunSig)t;
113  }
114 
115  @Override public boolean above_center() { return _formals.above_center(); }
116  @Override public boolean may_be_con() { return above_center(); }
117  @Override public boolean is_con() { return false; }
118  @Override public boolean must_nil() { return false; }
119  @Override public boolean may_nil() { return false; }
120  @Override Type not_nil() { return this; }
121  @Override public Type meet_nil(Type nil) { return Type.SCALAR; }
122  @Override public byte isBitShape(Type t) { return 99; }
123 }
com.cliffc.aa.type.Type< TypeFunSig >::TLIVE
static final byte TLIVE
Definition: Type.java:276
com.cliffc.aa.type.TypeFunSig.meet_nil
Type meet_nil(Type nil)
Definition: TypeFunSig.java:121
com.cliffc.aa.type.TypeFunSig.xmeet
Type xmeet(Type t)
Definition: TypeFunSig.java:92
com.cliffc.aa.type.Type< TypeFunSig >::TMEMPTR
static final byte TMEMPTR
Definition: Type.java:273
com.cliffc.aa.type.TypeTuple.make_args
static TypeTuple make_args(Type[] ts)
Definition: TypeTuple.java:106
com.cliffc.aa.type.TypeTuple.make_from_arg
TypeTuple make_from_arg(int idx, Type arg)
Definition: TypeTuple.java:110
com.cliffc.aa.type.Type< TypeFunSig >::typerr
RuntimeException typerr(Type t)
Definition: Type.java:947
com.cliffc.aa.type.TypeMem
Memory type; the state of all of memory; memory edges order memory ops.
Definition: TypeMem.java:53
com.cliffc.aa.type.TypeTuple.make_ret
static TypeTuple make_ret(Type trez)
Definition: TypeTuple.java:120
com.cliffc.aa.util.Util.eq
static boolean eq(String s0, String s1)
Definition: Util.java:16
com.cliffc.aa.type.TypeFunSig.compute_hash
int compute_hash()
Definition: TypeFunSig.java:30
com.cliffc.aa.type.Type.SCALAR
static final Type SCALAR
Definition: Type.java:328
com.cliffc
com.cliffc.aa.type.Type._hash
int _hash
Definition: Type.java:97
com.cliffc.aa.type.TypeFunSig.cycle_equals
boolean cycle_equals(Type o)
Definition: TypeFunSig.java:48
com.cliffc.aa.type.TypeTuple.above_center
boolean above_center()
Definition: TypeTuple.java:193
com.cliffc.aa.util
Definition: AbstractEntry.java:1
com.cliffc.aa.type.TypeInt
Definition: TypeInt.java:9
com.cliffc.aa.type.TypeFunSig.init
TypeFunSig init(String[] args, TypeTuple formals, TypeTuple ret)
Definition: TypeFunSig.java:18
com.cliffc.aa.type.Type
an implementation of language AA
Definition: Type.java:94
com.cliffc.aa.type.TypeFunSig.make
static TypeFunSig make(String[] args, TypeTuple formals, TypeTuple ret)
Definition: TypeFunSig.java:71
com.cliffc.aa.type.Type< TypeFunSig >::hashCode
final int hashCode()
Definition: Type.java:106
com.cliffc.aa.type.Type< TypeFunSig >::TSTR
static final byte TSTR
Definition: Type.java:270
com.cliffc.aa.type.TypeTuple.str
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
Definition: TypeTuple.java:65
com.cliffc.aa.type.TypeTuple
Definition: TypeTuple.java:11
com.cliffc.aa.type.Type._type
byte _type
Definition: Type.java:98
com.cliffc.aa.type.TypeFunSig.above_center
boolean above_center()
Definition: TypeFunSig.java:115
com.cliffc.aa.type.TypeFunSig.func_names
static final String[] func_names
Definition: TypeFunSig.java:82
com.cliffc.aa.type.Type.ANY
static final Type ANY
Definition: Type.java:325
com.cliffc.aa.type.Type.meet
final Type meet(Type t)
Definition: Type.java:412
com.cliffc.aa.type.Type.str
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
Definition: Type.java:131
com.cliffc.aa.type.Type< TypeFunSig >::TFUNPTR
static final byte TFUNPTR
Definition: Type.java:274
com.cliffc.aa.type.Type< TypeFunSig >::TINT
static final byte TINT
Definition: Type.java:263
com.cliffc.aa.type.TypeFunSig.str
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
Definition: TypeFunSig.java:50
com.cliffc.aa.type.Types
Definition: Types.java:9
com.cliffc.aa.util.SB.unchar
SB unchar()
Definition: SB.java:58
com.cliffc.aa.type.Types.ts
static Type[] ts(Type t0)
Definition: Types.java:90
com.cliffc.aa.type.Type.ALL
static final Type ALL
Definition: Type.java:324
com.cliffc.aa.type.TypeFunSig._ret
TypeTuple _ret
Definition: TypeFunSig.java:16
com.cliffc.aa.type.Type< TypeFunSig >::TMEM
static final byte TMEM
Definition: Type.java:272
com.cliffc.aa.type.TypeFunSig._args
String[] _args
Definition: TypeFunSig.java:14
com.cliffc.aa.type.TypeFunSig.xdual
TypeFunSig xdual()
Definition: TypeFunSig.java:91
com.cliffc.aa.type.Type< TypeFunSig >::TTUPLE
static final byte TTUPLE
Definition: Type.java:266
com.cliffc.aa.type.TypeFunSig.arg
Type arg(int idx)
Definition: TypeFunSig.java:88
com.cliffc.aa.type.TypeInt.INT64
static final TypeInt INT64
Definition: TypeInt.java:39
com.cliffc.aa.type.TypeFunSig.nargs
int nargs()
Definition: TypeFunSig.java:87
com.cliffc.aa.type.Type< TypeFunSig >::TSTRUCT
static final byte TSTRUCT
Definition: Type.java:268
com.cliffc.aa.type.TypeFunSig.may_nil
boolean may_nil()
Definition: TypeFunSig.java:119
com.cliffc.aa.util.Util
Definition: Util.java:5
com.cliffc.aa.type.Type.CTRL
static final Type CTRL
Definition: Type.java:326
com.cliffc.aa.type.TypeTuple.len
int len()
Definition: TypeTuple.java:183
com.cliffc.aa.type.TypeFunSig.make
static TypeFunSig make(TypeTuple ret, TypeMemPtr disp, Type arg1)
Definition: TypeFunSig.java:77
com.cliffc.aa.type.Type.XCTRL
static final Type XCTRL
Definition: Type.java:327
com.cliffc.aa.type.Type< TypeFunSig >::TRPC
static final byte TRPC
Definition: Type.java:265
com.cliffc.aa.util.VBitSet
Definition: VBitSet.java:5
com.cliffc.aa.type.TypeFunSig.make_from_arg
TypeFunSig make_from_arg(int idx, Type arg)
Definition: TypeFunSig.java:80
com.cliffc.aa.type.Type.hashcons_free
final T hashcons_free()
Definition: Type.java:153
com.cliffc.aa.util.SB
Tight/tiny StringBuilder wrapper.
Definition: SB.java:8
com.cliffc.aa.type.TypeFunSig.equals
boolean equals(Object o)
Definition: TypeFunSig.java:37
com.cliffc.aa.AA
an implementation of language AA
Definition: AA.java:9
com.cliffc.aa.type.Type.is_display_ptr
boolean is_display_ptr()
Definition: Type.java:941
com.cliffc.aa
Definition: AA.java:1
com.cliffc.aa.type.TypeFunSig.make
static TypeFunSig make(TypeTuple ret, Type[] ts)
Definition: TypeFunSig.java:76
com.cliffc.aa.type.Type< TypeFunSig >::_uid
int _uid
Definition: Type.java:96
com.cliffc.aa.type.TypeTuple.INT64_INT64
static final TypeTuple INT64_INT64
Definition: TypeTuple.java:139
com.cliffc.aa.util.SB.p
SB p(String s)
Definition: SB.java:13
com.cliffc.aa.type.TypeFunSig.not_nil
Type not_nil()
Definition: TypeFunSig.java:120
com.cliffc.aa.type.TypeTuple.at
Type at(int idx)
Definition: TypeTuple.java:182
com.cliffc.aa.type.TypeFunSig.display
Type display()
Definition: TypeFunSig.java:89
com.cliffc.aa.type.Type< TypeFunSig >::_name
String _name
Definition: Type.java:99
com.cliffc.aa.type.TypeFunSig
Definition: TypeFunSig.java:10
com.cliffc.aa.type.TypeFunSig.TYPES
static final TypeFunSig[] TYPES
Definition: TypeFunSig.java:85
com.cliffc.aa.type.Type.dual
final T dual()
Definition: Type.java:361
com.cliffc.aa.type.TypeTuple._ts
Type[] _ts
Definition: TypeTuple.java:13
com.cliffc.aa.type.TypeFunSig.may_be_con
boolean may_be_con()
Definition: TypeFunSig.java:116
com.cliffc.aa.type.Type< TypeFunSig >::POOLS
static final Pool[] POOLS
Definition: Type.java:281
com.cliffc.aa.type.Type< TypeFunSig >::TOBJ
static final byte TOBJ
Definition: Type.java:267
com
com.cliffc.aa.type.TypeFunSig.make
static TypeFunSig make(TypeTuple ret, TypeTuple formals)
Definition: TypeFunSig.java:79
com.cliffc.aa.type.TypeFunSig.make
static TypeFunSig make(TypeTuple ret, TypeMemPtr disp, Type arg1, Type arg2)
Definition: TypeFunSig.java:78
com.cliffc.aa.type.TypeFunSig.II_I
static final TypeFunSig II_I
Definition: TypeFunSig.java:84
com.cliffc.aa.type.TypeFunSig.is_con
boolean is_con()
Definition: TypeFunSig.java:117
com.cliffc.aa.type.TypeMemPtr
Definition: TypeMemPtr.java:14
com.cliffc.aa.type.TypeFunSig.must_nil
boolean must_nil()
Definition: TypeFunSig.java:118
com.cliffc.aa.type.Type< TypeFunSig >::TFUNSIG
static final byte TFUNSIG
Definition: Type.java:275
com.cliffc.aa.type.Type< TypeFunSig >::TARY
static final byte TARY
Definition: Type.java:269
com.cliffc.aa.type.TypeFunSig._formals
TypeTuple _formals
Definition: TypeFunSig.java:15
com.cliffc.aa.type.TypeFunSig.isBitShape
byte isBitShape(Type t)
Definition: TypeFunSig.java:122
com.cliffc.aa.type.Type< TypeFunSig >::TFLT
static final byte TFLT
Definition: Type.java:264