2022-03-02 22:02:51 +00:00
|
|
|
{-# OPTIONS --rewriting #-}
|
|
|
|
|
2022-02-09 23:14:29 +00:00
|
|
|
module Luau.RuntimeError.ToString where
|
|
|
|
|
2022-02-18 19:09:00 +00:00
|
|
|
open import Agda.Builtin.Float using (primShowFloat)
|
2022-02-09 23:14:29 +00:00
|
|
|
open import FFI.Data.String using (String; _++_)
|
2022-03-02 22:02:51 +00:00
|
|
|
open import Luau.RuntimeError using (RuntimeErrorᴮ; RuntimeErrorᴱ; local; return; FunctionMismatch; BinOpMismatch₁; BinOpMismatch₂; UnboundVariable; SEGV; app₁; app₂; block; bin₁; bin₂)
|
2022-02-22 23:52:56 +00:00
|
|
|
open import Luau.RuntimeType.ToString using (runtimeTypeToString)
|
2022-02-09 23:14:29 +00:00
|
|
|
open import Luau.Addr.ToString using (addrToString)
|
2022-03-02 22:02:51 +00:00
|
|
|
open import Luau.Syntax.ToString using (valueToString; exprToString)
|
2022-02-09 23:14:29 +00:00
|
|
|
open import Luau.Var.ToString using (varToString)
|
2022-03-02 22:02:51 +00:00
|
|
|
open import Luau.Syntax using (var; val; addr; binexp; block_is_end; local_←_; return; _∙_; name; _$_)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
errToStringᴱ : ∀ {a H} M → RuntimeErrorᴱ {a} H M → String
|
|
|
|
errToStringᴮ : ∀ {a H} B → RuntimeErrorᴮ {a} H B → String
|
2022-02-09 23:14:29 +00:00
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
errToStringᴱ (var x) (UnboundVariable) = "variable " ++ varToString x ++ " is unbound"
|
|
|
|
errToStringᴱ (val (addr a)) (SEGV p) = "address " ++ addrToString a ++ " is unallocated"
|
|
|
|
errToStringᴱ (M $ N) (FunctionMismatch v w p) = "value " ++ (valueToString v) ++ " is not a function"
|
|
|
|
errToStringᴱ (M $ N) (app₁ E) = errToStringᴱ M E
|
|
|
|
errToStringᴱ (M $ N) (app₂ E) = errToStringᴱ N E
|
|
|
|
errToStringᴱ (binexp M op N) (BinOpMismatch₁ v w p) = "value " ++ (valueToString v) ++ " is not a number"
|
|
|
|
errToStringᴱ (binexp M op N) (BinOpMismatch₂ v w p) = "value " ++ (valueToString w) ++ " is not a number"
|
|
|
|
errToStringᴱ (binexp M op N) (bin₁ E) = errToStringᴱ M E
|
|
|
|
errToStringᴱ (binexp M op N) (bin₂ E) = errToStringᴱ N E
|
|
|
|
errToStringᴱ (block b is B end) (block E) = errToStringᴮ B E ++ "\n in call of function " ++ varToString (name b)
|
2022-02-09 23:14:29 +00:00
|
|
|
|
2022-03-02 22:02:51 +00:00
|
|
|
errToStringᴮ (local x ← M ∙ B) (local E) = errToStringᴱ M E ++ "\n in definition of " ++ varToString (name x)
|
|
|
|
errToStringᴮ (return M ∙ B) (return E) = errToStringᴱ M E ++ "\n in return statement"
|