Add Nil constructor and tests
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -569,3 +569,13 @@ impl Bool {
|
|||||||
Float::create(bool_value as i64 as f64).into()
|
Float::create(bool_value as i64 as f64).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Nil {
|
||||||
|
pub(crate) fn do_call(_vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||||
|
FunctionResult::ReturnPush(Nil::create())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn init(_vm: &mut Vm, _state: FunctionState) -> FunctionResult {
|
||||||
|
FunctionResult::ReturnPush(Nil::create())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
10
src/obj.rs
10
src/obj.rs
@@ -221,7 +221,15 @@ pub fn init_types() {
|
|||||||
|
|
||||||
// Operators
|
// Operators
|
||||||
},
|
},
|
||||||
Nil { },
|
Nil {
|
||||||
|
// Conversion methods
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
__call__ => BuiltinFunction::create("__call__", Nil::do_call, 1),
|
||||||
|
__init__ => BuiltinFunction::create("__init__", Nil::init, 1),
|
||||||
|
|
||||||
|
// Operators
|
||||||
|
},
|
||||||
BuiltinFunction { },
|
BuiltinFunction { },
|
||||||
UserFunction { },
|
UserFunction { },
|
||||||
Method { },
|
Method { },
|
||||||
|
|||||||
@@ -70,3 +70,4 @@ println(Bool("true"))
|
|||||||
println(Bool(1))
|
println(Bool(1))
|
||||||
println(Bool(1.0))
|
println(Bool(1.0))
|
||||||
println(Bool(true))
|
println(Bool(true))
|
||||||
|
println(Bool(nil))
|
||||||
|
|||||||
@@ -53,3 +53,4 @@ true
|
|||||||
true
|
true
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
|
false
|
||||||
|
|||||||
16
tests/nil.npp
Normal file
16
tests/nil.npp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Nil type operator and function tests
|
||||||
|
|
||||||
|
a = nil
|
||||||
|
|
||||||
|
println("__not__")
|
||||||
|
println(!nil)
|
||||||
|
println(!!nil)
|
||||||
|
|
||||||
|
println("__eq__")
|
||||||
|
println(nil == nil)
|
||||||
|
|
||||||
|
println("__ne__")
|
||||||
|
println(nil != nil)
|
||||||
|
|
||||||
|
println("constructor")
|
||||||
|
println(Nil())
|
||||||
9
tests/nil.npp.expect
Normal file
9
tests/nil.npp.expect
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
__not__
|
||||||
|
true
|
||||||
|
false
|
||||||
|
__eq__
|
||||||
|
true
|
||||||
|
__ne__
|
||||||
|
false
|
||||||
|
constructor
|
||||||
|
nil
|
||||||
Reference in New Issue
Block a user