improve errors, add warnings, add some compile-time optimizations, fix variables, make sure conditionals and loops get booleans, affirm types, keep variables to a single type

This commit is contained in:
Neemek 2025-03-20 12:13:30 +01:00
parent e34b423967
commit b1b8e61f57
Signed by: neemek
GPG key ID: 28360A8951CD0E9B
14 changed files with 435 additions and 118 deletions

View file

@ -311,6 +311,7 @@ var DefaultGlobals = map[string]Value{
return nil, nil
},
nil,
false,
},
"print": &BuiltinFunctionValue{
"print",
@ -323,6 +324,7 @@ var DefaultGlobals = map[string]Value{
return nil, nil
},
nil,
false,
},
"format": &BuiltinFunctionValue{
"format",
@ -356,6 +358,7 @@ var DefaultGlobals = map[string]Value{
return GoToValue(b.String()), nil
},
nil,
true,
},
"char": &BuiltinFunctionValue{
"char",
@ -372,6 +375,7 @@ var DefaultGlobals = map[string]Value{
}, nil
},
nil,
true,
},
"assertEq": &BuiltinFunctionValue{
"assertEq",
@ -393,6 +397,7 @@ var DefaultGlobals = map[string]Value{
return &NilValue{}, nil
},
nil,
false,
},
"assertNotEq": &BuiltinFunctionValue{
"assertNotEq",
@ -414,6 +419,7 @@ var DefaultGlobals = map[string]Value{
return &NilValue{}, nil
},
nil,
false,
},
"str": &BuiltinFunctionValue{
"str",
@ -425,6 +431,21 @@ var DefaultGlobals = map[string]Value{
return GoToValue(args[0].String()), nil
},
nil,
true,
},
"type": &BuiltinFunctionValue{
Name: "type",
Signature: &FunctionSignature{
In: []TypeSignature{&AnySignature{}},
Out: &StringSignature{},
},
F: func(vm *VM, this Value, args []Value) (Value, error) {
v := args[0]
sig := SignatureOf(v)
return GoToValue(sig.String()), nil
},
Constant: true,
},
"exit": &BuiltinFunctionValue{
"exit",
@ -437,6 +458,7 @@ var DefaultGlobals = map[string]Value{
return &NilValue{}, nil
},
nil,
false,
},
}