# HG changeset patch # User Michael Pavone # Date 1439175608 25200 # Node ID 0673ccbc737954179539b4cc4eb38dde4e15641a # Parent e2c1309ab7507a217f0d1acac34963eb78e323c2 Add clone bethod to bytearray module diff -r e2c1309ab750 -r 0673ccbc7379 modules/bytearray.tp --- 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)) + } }