2022-03-02 22:02:51 +00:00
|
|
|
|
{-# OPTIONS --rewriting #-}
|
|
|
|
|
|
2022-02-09 23:14:29 +00:00
|
|
|
|
module Luau.OpSem where
|
|
|
|
|
|
|
|
|
|
open import Agda.Builtin.Equality using (_≡_)
|
2022-02-24 19:17:46 +00:00
|
|
|
|
open import Agda.Builtin.Float using (Float; primFloatPlus; primFloatMinus; primFloatTimes; primFloatDiv; primFloatEquality; primFloatLess; primFloatInequality)
|
|
|
|
|
open import Agda.Builtin.Bool using (Bool; true; false)
|
2022-03-02 23:26:58 +00:00
|
|
|
|
open import Agda.Builtin.String using (primStringEquality; primStringAppend)
|
2022-02-24 19:17:46 +00:00
|
|
|
|
open import Utility.Bool using (not; _or_; _and_)
|
2022-03-02 22:02:51 +00:00
|
|
|
|
open import Agda.Builtin.Nat using () renaming (_==_ to _==ᴬ_)
|
|
|
|
|
open import FFI.Data.Maybe using (Maybe; just; nothing)
|
2022-02-12 01:03:26 +00:00
|
|
|
|
open import Luau.Heap using (Heap; _≡_⊕_↦_; _[_]; function_is_end)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
open import Luau.Substitution using (_[_/_]ᴮ)
|
2022-03-02 23:26:58 +00:00
|
|
|
|
open import Luau.Syntax using (Value; Expr; Stat; Block; nil; addr; val; var; function_is_end; _$_; block_is_end; local_←_; _∙_; done; return; name; fun; arg; binexp; BinaryOperator; +; -; *; /; <; >; ==; ~=; <=; >=; ··; number; bool; string)
|
2022-02-24 19:17:46 +00:00
|
|
|
|
open import Luau.RuntimeType using (RuntimeType; valueType)
|
2022-03-02 22:02:51 +00:00
|
|
|
|
open import Properties.Product using (_×_; _,_)
|
|
|
|
|
|
|
|
|
|
evalEqOp : Value → Value → Bool
|
|
|
|
|
evalEqOp Value.nil Value.nil = true
|
|
|
|
|
evalEqOp (addr x) (addr y) = (x ==ᴬ y)
|
|
|
|
|
evalEqOp (number x) (number y) = primFloatEquality x y
|
|
|
|
|
evalEqOp (bool true) (bool y) = y
|
|
|
|
|
evalEqOp (bool false) (bool y) = not y
|
|
|
|
|
evalEqOp _ _ = false
|
|
|
|
|
|
|
|
|
|
evalNeqOp : Value → Value → Bool
|
|
|
|
|
evalNeqOp (number x) (number y) = primFloatInequality x y
|
|
|
|
|
evalNeqOp x y = not (evalEqOp x y)
|
|
|
|
|
|
|
|
|
|
data _⟦_⟧_⟶_ : Value → BinaryOperator → Value → Value → Set where
|
|
|
|
|
+ : ∀ m n → (number m) ⟦ + ⟧ (number n) ⟶ number (primFloatPlus m n)
|
|
|
|
|
- : ∀ m n → (number m) ⟦ - ⟧ (number n) ⟶ number (primFloatMinus m n)
|
|
|
|
|
/ : ∀ m n → (number m) ⟦ / ⟧ (number n) ⟶ number (primFloatTimes m n)
|
|
|
|
|
* : ∀ m n → (number m) ⟦ * ⟧ (number n) ⟶ number (primFloatDiv m n)
|
|
|
|
|
< : ∀ m n → (number m) ⟦ < ⟧ (number n) ⟶ bool (primFloatLess m n)
|
|
|
|
|
> : ∀ m n → (number m) ⟦ > ⟧ (number n) ⟶ bool (primFloatLess n m)
|
|
|
|
|
<= : ∀ m n → (number m) ⟦ <= ⟧ (number n) ⟶ bool ((primFloatLess m n) or (primFloatEquality m n))
|
|
|
|
|
>= : ∀ m n → (number m) ⟦ >= ⟧ (number n) ⟶ bool ((primFloatLess n m) or (primFloatEquality m n))
|
|
|
|
|
== : ∀ v w → v ⟦ == ⟧ w ⟶ bool (evalEqOp v w)
|
|
|
|
|
~= : ∀ v w → v ⟦ ~= ⟧ w ⟶ bool (evalNeqOp v w)
|
2022-03-02 23:26:58 +00:00
|
|
|
|
·· : ∀ x y → (string x) ⟦ ·· ⟧ (string y) ⟶ string (primStringAppend x y)
|
|
|
|
|
|
2022-02-12 01:03:26 +00: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-09 23:14:29 +00:00
|
|
|
|
|
|
|
|
|
data _⊢_⟶ᴱ_⊣_ where
|
|
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
|
function : ∀ a {H H′ F B} →
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
|
H′ ≡ H ⊕ a ↦ (function F is B end) →
|
2022-02-09 23:14:29 +00:00
|
|
|
|
-------------------------------------------
|
2022-03-02 22:02:51 +00:00
|
|
|
|
H ⊢ (function F is B end) ⟶ᴱ val(addr a) ⊣ H′
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
2022-02-18 22:47:23 +00:00
|
|
|
|
app₁ : ∀ {H H′ M M′ N} →
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
|
|
|
|
H ⊢ M ⟶ᴱ M′ ⊣ H′ →
|
|
|
|
|
-----------------------------
|
|
|
|
|
H ⊢ (M $ N) ⟶ᴱ (M′ $ N) ⊣ H′
|
|
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
|
app₂ : ∀ v {H H′ N N′} →
|
2022-02-18 22:47:23 +00:00
|
|
|
|
|
|
|
|
|
H ⊢ N ⟶ᴱ N′ ⊣ H′ →
|
|
|
|
|
-----------------------------
|
2022-03-02 22:02:51 +00:00
|
|
|
|
H ⊢ (val v $ N) ⟶ᴱ (val v $ N′) ⊣ H′
|
2022-02-18 22:47:23 +00:00
|
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
|
beta : ∀ O v {H a F B} →
|
|
|
|
|
|
|
|
|
|
(O ≡ function F is B end) →
|
|
|
|
|
H [ a ] ≡ just(O) →
|
2022-02-18 22:47:23 +00:00
|
|
|
|
-----------------------------------------------------------------------------
|
2022-03-02 22:02:51 +00:00
|
|
|
|
H ⊢ (val (addr a) $ val v) ⟶ᴱ (block (fun F) is (B [ v / name(arg F) ]ᴮ) end) ⊣ H
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
|
|
|
|
block : ∀ {H H′ B B′ b} →
|
|
|
|
|
|
|
|
|
|
H ⊢ B ⟶ᴮ B′ ⊣ H′ →
|
|
|
|
|
----------------------------------------------------
|
|
|
|
|
H ⊢ (block b is B end) ⟶ᴱ (block b is B′ end) ⊣ H′
|
|
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
|
return : ∀ v {H B b} →
|
|
|
|
|
|
2022-02-09 23:14:29 +00:00
|
|
|
|
--------------------------------------------------------
|
2022-03-02 22:02:51 +00:00
|
|
|
|
H ⊢ (block b is return (val v) ∙ B end) ⟶ᴱ val v ⊣ H
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
|
|
|
|
done : ∀ {H b} →
|
|
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
|
--------------------------------------------
|
|
|
|
|
H ⊢ (block b is done end) ⟶ᴱ (val nil) ⊣ H
|
2022-02-22 23:52:56 +00:00
|
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
|
binOp₀ : ∀ {H op v₁ v₂ w} →
|
|
|
|
|
|
|
|
|
|
v₁ ⟦ op ⟧ v₂ ⟶ w →
|
|
|
|
|
--------------------------------------------------
|
|
|
|
|
H ⊢ (binexp (val v₁) op (val v₂)) ⟶ᴱ (val w) ⊣ H
|
|
|
|
|
|
|
|
|
|
binOp₁ : ∀ {H H′ x x′ op y} →
|
|
|
|
|
|
2022-02-22 23:52:56 +00:00
|
|
|
|
H ⊢ x ⟶ᴱ x′ ⊣ H′ →
|
|
|
|
|
---------------------------------------------
|
|
|
|
|
H ⊢ (binexp x op y) ⟶ᴱ (binexp x′ op y) ⊣ H′
|
|
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
|
binOp₂ : ∀ {H H′ x op y y′} →
|
|
|
|
|
|
2022-02-22 23:52:56 +00:00
|
|
|
|
H ⊢ y ⟶ᴱ y′ ⊣ H′ →
|
|
|
|
|
---------------------------------------------
|
|
|
|
|
H ⊢ (binexp x op y) ⟶ᴱ (binexp x op y′) ⊣ H′
|
|
|
|
|
|
2022-02-09 23:14:29 +00:00
|
|
|
|
data _⊢_⟶ᴮ_⊣_ where
|
|
|
|
|
|
|
|
|
|
local : ∀ {H H′ x M M′ B} →
|
|
|
|
|
|
|
|
|
|
H ⊢ M ⟶ᴱ M′ ⊣ H′ →
|
|
|
|
|
-------------------------------------------------
|
|
|
|
|
H ⊢ (local x ← M ∙ B) ⟶ᴮ (local x ← M′ ∙ B) ⊣ H′
|
|
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
|
subst : ∀ v {H x B} →
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
|
------------------------------------------------------
|
|
|
|
|
H ⊢ (local x ← val v ∙ B) ⟶ᴮ (B [ v / name x ]ᴮ) ⊣ H
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
|
function : ∀ a {H H′ F B C} →
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
|
H′ ≡ H ⊕ a ↦ (function F is C end) →
|
2022-02-09 23:14:29 +00:00
|
|
|
|
--------------------------------------------------------------
|
2022-03-02 22:02:51 +00:00
|
|
|
|
H ⊢ (function F is C end ∙ B) ⟶ᴮ (B [ addr a / name(fun F) ]ᴮ) ⊣ H′
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
|
|
|
|
return : ∀ {H H′ M M′ B} →
|
|
|
|
|
|
|
|
|
|
H ⊢ M ⟶ᴱ M′ ⊣ H′ →
|
|
|
|
|
--------------------------------------------
|
|
|
|
|
H ⊢ (return M ∙ B) ⟶ᴮ (return M′ ∙ B) ⊣ H′
|
|
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
|
data _⊢_⟶*_⊣_ {a} : Heap a → Block a → Block a → Heap a → Set where
|
2022-02-09 23:14:29 +00: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″
|