From 3814d2624dc134757aec9d21c1aa33cfa07115c2 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Tue, 27 Nov 2018 17:26:58 +0000 Subject: [PATCH] Improve tests. --- tests/SixtyPical Analysis.md | 27 ++++++++++++++++++++++++--- tests/SixtyPical Syntax.md | 7 +++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index 6b8ac1e..6ee6410 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -3105,7 +3105,28 @@ routine. | } = ok -It is, however, important that the type context at every +Even though `goto` can only appear at the end of a block, +you can still wind up with dead code; the analysis detects +this. + + | define bar routine trashes x, z, n { + | ld x, 200 + | } + | + | define main routine trashes x, z, n { + | ld x, 0 + | if z { + | ld x, 1 + | goto bar + | } else { + | ld x, 0 + | goto bar + | } + | ld x, 100 + | } + ? TerminatedContextError + +It is important that the type context at every `goto` is compatible with the type context at the end of the routine. @@ -3128,7 +3149,7 @@ the routine. | } = ok -Here, we try to trash x before gotoing a routine that inputs x. +Here, we try to trash `x` before `goto`ing a routine that inputs `x`. | define bar routine | inputs x @@ -3152,7 +3173,7 @@ Here, we try to trash x before gotoing a routine that inputs x. | } ? UnmeaningfulReadError: x -Here, we declare that main outputs a, but we goto a routine that does not output a. +Here, we declare that main outputs `a`, but we `goto` a routine that does not output `a`. | define bar routine | inputs x diff --git a/tests/SixtyPical Syntax.md b/tests/SixtyPical Syntax.md index dc59a0f..7a660c8 100644 --- a/tests/SixtyPical Syntax.md +++ b/tests/SixtyPical Syntax.md @@ -551,6 +551,9 @@ goto. | } = ok +The label doesn't have to be defined yet at the point +in the program text where it is `goto`d. + | define main routine { | goto foo | } @@ -559,6 +562,8 @@ goto. | } = ok +Syntactically, you can `goto` a vector. + | vector routine foo | | define main routine { @@ -566,6 +571,8 @@ goto. | } = ok +But you can't `goto` a label that never gets defined. + | define main routine { | goto foo | }