1.1 --- a/generator.py Sat Feb 11 15:34:30 2017 +0100
1.2 +++ b/generator.py Sat Feb 11 16:04:40 2017 +0100
1.3 @@ -902,8 +902,7 @@
1.4 # Special internal data member.
1.5
1.6 elif attrname == "__data__":
1.7 - structure.append("{{.size=%d, .%s=%s}}" % (
1.8 - encode_literal_constant_size(attr),
1.9 + structure.append("{.%s=%s}" % (
1.10 encode_literal_constant_member(attr),
1.11 encode_literal_constant_value(attr)))
1.12 continue
2.1 --- a/templates/native/buffer.c Sat Feb 11 15:34:30 2017 +0100
2.2 +++ b/templates/native/buffer.c Sat Feb 11 16:04:40 2017 +0100
2.3 @@ -1,6 +1,6 @@
2.4 /* Native functions for buffer operations.
2.5
2.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
2.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
2.8
2.9 This program is free software; you can redistribute it and/or modify it under
2.10 the terms of the GNU General Public License as published by the Free Software
2.11 @@ -37,7 +37,7 @@
2.12
2.13 /* Calculate the size of the string. */
2.14 for (i = 0; i < data->size; i++)
2.15 - size += __load_via_object(data->attrs[i].value, __pos___data__).size;
2.16 + size += strlen(__load_via_object(data->attrs[i].value, __pos___data__).strvalue);
2.17
2.18 /* Reserve space for a new string. */
2.19 s = (char *) __ALLOCATE(size + 1, sizeof(char));
2.20 @@ -46,13 +46,13 @@
2.21 for (i = 0, j = 0; i < data->size; i++)
2.22 {
2.23 o = __load_via_object(data->attrs[i].value, __pos___data__);
2.24 - n = o.size;
2.25 + n = strlen(o.strvalue);
2.26 memcpy(s + j, o.strvalue, n); /* does not null terminate but final byte should be zero */
2.27 j += n;
2.28 }
2.29
2.30 /* Return a new string. */
2.31 - return __new_str(s, size);
2.32 + return __new_str(s);
2.33 }
2.34
2.35 /* Module initialisation. */
3.1 --- a/templates/native/common.c Sat Feb 11 15:34:30 2017 +0100
3.2 +++ b/templates/native/common.c Sat Feb 11 16:04:40 2017 +0100
3.3 @@ -1,6 +1,6 @@
3.4 /* Common operations for native functions.
3.5
3.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
3.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
3.8
3.9 This program is free software; you can redistribute it and/or modify it under
3.10 the terms of the GNU General Public License as published by the Free Software
3.11 @@ -34,11 +34,10 @@
3.12 return attr;
3.13 }
3.14
3.15 -__attr __new_str(char *s, size_t size)
3.16 +__attr __new_str(char *s)
3.17 {
3.18 /* Create a new string and mutate the __data__ and __key__ attributes. */
3.19 __attr attr = __new(&__InstanceTable___builtins___str_string, &__builtins___str_string, sizeof(__obj___builtins___str_string));
3.20 - attr.value->attrs[__pos___data__].size = size;
3.21 attr.value->attrs[__pos___data__].strvalue = s;
3.22 attr.value->attrs[__pos___key__] = __NULL;
3.23 return attr;
4.1 --- a/templates/native/common.h Sat Feb 11 15:34:30 2017 +0100
4.2 +++ b/templates/native/common.h Sat Feb 11 16:04:40 2017 +0100
4.3 @@ -1,6 +1,6 @@
4.4 /* Common operations for native functions.
4.5
4.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
4.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
4.8
4.9 This program is free software; you can redistribute it and/or modify it under
4.10 the terms of the GNU General Public License as published by the Free Software
4.11 @@ -24,7 +24,7 @@
4.12 /* Utility functions. */
4.13
4.14 __attr __new_int(int i);
4.15 -__attr __new_str(char *s, size_t size);
4.16 +__attr __new_str(char *s);
4.17 __attr __new_list(__fragment *f);
4.18 __fragment *__fragment_append(__fragment *data, __attr * const value);
4.19
5.1 --- a/templates/native/iconv.c Sat Feb 11 15:34:30 2017 +0100
5.2 +++ b/templates/native/iconv.c Sat Feb 11 16:04:40 2017 +0100
5.3 @@ -1,6 +1,6 @@
5.4 /* Native functions for character set conversion.
5.5
5.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
5.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
5.8
5.9 This program is free software; you can redistribute it and/or modify it under
5.10 the terms of the GNU General Public License as published by the Free Software
5.11 @@ -99,9 +99,9 @@
5.12 /* Incomplete sequence: raise the string in an OSError instead. */
5.13
5.14 if (errno == EINVAL)
5.15 - __raise_incomplete_sequence_error(__new_int(errno), __new_str(resultbuf, outbytestotal));
5.16 + __raise_incomplete_sequence_error(__new_int(errno), __new_str(resultbuf));
5.17
5.18 - return __new_str(resultbuf, outbytestotal);
5.19 + return __new_str(resultbuf);
5.20 }
5.21
5.22 /* Invalid sequence. */
5.23 @@ -110,7 +110,7 @@
5.24 {
5.25 resultbuf = __ALLOCATE(inbytesleft + 1, sizeof(char));
5.26 memcpy(resultbuf, inbuf, inbytesleft);
5.27 - __raise_invalid_sequence_error(__new_int(errno), __new_str(resultbuf, inbytesleft));
5.28 + __raise_invalid_sequence_error(__new_int(errno), __new_str(resultbuf));
5.29 }
5.30
5.31 /* General failure. */
6.1 --- a/templates/native/int.c Sat Feb 11 15:34:30 2017 +0100
6.2 +++ b/templates/native/int.c Sat Feb 11 16:04:40 2017 +0100
6.3 @@ -1,6 +1,6 @@
6.4 /* Native functions for integer operations.
6.5
6.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
6.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
6.8
6.9 This program is free software; you can redistribute it and/or modify it under
6.10 the terms of the GNU General Public License as published by the Free Software
6.11 @@ -268,7 +268,7 @@
6.12 snprintf(s, n, "%d", i);
6.13
6.14 /* Return a new string. */
6.15 - return __new_str(s, strlen(s));
6.16 + return __new_str(s);
6.17 }
6.18
6.19 /* Module initialisation. */
7.1 --- a/templates/native/io.c Sat Feb 11 15:34:30 2017 +0100
7.2 +++ b/templates/native/io.c Sat Feb 11 16:04:40 2017 +0100
7.3 @@ -1,6 +1,6 @@
7.4 /* Native functions for input/output.
7.5
7.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
7.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
7.8
7.9 This program is free software; you can redistribute it and/or modify it under
7.10 the terms of the GNU General Public License as published by the Free Software
7.11 @@ -150,7 +150,7 @@
7.12
7.13 s = __ALLOCATE(have_read + 1, sizeof(char));
7.14 memcpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */
7.15 - return __new_str(s, have_read);
7.16 + return __new_str(s);
7.17 }
7.18
7.19 __attr __fn_native_io_fwrite(__attr __args[])
7.20 @@ -162,7 +162,7 @@
7.21 /* str.__data__ interpreted as string */
7.22 __attr sa = __load_via_object(str->value, __pos___data__);
7.23 char *s = sa.strvalue;
7.24 - size_t to_write = sa.size;
7.25 + size_t to_write = strlen(sa.strvalue);
7.26 size_t have_written = fwrite(s, sizeof(char), to_write, f);
7.27 int error;
7.28
7.29 @@ -212,7 +212,7 @@
7.30
7.31 s = __ALLOCATE(have_read + 1, 1);
7.32 memcpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */
7.33 - return __new_str(s, have_read);
7.34 + return __new_str(s);
7.35 }
7.36
7.37 __attr __fn_native_io_write(__attr __args[])
7.38 @@ -227,7 +227,7 @@
7.39 ssize_t have_written;
7.40
7.41 errno = 0;
7.42 - have_written = write(i, s, sizeof(char) * sa.size);
7.43 + have_written = write(i, s, sizeof(char) * strlen(sa.strvalue));
7.44
7.45 if (have_written == -1)
7.46 __raise_io_error(__new_int(errno));
8.1 --- a/templates/native/list.c Sat Feb 11 15:34:30 2017 +0100
8.2 +++ b/templates/native/list.c Sat Feb 11 16:04:40 2017 +0100
8.3 @@ -32,7 +32,7 @@
8.4 __attr * const size = &__args[1];
8.5 /* size.__data__ interpreted as int */
8.6 unsigned int n = __load_via_object(size->value, __pos___data__).intvalue;
8.7 - __attr attr = {{.size=0, .seqvalue=__new_fragment(n)}};
8.8 + __attr attr = {.seqvalue=__new_fragment(n)};
8.9
8.10 /* Return the __data__ attribute. */
8.11 return attr;
8.12 @@ -61,7 +61,7 @@
8.13
8.14 /* Replace the __data__ attribute if appropriate. */
8.15 if (newdata != data)
8.16 - __store_via_object(self->value, __pos___data__, ((__attr) {{.size=0, .seqvalue=newdata}}));
8.17 + __store_via_object(self->value, __pos___data__, ((__attr) {.seqvalue=newdata}));
8.18 return __builtins___none_None;
8.19 }
8.20
8.21 @@ -92,7 +92,7 @@
8.22
8.23 /* Replace the __data__ attribute if appropriate. */
8.24 if (newdata != data)
8.25 - __store_via_object(self->value, __pos___data__, ((__attr) {{.size=0, .seqvalue=newdata}}));
8.26 + __store_via_object(self->value, __pos___data__, ((__attr) {.seqvalue=newdata}));
8.27 return __builtins___none_None;
8.28 }
8.29
9.1 --- a/templates/native/locale.c Sat Feb 11 15:34:30 2017 +0100
9.2 +++ b/templates/native/locale.c Sat Feb 11 16:04:40 2017 +0100
9.3 @@ -46,7 +46,7 @@
9.4 out = __ALLOCATE(length + 1, sizeof(char));
9.5 strncpy(out, result, length);
9.6
9.7 - return __new_str(result, length);
9.8 + return __new_str(result);
9.9 }
9.10
9.11 __attr __fn_native_locale_setlocale(__attr __args[])
9.12 @@ -69,7 +69,7 @@
9.13 out = __ALLOCATE(length + 1, sizeof(char));
9.14 strncpy(out, result, length);
9.15
9.16 - return __new_str(result, length);
9.17 + return __new_str(result);
9.18 }
9.19
9.20 /* Module initialisation. */
10.1 --- a/templates/native/str.c Sat Feb 11 15:34:30 2017 +0100
10.2 +++ b/templates/native/str.c Sat Feb 11 16:04:40 2017 +0100
10.3 @@ -35,14 +35,15 @@
10.4 /* _data, other interpreted as string */
10.5 char *s = _data->strvalue;
10.6 char *o = other->strvalue;
10.7 - int n = _data->size + other->size;
10.8 + size_t ss = strlen(_data->strvalue), os = strlen(other->strvalue);
10.9 + int n = ss + os;
10.10 char *r = (char *) __ALLOCATE(n + 1, sizeof(char));
10.11
10.12 - memcpy(r, s, _data->size);
10.13 - memcpy(r + _data->size, o, other->size);
10.14 + memcpy(r, s, ss);
10.15 + memcpy(r + ss, o, os);
10.16
10.17 /* Return a new string. */
10.18 - return __new_str(r, n);
10.19 + return __new_str(r);
10.20 }
10.21
10.22 __attr __fn_native_str_str_chr(__attr __args[])
10.23 @@ -53,7 +54,7 @@
10.24 char *s = (char *) __ALLOCATE(2, sizeof(char));
10.25
10.26 s[0] = (char) n;
10.27 - return __new_str(s, 1);
10.28 + return __new_str(s);
10.29 }
10.30
10.31 __attr __fn_native_str_str_lt(__attr __args[])
10.32 @@ -97,14 +98,14 @@
10.33 __attr * const _data = &__args[1];
10.34
10.35 /* Return the new integer. */
10.36 - return __new_int(_data->size);
10.37 + return __new_int(strlen(_data->strvalue));
10.38 }
10.39
10.40 __attr __fn_native_str_str_nonempty(__attr __args[])
10.41 {
10.42 __attr * const _data = &__args[1];
10.43
10.44 - return _data->size ? __builtins___boolean_True : __builtins___boolean_False;
10.45 + return _data->strvalue[0] ? __builtins___boolean_True : __builtins___boolean_False;
10.46 }
10.47
10.48 __attr __fn_native_str_str_ord(__attr __args[])
10.49 @@ -146,7 +147,7 @@
10.50 for (from = istart, to = 0; from > iend; from += istep, to++)
10.51 sub[to] = s[from];
10.52
10.53 - return __new_str(sub, resultsize);
10.54 + return __new_str(sub);
10.55 }
10.56
10.57 /* Module initialisation. */
11.1 --- a/templates/native/unicode.c Sat Feb 11 15:34:30 2017 +0100
11.2 +++ b/templates/native/unicode.c Sat Feb 11 16:04:40 2017 +0100
11.3 @@ -76,7 +76,7 @@
11.4 char *s = _data->strvalue;
11.5 unsigned int i, c = 0;
11.6
11.7 - for (i = 0; i < _data->size; i++)
11.8 + for (i = 0; s[i] != 0; i++)
11.9 if (boundary(s[i]))
11.10 c++;
11.11
11.12 @@ -91,7 +91,7 @@
11.13 char *s = _data->strvalue;
11.14 unsigned int i, c = 0, v;
11.15
11.16 - for (i = 0; i < _data->size; i++)
11.17 + for (i = 0; s[i] != 0; i++)
11.18 {
11.19 /* Evaluate the current character as a boundary. */
11.20
11.21 @@ -137,14 +137,14 @@
11.22 unsigned int indexes[nchar];
11.23
11.24 unsigned int c, d, i, to, from, lastbyte = 0;
11.25 - size_t resultsize = 0;
11.26 + size_t resultsize = 0, ss = strlen(_data->strvalue);
11.27
11.28 /* Find the indexes of the characters. */
11.29 if (istep > 0)
11.30 {
11.31 /* Get the first byte position. */
11.32 for (c = 0; c < istart; c++)
11.33 - lastbyte = nextpos(s, _data->size, lastbyte);
11.34 + lastbyte = nextpos(s, ss, lastbyte);
11.35
11.36 /* Get each subsequent byte position. */
11.37 for (c = istart, i = 0; i < nchar; c += istep, i++)
11.38 @@ -152,17 +152,17 @@
11.39 indexes[i] = lastbyte;
11.40
11.41 /* Add the character size to the result size. */
11.42 - resultsize += nextpos(s, _data->size, lastbyte) - lastbyte;
11.43 + resultsize += nextpos(s, ss, lastbyte) - lastbyte;
11.44
11.45 for (d = c; d < c + istep; d++)
11.46 - lastbyte = nextpos(s, _data->size, lastbyte);
11.47 + lastbyte = nextpos(s, ss, lastbyte);
11.48 }
11.49 }
11.50 else
11.51 {
11.52 /* Get the first byte position. */
11.53 for (c = 0; c < istart; c++)
11.54 - lastbyte = nextpos(s, _data->size, lastbyte);
11.55 + lastbyte = nextpos(s, ss, lastbyte);
11.56
11.57 /* Get each subsequent byte position. */
11.58 for (c = istart, i = 0; i < nchar; c += istep, i++)
11.59 @@ -170,7 +170,7 @@
11.60 indexes[i] = lastbyte;
11.61
11.62 /* Add the character size to the result size. */
11.63 - resultsize += nextpos(s, _data->size, lastbyte) - lastbyte;
11.64 + resultsize += nextpos(s, ss, lastbyte) - lastbyte;
11.65
11.66 for (d = c; d > c + istep; d--)
11.67 lastbyte = prevpos(s, lastbyte);
11.68 @@ -190,7 +190,7 @@
11.69 } while (!boundary(s[from]));
11.70 }
11.71
11.72 - return __new_str(sub, resultsize);
11.73 + return __new_str(sub);
11.74 }
11.75
11.76 /* Module initialisation. */
12.1 --- a/templates/progops.c Sat Feb 11 15:34:30 2017 +0100
12.2 +++ b/templates/progops.c Sat Feb 11 16:04:40 2017 +0100
12.3 @@ -57,7 +57,7 @@
12.4 /* Calculate the size of the fragment. */
12.5
12.6 __fragment *data = __new_fragment(number);
12.7 - __attr attr = {{.size=0, .seqvalue=data}};
12.8 + __attr attr = {.seqvalue=data};
12.9 unsigned int i, j;
12.10
12.11 /* Copy the given number of values, starting from the second element. */
13.1 --- a/templates/progops.h Sat Feb 11 15:34:30 2017 +0100
13.2 +++ b/templates/progops.h Sat Feb 11 16:04:40 2017 +0100
13.3 @@ -1,6 +1,6 @@
13.4 /* Operations depending on program specifics.
13.5
13.6 -Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
13.7 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
13.8
13.9 This program is free software; you can redistribute it and/or modify it under
13.10 the terms of the GNU General Public License as published by the Free Software
13.11 @@ -19,6 +19,7 @@
13.12 #ifndef __PROGOPS_H__
13.13 #define __PROGOPS_H__
13.14
13.15 +#include <stdlib.h> /* size_t */
13.16 #include "types.h"
13.17
13.18 /* Generic instantiation operations, defining common members. */
14.1 --- a/templates/types.h Sat Feb 11 15:34:30 2017 +0100
14.2 +++ b/templates/types.h Sat Feb 11 16:04:40 2017 +0100
14.3 @@ -19,8 +19,6 @@
14.4 #ifndef __TYPES_H__
14.5 #define __TYPES_H__
14.6
14.7 -#include <stddef.h> /* size_t */
14.8 -
14.9 /* Define code and position types, populated by enum values defined for each
14.10 program specifically. */
14.11
14.12 @@ -82,16 +80,13 @@
14.13 struct __attr (*inv)(); /* unbound callable details */
14.14 struct __attr (*fn)(); /* callable details */
14.15 };
14.16 - struct {
14.17 - size_t size; /* size of value */
14.18 - union
14.19 - {
14.20 - int intvalue; /* integer value */
14.21 - double floatvalue; /* floating point value */
14.22 - char * strvalue; /* string value */
14.23 - __fragment * seqvalue; /* sequence data */
14.24 - void * datavalue; /* object-specific data */
14.25 - };
14.26 + union
14.27 + {
14.28 + int intvalue; /* integer value */
14.29 + double floatvalue; /* floating point value */
14.30 + char * strvalue; /* string value */
14.31 + __fragment * seqvalue; /* sequence data */
14.32 + void * datavalue; /* object-specific data */
14.33 };
14.34 };
14.35 } __attr;