engine: local, lang: core: local: Add a pool function

This adds a new local API for pool allocation, and with it a
corresponding function in the "local" import.
This commit is contained in:
James Shubin
2024-10-04 22:37:39 -04:00
parent 898b58e3e7
commit c937280664
3 changed files with 362 additions and 0 deletions

19
examples/lang/pool.mcl Normal file
View File

@@ -0,0 +1,19 @@
# Remember that across runs if you use --tmp-prefix, this will give you new
# values each time! The local prefix is where the pool of values is taken from!
import "fmt"
import "local"
$ns = "my_namespace"
$i = local.pool($ns, "james") # the uid "james" will always return the same int
$j = local.pool($ns, "purple") # this is like a pool based allocator
print "value:i" {
msg => fmt.printf("i: %d", $i),
Meta:autogroup => false,
}
print "value:j" {
msg => fmt.printf("j: %d", $j),
Meta:autogroup => false,
}