[Nickle] nickle: Branch 'master' - 5 commits
Keith Packard
keithp at keithp.com
Sun Nov 25 21:52:22 PST 2007
command.5c | 44 ++++++++++++++++++++++----------------------
examples/apsp.5c | 2 +-
examples/circle.5c | 2 +-
examples/fourfours.5c | 24 ++++++++++++------------
examples/menace2.5c | 6 +++---
examples/miller-rabin.5c | 4 ++--
examples/mutextest.5c | 4 ++--
examples/numbers.5c | 2 +-
examples/polynomial.5c | 4 ++--
examples/prime.5c | 4 ++--
examples/randtest.5c | 2 +-
examples/rijndael.5c | 8 ++++----
examples/roman.5c | 6 +++---
examples/shortpaths.5c | 2 +-
examples/skiplist.5c | 14 +++++++-------
examples/skiplisttest.5c | 2 +-
examples/smlng/context.5c | 2 +-
examples/smlng/parse.5c | 30 +++++++++++++++---------------
mutex.5c | 4 ++--
printf.5c | 24 ++++++++++++------------
string.5c | 4 ++--
test/optest.5c | 4 ++--
22 files changed, 99 insertions(+), 99 deletions(-)
New commits:
commit 94a41e46b6381304a5b1c67675afd9c5f3f8574c
Author: Keith Packard <keithp at keithp.com>
Date: Sun Nov 25 21:51:23 2007 -0800
Examples - use '.' in struct initializers.
Add '.' before struct tag in initializers now that it is permitted.
diff --git a/examples/apsp.5c b/examples/apsp.5c
index 6547176..61a1455 100644
--- a/examples/apsp.5c
+++ b/examples/apsp.5c
@@ -22,7 +22,7 @@ namespace APSP {
int n = ns[0];
/* set things up */
shortest_path[n,n] path =
- {{{dist = -1, first_hop = -1}, ...},...};
+ {{{.dist = -1, .first_hop = -1}, ...},...};
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j && adjacencies[i,j] >= 0) {
diff --git a/examples/circle.5c b/examples/circle.5c
index c54cb2e..ae8cd50 100644
--- a/examples/circle.5c
+++ b/examples/circle.5c
@@ -29,5 +29,5 @@ course function great_circle (loc start, loc end) {
real rdist = earth_radius * r;
real sinth = sin(phi) * sin(b) / sin(r);
real th = asin(sinth) / rad;
- return (course){dist = rdist, bearing = th};
+ return (course){ .dist = rdist, .bearing = th };
}
diff --git a/examples/fourfours.5c b/examples/fourfours.5c
index e9233ab..e6f0da9 100644
--- a/examples/fourfours.5c
+++ b/examples/fourfours.5c
@@ -14,12 +14,12 @@ typedef struct {
poly() argloop() {
int i = 0;
static poly[] a = {
- (v_t) { s = "4", v = 4, p = 25 },
- (v_t) { s = ".4", v = .4, p = 5 },
- (v_t) { s = ".{4}", v =.{4}, p = 1 },
- (v_t) { s = "4!", v = 4!, p = 25 },
- (v_t) { s = "â4", v = sqrt(4), p = 25 },
- (v_t) { s = "â.{4}", v = sqrt(.{4}), p = 1 },
+ (v_t) { .s = "4", .v = 4, .p = 25 },
+ (v_t) { .s = ".4", .v = .4, .p = 5 },
+ (v_t) { .s = ".{4}", .v =.{4}, .p = 1 },
+ (v_t) { .s = "4!", .v = 4!, .p = 25 },
+ (v_t) { .s = "â4", .v = sqrt(4), .p = 25 },
+ (v_t) { .s = "â.{4}", .v = sqrt(.{4}), .p = 1 },
â
};
return poly func() = a[i++ % dim(a)];
@@ -30,14 +30,14 @@ poly () binloop(poly() l, poly() r) {
int i = 0;
poly la = â, ra = â;
static (poly(poly, poly))[] a = {
- poly func(x,y) = (v_t) { s = "(" + x.s + " + " + y.s + ")", v=x.v + y.v, p = x.p + y.p },
- poly func(x,y) = (v_t) { s = "(" + x.s + " - " + y.s + ")", v=x.v - y.v, p = x.p + y.p },
- poly func(x,y) = (v_t) { s = "(" + x.s + " * " + y.s + ")", v=x.v * y.v, p = x.p + y.p },
- poly func(x,y) = (v_t) { s = "(" + x.s + " / " + y.s + ")", v=x.v / y.v, p = x.p + y.p },
+ poly func(x,y) = (v_t) { .s = "(" + x.s + " + " + y.s + ")", .v = x.v + y.v, .p = x.p + y.p },
+ poly func(x,y) = (v_t) { .s = "(" + x.s + " - " + y.s + ")", .v = x.v - y.v, .p = x.p + y.p },
+ poly func(x,y) = (v_t) { .s = "(" + x.s + " * " + y.s + ")", .v = x.v * y.v, .p = x.p + y.p },
+ poly func(x,y) = (v_t) { .s = "(" + x.s + " / " + y.s + ")", .v = x.v / y.v, .p = x.p + y.p },
poly func(x,y) {
if (y.v > 4)
raise invalid_argument ("rhs of ** too large", 1, y.v);
- return (v_t) { s = "(" + x.s + " ^ " + y.s + ")", v=x.v ** y.v, p = x.p + y.p };
+ return (v_t) { .s = "(" + x.s + " ^ " + y.s + ")", .v =x.v ** y.v, .p = x.p + y.p };
}
};
return poly func() {
@@ -78,7 +78,7 @@ poly() parenloop(poly() x, poly() y, poly() z) {
/* find equations which compute all values */
void main () {
int limit = 100;
- v_t[limit + 1] values = { { s = "no solution", v = 0, p=0 } ... };
+ v_t[limit + 1] values = { { .s = "no solution", .v = 0, .p = 0 } ... };
poly() f = parenloop (binloop(argloop(), argloop()),
argloop(), argloop());
while (((poly value) = f()) != â) {
diff --git a/examples/menace2.5c b/examples/menace2.5c
index 006f155..7ac45ae 100755
--- a/examples/menace2.5c
+++ b/examples/menace2.5c
@@ -108,9 +108,9 @@ ttentref ttable_lookup(position pos) {
/* nope: create a new entry */
nttstates++;
ttent t = {
- on_move = side_on_move(&pos),
- posns = all_posns(pos),
- next = ttable
+ .on_move = side_on_move(&pos),
+ .posns = all_posns(pos),
+ .next = ttable
};
/* count legal moves */
int nmoves = 0;
diff --git a/examples/miller-rabin.5c b/examples/miller-rabin.5c
index cfd2ac1..01477a3 100644
--- a/examples/miller-rabin.5c
+++ b/examples/miller-rabin.5c
@@ -34,9 +34,9 @@ namespace MillerRabin {
witness_result function witnessexp(int b, int e, int m) {
switch (e) {
case 0:
- return (witness_result){pow = 0, wit = 1};
+ return (witness_result){ .pow = 0, .wit = 1};
case 1:
- return (witness_result){pow = b % m, wit = 0};
+ return (witness_result){ .pow = b % m, .wit = 0};
}
witness_result tmp = witnessexp(b, e // 2, m);
if (tmp.wit != 0)
diff --git a/examples/mutextest.5c b/examples/mutextest.5c
index 73faa1d..da3ecba 100644
--- a/examples/mutextest.5c
+++ b/examples/mutextest.5c
@@ -76,8 +76,8 @@ void start (int nthread, int nmut_ex, int delay)
for (i = 0; i < nmut_ex; i++)
{
mutexes[i] = (named_mutex) {
- mut_ex = new (),
- name = String::new('A' + i)
+ .mut_ex = new (),
+ .name = String::new('A' + i)
};
}
for (i = 0; i < nthread; i++)
diff --git a/examples/numbers.5c b/examples/numbers.5c
index 972146d..42cfe6f 100644
--- a/examples/numbers.5c
+++ b/examples/numbers.5c
@@ -32,7 +32,7 @@ namespace Numbers {
/* Extended Euclid's Algorithm */
public coeff function extgcd(int a, int b) {
if (b == 0)
- return (coeff) {d = a, x = 1, y = 0};
+ return (coeff) { .d = a, .x = 1, .y = 0};
coeff t = extgcd(b, a % b);
int x = t.x;
t.x = t.y;
diff --git a/examples/polynomial.5c b/examples/polynomial.5c
index 2e91fa6..1d9a61b 100644
--- a/examples/polynomial.5c
+++ b/examples/polynomial.5c
@@ -104,7 +104,7 @@ namespace Polynomial {
abort("leading integer coefficient in divisor should be 1");
coefficient nq = na - nb + 1;
if (nq <= 0)
- return (quot_rem) { quot = (polynomial){0}, rem = b };
+ return (quot_rem) { .quot = (polynomial){0}, .rem = b };
coefficient[nq] q = {0 ...};
while (na >= nb) {
@@ -119,7 +119,7 @@ namespace Polynomial {
while (na >= 1 && a[na - 1] == 0)
--na;
}
- return (quot_rem) { quot = q, rem = normalize(a) };
+ return (quot_rem) { .quot = q, .rem = normalize(a) };
}
diff --git a/examples/prime.5c b/examples/prime.5c
index 7068a03..b4ca209 100644
--- a/examples/prime.5c
+++ b/examples/prime.5c
@@ -50,12 +50,12 @@ namespace Factor {
}
if (i < 3)
- return (int_list.ref) reference ((int_list_struct) { next = int_list.end, v = 2 });
+ return (int_list.ref) reference ((int_list_struct) { .next = int_list.end, .v = 2 });
int_list l = primes (i-1);
if (prime_wrt (l, i))
- return (int_list.ref) reference ((int_list_struct) { next = l, v = i });
+ return (int_list.ref) reference ((int_list_struct) { .next = l, .v = i });
return l;
}
diff --git a/examples/rijndael.5c b/examples/rijndael.5c
index 7a9b951..09526d9 100644
--- a/examples/rijndael.5c
+++ b/examples/rijndael.5c
@@ -924,10 +924,10 @@ void function main ()
/*
* Create an encryption key and encryption instance
*/
- keyInstance encKeyInst = (keyInstance) { blockLen = 128 };
+ keyInstance encKeyInst = (keyInstance) { .blockLen = 128 };
makeKey (&encKeyInst, DIR_ENCRYPT, 128, secret);
- cipherInstance encCipherInst = (cipherInstance) { blockLen = 128 };
+ cipherInstance encCipherInst = (cipherInstance) { .blockLen = 128 };
cipherInit (&encCipherInst, MODE_ECB, "");
/*
@@ -942,10 +942,10 @@ void function main ()
/*
* Create a decryption key and decryption instance
*/
- keyInstance decKeyInst = (keyInstance) { blockLen = 128 };
+ keyInstance decKeyInst = (keyInstance) { .blockLen = 128 };
makeKey (&decKeyInst, DIR_DECRYPT, 128, secret);
- cipherInstance decCipherInst = (cipherInstance) { blockLen = 128 };
+ cipherInstance decCipherInst = (cipherInstance) { .blockLen = 128 };
cipherInit (&decCipherInst, MODE_ECB, "");
/*
diff --git a/examples/roman.5c b/examples/roman.5c
index 9c9da5b..5a15197 100644
--- a/examples/roman.5c
+++ b/examples/roman.5c
@@ -21,9 +21,9 @@ string function roman (int i)
} digit;
digit[*] digits = {
- (digit) { ones = "C", five = "D", tens = "M", base = 100 },
- (digit) { ones = "X", five = "L", tens = "C", base = 10 },
- (digit) { ones = "I", five = "V", tens = "X", base = 1 }
+ (digit) { .ones = "C", .five = "D", .tens = "M", .base = 100 },
+ (digit) { .ones = "X", .five = "L", .tens = "C", .base = 10 },
+ (digit) { .ones = "I", .five = "V", .tens = "X", .base = 1 }
};
string function place (int i, digit dig)
diff --git a/examples/shortpaths.5c b/examples/shortpaths.5c
index 14512ec..9c42a35 100644
--- a/examples/shortpaths.5c
+++ b/examples/shortpaths.5c
@@ -21,7 +21,7 @@ int blot = 10;
SVG::start(stdout, side, side);
-point[10] locns = { [i] = (point){x = randint(side), y = randint(side)} };
+point[10] locns = { [i] = (point){ .x = randint(side), .y = randint(side)} };
for (int i = 0; i < dim(locns); i++)
SVG::spot(stdout, "red", locns[i].x, locns[i].y, blot);
diff --git a/examples/skiplist.5c b/examples/skiplist.5c
index b71afe5..f081d48 100644
--- a/examples/skiplist.5c
+++ b/examples/skiplist.5c
@@ -66,11 +66,11 @@ namespace Skiplist {
*/
{
return &(SkipRec) {
- level = 0,
- greater = greater,
- header = {
- forward = (ElementPtr[MaxLevel]) { [i] = ElementPtr.nil },
- value = <>
+ .level = 0,
+ .greater = greater,
+ .header = {
+ .forward = (ElementPtr[MaxLevel]) { [i] = ElementPtr.nil },
+ .value = <>
}
};
}
@@ -125,8 +125,8 @@ namespace Skiplist {
* Allocate new list entry
*/
ElementPtr new = (ElementPtr.element) &(Element) {
- value = value,
- forward = (ElementPtr[level]) {}
+ .value = value,
+ .forward = (ElementPtr[level]) {}
};
for (int i = 0; i < level; i++)
diff --git a/examples/smlng/context.5c b/examples/smlng/context.5c
index f0c8cec..1517d05 100644
--- a/examples/smlng/context.5c
+++ b/examples/smlng/context.5c
@@ -22,7 +22,7 @@ typedef struct {
*context no_context = reference ((context) {});
context root_context = (context) {
- styles=0, underline=0, color=-1, size=-1
+ .styles=0, .underline=0, .color=-1, .size=-1
};
public exception UnknownColor (int name);
diff --git a/examples/smlng/parse.5c b/examples/smlng/parse.5c
index e29d42b..584e981 100644
--- a/examples/smlng/parse.5c
+++ b/examples/smlng/parse.5c
@@ -94,15 +94,15 @@ public namespace Lex {
case StateStart:
switch (c.id) {
case Lexc::Eof:
- return (token) { id = Eof, value = "" };
+ return (token) { .id = Eof, .value = "" };
case Lexc::Printable:
case Lexc::Slash:
state = StateString;
- t = (token) { id = Text, value = String::new (c.c) };
+ t = (token) { .id = Text, .value = String::new (c.c) };
continue;
case Lexc::White:
state = StateSpace;
- t = (token) { id = Space, value = String::new (c.c) };
+ t = (token) { .id = Space, .value = String::new (c.c) };
continue;
case Lexc::Left:
state = StateSeenLeft;
@@ -113,11 +113,11 @@ public namespace Lex {
switch (c.id) {
case Lexc::Printable:
state = StateStartTag;
- t = (token) { id = Start, value = String::new (c.c) };
+ t = (token) { .id = Start, .value = String::new (c.c) };
continue;
case Lexc::Slash:
state = StateEndTag;
- t = (token) { id = End, value = "" };
+ t = (token) { .id = End, .value = "" };
continue;
}
break;
@@ -197,7 +197,7 @@ public namespace Parse {
{
*element first = element_end;
* *element p = &first;
- *c_list c = reference ( (c_list) { ctxt=&root_context, prev=c_list_end});
+ *c_list c = reference ( (c_list) { .ctxt=&root_context, .prev=c_list_end});
for (;;)
{
@@ -211,23 +211,23 @@ public namespace Parse {
return first;
case Lex::Text:
*p = reference ((element) {
- next = element_end,
- data = t.value,
- ctxt = c->ctxt });
+ .next = element_end,
+ .data = t.value,
+ .ctxt = c->ctxt });
p = &(*p)->next;
break;
case Lex::Space:
*p = reference ((element) {
- next = element_end,
- data = t.value,
- ctxt = c->ctxt });
+ .next = element_end,
+ .data = t.value,
+ .ctxt = c->ctxt });
p = &(*p)->next;
break;
case Lex::Start:
c = reference ((c_list) {
- ctxt = reference (*c->ctxt),
- prev = c,
- active_tag = t.value });
+ .ctxt = reference (*c->ctxt),
+ .prev = c,
+ .active_tag = t.value });
context_set (c->ctxt, t.value);
break;
case Lex::End:
commit 3cf7567bbfa16e93c32a5a2477b28e2a91b37ae1
Author: Keith Packard <keithp at keithp.com>
Date: Sun Nov 25 21:50:59 2007 -0800
Skiplist test code had a typo.
"hi" is not a legal initializer for an integer variable.
diff --git a/examples/skiplisttest.5c b/examples/skiplisttest.5c
index 9037d86..baf0236 100644
--- a/examples/skiplisttest.5c
+++ b/examples/skiplisttest.5c
@@ -10,7 +10,7 @@
autoload Skiplist;
autoload PRNG;
-int gt_count = "hi";
+int gt_count = 0;
bool int_gt (int a, int b) {
++gt_count;
commit 9be14d5dcb8e55d22066845a0278a0c22374b0c9
Author: Keith Packard <keithp at keithp.com>
Date: Sun Nov 25 21:49:41 2007 -0800
'randtest' example used now-missing 'vprintf' function.
vprintf was replaced by the general '...' mechanism for passing
an array as a list of arguments. Somehow, this example was never updated.
diff --git a/examples/randtest.5c b/examples/randtest.5c
index adebee4..5b68c9f 100644
--- a/examples/randtest.5c
+++ b/examples/randtest.5c
@@ -18,4 +18,4 @@ int[*] function t(int n) {
return s;
}
-File::vprintf ("%d %d\n", t (string_to_integer (argv[1])));
+File::printf ("%d %d\n", t (string_to_integer (argv[1]))...);
commit f8f1d223a46cffff9fcc89fa7524fdf57cbacf7c
Author: Keith Packard <keithp at keithp.com>
Date: Sun Nov 25 21:48:22 2007 -0800
Tests - use '.' in struct initializers.
Add '.' before struct tag in initializers now that it is permitted.
diff --git a/test/optest.5c b/test/optest.5c
index 18dbb76..1b88d7e 100644
--- a/test/optest.5c
+++ b/test/optest.5c
@@ -49,9 +49,9 @@ check (*z, 4);
union {int a; string b;} test;
check (sprintf ("%v", test), "{<unset>}")
check (test.a = 1, 1);
-check (test, (union {int a;}) {a = 1});
+check (test, (union {int a;}) { .a = 1});
check (test.b = "hello", "hello");
-check (test, (union {string b;}) { b = "hello" });
+check (test, (union {string b;}) { .b = "hello" });
check (bool func () { try {
test.a;
return false;
commit 81beb0e9394e715e7354cebeb58c261a2e9b2019
Author: Keith Packard <keithp at keithp.com>
Date: Sun Nov 25 21:47:11 2007 -0800
Builtins -- add newly permitted '.' before tag in struct initializers.
Now that struct initializers permit '.', use them for the builtin nickle
code.
diff --git a/command.5c b/command.5c
index e3778f8..c4f69c1 100644
--- a/command.5c
+++ b/command.5c
@@ -274,30 +274,30 @@ extend namespace Command {
}
ParseArgs::argdesc argd = {
- args = {
- {var = {arg_lambda = save_library},
- abbr = 'l',
- name = "library",
- expr_name = "lib",
- desc = "Library to load."},
- {var = {arg_lambda = save_file},
- abbr = 'f',
- name = "file",
- expr_name = "source",
- desc = "Source file to load."},
- {var = {arg_lambda = save_expr},
- abbr = 'e',
- name = "expr",
- expr_name = "expression",
- desc = "Expression to evaluate."}
+ .args = {
+ { .var = { .arg_lambda = save_library},
+ .abbr = 'l',
+ .name = "library",
+ .expr_name = "lib",
+ .desc = "Library to load."},
+ { .var = { .arg_lambda = save_file},
+ .abbr = 'f',
+ .name = "file",
+ .expr_name = "source",
+ .desc = "Source file to load."},
+ { .var = { .arg_lambda = save_expr},
+ .abbr = 'e',
+ .name = "expr",
+ .expr_name = "expression",
+ .desc = "Expression to evaluate."}
},
- posn_args = {
- {var = {arg_lambda = save_script},
- name = "script",
- optional = <>}
+ .posn_args = {
+ { .var = { .arg_lambda = save_script},
+ .name = "script",
+ .optional = <>}
},
- unknown = &(int user_argind),
- prog_name = "nickle"
+ .unknown = &(int user_argind),
+ .prog_name = "nickle"
};
/* actually parse the arguments */
diff --git a/mutex.5c b/mutex.5c
index 2882a88..865354b 100644
--- a/mutex.5c
+++ b/mutex.5c
@@ -91,8 +91,8 @@ namespace Mutex {
*/
{
return reference ((mutex_struct) {
- sem = Semaphore::new (1),
- owner = mutex_owner.nobody
+ .sem = Semaphore::new (1),
+ .owner = mutex_owner.nobody
});
}
}
diff --git a/printf.5c b/printf.5c
index 480521b..69d13eb 100644
--- a/printf.5c
+++ b/printf.5c
@@ -161,18 +161,18 @@ extend namespace File {
string message;
int base;
}[*] fmts = {
- { formats = "s", test = is_string,
- message = "string", base = 10 },
- { formats = "dD", test = is_int,
- message = "int", base = 10 },
- { formats = "bB", test = is_int,
- message = "int", base = 2 },
- { formats = "oO", test = is_int,
- message = "int", base = 8 },
- { formats = "xX", test = is_int,
- message = "int", base = 16 },
- { formats = "efEF", test = is_number,
- message = "real", base = 10 }
+ { .formats = "s", .test = is_string,
+ .message = "string", .base = 10 },
+ { .formats = "dD", .test = is_int,
+ .message = "int", .base = 10 },
+ { .formats = "bB", .test = is_int,
+ .message = "int", .base = 2 },
+ { .formats = "oO", .test = is_int,
+ .message = "int", .base = 8 },
+ { .formats = "xX", .test = is_int,
+ .message = "int", .base = 16 },
+ { .formats = "efEF", .test = is_number,
+ .message = "real", .base = 10 }
};
poly this_arg = arg::next();
diff --git a/string.5c b/string.5c
index 24e30d1..8f9af18 100644
--- a/string.5c
+++ b/string.5c
@@ -185,7 +185,7 @@ extend namespace String {
}
public dequote_t dequote = make_dequote(
- (quote_context) {oq = "\"", cq = "\"", qq = "\\"}
+ (quote_context) { .oq = "\"", .cq = "\"", .qq = "\\"}
);
typedef (string[*])(string) parse_csv_t;
@@ -249,7 +249,7 @@ extend namespace String {
}
public parse_csv_t parse_csv = make_parse_csv(
- (quote_context) {oq = "\"", cq = "\"", qq = "\""}
+ (quote_context) { .oq = "\"", .cq = "\"", .qq = "\""}
);
}
More information about the Nickle
mailing list