2022-02-09 00:26:58 +00:00
|
|
|
|
module Luau.Syntax where
|
|
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
|
open import Agda.Builtin.Equality using (_≡_)
|
2022-03-02 22:02:51 +00:00
|
|
|
|
open import Agda.Builtin.Bool using (Bool; true; false)
|
2022-02-18 19:09:00 +00:00
|
|
|
|
open import Agda.Builtin.Float using (Float)
|
2022-03-02 23:26:58 +00:00
|
|
|
|
open import Agda.Builtin.String using (String)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
open import Luau.Var using (Var)
|
|
|
|
|
open import Luau.Addr using (Addr)
|
2022-02-12 01:03:26 +00:00
|
|
|
|
open import Luau.Type using (Type)
|
2022-03-02 22:02:51 +00:00
|
|
|
|
open import FFI.Data.Maybe using (Maybe; just; nothing)
|
2022-02-09 00:26:58 +00:00
|
|
|
|
|
|
|
|
|
infixr 5 _∙_
|
|
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
|
data Annotated : Set where
|
|
|
|
|
maybe : Annotated
|
|
|
|
|
yes : Annotated
|
|
|
|
|
|
|
|
|
|
data VarDec : Annotated → Set where
|
|
|
|
|
var : Var → VarDec maybe
|
|
|
|
|
var_∈_ : ∀ {a} → Var → Type → VarDec a
|
|
|
|
|
|
|
|
|
|
name : ∀ {a} → VarDec a → Var
|
|
|
|
|
name (var x) = x
|
|
|
|
|
name (var x ∈ T) = x
|
|
|
|
|
|
|
|
|
|
data FunDec : Annotated → Set where
|
|
|
|
|
_⟨_⟩∈_ : ∀ {a} → Var → VarDec a → Type → FunDec a
|
|
|
|
|
_⟨_⟩ : Var → VarDec maybe → FunDec maybe
|
|
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
|
fun : ∀ {a} → FunDec a → VarDec a
|
|
|
|
|
fun (f ⟨ x ⟩∈ T) = (var f ∈ T)
|
|
|
|
|
fun (f ⟨ x ⟩) = (var f)
|
2022-02-12 01:03:26 +00:00
|
|
|
|
|
|
|
|
|
arg : ∀ {a} → FunDec a → VarDec a
|
|
|
|
|
arg (f ⟨ x ⟩∈ T) = x
|
|
|
|
|
arg (f ⟨ x ⟩) = x
|
|
|
|
|
|
2022-02-22 23:52:56 +00:00
|
|
|
|
data BinaryOperator : Set where
|
|
|
|
|
+ : BinaryOperator
|
|
|
|
|
- : BinaryOperator
|
|
|
|
|
* : BinaryOperator
|
|
|
|
|
/ : BinaryOperator
|
2022-02-24 19:17:46 +00:00
|
|
|
|
< : BinaryOperator
|
|
|
|
|
> : BinaryOperator
|
2022-03-02 22:02:51 +00:00
|
|
|
|
== : BinaryOperator
|
|
|
|
|
~= : BinaryOperator
|
|
|
|
|
<= : BinaryOperator
|
|
|
|
|
>= : BinaryOperator
|
2022-03-02 23:26:58 +00:00
|
|
|
|
·· : BinaryOperator
|
2022-03-02 22:02:51 +00:00
|
|
|
|
|
|
|
|
|
data Value : Set where
|
|
|
|
|
nil : Value
|
|
|
|
|
addr : Addr → Value
|
|
|
|
|
number : Float → Value
|
|
|
|
|
bool : Bool → Value
|
2022-03-02 23:26:58 +00:00
|
|
|
|
string : String → Value
|
2022-02-22 23:52:56 +00:00
|
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
|
data Block (a : Annotated) : Set
|
|
|
|
|
data Stat (a : Annotated) : Set
|
|
|
|
|
data Expr (a : Annotated) : Set
|
|
|
|
|
|
|
|
|
|
data Block a where
|
|
|
|
|
_∙_ : Stat a → Block a → Block a
|
|
|
|
|
done : Block a
|
|
|
|
|
|
|
|
|
|
data Stat a where
|
|
|
|
|
function_is_end : FunDec a → Block a → Stat a
|
|
|
|
|
local_←_ : VarDec a → Expr a → Stat a
|
|
|
|
|
return : Expr a → Stat a
|
|
|
|
|
|
|
|
|
|
data Expr a where
|
|
|
|
|
var : Var → Expr a
|
2022-03-02 22:02:51 +00:00
|
|
|
|
val : Value → Expr a
|
2022-02-12 01:03:26 +00:00
|
|
|
|
_$_ : Expr a → Expr a → Expr a
|
|
|
|
|
function_is_end : FunDec a → Block a → Expr a
|
2022-03-02 22:02:51 +00:00
|
|
|
|
block_is_end : VarDec a → Block a → Expr a
|
2022-02-22 23:52:56 +00:00
|
|
|
|
binexp : Expr a → BinaryOperator → Expr a → Expr a
|
2022-03-02 22:02:51 +00:00
|
|
|
|
|
|
|
|
|
isAnnotatedᴱ : ∀ {a} → Expr a → Maybe (Expr yes)
|
|
|
|
|
isAnnotatedᴮ : ∀ {a} → Block a → Maybe (Block yes)
|
|
|
|
|
|
|
|
|
|
isAnnotatedᴱ (var x) = just (var x)
|
|
|
|
|
isAnnotatedᴱ (val v) = just (val v)
|
|
|
|
|
isAnnotatedᴱ (M $ N) with isAnnotatedᴱ M | isAnnotatedᴱ N
|
|
|
|
|
isAnnotatedᴱ (M $ N) | just M′ | just N′ = just (M′ $ N′)
|
|
|
|
|
isAnnotatedᴱ (M $ N) | _ | _ = nothing
|
|
|
|
|
isAnnotatedᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) with isAnnotatedᴮ B
|
|
|
|
|
isAnnotatedᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) | just B′ = just (function f ⟨ var x ∈ T ⟩∈ U is B′ end)
|
|
|
|
|
isAnnotatedᴱ (function f ⟨ var x ∈ T ⟩∈ U is B end) | _ = nothing
|
|
|
|
|
isAnnotatedᴱ (function _ is B end) = nothing
|
|
|
|
|
isAnnotatedᴱ (block var b ∈ T is B end) with isAnnotatedᴮ B
|
|
|
|
|
isAnnotatedᴱ (block var b ∈ T is B end) | just B′ = just (block var b ∈ T is B′ end)
|
|
|
|
|
isAnnotatedᴱ (block var b ∈ T is B end) | _ = nothing
|
|
|
|
|
isAnnotatedᴱ (block _ is B end) = nothing
|
|
|
|
|
isAnnotatedᴱ (binexp M op N) with isAnnotatedᴱ M | isAnnotatedᴱ N
|
|
|
|
|
isAnnotatedᴱ (binexp M op N) | just M′ | just N′ = just (binexp M′ op N′)
|
|
|
|
|
isAnnotatedᴱ (binexp M op N) | _ | _ = nothing
|
|
|
|
|
|
|
|
|
|
isAnnotatedᴮ (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) with isAnnotatedᴮ B | isAnnotatedᴮ C
|
|
|
|
|
isAnnotatedᴮ (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) | just B′ | just C′ = just (function f ⟨ var x ∈ T ⟩∈ U is C′ end ∙ B′)
|
|
|
|
|
isAnnotatedᴮ (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) | _ | _ = nothing
|
|
|
|
|
isAnnotatedᴮ (function _ is C end ∙ B) = nothing
|
|
|
|
|
isAnnotatedᴮ (local var x ∈ T ← M ∙ B) with isAnnotatedᴱ M | isAnnotatedᴮ B
|
|
|
|
|
isAnnotatedᴮ (local var x ∈ T ← M ∙ B) | just M′ | just B′ = just (local var x ∈ T ← M′ ∙ B′)
|
|
|
|
|
isAnnotatedᴮ (local var x ∈ T ← M ∙ B) | _ | _ = nothing
|
|
|
|
|
isAnnotatedᴮ (local _ ← M ∙ B) = nothing
|
|
|
|
|
isAnnotatedᴮ (return M ∙ B) with isAnnotatedᴱ M | isAnnotatedᴮ B
|
|
|
|
|
isAnnotatedᴮ (return M ∙ B) | just M′ | just B′ = just (return M′ ∙ B′)
|
|
|
|
|
isAnnotatedᴮ (return M ∙ B) | _ | _ = nothing
|
|
|
|
|
isAnnotatedᴮ done = just done
|