Mercurial > repos > tabletprog
comparison modules/bytearray.tp @ 368:0673ccbc7379
Add clone bethod to bytearray module
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 09 Aug 2015 20:00:08 -0700 |
parents | 06dceff348ea |
children |
comparison
equal
deleted
inserted
replaced
367:e2c1309ab750 | 368:0673ccbc7379 |
---|---|
53 if: (newsize num) < bytes { | 53 if: (newsize num) < bytes { |
54 bytes <- newsize num | 54 bytes <- newsize num |
55 } | 55 } |
56 self | 56 self |
57 } | 57 } |
58 | |
59 llMessage: clone withVars: { | |
60 opaque <- cpointer ptr | |
61 szo <- obj_int32 ptr | |
62 } andCode: { | |
63 opaque <- make_object: (addr_of: cpointer_meta) NULL 0 | |
64 opaque val!: (GC_MALLOC_ATOMIC: bytes) | |
65 memcpy: (opaque val) buffer bytes | |
66 szo <- make_object: (addr_of: obj_int32_meta) NULL 0 | |
67 szo num!: bytes | |
68 mcall: fromOpaque:withSize 3 bytearray opaque szo | |
69 } | |
58 | 70 |
59 llMessage: stringFrom:to withVars: { | 71 llMessage: stringFrom:to withVars: { |
60 from <- obj_int32 ptr | 72 from <- obj_int32 ptr |
61 to <- obj_int32 ptr | 73 to <- obj_int32 ptr |
62 str <- string ptr | 74 str <- string ptr |
182 bytes fold: 0 with: :idx el { | 194 bytes fold: 0 with: :idx el { |
183 el flattenTo: ba at: idx | 195 el flattenTo: ba at: idx |
184 } | 196 } |
185 ba | 197 ba |
186 } | 198 } |
199 | |
200 main <- { | |
201 str <- "foobarbaz\n" | |
202 buf <- normal: (str byte_length) | |
203 i <- 0 | |
204 while: { i < (str byte_length) } do: { | |
205 buf set: i (str byte: i) | |
206 i <- i + 1 | |
207 } | |
208 print: (string: buf) | |
209 print: (string: (buf clone)) | |
210 } | |
187 } | 211 } |