diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-11-26 22:43:51 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-11-26 22:43:51 -0800 |
commit | 1b58aa1dec71d437965327c7f88cc54f134fed02 (patch) | |
tree | f0f42c010e9c7f7a458a8c2b040044bf1cd4d784 /mu.arc.t | |
parent | 2e818ac82fdcf6474d1cf1a0634aba80af1279e4 (diff) | |
download | mu-1b58aa1dec71d437965327c7f88cc54f134fed02.tar.gz |
339 - string literals for convenience
I'm cheating a little when it comes to strings, making use of Racket primitives. But in principle it seems like a local transform to implement even in machine code.
Diffstat (limited to 'mu.arc.t')
-rw-r--r-- | mu.arc.t | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/mu.arc.t b/mu.arc.t index bad704c8..cbb566bc 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -2881,4 +2881,22 @@ (if (~iso Memory-in-use-until (+ before 5 1)) (prn "F - 'new' allocates arrays of bytes for strings"))) +; Convenience: initialize strings using string literals +(reset) +(new-trace "string-literal") +(add-code '((def main [ + ((1 integer) <- new "hello") + ]))) +(let before Memory-in-use-until + (run 'main) + (if (~iso Memory-in-use-until (+ before 5 1)) + (prn "F - 'new' allocates arrays of bytes for string literals")) + (if (or (~is 5 (memory* before)) + (~is #\h (memory* (+ before 1))) + (~is #\e (memory* (+ before 2))) + (~is #\l (memory* (+ before 3))) + (~is #\l (memory* (+ before 4))) + (~is #\o (memory* (+ before 5)))) + (prn "F - 'new' initializes allocated memory to string literal"))) + (reset) ; end file with this to persist the trace for the final test |