Make repeat statement support return, break and continue

This commit is contained in:
No Time To Play 2023-09-15 05:25:18 +00:00
parent e561b4eb21
commit 1267a8ed3b
3 changed files with 23 additions and 4 deletions

View File

@ -1,5 +1,11 @@
# Genoa Banner Creator project news
## [0.5 alpha] - unreleased
### Changed
* The repeat statement now supports return, break and continue.
## [0.4 alpha] - 2023-09-14
### Added

View File

@ -6,7 +6,7 @@ Rationale: I make vector art by hand (see the Pocket Guide to Writing SVG, by Jo
## Availability
As of September 2023, Genoa is at a very early alpha stage: incomplete, undocumented and probably buggy. Use at your own risk. System requirements:
As of September 2023, Genoa is at a very early alpha stage: incomplete, poorly documented and probably buggy. Use at your own risk. System requirements:
- to run from source, Tcl/Tk 8.6 with tklib
- screen resolution:
@ -15,7 +15,7 @@ As of September 2023, Genoa is at a very early alpha stage: incomplete, undocume
## Usage
Genoa is powered by a little language based on Tcl. Right now it can generate its own promotional banner, like this:
Genoa is powered by a little language based on Tcl. For example its own promotional banner is defined like this:
```tcl
# The viewport declaration can be anywhere.
@ -39,7 +39,7 @@ color darkblue; circles 400 400
font "Noto Sans"; size 48
color white; set j 0
foreach i {GENERATE ORIGINAL ART} {
foreach i "GENERATE ORIGINAL ART" {
incr j 64
text 225 [+ 225 $j] $i
}

View File

@ -54,7 +54,20 @@ interp create -safe runner
runner eval {
proc repeat {times code} {
for {set i 0} {$i < $times} {incr i} {
uplevel 1 $code
set ret [catch {uplevel 1 $code} message]
switch $ret {
0 {}
1 {
return -code error \
-errorinfo $::errorInfo \
-errorcode $::errorCode \
$message
}
2 { return -code return $message }
3 { break }
4 {}
default { return -code $code $message }
}
}
}
namespace path {::tcl::mathop ::tcl::mathfunc}