Skip to content

Commit 4adbf8a

Browse files
committed
Merge pull request #24 from hintjens/master
Fails to catch syntax error "1 { 1 }"
2 parents 726528c + 8d21371 commit 4adbf8a

File tree

10 files changed

+104
-103
lines changed

10 files changed

+104
-103
lines changed

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@
3232

3333
**<a href="#toc3-414">The Shell</a>**
3434

35-
**<a href="#toc3-419">Arguments</a>**
35+
**<a href="#toc3-421">Arguments</a>**
3636

37-
**<a href="#toc3-428">Other Goals</a>**
37+
**<a href="#toc3-430">Other Goals</a>**
3838

39-
**<a href="#toc2-447">Design Notes</a>**
39+
**<a href="#toc2-449">Design Notes</a>**
4040

41-
**<a href="#toc2-455">Bibliography</a>**
41+
**<a href="#toc2-457">Bibliography</a>**
4242

43-
**<a href="#toc2-464">Technicalities</a>**
43+
**<a href="#toc2-466">Technicalities</a>**
4444

45-
**<a href="#toc3-467">Ownership and License</a>**
45+
**<a href="#toc3-469">Ownership and License</a>**
4646

47-
**<a href="#toc3-478">Building and Installing</a>**
47+
**<a href="#toc3-480">Building and Installing</a>**
4848

49-
**<a href="#toc3-511">This Document</a>**
49+
**<a href="#toc3-513">This Document</a>**
5050

5151
Seriously, this is renewing my hope in technology. Thanks @hintjens -- Jason J. Gullickson ‏@jasonbot2000
5252

@@ -455,7 +455,9 @@ We use GSL code generation to build the core language pieces. There are two case
455455

456456
The zs shell provides command history, editing, and tab completion using the Tab key or '?' (as I'm trying to not use special characters in the language, the question mark should remain free for the CLI) (We'll see). We use the editline library for this; it is a clone of the FSF readline function, though much smaller and without extra dependencies. One neat feature is that as you define commands, these become available in the shell.
457457

458-
<A name="toc3-419" title="Arguments" />
458+
To animate the state machines for the lexer and parser, run "zs -v".
459+
460+
<A name="toc3-421" title="Arguments" />
459461
### Arguments
460462

461463
The nice thing about languages is the Internet Comments per Kiloline of Code (IC/KLOC) factor, easily 10-1,000 times higher than for things like protocols, security mechanisms, or library functions. Make a messy API and no-one gives a damn. Ah, but a language! Everyone has an opinion. I kind of like this, the long troll.
@@ -464,7 +466,7 @@ If you want to talk about minor details like my use of < and > for strings, be m
464466

465467
When doing an experiment, "everyone else does it this way, so you should too" is not valid science. Unless, the alternatives are known to be painful, toxic, or deadly. In fact doing stuff no-one expects is kind of exactly the point.
466468

467-
<A name="toc3-428" title="Other Goals" />
469+
<A name="toc3-430" title="Other Goals" />
468470
### Other Goals
469471

470472
Disclaimer: the "vision" thing is way overrated. I only add this section because it's fun.
@@ -483,15 +485,15 @@ Since each box will have an arbitrary set of atomics, bytecode is not portable.
483485

484486
Perhaps the most compelling reason for a new language project is to give the ZeroMQ community an opportunity to work together. We are often fragmented across platforms and operating systems, yet we are solving the same kinds of problems over and over. A shared language would bring together valuable experience. This is the thing which excites me the most, which we managed to almost do using C (as it can be wrapped in anything, so ties together many cultural threads).
485487

486-
<A name="toc2-447" title="Design Notes" />
488+
<A name="toc2-449" title="Design Notes" />
487489
## Design Notes
488490

489491
* Any language aspect that takes more than 10 minutes to understand is too complex.
490492
* Function names are case-sensitive because the real world is case sensitive (1 M vs. 1 m).
491493
* Special characters are annoying and I want to reduce or eliminate the need on them. Some punctuation is OK.
492494
* Real numbers and whole numbers are not the same set in reality. How much is 2 + 2? Anything from 3 to 5, if you are counting real things.
493495

494-
<A name="toc2-455" title="Bibliography" />
496+
<A name="toc2-457" title="Bibliography" />
495497
## Bibliography
496498

