Mercurial > repos > icfp2013
annotate src/requests.tp @ 24:e1109e33b796
some work that probably needs to be trashed on requests.tp
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 10 Aug 2013 11:53:21 -0700 |
parents | fcd7ae66a9ee |
children | bb80f86c5048 |
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 { |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
17 "\"" . str . "\"" |
18 | 18 } |
19 | |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
20 println <- :str { |
23 | 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: { |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
53 print: "parse error: expected " . target . "!\n" |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
54 doElse: |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
55 } |
22
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 |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
60 secondQuote <- firstKeyQuote + 1 + (key length) |
23 | 61 |
62 #{ | |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
63 value <- "" |
23 | 64 rest <- src from: (value length) |
65 } | |
66 } | |
67 | |
68 getOutputs:else <- :str :fail { | |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
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 |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
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 <- #{ |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
78 status <- statusRest value |
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
79 outputs <- outputsRest value |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
80 } |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
81 rest <- outputsRest rest |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
82 } |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
83 } else: { |
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
84 message <- "" |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
85 print: "Status was error, message: " . message |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
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 #{ |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
88 value <- #{ |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
89 status <- statusRest value |
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
90 message <- messageRest value |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
91 } |
24
e1109e33b796
some work that probably needs to be trashed on requests.tp
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
92 rest <- messageRest rest |
22
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 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
98 |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
99 main <- { |
20 | 100 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
|
101 print: ((guessRequest: "someId" "someProg") string) . "\n" |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
102 |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
103 exampleEvalResponse <- "{\"status\":\"ok\",\"outputs\":[\"0x0000000000000002\",\"0x01DFFFFFFFFFFFFE\"]}" |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
104 resp <- getEval: exampleEvalResponse else: { |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
105 println: "failed to parse response." |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
106 } |
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
107 println: ((resp value) status) |
12
7d8b8f82cbef
Help Bill work around some compiler bugs
Mike Pavone <pavone@retrodev.com>
parents:
10
diff
changeset
|
108 } |
22
a4837071b73d
some attempts at parsing an eval response
William Morgan <bill@mrgn.org>
parents:
21
diff
changeset
|
109 |
10
79c1db5e7ebd
sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff
changeset
|
110 } |