aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-11 15:04:22 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-11 15:04:22 -0400
commitd2f4d07585d1e915365f3aaea6fc696e00a9e26d (patch)
tree12cf2a0f978835bc55db572df8e0d114c9b89494 /compile.c
parent2ecb5fe885042ca6c25ee0a3e3da070ddec9e07e (diff)
Support channels with maximum size
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/compile.c b/compile.c
index 8e8f7c6e..df830a9b 100644
--- a/compile.c
+++ b/compile.c
@@ -1747,10 +1747,18 @@ CORD compile(env_t *env, ast_t *ast)
}
}
case Channel: {
- type_t *item_t = parse_type_ast(env, Match(ast, Channel)->item_type);
+ auto chan = Match(ast, Channel);
+ type_t *item_t = parse_type_ast(env, chan->item_type);
if (!can_send_over_channel(item_t))
code_err(ast, "This item type can't be sent over a channel because it contains reference to memory that may not be thread-safe.");
- return "Channel$new()";
+ if (chan->max_size) {
+ CORD max_size = compile(env, chan->max_size);
+ if (!promote(env, &max_size, get_type(env, chan->max_size), INT_TYPE))
+ code_err(chan->max_size, "This value must be an integer, not %T", get_type(env, chan->max_size));
+ return CORD_all("Channel$new(", max_size, ")");
+ } else {
+ return "Channel$new(INT64_MAX)";
+ }
}
case Table: {
auto table = Match(ast, Table);