about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-07-26 12:48:54 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-07-26 12:48:54 -0700
commit5b7de7f6d6b613184b7e808b1700fa6c918c8d6f (patch)
treea463e9ccc316958f6166c507c68d57fb2df8f19d
parent29c2f5a398a5f0305b6628fdc01b1d0cb45bda8a (diff)
downloadmu-5b7de7f6d6b613184b7e808b1700fa6c918c8d6f.tar.gz
5 - first stab at allocator, just for ints
Still can't write to a pointer.
-rw-r--r--mu.arc5
-rw-r--r--new.mu14
2 files changed, 19 insertions, 0 deletions
diff --git a/mu.arc b/mu.arc
index 1c58fd8c..ac1cceb6 100644
--- a/mu.arc
+++ b/mu.arc
@@ -99,6 +99,11 @@
 ;?                   (prn "jumping to " arg.1.1)
                   (= pc (+ pc arg.1.1))  ; relies on continue still incrementing (bug)
                   (continue))
+              copy
+                (= (memory* oarg.0.1) (memory* arg.0.1))
+              deref
+                (= (memory* oarg.0.1)
+                   (memory* (memory* arg.0.1)))
               reply
                 (do (= result arg)
                     (break))
diff --git a/new.mu b/new.mu
new file mode 100644
index 00000000..0f86f378
--- /dev/null
+++ b/new.mu
@@ -0,0 +1,14 @@
+; memory map: 1-1000 reserved for the (currently non-reentrant) allocator
+(main
+  ((integer 1) <- literal 1000)  ; location 1 contains the high-water mark for the memory allocator
+  ((integer-pointer 4) <- new)
+  ((integer 5) <- deref (integer-pointer 4))
+)
+
+(new
+  ((integer-pointer 2) <- copy (integer 1))
+  ((integer 3) <- literal 1)
+  ((integer 1) <- add (integer 1) (integer 3))
+  (reply (integer-pointer 2)))
+
+;; vim:ft=scheme