Skip to content

Commit

Permalink
Add more error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
peachpit-site committed Jan 31, 2025
1 parent 92667fc commit 4961c1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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...)
Expand Down
19 changes: 19 additions & 0 deletions source/err/errorfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4961c1f

Please sign in to comment.