Improved VarDec syntax

This commit is contained in:
ajeffrey@roblox.com 2022-02-10 11:13:13 -06:00
parent daa38aa29d
commit efa0ceede2
7 changed files with 19 additions and 25 deletions

View file

@ -1,11 +1,9 @@
module Examples.OpSem where module Examples.OpSem where
open import Luau.OpSem using (_⊢_⟶ᴱ_⊣_; _⊢_⟶ᴮ_⊣_; subst) open import Luau.OpSem using (_⊢_⟶ᴱ_⊣_; _⊢_⟶ᴮ_⊣_; subst)
open import Luau.Syntax using (var; nil; local_←_; _∙_; done; return; block_is_end; untyped) open import Luau.Syntax using (var; nil; local_←_; _∙_; done; return; block_is_end)
open import Luau.Heap using (emp) open import Luau.Heap using (emp)
x = var "x" ex1 : emp (local (var "x") nil return (var "x") done) ⟶ᴮ (return nil done) emp
ex1 : emp (local (untyped "x") nil return x done) ⟶ᴮ (return nil done) emp
ex1 = subst ex1 = subst

View file

@ -3,7 +3,7 @@
module Examples.Run where module Examples.Run where
open import Agda.Builtin.Equality using (_≡_; refl) open import Agda.Builtin.Equality using (_≡_; refl)
open import Luau.Syntax using (nil; var; _$_; function_⟨_⟩_end; return; _∙_; done; untyped) open import Luau.Syntax using (nil; var; _$_; function_⟨_⟩_end; return; _∙_; done)
open import Luau.Value using (nil) open import Luau.Value using (nil)
open import Luau.Run using (run; return) open import Luau.Run using (run; return)
open import Luau.Heap using (emp; lookup-next; next-emp; lookup-next-emp) open import Luau.Heap using (emp; lookup-next; next-emp; lookup-next-emp)
@ -11,8 +11,5 @@ open import Luau.Heap using (emp; lookup-next; next-emp; lookup-next-emp)
import Agda.Builtin.Equality.Rewrite import Agda.Builtin.Equality.Rewrite
{-# REWRITE lookup-next next-emp lookup-next-emp #-} {-# REWRITE lookup-next next-emp lookup-next-emp #-}
x = var "x" ex1 : (run (function "id" var "x" return (var "x") done end return (var "id" $ nil) done) return nil _)
id = var "id"
ex1 : (run (function "id" untyped "x" return x done end return (id $ nil) done) return nil _)
ex1 = refl ex1 = refl

View file

@ -2,13 +2,10 @@ module Examples.Syntax where
open import Agda.Builtin.Equality using (_≡_; refl) open import Agda.Builtin.Equality using (_≡_; refl)
open import FFI.Data.String using (_++_) open import FFI.Data.String using (_++_)
open import Luau.Syntax using (var; _$_; return; nil; function_⟨_⟩_end; done; _∙_; untyped) open import Luau.Syntax using (var; _$_; return; nil; function_⟨_⟩_end; done; _∙_)
open import Luau.Syntax.ToString using (exprToString; blockToString) open import Luau.Syntax.ToString using (exprToString; blockToString)
f = var "f" ex1 : exprToString(var "f" $ var "x")
x = var "x"
ex1 : exprToString(f $ x)
"f(x)" "f(x)"
ex1 = refl ex1 = refl
@ -16,7 +13,7 @@ ex2 : blockToString(return nil ∙ done) ≡
"return nil" "return nil"
ex2 = refl ex2 = refl
ex3 : blockToString(function "f" untyped "x" return x done end return f done) ex3 : blockToString(function "f" var "x" return (var "x") done end return (var "f") done)
"local function f(x)\n" ++ "local function f(x)\n" ++
" return x\n" ++ " return x\n" ++
"end\n" ++ "end\n" ++

View file

@ -7,12 +7,12 @@ open import Luau.Type using (Type)
infixr 5 _∙_ infixr 5 _∙_
data VarDec : Set where data VarDec : Set where
untyped : Var VarDec var : Var VarDec
typed_∈_ : Var Type VarDec var_∈_ : Var Type VarDec
name : VarDec Var name : VarDec Var
name (untyped x) = x name (var x) = x
name (typed x T) = x name (var x T) = x
data Block : Set data Block : Set
data Stat : Set data Stat : Set

View file

@ -1,6 +1,6 @@
module Luau.Syntax.FromJSON where module Luau.Syntax.FromJSON where
open import Luau.Syntax using (Block; Stat ; Expr; nil; _$_; var; function⟨_⟩_end; local_←_; function_⟨_⟩_end; return; done; _∙_; untyped) open import Luau.Syntax using (Block; Stat ; Expr; nil; _$_; var; function⟨_⟩_end; local_←_; function_⟨_⟩_end; return; done; _∙_)
open import Agda.Builtin.List using (List; _∷_; []) open import Agda.Builtin.List using (List; _∷_; [])
@ -55,7 +55,7 @@ exprFromObject obj | just (string "AstExprCall") | _ | nothing = Left ("AstExpr
exprFromObject obj | just (string "AstExprConstantNil") = Right nil exprFromObject obj | just (string "AstExprConstantNil") = Right nil
exprFromObject obj | just (string "AstExprFunction") with lookup args obj | lookup body obj exprFromObject obj | just (string "AstExprFunction") with lookup args obj | lookup body obj
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just value with head arr | blockFromJSON value exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just value with head arr | blockFromJSON value
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just value | just (string x) | Right B = Right (function⟨ untyped x B end) exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just value | just (string x) | Right B = Right (function⟨ var x B end)
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just value | just _ | Right B = Left "AstExprFunction args not a string array" exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just value | just _ | Right B = Left "AstExprFunction args not a string array"
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just value | nothing | Right B = Left "Unsupported AstExprFunction empty args" exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just value | nothing | Right B = Left "Unsupported AstExprFunction empty args"
exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just value | _ | Left err = Left err exprFromObject obj | just (string "AstExprFunction") | just (array arr) | just value | _ | Left err = Left err
@ -78,7 +78,7 @@ statFromObject obj with lookup type obj
statFromObject obj | just(string "AstStatLocal") with lookup vars obj | lookup values obj statFromObject obj | just(string "AstStatLocal") with lookup vars obj | lookup values obj
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) with head(arr1) | head(arr2) statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) with head(arr1) | head(arr2)
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(string x) | just(value) with exprFromJSON(value) statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(string x) | just(value) with exprFromJSON(value)
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(string x) | just(value) | Right M = Right (local untyped x M) statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(string x) | just(value) | Right M = Right (local (var x) M)
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(string x) | just(value) | Left err = Left err statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(string x) | just(value) | Left err = Left err
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(string x) | nothing = Left "AstStatLocal empty values" statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(string x) | nothing = Left "AstStatLocal empty values"
statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(_) | _ = Left "AstStatLocal vars not a string array" statFromObject obj | just(string "AstStatLocal") | just(array arr1) | just(array arr2) | just(_) | _ = Left "AstStatLocal vars not a string array"

