Mercurial > repos > tabletprog
changeset 368:0673ccbc7379
Add clone bethod to bytearray module
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 09 Aug 2015 20:00:08 -0700 |
parents | e2c1309ab750 |
children | 93c28eee141e |
files | modules/bytearray.tp |
diffstat | 1 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/modules/bytearray.tp Sun Aug 09 18:07:23 2015 -0700 +++ b/modules/bytearray.tp Sun Aug 09 20:00:08 2015 -0700 @@ -55,6 +55,18 @@ } self } + + llMessage: clone withVars: { + opaque <- cpointer ptr + szo <- obj_int32 ptr + } andCode: { + opaque <- make_object: (addr_of: cpointer_meta) NULL 0 + opaque val!: (GC_MALLOC_ATOMIC: bytes) + memcpy: (opaque val) buffer bytes + szo <- make_object: (addr_of: obj_int32_meta) NULL 0 + szo num!: bytes + mcall: fromOpaque:withSize 3 bytearray opaque szo + } llMessage: stringFrom:to withVars: { from <- obj_int32 ptr @@ -184,4 +196,16 @@ } ba } + + main <- { + str <- "foobarbaz\n" + buf <- normal: (str byte_length) + i <- 0 + while: { i < (str byte_length) } do: { + buf set: i (str byte: i) + i <- i + 1 + } + print: (string: buf) + print: (string: (buf clone)) + } }