git @ Cat's Eye Technologies Eightebed / rel_1_1_2021_0621
Merge pull request #1 from catseye/support-python-3 Support Python 3 Chris Pressey authored 2 years ago GitHub committed 2 years ago
11 changed file(s) with 72 addition(s) and 88 deletion(s). Raw diff Collapse all Expand all
0 __pycache__
1 *.pyc
2 a.out
3 *.c
+0
-4
.hgignore less more
0 syntax: glob
1
2 *.pyc
3
+0
-3
.hgtags less more
0 4938a2222c2250779560047a61cfa7ad11dc03e8 rel_1_1_2011_0510
1 3bd7e4328239a60da67ae0382394c8c7da33a582 rel_1_1_2012_0623
2 9d2a2d1cf4b1ab59adf6a511c609e20c8d0a6ff0 rel_1_1_2014_0819
0 Eightebed is distributed under the following, BSD-compatible licenses.
0 BSD 3-Clause License
11
2 All documentation is covered by this license, modelled after the
3 "Report on the Programming Language Haskell 98" license:
4
5 -----------------------------------------------------------------------------
6
7 Copyright (c)2010-2012 Chris Pressey, Cat's Eye Technologies.
8 All rights reserved.
9
10 The authors intend this Report to belong to the entire Eightebed
11 community, and so we grant permission to copy and distribute it for
12 any purpose, provided that it is reproduced in its entirety,
13 including this Notice. Modified versions of this Report may also be
14 copied and distributed for any purpose, provided that the modified
15 version is clearly presented as such, and that it does not claim to
16 be a definition of the Eightebed Programming Language.
17
18 -----------------------------------------------------------------------------
19
20 All source code for the reference implementation, except the `rooibos`
21 module, is covered by this license:
22
23 -----------------------------------------------------------------------------
24
25 Copyright (c)2010-2012 Chris Pressey, Cat's Eye Technologies.
2 Copyright (c) 2010-2021, Chris Pressey, Cat's Eye Technologies.
263 All rights reserved.
274
285 Redistribution and use in source and binary forms, with or without
29 modification, are permitted provided that the following conditions
30 are met:
6 modification, are permitted provided that the following conditions are met:
317
32 1. Redistributions of source code must retain the above copyright
33 notices, this list of conditions and the following disclaimer.
34 2. Redistributions in binary form must reproduce the above copyright
35 notices, this list of conditions, and the following disclaimer in
36 the documentation and/or other materials provided with the
37 distribution.
38 3. Neither the names of the copyright holders nor the names of their
39 contributors may be used to endorse or promote products derived
40 from this software without specific prior written permission.
8 * Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
4110
42 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
45 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
46 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
47 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
48 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
52 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53 POSSIBILITY OF SUCH DAMAGE.
11 * Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
5414
55 -----------------------------------------------------------------------------
15 * Neither the name of the copyright holder nor the names of its
16 contributors may be used to endorse or promote products derived from
17 this software without specific prior written permission.
5618
57 The `rooibos` module is a work by Chris Pressey, placed into the public
58 domain.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
172172 ------------------------
173173
174174 Cat's Eye Technologies provides a cockamamie reference implementation of
175 Eightebed called `8ebed2c.py`. Written in Python 2.6, it compiles
175 Eightebed called `8ebed2c.py`. Written in Python 2.7 or 3.6, it compiles
176176 Eightebed code to C, and for convenience will optionally compile that C
177177 with the C compiler of your choice and run the resulting executable.
178178
55 (in.8ebed|@testprog) (out.c|-)
66
77 8ebed2c.py: A compiler (to C) for the Eightebed programming language.
8 Language version 1.1. Implementation version 2011.0510.
8 Language version 1.1. Implementation version 2021.0621.
99
1010 The @testprog syntax can be used to acquire input from the
1111 specified attribute of the Tests class of the tests module.
8787 infilename = args[0]
8888 outfilename = args[1]
8989 except IndexError:
90 print "Usage:", __doc__, "\n"
91 print "Run with the -h option to see a list of all options."
90 print("Usage: {}\n".format(__doc__))
91 print("Run with the -h option to see a list of all options.")
9292 sys.exit(1)
9393 parse_and_gen(options, infilename, outfilename, tests=tests.Tests)
9494 if options.compile:
1111 """
1212 >>> d = Context({ 'a': 2, 'b': 3 })
1313 >>> e = Context({ 'c': 4 }, parent=d)
14 >>> print e.lookup('c')
14 >>> e.lookup('c')
1515 4
16 >>> print e.lookup('b')
16 >>> e.lookup('b')
1717 3
18 >>> print e.lookup('e', None)
19 None
20 >>> print e.lookup('e')
18 >>> e.lookup('e', None) is None
19 True
20 >>> e.lookup('e')
2121 Traceback (most recent call last):
2222 ...
2323 KeyError: 'e'
2424 >>> d.declare('d', 7)
25 >>> print e.lookup('d')
25 >>> e.lookup('d')
2626 7
2727 >>> d.declare('b', 4)
2828 Traceback (most recent call last):
3333 ...
3434 KeyError: 'b already declared'
3535 >>> e.empty()
36 >>> print e.lookup('c', None)
37 None
38 >>> print d.lookup('a', None)
39 None
36 >>> e.lookup('c', None) is None
37 True
38 >>> d.lookup('a', None) is None
39 True
4040
4141 """
4242
5555 output = Popen([options.compiler, filename], stdout=PIPE).communicate()[0]
5656 if options.verbose:
5757 sys.stdout.write(output)
58 if output != '':
58 if output not in ('', b''):
5959 raise RuntimeError("Compilation failed!")
6060 if options.run:
6161 logger.info("Running...")
6262 output = Popen([a_out], stdout=PIPE).communicate()[0]
63 try:
64 # Python 2
65 output = unicode(output).encode('ascii')
66 except NameError:
67 # Python 3
68 output = output.decode('ascii')
6369 if options.clean:
6470 os.remove(filename)
6571 os.remove(a_out)
8490
8591 def cmdline(options):
8692 cmd = ""
87 print "Eightebed interactive! Type 'quit' to quit."
93 print("Eightebed interactive! Type 'quit' to quit.")
8894 options.run = True
8995 options.clean = True
9096 while True:
96102 ast = parse_and_check(cmd, options=options)
97103 result = load_and_go(ast, options=options)
98104 sys.stdout.write(result)
99 except Exception, e:
100 print "Exception!", repr(e)
105 except Exception as e:
106 print("Exception!", repr(e))
5151 def peek(self):
5252 if not self.buffer:
5353 try:
54 self.buffer.append(self.generator.next())
54 self.buffer.append(next(self.generator))
5555 except StopIteration:
5656 return None
5757 return self.buffer[0]
5858
5959 def advance(self):
6060 if not self.buffer:
61 self.buffer.extend(self.generator.next())
61 self.buffer.extend(next(self.generator))
6262 self.buffer.pop()
6363
6464
464464
465465 def __getitem__(self, key):
466466 if self.trace:
467 print "Reading production ", key
467 print("Reading production ", key)
468468 if key in self.productions:
469469 return self.productions[key]
470470 elif self.parent:
33 """
44 Test suite for (Python implementations of) the Eightebed programming language.
55 """
6
7
8 def expect_type_error(fun):
9 from .parser import TypeError
10 try:
11 fun()
12 except TypeError as e:
13 print('Traceback (most recent call last):')
14 print('...')
15 print('TypeError: {}'.format(e))
616
717
818 class Tests(object):
2636 ...
2737 KeyError: 'jim already declared'
2838
29 >>> parse_and_check(Tests.ptr_to_ptr)
39 >>> expect_type_error(lambda: parse_and_check(Tests.ptr_to_ptr))
3040 Traceback (most recent call last):
3141 ...
3242 TypeError: Pointer type must point to named type
3343
34 >>> parse_and_check(Tests.ptr_to_int)
44 >>> expect_type_error(lambda: parse_and_check(Tests.ptr_to_int))
3545 Traceback (most recent call last):
3646 ...
3747 TypeError: Pointer type must point to named type
3848
39 >>> parse_and_check(Tests.struct_within_struct)
49 >>> expect_type_error(lambda: parse_and_check(Tests.struct_within_struct))
4050 Traceback (most recent call last):
4151 ...
4252 TypeError: Structs may not contain other structs
4353
44 >>> parse_and_check(Tests.named_int)
54 >>> expect_type_error(lambda: parse_and_check(Tests.named_int))
4555 Traceback (most recent call last):
4656 ...
4757 TypeError: Only structs may be named
4858
49 >>> parse_and_check(Tests.dereference_outside_conditional)
59 >>> expect_type_error(lambda: parse_and_check(Tests.dereference_outside_conditional))
5060 Traceback (most recent call last):
5161 ...
5262 TypeError: Attempt to dereference jim in non-safe context
5363
54 >>> parse_and_check(Tests.dereference_outside_safe_area)
64 >>> expect_type_error(lambda: parse_and_check(Tests.dereference_outside_safe_area))
5565 Traceback (most recent call last):
5666 ...
5767 TypeError: Attempt to dereference jim in non-safe context
6070 >>> p is None
6171 False
6272
63 >>> parse_and_check(Tests.dereference_after_free)
73 >>> expect_type_error(lambda: parse_and_check(Tests.dereference_after_free))
6474 Traceback (most recent call last):
6575 ...
6676 TypeError: Attempt to dereference jim in non-safe context
0 #!/bin/sh
0 #!/bin/sh -x
11
2 src/8ebed2c.py -t -v
2 python2 src/8ebed2c.py -t || exit 1
3 python3 src/8ebed2c.py -t || exit 1