From d2f4d07585d1e915365f3aaea6fc696e00a9e26d Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 11 Aug 2024 15:04:22 -0400 Subject: Support channels with maximum size --- compile.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'compile.c') 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); -- cgit v1.2.3