diff options
| author | mryouse | 2022-05-12 02:12:48 +0000 | 
|---|---|---|
| committer | mryouse | 2022-05-12 02:12:48 +0000 | 
| commit | d5d5e9c48a1583960ddb2db550e947926f9f869e (patch) | |
| tree | ec6029a7886204114091ca53249150e9158c07ec | |
| parent | d75ab6f5ef14cab3c2ad3841258656e217d36043 (diff) | |
type compare and Any type
| -rw-r--r-- | std.py | 14 | ||||
| -rw-r--r-- | tokens.py | 2 | 
2 files changed, 14 insertions, 2 deletions
| @@ -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() @@ -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_) | 
