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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
79c1db5e7ebd sending broken file for mike to check error
William Morgan <bill@mrgn.org>
parents:
diff changeset
1 #{
18
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
2
20
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
3 strJoin <- :str arr {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
4 acc <- ""
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
5 arr foreach: :i el {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
6 if: i = 0 {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
7 acc <- (string: el)
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
8 } else: {
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
9 acc <- acc . ", " . (string: el)
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
10 }
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
11 }
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
12 acc
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
13 //arr fold: "" with: :acc el {acc . el}
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
14 }
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
15
18
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
18 }
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
21 print: str . "\n"
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
22 }
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
23
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
24
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
25
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
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
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
30 idStr <- (quote: "id") . ":" . (quote: id)
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
31 argsStr <- (quote: "arguments") . ":" . (quote: (strJoin: "," args))
18
a0e66161bde0 for bug investigation
William Morgan <bill@mrgn.org>
parents: 17
diff changeset
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
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
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
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
61
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
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
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
64 rest <- src from: (value length)
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
65 }
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
66 }
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
67
fcd7ae66a9ee cleanup.
William Morgan <bill@mrgn.org>
parents: 22
diff changeset
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
92db3d1e8809 strJoin finally works.
William Morgan <bill@mrgn.org>
parents: 19
diff changeset
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 }