From 9a8324315c74ea102e0fb0ed22c695ce78c221c7 Mon Sep 17 00:00:00 2001 From: mryouse Date: Thu, 12 May 2022 02:32:51 +0000 Subject: native type compare methods --- std.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'std.py') diff --git a/std.py b/std.py index 26c6793..235d560 100644 --- a/std.py +++ b/std.py @@ -73,6 +73,30 @@ def std_is_string(arg): else: return NebBool(False) +def std_is_int(arg): + if isinstance(arg, NebInt): + return NebBool(True) + else: + return NebBool(False) + +def std_is_float(arg): + if isinstance(arg, NebFloat): + return NebBool(True) + else: + return NebBool(False) + +def std_is_number(arg): + if isinstance(arg, NebNumber): + return NebBool(True) + else: + return NebBool(False) + +def std_is_bool(arg): + if isinstance(arg, NebBool): + return NebBool(True) + else: + return NebBool(False) + def evaluate_expression(expr): if not expr.symbol.name in STD: raise Exception(f"no such symbol: {expr.symbol.name}") @@ -136,5 +160,13 @@ def build_std(): # type checking is_string = FuncImpl(NebFunction("string?", [NebAny], NebBool), std_is_string) STD["string?"] = [is_string] + is_int = FuncImpl(NebFunction("string?", [NebAny], NebBool), std_is_int) + STD["int?"] = [is_int] + is_float = FuncImpl(NebFunction("string?", [NebAny], NebBool), std_is_float) + STD["float?"] = [is_float] + is_number = FuncImpl(NebFunction("string?", [NebAny], NebBool), std_is_number) + STD["number?"] = [is_number] + is_bool = FuncImpl(NebFunction("string?", [NebAny], NebBool), std_is_bool) + STD["bool?"] = [is_bool] build_std() -- cgit v1.2.3