mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-21 04:29:14 +00:00
A little awkward, but analyze byte table access correctly.
This commit is contained in:
parent
f4186c5f22
commit
5a5953ca4c
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from sixtypical.ast import Program, Routine, Block, Instr
|
from sixtypical.ast import Program, Routine, Block, Instr
|
||||||
from sixtypical.model import (
|
from sixtypical.model import (
|
||||||
|
TYPE_BYTE, TYPE_BYTE_TABLE,
|
||||||
ConstantRef, LocationRef, FLAG_Z, FLAG_N, FLAG_V, FLAG_C
|
ConstantRef, LocationRef, FLAG_Z, FLAG_N, FLAG_V, FLAG_C
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,6 +35,10 @@ class UsageClashError(StaticAnalysisError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TypeMismatchError(StaticAnalysisError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Context():
|
class Context():
|
||||||
def __init__(self, inputs, outputs, trashes):
|
def __init__(self, inputs, outputs, trashes):
|
||||||
self._store = {} # Ref -> INITALIZED/UNINITIALIZED
|
self._store = {} # Ref -> INITALIZED/UNINITIALIZED
|
||||||
@ -137,10 +142,24 @@ def analyze_instr(instr, context, routines):
|
|||||||
src = instr.src
|
src = instr.src
|
||||||
|
|
||||||
if opcode == 'ld':
|
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_initialized(src)
|
||||||
context.assert_writeable(dest, FLAG_Z, FLAG_N)
|
context.assert_writeable(dest, FLAG_Z, FLAG_N)
|
||||||
context.set_initialized(dest, FLAG_Z, FLAG_N)
|
context.set_initialized(dest, FLAG_Z, FLAG_N)
|
||||||
elif opcode == 'st':
|
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_initialized(src)
|
||||||
context.assert_writeable(dest)
|
context.assert_writeable(dest)
|
||||||
context.set_initialized(dest)
|
context.set_initialized(dest)
|
||||||
|
@ -195,6 +195,116 @@ Can't `st` to a memory location that doesn't appear in (outputs ∪ trashes).
|
|||||||
| }
|
| }
|
||||||
? IllegalWriteError: lives
|
? 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 ###
|
### add ###
|
||||||
|
|
||||||
Can't `add` from or to a memory location that isn't initialized.
|
Can't `add` from or to a memory location that isn't initialized.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user