diff --git a/doc/Checking.markdown b/doc/Checking.markdown index 194b812..7f8e121 100644 --- a/doc/Checking.markdown +++ b/doc/Checking.markdown @@ -123,6 +123,35 @@ Test for many combinations of `reserve` and `assign`. | } = True +`reserve` may be block-level. + + | routine main { + | reserve byte lives + | lda lives + | } + = True + +Block-level declarations are only visible in the block in which they are +declared. + + | routine main { + | reserve byte lives + | lda #3 + | sta lives + | } + | routine died { + | dec lives + | } + ? undeclared location 'lives' + +A block-level `reserve` may not supply an initial value. + + | routine main { + | reserve byte lives : 3 + | lda lives + | } + ? block-level 'lives' cannot supply initial value + A program may declare an `external`. | external blastoff 49152 diff --git a/src/SixtyPical/Transformer.hs b/src/SixtyPical/Transformer.hs index ca13820..b050d33 100644 --- a/src/SixtyPical/Transformer.hs +++ b/src/SixtyPical/Transformer.hs @@ -169,7 +169,8 @@ foldDeclsRenaming ((Reserve name typ Nothing):decls) id block = block'' = substDeclName name newName block' in foldDeclsRenaming decls id' block'' - +foldDeclsRenaming ((Reserve name typ _):decls) id block = + error ("block-level '" ++ name ++ "' cannot supply initial value") -- this is kind of horrible. that we do it this way, i mean substDeclName n1 n2 (Block decls instrs) = @@ -198,16 +199,22 @@ mapInstrName n1 n2 (SUB sl1 sl2) = SUB (mapStorageLocationName n1 n2 sl1) (mapStorageLocationName n1 n2 sl2) mapInstrName n1 n2 (OR sl1 sl2) = OR (mapStorageLocationName n1 n2 sl1) (mapStorageLocationName n1 n2 sl2) +mapInstrName n1 n2 (XOR sl1 sl2) = + XOR (mapStorageLocationName n1 n2 sl1) (mapStorageLocationName n1 n2 sl2) +mapInstrName n1 n2 (SHL sl1 sl2) = + SHL (mapStorageLocationName n1 n2 sl1) (mapStorageLocationName n1 n2 sl2) +mapInstrName n1 n2 (SHR sl1 sl2) = + SHR (mapStorageLocationName n1 n2 sl1) (mapStorageLocationName n1 n2 sl2) +mapInstrName n1 n2 (BIT sl1) = + BIT (mapStorageLocationName n1 n2 sl1) +mapInstrName n1 n2 (JMPVECTOR sl1) = + JMPVECTOR (mapStorageLocationName n1 n2 sl1) +mapInstrName n1 n2 (DELTA sl1 v) = + DELTA (mapStorageLocationName n1 n2 sl1) v {- - | XOR StorageLocation StorageLocation - | SHL StorageLocation StorageLocation - | SHR StorageLocation StorageLocation - | BIT StorageLocation - | JMPVECTOR StorageLocation | IF InternalID Branch Block Block | REPEAT InternalID Branch Block - | DELTA StorageLocation DataValue | WITH WithInstruction Block | COPYROUTINE RoutineName StorageLocation -}