From d804b09b02b9c4a6ea6b16ae85524a704796cbc1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 18 Aug 2024 20:28:16 -0400 Subject: Added a .length field to arrays/sets/tables, added a .max_size field to channels, and updated the API --- compile.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index cc06b92d..5e97d0ea 100644 --- a/compile.c +++ b/compile.c @@ -2630,13 +2630,27 @@ CORD compile(env_t *env, ast_t *ast) } code_err(ast, "The field '%s' is not a valid field name of %T", f->field, value_t); } + case ArrayType: { + if (streq(f->field, "length")) + return CORD_all("Int64_to_Int((", compile_to_pointer_depth(env, f->fielded, 0, false), ").length)"); + code_err(ast, "There is no %s field on arrays", f->field); + } + case ChannelType: { + if (streq(f->field, "max_size")) + return CORD_all("Int64_to_Int((", compile_to_pointer_depth(env, f->fielded, 0, false), ")->max_size)"); + code_err(ast, "There is no %s field on arrays", f->field); + } case SetType: { if (streq(f->field, "items")) return CORD_all("(", compile_to_pointer_depth(env, f->fielded, 0, false), ").entries"); + else if (streq(f->field, "length")) + return CORD_all("Int64_to_Int((", compile_to_pointer_depth(env, f->fielded, 0, false), ").entries.length)"); code_err(ast, "There is no '%s' field on sets", f->field); } case TableType: { - if (streq(f->field, "keys")) { + if (streq(f->field, "length")) { + return CORD_all("Int64_to_Int((", compile_to_pointer_depth(env, f->fielded, 0, false), ").entries.length)"); + } else if (streq(f->field, "keys")) { return CORD_all("(", compile_to_pointer_depth(env, f->fielded, 0, false), ").entries"); } else if (streq(f->field, "values")) { auto table = Match(value_t, TableType); -- cgit v1.2.3