comparison modules/bytearray.tp @ 377:93c28eee141e default tip

Merge
author Michael Pavone <pavone@retrodev.com>
date Sat, 15 Aug 2015 22:45:33 -0700
parents 0673ccbc7379
children
comparison
equal deleted inserted replaced
376:d61b1f0e1936 377:93c28eee141e
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 }