Skip to content

Commit 165c711

Browse files
committed
all: Rename "runtime" to "platform"
Rename uses of "runtime" where it refers to the CLI runtime and the browser runtime to "platform". Runtime usually refers to the thing doing the running, such as the evaluator or bytecode VM and has started to cause a little confusion or cumbersome language now that the bytecode VM is being developed. Initial talk of perhaps targeting micro-controllers as "platforms" also suggests this should be called platform. There are still a few uses of the word "runtime" left - these refer to things like "runtime errors" where the term still makes sense, as it does not refer to the Evy abstraction for runtime/platform. Fix a lint error in `learn/pkg/learn/markdown.go` since golangci-lint wants to complain about this now. Commit-group: 1/2
1 parent 1acce60 commit 165c711

File tree

18 files changed

+187
-186
lines changed

18 files changed

+187
-186
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Use [Homebrew] to install `evy`.
7979
The Evy interpreter is written in [Go] and built using the Go and
8080
[TinyGo] compilers. TinyGo targets [WebAssembly], which allows Evy
8181
source code to be parsed and run in a web browser. The browser
82-
runtime is written in plain JavaScript without the use of frameworks.
82+
platform is written in plain JavaScript without the use of frameworks.
8383

8484
To build the Evy source code, [clone] this repository and
8585
[activate Hermit] in your terminal. Then, build the sources with

docs/builtins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ with `del` while iterating with a `for … range` loop.
433433
`sleep` can be used to create delays in Evy programs. For example, you
434434
could use sleep to create a countdown timer.
435435

