Establish an `include` directory and `--include-path` option.

This commit is contained in:
Chris Pressey 2019-10-22 15:10:55 +01:00
parent c70e4a55e4
commit d408e740ed
25 changed files with 75 additions and 42 deletions

View File

@ -4,23 +4,26 @@ History of SixtyPical
0.21
----
* A source file can be included in another source file
by means of the `include` directive.
* A routine can be declared `preserved`, which prevents a
compiler from omitting it from the final executable, even
if it determines it is not called by any other routine.
* The reference implementation constructs a callgraph and
determines the set of routines which are not reachable
(directly or indirectly) from `main`, with an eye to
omitting them from the final executable.
* A routine can be declared `preserved`, which prevents a
compiler from omitting it from the final executable, even
if it determines it is not called by any other routine.
* Added `--prune-unreachable-routines` option, which causes
the compiler to in fact omit routines determined to be
unreachable as described above.
* Added `--include-path` option, which configures the list
of directories that are searched when a source file is
included with the `include` directive.
* Code generation now performs modest peephole optimization
at the end of each routine. This results in better code
generation for constructs in tail position, notably
tail optimization of `calls`, but also for `goto`s and
`if` blocks at the end of a routine.
* The `dcc6502-adapter` test adapter was updated to conform
to the output of the latest version of `dcc6502`.
0.20
----

View File

@ -31,14 +31,6 @@ For goodness sake, let the programmer say `'A'` instead of `65`.
Not all computers think `'A'` should be `65`. Allow the character set to be
mapped. Probably copy what Ophis does.
### "Include" directives
Search a searchlist of include paths. And use them to make libraries of routines.
One such library routine might be an `interrupt routine` type for various architectures.
Since "the supervisor" has stored values on the stack, we should be able to trash them
with impunity, in such a routine.
### Pointers into non-byte tables
Right now you cannot get a pointer into a non-byte (for instance, word or vector) table.

View File

@ -26,11 +26,12 @@ from sixtypical.compiler import Compiler
def process_input_files(filenames, options):
symtab = SymbolTable()
include_path = options.include_path.split(':')
programs = []
for filename in options.filenames:
program = load_program(filename, symtab)
program = load_program(filename, symtab, include_path)
if options.debug:
print(symtab)
programs.append(program)
@ -137,6 +138,12 @@ if __name__ == '__main__':
"Default: raw."
)
argparser.add_argument(
"--include-path", "-I", type=str, metavar='PATH', default='.',
help="A colon-separated list of directories in which to look for "
"files which are included during `include` directives."
)
argparser.add_argument(
"--analyze-only",
action="store_true",

View File

@ -3,11 +3,18 @@ in subdirectories by machine architecture.
### rudiments
In the [rudiments](rudiments/) directory are programs which are not for
any particular machine, but meant to demonstrate the features of SixtyPical.
Some are meant to fail and produce an error message. Others can run on
any architecture where there is a routine at 65490 which outputs the value
of the accumulator as an ASCII character.
In the [rudiments](rudiments/) directory are programs which are
meant to demonstrate the elementary features of SixtyPical, and
to serve as manual integration test cases.
These sources are portable across architectures. They include
architecture-dependent libraries to produce output. Libraries
for such are provided in the `include` directory in the root
directory of the repository; make it is on the compiler's include
search path.
Some others of these sources are meant to fail and produce an error
message when compiled.
### c64

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print YY
include "chrout.60p"
word score
define main routine

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print Y
include "chrout.60p"
byte table[2048] buf
pointer ptr @ 254
byte foo

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print AA
include "chrout.60p"
define print routine
trashes a, z, n
{

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print ENGGL
include "chrout.60p"
byte b
define main routine

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print ENGGL
include "chrout.60p"
word w1
define main routine

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print ENGGL
include "chrout.60p"
word w1
word w2

View File

@ -1,7 +1,7 @@
// Demonstrates vector tables.
// Include `support/${PLATFORM}.60p` before this source
// Should print YN
include "chrout.60p"
define main routine
trashes a, x, y, z, n, c, v
{

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print YA
include "chrout.60p"
define main routine
trashes a, x, y, z, n, c, v
{

View File

@ -1,6 +1,8 @@
// Include `support/${PLATFORM}.60p` and `support/stdlib.60p` before this source
// Should print 01
include "chrout.60p"
include "prbyte.60p"
byte lives
define main routine

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print AB
include "chrout.60p"
define bar routine trashes a, z, n {
ld a, 66
call chrout

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print ABCDEFGHIJKLMNOPQRSTUVWXYZ
include "chrout.60p"
define main routine
trashes a, y, z, n, c
{

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print AB
include "chrout.60p"
byte foo
define print routine

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print H (being ASCII 72 = 8 * 9)
include "chrout.60p"
// Increase y by 7, circuitously
//
define foo routine

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print A
include "chrout.60p"
define main routine
inputs a
trashes a, z, n

View File

@ -1,7 +1,9 @@
// Demonstrates vector tables.
// Include `support/${PLATFORM}.60p` before this source
// Should print AABAB
// Demonstrates vector tables.
include "chrout.60p"
vector routine
trashes a, z, n
print

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print AB
include "chrout.60p"
vector routine
trashes a, z, n
print

View File

@ -1,6 +1,7 @@
// Include `support/${PLATFORM}.60p` before this source
// Should print YY
include "chrout.60p"
word one
word table[256] many

View File

@ -21,8 +21,9 @@ class ForwardReference(object):
class Parser(object):
def __init__(self, symtab, text, filename):
def __init__(self, symtab, text, filename, include_path):
self.symtab = symtab
self.include_path = include_path
self.scanner = Scanner(text, filename)
self.current_routine_name = None
@ -100,7 +101,7 @@ class Parser(object):
while self.scanner.consume('include'):
filename = self.scanner.token
self.scanner.scan()
program = load_program(filename, self.symtab)
program = load_program(filename, self.symtab, self.include_path)
includes.append(program)
while self.scanner.on('typedef', 'const'):
if self.scanner.on('typedef'):
@ -479,9 +480,14 @@ class Parser(object):
# - - - -
def load_program(filename, symtab):
def load_program(filename, symtab, include_path):
import os
for include_dir in include_path:
if os.path.exists(os.path.join(include_dir, filename)):
filename = os.path.join(include_dir, filename)
break
text = open(filename).read()
parser = Parser(symtab, text, filename)
parser = Parser(symtab, text, filename, include_path)
program = parser.program()
return program