diff options
| author | mryouse | 2022-06-18 04:13:39 +0000 |
|---|---|---|
| committer | mryouse | 2022-06-18 04:13:39 +0000 |
| commit | 2f35362db78fb9ac1a4399b8d9c4f46bd2a46631 (patch) | |
| tree | 3d82fd06d07ddeb52caf2a52ecffc953ddb1455a | |
| parent | 202343704ea15c2fe76bb168c21516e3f57455a9 (diff) | |
implement type checking functions
| -rw-r--r-- | neb/interpreter.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/neb/interpreter.py b/neb/interpreter.py index e64e420..2461f90 100644 --- a/neb/interpreter.py +++ b/neb/interpreter.py @@ -820,3 +820,29 @@ def interpretTypeOf(symbol, args, env, ns): return Type(f"{args[0].type_}") GLOBALS.register("typeof", Builtin(interpretTypeOf, [Arg("candidate", TypeEnum.ANY)])) + +def interpretIsString(symbol, args, env, ns): + return Bool(isinstance(args[0], String)) + +GLOBALS.register("string?", Builtin(interpretIsString, [Arg("arg", TypeEnum.ANY)])) + +def interpretIsInt(symbol, args, env, ns): + return Bool(isinstance(args[0], Int)) + +GLOBALS.register("int?", Builtin(interpretIsInt, [Arg("arg", TypeEnum.ANY)])) + +def interpretIsFloat(symbol, args, env, ns): + return Bool(isinstance(args[0], Float)) + +GLOBALS.register("float?", Builtin(interpretIsFloat, [Arg("arg", TypeEnum.ANY)])) + +def interpretIsNumber(symbol, args, env, ns): + ret = isinstance(args[0], Int) or isinstance(args[0], Float) + return Bool(ret) + +GLOBALS.register("number?", Builtin(interpretIsNumber, [Arg("arg", TypeEnum.ANY)])) + +def interpretIsBool(symbol, args, env, ns): + return Bool(isinstance(args[0], Bool)) + +GLOBALS.register("bool?", Builtin(interpretIsBool, [Arg("arg", TypeEnum.ANY)])) |
