diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-11 15:04:22 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-11 15:04:22 -0400 |
| commit | d2f4d07585d1e915365f3aaea6fc696e00a9e26d (patch) | |
| tree | 12cf2a0f978835bc55db572df8e0d114c9b89494 /compile.c | |
| parent | 2ecb5fe885042ca6c25ee0a3e3da070ddec9e07e (diff) | |
Support channels with maximum size
Diffstat (limited to 'compile.c')
| -rw-r--r-- | compile.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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); |
