1.1 --- a/common.py Mon Feb 04 18:54:14 2019 +0100
1.2 +++ b/common.py Tue Aug 22 19:26:10 2023 +0200
1.3 @@ -3,8 +3,7 @@
1.4 """
1.5 Common functions.
1.6
1.7 -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
1.8 - 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
1.9 +Copyright (C) 2007-2019, 2021 Paul Boddie <paul@boddie.org.uk>
1.10
1.11 This program is free software; you can redistribute it and/or modify it under
1.12 the terms of the GNU General Public License as published by the Free Software
1.13 @@ -563,6 +562,8 @@
1.14 self.next_temporary()
1.15 t2 = self.get_temporary_name()
1.16 self.next_temporary()
1.17 + t3 = self.get_temporary_name()
1.18 + self.next_temporary()
1.19
1.20 node = compiler.ast.Stmt([
1.21
1.22 @@ -583,9 +584,10 @@
1.23 # try:
1.24 # while True:
1.25 # try:
1.26 - # <var>... = <t2>()
1.27 + # <t3> = <t2>()
1.28 # except StopIteration:
1.29 # raise LoopExit
1.30 + # <var>... = <t3>
1.31 # {n.body}
1.32 # except LoopExit:
1.33 # {n.else_}
1.34 @@ -595,21 +597,47 @@
1.35 [compiler.ast.AssName(t2, "OP_ASSIGN")],
1.36 compiler.ast.Getattr(compiler.ast.Name(t1), "next")),
1.37
1.38 + # try:
1.39 +
1.40 compiler.ast.TryExcept(
1.41 +
1.42 + # while True:
1.43 +
1.44 compiler.ast.While(
1.45 compiler.ast.Name("True"),
1.46 compiler.ast.Stmt([
1.47 +
1.48 + # try:
1.49 +
1.50 compiler.ast.TryExcept(
1.51 +
1.52 + # <t3> = <t2>()
1.53 +
1.54 compiler.ast.Assign(
1.55 - [n.assign],
1.56 + [compiler.ast.AssName(t3, "OP_ASSIGN")],
1.57 compiler.ast.CallFunc(
1.58 compiler.ast.Name(t2),
1.59 [])),
1.60 +
1.61 + # except StopIteration:
1.62 + # raise LoopExit
1.63 +
1.64 [(compiler.ast.Name("StopIteration"), None,
1.65 compiler.ast.Raise(compiler.ast.Name("LoopExit")))],
1.66 None),
1.67 +
1.68 + # <var>... = <t3>
1.69 +
1.70 + compiler.ast.Assign(
1.71 + [n.assign],
1.72 + compiler.ast.Name(t3)),
1.73 n.body]),
1.74 None),
1.75 +
1.76 + # except LoopExit:
1.77 + # {n.else_}
1.78 + # pass
1.79 +
1.80 [(compiler.ast.Name("LoopExit"), None, n.else_ or compiler.ast.Pass())],
1.81 None)
1.82 ])
1.83 @@ -1566,11 +1594,7 @@
1.84
1.85 "Return the module name containing the given type 'name'."
1.86
1.87 - if name == "string":
1.88 - modname = "str"
1.89 - elif name == "utf8string":
1.90 - modname = "unicode"
1.91 - elif name == "NoneType":
1.92 + if name == "NoneType":
1.93 modname = "none"
1.94 else:
1.95 modname = name
1.96 @@ -1581,12 +1605,7 @@
1.97
1.98 "Return the type name provided by the given Python value 'name'."
1.99
1.100 - if name == "str":
1.101 - return "string"
1.102 - elif name == "unicode":
1.103 - return "utf8string"
1.104 - else:
1.105 - return name
1.106 + return name
1.107
1.108 def get_builtin_class(name):
1.109
2.1 --- a/docs/COPYING.txt Mon Feb 04 18:54:14 2019 +0100
2.2 +++ b/docs/COPYING.txt Tue Aug 22 19:26:10 2023 +0200
2.3 @@ -1,8 +1,8 @@
2.4 Licence Agreement
2.5 -----------------
2.6
2.7 -Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
2.8 - 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
2.9 +Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
2.10 + 2016, 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
2.11
2.12 This program is free software; you can redistribute it and/or modify it under
2.13 the terms of the GNU General Public License as published by the Free Software
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/docs/tools/make_docs.sh Tue Aug 22 19:26:10 2023 +0200
3.3 @@ -0,0 +1,30 @@
3.4 +#!/bin/sh
3.5 +
3.6 +THISDIR=`dirname "$0"`
3.7 +INDIR="$THISDIR/../wiki"
3.8 +OUTDIR="$THISDIR/../html"
3.9 +
3.10 +ROOT="Lichen"
3.11 +
3.12 +MAPPING='--mapping WikiPedia https://en.wikipedia.org/wiki/'
3.13 +THEME='--theme mercurial'
3.14 +
3.15 +if [ "$1" = '--web' ] ; then
3.16 + DOCINDEX=
3.17 + shift 1
3.18 +else
3.19 + DOCINDEX='--document-index index.html'
3.20 +fi
3.21 +
3.22 +FILENAMES=${*:-'--all'}
3.23 +
3.24 +moinconvert --input-dir "$INDIR" \
3.25 + --input-page-sep '--' \
3.26 + --output-dir "$OUTDIR" \
3.27 + --root "$ROOT" \
3.28 + --format html \
3.29 + --macros \
3.30 + $DOCINDEX \
3.31 + $MAPPING \
3.32 + $THEME \
3.33 + $FILENAMES
4.1 --- a/docs/tools/make_pages.sh Mon Feb 04 18:54:14 2019 +0100
4.2 +++ b/docs/tools/make_pages.sh Tue Aug 22 19:26:10 2023 +0200
4.3 @@ -56,7 +56,7 @@
4.4 BASENAME=`basename "$FILENAME"`
4.5 PAGENAME=`echo "$BASENAME" | sed 's/--/\//g'`
4.6 if [ "$PREFIX" ]; then
4.7 - if [ "$PAGENAME" = "FrontPage" ]; then
4.8 + if [ "$PAGENAME" = "Lichen" ]; then
4.9 PAGENAME="$PREFIX"
4.10 else
4.11 PAGENAME="$PREFIX/$PAGENAME"
5.1 --- a/docs/wiki/Deduction Mon Feb 04 18:54:14 2019 +0100
5.2 +++ b/docs/wiki/Deduction Tue Aug 22 19:26:10 2023 +0200
5.3 @@ -89,7 +89,7 @@
5.4 //format=svg
5.5 //transform=notugly
5.6 digraph indexes {
5.7 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Indexes"];
5.8 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Indexes"];
5.9 edge [tooltip="Indexes"];
5.10 rankdir=LR;
5.11
5.12 @@ -142,7 +142,7 @@
5.13 //format=svg
5.14 //transform=notugly
5.15 digraph deduction {
5.16 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Deduction"];
5.17 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Deduction"];
5.18 edge [tooltip="Deduction"];
5.19 rankdir=LR;
5.20
5.21 @@ -192,7 +192,7 @@
5.22 //format=svg
5.23 //transform=notugly
5.24 digraph usage_to_types {
5.25 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Usage to types"];
5.26 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Usage to types"];
5.27 edge [tooltip="Usage to types"];
5.28 rankdir=LR;
5.29
5.30 @@ -249,7 +249,7 @@
5.31 //format=svg
5.32 //transform=notugly
5.33 digraph instance_providers {
5.34 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Instance providers"];
5.35 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Instance providers"];
5.36 edge [tooltip="Instance providers"];
5.37 rankdir=LR;
5.38
5.39 @@ -310,7 +310,7 @@
5.40 //format=svg
5.41 //transform=notugly
5.42 digraph assignments {
5.43 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Attribute assignments"];
5.44 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Attribute assignments"];
5.45 edge [tooltip="Attribute assignments"];
5.46 rankdir=LR;
5.47
6.1 --- a/docs/wiki/FrontPage Mon Feb 04 18:54:14 2019 +0100
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,95 +0,0 @@
6.4 -= Lichen =
6.5 -
6.6 -|| [[/Downloads|Downloads]] || [[#Language|Language]] || [[#Toolchain|Toolchain]] || [[#Rationale|Rationale]] || [[#Documents|Documents]] ||
6.7 -
6.8 -Lichen is both a Python-like [[/Design|language]] and a
6.9 -[[/Toolchain|toolchain]] for that language.
6.10 -
6.11 -Some objectives:
6.12 -
6.13 - * Perform analysis on programs to better understand program structure and
6.14 - behaviour
6.15 - * Develop code generation capabilities
6.16 - * Provide a platform for experimentation independent of existing Python
6.17 - language and library implementations
6.18 - * Provide independence from Python language evolution
6.19 - * Learn things about writing compilers
6.20 -
6.21 -Despite building on a long [[/History|history]] of experimentation, Lichen
6.22 -still requires some [[/ToDo|work to be done]] for it to be more widely usable.
6.23 -
6.24 -<<Anchor(Language)>>
6.25 -== Language ==
6.26 -
6.27 -The Lichen language [[/Design|foregoes]] various dynamic aspects of Python to
6.28 -provide a foundation upon which more predictable programs can be built, while
6.29 -preserving essential functionality to make the core of the language seem very
6.30 -much "like Python" (thus yielding the name "Lichen"). The general syntax is
6.31 -largely identical to Python, with only certain syntactic constructs being
6.32 -deliberately unsupported, largely because the associated features are not
6.33 -desired.
6.34 -
6.35 -<<Anchor(Toolchain)>>
6.36 -== Toolchain ==
6.37 -
6.38 -The Lichen [[/Toolchain|toolchain]] employs existing tokeniser and parser
6.39 -software to obtain an abstract syntax tree which is then inspected to provide
6.40 -data to support deductions about the structure and nature of a given program.
6.41 -With the information obtained from these processes, a program is then
6.42 -constructed, consisting of a number of source files in the target compilation
6.43 -language (which is currently the C programming language). This generated
6.44 -program may be compiled and run, hopefully producing the results intended by
6.45 -the source program's authors.
6.46 -
6.47 -Lichen source files use the `.py` suffix since the language syntax is
6.48 -superficially compatible with Python, allowing text editors to provide
6.49 -highlighting and editing support for Lichen programs without the need to
6.50 -reconfigure such tools. However, an alternative, recommended suffix is likely
6.51 -to be introduced in future.
6.52 -
6.53 -<<Anchor(Library)>>
6.54 -== Library ==
6.55 -
6.56 -Unlike other Python compilation efforts, Lichen programs employ a newly-written
6.57 -library that is distinct from the CPython standard library distribution and
6.58 -completely independent from the CPython extension and object libraries on which
6.59 -Python programs being run with CPython must depend. Thus, there is no
6.60 -dependency on any `libpython` for run-time functionality. Since the parts of
6.61 -the Python standard library that are written in Python tend to be rather
6.62 -variable in quality, there has been no real inclination to re-use modules from
6.63 -that particular source, noting that they would need modifying to be compatible
6.64 -with Lichen, anyway. However, rewriting such modules provides opportunities to
6.65 -"do things right": with some functionality being over twenty years old and in
6.66 -bad shape, this is arguably something that should have been done for Python,
6.67 -anyway.
6.68 -
6.69 -<<Anchor(Rationale)>>
6.70 -== Rationale ==
6.71 -
6.72 -Python has proven to be a readable, productive, comfortable-to-use and popular
6.73 -programming language. However, as it has accumulated features, the precise
6.74 -behaviour of programs making use of many of these features has become more
6.75 -difficult to predict. Features added to provide even more convenience to the
6.76 -programmer have often incurred run-time costs, introduced layers of
6.77 -indirection, and have made programs even more inscrutable. Instead of
6.78 -development tools reaching a point of being able to infer information about
6.79 -programs, it has been suggested that programmers annotate their programs in
6.80 -order to help tools understand those programs instead. Beyond superficial code
6.81 -style analysis and providing tooltips in integrated development environments,
6.82 -Python code analysis is often portrayed as a lost cause.
6.83 -
6.84 -By employing a refined language [[/Design|design]], Lichen aims to let each
6.85 -program define its [[/Structure|structure]] conveniently, be readily
6.86 -[[/Inspection|inspected]], and thus support [[/Deduction|deductions]] about the
6.87 -use of the program's objects by the code. The result should be more predictable
6.88 -programs that can be [[/Translation|translated]] to other, more efficient,
6.89 -[[/Representations|representations]]. The Lichen toolchain should be able to
6.90 -tell the programmer useful things about their programs that it may also be able
6.91 -to make use of itself. It not only aims to report information about programs
6.92 -that might be of interest to the developer, but it seeks to produce
6.93 -functioning, translated programs that can actually be run.
6.94 -
6.95 -<<Anchor(Documents)>>
6.96 -== Document Index ==
6.97 -
6.98 -<<FullSearch(title:Lichen/)>>
7.1 --- a/docs/wiki/History Mon Feb 04 18:54:14 2019 +0100
7.2 +++ b/docs/wiki/History Tue Aug 22 19:26:10 2023 +0200
7.3 @@ -71,7 +71,7 @@
7.4 == Current Work ==
7.5
7.6 It was with such realisations that a new project was effectively born.
7.7 -Tentatively called "!PythonLight" but renamed to "Lichen" as the code matured,
7.8 +Tentatively called "PythonLight" but renamed to "Lichen" as the code matured,
7.9 the objectives now involved a simpler processing framework that merely
7.10 attempted to catalogue structure members, to determine the origins of such
7.11 members, and to record data flow within namespaces in order to determine
8.1 --- a/docs/wiki/Imports Mon Feb 04 18:54:14 2019 +0100
8.2 +++ b/docs/wiki/Imports Tue Aug 22 19:26:10 2023 +0200
8.3 @@ -95,7 +95,7 @@
8.4 //format=svg
8.5 //transform=notugly
8.6 digraph mutual {
8.7 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Mutually-dependent modules"];
8.8 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Mutually-dependent modules"];
8.9 edge [tooltip="Mutually-dependent modules"];
8.10 rankdir=LR;
8.11
8.12 @@ -209,7 +209,7 @@
8.13 //format=svg
8.14 //transform=notugly
8.15 digraph imports {
8.16 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Import dependencies"];
8.17 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Import dependencies"];
8.18 edge [tooltip="Import dependencies"];
8.19 rankdir=LR;
8.20
9.1 --- a/docs/wiki/Inspection Mon Feb 04 18:54:14 2019 +0100
9.2 +++ b/docs/wiki/Inspection Tue Aug 22 19:26:10 2023 +0200
9.3 @@ -179,7 +179,7 @@
9.4 //format=svg
9.5 //transform=notugly
9.6 digraph accesses {
9.7 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Names and accesses"];
9.8 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Names and accesses"];
9.9 edge [tooltip="Names and accesses"];
9.10 rankdir=TB;
9.11
9.12 @@ -316,7 +316,7 @@
9.13 //format=svg
9.14 //transform=notugly
9.15 digraph usage {
9.16 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Name and attribute tracking"];
9.17 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Name and attribute tracking"];
9.18 edge [tooltip="Name and attribute tracking"];
9.19 rankdir=TB;
9.20
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/docs/wiki/Lichen Tue Aug 22 19:26:10 2023 +0200
10.3 @@ -0,0 +1,95 @@
10.4 += Lichen =
10.5 +
10.6 +|| [[/Downloads|Downloads]] || [[#Language|Language]] || [[#Toolchain|Toolchain]] || [[#Rationale|Rationale]] || [[#Documents|Documents]] ||
10.7 +
10.8 +Lichen is both a Python-like [[/Design|language]] and a
10.9 +[[/Toolchain|toolchain]] for that language.
10.10 +
10.11 +Some objectives:
10.12 +
10.13 + * Perform analysis on programs to better understand program structure and
10.14 + behaviour
10.15 + * Develop code generation capabilities
10.16 + * Provide a platform for experimentation independent of existing Python
10.17 + language and library implementations
10.18 + * Provide independence from Python language evolution
10.19 + * Learn things about writing compilers
10.20 +
10.21 +Despite building on a long [[/History|history]] of experimentation, Lichen
10.22 +still requires some [[/ToDo|work to be done]] for it to be more widely usable.
10.23 +
10.24 +<<Anchor(Language)>>
10.25 +== Language ==
10.26 +
10.27 +The Lichen language [[/Design|foregoes]] various dynamic aspects of Python to
10.28 +provide a foundation upon which more predictable programs can be built, while
10.29 +preserving essential functionality to make the core of the language seem very
10.30 +much "like Python" (thus yielding the name "Lichen"). The general syntax is
10.31 +largely identical to Python, with only certain syntactic constructs being
10.32 +deliberately unsupported, largely because the associated features are not
10.33 +desired.
10.34 +
10.35 +<<Anchor(Toolchain)>>
10.36 +== Toolchain ==
10.37 +
10.38 +The Lichen [[/Toolchain|toolchain]] employs existing tokeniser and parser
10.39 +software to obtain an abstract syntax tree which is then inspected to provide
10.40 +data to support deductions about the structure and nature of a given program.
10.41 +With the information obtained from these processes, a program is then
10.42 +constructed, consisting of a number of source files in the target compilation
10.43 +language (which is currently the C programming language). This generated
10.44 +program may be compiled and run, hopefully producing the results intended by
10.45 +the source program's authors.
10.46 +
10.47 +Lichen source files use the `.py` suffix since the language syntax is
10.48 +superficially compatible with Python, allowing text editors to provide
10.49 +highlighting and editing support for Lichen programs without the need to
10.50 +reconfigure such tools. However, an alternative, recommended suffix is likely
10.51 +to be introduced in future.
10.52 +
10.53 +<<Anchor(Library)>>
10.54 +== Library ==
10.55 +
10.56 +Unlike other Python compilation efforts, Lichen programs employ a newly-written
10.57 +library that is distinct from the CPython standard library distribution and
10.58 +completely independent from the CPython extension and object libraries on which
10.59 +Python programs being run with CPython must depend. Thus, there is no
10.60 +dependency on any `libpython` for run-time functionality. Since the parts of
10.61 +the Python standard library that are written in Python tend to be rather
10.62 +variable in quality, there has been no real inclination to re-use modules from
10.63 +that particular source, noting that they would need modifying to be compatible
10.64 +with Lichen, anyway. However, rewriting such modules provides opportunities to
10.65 +"do things right": with some functionality being over twenty years old and in
10.66 +bad shape, this is arguably something that should have been done for Python,
10.67 +anyway.
10.68 +
10.69 +<<Anchor(Rationale)>>
10.70 +== Rationale ==
10.71 +
10.72 +Python has proven to be a readable, productive, comfortable-to-use and popular
10.73 +programming language. However, as it has accumulated features, the precise
10.74 +behaviour of programs making use of many of these features has become more
10.75 +difficult to predict. Features added to provide even more convenience to the
10.76 +programmer have often incurred run-time costs, introduced layers of
10.77 +indirection, and have made programs even more inscrutable. Instead of
10.78 +development tools reaching a point of being able to infer information about
10.79 +programs, it has been suggested that programmers annotate their programs in
10.80 +order to help tools understand those programs instead. Beyond superficial code
10.81 +style analysis and providing tooltips in integrated development environments,
10.82 +Python code analysis is often portrayed as a lost cause.
10.83 +
10.84 +By employing a refined language [[/Design|design]], Lichen aims to let each
10.85 +program define its [[/Structure|structure]] conveniently, be readily
10.86 +[[/Inspection|inspected]], and thus support [[/Deduction|deductions]] about the
10.87 +use of the program's objects by the code. The result should be more predictable
10.88 +programs that can be [[/Translation|translated]] to other, more efficient,
10.89 +[[/Representations|representations]]. The Lichen toolchain should be able to
10.90 +tell the programmer useful things about their programs that it may also be able
10.91 +to make use of itself. It not only aims to report information about programs
10.92 +that might be of interest to the developer, but it seeks to produce
10.93 +functioning, translated programs that can actually be run.
10.94 +
10.95 +<<Anchor(Documents)>>
10.96 +== Document Index ==
10.97 +
10.98 +<<PageList>>
11.1 --- a/docs/wiki/Representations Mon Feb 04 18:54:14 2019 +0100
11.2 +++ b/docs/wiki/Representations Tue Aug 22 19:26:10 2023 +0200
11.3 @@ -16,8 +16,8 @@
11.4 //format=svg
11.5 //transform=notugly
11.6 digraph attributes {
11.7 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Attributes"];
11.8 - edge [fontsize="13.0",fontname="Helvetica",tooltip="Attributes"];
11.9 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Attributes"];
11.10 + edge [fontsize="13.0",fontname="sans-serif",tooltip="Attributes"];
11.11 rankdir=TB;
11.12
11.13 attrA [label="attribute | { value |<value> reference to object }",shape=record];
11.14 @@ -77,8 +77,8 @@
11.15 //format=svg
11.16 //transform=notugly
11.17 digraph wrappers {
11.18 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Wrappers"];
11.19 - edge [fontsize="13.0",fontname="Helvetica",tooltip="Wrappers"];
11.20 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Wrappers"];
11.21 + edge [fontsize="13.0",fontname="sans-serif",tooltip="Wrappers"];
11.22 rankdir=TB;
11.23
11.24 inst [label="<main> instance | { attr1 |<attr1> reference to method } | { attr2 | value } | ...",shape=record];
11.25 @@ -104,8 +104,8 @@
11.26 //format=svg
11.27 //transform=notugly
11.28 digraph objects {
11.29 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Objects"];
11.30 - edge [fontsize="13.0",fontname="Helvetica",tooltip="Objects"];
11.31 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Objects"];
11.32 + edge [fontsize="13.0",fontname="sans-serif",tooltip="Objects"];
11.33 rankdir=TB;
11.34
11.35 instC [label="<main> instance of C | { 0 | reference to\ninstance table } | { __class__ |<cls> reference\nto C } | { a | value } | { b | value } | ...",shape=record];
12.1 --- a/docs/wiki/Restarted Mon Feb 04 18:54:14 2019 +0100
12.2 +++ b/docs/wiki/Restarted Tue Aug 22 19:26:10 2023 +0200
12.3 @@ -262,8 +262,8 @@
12.4 //format=svg
12.5 //transform=notugly
12.6 digraph structures {
12.7 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Instance and class structures"];
12.8 - edge [fontsize="13.0",fontname="Helvetica",tooltip="Instance and class structures"];
12.9 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Instance and class structures"];
12.10 + edge [fontsize="13.0",fontname="sans-serif",tooltip="Instance and class structures"];
12.11 rankdir=TB;
12.12
12.13 instanceC [label="<main> instance of C |{ context of a | value of a }|{context of b | value of b }",shape=record];
12.14 @@ -285,8 +285,8 @@
12.15 //format=svg
12.16 //transform=notugly
12.17 digraph methods {
12.18 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Method structures"];
12.19 - edge [fontsize="13.0",fontname="Helvetica",tooltip="Method structures"];
12.20 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Method structures"];
12.21 + edge [fontsize="13.0",fontname="sans-serif",tooltip="Method structures"];
12.22 rankdir=TB;
12.23
12.24 classC [label="<main> class C | { context of m | <mvalue> uncallable for m } | ...",shape=record];
13.1 --- a/docs/wiki/Structure Mon Feb 04 18:54:14 2019 +0100
13.2 +++ b/docs/wiki/Structure Tue Aug 22 19:26:10 2023 +0200
13.3 @@ -29,7 +29,7 @@
13.4 //format=svg
13.5 //transform=notugly
13.6 digraph program {
13.7 - node [shape=box,fontsize="13.0",fontname="Helvetica",tooltip="Program structure"];
13.8 + node [shape=box,fontsize="13.0",fontname="sans-serif",tooltip="Program structure"];
13.9 edge [tooltip="Program structure"];
13.10 rankdir=LR;
13.11
14.1 --- a/docs/wiki/Toolchain Mon Feb 04 18:54:14 2019 +0100
14.2 +++ b/docs/wiki/Toolchain Tue Aug 22 19:26:10 2023 +0200
14.3 @@ -73,12 +73,12 @@
14.4 which the `parser` module effectively is (as would the `ast` module also be if
14.5 it were used here), with it typically being implemented as an extension module
14.6 in a non-Python language (in C for CPython, in Java for Jython, and so on).
14.7 -Fortunately, the !PyPy project implemented their own parsing module,
14.8 -`pyparser`, that is intended to be used within the !PyPy environment together
14.9 -with their own `ast` equivalent, but it has been possible to rework `pyparser`
14.10 -to produce representations that are compatible with the `compiler` package,
14.11 -itself being modified in various ways to achieve compatibility (and also to
14.12 -provide various other conveniences).
14.13 +Fortunately, the [[http://pypy.org/|PyPy]] project implemented their own
14.14 +parsing module, `pyparser`, that is intended to be used within the PyPy
14.15 +environment together with their own `ast` equivalent, but it has been possible
14.16 +to rework `pyparser` to produce representations that are compatible with the
14.17 +`compiler` package, itself being modified in various ways to achieve
14.18 +compatibility (and also to provide various other conveniences).
14.19
14.20 == Program Analysis ==
14.21
15.1 --- a/generator.py Mon Feb 04 18:54:14 2019 +0100
15.2 +++ b/generator.py Tue Aug 22 19:26:10 2023 +0200
15.3 @@ -3,7 +3,7 @@
15.4 """
15.5 Generate C code from object layouts and other deduced information.
15.6
15.7 -Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
15.8 +Copyright (C) 2015-2019, 2021 Paul Boddie <paul@boddie.org.uk>
15.9
15.10 This program is free software; you can redistribute it and/or modify it under
15.11 the terms of the GNU General Public License as published by the Free Software
15.12 @@ -48,10 +48,10 @@
15.13 int_type = "__builtins__.int.int"
15.14 list_type = "__builtins__.list.list"
15.15 none_type = "__builtins__.none.NoneType"
15.16 - string_type = "__builtins__.str.string"
15.17 + string_type = "__builtins__.str.str"
15.18 tuple_type = "__builtins__.tuple.tuple"
15.19 type_type = "__builtins__.core.type"
15.20 - unicode_type = "__builtins__.unicode.utf8string"
15.21 + unicode_type = "__builtins__.unicode.unicode"
15.22
15.23 none_value = "__builtins__.none.None"
15.24
15.25 @@ -1066,7 +1066,7 @@
15.26 # Special internal size member.
15.27
15.28 elif attrname == "__size__":
15.29 - structure.append("__INTVALUE(%d)" % attr)
15.30 + structure.append("{.sizevalue=%d}" % attr)
15.31 continue
15.32
15.33 # Special internal key member.
15.34 @@ -1263,18 +1263,51 @@
15.35 for name in parameters:
15.36 l.append("__attr %s" % name)
15.37
15.38 - print >>f_code, """\
15.39 + # Special-case the integer type.
15.40 +
15.41 + # Here, the __builtins__.int.new_int function is called with the
15.42 + # initialiser's parameters.
15.43 +
15.44 + if path == self.int_type:
15.45 + print >>f_code, """\
15.46 +__attr %s(__attr __self, __attr number_or_string, __attr base)
15.47 +{
15.48 + return __fn___builtins___int_new_int(__NULL, number_or_string, base);
15.49 +}
15.50 +""" % (
15.51 + encode_instantiator_pointer(path),
15.52 + )
15.53 +
15.54 + # Special-case the string types.
15.55 +
15.56 + # Here, the __builtins__.str.new_str function is called with the
15.57 + # initialiser's parameter.
15.58 +
15.59 + elif path == self.string_type:
15.60 + print >>f_code, """\
15.61 +__attr %s(__attr __self, __attr obj)
15.62 +{
15.63 + return __fn___builtins___str_new_str(__NULL, obj);
15.64 +}
15.65 +""" % (
15.66 + encode_instantiator_pointer(path),
15.67 + )
15.68 +
15.69 + # Generic instantiation support.
15.70 +
15.71 + else:
15.72 + print >>f_code, """\
15.73 __attr %s(__attr __self%s)
15.74 {
15.75 return %s(__NEWINSTANCE(%s)%s);
15.76 }
15.77 """ % (
15.78 - encode_instantiator_pointer(path),
15.79 - l and ", %s" % ",".join(l) or "",
15.80 - encode_function_pointer(initialiser),
15.81 - encode_path(path),
15.82 - parameters and ", %s" % ", ".join(parameters) or ""
15.83 - )
15.84 + encode_instantiator_pointer(path),
15.85 + l and ", %s" % ",".join(l) or "",
15.86 + encode_function_pointer(initialiser),
15.87 + encode_path(path),
15.88 + parameters and ", %s" % ", ".join(parameters) or ""
15.89 + )
15.90
15.91 # Signature: __new_typename(__attr __self, ...)
15.92
15.93 @@ -1332,6 +1365,6 @@
15.94
15.95 return 0;
15.96 }
15.97 -""" % encode_function_pointer("__builtins__.str.str")
15.98 +""" % encode_instantiator_pointer("__builtins__.str.str")
15.99
15.100 # vim: tabstop=4 expandtab shiftwidth=4
16.1 --- a/inspector.py Mon Feb 04 18:54:14 2019 +0100
16.2 +++ b/inspector.py Tue Aug 22 19:26:10 2023 +0200
16.3 @@ -3,8 +3,7 @@
16.4 """
16.5 Inspect and obtain module structure.
16.6
16.7 -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013,
16.8 - 2014, 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
16.9 +Copyright (C) 2007-2019, 2021 Paul Boddie <paul@boddie.org.uk>
16.10
16.11 This program is free software; you can redistribute it and/or modify it under
16.12 the terms of the GNU General Public License as published by the Free Software
16.13 @@ -78,13 +77,13 @@
16.14
16.15 ref = self.get_builtin("module")
16.16 self.set_name("__class__", ref)
16.17 - self.set_name("__name__", self.get_constant("string", self.name).reference())
16.18 - self.set_name("__file__", self.get_constant("string", filename).reference())
16.19 + self.set_name("__name__", self.get_constant("str", self.name).reference())
16.20 + self.set_name("__file__", self.get_constant("str", filename).reference())
16.21
16.22 # Reserve a constant for the encoding.
16.23
16.24 if self.encoding:
16.25 - self.get_constant("string", self.encoding)
16.26 + self.get_constant("str", self.encoding)
16.27
16.28 # Get module-level attribute usage details.
16.29
16.30 @@ -531,7 +530,7 @@
16.31 # Provide leafname, parent and context attributes.
16.32
16.33 parent, leafname = class_name.rsplit(".", 1)
16.34 - self.set_name("__name__", self.get_constant("string", leafname).reference())
16.35 + self.set_name("__name__", self.get_constant("str", leafname).reference())
16.36
16.37 if class_name != "__builtins__.core.function":
16.38 self.set_name("__parent__")
16.39 @@ -659,6 +658,9 @@
16.40 self.function_defaults[function_name] = []
16.41
16.42 for argname, default in compiler.ast.get_defaults(n):
16.43 + if argname[0] == ".":
16.44 + argname = argname[1:]
16.45 +
16.46 if default:
16.47
16.48 # Obtain any reference for the default.
16.49 @@ -678,7 +680,7 @@
16.50
16.51 # Define a leafname attribute value for the function instance.
16.52
16.53 - ref = self.get_builtin_class("string")
16.54 + ref = self.get_builtin_class("str")
16.55 self.reserve_constant(function_name, name, ref.get_origin())
16.56
16.57 # Track attribute usage within the namespace.
17.1 --- a/internal_tests/branches.py Mon Feb 04 18:54:14 2019 +0100
17.2 +++ b/internal_tests/branches.py Tue Aug 22 19:26:10 2023 +0200
17.3 @@ -687,4 +687,77 @@
17.4 bt.get_assignment_positions_for_branches("a", ar)
17.5 names.append(bt.assignments["a"])
17.6
17.7 +# This demonstrates why the assignment in a "for" loop construct must appear
17.8 +# outside the inner "try" body: null usage escapes the loop via the exception
17.9 +# handler and the raise statement, even though the assignment would only be
17.10 +# valid otherwise.
17.11 +
17.12 +# Equivalent to...
17.13 +#
17.14 +# try:
17.15 +# while ...:
17.16 +# try:
17.17 +# a = ...
17.18 +# except:
17.19 +# raise ...
17.20 +# a.p
17.21 +# except:
17.22 +# pass
17.23 +
17.24 +bt = branching.BranchTracker()
17.25 +bt.new_branchpoint() # begin (try)
17.26 +bt.new_branchpoint(True) # begin (while)
17.27 +bt.new_branch(True) # while ...
17.28 +bt.new_branchpoint() # begin (try)
17.29 +a = bt.assign_names(["a"])
17.30 +bt.resume_abandoned_branches() # except
17.31 +bt.abandon_branch() # raise
17.32 +bt.shelve_branch()
17.33 +bt.new_branch() # (null)
17.34 +bt.shelve_branch()
17.35 +bt.merge_branches() # end (try)
17.36 +ap = bt.use_attribute("a", "p")
17.37 +bt.resume_continuing_branches()
17.38 +bt.shelve_branch(True)
17.39 +bt.new_branch() # (null)
17.40 +bt.shelve_branch()
17.41 +bt.merge_branches() # end (while)
17.42 +bt.resume_broken_branches()
17.43 +bt.resume_abandoned_branches() # except
17.44 +bt.shelve_branch()
17.45 +bt.new_branch() # (null)
17.46 +bt.shelve_branch()
17.47 +bt.merge_branches() # end (try)
17.48 +
17.49 +print simple_usage(a) == \
17.50 + {'a' : set([('p',), ()])}, simple_usage(a)
17.51 +print bt.get_assignment_positions_for_branches("a", ap) == [0], \
17.52 + bt.get_assignment_positions_for_branches("a", ap)
17.53 +names.append(bt.assignments["a"])
17.54 +
17.55 +# Equivalent to...
17.56 +#
17.57 +# b = ...
17.58 +# while ...:
17.59 +# a = ...
17.60 +# a.p
17.61 +
17.62 +bt = branching.BranchTracker()
17.63 +bt.new_branchpoint(True) # begin
17.64 +b = bt.assign_names(["b"])
17.65 +bt.new_branch(True) # while ...
17.66 +a = bt.assign_names(["a"])
17.67 +ap = bt.use_attribute("a", "p")
17.68 +bt.resume_continuing_branches()
17.69 +bt.shelve_branch(True)
17.70 +bt.new_branch() # (null)
17.71 +bt.shelve_branch()
17.72 +bt.merge_branches() # end
17.73 +
17.74 +print simple_usage(a) == \
17.75 + {'a' : set([('p',)])}, simple_usage(a)
17.76 +print bt.get_assignment_positions_for_branches("a", ap) == [0], \
17.77 + bt.get_assignment_positions_for_branches("a", ap)
17.78 +names.append(bt.assignments["a"])
17.79 +
17.80 # vim: tabstop=4 expandtab shiftwidth=4
18.1 --- a/lib/__builtins__/__init__.py Mon Feb 04 18:54:14 2019 +0100
18.2 +++ b/lib/__builtins__/__init__.py Tue Aug 22 19:26:10 2023 +0200
18.3 @@ -3,7 +3,7 @@
18.4 """
18.5 Simple built-in classes and functions.
18.6
18.7 -Copyright (C) 2015, 2016, 2017, 2019 Paul Boddie <paul@boddie.org.uk>
18.8 +Copyright (C) 2015, 2016, 2017, 2019, 2021 Paul Boddie <paul@boddie.org.uk>
18.9
18.10 This program is free software; you can redistribute it and/or modify it under
18.11 the terms of the GNU General Public License as published by the Free Software
18.12 @@ -68,9 +68,9 @@
18.13 from __builtins__.none import None, NoneType
18.14 from __builtins__.notimplemented import NotImplemented, NotImplementedType
18.15 from __builtins__.set import frozenset, set
18.16 -from __builtins__.str import basestring, str, string
18.17 +from __builtins__.str import basestring, str
18.18 from __builtins__.tuple import tuple
18.19 -from __builtins__.unicode import unicode, utf8string
18.20 +from __builtins__.unicode import unicode
18.21
18.22 # Functions.
18.23
19.1 --- a/lib/__builtins__/buffer.py Mon Feb 04 18:54:14 2019 +0100
19.2 +++ b/lib/__builtins__/buffer.py Tue Aug 22 19:26:10 2023 +0200
19.3 @@ -53,7 +53,7 @@
19.4
19.5 if isinstance(s, buffer):
19.6 list_concat(self, s.__data__)
19.7 - elif isinstance(s, string):
19.8 + elif isinstance(s, str):
19.9 list_append(self, s)
19.10 else:
19.11 list_append(self, str(s))
20.1 --- a/lib/__builtins__/character.py Mon Feb 04 18:54:14 2019 +0100
20.2 +++ b/lib/__builtins__/character.py Tue Aug 22 19:26:10 2023 +0200
20.3 @@ -103,7 +103,7 @@
20.4 check_int(i)
20.5
20.6 if 0 <= i <= 2097151:
20.7 - return utf8string(unicode_unichr(i))
20.8 + return unicode(unicode_unichr(i))
20.9 else:
20.10 raise ValueError, i
20.11
21.1 --- a/lib/__builtins__/exception/base.py Mon Feb 04 18:54:14 2019 +0100
21.2 +++ b/lib/__builtins__/exception/base.py Tue Aug 22 19:26:10 2023 +0200
21.3 @@ -71,7 +71,11 @@
21.4
21.5 "An exception signalling the end of iteration."
21.6
21.7 - pass
21.8 + def __init__(self, .iterator=None):
21.9 +
21.10 + "Initialise the exception with the given 'iterator'."
21.11 +
21.12 + pass
21.13
21.14 class ValueError(Exception):
21.15
22.1 --- a/lib/__builtins__/float.py Mon Feb 04 18:54:14 2019 +0100
22.2 +++ b/lib/__builtins__/float.py Tue Aug 22 19:26:10 2023 +0200
22.3 @@ -3,7 +3,7 @@
22.4 """
22.5 Floating point number objects.
22.6
22.7 -Copyright (C) 2015, 2016, 2018 Paul Boddie <paul@boddie.org.uk>
22.8 +Copyright (C) 2015, 2016, 2018, 2021 Paul Boddie <paul@boddie.org.uk>
22.9
22.10 This program is free software; you can redistribute it and/or modify it under
22.11 the terms of the GNU General Public License as published by the Free Software
22.12 @@ -19,7 +19,7 @@
22.13 this program. If not, see <http://www.gnu.org/licenses/>.
22.14 """
22.15
22.16 -from __builtins__.unicode import utf8string
22.17 +from __builtins__.unicode import unicode
22.18 from native import isinstance as _isinstance, \
22.19 int_float, is_int, \
22.20 float_add, float_div, float_eq, float_ge, float_gt, \
22.21 @@ -194,7 +194,7 @@
22.22
22.23 "Return a string representation."
22.24
22.25 - return utf8string(float_str(self))
22.26 + return unicode(float_str(self))
22.27
22.28 __repr__ = __str__
22.29
23.1 --- a/lib/__builtins__/int.py Mon Feb 04 18:54:14 2019 +0100
23.2 +++ b/lib/__builtins__/int.py Tue Aug 22 19:26:10 2023 +0200
23.3 @@ -3,7 +3,7 @@
23.4 """
23.5 Integer objects.
23.6
23.7 -Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
23.8 +Copyright (C) 2015, 2016, 2017, 2018, 2021 Paul Boddie <paul@boddie.org.uk>
23.9
23.10 This program is free software; you can redistribute it and/or modify it under
23.11 the terms of the GNU General Public License as published by the Free Software
23.12 @@ -19,22 +19,55 @@
23.13 this program. If not, see <http://www.gnu.org/licenses/>.
23.14 """
23.15
23.16 -from __builtins__.unicode import utf8string
23.17 +from __builtins__.str import basestring
23.18 +from __builtins__.unicode import unicode
23.19 from native import get_maxint, get_minint, is_int, \
23.20 int_add, int_and, int_div, int_eq, int_ge, int_gt, \
23.21 int_lshift, int_le, int_lt, int_mod, int_mul, int_ne, \
23.22 int_neg, int_not, int_or, int_pow, int_rshift, int_str, \
23.23 int_sub, int_xor
23.24
23.25 +def new_int(number_or_string, base=10):
23.26 +
23.27 + "Initialise the integer with the given 'number_or_string'."
23.28 +
23.29 + if is_int(number_or_string):
23.30 + return number_or_string
23.31 + elif isinstance(number_or_string, basestring):
23.32 + return str_to_int(number_or_string, base)
23.33 + else:
23.34 + raise TypeError
23.35 +
23.36 +def str_to_int(value, base=10):
23.37 +
23.38 + "Decode the string 'value' using the given 'base'."
23.39 +
23.40 + # NOTE: Add support for lower and upper in the string classes.
23.41 +
23.42 + #value = value.lower()
23.43 + len_value = len(value)
23.44 + digits = "0123456789abcdefghijklmnopqrstuvwxyz"
23.45 +
23.46 + result = 0
23.47 + i = 0
23.48 +
23.49 + while i < len_value:
23.50 + c = value[i]
23.51 + d = digits.index(c)
23.52 + result = result * base + d
23.53 + i += 1
23.54 +
23.55 + return result
23.56 +
23.57 class int:
23.58
23.59 "An integer abstraction."
23.60
23.61 - def __init__(self, number_or_string=None):
23.62 + def __init__(self, number_or_string=None, base=10):
23.63
23.64 "Initialise the integer with the given 'number_or_string'."
23.65
23.66 - # NOTE: To be implemented.
23.67 + # Implemented by new_int above, invoked specially by the translator.
23.68
23.69 pass
23.70
23.71 @@ -245,7 +278,7 @@
23.72
23.73 "Return a string representation."
23.74
23.75 - return utf8string(int_str(self))
23.76 + return unicode(int_str(self))
23.77
23.78 __repr__ = __str__
23.79
24.1 --- a/lib/__builtins__/iteration/iterator.py Mon Feb 04 18:54:14 2019 +0100
24.2 +++ b/lib/__builtins__/iteration/iterator.py Tue Aug 22 19:26:10 2023 +0200
24.3 @@ -3,7 +3,7 @@
24.4 """
24.5 Iterator objects.
24.6
24.7 -Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
24.8 +Copyright (C) 2015, 2016, 2019 Paul Boddie <paul@boddie.org.uk>
24.9
24.10 This program is free software; you can redistribute it and/or modify it under
24.11 the terms of the GNU General Public License as published by the Free Software
24.12 @@ -39,6 +39,6 @@
24.13 self.i += 1
24.14 return value
24.15 except IndexError:
24.16 - raise StopIteration()
24.17 + raise StopIteration, self
24.18
24.19 # vim: tabstop=4 expandtab shiftwidth=4
25.1 --- a/lib/__builtins__/set.py Mon Feb 04 18:54:14 2019 +0100
25.2 +++ b/lib/__builtins__/set.py Tue Aug 22 19:26:10 2023 +0200
25.3 @@ -3,7 +3,7 @@
25.4 """
25.5 Set objects.
25.6
25.7 -Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
25.8 +Copyright (C) 2015, 2016, 2017, 2019 Paul Boddie <paul@boddie.org.uk>
25.9
25.10 This program is free software; you can redistribute it and/or modify it under
25.11 the terms of the GNU General Public License as published by the Free Software
25.12 @@ -323,7 +323,7 @@
25.13 try:
25.14 bucket = self.mapping.buckets[self.index]
25.15 except IndexError:
25.16 - raise StopIteration
25.17 + raise StopIteration, self
25.18
25.19 # Access the current item. If no such item exists, get another
25.20 # bucket.
26.1 --- a/lib/__builtins__/span.py Mon Feb 04 18:54:14 2019 +0100
26.2 +++ b/lib/__builtins__/span.py Tue Aug 22 19:26:10 2023 +0200
26.3 @@ -3,7 +3,7 @@
26.4 """
26.5 Span-related objects.
26.6
26.7 -Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
26.8 +Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
26.9
26.10 This program is free software; you can redistribute it and/or modify it under
26.11 the terms of the GNU General Public License as published by the Free Software
26.12 @@ -101,7 +101,7 @@
26.13 "Return the next item or raise a StopIteration exception."
26.14
26.15 if not self.count:
26.16 - raise StopIteration
26.17 + raise StopIteration, self
26.18
26.19 current = self.current
26.20 self.current = self.current.__add__(self.step)
27.1 --- a/lib/__builtins__/str.py Mon Feb 04 18:54:14 2019 +0100
27.2 +++ b/lib/__builtins__/str.py Tue Aug 22 19:26:10 2023 +0200
27.3 @@ -3,7 +3,7 @@
27.4 """
27.5 String objects.
27.6
27.7 -Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
27.8 +Copyright (C) 2015, 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
27.9
27.10 This program is free software; you can redistribute it and/or modify it under
27.11 the terms of the GNU General Public License as published by the Free Software
27.12 @@ -24,7 +24,7 @@
27.13 from __builtins__.types import check_int
27.14 from native import isinstance as _isinstance, \
27.15 str_add, str_lt, str_gt, str_eq, str_ord, \
27.16 - str_substr
27.17 + str_size, str_substr
27.18
27.19 WHITESPACE = (" ", "\f", "\n", "\r", "\t")
27.20
27.21 @@ -54,7 +54,7 @@
27.22 else:
27.23 self.__data__ = None
27.24 self.__key__ = None
27.25 - self.__size__ = 0
27.26 + self.__size__ = None
27.27
27.28 # Internal methods.
27.29
27.30 @@ -158,7 +158,7 @@
27.31
27.32 "Return the number of bytes in this string."
27.33
27.34 - return self.__size__
27.35 + return str_size(self.__size__)
27.36
27.37 # General type methods.
27.38
27.39 @@ -166,7 +166,7 @@
27.40
27.41 "Return whether the string provides any data."
27.42
27.43 - return self.__size__.__bool__()
27.44 + return str_size(self.__size__).__bool__()
27.45
27.46 def __contains__(self, value):
27.47
27.48 @@ -576,7 +576,7 @@
27.49
27.50 def upper(self): pass
27.51
27.52 -class string(basestring):
27.53 +class str(basestring):
27.54
27.55 "A plain string of bytes."
27.56
27.57 @@ -607,7 +607,7 @@
27.58 l = get_using(basestring.__get_multiple_items__, self)(start, end, step)
27.59 return "".join(l)
27.60
27.61 -def str(obj):
27.62 +def new_str(obj):
27.63
27.64 "Return the string representation of 'obj'."
27.65
28.1 --- a/lib/__builtins__/stream.py Mon Feb 04 18:54:14 2019 +0100
28.2 +++ b/lib/__builtins__/stream.py Tue Aug 22 19:26:10 2023 +0200
28.3 @@ -144,7 +144,7 @@
28.4 # Encode text as bytes if necessary. When the encoding is not set, any
28.5 # original encoding of the text will be applied.
28.6
28.7 - if _isinstance(s, utf8string):
28.8 + if _isinstance(s, unicode):
28.9 s = s.encode(self.encoding)
28.10
28.11 fwrite(self.__data__, s)
29.1 --- a/lib/__builtins__/unicode.py Mon Feb 04 18:54:14 2019 +0100
29.2 +++ b/lib/__builtins__/unicode.py Tue Aug 22 19:26:10 2023 +0200
29.3 @@ -3,7 +3,7 @@
29.4 """
29.5 Unicode objects.
29.6
29.7 -Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
29.8 +Copyright (C) 2015, 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
29.9
29.10 This program is free software; you can redistribute it and/or modify it under
29.11 the terms of the GNU General Public License as published by the Free Software
29.12 @@ -25,21 +25,58 @@
29.13 from native import str_add, unicode_len, unicode_ord, unicode_substr, \
29.14 isinstance as _isinstance
29.15
29.16 -class utf8string(basestring):
29.17 +class unicode(basestring):
29.18
29.19 "A character string representation based on UTF-8."
29.20
29.21 - def __init__(self, other=None, encoding=None):
29.22 + def __init__(self, s, encoding=None, original=None):
29.23
29.24 """
29.25 - Initialise the string, perhaps from 'other', with any original
29.26 - 'encoding' indicated.
29.27 + Initialise the string from 'other', employing any indicated 'encoding'
29.28 + for the provided string data.
29.29 +
29.30 + If 'original' is indicated, this may be used to override the original
29.31 + encoding. This is useful when the string data is already in UTF-8
29.32 + format, but where the original encoding needs to be communicated.
29.33 """
29.34
29.35 - get_using(basestring.__init__, self)(other)
29.36 - self.encoding = encoding
29.37 self.length = None
29.38
29.39 + # Initialise using another Unicode object.
29.40 +
29.41 + if _isinstance(s, unicode):
29.42 + get_using(basestring.__init__, self)(s)
29.43 + self.encoding = s.encoding
29.44 +
29.45 + # Initialise using suitable string data but with an explicit original
29.46 + # encoding.
29.47 +
29.48 + elif original:
29.49 + get_using(basestring.__init__, self)(s)
29.50 + self.encoding = original
29.51 +
29.52 + # Initialise using string data having either UTF-8 or another encoding,
29.53 + # converting to UTF-8 and retaining the encoding details as the original
29.54 + # encoding.
29.55 +
29.56 + else:
29.57 + # Obtain a string representation.
29.58 +
29.59 + s = s.__str__()
29.60 +
29.61 + # Convert the string to UTF-8. Even if the stated encoding is UTF-8, it
29.62 + # needs to be validated.
29.63 +
29.64 + to_utf8 = Converter(encoding or "UTF-8", "UTF-8")
29.65 +
29.66 + try:
29.67 + to_utf8.feed(s)
29.68 + get_using(basestring.__init__, self)(str(to_utf8))
29.69 + finally:
29.70 + to_utf8.close()
29.71 +
29.72 + self.encoding = encoding
29.73 +
29.74 def _binary_op(self, op, other, sizes=False):
29.75
29.76 "Perform 'op' on this object and 'other' if appropriate."
29.77 @@ -51,7 +88,7 @@
29.78
29.79 # Combining text with bytes.
29.80
29.81 - if not _isinstance(other, utf8string):
29.82 + if not _isinstance(other, unicode):
29.83 s = self.encode()
29.84 else:
29.85 s = self
29.86 @@ -72,7 +109,7 @@
29.87
29.88 # Combining text with bytes.
29.89
29.90 - if not _isinstance(other, utf8string):
29.91 + if not _isinstance(other, unicode):
29.92 s = self.encode()
29.93 else:
29.94 s = self
29.95 @@ -86,8 +123,8 @@
29.96
29.97 "Convert 'result' to a Unicode object if 'other' already is."
29.98
29.99 - if _isinstance(other, utf8string):
29.100 - return utf8string(result, self.encoding)
29.101 + if _isinstance(other, unicode):
29.102 + return unicode(result, None, self.encoding)
29.103 else:
29.104 return result
29.105
29.106 @@ -188,15 +225,14 @@
29.107 elif nonempty:
29.108 b.append(self)
29.109
29.110 - if _isinstance(s, utf8string):
29.111 + if _isinstance(s, unicode):
29.112 encoding = None
29.113
29.114 b.append(s)
29.115
29.116 s = str(b)
29.117 if encoding:
29.118 - s = utf8string(s)
29.119 - s.encoding = encoding
29.120 + s = unicode(s, None, encoding)
29.121 return s
29.122
29.123 # Special implementation methods.
29.124 @@ -204,9 +240,9 @@
29.125 def __get_single_item__(self, index):
29.126
29.127 "Return the item at the normalised (positive) 'index'."
29.128 -
29.129 +
29.130 self._check_index(index)
29.131 - return utf8string(unicode_substr(self.__data__, self.__size__, index, index + 1, 1), self.encoding)
29.132 + return unicode(unicode_substr(self.__data__, self.__size__, index, index + 1, 1), None, self.encoding)
29.133
29.134 def __get_multiple_items__(self, start, end, step):
29.135
29.136 @@ -224,29 +260,6 @@
29.137 raise ValueError(step)
29.138
29.139 l = get_using(basestring.__get_multiple_items__, self)(start, end, step)
29.140 - return utf8string("".join(l), self.encoding)
29.141 -
29.142 -def unicode(s, encoding):
29.143 -
29.144 - "Convert 's' to a Unicode object, interpreting 's' as using 'encoding'."
29.145 -
29.146 - if isinstance(s, utf8string):
29.147 - return s
29.148 -
29.149 - # Obtain a string representation.
29.150 -
29.151 - s = s.__str__()
29.152 -
29.153 - # Convert the string to UTF-8. Even if the stated encoding is UTF-8, it
29.154 - # needs to be validated.
29.155 -
29.156 - to_utf8 = Converter(encoding, "UTF-8")
29.157 -
29.158 - try:
29.159 - to_utf8.feed(s)
29.160 - return utf8string(str(to_utf8), encoding)
29.161 -
29.162 - finally:
29.163 - to_utf8.close()
29.164 + return unicode("".join(l), None, self.encoding)
29.165
29.166 # vim: tabstop=4 expandtab shiftwidth=4
30.1 --- a/lib/native/__init__.py Mon Feb 04 18:54:14 2019 +0100
30.2 +++ b/lib/native/__init__.py Tue Aug 22 19:26:10 2023 +0200
30.3 @@ -3,7 +3,7 @@
30.4 """
30.5 Native library functions.
30.6
30.7 -Copyright (C) 2011, 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
30.8 +Copyright (C) 2011, 2015-2018, 2021 Paul Boddie <paul@boddie.org.uk>
30.9
30.10 This program is free software; you can redistribute it and/or modify it under
30.11 the terms of the GNU General Public License as published by the Free Software
30.12 @@ -51,7 +51,7 @@
30.13 from native.program import get_using
30.14
30.15 from native.str import str_add, str_chr, str_eq, str_gt, str_lt, \
30.16 - str_ord, str_substr
30.17 + str_ord, str_size, str_substr
30.18
30.19 from native.system import exit, get_argv, get_path
30.20
31.1 --- a/lib/native/str.py Mon Feb 04 18:54:14 2019 +0100
31.2 +++ b/lib/native/str.py Tue Aug 22 19:26:10 2023 +0200
31.3 @@ -8,7 +8,7 @@
31.4 non-core exceptions used by the native functions because they need to be
31.5 identified as being needed by the program.
31.6
31.7 -Copyright (C) 2011, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
31.8 +Copyright (C) 2011, 2015, 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
31.9
31.10 This program is free software; you can redistribute it and/or modify it under
31.11 the terms of the GNU General Public License as published by the Free Software
31.12 @@ -32,6 +32,7 @@
31.13 def str_gt(data, other_data): return True or False
31.14 def str_lt(data, other_data): return True or False
31.15 def str_ord(data): return 0
31.16 +def str_size(size): return 0
31.17 def str_substr(data, start, end, step): return ""
31.18
31.19 # vim: tabstop=4 expandtab shiftwidth=4
32.1 --- a/lplc Mon Feb 04 18:54:14 2019 +0100
32.2 +++ b/lplc Tue Aug 22 19:26:10 2023 +0200
32.3 @@ -3,7 +3,7 @@
32.4 """
32.5 Lichen Python-like compiler tool.
32.6
32.7 -Copyright (C) 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
32.8 +Copyright (C) 2016-2018, 2021 Paul Boddie <paul@boddie.org.uk>
32.9
32.10 This program is free software; you can redistribute it and/or modify it under
32.11 the terms of the GNU General Public License as published by the Free Software
32.12 @@ -151,6 +151,7 @@
32.13 Some options may be followed by values, either immediately after the option
32.14 (without any space between) or in the arguments that follow them:
32.15
32.16 +-j Number of processes to be used when compiling
32.17 -o Indicate the output executable name
32.18 -W Show warnings on the topics indicated
32.19
32.20 @@ -190,8 +191,7 @@
32.21 elif "--version" in args or "-V" in args:
32.22 print >>sys.stderr, """\
32.23 lplc %s
32.24 -Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
32.25 - 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
32.26 +Copyright (C) 2006-2018, 2021 Paul Boddie <paul@boddie.org.uk>
32.27 This program is free software; you may redistribute it under the terms of
32.28 the GNU General Public License version 3 or (at your option) a later version.
32.29 This program has absolutely no warranty.
32.30 @@ -206,6 +206,7 @@
32.31 gc_sections = False
32.32 ignore_env = False
32.33 make = True
32.34 + make_processes = []
32.35 make_verbose = True
32.36 outputs = []
32.37 paramnames = []
32.38 @@ -232,6 +233,7 @@
32.39 elif arg in ("-E", "--no-env"): ignore_env = True
32.40 elif arg in ("-g", "--debug"): debug = True
32.41 elif arg in ("-G", "--gc-sections"): gc_sections = True
32.42 + elif arg.startswith("-j"): l, needed = start_arg_list(make_processes, arg, 1)
32.43 # "P" handled below.
32.44 elif arg.startswith("--param-codes"): l, needed = start_arg_list(paramnames, arg, 1)
32.45 elif arg.startswith("--param-locations"): l, needed = start_arg_list(paramlocations, arg, 1)
32.46 @@ -353,7 +355,8 @@
32.47 # Compile the program unless otherwise indicated.
32.48
32.49 if make:
32.50 - make_clean_cmd = ["make", "-C", generated_dir, "clean"]
32.51 + processes = make_processes and ["-j"] + make_processes or []
32.52 + make_clean_cmd = ["make", "-C", generated_dir] + processes + ["clean"]
32.53 make_cmd = make_clean_cmd[:-1]
32.54
32.55 retval = call(make_cmd, make_verbose)
33.1 --- a/templates/native/buffer.c Mon Feb 04 18:54:14 2019 +0100
33.2 +++ b/templates/native/buffer.c Tue Aug 22 19:26:10 2023 +0200
33.3 @@ -1,6 +1,6 @@
33.4 /* Native functions for buffer operations.
33.5
33.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
33.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
33.8
33.9 This program is free software; you can redistribute it and/or modify it under
33.10 the terms of the GNU General Public License as published by the Free Software
33.11 @@ -30,13 +30,13 @@
33.12 {
33.13 /* _data interpreted as buffer.__data__ */
33.14 __fragment *data = _data.seqvalue;
33.15 - unsigned int size = 0, i, j, n;
33.16 + __int size = 0, i, j, n;
33.17 char *s;
33.18 __attr o;
33.19
33.20 /* Calculate the size of the string. */
33.21 for (i = 0; i < data->size; i++)
33.22 - size += __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__));
33.23 + size += __load_via_object(__VALUE(data->attrs[i]), __size__).sizevalue;
33.24
33.25 /* Reserve space for a new string. */
33.26 s = (char *) __ALLOCATE(size + 1, sizeof(char));
33.27 @@ -45,7 +45,7 @@
33.28 for (i = 0, j = 0; i < data->size; i++)
33.29 {
33.30 o = __load_via_object(__VALUE(data->attrs[i]), __data__);
33.31 - n = __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__));
33.32 + n = __load_via_object(__VALUE(data->attrs[i]), __size__).sizevalue;
33.33 memcpy(s + j, o.strvalue, n); /* does not null terminate but final byte should be zero */
33.34 j += n;
33.35 }
34.1 --- a/templates/native/common.c Mon Feb 04 18:54:14 2019 +0100
34.2 +++ b/templates/native/common.c Tue Aug 22 19:26:10 2023 +0200
34.3 @@ -1,6 +1,6 @@
34.4 /* Common operations for native functions.
34.5
34.6 -Copyright (C) 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
34.7 +Copyright (C) 2016, 2017, 2018, 2021 Paul Boddie <paul@boddie.org.uk>
34.8
34.9 This program is free software; you can redistribute it and/or modify it under
34.10 the terms of the GNU General Public License as published by the Free Software
34.11 @@ -26,12 +26,12 @@
34.12
34.13 /* Utility functions. */
34.14
34.15 -__attr __new_str(char *s, int size)
34.16 +__attr __new_str(char *s, __int size)
34.17 {
34.18 /* Create a new string and mutate the __data__, __size__ and __key__ attributes. */
34.19 - __attr attr = __NEWINSTANCE(__builtins___str_string);
34.20 + __attr attr = __NEWINSTANCE(__builtins___str_str);
34.21 __store_via_object(__VALUE(attr), __data__, (__attr) {.strvalue=s});
34.22 - __store_via_object(__VALUE(attr), __size__, __INTVALUE(size));
34.23 + __store_via_object(__VALUE(attr), __size__, (__attr) {.sizevalue=size});
34.24 __store_via_object(__VALUE(attr), __key__, __NULL);
34.25 return attr;
34.26 }
34.27 @@ -55,8 +55,8 @@
34.28 __fragment *__fragment_append(__fragment *data, __attr value)
34.29 {
34.30 __fragment *newdata = data;
34.31 - unsigned int size = data->size, capacity = data->capacity;
34.32 - unsigned int n;
34.33 + __int size = data->size, capacity = data->capacity;
34.34 + __int n;
34.35
34.36 /* Re-allocate the fragment if the capacity has been reached. */
34.37 if (size >= capacity)
35.1 --- a/templates/native/common.h Mon Feb 04 18:54:14 2019 +0100
35.2 +++ b/templates/native/common.h Tue Aug 22 19:26:10 2023 +0200
35.3 @@ -1,6 +1,6 @@
35.4 /* Common operations for native functions.
35.5
35.6 -Copyright (C) 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
35.7 +Copyright (C) 2016, 2017, 2018, 2021 Paul Boddie <paul@boddie.org.uk>
35.8
35.9 This program is free software; you can redistribute it and/or modify it under
35.10 the terms of the GNU General Public License as published by the Free Software
35.11 @@ -27,7 +27,7 @@
35.12
35.13 /* Utility functions. */
35.14
35.15 -__attr __new_str(char *s, int size);
35.16 +__attr __new_str(char *s, __int size);
35.17 __attr __new_list(__fragment *f);
35.18 __attr __new_float(double n);
35.19 __fragment *__fragment_append(__fragment *data, __attr value);
36.1 --- a/templates/native/iconv.c Mon Feb 04 18:54:14 2019 +0100
36.2 +++ b/templates/native/iconv.c Tue Aug 22 19:26:10 2023 +0200
36.3 @@ -1,6 +1,6 @@
36.4 /* Native functions for character set conversion.
36.5
36.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
36.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
36.8
36.9 This program is free software; you can redistribute it and/or modify it under
36.10 the terms of the GNU General Public License as published by the Free Software
36.11 @@ -56,8 +56,8 @@
36.12 /* Obtain the string, start position, and remaining bytes from the state. */
36.13
36.14 char *inbuf = __load_via_object(__VALUE(f->attrs[0]), __data__).strvalue;
36.15 - int start = __TOINT(f->attrs[1]);
36.16 - int remaining = __TOINT(f->attrs[2]);
36.17 + __int start = __TOINT(f->attrs[1]);
36.18 + __int remaining = __TOINT(f->attrs[2]);
36.19
36.20 /* Allocate a string for the output buffer using the remaining input size
36.21 as a guide. */
37.1 --- a/templates/native/int.c Mon Feb 04 18:54:14 2019 +0100
37.2 +++ b/templates/native/int.c Tue Aug 22 19:26:10 2023 +0200
37.3 @@ -1,6 +1,6 @@
37.4 /* Native functions for integer operations.
37.5
37.6 -Copyright (C) 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
37.7 +Copyright (C) 2016, 2017, 2018, 2021 Paul Boddie <paul@boddie.org.uk>
37.8
37.9 This program is free software; you can redistribute it and/or modify it under
37.10 the terms of the GNU General Public License as published by the Free Software
37.11 @@ -39,8 +39,8 @@
37.12 __attr __fn_native_int_int_add(__attr __self, __attr self, __attr other)
37.13 {
37.14 /* self and other interpreted as int */
37.15 - int i = __TOINT(self);
37.16 - int j = __TOINT(other);
37.17 + __int i = __TOINT(self);
37.18 + __int j = __TOINT(other);
37.19
37.20 /* Test for overflow. */
37.21 if (((i > 0) && (j > 0) && (i > __MAXINT - j)) ||
37.22 @@ -55,8 +55,8 @@
37.23 __attr __fn_native_int_int_sub(__attr __self, __attr self, __attr other)
37.24 {
37.25 /* self and other interpreted as int */
37.26 - int i = __TOINT(self);
37.27 - int j = __TOINT(other);
37.28 + __int i = __TOINT(self);
37.29 + __int j = __TOINT(other);
37.30
37.31 /* Test for overflow. */
37.32 if (((i < 0) && (j > 0) && (i < __MININT + j)) ||
37.33 @@ -71,8 +71,8 @@
37.34 __attr __fn_native_int_int_mul(__attr __self, __attr self, __attr other)
37.35 {
37.36 /* self and other interpreted as int */
37.37 - int i = __TOINT(self);
37.38 - int j = __TOINT(other);
37.39 + __int i = __TOINT(self);
37.40 + __int j = __TOINT(other);
37.41
37.42 /* Test for overflow. */
37.43 if (((i > 0) && (j > 0) && (i > __MAXINT / j)) ||
37.44 @@ -89,8 +89,8 @@
37.45 __attr __fn_native_int_int_div(__attr __self, __attr self, __attr other)
37.46 {
37.47 /* self and other interpreted as int */
37.48 - int i = __TOINT(self);
37.49 - int j = __TOINT(other);
37.50 + __int i = __TOINT(self);
37.51 + __int j = __TOINT(other);
37.52
37.53 /* Test for division by zero or overflow. */
37.54 if (j == 0)
37.55 @@ -105,8 +105,8 @@
37.56 __attr __fn_native_int_int_mod(__attr __self, __attr self, __attr other)
37.57 {
37.58 /* self and other interpreted as int */
37.59 - int i = __TOINT(self);
37.60 - int j = __TOINT(other);
37.61 + __int i = __TOINT(self);
37.62 + __int j = __TOINT(other);
37.63
37.64 /* Test for division by zero or overflow. */
37.65 if (j == 0)
37.66 @@ -121,7 +121,7 @@
37.67 __attr __fn_native_int_int_neg(__attr __self, __attr self)
37.68 {
37.69 /* self interpreted as int */
37.70 - int i = __TOINT(self);
37.71 + __int i = __TOINT(self);
37.72
37.73 /* Test for overflow. */
37.74 if (i == __MININT)
37.75 @@ -134,8 +134,8 @@
37.76 __attr __fn_native_int_int_pow(__attr __self, __attr self, __attr other)
37.77 {
37.78 /* self and other interpreted as int */
37.79 - int i = __TOINT(self);
37.80 - int j = __TOINT(other);
37.81 + __int i = __TOINT(self);
37.82 + __int j = __TOINT(other);
37.83 int k;
37.84
37.85 errno = 0;
37.86 @@ -157,8 +157,8 @@
37.87 __attr __fn_native_int_int_and(__attr __self, __attr self, __attr other)
37.88 {
37.89 /* self and other interpreted as int */
37.90 - int i = __TOINT(self);
37.91 - int j = __TOINT(other);
37.92 + __int i = __TOINT(self);
37.93 + __int j = __TOINT(other);
37.94
37.95 /* Return the new integer. */
37.96 /* NOTE: No overflow test applied. */
37.97 @@ -168,7 +168,7 @@
37.98 __attr __fn_native_int_int_not(__attr __self, __attr self)
37.99 {
37.100 /* self interpreted as int */
37.101 - int i = __TOINT(self);
37.102 + __int i = __TOINT(self);
37.103
37.104 /* Return the new integer. */
37.105 return __new_int(~i);
37.106 @@ -177,8 +177,8 @@
37.107 __attr __fn_native_int_int_or(__attr __self, __attr self, __attr other)
37.108 {
37.109 /* self and other interpreted as int */
37.110 - int i = __TOINT(self);
37.111 - int j = __TOINT(other);
37.112 + __int i = __TOINT(self);
37.113 + __int j = __TOINT(other);
37.114
37.115 /* Return the new integer. */
37.116 /* NOTE: No overflow test applied. */
37.117 @@ -188,8 +188,8 @@
37.118 __attr __fn_native_int_int_xor(__attr __self, __attr self, __attr other)
37.119 {
37.120 /* self and other interpreted as int */
37.121 - int i = __TOINT(self);
37.122 - int j = __TOINT(other);
37.123 + __int i = __TOINT(self);
37.124 + __int j = __TOINT(other);
37.125
37.126 /* Return the new integer. */
37.127 /* NOTE: No overflow test applied. */
37.128 @@ -199,8 +199,8 @@
37.129 __attr __fn_native_int_int_lshift(__attr __self, __attr self, __attr other)
37.130 {
37.131 /* self and other interpreted as int */
37.132 - int i = __TOINT(self);
37.133 - int j = __TOINT(other);
37.134 + __int i = __TOINT(self);
37.135 + __int j = __TOINT(other);
37.136
37.137 /* Return the new integer. */
37.138 /* NOTE: No overflow test applied. */
37.139 @@ -210,8 +210,8 @@
37.140 __attr __fn_native_int_int_rshift(__attr __self, __attr self, __attr other)
37.141 {
37.142 /* self and other interpreted as int */
37.143 - int i = __TOINT(self);
37.144 - int j = __TOINT(other);
37.145 + __int i = __TOINT(self);
37.146 + __int j = __TOINT(other);
37.147
37.148 /* Return the new integer. */
37.149 /* NOTE: No overflow test applied. */
37.150 @@ -221,8 +221,8 @@
37.151 __attr __fn_native_int_int_le(__attr __self, __attr self, __attr other)
37.152 {
37.153 /* self and other interpreted as int */
37.154 - int i = __TOINT(self);
37.155 - int j = __TOINT(other);
37.156 + __int i = __TOINT(self);
37.157 + __int j = __TOINT(other);
37.158
37.159 /* Return a boolean result. */
37.160 return i <= j ? __builtins___boolean_True : __builtins___boolean_False;
37.161 @@ -231,8 +231,8 @@
37.162 __attr __fn_native_int_int_lt(__attr __self, __attr self, __attr other)
37.163 {
37.164 /* self and other interpreted as int */
37.165 - int i = __TOINT(self);
37.166 - int j = __TOINT(other);
37.167 + __int i = __TOINT(self);
37.168 + __int j = __TOINT(other);
37.169
37.170 /* Return a boolean result. */
37.171 return i < j ? __builtins___boolean_True : __builtins___boolean_False;
37.172 @@ -241,8 +241,8 @@
37.173 __attr __fn_native_int_int_ge(__attr __self, __attr self, __attr other)
37.174 {
37.175 /* self and other interpreted as int */
37.176 - int i = __TOINT(self);
37.177 - int j = __TOINT(other);
37.178 + __int i = __TOINT(self);
37.179 + __int j = __TOINT(other);
37.180
37.181 /* Return a boolean result. */
37.182 return i >= j ? __builtins___boolean_True : __builtins___boolean_False;
37.183 @@ -251,8 +251,8 @@
37.184 __attr __fn_native_int_int_gt(__attr __self, __attr self, __attr other)
37.185 {
37.186 /* self and other interpreted as int */
37.187 - int i = __TOINT(self);
37.188 - int j = __TOINT(other);
37.189 + __int i = __TOINT(self);
37.190 + __int j = __TOINT(other);
37.191
37.192 /* Return a boolean result. */
37.193 return i > j ? __builtins___boolean_True : __builtins___boolean_False;
37.194 @@ -261,8 +261,8 @@
37.195 __attr __fn_native_int_int_eq(__attr __self, __attr self, __attr other)
37.196 {
37.197 /* self and other interpreted as int */
37.198 - int i = __TOINT(self);
37.199 - int j = __TOINT(other);
37.200 + __int i = __TOINT(self);
37.201 + __int j = __TOINT(other);
37.202
37.203 /* Return a boolean result. */
37.204 return i == j ? __builtins___boolean_True : __builtins___boolean_False;
37.205 @@ -271,8 +271,8 @@
37.206 __attr __fn_native_int_int_ne(__attr __self, __attr self, __attr other)
37.207 {
37.208 /* self and other interpreted as int */
37.209 - int i = __TOINT(self);
37.210 - int j = __TOINT(other);
37.211 + __int i = __TOINT(self);
37.212 + __int j = __TOINT(other);
37.213
37.214 /* Return a boolean result. */
37.215 return i != j ? __builtins___boolean_True : __builtins___boolean_False;
37.216 @@ -281,14 +281,14 @@
37.217 __attr __fn_native_int_int_str(__attr __self, __attr self)
37.218 {
37.219 /* self interpreted as int */
37.220 - int i = __TOINT(self);
37.221 + __int i = __TOINT(self);
37.222
37.223 /* Employ a buffer big enough to fit the largest integer plus an extra
37.224 character, a minus sign, and the null terminator. */
37.225 unsigned int n = (int) log10(__MAXINT) + 3;
37.226 char *s = (char *) __ALLOCATE(n, sizeof(char));
37.227
37.228 - snprintf(s, n, "%d", i);
37.229 + snprintf(s, n, "%ld", i);
37.230
37.231 /* Return a new string. */
37.232 return __new_str(s, strlen(s));
38.1 --- a/templates/native/io.c Mon Feb 04 18:54:14 2019 +0100
38.2 +++ b/templates/native/io.c Tue Aug 22 19:26:10 2023 +0200
38.3 @@ -1,6 +1,6 @@
38.4 /* Native functions for input/output.
38.5
38.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
38.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
38.8
38.9 This program is free software; you can redistribute it and/or modify it under
38.10 the terms of the GNU General Public License as published by the Free Software
38.11 @@ -120,7 +120,7 @@
38.12 /* fp interpreted as FILE reference */
38.13 FILE *f = (FILE *) fp.datavalue;
38.14 /* size interpreted as int */
38.15 - int to_read = __TOINT(size);
38.16 + size_t to_read = __TOINT(size);
38.17 char buf[to_read];
38.18 size_t have_read;
38.19 int error;
38.20 @@ -150,7 +150,7 @@
38.21 /* str.__data__ interpreted as string */
38.22 char *s = __load_via_object(__VALUE(str), __data__).strvalue;
38.23 /* str.__size__ interpreted as int */
38.24 - int to_write = __TOINT(__load_via_object(__VALUE(str), __size__));
38.25 + size_t to_write = __load_via_object(__VALUE(str), __size__).sizevalue;
38.26 size_t have_written = fwrite(s, sizeof(char), to_write, f);
38.27 int error;
38.28
38.29 @@ -182,7 +182,7 @@
38.30 /* fd interpreted as int */
38.31 int i = __TOINT(fd);
38.32 /* n interpreted as int */
38.33 - int to_read = __TOINT(n);
38.34 + size_t to_read = __TOINT(n);
38.35 char buf[to_read];
38.36 ssize_t have_read;
38.37 char *s;
38.38 @@ -207,7 +207,7 @@
38.39 /* str.__data__ interpreted as string */
38.40 char *s = __load_via_object(__VALUE(str), __data__).strvalue;
38.41 /* str.__size__ interpreted as int */
38.42 - int size = __TOINT(__load_via_object(__VALUE(str), __size__));
38.43 + size_t size = __load_via_object(__VALUE(str), __size__).sizevalue;
38.44 ssize_t have_written;
38.45
38.46 errno = 0;
39.1 --- a/templates/native/list.c Mon Feb 04 18:54:14 2019 +0100
39.2 +++ b/templates/native/list.c Tue Aug 22 19:26:10 2023 +0200
39.3 @@ -1,6 +1,6 @@
39.4 /* Native functions for list operations.
39.5
39.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
39.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
39.8
39.9 This program is free software; you can redistribute it and/or modify it under
39.10 the terms of the GNU General Public License as published by the Free Software
39.11 @@ -30,7 +30,7 @@
39.12 __attr __fn_native_list_list_init(__attr __self, __attr size)
39.13 {
39.14 /* size interpreted as int */
39.15 - unsigned int n = __TOINT(size);
39.16 + __int n = __TOINT(size);
39.17 __attr attr = {.seqvalue=__new_fragment(n)};
39.18
39.19 /* Return the __data__ attribute. */
39.20 @@ -42,7 +42,7 @@
39.21 /* _data interpreted as list.__data__ */
39.22 __fragment *data = _data.seqvalue;
39.23 /* size interpreted as int */
39.24 - unsigned int n = __TOINT(size);
39.25 + __int n = __TOINT(size);
39.26
39.27 data->size = n;
39.28 return __builtins___none_None;
39.29 @@ -66,9 +66,9 @@
39.30 __fragment *data = __load_via_object(__VALUE(self), __data__).seqvalue;
39.31 __fragment *other_data = other.seqvalue;
39.32 __fragment *newdata = data;
39.33 - unsigned int size = data->size, capacity = data->capacity;
39.34 - unsigned int other_size = other_data->size;
39.35 - unsigned int i, j, n = size + other_size;
39.36 + __int size = data->size, capacity = data->capacity;
39.37 + __int other_size = other_data->size;
39.38 + __int i, j, n = size + other_size;
39.39
39.40 /* Re-allocate the fragment if the capacity has been reached. */
39.41 if (n >= capacity)
39.42 @@ -91,7 +91,7 @@
39.43 __attr __fn_native_list_list_len(__attr self, __attr _data)
39.44 {
39.45 /* _data interpreted as list.__data__ */
39.46 - unsigned int size = _data.seqvalue->size;
39.47 + __int size = _data.seqvalue->size;
39.48
39.49 /* Return the new integer. */
39.50 return __new_int(size);
39.51 @@ -107,7 +107,7 @@
39.52 /* _data interpreted as list.__data__ */
39.53 __attr *elements = _data.seqvalue->attrs;
39.54 /* index interpreted as int */
39.55 - int i = __TOINT(index);
39.56 + __int i = __TOINT(index);
39.57
39.58 return elements[i];
39.59 }
39.60 @@ -117,7 +117,7 @@
39.61 /* _data interpreted as list.__data__ */
39.62 __attr *elements = _data.seqvalue->attrs;
39.63 /* index interpreted as int */
39.64 - int i = __TOINT(index);
39.65 + __int i = __TOINT(index);
39.66
39.67 /* Set the element. */
39.68 elements[i] = value;
40.1 --- a/templates/native/locale.c Mon Feb 04 18:54:14 2019 +0100
40.2 +++ b/templates/native/locale.c Tue Aug 22 19:26:10 2023 +0200
40.3 @@ -1,6 +1,6 @@
40.4 /* Native functions for locale handling.
40.5
40.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
40.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
40.8
40.9 This program is free software; you can redistribute it and/or modify it under
40.10 the terms of the GNU General Public License as published by the Free Software
40.11 @@ -43,7 +43,7 @@
40.12
40.13 length = strlen(result);
40.14 out = __ALLOCATE(length + 1, sizeof(char));
40.15 - strncpy(out, result, length);
40.16 + strcpy(out, result);
40.17
40.18 return __new_str(result, length);
40.19 }
40.20 @@ -64,7 +64,7 @@
40.21
40.22 length = strlen(result);
40.23 out = __ALLOCATE(length + 1, sizeof(char));
40.24 - strncpy(out, result, length);
40.25 + strcpy(out, result);
40.26
40.27 return __new_str(result, length);
40.28 }
41.1 --- a/templates/native/str.c Mon Feb 04 18:54:14 2019 +0100
41.2 +++ b/templates/native/str.c Tue Aug 22 19:26:10 2023 +0200
41.3 @@ -1,6 +1,6 @@
41.4 /* Native functions for string operations.
41.5
41.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
41.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
41.8
41.9 This program is free software; you can redistribute it and/or modify it under
41.10 the terms of the GNU General Public License as published by the Free Software
41.11 @@ -33,9 +33,9 @@
41.12 /* _data, other interpreted as string.__data__ */
41.13 char *s = _data.strvalue;
41.14 char *o = other.strvalue;
41.15 - /* _size, othersize interpreted as int */
41.16 - int ss = __TOINT(_size), os = __TOINT(othersize);
41.17 - int n = ss + os;
41.18 + /* _size, othersize interpreted as size */
41.19 + __int ss = _size.sizevalue, os = othersize.sizevalue;
41.20 + __int n = ss + os;
41.21 char *r = (char *) __ALLOCATE(n + 1, sizeof(char));
41.22
41.23 memcpy(r, s, ss);
41.24 @@ -90,7 +90,12 @@
41.25 /* _data interpreted as string.__data__ */
41.26 char *s = _data.strvalue;
41.27
41.28 - return __new_int((unsigned int) s[0]);
41.29 + return __new_int((__int) s[0]);
41.30 +}
41.31 +
41.32 +__attr __fn_native_str_str_size(__attr __self, __attr _size)
41.33 +{
41.34 + return __new_int(_size.sizevalue);
41.35 }
41.36
41.37 __attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step)
41.38 @@ -98,15 +103,15 @@
41.39 /* _data interpreted as string.__data__ */
41.40 char *s = _data.strvalue, *sub;
41.41 /* start interpreted as int */
41.42 - int istart = __TOINT(start);
41.43 + __int istart = __TOINT(start);
41.44 /* end interpreted as int */
41.45 - int iend = __TOINT(end);
41.46 + __int iend = __TOINT(end);
41.47 /* step interpreted as int */
41.48 - int istep = __TOINT(step);
41.49 + __int istep = __TOINT(step);
41.50
41.51 /* Calculate the size of the substring. */
41.52 size_t resultsize = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1;
41.53 - int to, from;
41.54 + size_t to, from;
41.55
41.56 /* Reserve space for a new string. */
41.57 sub = (char *) __ALLOCATE(resultsize + 1, sizeof(char));
42.1 --- a/templates/native/str.h Mon Feb 04 18:54:14 2019 +0100
42.2 +++ b/templates/native/str.h Tue Aug 22 19:26:10 2023 +0200
42.3 @@ -1,6 +1,6 @@
42.4 /* Native functions for string operations.
42.5
42.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
42.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
42.8
42.9 This program is free software; you can redistribute it and/or modify it under
42.10 the terms of the GNU General Public License as published by the Free Software
42.11 @@ -27,6 +27,7 @@
42.12 __attr __fn_native_str_str_gt(__attr __self, __attr _data, __attr other);
42.13 __attr __fn_native_str_str_eq(__attr __self, __attr _data, __attr other);
42.14 __attr __fn_native_str_str_ord(__attr __self, __attr _data);
42.15 +__attr __fn_native_str_str_size(__attr __self);
42.16 __attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step);
42.17
42.18 /* Module initialisation. */
43.1 --- a/templates/native/system.c Mon Feb 04 18:54:14 2019 +0100
43.2 +++ b/templates/native/system.c Tue Aug 22 19:26:10 2023 +0200
43.3 @@ -1,6 +1,6 @@
43.4 /* Native functions for system operations.
43.5
43.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
43.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
43.8
43.9 This program is free software; you can redistribute it and/or modify it under
43.10 the terms of the GNU General Public License as published by the Free Software
44.1 --- a/templates/native/tuple.c Mon Feb 04 18:54:14 2019 +0100
44.2 +++ b/templates/native/tuple.c Tue Aug 22 19:26:10 2023 +0200
44.3 @@ -1,6 +1,6 @@
44.4 /* Native functions for tuple operations.
44.5
44.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
44.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
44.8
44.9 This program is free software; you can redistribute it and/or modify it under
44.10 the terms of the GNU General Public License as published by the Free Software
44.11 @@ -32,7 +32,7 @@
44.12 __attr __fn_native_tuple_tuple_init(__attr __self, __attr size)
44.13 {
44.14 /* size interpreted as int */
44.15 - int n = __TOINT(size);
44.16 + __int n = __TOINT(size);
44.17
44.18 /* Return the __data__ attribute. */
44.19 if (n) return (__attr) {.seqvalue=__new_fragment(n)};
45.1 --- a/templates/native/unicode.c Mon Feb 04 18:54:14 2019 +0100
45.2 +++ b/templates/native/unicode.c Tue Aug 22 19:26:10 2023 +0200
45.3 @@ -1,6 +1,6 @@
45.4 /* Native functions for Unicode operations.
45.5
45.6 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
45.7 +Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
45.8
45.9 This program is free software; you can redistribute it and/or modify it under
45.10 the terms of the GNU General Public License as published by the Free Software
45.11 @@ -39,9 +39,9 @@
45.12 else return 0;
45.13 }
45.14
45.15 -static unsigned int nextpos(char *s, unsigned int size, unsigned int bytestart)
45.16 +static __int nextpos(char *s, __int size, __int bytestart)
45.17 {
45.18 - unsigned int i = bytestart;
45.19 + __int i = bytestart;
45.20
45.21 while (i < size)
45.22 {
45.23 @@ -53,9 +53,9 @@
45.24 return i;
45.25 }
45.26
45.27 -static unsigned int prevpos(char *s, unsigned int bytestart)
45.28 +static __int prevpos(char *s, __int bytestart)
45.29 {
45.30 - unsigned int i = bytestart;
45.31 + __int i = bytestart;
45.32
45.33 while (i > 0)
45.34 {
45.35 @@ -73,9 +73,9 @@
45.36 {
45.37 /* _data interpreted as string.__data__ */
45.38 char *s = _data.strvalue;
45.39 - /* _size interpreted as int */
45.40 - int size = __TOINT(_size);
45.41 - unsigned int i, c = 0;
45.42 + /* _size interpreted as size */
45.43 + __int size = _size.sizevalue;
45.44 + __int i, c = 0;
45.45
45.46 for (i = 0; i < size; i++)
45.47 if (boundary(s[i]))
45.48 @@ -89,9 +89,9 @@
45.49 {
45.50 /* _data interpreted as string.__data__ */
45.51 char *s = _data.strvalue;
45.52 - /* _size interpreted as int */
45.53 - int size = __TOINT(_size);
45.54 - unsigned int i, c = 0, v;
45.55 + /* _size interpreted as size */
45.56 + __int size = _size.sizevalue;
45.57 + __int i, c = 0, v;
45.58
45.59 for (i = 0; i < size; i++)
45.60 {
45.61 @@ -123,21 +123,21 @@
45.62 {
45.63 /* _data interpreted as string.__data__ */
45.64 char *s = _data.strvalue, *sub;
45.65 - /* _size interpreted as int */
45.66 - int ss = __TOINT(_size);
45.67 + /* _size interpreted as size */
45.68 + __int ss = _size.sizevalue;
45.69 /* start interpreted as int */
45.70 - int istart = __TOINT(start);
45.71 + __int istart = __TOINT(start);
45.72 /* end interpreted as int */
45.73 - int iend = __TOINT(end);
45.74 + __int iend = __TOINT(end);
45.75 /* step interpreted as int */
45.76 - int istep = __TOINT(step);
45.77 + __int istep = __TOINT(step);
45.78
45.79 /* Calculate the number of characters. */
45.80 - size_t nchar = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1;
45.81 - unsigned int indexes[nchar];
45.82 + __int nchar = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1;
45.83 + __int indexes[nchar];
45.84
45.85 - unsigned int c, d, i, to, from, lastbyte = 0;
45.86 - int resultsize = 0;
45.87 + __int c, d, i, to, from, lastbyte = 0;
45.88 + __int resultsize = 0;
45.89
45.90 /* Find the indexes of the characters. */
45.91 if (istep > 0)
45.92 @@ -197,7 +197,7 @@
45.93 {
45.94 /* value interpreted as int */
45.95 int i = __TOINT(value);
45.96 - unsigned int resultsize;
45.97 + __int resultsize;
45.98 char *s;
45.99
45.100 if (i < 128) resultsize = 1;
46.1 --- a/templates/progops.c Mon Feb 04 18:54:14 2019 +0100
46.2 +++ b/templates/progops.c Tue Aug 22 19:26:10 2023 +0200
46.3 @@ -1,6 +1,6 @@
46.4 /* Operations depending on program specifics.
46.5
46.6 -Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
46.7 +Copyright (C) 2015-2019, 2021 Paul Boddie <paul@boddie.org.uk>
46.8
46.9 This program is free software; you can redistribute it and/or modify it under
46.10 the terms of the GNU General Public License as published by the Free Software
46.11 @@ -49,7 +49,7 @@
46.12
46.13 /* Generic internal data allocation. */
46.14
46.15 -__fragment *__new_fragment(unsigned int n)
46.16 +__fragment *__new_fragment(__int n)
46.17 {
46.18 /* Allocate space for the list. */
46.19
46.20 @@ -62,9 +62,9 @@
46.21 return data;
46.22 }
46.23
46.24 -void __newdata_sequence(unsigned int number, __fragment *data, __attr args[])
46.25 +void __newdata_sequence(__int number, __fragment *data, __attr args[])
46.26 {
46.27 - unsigned int i;
46.28 + __int i;
46.29
46.30 /* Copy the given number of values. */
46.31
46.32 @@ -74,7 +74,7 @@
46.33 data->size = number;
46.34 }
46.35
46.36 -__attr __newdata_list(unsigned int number, __attr args[])
46.37 +__attr __newdata_list(__int number, __attr args[])
46.38 {
46.39 __attr self = __NEWINSTANCE(__builtins___list_list);
46.40 __fragment *data = __new_fragment(number);
46.41 @@ -86,7 +86,7 @@
46.42 return self;
46.43 }
46.44
46.45 -__attr __newdata_tuple(unsigned int number, __attr args[])
46.46 +__attr __newdata_tuple(__int number, __attr args[])
46.47 {
46.48 /* Allocate the tuple and fragment together. */
46.49
46.50 @@ -103,7 +103,7 @@
46.51 }
46.52
46.53 #ifdef __HAVE___builtins___dict_dict
46.54 -__attr __newdata_dict(unsigned int number, __attr args[])
46.55 +__attr __newdata_dict(__int number, __attr args[])
46.56 {
46.57 __attr self = __NEWINSTANCE(__builtins___dict_dict);
46.58
46.59 @@ -171,6 +171,13 @@
46.60 __Raise(__new___builtins___core_UnderflowError(__NULL));
46.61 }
46.62
46.63 +void __raise_value_error(__attr value)
46.64 +{
46.65 +#ifdef __HAVE___builtins___exception_base_ValueError
46.66 + __Raise(__new___builtins___exception_base_ValueError(__NULL, value));
46.67 +#endif /* __HAVE___builtins___exception_base_ValueError */
46.68 +}
46.69 +
46.70 void __raise_zero_division_error()
46.71 {
46.72 __Raise(__new___builtins___core_ZeroDivisionError(__NULL));
46.73 @@ -316,10 +323,11 @@
46.74 {
46.75 __ref value;
46.76
46.77 - /* Integers can be used directly as truth values. */
46.78 + /* Non-zero integers yield a non-zero result. Since the integer type can be
46.79 + larger than int, a conversion is performed. */
46.80
46.81 if (__INTEGER(attr))
46.82 - return __TOINT(attr);
46.83 + return __TOINT(attr) ? 1 : 0;
46.84
46.85 /* Test against True and False explicitly. If necessary, invoke the bool
46.86 function with the object and test against True. */
47.1 --- a/templates/progops.h Mon Feb 04 18:54:14 2019 +0100
47.2 +++ b/templates/progops.h Tue Aug 22 19:26:10 2023 +0200
47.3 @@ -1,6 +1,6 @@
47.4 /* Operations depending on program specifics.
47.5
47.6 -Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
47.7 +Copyright (C) 2015-2019, 2021 Paul Boddie <paul@boddie.org.uk>
47.8
47.9 This program is free software; you can redistribute it and/or modify it under
47.10 the terms of the GNU General Public License as published by the Free Software
47.11 @@ -31,10 +31,10 @@
47.12
47.13 /* Generic internal data allocation. */
47.14
47.15 -__fragment *__new_fragment(unsigned int n);
47.16 +__fragment *__new_fragment(__int n);
47.17
47.18 -__attr __newdata_list(unsigned int number, __attr args[]);
47.19 -__attr __newdata_tuple(unsigned int number, __attr args[]);
47.20 +__attr __newdata_list(__int number, __attr args[]);
47.21 +__attr __newdata_tuple(__int number, __attr args[]);
47.22
47.23 #define __newliteral___builtins___list_list(NUM, ...) __newdata_list(NUM, __ARGS(__VA_ARGS__))
47.24 #define __newliteral___builtins___tuple_tuple(NUM, ...) __newdata_tuple(NUM, __ARGS(__VA_ARGS__))
47.25 @@ -42,7 +42,7 @@
47.26 /* Potentially superfluous operations. */
47.27
47.28 #ifdef __HAVE___builtins___dict_dict
47.29 -__attr __newdata_dict(unsigned int number, __attr args[]);
47.30 +__attr __newdata_dict(__int number, __attr args[]);
47.31 #define __newliteral___builtins___dict_dict(NUM, ...) __newdata_dict(NUM, __ARGS(__VA_ARGS__))
47.32 #endif
47.33
47.34 @@ -56,6 +56,7 @@
47.35 void __raise_overflow_error();
47.36 void __raise_unbound_method_error();
47.37 void __raise_underflow_error();
47.38 +void __raise_value_error(__attr value);
47.39 void __raise_zero_division_error();
47.40 void __raise_type_error();
47.41
48.1 --- a/templates/types.h Mon Feb 04 18:54:14 2019 +0100
48.2 +++ b/templates/types.h Tue Aug 22 19:26:10 2023 +0200
48.3 @@ -1,6 +1,6 @@
48.4 /* Runtime types.
48.5
48.6 -Copyright (C) 2015, 2016, 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
48.7 +Copyright (C) 2015-2019, 2021 Paul Boddie <paul@boddie.org.uk>
48.8
48.9 This program is free software; you can redistribute it and/or modify it under
48.10 the terms of the GNU General Public License as published by the Free Software
48.11 @@ -23,6 +23,7 @@
48.12 program specifically. */
48.13
48.14 #include <stdint.h>
48.15 +#include <stdlib.h>
48.16
48.17 /* Include the special instance position value. The pos member of __obj refers
48.18 to the special type attribute for classes, indicating which position holds
48.19 @@ -70,12 +71,18 @@
48.20 typedef union __attr __attr;
48.21 typedef __obj * __ref;
48.22
48.23 +/* Introduce an integer type that is interoperable with the size type. */
48.24 +
48.25 +typedef ssize_t __int;
48.26 +
48.27 +/* Attribute value interpretations. */
48.28 +
48.29 typedef union __attr
48.30 {
48.31 /* General attribute members. */
48.32
48.33 __ref value; /* attribute value */
48.34 - int intvalue; /* integer value data (shifted value, tagged) */
48.35 + __int intvalue; /* integer value data (shifted value, tagged) */
48.36
48.37 /* Special case attribute members. */
48.38
48.39 @@ -88,6 +95,7 @@
48.40 char * strvalue; /* string value */
48.41 __fragment * seqvalue; /* sequence data */
48.42 void * datavalue; /* object-specific data */
48.43 + __int sizevalue; /* object-specific size */
48.44 } __attr;
48.45
48.46 typedef struct __obj
48.47 @@ -109,17 +117,18 @@
48.48
48.49 typedef struct __fragment
48.50 {
48.51 - unsigned int size, capacity;
48.52 + __int size, capacity;
48.53 __attr attrs[];
48.54 } __fragment;
48.55
48.56 -#define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(unsigned int))
48.57 +#define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(__int))
48.58
48.59 /* Attribute interpretation. */
48.60
48.61 -#define __NUM_TAG_BITS 1
48.62 -#define __TAG_INT 0b1
48.63 -#define __INTEGER(ATTR) ((ATTR).intvalue & __TAG_INT)
48.64 +#define __NUM_TAG_BITS 2
48.65 +#define __TAG_INT 0b01
48.66 +#define __TAG_MASK 0b11
48.67 +#define __INTEGER(ATTR) (((ATTR).intvalue & __TAG_MASK) == __TAG_INT)
48.68
48.69 /* Attribute value setting. */
48.70
48.71 @@ -129,10 +138,10 @@
48.72
48.73 /* Attribute as instance setting. */
48.74
48.75 -#define __INTVALUE(VALUE) ((__attr) {.intvalue=((VALUE) << __NUM_TAG_BITS) | __TAG_INT})
48.76 +#define __INTVALUE(VALUE) ((__attr) {.intvalue=(((__int) VALUE) << __NUM_TAG_BITS) | __TAG_INT})
48.77 #define __TOINT(ATTR) ((ATTR).intvalue >> __NUM_TAG_BITS)
48.78 -#define __MAXINT ((1 << ((sizeof(__attr) * 8) - 1 - __NUM_TAG_BITS)) - 1)
48.79 -#define __MININT (-(1 << ((sizeof(__attr) * 8) - 1 - __NUM_TAG_BITS)))
48.80 +#define __MAXINT ((((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)) - 1)
48.81 +#define __MININT (-(((__int) 1) << ((sizeof(__int) * 8) - 1 - __NUM_TAG_BITS)))
48.82
48.83 /* Argument lists. */
48.84
49.1 --- a/test_all.sh Mon Feb 04 18:54:14 2019 +0100
49.2 +++ b/test_all.sh Tue Aug 22 19:26:10 2023 +0200
49.3 @@ -3,7 +3,7 @@
49.4 # This tool runs the toolchain for each of the tests, optionally building and
49.5 # running the test programs.
49.6 #
49.7 -# Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
49.8 +# Copyright (C) 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
49.9 #
49.10 # This program is free software; you can redistribute it and/or modify it under
49.11 # the terms of the GNU General Public License as published by the Free Software
49.12 @@ -20,6 +20,8 @@
49.13
49.14 PROGNAME=$0
49.15 OPTION=$1
49.16 +shift 1
49.17 +MAKE_OPTIONS="$*"
49.18
49.19 LPLC="./lplc"
49.20 DATADIR="_main.lplc"
49.21 @@ -53,7 +55,7 @@
49.22
49.23 if [ "$OPTION" = '--help' ] ; then
49.24 cat 1>&2 <<EOF
49.25 -Usage: $0 [ --build | --build-only | --run-built ]
49.26 +Usage: $0 [ --build | --build-only | --run-built ] [ <make options> ]
49.27
49.28 Run the toolchain over all tests in the tests directory.
49.29
49.30 @@ -87,6 +89,11 @@
49.31 Build and output logs are stored in the _results directory with the .build and
49.32 .out suffixes employed respectively, one of each kind for each generated
49.33 program.
49.34 +
49.35 +The make options can be used to specify things like the number of processes
49.36 +employed to perform a build of each program. For example:
49.37 +
49.38 +$PROGNAME --build -j8
49.39 EOF
49.40 exit 1
49.41 fi
49.42 @@ -193,7 +200,7 @@
49.43
49.44 echo " (build)..." 1>&2
49.45 if ! make -C "$DATADIR/_generated" clean > "$BUILDLOG" 2>&1 || \
49.46 - ! make -C "$DATADIR/_generated" > "$BUILDLOG" 2>&1 ; then
49.47 + ! make -C "$DATADIR/_generated" $MAKE_OPTIONS > "$BUILDLOG" 2>&1 ; then
49.48 exit 1
49.49 fi
49.50
50.1 --- a/tests/identity.py Mon Feb 04 18:54:14 2019 +0100
50.2 +++ b/tests/identity.py Tue Aug 22 19:26:10 2023 +0200
50.3 @@ -1,7 +1,7 @@
50.4 -print isinstance("string", string) # True
50.5 +print isinstance("string", str) # True
50.6 print isinstance("string", int) # False
50.7 print isinstance(123, int) # True
50.8 -print isinstance(123, string) # False
50.9 +print isinstance(123, str) # False
50.10 print
50.11
50.12 class A:
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
51.2 +++ b/tests/int.py Tue Aug 22 19:26:10 2023 +0200
51.3 @@ -0,0 +1,30 @@
51.4 +i = int(123)
51.5 +j = 123
51.6 +print i, j, i == j # 123 123 True
51.7 +k = 456
51.8 +print i, k, i == k # 123 456 False
51.9 +h = int(789)
51.10 +print i, h, i == h # 123 789 False
51.11 +print j, h, j == h # 123 789 False
51.12 +
51.13 +try:
51.14 + a = int("a") # should raise an exception
51.15 +except ValueError, exc:
51.16 + print 'int("a") failed:', exc.value
51.17 +
51.18 +try:
51.19 + a = int("!") # should raise an exception
51.20 +except ValueError, exc:
51.21 + print 'int("!") failed:', exc.value
51.22 +
51.23 +a = int("a", 16)
51.24 +b = int("123")
51.25 +print a # 10
51.26 +print b, i, b == i # 123, 123, True
51.27 +print b, j, b == j # 123, 123, True
51.28 +
51.29 +a_is_int = isinstance(a, int)
51.30 +j_is_int = isinstance(j, int)
51.31 +
51.32 +print a_is_int # True
51.33 +print j_is_int # True
52.1 --- a/tests/numbers.py Mon Feb 04 18:54:14 2019 +0100
52.2 +++ b/tests/numbers.py Tue Aug 22 19:26:10 2023 +0200
52.3 @@ -18,7 +18,7 @@
52.4 j = -2 ** 29
52.5 print j # -536870912
52.6 print hex(j) # -0x20000000
52.7 -print oct(j) # -05000000000
52.8 +print oct(j) # -04000000000
52.9
52.10 print i + j # 0
52.11
53.1 --- a/tests/unicode.py Mon Feb 04 18:54:14 2019 +0100
53.2 +++ b/tests/unicode.py Tue Aug 22 19:26:10 2023 +0200
53.3 @@ -18,37 +18,37 @@
53.4 s2 = b"\xe6\xf8\xe5"
53.5 print "ISO-8859-15 values:"
53.6 print s2 # זרו
53.7 -print s2.__class__ # __builtins__.str.string
53.8 +print s2.__class__ # __builtins__.str.str
53.9 print len(s2) # 3
53.10
53.11 s3 = "\xe6\xf8\xe5"
53.12 print "ISO-8859-15 values:"
53.13 print s3 # זרו
53.14 -print s3.__class__ # __builtins__.str.string
53.15 +print s3.__class__ # __builtins__.str.str
53.16 print len(s3) # 3
53.17
53.18 s4 = b"\u00e6\u00f8\u00e5"
53.19 print "Untranslated values:"
53.20 print s4 # \u00e6\u00f8\u00e5
53.21 -print s4.__class__ # __builtins__.str.string
53.22 +print s4.__class__ # __builtins__.str.str
53.23 print len(s4) # 18
53.24
53.25 s5 = b"\346\370\345"
53.26 print "ISO-8859-15 values:"
53.27 print s5 # זרו
53.28 -print s5.__class__ # __builtins__.str.string
53.29 +print s5.__class__ # __builtins__.str.str
53.30 print len(s5) # 3
53.31
53.32 s6 = "\346\370\345"
53.33 print "ISO-8859-15 values:"
53.34 print s6 # זרו
53.35 -print s6.__class__ # __builtins__.str.string
53.36 +print s6.__class__ # __builtins__.str.str
53.37 print len(s6) # 3
53.38
53.39 s7 = r"\346\370\345"
53.40 print "Untranslated values:"
53.41 print s7 # \346\370\345
53.42 -print s7.__class__ # __builtins__.unicode.utf8string
53.43 +print s7.__class__ # __builtins__.unicode.unicode
53.44 print len(s7) # 12
53.45
53.46 # Obtain text and print it.
53.47 @@ -58,7 +58,7 @@
53.48 u = unicode(b"זרו", "ISO-8859-15")
53.49 print "Unicode values:"
53.50 print u # זרו
53.51 -print u.__class__ # __builtins__.unicode.utf8string
53.52 +print u.__class__ # __builtins__.unicode.unicode
53.53 print u.encode("ISO-8859-15") # זרו
53.54 print u.encoding # ISO-8859-15
53.55 print len(u) # 3
53.56 @@ -68,7 +68,7 @@
53.57 u2 = u"זרו"
53.58 print "Unicode values:"
53.59 print u2 # זרו
53.60 -print u2.__class__ # __builtins__.unicode.utf8string
53.61 +print u2.__class__ # __builtins__.unicode.unicode
53.62 print u2.encode("ISO-8859-15") # זרו
53.63 print u2.encoding # ISO-8859-15
53.64 print len(u2) # 3
53.65 @@ -78,7 +78,7 @@
53.66 u3 = "זרו"
53.67 print "Unicode values:"
53.68 print u3 # זרו
53.69 -print u3.__class__ # __builtins__.unicode.utf8string
53.70 +print u3.__class__ # __builtins__.unicode.unicode
53.71 print u3.encode("ISO-8859-15") # זרו
53.72 print u3.encoding # ISO-8859-15
53.73 print len(u3) # 3
53.74 @@ -88,7 +88,7 @@
53.75 u4 = unicode("זרו", "ISO-8859-15")
53.76 print "Unicode values:"
53.77 print u4 # זרו
53.78 -print u4.__class__ # __builtins__.unicode.utf8string
53.79 +print u4.__class__ # __builtins__.unicode.unicode
53.80 print u4.encode("ISO-8859-15") # זרו
53.81 print u4.encoding # ISO-8859-15
53.82 print len(u4) # 3
53.83 @@ -98,7 +98,7 @@
53.84 u5 = "\u00e6\u00f8\u00e5"
53.85 print "Unicode values:"
53.86 print u5 # זרו
53.87 -print u5.__class__ # __builtins__.unicode.ut8string
53.88 +print u5.__class__ # __builtins__.unicode.unicode
53.89 print len(u5) # 3
53.90
53.91 # Test some untranslated values.
53.92 @@ -106,7 +106,7 @@
53.93 u6 = "\\u00e6\\u00f8\\u00e5"
53.94 print "Untranslated values:"
53.95 print u6 # \u00e6\u00f8\u00e5
53.96 -print u6.__class__ # __builtins__.unicode.ut8string
53.97 +print u6.__class__ # __builtins__.unicode.unicode
53.98 print len(u6) # 18
53.99
53.100 # Test Unicode values.
53.101 @@ -114,7 +114,7 @@
53.102 u7 = u"\346\370\345"
53.103 print "Unicode values:"
53.104 print u7 # זרו
53.105 -print u7.__class__ # __builtins__.unicode.ut8string
53.106 +print u7.__class__ # __builtins__.unicode.unicode
53.107 print len(u7) # 3
53.108
53.109 # Test Unicode values.
53.110 @@ -122,7 +122,7 @@
53.111 u8 = ur"\346\370\345"
53.112 print "Untranslated values:"
53.113 print u8 # \346\370\345
53.114 -print u8.__class__ # __builtins__.unicode.ut8string
53.115 +print u8.__class__ # __builtins__.unicode.unicode
53.116 print len(u8) # 12
53.117
53.118 # Test invalid sequences.
53.119 @@ -137,7 +137,7 @@
53.120 u10 = "\u00e6\xf8\u00e5"
53.121 print "ISO-8859-15 values:"
53.122 print u10 # \u00e6ר\u00e5
53.123 -print u10.__class__ # __builtins__.str.string
53.124 +print u10.__class__ # __builtins__.str.str
53.125 print len(u10) # 13
53.126
53.127 # Combine bytes and text.
53.128 @@ -146,7 +146,7 @@
53.129 su = s + u
53.130 print "ISO-8859-15 values:"
53.131 print su # ֶ״ֵזרו
53.132 -print su.__class__ # __builtins__.str.string
53.133 +print su.__class__ # __builtins__.str.str
53.134 print len(su) # 6
53.135
53.136 # Combine text and bytes.
53.137 @@ -155,7 +155,7 @@
53.138 us = u + s
53.139 print "ISO-8859-15 values:"
53.140 print us # זרוֶ״ֵ
53.141 -print us.__class__ # __builtins__.str.string
53.142 +print us.__class__ # __builtins__.str.str
53.143 print len(us) # 6
53.144
53.145 # Combine text and text.
53.146 @@ -163,7 +163,7 @@
53.147 uu2 = u + u2
53.148 print "Unicode values:"
53.149 print uu2 # זרוזרו
53.150 -print uu2.__class__ # __builtins__.unicode.utf8string
53.151 +print uu2.__class__ # __builtins__.unicode.unicode
53.152 print uu2.encoding # ISO-8859-15
53.153 print len(uu2) # 6
53.154
53.155 @@ -195,7 +195,7 @@
53.156 # Test character access.
53.157
53.158 u0 = u[0]
53.159 -print u0.__class__ # __builtins__.unicode.utf8string
53.160 +print u0.__class__ # __builtins__.unicode.unicode
53.161 print u0.encoding # ISO-8859-15
53.162 print u0 # ז
53.163 print u[-1] # ו