Skip to content

Commit 9604fed

Browse files
gh-112: Add operator ISMAP.
1 parent a237886 commit 9604fed

5 files changed

Lines changed: 32 additions & 1 deletion

File tree

docs/SPECIFICATION.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@
705705

706706
- `BOOL: EXIST(SYMBOL: name)` = MUST return `TRUE` if `name` resolves to a visible readable binding in the current lexical environment chain and `FALSE` otherwise.
707707

708-
- `BOOL: ISBOOL/ISINT/ISFLT/ISSTR/ISTNS(ANY: value)` = MUST return `TRUE` if the runtime type of `value` is respectively `BOOL`, `INT`, `FLT`, `STR`, or `TNS`, and `FALSE` otherwise.
708+
- `BOOL: ISBOOL/ISINT/ISFLT/ISSTR/ISTNS/ISMAP(ANY: value)` = MUST return `TRUE` if the runtime type of `value` is respectively `BOOL`, `INT`, `FLT`, `STR`, `TNS`, or `MAP`, and `FALSE` otherwise.
709709

710710
- `STR: TYPE(ANY: value)` = MUST return the runtime type name of `value` as a `STR`. For core language values, the result MUST be one of `BOOL`, `INT`, `FLT`, `STR`, `TNS`, `MAP`, `FUNC`, or `THR`. For null or otherwise unrecognized internal values, the result MUST be `NULL`. Extension-defined values MUST report their registered type names.
711711

src/builtins.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6540,6 +6540,11 @@ static Value builtin_istns(Interpreter* interp, Value* args, int argc, Expr** ar
65406540
return value_bool(args[0].type == VAL_TNS);
65416541
}
65426542

6543+
static Value builtin_ismap(Interpreter* interp, Value* args, int argc, Expr** arg_nodes, Env* env, int line, int col) {
6544+
(void)arg_nodes; (void)env; (void)interp; (void)line; (void)col;
6545+
return value_bool(args[0].type == VAL_MAP);
6546+
}
6547+
65436548
static Value builtin_type(Interpreter* interp, Value* args, int argc, Expr** arg_nodes, Env* env, int line, int col) {
65446549
(void)arg_nodes; (void)env; (void)interp; (void)line; (void)col;
65456550
return value_str(value_type_name(args[0]));
@@ -9067,6 +9072,7 @@ static BuiltinFunction builtins_table[] = {
90679072
{"ISFLT", 1, 1, builtin_isflt},
90689073
{"ISSTR", 1, 1, builtin_isstr},
90699074
{"ISTNS", 1, 1, builtin_istns},
9075+
{"ISMAP", 1, 1, builtin_ismap},
90709076
{"TYPE", 1, 1, builtin_type},
90719077
{"SIGNATURE", 1, 1, builtin_signature},
90729078

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ISMAP(TRUE, FALSE)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ISMAP()

tests/cases/passing/ismap.pre

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
BOOL: sample_bool_true = TRUE
2+
BOOL: sample_bool_false = FALSE
3+
INT: sample_int = -0d7
4+
FLT: sample_flt = 0d3.5
5+
STR: sample_str = "prefix"
6+
TNS: sample_tns = [0d1, 0d2]
7+
MAP: sample_map = <"n" = 0d1>
8+
9+
FUNC INT: sample_func(INT: value){
10+
RETURN(value)
11+
}
12+
13+
THR(sample_thr){}
14+
15+
ASSERT(ISMAP(sample_map))
16+
ASSERT(NOT(ISMAP(sample_bool_true)))
17+
ASSERT(NOT(ISMAP(sample_bool_false)))
18+
ASSERT(NOT(ISMAP(sample_int)))
19+
ASSERT(NOT(ISMAP(sample_flt)))
20+
ASSERT(NOT(ISMAP(sample_str)))
21+
ASSERT(NOT(ISMAP(sample_tns)))
22+
ASSERT(NOT(ISMAP(sample_func)))
23+
ASSERT(NOT(ISMAP(sample_thr)))

0 commit comments

Comments
 (0)