about summary refs log tree commit diff
path: root/pkg/lang/vm/errors.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-05-28 01:22:17 +0000
committerGitHub <noreply@github.com>2022-05-28 01:22:17 +0000
commit0a7700112f82e634a957685bee0cbaa3458f4945 (patch)
tree847c397970d7d852bc988a7a01f4625eae443edb /pkg/lang/vm/errors.go
parent83d1dc87f3336d70ccda476627c70c282b7b6e11 (diff)
downloadjinx-0a7700112f82e634a957685bee0cbaa3458f4945.tar.zst
jinx-0a7700112f82e634a957685bee0cbaa3458f4945.zip
Harden VM Mem
Diffstat (limited to 'pkg/lang/vm/errors.go')
-rw-r--r--pkg/lang/vm/errors.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/pkg/lang/vm/errors.go b/pkg/lang/vm/errors.go
index 264dd3a..2f5b56a 100644
--- a/pkg/lang/vm/errors.go
+++ b/pkg/lang/vm/errors.go
@@ -4,6 +4,7 @@ import (
 	"errors"
 	"fmt"
 	"jinx/pkg/lang/vm/code"
+	"jinx/pkg/lang/vm/mem"
 	"jinx/pkg/lang/vm/text"
 	"jinx/pkg/lang/vm/value"
 )
@@ -31,6 +32,8 @@ var (
 	ErrReachedRootCallFrame = errors.New("reached root call frame")
 
 	ErrCallBaseCantBeNegative = errors.New("call base cannot be negative")
+
+	ErrEnvNotSet = errors.New("env not set")
 )
 
 type ErrLocalIndexOutOfBounds struct {
@@ -59,6 +62,32 @@ func (e ErrInvalidOp) Error() string {
 	return fmt.Sprintf("invalid opcode: %d", e.Op)
 }
 
+type ErrUnexpectedMemCell struct {
+	Ptr      mem.Ptr
+	Expected mem.CellKind
+	Got      mem.CellKind
+}
+
+func (e ErrUnexpectedMemCell) Error() string {
+	return fmt.Sprintf("unexpected memory cell at %s: expected %v, got %v", e.Ptr.String(), e.Expected, e.Got)
+}
+
+type ErrMemNilCell struct {
+	Ptr mem.Ptr
+}
+
+func (e ErrMemNilCell) Error() string {
+	return fmt.Sprintf("found no value at %s", e.Ptr.String())
+}
+
+type ErrCorruptedMemCell struct {
+	Ptr mem.Ptr
+}
+
+func (e ErrCorruptedMemCell) Error() string {
+	return fmt.Sprintf("corrupted memory cell at %s", e.Ptr.String())
+}
+
 // Non-fatal errors, which will later be implemented as catchable exceptions
 
 type ErrInvalidOperandType struct {