Add array:sample(n, weights)

This commit is contained in:
Bruce Hill 2024-04-02 23:40:18 -04:00
parent 728cd8026c
commit 6eb680f1b7

View File

@ -1484,7 +1484,8 @@ CORD compile(env_t *env, ast_t *ast)
} else if (streq(call->name, "sample")) {
CORD self = compile_to_pointer_depth(env, call->self, 0, false);
arg_t *arg_spec = new(arg_t, .name="count", .type=Type(IntType, .bits=64),
.next=new(arg_t, .name="weights", .type=self_value_t, .default_val=FakeAST(Array)));
.next=new(arg_t, .name="weights", .type=Type(ArrayType, .item_type=Type(NumType, .bits=64)),
.default_val=FakeAST(Array, .type=new(type_ast_t, .tag=VarTypeAST, .__data.VarTypeAST.name="Num"))));
return CORD_all("Array$sample(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ",
compile_type_info(env, self_value_t), ")");
} else if (streq(call->name, "shuffle")) {