Mercurial > repos > icfp2013
annotate src/requests.tp @ 23:fcd7ae66a9ee
cleanup.
author | William Morgan <bill@mrgn.org> |
---|---|
date | Sat, 10 Aug 2013 03:56:32 -0700 |
parents | a4837071b73d |
children | e1109e33b796 |
rev | line source |
---|---|
10
79c1db5e7ebd
sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff
changeset
|
1 #{ |
18 | 2 |
20 | 3 strJoin <- :str arr { |
4 acc <- "" | |
5 arr foreach: :i el { | |
6 if: i = 0 { | |
7 acc <- (string: el) | |
8 } else: { | |
9 acc <- acc . ", " . (string: el) | |
10 } | |
11 } | |
12 acc | |
13 //arr fold: "" with: :acc el {acc . el} | |
14 } | |
15 | |
18 | 16 quote <- :str { |
17 "\"" . str . "\"" | |
18 } | |
19 | |
23 | 20 println: str { |
21 print: str . "\n" | |
22 } | |
23 | |
24 | |
25 | |
26 | |
19
5a025e6c6f89
simple parallel requests limit test
William Morgan <bill@mrgn.org>
parents:
18
diff
changeset
|
27 evalRequest <- :id args { |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
28 #{ |
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
29 string <- { |
20 | 30 idStr <- (quote: "id") . ":" . (quote: id) |
31 argsStr <- (quote: "arguments") . ":" . (quote: (strJoin: "," args)) | |
18 | 32 "{" . idStr . "," . argsStr . "}" |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
33 } |
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
34 } |
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
35 } |
10
79c1db5e7ebd
sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff
changeset
|
36 |
15
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
37 guessRequest <- :id :prog { |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
38 #{ |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
39 string <- { |
17
566960135ea1
Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
40 idStr <- "\"id\":\"" . id . "\"" |
566960135ea1
Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
41 progStr <- "\"program\":\"" . prog . "\"" |
566960135ea1
Small bit of cleanup now that the string escaping bug is fixed.
Mike Pavone <pavone@retrodev.com>
parents:
16
diff
changeset
|
42 "{" . idStr . "," . progStr . "}" |
15
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
43 } |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
44 } |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
45 } |
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
46 |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
47 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
48 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
49 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
50 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
51 expect:in:else <- :target src doElse { |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
52 src find: target else: { |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
53 print: "parse error: expected " . target . "!\n" |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
54 doElse: |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
55 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
56 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
57 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
58 getStrForKey:from:else <- :key :src :doElse { |
23 | 59 firstKeyQuote <- expect: "\"" in: src else: doElse |
60 secondQuote <- idx + (key length): | |
61 | |
62 #{ | |
63 value <- | |
64 rest <- src from: (value length) | |
65 } | |
66 } | |
67 | |
68 getOutputs:else <- :str :fail { | |
69 | |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
70 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
71 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
72 getEval:else <- :str :fail { |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
73 statusRest <- getStrForKey: "status" from: str else: fail |
23 | 74 if (statusRest value) = "ok" { // string equality? revisit. |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
75 outputsRest <- getOutputs: (statusRest rest) else: fail |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
76 #{ |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
77 value <- #{ |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
78 status <- statusRest.value |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
79 outputs <- outputsRest.value |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
80 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
81 rest <- outputsRest.rest |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
82 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
83 } else { |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
84 print: "Status was error, message: " . message |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
85 #{ |
23 | 86 messageRest <- getStrForKey: "message" from: (statusRest rest) else: fail |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
87 value <- #{ |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
88 status <- statusRest.value |
23 | 89 message <- messageRest.value |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
90 } |
23 | 91 rest <- messageRest.rest |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
92 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
93 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
94 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
95 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
96 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
97 |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
98 main <- { |
20 | 99 print: ((evalRequest: "someId" #[1 2i64 3i64]) string) . "\n" |
15
18ec9131f594
one more compiler bug for mike.
William Morgan <bill@mrgn.org>
parents:
14
diff
changeset
|
100 print: ((guessRequest: "someId" "someProg") string) . "\n" |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
101 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
102 exampleEvalResponse <- "{\"status\":\"ok\",\"outputs\":[\"0x0000000000000002\",\"0x01DFFFFFFFFFFFFE\"]}" |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
103 resp <- getEval: exampleEvalResponse else: { |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
104 println: "failed to parse response." |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
105 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
106 println: ((resp value) status) |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
107 } |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
108 |
10
79c1db5e7ebd
sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff
changeset
|
109 } |