This modification is relevant for fixing regressions on recent changes to the auto implicit behavior for inductive families. The following declarations are now accepted: ```lean inductive HasType : Fin n → Vector Ty n → Ty → Type where | stop : HasType 0 (ty :: ctx) ty | pop : HasType k ctx ty → HasType k.succ (u :: ctx) ty inductive Sublist : List α → List α → Prop | slnil : Sublist [] [] | cons l₁ l₂ a : Sublist l₁ l₂ → Sublist l₁ (a :: l₂) | cons2 l₁ l₂ a : Sublist l₁ l₂ → Sublist (a :: l₁) (a :: l₂) inductive Lst : Type u → Type u | nil : Lst α | cons : α → Lst α → Lst α ``` TODO: universe inference for `inductive` should be improved. The current approach is not good enough when we have auto implicits. TODO: allow implicit fixed indices that do not depend on indices that cannot be moved to become parameters.
37 lines
1.4 KiB
Text
37 lines
1.4 KiB
Text
abbrev semantics (α:Type) := StateM (List Nat) α
|
||
|
||
inductive expression : Nat → Type
|
||
| const : (n : Nat) → expression n
|
||
|
||
def uext {w:Nat} (x: expression w) (o:Nat) : expression w := expression.const
|
||
def eval {n : Nat} (v:expression n) : semantics (expression n) := pure expression.const
|
||
def set_overflow {w : Nat} (e : expression w) : semantics Unit := pure ()
|
||
|
||
structure instruction :=
|
||
(mnemonic:String)
|
||
(patterns:List Nat)
|
||
|
||
def definst (mnem:String) (body: expression 8 -> semantics Unit) : instruction :=
|
||
{ mnemonic := mnem
|
||
, patterns := ((body expression.const).run []).snd.reverse
|
||
}
|
||
|
||
def mul : instruction := Id.run <| do -- this is a "pure" do block (as in it is the Id monad)
|
||
definst "mul" $ fun (src : expression 8) =>
|
||
let action : semantics Unit := do -- this is not "pure" do block
|
||
let tmp <- eval $ uext src 16
|
||
set_overflow $ tmp
|
||
action
|
||
|
||
def mul' : instruction := Id.run <| do -- this is a "pure" do block (as in it is the Id monad)
|
||
definst "mul" $ fun (src : expression 8) =>
|
||
let rec action : semantics Unit := do -- this is not "pure" do block
|
||
let tmp <- eval $ uext src 16
|
||
set_overflow $ tmp
|
||
action
|
||
|
||
def mul'' : instruction := Id.run <| do -- this is a "pure" do block (as in it is the Id monad)
|
||
definst "mul" $ fun (src : expression 8) =>
|
||
let action : semantics (expression 8) :=
|
||
return (<- eval $ uext src 16)
|
||
pure ()
|