1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2025-02-16 15:30:26 +00:00

A little awkward, but analyze byte table access correctly.

This commit is contained in:
Chris Pressey 2015-10-18 18:12:47 +01:00
parent f4186c5f22
commit 5a5953ca4c
2 changed files with 129 additions and 0 deletions

View File

@ -2,6 +2,7 @@
from sixtypical.ast import Program, Routine, Block, Instr
from sixtypical.model import (
TYPE_BYTE, TYPE_BYTE_TABLE,
ConstantRef, LocationRef, FLAG_Z, FLAG_N, FLAG_V, FLAG_C
)
@ -34,6 +35,10 @@ class UsageClashError(StaticAnalysisError):
pass
class TypeMismatchError(StaticAnalysisError):
pass
class Context():
def __init__(self, inputs, outputs, trashes):
self._store = {} # Ref -> INITALIZED/UNINITIALIZED
@ -137,10 +142,24 @@ def analyze_instr(instr, context, routines):
src = instr.src
if opcode == 'ld':
if instr.index:
if src.type == TYPE_BYTE_TABLE and dest.type == TYPE_BYTE:
pass
else:
raise TypeMismatchError((src, dest))
elif src.type != dest.type:
raise TypeMismatchError((src, dest))
context.assert_initialized(src)
context.assert_writeable(dest, FLAG_Z, FLAG_N)
context.set_initialized(dest, FLAG_Z, FLAG_N)
elif opcode == 'st':
if instr.index:
if src.type == TYPE_BYTE and dest.type == TYPE_BYTE_TABLE:
pass
else:
raise TypeMismatchError((src, dest))
elif src.type != dest.type:
raise TypeMismatchError((src, dest))
context.assert_initialized(src)
context.assert_writeable(dest)
context.set_initialized(dest)

View File

@ -195,6 +195,116 @@ Can't `st` to a memory location that doesn't appear in (outputs trashes).
| }
? IllegalWriteError: lives
Storing to a table, you must use an index, and vice-versa.
| byte one
| byte table many
|
| routine main
| outputs one
| trashes a, x, n, z
| {
| ld x, 0
| ld a, 0
| st a, one
| }
= ok
| byte one
| byte table many
|
| routine main
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| ld a, 0
| st a, many
| }
? TypeMismatchError
| byte one
| byte table many
|
| routine main
| outputs one
| trashes a, x, n, z
| {
| ld x, 0
| ld a, 0
| st a, one + x
| }
? TypeMismatchError
| byte one
| byte table many
|
| routine main
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| ld a, 0
| st a, many + x
| }
= ok
Reading from a table, you must use an index, and vice-versa.
| byte one
| byte table many
|
| routine main
| outputs one
| trashes a, x, n, z
| {
| ld x, 0
| st x, one
| ld a, one
| }
= ok
| byte one
| byte table many
|
| routine main
| outputs one
| trashes a, x, n, z
| {
| ld x, 0
| st x, one
| ld a, one + x
| }
? TypeMismatchError
| byte one
| byte table many
|
| routine main
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| ld a, 0
| st a, many + x
| ld a, many
| }
? TypeMismatchError
| byte one
| byte table many
|
| routine main
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| ld a, 0
| st a, many + x
| ld a, many + x
| }
= ok
### add ###
Can't `add` from or to a memory location that isn't initialized.