From 10e86153a2c619d7f853ab149e451a9cc05fdb27 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 10 Jul 2024 13:34:45 -0400 Subject: Replace array:slice() with array:from(first, last) and array:by(step) --- compile.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 09314c82..9d6b1665 100644 --- a/compile.c +++ b/compile.c @@ -1813,13 +1813,15 @@ CORD compile(env_t *env, ast_t *ast) CORD self = compile_to_pointer_depth(env, call->self, 1, false); (void)compile_arguments(env, ast, NULL, call->args); return CORD_all("Array$clear(", self, ")"); - } else if (streq(call->name, "slice")) { + } else if (streq(call->name, "from")) { CORD self = compile_to_pointer_depth(env, call->self, 1, false); arg_t *arg_spec = new(arg_t, .name="first", .type=Type(IntType, .bits=64), .default_val=FakeAST(Int, .i=1, .bits=64), - .next=new(arg_t, .name="length", .type=Type(IntType, .bits=64), .default_val=FakeAST(Int, .i=INT64_MAX, .bits=64), - .next=new(arg_t, .name="stride", .type=Type(IntType, .bits=64), .default_val=FakeAST(Int, .i=1, .bits=64)))); - return CORD_all("Array$slice(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", - compile_type_info(env, self_value_t), ")"); + .next=new(arg_t, .name="last", .type=Type(IntType, .bits=64), .default_val=FakeAST(Int, .i=-1, .bits=64))); + return CORD_all("Array$from(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ")"); + } else if (streq(call->name, "by")) { + CORD self = compile_to_pointer_depth(env, call->self, 1, false); + arg_t *arg_spec = new(arg_t, .name="stride", .type=Type(IntType, .bits=64)); + return CORD_all("Array$by(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ")"); } else if (streq(call->name, "reversed")) { CORD self = compile_to_pointer_depth(env, call->self, 0, false); (void)compile_arguments(env, ast, NULL, call->args); -- cgit v1.2.3