From af7d65ee09526462a028836d6398553254f48727 Mon Sep 17 00:00:00 2001 From: Cat's Eye Technologies Date: Sat, 12 Apr 2014 19:13:13 +0100 Subject: [PATCH] Fix example programs; allow externals to be called. --HG-- rename : eg/hi.60p => eg/hello-world.60p --- doc/Emitting.markdown | 24 ++++++++++++++++++++++++ eg/demo.60p | 18 +++++++++--------- eg/game.60p | 18 +++++++++--------- eg/hello-world.60p | 13 +++++++++++++ eg/hi.60p | 9 --------- eg/screen3.60p | 2 +- src/SixtyPical/Analyzer.hs | 21 +++++++++++++-------- src/SixtyPical/Checker.hs | 2 +- src/SixtyPical/Model.hs | 1 + 9 files changed, 71 insertions(+), 37 deletions(-) create mode 100644 eg/hello-world.60p delete mode 100644 eg/hi.60p diff --git a/doc/Emitting.markdown b/doc/Emitting.markdown index fc757d9..543398b 100644 --- a/doc/Emitting.markdown +++ b/doc/Emitting.markdown @@ -266,3 +266,27 @@ temporaries are not unioned yet, but they could be. = .space _temp_4 2 = .space _temp_1 1 = .space _temp_2 2 + +Declaring and calling an external routine. + + | external chrout 65490 + | routine main { + | lda #72 + | jsr chrout + | lda #73 + | jsr chrout + | lda #13 + | jsr chrout + | } + = main: + = lda #72 + = jsr chrout + = lda #73 + = jsr chrout + = lda #13 + = jsr chrout + = rts + = + = .data + = .alias chrout 65490 + diff --git a/eg/demo.60p b/eg/demo.60p index fa2906f..8c0b1a7 100644 --- a/eg/demo.60p +++ b/eg/demo.60p @@ -1,15 +1,15 @@ - assign byte table screen $0400 -assign byte table screen2 1274 -assign byte table screen3 1524 -assign byte table screen4 1774 +assign byte[256] screen $0400 +assign byte[256] screen2 1274 +assign byte[256] screen3 1524 +assign byte[256] screen4 1774 -assign byte table colormap 55296 -assign byte table colormap2 55546 -assign byte table colormap3 55796 -assign byte table colormap4 56046 +assign byte[256] colormap 55296 +assign byte[256] colormap2 55546 +assign byte[256] colormap3 55796 +assign byte[256] colormap4 56046 assign byte vic_border 53280 -assign byte table vic_bg 53281 +assign byte[4] vic_bg 53281 assign vector cinv 788 reserve vector save_cinv diff --git a/eg/game.60p b/eg/game.60p index f729ec7..dbd0175 100644 --- a/eg/game.60p +++ b/eg/game.60p @@ -1,15 +1,15 @@ -assign byte table screen $0400 -assign byte table screen2 1274 -assign byte table screen3 1524 -assign byte table screen4 1774 +assign byte[256] screen $0400 +assign byte[256] screen2 1274 +assign byte[256] screen3 1524 +assign byte[256] screen4 1774 -assign byte table colormap 55296 -assign byte table colormap2 55546 -assign byte table colormap3 55796 -assign byte table colormap4 56046 +assign byte[256] colormap 55296 +assign byte[256] colormap2 55546 +assign byte[256] colormap3 55796 +assign byte[256] colormap4 56046 assign byte vic_border 53280 -assign byte table vic_bg 53281 +assign byte[4] vic_bg 53281 assign byte joy2 $dc00 diff --git a/eg/hello-world.60p b/eg/hello-world.60p new file mode 100644 index 0000000..7e4cadc --- /dev/null +++ b/eg/hello-world.60p @@ -0,0 +1,13 @@ +reserve byte[13] message: "HELLO, WORLD!" +external chrout 65490 +routine main { + ldy #0 + repeat bne { + lda message, y + jsr chrout + iny + cpy #13 + } + lda #13 + jsr chrout +} diff --git a/eg/hi.60p b/eg/hi.60p deleted file mode 100644 index 6071538..0000000 --- a/eg/hi.60p +++ /dev/null @@ -1,9 +0,0 @@ -external chrout 65490 -routine main { - lda #72 - jsr chrout - lda #73 - jsr chrout - lda #13 - jsr chrout -} diff --git a/eg/screen3.60p b/eg/screen3.60p index 99c83fb..789a27a 100644 --- a/eg/screen3.60p +++ b/eg/screen3.60p @@ -1,4 +1,4 @@ -assign byte table screen 1024 +assign byte[256] screen 1024 reserve byte value routine main { lda #0 diff --git a/src/SixtyPical/Analyzer.hs b/src/SixtyPical/Analyzer.hs index bb8870b..fcebe7b 100644 --- a/src/SixtyPical/Analyzer.hs +++ b/src/SixtyPical/Analyzer.hs @@ -53,14 +53,19 @@ analyzeProgram program@(Program decls routines) = updateRoutCtx nm dst (UpdatedWith src) routCtx checkInstr nm (JSR name) progCtx routCtx = - let - Just calledRout = lookupRoutine program name - in - case Map.lookup name progCtx of - Just calledRoutCtx -> - mergeRoutCtxs nm routCtx calledRoutCtx calledRout - Nothing -> - error ("can't call routine '" ++ name ++ "' before it is defined") + case lookupRoutine program name of + Just calledRout -> + case Map.lookup name progCtx of + Just calledRoutCtx -> + mergeRoutCtxs nm routCtx calledRoutCtx calledRout + Nothing -> + error ("can't call routine '" ++ name ++ "' before it is defined") + Nothing -> + -- it must be an external. + -- TODO: merge in any poisoning/outputs that are declared + -- on the external. for now, + routCtx + checkInstr nm (CMP reg addr) progCtx routCtx = -- TODO: mark Carry bit as "touched" here routCtx diff --git a/src/SixtyPical/Checker.hs b/src/SixtyPical/Checker.hs index 6dc6aee..4609f5f 100644 --- a/src/SixtyPical/Checker.hs +++ b/src/SixtyPical/Checker.hs @@ -69,7 +69,7 @@ consistentInitialTableSizes p@(Program decls routines) = checkAndTransformProgram :: Program -> Maybe Program checkAndTransformProgram program = if - trueOrDie "missing 'main' routine" (routineDeclared "main" program) && + trueOrDie ("missing 'main' routine: " ++ show program) (routineDeclared "main" program) && trueOrDie "duplicate location name" (noDuplicateDecls program) && trueOrDie "duplicate routine name" (noDuplicateRoutines program) && trueOrDie "undeclared routine" (noUseOfUndeclaredRoutines program) && diff --git a/src/SixtyPical/Model.hs b/src/SixtyPical/Model.hs index 27ee79e..933aa97 100644 --- a/src/SixtyPical/Model.hs +++ b/src/SixtyPical/Model.hs @@ -111,6 +111,7 @@ isLocationDecl _ = False isInitializedDecl (Assign _ _ _) = False isInitializedDecl (Reserve _ _ (v:vs)) = True isInitializedDecl (Reserve _ _ []) = False +isInitializedDecl _ = False declaredLocationNames (Program decls _) = map (getDeclLocationName) (filter (isLocationDecl) decls)