2022-03-02 22:02:51 +00:00
|
|
|
{-# OPTIONS --rewriting #-}
|
|
|
|
|
2022-02-09 23:14:29 +00:00
|
|
|
module Luau.RuntimeError where
|
|
|
|
|
|
|
|
open import Agda.Builtin.Equality using (_≡_)
|
2022-02-12 01:03:26 +00:00
|
|
|
open import Luau.Heap using (Heap; _[_])
|
2022-02-09 23:14:29 +00:00
|
|
|
open import FFI.Data.Maybe using (just; nothing)
|
2022-02-18 19:09:00 +00:00
|
|
|
open import FFI.Data.String using (String)
|
2022-03-02 23:26:58 +00:00
|
|
|
open import Luau.Syntax using (BinaryOperator; Block; Expr; nil; var; val; addr; block_is_end; _$_; local_←_; return; done; _∙_; number; string; binexp; +; -; *; /; <; >; <=; >=; ··)
|
|
|
|
open import Luau.RuntimeType using (RuntimeType; valueType; function; number; string)
|
2022-02-22 23:52:56 +00:00
|
|
|
open import Properties.Equality using (_≢_)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
data BinOpError : BinaryOperator → RuntimeType → Set where
|
|
|
|
+ : ∀ {t} → (t ≢ number) → BinOpError + t
|
|
|
|
- : ∀ {t} → (t ≢ number) → BinOpError - t
|
|
|
|
* : ∀ {t} → (t ≢ number) → BinOpError * t
|
|
|
|
/ : ∀ {t} → (t ≢ number) → BinOpError / t
|
|
|
|
< : ∀ {t} → (t ≢ number) → BinOpError < t
|
|
|
|
> : ∀ {t} → (t ≢ number) → BinOpError > t
|
|
|
|
<= : ∀ {t} → (t ≢ number) → BinOpError <= t
|
|
|
|
>= : ∀ {t} → (t ≢ number) → BinOpError >= t
|
2022-03-02 23:26:58 +00:00
|
|
|
·· : ∀ {t} → (t ≢ string) → BinOpError ·· t
|
2022-03-02 22:02:51 +00:00
|
|
|
|
2022-02-12 01:03:26 +00:00
|
|
|
data RuntimeErrorᴮ {a} (H : Heap a) : Block a → Set
|
|
|
|
data RuntimeErrorᴱ {a} (H : Heap a) : Expr a → Set
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
|
|
data RuntimeErrorᴱ H where
|
2022-03-02 22:02:51 +00:00
|
|
|
FunctionMismatch : ∀ v w → (function ≢ valueType v) → RuntimeErrorᴱ H (val v $ val w)
|
|
|
|
BinOpMismatch₁ : ∀ v w {op} → (BinOpError op (valueType v)) → RuntimeErrorᴱ H (binexp (val v) op (val w))
|
|
|
|
BinOpMismatch₂ : ∀ v w {op} → (BinOpError op (valueType w)) → RuntimeErrorᴱ H (binexp (val v) op (val w))
|
|
|
|
UnboundVariable : ∀ {x} → RuntimeErrorᴱ H (var x)
|
|
|
|
SEGV : ∀ {a} → (H [ a ] ≡ nothing) → RuntimeErrorᴱ H (val (addr a))
|
2022-02-18 22:47:23 +00:00
|
|
|
app₁ : ∀ {M N} → RuntimeErrorᴱ H M → RuntimeErrorᴱ H (M $ N)
|
|
|
|
app₂ : ∀ {M N} → RuntimeErrorᴱ H N → RuntimeErrorᴱ H (M $ N)
|
2022-03-02 22:02:51 +00:00
|
|
|
block : ∀ {b B} → RuntimeErrorᴮ H B → RuntimeErrorᴱ H (block b is B end)
|
2022-02-22 23:52:56 +00:00
|
|
|
bin₁ : ∀ {M N op} → RuntimeErrorᴱ H M → RuntimeErrorᴱ H (binexp M op N)
|
|
|
|
bin₂ : ∀ {M N op} → RuntimeErrorᴱ H N → RuntimeErrorᴱ H (binexp M op N)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
|
|
|
data RuntimeErrorᴮ H where
|
2022-03-02 22:02:51 +00:00
|
|
|
local : ∀ {x M B} → RuntimeErrorᴱ H M → RuntimeErrorᴮ H (local x ← M ∙ B)
|
2022-02-09 23:14:29 +00:00
|
|
|
return : ∀ {M B} → RuntimeErrorᴱ H M → RuntimeErrorᴮ H (return M ∙ B)
|