2022-02-09 23:14:29 +00:00
|
|
|
|
module Properties.Step where
|
|
|
|
|
|
|
|
|
|
open import Agda.Builtin.Equality using (_≡_; refl)
|
2022-02-22 23:52:56 +00:00
|
|
|
|
open import Agda.Builtin.Float using (primFloatPlus; primFloatMinus; primFloatTimes; primFloatDiv)
|
2022-02-24 19:17:46 +00:00
|
|
|
|
open import Agda.Builtin.Bool using (true; false)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
open import FFI.Data.Maybe using (just; nothing)
|
2022-02-12 01:03:26 +00:00
|
|
|
|
open import Luau.Heap using (Heap; _[_]; alloc; ok; function_is_end)
|
2022-02-24 19:17:46 +00:00
|
|
|
|
open import Luau.Syntax using (Block; Expr; nil; var; addr; true; false; function_is_end; block_is_end; _$_; local_←_; return; done; _∙_; name; fun; arg; number; binexp; +; ≅)
|
|
|
|
|
open import Luau.OpSem using (_⊢_⟶ᴱ_⊣_; _⊢_⟶ᴮ_⊣_; app₁ ; app₂ ; beta; function; block; return; done; local; subst; binOpNumbers; evalNumOp; binOp₁; binOp₂; evalEqOp; evalNeqOp; binOpEquality; binOpInequality)
|
2022-02-22 23:52:56 +00:00
|
|
|
|
open import Luau.RuntimeError using (RuntimeErrorᴱ; RuntimeErrorᴮ; TypeMismatch; UnboundVariable; SEGV; app₁; app₂; block; local; return; bin₁; bin₂)
|
|
|
|
|
open import Luau.RuntimeType using (function; number)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
open import Luau.Substitution using (_[_/_]ᴮ)
|
2022-02-24 19:17:46 +00:00
|
|
|
|
open import Luau.Value using (nil; addr; val; number; bool)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
open import Properties.Remember using (remember; _,_)
|
|
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
|
data StepResultᴮ {a} (H : Heap a) (B : Block a) : Set
|
|
|
|
|
data StepResultᴱ {a} (H : Heap a) (M : Expr a) : Set
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
|
|
|
|
data StepResultᴮ H B where
|
|
|
|
|
step : ∀ H′ B′ → (H ⊢ B ⟶ᴮ B′ ⊣ H′) → StepResultᴮ H B
|
|
|
|
|
return : ∀ V {B′} → (B ≡ (return (val V) ∙ B′)) → StepResultᴮ H B
|
|
|
|
|
done : (B ≡ done) → StepResultᴮ H B
|
|
|
|
|
error : (RuntimeErrorᴮ H B) → StepResultᴮ H B
|
|
|
|
|
|
|
|
|
|
data StepResultᴱ H M where
|
|
|
|
|
step : ∀ H′ M′ → (H ⊢ M ⟶ᴱ M′ ⊣ H′) → StepResultᴱ H M
|
|
|
|
|
value : ∀ V → (M ≡ val V) → StepResultᴱ H M
|
|
|
|
|
error : (RuntimeErrorᴱ H M) → StepResultᴱ H M
|
|
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
|
stepᴱ : ∀ {a} H M → StepResultᴱ {a} H M
|
|
|
|
|
stepᴮ : ∀ {a} H B → StepResultᴮ {a} H B
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
|
|
|
|
stepᴱ H nil = value nil refl
|
|
|
|
|
stepᴱ H (var x) = error (UnboundVariable x)
|
|
|
|
|
stepᴱ H (addr a) = value (addr a) refl
|
2022-02-18 19:09:00 +00:00
|
|
|
|
stepᴱ H (number x) = value (number x) refl
|
2022-02-24 19:17:46 +00:00
|
|
|
|
stepᴱ H (true) = value (bool true) refl
|
|
|
|
|
stepᴱ H (false) = value (bool false) refl
|
2022-02-09 23:14:29 +00:00
|
|
|
|
stepᴱ H (M $ N) with stepᴱ H M
|
2022-02-18 22:47:23 +00:00
|
|
|
|
stepᴱ H (M $ N) | step H′ M′ D = step H′ (M′ $ N) (app₁ D)
|
|
|
|
|
stepᴱ H (_ $ N) | value V refl with stepᴱ H N
|
|
|
|
|
stepᴱ H (_ $ N) | value V refl | step H′ N′ s = step H′ (val V $ N′) (app₂ s)
|
2022-02-22 23:52:56 +00:00
|
|
|
|
stepᴱ H (_ $ _) | value nil refl | value W refl = error (app₁ (TypeMismatch function nil λ()))
|
|
|
|
|
stepᴱ H (_ $ _) | value (number n) refl | value W refl = error (app₁ (TypeMismatch function (number n) λ()))
|
2022-02-24 19:17:46 +00:00
|
|
|
|
stepᴱ H (_ $ _) | value (bool x) refl | value W refl = error (app₁ (TypeMismatch function (bool x) λ()))
|
2022-02-18 22:47:23 +00:00
|
|
|
|
stepᴱ H (_ $ _) | value (addr a) refl | value W refl with remember (H [ a ])
|
|
|
|
|
stepᴱ H (_ $ _) | value (addr a) refl | value W refl | (nothing , p) = error (app₁ (SEGV a p))
|
|
|
|
|
stepᴱ H (_ $ _) | value (addr a) refl | value W refl | (just(function F is B end) , p) = step H (block fun F is B [ W / name (arg F) ]ᴮ end) (beta p)
|
|
|
|
|
stepᴱ H (M $ N) | value V p | error E = error (app₂ E)
|
|
|
|
|
stepᴱ H (M $ N) | error E = error (app₁ E)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
stepᴱ H (block b is B end) with stepᴮ H B
|
|
|
|
|
stepᴱ H (block b is B end) | step H′ B′ D = step H′ (block b is B′ end) (block D)
|
|
|
|
|
stepᴱ H (block b is (return _ ∙ B′) end) | return V refl = step H (val V) return
|
|
|
|
|
stepᴱ H (block b is done end) | done refl = step H nil done
|
|
|
|
|
stepᴱ H (block b is B end) | error E = error (block b E)
|
2022-02-12 01:03:26 +00:00
|
|
|
|
stepᴱ H (function F is C end) with alloc H (function F is C end)
|
|
|
|
|
stepᴱ H function F is C end | ok a H′ p = step H′ (addr a) (function p)
|
2022-02-22 23:52:56 +00:00
|
|
|
|
stepᴱ H (binexp x op y) with stepᴱ H x
|
|
|
|
|
stepᴱ H (binexp x op y) | value x′ refl with stepᴱ H y
|
2022-02-24 19:17:46 +00:00
|
|
|
|
-- Have to use explicit form for ≡ here because it's a heavily overloaded symbol
|
|
|
|
|
stepᴱ H (binexp x Luau.Syntax.≡ y) | value x′ refl | value y′ refl = step H (val (evalEqOp x′ y′)) binOpEquality
|
|
|
|
|
stepᴱ H (binexp x ≅ y) | value x′ refl | value y′ refl = step H (val (evalNeqOp x′ y′)) binOpInequality
|
|
|
|
|
stepᴱ H (binexp x op y) | value (number x′) refl | value (number y′) refl = step H (val (evalNumOp x′ op y′)) binOpNumbers
|
2022-02-22 23:52:56 +00:00
|
|
|
|
stepᴱ H (binexp x op y) | value (number x′) refl | step H′ y′ s = step H′ (binexp (number x′) op y′) (binOp₂ s)
|
|
|
|
|
stepᴱ H (binexp x op y) | value (number x′) refl | error E = error (bin₂ E)
|
|
|
|
|
stepᴱ H (binexp x op y) | value nil refl | _ = error (bin₁ (TypeMismatch number nil λ()))
|
|
|
|
|
stepᴱ H (binexp x op y) | _ | value nil refl = error (bin₂ (TypeMismatch number nil λ()))
|
|
|
|
|
stepᴱ H (binexp x op y) | value (addr a) refl | _ = error (bin₁ (TypeMismatch number (addr a) λ()))
|
|
|
|
|
stepᴱ H (binexp x op y) | _ | value (addr a) refl = error (bin₂ (TypeMismatch number (addr a) λ()))
|
2022-02-24 19:17:46 +00:00
|
|
|
|
stepᴱ H (binexp x op y) | value (bool x′) refl | _ = error (bin₁ (TypeMismatch number (bool x′) λ()))
|
|
|
|
|
stepᴱ H (binexp x op y) | _ | value (bool y′) refl = error (bin₂ (TypeMismatch number (bool y′) λ()))
|
2022-02-22 23:52:56 +00:00
|
|
|
|
stepᴱ H (binexp x op y) | step H′ x′ s = step H′ (binexp x′ op y) (binOp₁ s)
|
|
|
|
|
stepᴱ H (binexp x op y) | error E = error (bin₁ E)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
|
stepᴮ H (function F is C end ∙ B) with alloc H (function F is C end)
|
|
|
|
|
stepᴮ H (function F is C end ∙ B) | ok a H′ p = step H′ (B [ addr a / fun F ]ᴮ) (function p)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
stepᴮ H (local x ← M ∙ B) with stepᴱ H M
|
|
|
|
|
stepᴮ H (local x ← M ∙ B) | step H′ M′ D = step H′ (local x ← M′ ∙ B) (local D)
|
2022-02-12 01:03:26 +00:00
|
|
|
|
stepᴮ H (local x ← _ ∙ B) | value V refl = step H (B [ V / name x ]ᴮ) subst
|
2022-02-09 23:14:29 +00:00
|
|
|
|
stepᴮ H (local x ← M ∙ B) | error E = error (local x E)
|
|
|
|
|
stepᴮ H (return M ∙ B) with stepᴱ H M
|
|
|
|
|
stepᴮ H (return M ∙ B) | step H′ M′ D = step H′ (return M′ ∙ B) (return D)
|
|
|
|
|
stepᴮ H (return _ ∙ B) | value V refl = return V refl
|
|
|
|
|
stepᴮ H (return M ∙ B) | error E = error (return E)
|
|
|
|
|
stepᴮ H done = done refl
|