1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2025-02-19 20:30:45 +00:00

mergeRoutCtxs does not need to throw poisoning errors.

This commit is contained in:
Cat's Eye Technologies 2014-04-12 20:37:42 +01:00
parent af7d65ee09
commit 8acde175ad
3 changed files with 55 additions and 42 deletions

View File

@ -26,11 +26,10 @@ reserve word delta
reserve byte value reserve byte value
reserve word compare_target reserve word compare_target
routine reset_position { reserve byte[16] actor_pos_hi
copy #$0400 position reserve byte[16] actor_pos_lo
}
routine advance_pos { routine calculate_new_position outputs (new_position) {
clc clc
lda <position lda <position
adc <delta adc <delta
@ -40,10 +39,6 @@ routine advance_pos {
sta >new_position sta >new_position
} }
routine install_new_position {
copy new_position position
}
routine compare_new_pos { routine compare_new_pos {
lda >new_position lda >new_position
cmp >compare_target cmp >compare_target
@ -117,7 +112,6 @@ routine read_stick {
if beq { if beq {
lda #255 // -1 lda #255 // -1
sta <delta sta <delta
lda #255
sta >delta sta >delta
} else { } else {
txa txa
@ -132,19 +126,30 @@ routine read_stick {
} }
routine our_cinv { routine our_cinv {
lda #32
ldy #0 ldy #0
sta (position), y lda actor_pos_hi, y
sta >position
lda actor_pos_lo, y
sta <position
jsr read_stick jsr read_stick
jsr advance_pos jsr calculate_new_position
jsr check_new_position_in_bounds jsr check_new_position_in_bounds
if bcs { if bcs {
jsr install_new_position lda #32
ldy #0
sta (position), y
copy new_position position
lda #81
ldy #0
sta (position), y
} else { } } else { }
lda #81
ldy #0 ldy #0
sta (position), y lda >position
sta actor_pos_hi, y
lda <position
sta actor_pos_lo, y
jmp (save_cinv) jmp (save_cinv)
} }
@ -154,7 +159,14 @@ routine main {
sta vic_border sta vic_border
lda #0 lda #0
sta vic_bg sta vic_bg
jsr reset_position // copy #$0400 position
ldy #0
lda #$04
sta actor_pos_hi, y
lda #$00
sta actor_pos_lo, y
jsr clear_screen jsr clear_screen
with sei { with sei {
copy cinv save_cinv copy cinv save_cinv

View File

@ -37,20 +37,20 @@ analyzeProgram program@(Program decls routines) =
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
checkInstr nm (COPY src dst) progCtx routCtx = checkInstr nm (COPY src dst) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith src) routCtx updateRoutCtxPoison nm dst (UpdatedWith src) routCtx
checkInstr nm (DELTA dst val) progCtx routCtx = checkInstr nm (DELTA dst val) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith (Immediate val)) routCtx updateRoutCtxPoison nm dst (UpdatedWith (Immediate val)) routCtx
checkInstr nm (ADD dst src) progCtx routCtx = checkInstr nm (ADD dst src) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith src) routCtx updateRoutCtxPoison nm dst (UpdatedWith src) routCtx
checkInstr nm (SUB dst src) progCtx routCtx = checkInstr nm (SUB dst src) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith src) routCtx updateRoutCtxPoison nm dst (UpdatedWith src) routCtx
checkInstr nm (AND dst src) progCtx routCtx = checkInstr nm (AND dst src) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith src) routCtx updateRoutCtxPoison nm dst (UpdatedWith src) routCtx
checkInstr nm (OR dst src) progCtx routCtx = checkInstr nm (OR dst src) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith src) routCtx updateRoutCtxPoison nm dst (UpdatedWith src) routCtx
checkInstr nm (XOR dst src) progCtx routCtx = checkInstr nm (XOR dst src) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith src) routCtx updateRoutCtxPoison nm dst (UpdatedWith src) routCtx
checkInstr nm (JSR name) progCtx routCtx = checkInstr nm (JSR name) progCtx routCtx =
case lookupRoutine program name of case lookupRoutine program name of
@ -77,7 +77,7 @@ analyzeProgram program@(Program decls routines) =
mergeAlternateRoutCtxs nm routCtx1 routCtx2 mergeAlternateRoutCtxs nm routCtx1 routCtx2
checkInstr nm (REPEAT _ branch blk) progCtx routCtx = checkInstr nm (REPEAT _ branch blk) progCtx routCtx =
-- we analyze the block twice, to simulate it being -- we analyze the block twice, to simulate it being
-- repeated. (see tests for a test case on this. -- repeated. (see tests for a test case on this.)
let let
routCtx' = checkBlock nm blk progCtx routCtx routCtx' = checkBlock nm blk progCtx routCtx
routCtx'' = checkBlock nm blk progCtx routCtx' routCtx'' = checkBlock nm blk progCtx routCtx'
@ -89,15 +89,15 @@ analyzeProgram program@(Program decls routines) =
checkBlock nm blk progCtx routCtx checkBlock nm blk progCtx routCtx
checkInstr nm (BIT dst) progCtx routCtx = checkInstr nm (BIT dst) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith (Immediate 0)) routCtx updateRoutCtxPoison nm dst (UpdatedWith (Immediate 0)) routCtx
checkInstr nm (SHR dst flg) progCtx routCtx = checkInstr nm (SHR dst flg) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith flg) routCtx updateRoutCtxPoison nm dst (UpdatedWith flg) routCtx
checkInstr nm (SHL dst flg) progCtx routCtx = checkInstr nm (SHL dst flg) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith flg) routCtx updateRoutCtxPoison nm dst (UpdatedWith flg) routCtx
checkInstr nm (COPYROUTINE name dst) progCtx routCtx = checkInstr nm (COPYROUTINE name dst) progCtx routCtx =
updateRoutCtx nm dst (UpdatedWith (Immediate 7)) routCtx updateRoutCtxPoison nm dst (UpdatedWith (Immediate 7)) routCtx
checkInstr nm (JMPVECTOR dst) progCtx routCtx = checkInstr nm (JMPVECTOR dst) progCtx routCtx =
routCtx routCtx
@ -115,6 +115,9 @@ analyzeProgram program@(Program decls routines) =
-- JSR'ed to (immediately previously) -- and merge them to create a new -- JSR'ed to (immediately previously) -- and merge them to create a new
-- context for the current routine. -- context for the current routine.
-- --
-- This can't, by itself, cause a poisoning error.
-- So we use a weaker version of updateRoutCtx to build the merged context.
--
mergeRoutCtxs nm routCtx calledRoutCtx calledRout@(Routine name outputs _) = mergeRoutCtxs nm routCtx calledRoutCtx calledRout@(Routine name outputs _) =
let let
-- go through all the Usages in the calledRoutCtx -- go through all the Usages in the calledRoutCtx
@ -165,14 +168,3 @@ mergeAlternateRoutCtxs nm routCtx1 routCtx2 =
updateRoutCtx nm location newUsage routCtxAccum updateRoutCtx nm location newUsage routCtxAccum
in in
Map.foldrWithKey (poison) routCtx1 routCtx2 Map.foldrWithKey (poison) routCtx1 routCtx2
where
-- a weaker version of updateRoutCtx, which does not error if
-- we access a poisoned source
updateRoutCtx nm dst (UpdatedWith src) routCtx =
let
s = untypedLocation src
d = untypedLocation dst
in
Map.insert d (UpdatedWith s) routCtx
updateRoutCtx nm dst (PoisonedWith src) routCtx =
Map.insert (untypedLocation dst) (PoisonedWith $ untypedLocation src) routCtx

