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 +++++++++++++- tokens.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) 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() diff --git a/tokens.py b/tokens.py index a8f6268..66fb98d 100644 --- a/tokens.py +++ b/tokens.py @@ -31,7 +31,7 @@ class NebAny(NebBaseType): def __init__(self, type_name, type_): super().__init__("any", NebType.ANY) -class NebLiteral(NebBaseType): +class NebLiteral(NebAny): def __init__(self, type_name, type_, value): super().__init__(type_name, type_) -- cgit v1.2.3