about summary refs log tree commit diff stats
path: root/mu_instructions
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-07-13 22:21:26 -0700
committerKartik Agaram <vc@akkartik.com>2020-07-13 22:21:26 -0700
commit5e0ae917d07740b9a06f3255591245acfcd9389e (patch)
treec3ce38ac880ec529863c11a7663be607e27571d5 /mu_instructions
parent4cb4d4d2d8002705c966ae7bed0b7332f4e21978 (diff)
downloadmu-5e0ae917d07740b9a06f3255591245acfcd9389e.tar.gz
6645 - heap allocations in Mu
- allocate var
- populate var, n

Both rely on the type of `var` to compute the size of the allocation. No
need to repeat the name of the type like in C, C++ or Java.
Diffstat (limited to 'mu_instructions')
-rw-r--r--mu_instructions8
1 files changed, 8 insertions, 0 deletions
diff --git a/mu_instructions b/mu_instructions
index 7b38a1f8..c23606ec 100644
--- a/mu_instructions
+++ b/mu_instructions
@@ -258,4 +258,12 @@ out/reg: (addr T) <- lookup in: (handle T)
      "8b/-> *(epb+" (in.stack-offset+4) ") " reg "/r32"
      "81 0/subop/add %" reg " 4/imm32"  # skip payload->allocid
 
+# Allocating memory
+
+allocate in: (addr handle T)
+  => "(allocate Heap " size-of(T) " " in ")"
+
+populate in: (addr handle array T), num  # can be literal or variable on stack or register
+  => "(allocate-array2 Heap " size-of(T) " " num " " in ")"
+
 vim:ft=mu:nowrap:textwidth=0