Mercurial > repos > tabletprog
comparison modules/string.tp @ 93:46504d34cb44
merge
author | William Morgan <bill@mrgn.org> |
---|---|
date | Tue, 24 Jul 2012 00:35:24 -0700 |
parents | 474f17ebaaa0 |
children | 4c96a393103e |
comparison
equal
deleted
inserted
replaced
92:6abbf2454657 | 93:46504d34cb44 |
---|---|
1 #{ | |
2 llProperty: len withType: uint32_t | |
3 llProperty: bytes withType: uint32_t | |
4 llProperty: data withType: (char ptr) | |
5 | |
6 llMessage: length withVars: { | |
7 intret <- (obj_int32 ptr) | |
8 } andCode: { | |
9 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | |
10 intret num!: len | |
11 intret | |
12 } | |
13 | |
14 llMessage: byte_length withVars: { | |
15 intret <- (obj_int32 ptr) | |
16 } andCode: { | |
17 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | |
18 intret num!: bytes | |
19 intret | |
20 } | |
21 | |
22 llMessage: EQ_ withVars: { | |
23 argb <- (string ptr) | |
24 } andCode: :argb { | |
25 if: len = (argb len) && bytes = (argb bytes) && (not: (memcmp: data (argb data) bytes)) { | |
26 true | |
27 } | |
28 } | |
29 | |
30 llMessage: NEQ_ withVars: { | |
31 argb <- (string ptr) | |
32 } andCode: :argb { | |
33 if: len != (argb len) || bytes != (argb bytes) || (memcmp: data (argb data) bytes) { | |
34 true | |
35 } | |
36 } | |
37 | |
38 llMessage: print withVars: {} andCode: { | |
39 fwrite: data 1 bytes stdout | |
40 self | |
41 } | |
42 | |
43 llMessage: string withVars: {} andCode: { | |
44 self | |
45 } | |
46 | |
47 llMessage: CAT_ withVars: { | |
48 argbo <- (object ptr) | |
49 argb <- (string ptr) | |
50 out <- (string ptr) | |
51 } andCode: :argbo { | |
52 argb <- mcall: string 1 argbo | |
53 out <- make_object: (addr_of: string_meta) NULL 0 | |
54 out bytes!: bytes + (argb bytes) | |
55 out len!: len + (argb len) | |
56 out data!: (GC_MALLOC_ATOMIC: (out bytes) + 1) | |
57 memcpy: (out data) data bytes | |
58 memcpy: (out data) + bytes (argb data) (argb bytes) + 1 | |
59 out | |
60 } | |
61 | |
62 llMessage: byte withVars: { | |
63 index <- (obj_int32 ptr) | |
64 intret <- (obj_int32 ptr) | |
65 } andCode: :index { | |
66 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | |
67 intret num!: (if: (index num) < bytes { data get: (index num) } else: {0}) | |
68 intret | |
69 } | |
70 | |
71 llMessage: int32 withVars: { | |
72 intret <- (obj_int32 ptr) | |
73 } andCode: { | |
74 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | |
75 intret num!: (atoi: data) | |
76 intret | |
77 } | |
78 | |
79 llMessage: hash withVars: { | |
80 intret <- (obj_int32 ptr) | |
81 i <- uint32_t | |
82 } andCode: { | |
83 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 | |
84 intret num!: 0 | |
85 if: bytes { | |
86 intret num!: (data get: 0) * 128 | |
87 i <- 0 | |
88 while: { i < bytes } do: { | |
89 intret num!: (1000003 * (intret num)) xor (data get: i) | |
90 i <- i + 1 | |
91 } | |
92 intret num!: (intret num) xor bytes | |
93 } | |
94 intret | |
95 } | |
96 } |