From 4961c1fa0a8160406303c6674390c90ac657cb81 Mon Sep 17 00:00:00 2001 From: Peachpit Date: Fri, 31 Jan 2025 01:42:09 -0800 Subject: [PATCH] Add more error messages --- source/compiler/compiler.go | 4 ++-- source/err/errorfile.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/source/compiler/compiler.go b/source/compiler/compiler.go index 9de96319..29cfb2c6 100644 --- a/source/compiler/compiler.go +++ b/source/compiler/compiler.go @@ -790,7 +790,7 @@ NodeTypeSwitch: cp.put(vm.Notb, cp.That()) cp.Emit(vm.Jmp, cp.CodeTop()+2) cp.vmComeFrom(boolTest) - cp.Emit(vm.Asgm, cp.That(), cp.reserveError("vm/bool/not", node.GetToken())) + cp.Emit(vm.Asgm, cp.That(), cp.reserveError("vm/bool/not", node.GetToken()), cp.That()) rtnTypes, rtnConst = AltType(values.ERROR, values.BOOL), cst break NodeTypeSwitch default: @@ -881,7 +881,7 @@ NodeTypeSwitch: cp.Emit(vm.Rpop) } case v.types.Contains(values.FUNC): - errorLoc := cp.reserveError("vm/apply/func", node.GetToken()) + errorLoc := cp.reserveError("vm/apply/func", node.GetToken(), v.MLoc) cp.Cm("Prefix variable might be lambda. Emitting type check.", node.GetToken()) funcTest := cp.vmIf(vm.Qtyp, v.MLoc, uint32(values.FUNC)) cp.put(vm.Dofn, operands...) diff --git a/source/err/errorfile.go b/source/err/errorfile.go index aba7e873..a8ac2d7a 100644 --- a/source/err/errorfile.go +++ b/source/err/errorfile.go @@ -2566,6 +2566,25 @@ var ErrorCreatorMap = map[string]ErrorCreator{ }, }, + "vm/apply/func": { + Message: func(tok *token.Token, args ...any) string { + return "value is not of type 'func'" + }, + Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string { + return "It only makes sense to apply a value to an expression if the value " + + "is a lambda function." + }, + }, + + "vm/bool/not": { + Message: func(tok *token.Token, args ...any) string { + return "value is not of type 'bool'" + }, + Explanation: func(errors Errors, pos int, tok *token.Token, args ...any) string { + return "The built-in 'not' operator can only be applied to values of boolean types." + }, + }, + "vm/div/float": { Message: func(tok *token.Token, args ...any) string { return "division by zero"