diff --git a/README.markdown b/README.markdown index 5e6b40e..b937e7a 100644 --- a/README.markdown +++ b/README.markdown @@ -131,4 +131,3 @@ TODO * `outputs` on externals * Routine is a kind of StorageLocation? (Location)? * remove DELTA -> ADD/SUB (requires carry be notated on ADD and SUB though) -* explicit `with` syntax diff --git a/doc/Emitting.markdown b/doc/Emitting.markdown index 7d79e54..e30aa18 100644 --- a/doc/Emitting.markdown +++ b/doc/Emitting.markdown @@ -105,7 +105,7 @@ Installing an interrupt handler (at the Kernal level, i.e. with CINV) | reserve vector save_cinv | | routine main { - | sei { + | with sei { | copy cinv save_cinv | copy routine our_cinv to cinv | } diff --git a/doc/Instruction_Support.markdown b/doc/Instruction_Support.markdown index 6854686..986d506 100644 --- a/doc/Instruction_Support.markdown +++ b/doc/Instruction_Support.markdown @@ -297,9 +297,9 @@ Big test for parsing and emitting instructions. = .alias table 1024 | routine main { - | pha { - | sei { - | php { + | with pha { + | with sei { + | with php { | lda #0 | } | lda #1 diff --git a/eg/cinv.60p b/eg/cinv.60p index 78cdc6a..7ebe503 100644 --- a/eg/cinv.60p +++ b/eg/cinv.60p @@ -3,7 +3,7 @@ assign vector cinv 788 reserve vector save_cinv routine main { - sei { + with sei { copy cinv save_cinv copy routine our_cinv to cinv } diff --git a/eg/demo.60p b/eg/demo.60p index 612bd04..fa2906f 100644 --- a/eg/demo.60p +++ b/eg/demo.60p @@ -101,7 +101,7 @@ routine main { sta vic_bg jsr reset_position jsr clear_screen - sei { + with sei { copy cinv save_cinv copy routine our_cinv to cinv } diff --git a/eg/game.60p b/eg/game.60p index 05e18bb..f729ec7 100644 --- a/eg/game.60p +++ b/eg/game.60p @@ -156,7 +156,7 @@ routine main { sta vic_bg jsr reset_position jsr clear_screen - sei { + with sei { copy cinv save_cinv copy routine our_cinv to cinv } diff --git a/src/SixtyPical/Analyzer.hs b/src/SixtyPical/Analyzer.hs index ef0f2c8..58718d3 100644 --- a/src/SixtyPical/Analyzer.hs +++ b/src/SixtyPical/Analyzer.hs @@ -73,9 +73,7 @@ analyzeProgram program@(Program decls routines) = routCtx -- TODO -- THESE ARE WEAK -- - checkInstr nm (SEI blk) progCtx routCtx = - checkBlock nm blk progCtx routCtx - checkInstr nm (PUSH _ blk) progCtx routCtx = + checkInstr nm (WITH _ blk) progCtx routCtx = checkBlock nm blk progCtx routCtx checkInstr nm (BIT dst) progCtx routCtx = diff --git a/src/SixtyPical/Checker.hs b/src/SixtyPical/Checker.hs index f87ef42..c2ffcfc 100644 --- a/src/SixtyPical/Checker.hs +++ b/src/SixtyPical/Checker.hs @@ -134,10 +134,10 @@ fillOutNamedLocationTypes p@(Program decls routines) = REPEAT iid branch (mapBlock xform blk) xform (DELTA dest val) = DELTA (resolve dest) val - xform (SEI blk) = - SEI (mapBlock xform blk) - xform (PUSH val blk) = - PUSH (resolve val) (mapBlock xform blk) + xform (WITH SEI blk) = + WITH SEI (mapBlock xform blk) + xform (WITH (PUSH val) blk) = + WITH (PUSH (resolve val)) (mapBlock xform blk) xform (COPYROUTINE name dest) = COPYROUTINE name (resolve dest) xform other = diff --git a/src/SixtyPical/Emitter.hs b/src/SixtyPical/Emitter.hs index 070d91a..8f249e4 100644 --- a/src/SixtyPical/Emitter.hs +++ b/src/SixtyPical/Emitter.hs @@ -169,17 +169,17 @@ emitInstr p r (REPEAT iid branch blk) = emitInstrs p r blk ++ " " ++ (show branch) ++ " _repeat_" ++ (show iid) -emitInstr p r (SEI blk) = +emitInstr p r (WITH SEI blk) = "sei\n" ++ emitInstrs p r blk ++ " cli" -emitInstr p r (PUSH A blk) = +emitInstr p r (WITH (PUSH A) blk) = "pha\n" ++ emitInstrs p r blk ++ " pla" -emitInstr p r (PUSH AllFlags blk) = +emitInstr p r (WITH (PUSH AllFlags) blk) = "php\n" ++ emitInstrs p r blk ++ " plp" diff --git a/src/SixtyPical/Model.hs b/src/SixtyPical/Model.hs index 5f23650..ed0ce45 100644 --- a/src/SixtyPical/Model.hs +++ b/src/SixtyPical/Model.hs @@ -56,6 +56,10 @@ type RoutineName = String data Branch = BCC | BCS | BEQ | BMI | BNE | BPL | BVC | BVS deriving (Show, Ord, Eq) +data WithInstruction = SEI + | PUSH StorageLocation + deriving (Show, Ord, Eq) + data Instruction = COPY StorageLocation StorageLocation | CMP StorageLocation StorageLocation | ADD StorageLocation StorageLocation @@ -72,8 +76,7 @@ data Instruction = COPY StorageLocation StorageLocation | IF InternalID Branch [Instruction] [Instruction] | REPEAT InternalID Branch [Instruction] | DELTA StorageLocation DataValue - | SEI [Instruction] - | PUSH StorageLocation [Instruction] + | WITH WithInstruction [Instruction] | COPYROUTINE RoutineName StorageLocation | NOP deriving (Show, Ord, Eq) diff --git a/src/SixtyPical/Parser.hs b/src/SixtyPical/Parser.hs index 27ad98b..c037e0d 100644 --- a/src/SixtyPical/Parser.hs +++ b/src/SixtyPical/Parser.hs @@ -27,7 +27,7 @@ Command := "if" Branch Block "else" Block | "cpy" (LocationName | Immediate) | "inx" | "iny" | "dex" | "dey" | "inc" Location | "dec" Location | "clc" | "cld" | "clv" | "sec" | "sed" - | "sei" Block | "pha" Block | "php" Block + | "with ("sei" | "pha" | "php") Block | "jmp" LocationName | "jsr" RoutineName | "nop". @@ -226,8 +226,8 @@ command = (try lda) <|> (try sbc) <|> (try ora) <|> (try asl) <|> (try bit) <|> (try eor) <|> (try lsr) <|> (try rol) <|> (try ror) <|> - (try sei) <|> (try pha) <|> (try php) <|> (try jmp) <|> (try jsr) <|> + (try with_block) <|> (try copy_routine_statement) <|> (try copy_general_statement) <|> if_statement <|> repeat_statement <|> nop @@ -477,26 +477,32 @@ tay = do nspaces return (COPY A Y) -sei :: Parser Instruction +with_block :: Parser Instruction +with_block = do + string "with" + nspaces + instr <- (try sei) <|> (try pha) <|> php + blk <- block + return (WITH instr blk) + + +sei :: Parser WithInstruction sei = do string "sei" nspaces - blk <- block - return (SEI blk) + return SEI -pha :: Parser Instruction +pha :: Parser WithInstruction pha = do string "pha" nspaces - blk <- block - return (PUSH A blk) + return (PUSH A) -php :: Parser Instruction +php :: Parser WithInstruction php = do string "php" nspaces - blk <- block - return (PUSH AllFlags blk) + return (PUSH AllFlags) jmp :: Parser Instruction jmp = do