diff options
| author | azidar | 2015-04-29 11:42:37 -0700 |
|---|---|---|
| committer | azidar | 2015-04-29 11:42:37 -0700 |
| commit | ddc0dfe7a5f942ad1066b86b4f3ba9494493c6ed (patch) | |
| tree | c440e3569707a0451da1330a2fd036718c36a9d7 /src/main/stanza/passes.stanza | |
| parent | c46608d92bd493fa33c3c5122341c716ca75ecb0 (diff) | |
Added dshl and dshr
Diffstat (limited to 'src/main/stanza/passes.stanza')
| -rw-r--r-- | src/main/stanza/passes.stanza | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main/stanza/passes.stanza b/src/main/stanza/passes.stanza index 31d8fc5f..0b586080 100644 --- a/src/main/stanza/passes.stanza +++ b/src/main/stanza/passes.stanza @@ -1297,6 +1297,8 @@ public defstruct MinusWidth <: Width : arg2 : Width public defstruct MaxWidth <: Width : args : List<Width> +public defstruct ExpWidth <: Width : + arg1 : Width public defmulti map<?T> (f: Width -> Width, w:?T&Width) -> T defmethod map (f: Width -> Width, w:Width) -> Width : @@ -1304,6 +1306,7 @@ defmethod map (f: Width -> Width, w:Width) -> Width : (w:MaxWidth) : MaxWidth(map(f,args(w))) (w:PlusWidth) : PlusWidth(f(arg1(w)),f(arg2(w))) (w:MinusWidth) : MinusWidth(f(arg1(w)),f(arg2(w))) + (w:ExpWidth) : ExpWidth(f(arg1(w))) (w) : w public defmethod print (o:OutputStream, w:VarWidth) : @@ -1314,6 +1317,8 @@ public defmethod print (o:OutputStream, w:PlusWidth) : print-all(o,[ arg1(w) " + " arg2(w)]) public defmethod print (o:OutputStream, w:MinusWidth) : print-all(o,[ arg1(w) " - " arg2(w)]) +public defmethod print (o:OutputStream, w:ExpWidth) : + print-all(o,[ "exp(" arg1(w) ")"]) public definterface Constraint public defstruct WGeq <: Constraint : @@ -1407,6 +1412,9 @@ defn solve-constraints (l:List<WGeq>) -> HashTable<Symbol,Int> : look(w) has? defn evaluate (h:HashTable<Symbol,Width>) -> HashTable<Symbol,Int> : + defn apply (a:Int|False,f:(Int) -> Int) -> Int|False : + if a typeof Int : f(a as Int) + else : false defn apply (a:Int|False,b:Int|False, f: (Int,Int) -> Int) -> Int|False : if a typeof Int and b typeof Int : f(a as Int, b as Int) else : false @@ -1422,6 +1430,7 @@ defn solve-constraints (l:List<WGeq>) -> HashTable<Symbol,Int> : (w:MaxWidth) : apply-l(map(solve,args(w)),max) (w:PlusWidth) : apply(solve(arg1(w)),solve(arg2(w)),{_ + _}) (w:MinusWidth) : apply(solve(arg1(w)),solve(arg2(w)),{_ - _}) + (w:ExpWidth) : apply(2,solve(arg1(w)),{pow(_,_) - 1}) (w:IntWidth) : width(w) (w) : error("Shouldn't be here") |
