added type casts

This commit is contained in:
Aidan 2020-07-18 00:22:43 -07:00
parent 77ce00970f
commit 8278430882
No known key found for this signature in database
GPG key ID: 327711E983899316
4 changed files with 72 additions and 1 deletions

View file

@ -29,6 +29,27 @@ import (
// perhaps we simply write out arithmetic routines that operate on the strings
// then we need not worry about storage length.
func num_cast(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
in = in.Eval(f, a, false)
if in.Tag != ast.STRING {
log.Log(log.ERR,
"only a string can successfully be cast to a number",
"number_cast")
return nil
}
if !ast.StrIsNumber(in.Value()) {
log.Log(log.ERR,
"string failed number cast",
"number_cast")
return nil
}
out := in.Copy()
out.Tag = ast.NUMBER
return out
}
func add(in *ast.Token, a ast.VarTable, f ast.FuncTable) *ast.Token {
var res float64