497499
* http://www.complang.tuwien.ac.at/forth/threaded-code.html
@@ -500,10 +502,10 @@ Perhaps the most compelling reason for a new language project is to give the Zer
500502
* http://en.wikipedia.org/wiki/Concatenative_programming_language
501503
* https://wiki.haskell.org/Functional_programming
502504

503-
<A name="toc2-464" title="Technicalities" />
505+
<A name="toc2-466" title="Technicalities" />
504506
## Technicalities
505507

506-
<A name="toc3-467" title="Ownership and License" />
508+
<A name="toc3-469" title="Ownership and License" />
507509
### Ownership and License
508510

509511
The contributors are listed in AUTHORS. This project uses the MPL v2 license, see LICENSE.
@@ -514,7 +516,7 @@ ZeroScript uses the [CLASS (C Language Style for Scalabilty)](http://rfc.zeromq.
514516

515517
To report an issue, use the [ZeroScript issue tracker](https://github.com/lepaspace/zs/issues) at github.com.
516518

517-
<A name="toc3-478" title="Building and Installing" />
519+
<A name="toc3-480" title="Building and Installing" />
518520
### Building and Installing
519521

520522
Here's how to build ZeroScript from GitHub:
@@ -547,7 +549,7 @@ You will need the pkg-config, libtool, and autoreconf packages.
547549

548550
Uses: https://github.com/troglobit/editline. Get the tarballs from http://troglobit.com/editline.html.
549551

550-
<A name="toc3-511" title="This Document" />
552+
<A name="toc3-513" title="This Document" />
551553
### This Document
552554

553555
This document is originally at README.txt and is built using [gitdown](http://github.com/imatix/gitdown).

README.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ We use GSL code generation to build the core language pieces. There are two case
403403

404404
The zs shell provides command history, editing, and tab completion using the Tab key or '?' (as I'm trying to not use special characters in the language, the question mark should remain free for the CLI) (We'll see). We use the editline library for this; it is a clone of the FSF readline function, though much smaller and without extra dependencies. One neat feature is that as you define commands, these become available in the shell.
405405

406+
To animate the state machines for the lexer and parser, run "zs -v".
407+
406408
### Arguments
407409

408410
The nice thing about languages is the Internet Comments per Kiloline of Code (IC/KLOC) factor, easily 10-1,000 times higher than for things like protocols, security mechanisms, or library functions. Make a messy API and no-one gives a damn. Ah, but a language! Everyone has an opinion. I kind of like this, the long troll.

doc/zs_pipe.doc

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,127 +10,116 @@ This is the class interface:
1010
// if construction failed due to lack of available memory.
1111
zs_pipe_t *
1212
zs_pipe_new (void);
13-
13+
1414
// Destroy the zs_pipe and free all memory used by the object.
1515
void
1616
zs_pipe_destroy (zs_pipe_t **self_p);
17-
18-
// Sets pipe register to contain a specified whole number; any previous
19-
// value in the register is lost.
20-
void
21-
zs_pipe_set_whole (zs_pipe_t *self, int64_t whole);
22-
23-
// Sets pipe register to contain a specified real number; any previous
24-
// value in the register is lost.
25-
void
26-
zs_pipe_set_real (zs_pipe_t *self, double real);
27-
28-
// Sets pipe register to contain a specified string; any previous value
29-
// in the register is lost.
30-
void
31-
zs_pipe_set_string (zs_pipe_t *self, const char *string);
32-
33-
// Sends current pipe register to the pipe; returns 0 if successful, or
34-
// -1 if the pipe register was empty. Clears the register.
35-
int
36-
zs_pipe_send (zs_pipe_t *self);
37-
17+
3818
// Send whole number to pipe; this wipes the current pipe register.
3919
void
4020
zs_pipe_send_whole (zs_pipe_t *self, int64_t whole);
41-
21+
4222
// Send real number to pipe; this wipes the current pipe register.
4323
void
4424
zs_pipe_send_real (zs_pipe_t *self, double real);
45-
25+
4626
// Send string to pipe; this wipes the current pipe register.
4727
void
4828
zs_pipe_send_string (zs_pipe_t *self, const char *string);
49-
29+
5030
// Returns true if the pipe contains at least one real number. Returns false
5131
// otherwise.
5232
bool
5333
zs_pipe_realish (zs_pipe_t *self);
54-
34+
5535
// Receives the next value off the pipe, into the register. Any previous
5636
// value in the register is lost. Returns true if a value was successfully
5737
// received. If no values were received, returns false. This method does
5838
// not block.
5939
bool
6040
zs_pipe_recv (zs_pipe_t *self);
61-
41+
6242
// Returns the type of the register, 'w' for whole, 'r' for real, or 's' for
6343
// string. Returns -1 if the register is empty.
6444
char
6545
zs_pipe_type (zs_pipe_t *self);
66-
46+
6747
// Returns the value of the register, coerced to a whole number. This can
6848
// cause loss of precision. If no conversion was possible, or the register
6949
// is empty, returns zero.
7050
int64_t
7151
zs_pipe_whole (zs_pipe_t *self);
72-
52+
7353
// Returns the value of the register, coerced to a real number. This can
7454
// cause loss of precision. If no conversion was possible, or the register
7555
// is empty, returns zero.
7656
double
7757
zs_pipe_real (zs_pipe_t *self);
78-
58+
7959
// Returns the value of the register, coerced to a string if needed. If the
8060
// register is empty, returns an empty string "". The caller must not modify
8161
// or free the string.
82-
char *
62+
const char *
8363
zs_pipe_string (zs_pipe_t *self);
84-
64+
8565
// Receives the next value off the pipe, into the register, and coerces it
8666
// to a whole if needed. If there is no value to receive, returns 0.
8767
int64_t
8868
zs_pipe_recv_whole (zs_pipe_t *self);
89-
69+
9070
// Receives the next value off the pipe, into the register, and coerces it
9171
// to a real if needed. If there is no value to receive, returns 0.
9272
double
9373
zs_pipe_recv_real (zs_pipe_t *self);
94-
74+
9575
// Receives the next value off the pipe, into the register, and coerces it
9676
// to a string if needed. If there is no value to receive, returns "". The
9777
// The caller must not modify or free the string.
98-
char *
78+
const char *
9979
zs_pipe_recv_string (zs_pipe_t *self);
100-
80+
10181
// Marks an end of phrase in the pipe. This is used to delimit the pipe
10282
// as input for later function calls. Marks are ignored when receiving
10383
// values off a pipe.
10484
void
10585
zs_pipe_mark (zs_pipe_t *self);
106-
86+
87+
// Pulls a single value from the source pipe into the pipe. If there was
88+
// no value to pull, sends a constant '1' value to the pipe.
89+
void
90+
zs_pipe_pull_single (zs_pipe_t *self, zs_pipe_t *source);
91+
10792
// Pulls a list of values from the source pipe into the pipe. This function
10893
// does a "modest" pull: in a phrase, pulls the last single value. After a
10994
// phrase, pulls the preceding phrase.
11095
void
11196
zs_pipe_pull_modest (zs_pipe_t *self, zs_pipe_t *source);
112-
97+
11398
// Pulls a list of values from the source pipe into the pipe. This function
11499
// does a "greedy" pull: in a phrase, pulls the current phrase. After a
115100
// phrase, pulls the preceding entire sentence.
116101
void
117102
zs_pipe_pull_greedy (zs_pipe_t *self, zs_pipe_t *source);
118-
103+
119104
// Pulls a list of values from the source pipe into the pipe. This function
120105
// does an array pull: (a) move last value to input, then (b) move either rest
121106
// of current phrase, or entire previous phrase, to input.
122107
void
123108
zs_pipe_pull_array (zs_pipe_t *self, zs_pipe_t *source);
124-
109+
125110
// Return pipe contents, as string. Caller must free it when done. Values are
126111
// separated by spaces. This empties the pipe.
127112
char *
128113
zs_pipe_paste (zs_pipe_t *self);
129-
114+
115+
// Print pipe contents, for debugging, prints nothing if pipe is empty
116+
void
117+
zs_pipe_print (zs_pipe_t *self, const char *prefix);
118+
130119
// Empty the pipe of any values it might contain.
131120
void
132121
zs_pipe_purge (zs_pipe_t *self);
133-
122+
134123
// Self test of this class
135124
void
136125
zs_pipe_test (bool animate);
@@ -139,10 +128,10 @@ This is the class self test code:
139128

140129
zs_pipe_t *pipe = zs_pipe_new ();
141130
zs_pipe_t *copy = zs_pipe_new ();
142-
131+
143132
zs_pipe_send_whole (pipe, 12345);
144133
zs_pipe_send_string (pipe, "Hello World");
145-
134+
146135
bool rc = zs_pipe_recv (pipe);
147136
assert (rc);
148137
int64_t whole = zs_pipe_whole (pipe);
@@ -152,10 +141,11 @@ This is the class self test code:
152141
const char *string = zs_pipe_string (pipe);
153142
assert (streq (string, "Hello World"));
154143
assert (!zs_pipe_recv (pipe));
155-
144+
156145
char *results = zs_pipe_paste (pipe);
157146
assert (streq (results, ""));
158-
147+
zstr_free (&results);
148+
159149
zs_pipe_send_whole (pipe, 4);
160150
zs_pipe_send_whole (pipe, 5);
161151
zs_pipe_send_whole (pipe, 6);
@@ -164,7 +154,7 @@ This is the class self test code:
164154
zs_pipe_purge (pipe);
165155
whole = zs_pipe_recv_whole (pipe);
166156
assert (whole == 0);
167-
157+
168158
// Test phrases
169159
zs_pipe_mark (pipe);
170160
zs_pipe_send_whole (pipe, 1);
@@ -180,13 +170,13 @@ This is the class self test code:
180170
zs_pipe_send_whole (pipe, 9);
181171
zs_pipe_mark (pipe);
182172
zs_pipe_send_whole (pipe, 10);
183-
173+
184174
// Modest pull should take single last value
185175
zs_pipe_pull_modest (copy, pipe);
186176
whole = zs_pipe_recv_whole (copy);
187177
assert (whole == 10);
188178
assert (!zs_pipe_recv (copy));
189-
179+
190180
// Modest pull should take last phrase
191181
zs_pipe_pull_modest (copy, pipe);
192182
whole = zs_pipe_recv_whole (copy);
@@ -196,20 +186,20 @@ This is the class self test code:
196186
whole = zs_pipe_recv_whole (copy);
197187
assert (whole == 9);
198188
assert (!zs_pipe_recv (copy));
199-
189+
200190
// Add some more to the pipe...
201191
zs_pipe_mark (pipe);
202192
zs_pipe_send_whole (pipe, 7);
203193
zs_pipe_send_whole (pipe, 8);
204-
194+
205195
// Greedy pull should take just those two values now
206196
zs_pipe_pull_greedy (copy, pipe);
207197
whole = zs_pipe_recv_whole (copy);
208198
assert (whole == 7);
209199
whole = zs_pipe_recv_whole (copy);
210200
assert (whole == 8);
211201
assert (!zs_pipe_recv (copy));
212-
202+
213203
// Greedy pull should take all six remaining values
214204
zs_pipe_pull_greedy (copy, pipe);
215205
whole = zs_pipe_recv_whole (copy);
@@ -225,10 +215,10 @@ This is the class self test code:
225215
whole = zs_pipe_recv_whole (copy);
226216
assert (whole == 6);
227217
assert (!zs_pipe_recv (copy));
228-
218+
229219
// Check pipe is empty
230220
assert (!zs_pipe_recv (copy));
231-
221+
232222
// Test array pull
233223
zs_pipe_send_whole (pipe, 1);
234224
zs_pipe_send_whole (pipe, 2);
@@ -239,7 +229,7 @@ This is the class self test code:
239229
zs_pipe_send_whole (pipe, 6);
240230
zs_pipe_mark (pipe);
241231
zs_pipe_send_whole (pipe, 7);
242-
232+
243233
zs_pipe_pull_array (copy, pipe);
244234
whole = zs_pipe_recv_whole (copy);
245235
assert (whole == 7);
@@ -250,7 +240,7 @@ This is the class self test code:
250240
whole = zs_pipe_recv_whole (copy);
251241
assert (whole == 6);
252242
assert (!zs_pipe_recv (copy));
253-
243+
254244
// Test casting
255245
zs_pipe_purge (pipe);
256246
zs_pipe_send_whole (pipe, 1);
@@ -264,7 +254,7 @@ This is the class self test code:
264254
assert (!zs_pipe_realish (pipe));
265255
real = zs_pipe_recv_real (pipe);
266256
assert (real == 3.0);
267-
257+
268258
zs_pipe_destroy (&copy);
269259
zs_pipe_destroy (&pipe);
270260

0 commit comments

Comments
 (0)