# HG changeset patch # User Michael Pavone # Date 1439703933 25200 # Node ID 93c28eee141e0f35e3024c6e69b54c1a3f600aa3 # Parent d61b1f0e1936af29aa8d0f76ff47e00990069883# Parent 0673ccbc737954179539b4cc4eb38dde4e15641a Merge diff -r d61b1f0e1936 -r 93c28eee141e modules/array.tp --- a/modules/array.tp Sat Aug 15 22:45:24 2015 -0700 +++ b/modules/array.tp Sat Aug 15 22:45:33 2015 -0700 @@ -54,6 +54,16 @@ size <- size + 1 self } + + llMessage: pop withVars: { + } andCode: { + if: size > 0 { + size <- size - 1 + data get: size + } else: { + false + } + } llMessage: resize withVars: { newsize <- obj_uint32 ptr diff -r d61b1f0e1936 -r 93c28eee141e modules/bytearray.tp --- a/modules/bytearray.tp Sat Aug 15 22:45:24 2015 -0700 +++ b/modules/bytearray.tp Sat Aug 15 22:45:33 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)) + } } diff -r d61b1f0e1936 -r 93c28eee141e modules/json.tp --- a/modules/json.tp Sat Aug 15 22:45:24 2015 -0700 +++ b/modules/json.tp Sat Aug 15 22:45:33 2015 -0700 @@ -18,7 +18,7 @@ t <- "t" byte: 0 f <- "f" byte: 0 - parseNumAt <- :str :at :recvResult { + parseNumAt <- :str at { num <- 0 l <- str length minus <- false @@ -56,12 +56,50 @@ } } - parseStrAt <- :src :at :recvResult { - //TODO: Deal with escaped characters - end <- src find: "\"" startingAt: at + 1 else: { src length } + parseStrAt <- :src at { + //TODO: Deal with unicode escapes + bslash <- "\\" byte: 0 + quote <- "\"" byte: 0 + escapes <- dict hash + escapes set: bslash "\\" + escapes set: quote "\"" + escapes set: ("n" byte: 0) "\n" + escapes set: ("t" byte: 0) "\t" + escapes set: ("r" byte: 0) "\r" + i <- at + 1 + chunks <- #[] + start <- i + continue <- true + while: { continue && i < (src byte_length) } do: { + b <- src byte: i + if: b = bslash { + if: i > start { + chunks append: (src from: start withLength: i-start) + } + if: i + 1 < (src byte_length) { + i <- i + 1 + b <- src byte: i + start <- i + 1 + escapes ifget: b :v { + chunks append: v + } else: { + //not a recognized escape, just copy it raw + chunks append: (src from: i-1 withLength: 2) + } + } + } else: { + if: b = quote { + if: i > start { + chunks append: (src from: start withLength: i-start) + } + continue <- false + } + } + i <- i + 1 + } #{ - value <- src from: (at + 1) withLength: (end - at - 1) - after <- end + 1 + value <- chunks join: "" + after <- i } } @@ -69,10 +107,10 @@ ret <- false b <- text byte: cur if: b = neg || b >= zero && b <= nine { - text parseNumAt: cur + parseNumAt: text cur } else: { if: b = quote { - text parseStrAt: cur + parseStrAt: text cur } else: { if: b = startArr { len <- text length @@ -101,7 +139,7 @@ } else: { if: b = startObj { len <- text length - val <- dict linear + val <- dict hash cur <- cur + 1 aft <- -1 expectKey <- true diff -r d61b1f0e1936 -r 93c28eee141e samples/testarray.tp --- a/samples/testarray.tp Sat Aug 15 22:45:24 2015 -0700 +++ b/samples/testarray.tp Sat Aug 15 22:45:33 2015 -0700 @@ -13,6 +13,8 @@ bar append: 28 bar append: 42 print: "" . ((sum: foo) + (sum: bar)) . "\n" + val <- bar pop + print: "popped off: " . val . ", new length: " . (bar length) . "\n" } }