From d5d5e9c48a1583960ddb2db550e947926f9f869e Mon Sep 17 00:00:00 2001 From: mryouse Date: Thu, 12 May 2022 02:12:48 +0000 Subject: type compare and Any type --- std.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'std.py') diff --git a/std.py b/std.py index 1393acf..26c6793 100644 --- a/std.py +++ b/std.py @@ -66,6 +66,13 @@ def std_if(cond, t_branch, f_branch): ret = evaluate_expression(f_branch) return ret +# type validation +def std_is_string(arg): + if isinstance(arg, NebString): + 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}") @@ -83,6 +90,7 @@ def evaluate_expression(expr): if isinstance(in_sig[idx], sig[idx]): validated += 1 if validated == len(sig): + print(f"{value.func.args}") ret = value.impl(*(expr.args)) return ret @@ -122,7 +130,11 @@ def build_std(): STD["concat"] = [concat_string_string] # flow control - if_bool_expr_expr = FuncImpl(NebFunction("if", [NebBool, NebExpression, NebExpression], NebType.ANY), std_if) + if_bool_expr_expr = FuncImpl(NebFunction("if", [NebBool, NebExpression, NebExpression], NebAny), std_if) STD["if"] = [if_bool_expr_expr] + # type checking + is_string = FuncImpl(NebFunction("string?", [NebAny], NebBool), std_is_string) + STD["string?"] = [is_string] + build_std() -- cgit v1.2.3