436-
In the [browser runtime](spec.md#runtimes) `sleep` pauses a minimum of 1
436+
In the [browser platform](spec.md#platforms) `sleep` pauses a minimum of 1
437437
millisecond.
438438

439439
#### Example

docs/spec.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ To get an intuitive understanding of Evy, you can either look at its
4848
[Assignability of variable values](#assignability-of-variable-values), [Assignability of constant values](#assignability-of-constant-values), [Assignability of empty composite literals](#assignability-of-empty-composite-literals)
4949
24. [**Run-time Panics and Recoverable Errors**](#run-time-panics-and-recoverable-errors)
5050
25. [**Execution Model and Event Handlers**](#execution-model-and-event-handlers)
51-
26. [**Runtimes**](#runtimes)
51+
26. [**Platforms**](#platforms)
5252

5353
<!-- genend:toc -->
5454

@@ -1490,15 +1490,16 @@ only some parameters are needed, use the anonymous `_` parameter.
14901490
For more information on individual event handlers, see the
14911491
[built-in documentation](builtins.md#event-handlers).
14921492

1493-
## Runtimes
1493+
## Platforms
14941494

1495-
Evy has two runtimes: the **terminal runtime** and the **browser runtime**.
1495+
Evy has two platforms: the **terminal platform** and the **browser
1496+
platform**.
14961497

1497-
The browser runtime can be tried at [play.evy.dev]. It fully
1498+
The browser platform can be tried at [play.evy.dev]. It fully
14981499
supports all built-in functions and event handlers as described in the
14991500
[built-in documentation](builtin.md).
15001501

1501-
To use the terminal runtime, first install Evy and then run
1502+
To use the terminal platform, first install Evy and then run
15021503

15031504
evy run FILE.evy
15041505

@@ -1509,6 +1510,6 @@ with
15091510
evy fmt FILE.evy
15101511

15111512
For more details, run `evy run --help` or `evy fmt --help`. The terminal
1512-
runtime does not support event handlers or graphics functions.
1513+
platform does not support event handlers or graphics functions.
15131514

15141515
[play.evy.dev]: https://play.evy.dev

learn/pkg/learn/markdown.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func printAlert(quote *markdown.Quote, buf *bytes.Buffer, alertType string) {
152152
buf.WriteString(`<svg viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="`)
153153
buf.WriteString(alertIconPath[alertType])
154154
buf.WriteString(`"></path></svg>`)
155-
buf.WriteString(strings.Title(alertType)) //nolint: staticcheck // we can savely use it here as we know all strings we want to use and have no punctuation.
155+
buf.WriteString(strings.Title(alertType)) //nolint:staticcheck // we can safely use it here as we know all strings we want to use and have no punctuation.
156156
buf.WriteString(`</p>`)
157157
for _, block := range quote.Blocks {
158158
buf.WriteString(markdown.ToHTML(block))

learn/pkg/learn/renderer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func runEvy(source string, t ResultType) string {
348348
cli.WithCls(textWriter.Reset),
349349
cli.WithSVG("", "", "" /* root style, width, height */),
350350
}
351-
rt := cli.NewRuntime(opts...)
351+
rt := cli.NewPlatform(opts...)
352352
eval := evaluator.NewEvaluator(rt)
353353
err := eval.Run(source)
354354
if err != nil {

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (c *runCmd) Run() error {
185185
if err != nil {
186186
return err
187187
}
188-
rt := cli.NewRuntime(c.runtimeOptions()...)
188+
rt := cli.NewPlatform(c.platformOptions()...)
189189
if c.RandSeed != 0 {
190190
evaluator.RandSource = rand.New(rand.NewSource(c.RandSeed)) //nolint:gosec // not for security
191191
}
@@ -221,15 +221,15 @@ func (c *runCmd) fileBytes() ([]byte, error) {
221221
return b, nil
222222
}
223223

224-
func (c *runCmd) runtimeOptions() []cli.Option {
224+
func (c *runCmd) platformOptions() []cli.Option {
225225
opts := []cli.Option{cli.WithSkipSleep(c.SkipSleep)}
226226
if c.SVGOut != "" {
227227
opts = append(opts, cli.WithSVG(c.SVGStyle, c.SVGWidth, c.SVGHeight))
228228
}
229229
return opts
230230
}
231231

232-
func (c *runCmd) writeSVG(rt *cli.Runtime) error {
232+
func (c *runCmd) writeSVG(rt *cli.Platform) error {
233233
if c.SVGOut == "" {
234234
return nil
235235
}

pkg/cli/runtime.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build !tinygo
22

3-
// Package cli provides an Evy runtime to for Evy CLI execution in terminal.
3+
// Package cli provides an Evy platform to for Evy CLI execution in terminal.
44
package cli
55

66
import (
@@ -16,58 +16,58 @@ import (
1616
"evylang.dev/evy/pkg/evaluator"
1717
)
1818

19-
// Runtime implements evaluator.Runtime.
20-
type Runtime struct {
21-
evaluator.GraphicsRuntime
19+
// Platform implements evaluator.Platform.
20+
type Platform struct {
21+
evaluator.GraphicsPlatform
2222
reader *bufio.Reader
2323
writer io.Writer
2424
clsFn func()
2525
SkipSleep bool
2626
}
2727

28-
// Option is used on Runtime creation to set optional parameters.
29-
type Option func(*Runtime)
28+
// Option is used on Platform creation to set optional parameters.
29+
type Option func(*Platform)
3030

31-
// WithSkipSleep sets the SkipSleep field Runtime and is intended to be used
32-
// with NewRuntime.
31+
// WithSkipSleep sets the SkipSleep field Platform and is intended to be used
32+
// with NewPlatform.
3333
func WithSkipSleep(skipSleep bool) Option {
34-
return func(rt *Runtime) {
34+
return func(rt *Platform) {
3535
rt.SkipSleep = skipSleep
3636
}
3737
}
3838

39-
// WithSVG sets up an SVG graphics runtime and writes its output to the
39+
// WithSVG sets up an SVG graphics platform and writes its output to the
4040
// given writer.
4141
func WithSVG(svgStyle string, svgWidth string, svgHeight string) Option {
42-
return func(rt *Runtime) {
43-
svgRT := svg.NewGraphicsRuntime()
42+
return func(rt *Platform) {
43+
svgRT := svg.NewGraphicsPlatform()
4444
svgRT.SVG.Style = svgStyle
4545
svgRT.SVG.Width = svgWidth
4646
svgRT.SVG.Height = svgHeight
47-
rt.GraphicsRuntime = svgRT
47+
rt.GraphicsPlatform = svgRT
4848
}
4949
}
5050

5151
// WithOutputWriter sets the text output writer, which defaults to os.Stdout.
5252
func WithOutputWriter(w io.Writer) Option {
53-
return func(rt *Runtime) {
53+
return func(rt *Platform) {
5454
rt.writer = w
5555
}
5656
}
5757

5858
// WithCls sets the action to be done for `cls` command.
5959
func WithCls(clsFn func()) Option {
60-
return func(rt *Runtime) {
60+
return func(rt *Platform) {
6161
rt.clsFn = clsFn
6262
}
6363
}
6464

65-
// NewRuntime returns an initialized cli runtime.
66-
func NewRuntime(options ...Option) *Runtime {
67-
rt := &Runtime{
68-
reader: bufio.NewReader(os.Stdin),
69-
writer: os.Stdout,
70-
GraphicsRuntime: &evaluator.UnimplementedRuntime{},
65+
// NewPlatform returns an initialized cli platform.
66+
func NewPlatform(options ...Option) *Platform {
67+
rt := &Platform{
68+
reader: bufio.NewReader(os.Stdin),
69+
writer: os.Stdout,
70+
GraphicsPlatform: &evaluator.UnimplementedPlatform{},
7171
}
7272
for _, opt := range options {
7373
opt(rt)
@@ -76,12 +76,12 @@ func NewRuntime(options ...Option) *Runtime {
7676
}
7777

7878
// Print prints s to stdout.
79-
func (rt *Runtime) Print(s string) {
79+
func (rt *Platform) Print(s string) {
8080
fmt.Fprint(rt.writer, s) //nolint:errcheck // no need to check for stdout
8181
}
8282

8383
// Cls clears the screen.
84-
func (rt *Runtime) Cls() {
84+
func (rt *Platform) Cls() {
8585
if rt.clsFn != nil {
8686
rt.clsFn()
8787
return
@@ -97,7 +97,7 @@ func (rt *Runtime) Cls() {
9797
}
9898

9999
// Read reads a line of input from stdin and strips trailing newline.
100-
func (rt *Runtime) Read() string {
100+
func (rt *Platform) Read() string {
101101
s, err := rt.reader.ReadString('\n')
102102
if err != nil {
103103
panic(err)
@@ -106,7 +106,7 @@ func (rt *Runtime) Read() string {
106106
}
107107

108108
// Sleep sleeps for dur. If the --skip-sleep flag is used, it does nothing.
109-
func (rt *Runtime) Sleep(dur time.Duration) {
109+
func (rt *Platform) Sleep(dur time.Duration) {
110110
if !rt.SkipSleep {
111111
time.Sleep(dur)
112112
}
@@ -115,11 +115,11 @@ func (rt *Runtime) Sleep(dur time.Duration) {
115115
// Yielder returns a no-op yielder for CLI evy as it is not needed. By
116116
// contrast, browser Evy needs to explicitly hand over control to JS
117117
// host with Yielder.
118-
func (*Runtime) Yielder() evaluator.Yielder { return nil }
118+
func (*Platform) Yielder() evaluator.Yielder { return nil }
119119

120120
// WriteSVG writes the graphics output in SVG format to the writer set with
121121
// option WithSVGWriter.
122-
func (rt *Runtime) WriteSVG(w io.Writer) error {
123-
graphicsRT := rt.GraphicsRuntime.(*svg.GraphicsRuntime)
122+
func (rt *Platform) WriteSVG(w io.Writer) error {
123+
graphicsRT := rt.GraphicsPlatform.(*svg.GraphicsPlatform)
124124
return graphicsRT.WriteSVG(w)
125125
}

pkg/cli/runtime_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestGraphics(t *testing.T) {
2222
t.Run(name, func(t *testing.T) {
2323
style := "border: 1px solid red; width: 400px; height: 400px"
2424
svgWriter := &bytes.Buffer{}
25-
rt := NewRuntime(WithSVG(style, "", ""), WithSkipSleep(true))
25+
rt := NewPlatform(WithSVG(style, "", ""), WithSkipSleep(true))
2626

2727
eval := evaluator.NewEvaluator(rt)
2828
evyFilename := strings.TrimSuffix(file, filepath.Ext(file)) + ".evy"
@@ -45,10 +45,10 @@ func TestGraphics(t *testing.T) {
4545
func TestPrintRead(t *testing.T) {
4646
readBuffer := &bytes.Buffer{}
4747
writeBuffer := &bytes.Buffer{}
48-
rt := &Runtime{
49-
reader: bufio.NewReader(readBuffer),
50-
writer: writeBuffer,
51-
GraphicsRuntime: &evaluator.UnimplementedRuntime{},
48+
rt := &Platform{
49+
reader: bufio.NewReader(readBuffer),
50+
writer: writeBuffer,
51+
GraphicsPlatform: &evaluator.UnimplementedPlatform{},
5252
}
5353
readBuffer.WriteString("Hello world\n")
5454
s := rt.Read()

0 commit comments

Comments
 (0)