View File

@ -38,8 +38,8 @@ untypedLocation (NamedLocation _ name) =
NamedLocation Nothing name NamedLocation Nothing name
untypedLocation x = x untypedLocation x = x
updateRoutCtx :: String -> StorageLocation -> Usage -> RoutineContext -> RoutineContext updateRoutCtxPoison :: String -> StorageLocation -> Usage -> RoutineContext -> RoutineContext
updateRoutCtx nm dst (UpdatedWith src) routCtx = updateRoutCtxPoison nm dst (UpdatedWith src) routCtx =
let let
s = untypedLocation src s = untypedLocation src
d = untypedLocation dst d = untypedLocation dst
@ -50,9 +50,18 @@ updateRoutCtx nm dst (UpdatedWith src) routCtx =
(show s) ++ "' (in context: " ++ (show routCtx) ++ ")") (show s) ++ "' (in context: " ++ (show routCtx) ++ ")")
_ -> _ ->
Map.insert d (UpdatedWith s) routCtx Map.insert d (UpdatedWith s) routCtx
updateRoutCtx nm dst (PoisonedWith src) routCtx = updateRoutCtxPoison nm dst (PoisonedWith src) routCtx =
Map.insert (untypedLocation dst) (PoisonedWith $ untypedLocation src) routCtx Map.insert (untypedLocation dst) (PoisonedWith $ untypedLocation src) routCtx
updateRoutCtx nm dst (UpdatedWith src) routCtx =
let
s = untypedLocation src
d = untypedLocation dst
in
Map.insert d (UpdatedWith s) routCtx
updateRoutCtx nm dst (PoisonedWith src) routCtx =
Map.insert (untypedLocation dst) (PoisonedWith $ untypedLocation src) routCtx
-- pretty printing -- pretty printing
ppAnalysis :: Program -> ProgramContext -> IO () ppAnalysis :: Program -> ProgramContext -> IO ()