annotate modules/string.tp @ 158:38140b7dbe3d

Add parseHex32 and parseHex64 to string objects
author Mike Pavone <pavone@retrodev.com>
date Sat, 10 Aug 2013 15:20:38 -0700
parents 55e0dca7d3d7
children 5b830147c1cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #{
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 llProperty: len withType: uint32_t
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 llProperty: bytes withType: uint32_t
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 llProperty: data withType: (char ptr)
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
5
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 llMessage: length withVars: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 intret <- (obj_int32 ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 } andCode: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 intret num!: len
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 intret
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 }
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
13
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 llMessage: byte_length withVars: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15 intret <- (obj_int32 ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 } andCode: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 intret num!: bytes
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 intret
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 }
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
21
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
22 llMessage: EQ_ withVars: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 argb <- (string ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24 } andCode: :argb {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
25 if: len = (argb len) && bytes = (argb bytes) && (not: (memcmp: data (argb data) bytes)) {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26 true
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27 }
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 }
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
29
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30 llMessage: NEQ_ withVars: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31 argb <- (string ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 } andCode: :argb {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
33 if: len != (argb len) || bytes != (argb bytes) || (memcmp: data (argb data) bytes) {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34 true
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
35 }
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 }
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
37
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
38 llMessage: print withVars: {} andCode: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 fwrite: data 1 bytes stdout
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 self
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41 }
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
42
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 llMessage: string withVars: {} andCode: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 self
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45 }
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
46
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 llMessage: CAT_ withVars: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 argbo <- (object ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 argb <- (string ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 out <- (string ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51 } andCode: :argbo {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 argb <- mcall: string 1 argbo
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 out <- make_object: (addr_of: string_meta) NULL 0
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
54 out bytes!: bytes + (argb bytes)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 out len!: len + (argb len)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56 out data!: (GC_MALLOC_ATOMIC: (out bytes) + 1)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57 memcpy: (out data) data bytes
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 memcpy: (out data) + bytes (argb data) (argb bytes) + 1
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 out
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60 }
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
61
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
62 llMessage: byte withVars: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 index <- (obj_int32 ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
64 intret <- (obj_int32 ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 } andCode: :index {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 intret num!: (if: (index num) < bytes { data get: (index num) } else: {0})
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 intret
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 }
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
70
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 llMessage: int32 withVars: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 intret <- (obj_int32 ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 } andCode: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
74 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
75 intret num!: (atoi: data)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
76 intret
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
77 }
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
78
158
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
79 parseHex32 <- {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
80 num <- 0u32
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
81 cur <- 0
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
82 a <- uint32: ("a" byte: 0)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
83 A <- uint32: ("A" byte: 0)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
84 f <- uint32: ("f" byte: 0)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
85 F <- uint32: ("F" byte: 0)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
86 zero <- "0" byte: 0
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
87 nine <- "9" byte: 0
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
88 while: { cur < byte_length} do: {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
89 b <- uint32: (byte: cur)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
90 cur <- cur + 1
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
91 if: b >= zero && b <= nine {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
92 num <- num * 16 + (b - zero)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
93 } else: {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
94 if: b >= a && b <= f {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
95 num <- num * 16 + (b - a) + 10u32
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
96 } else: {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
97 if: b >= A && b <= F {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
98 num <- num * 16 + (b - A) + 10u32
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
99 } else: {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
100 cur <- byte_length
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
101 }
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
102 }
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
103 }
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
104 }
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
105 num
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
106 }
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
107
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
108 parseHex64 <- {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
109 num <- 0u64
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
110 cur <- 0
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
111 a <- uint64: ("a" byte: 0)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
112 A <- uint64: ("A" byte: 0)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
113 f <- uint64: ("f" byte: 0)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
114 F <- uint64: ("F" byte: 0)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
115 zero <- "0" byte: 0
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
116 nine <- "9" byte: 0
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
117 while: { cur < byte_length} do: {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
118 b <- uint64: (byte: cur)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
119 cur <- cur + 1
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
120 if: b >= zero && b <= nine {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
121 num <- num * 16 + (b - zero)
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
122 } else: {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
123 if: b >= a && b <= f {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
124 num <- num * 16 + (b - a) + 10u64
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
125 } else: {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
126 if: b >= A && b <= F {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
127 num <- num * 16 + (b - A) + 10u64
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
128 } else: {
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
129 cur <- byte_length
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
130 }
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
131 }
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
132 }
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
133 }
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
134 num
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
135 }
38140b7dbe3d Add parseHex32 and parseHex64 to string objects
Mike Pavone <pavone@retrodev.com>
parents: 157
diff changeset
136
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
137 llMessage: hash withVars: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
138 intret <- (obj_int32 ptr)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
139 i <- uint32_t
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
140 } andCode: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
141 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
142 intret num!: 0
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
143 if: bytes {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
144 intret num!: (data get: 0) * 128
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
145 i <- 0
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
146 while: { i < bytes } do: {
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
147 intret num!: (1000003 * (intret num)) xor (data get: i)
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
148 i <- i + 1
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
149 }
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
150 intret num!: (intret num) xor bytes
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
151 }
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
152 intret
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
153 }
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
154
154
6e579a75a0a9 Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
155 llMessage: find:startingAt:else withVars: {
150
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
156 intret <- obj_int32 ptr
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
157 oneedle <- object ptr
154
6e579a75a0a9 Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
158 startpos <- obj_int32 ptr
150
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
159 ifNotFound <- object ptr
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
160 sneedle <- string ptr
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
161 i <- uint32_t
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
162 notFound <- uint32_t
154
6e579a75a0a9 Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
163 } andCode: :oneedle :startpos :ifNotFound {
150
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
164 sneedle <- mcall: string 1 oneedle
154
6e579a75a0a9 Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
165 i <- startpos num
150
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
166 notFound <- 1
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
167 while: { notFound && i + (sneedle bytes) <= bytes} do: {
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
168 if: (memcmp: data + i (sneedle data) (sneedle bytes)) = 0 {
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
169 notFound <- 0
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
170 } else: {
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
171 i <- i + 1
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
172 }
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
173 }
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
174 if: notFound {
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
175 ccall: ifNotFound 0
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
176 } else: {
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
177 intret <- make_object: (addr_of: obj_int32_meta) NULL 0
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
178 intret num!: i
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
179 intret
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
180 }
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
181 }
7dfa4481deb0 Implement find:else on string objects
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
182
154
6e579a75a0a9 Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
183 find:else <- :toFind :orElse {
6e579a75a0a9 Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
184 find: toFind startingAt: 0 else: orElse
6e579a75a0a9 Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
185 }
6e579a75a0a9 Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
186
151
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
187 llMessage: from:withLength withVars: {
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
188 from <- obj_int32 ptr
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
189 tocopy <- obj_int32 ptr
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
190 ret <- string ptr
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
191 start <- int32_t
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
192 clampedLen <- int32_t
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
193 } andCode: :from :tocopy {
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
194 start <- from num
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
195 if: start < 0 {
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
196 start <- bytes + start
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
197 }
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
198 if: start > bytes {
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
199 start <- bytes
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
200 }
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
201 clampedLen <- tocopy num
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
202 if: start + clampedLen > bytes {
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
203 clampedLen <- bytes - start
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
204 }
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
205 ret <- make_object: (addr_of: string_meta) NULL 0
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
206 ret data!: (GC_MALLOC_ATOMIC: clampedLen + 1)
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
207 memcpy: (ret data) data + start clampedLen
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
208 ret len!: clampedLen
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
209 ret bytes!: clampedLen
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
210 ret
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
211 }
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
212
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
213 from <- :start {
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
214 from: start withLength: length
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
215 }
3e9cb69e516d Added from and from:withLength for doing substring operations
Mike Pavone <pavone@retrodev.com>
parents: 150
diff changeset
216
152
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
217 partitionOn <- :delim {
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
218 pos <- find: delim else: { -1 }
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
219 if: pos >= 0 {
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
220 _before <- from: 0 withLength: pos
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
221 _after <- from: (pos + (delim length))
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
222 #{
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
223 before <- _before
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
224 after <- _after
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
225 }
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
226 } else: {
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
227 _before <- self
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
228 #{
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
229 before <- _before
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
230 after <- ""
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
231 }
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
232 }
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
233 }
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
234
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
235 splitOn <- :delim {
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
236 pos <- 0
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
237 pieces <- #[]
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
238 while: {
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
239 pos <- find: delim else: { -1 }
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
240 pos >= 0
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
241 } do: {
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
242 pieces append: (from: 0 withLength: pos)
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
243 self <- from: pos + (delim length)
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
244 }
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
245 pieces append: self
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
246 }
a6739206a9e3 Add splitOn and partitionOn to string objects
Mike Pavone <pavone@retrodev.com>
parents: 151
diff changeset
247
157
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
248 trim <- {
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
249 l <- length
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
250 start <- 0
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
251 space <- " " byte: 0
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
252 tab <- "\t" byte: 0
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
253 nl <- "\n" byte: 0
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
254 cr <- "\r" byte: 0
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
255
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
256 while: {
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
257 if: start < l {
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
258 b <- byte: start
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
259 b = space || b = tab || b = nl || b = cr
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
260 }
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
261 } do: {
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
262 start <- start + 1
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
263 }
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
264 end <- l
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
265 while: {
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
266 if: end > 0 {
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
267 b <- byte: end
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
268 b = space || b = tab || b = nl || b = cr
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
269 }
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
270 } do: {
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
271 end <- end + 1
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
272 }
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
273 from: start withLength: (end - start)
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
274 }
55e0dca7d3d7 Partial implementation of HTTP get requests
Mike Pavone <pavone@retrodev.com>
parents: 154
diff changeset
275
147
4c96a393103e Add support for receiving data from a socket
Mike Pavone <pavone@retrodev.com>
parents: 88
diff changeset
276 isInteger? <- { false }
154
6e579a75a0a9 Add JSON parser and sample
Mike Pavone <pavone@retrodev.com>
parents: 152
diff changeset
277 isString? <- { true }
88
474f17ebaaa0 Add string.tp which should have been in previous commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
278 }