2022-02-10 07:14:29 +08:00
|
|
|
|
module Luau.OpSem where
|
|
|
|
|
|
|
|
|
|
open import Agda.Builtin.Equality using (_≡_)
|
|
|
|
|
open import FFI.Data.Maybe using (just)
|
2022-02-12 09:03:26 +08:00
|
|
|
|
open import Luau.Heap using (Heap; _≡_⊕_↦_; _[_]; function_is_end)
|
2022-02-10 07:14:29 +08:00
|
|
|
|
open import Luau.Substitution using (_[_/_]ᴮ)
|
2022-02-12 09:03:26 +08:00
|
|
|
|
open import Luau.Syntax using (Expr; Stat; Block; nil; addr; var; function_is_end; _$_; block_is_end; local_←_; _∙_; done; return; name; fun; arg)
|
2022-02-10 07:14:29 +08:00
|
|
|
|
open import Luau.Value using (addr; val)
|
|
|
|
|
|
2022-02-12 09:03:26 +08:00
|
|
|
|
data _⊢_⟶ᴮ_⊣_ {a} : Heap a → Block a → Block a → Heap a → Set
|
|
|
|
|
data _⊢_⟶ᴱ_⊣_ {a} : Heap a → Expr a → Expr a → Heap a → Set
|
2022-02-10 07:14:29 +08:00
|
|
|
|
|
|
|
|
|
data _⊢_⟶ᴱ_⊣_ where
|
|
|
|
|
|
|
|
|
|
nil : ∀ {H} →
|
|
|
|
|
|
|
|
|
|
-------------------
|
|
|
|
|
H ⊢ nil ⟶ᴱ nil ⊣ H
|
|
|
|
|
|
2022-02-12 09:03:26 +08:00
|
|
|
|
function : ∀ {H H′ a F B} →
|
2022-02-10 07:14:29 +08:00
|
|
|
|
|
2022-02-12 09:03:26 +08:00
|
|
|
|
H′ ≡ H ⊕ a ↦ (function F is B end) →
|
2022-02-10 07:14:29 +08:00
|
|
|
|
-------------------------------------------
|
2022-02-12 09:03:26 +08:00
|
|
|
|
H ⊢ (function F is B end) ⟶ᴱ (addr a) ⊣ H′
|
2022-02-10 07:14:29 +08:00
|
|
|
|
|
|
|
|
|
app : ∀ {H H′ M M′ N} →
|
|
|
|
|
|
|
|
|
|
H ⊢ M ⟶ᴱ M′ ⊣ H′ →
|
|
|
|
|
-----------------------------
|
|
|
|
|
H ⊢ (M $ N) ⟶ᴱ (M′ $ N) ⊣ H′
|
|
|
|
|
|
2022-02-12 09:03:26 +08:00
|
|
|
|
beta : ∀ {H M a F B} →
|
2022-02-10 07:14:29 +08:00
|
|
|
|
|
2022-02-12 09:03:26 +08:00
|
|
|
|
H [ a ] ≡ just(function F is B end) →
|
2022-02-10 07:14:29 +08:00
|
|
|
|
-----------------------------------------------------
|
2022-02-12 09:03:26 +08:00
|
|
|
|
H ⊢ (addr a $ M) ⟶ᴱ (block (fun F) is local (arg F) ← M ∙ B end) ⊣ H
|
2022-02-10 07:14:29 +08:00
|
|
|
|
|
|
|
|
|
block : ∀ {H H′ B B′ b} →
|
|
|
|
|
|
|
|
|
|
H ⊢ B ⟶ᴮ B′ ⊣ H′ →
|
|
|
|
|
----------------------------------------------------
|
|
|
|
|
H ⊢ (block b is B end) ⟶ᴱ (block b is B′ end) ⊣ H′
|
|
|
|
|
|
|
|
|
|
return : ∀ {H V B b} →
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------
|
|
|
|
|
H ⊢ (block b is return (val V) ∙ B end) ⟶ᴱ (val V) ⊣ H
|
|
|
|
|
|
|
|
|
|
done : ∀ {H b} →
|
|
|
|
|
|
|
|
|
|
---------------------------------
|
|
|
|
|
H ⊢ (block b is done end) ⟶ᴱ nil ⊣ H
|
|
|
|
|
|
|
|
|
|
data _⊢_⟶ᴮ_⊣_ where
|
|
|
|
|
|
|
|
|
|
local : ∀ {H H′ x M M′ B} →
|
|
|
|
|
|
|
|
|
|
H ⊢ M ⟶ᴱ M′ ⊣ H′ →
|
|
|
|
|
-------------------------------------------------
|
|
|
|
|
H ⊢ (local x ← M ∙ B) ⟶ᴮ (local x ← M′ ∙ B) ⊣ H′
|
|
|
|
|
|
|
|
|
|
subst : ∀ {H x v B} →
|
|
|
|
|
|
2022-02-12 09:03:26 +08:00
|
|
|
|
------------------------------------------------------
|
|
|
|
|
H ⊢ (local x ← val v ∙ B) ⟶ᴮ (B [ v / name x ]ᴮ) ⊣ H
|
2022-02-10 07:14:29 +08:00
|
|
|
|
|
2022-02-12 09:03:26 +08:00
|
|
|
|
function : ∀ {H H′ a F B C} →
|
2022-02-10 07:14:29 +08:00
|
|
|
|
|
2022-02-12 09:03:26 +08:00
|
|
|
|
H′ ≡ H ⊕ a ↦ (function F is C end) →
|
2022-02-10 07:14:29 +08:00
|
|
|
|
--------------------------------------------------------------
|
2022-02-12 09:03:26 +08:00
|
|
|
|
H ⊢ (function F is C end ∙ B) ⟶ᴮ (B [ addr a / fun F ]ᴮ) ⊣ H′
|
2022-02-10 07:14:29 +08:00
|
|
|
|
|
|
|
|
|
return : ∀ {H H′ M M′ B} →
|
|
|
|
|
|
|
|
|
|
H ⊢ M ⟶ᴱ M′ ⊣ H′ →
|
|
|
|
|
--------------------------------------------
|
|
|
|
|
H ⊢ (return M ∙ B) ⟶ᴮ (return M′ ∙ B) ⊣ H′
|
|
|
|
|
|
2022-02-12 09:03:26 +08:00
|
|
|
|
data _⊢_⟶*_⊣_ {a} : Heap a → Block a → Block a → Heap a → Set where
|
2022-02-10 07:14:29 +08:00
|
|
|
|
|
|
|
|
|
refl : ∀ {H B} →
|
|
|
|
|
|
|
|
|
|
----------------
|
|
|
|
|
H ⊢ B ⟶* B ⊣ H
|
|
|
|
|
|
|
|
|
|
step : ∀ {H H′ H″ B B′ B″} →
|
|
|
|
|
H ⊢ B ⟶ᴮ B′ ⊣ H′ →
|
|
|
|
|
H′ ⊢ B′ ⟶* B″ ⊣ H″ →
|
|
|
|
|
------------------
|
|
|
|
|
H ⊢ B ⟶* B″ ⊣ H″
|
|
|
|
|
|
|
|
|
|
|