View file

@ -1,14 +1,14 @@
module Luau.Syntax.ToString where module Luau.Syntax.ToString where
open import Luau.Syntax using (Block; Stat; Expr; VarDec; nil; var; addr; _$_; function⟨_⟩_end; return; function_⟨_⟩_end ;local_←_; _∙_; done; block_is_end; typed_∈_; untyped) open import Luau.Syntax using (Block; Stat; Expr; VarDec; nil; var; var_∈_; addr; _$_; function⟨_⟩_end; return; function_⟨_⟩_end ;local_←_; _∙_; done; block_is_end)
open import FFI.Data.String using (String; _++_) open import FFI.Data.String using (String; _++_)
open import Luau.Addr.ToString using (addrToString) open import Luau.Addr.ToString using (addrToString)
open import Luau.Type.ToString using (typeToString) open import Luau.Type.ToString using (typeToString)
open import Luau.Var.ToString using (varToString) open import Luau.Var.ToString using (varToString)
varDecToString : VarDec String varDecToString : VarDec String
varDecToString (untyped x) = varToString x varDecToString (var x) = varToString x
varDecToString (typed x T) = varToString x ++ " : " ++ typeToString T varDecToString (var x T) = varToString x ++ " : " ++ typeToString T
exprToString : String Expr String exprToString : String Expr String
statToString : String Stat String statToString : String Stat String

View file

@ -1,3 +1,5 @@
module Properties where module Properties where
import Properties.Dec import Properties.Dec
import Properties.Remember
import Properties.Step