Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: Rename "runtime" to "platform" #458

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Use [Homebrew] to install `evy`.
The Evy interpreter is written in [Go] and built using the Go and
[TinyGo] compilers. TinyGo targets [WebAssembly], which allows Evy
source code to be parsed and run in a web browser. The browser
runtime is written in plain JavaScript without the use of frameworks.
platform is written in plain JavaScript without the use of frameworks.

To build the Evy source code, [clone] this repository and
[activate Hermit] in your terminal. Then, build the sources with
Expand Down
2 changes: 1 addition & 1 deletion docs/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ with `del` while iterating with a `for … range` loop.
`sleep` can be used to create delays in Evy programs. For example, you
could use sleep to create a countdown timer.

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

#### Example
Expand Down
13 changes: 7 additions & 6 deletions docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ To get an intuitive understanding of Evy, you can either look at its
[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)
24. [**Run-time Panics and Recoverable Errors**](#run-time-panics-and-recoverable-errors)
25. [**Execution Model and Event Handlers**](#execution-model-and-event-handlers)
26. [**Runtimes**](#runtimes)
26. [**Platforms**](#platforms)

<!-- genend:toc -->

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

## Runtimes
## Platforms

Evy has two runtimes: the **terminal runtime** and the **browser runtime**.
Evy has two platforms: the **terminal platform** and the **browser
platform**.

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

To use the terminal runtime, first install Evy and then run
To use the terminal platform, first install Evy and then run

evy run FILE.evy

Expand All @@ -1509,6 +1510,6 @@ with
evy fmt FILE.evy

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

[play.evy.dev]: https://play.evy.dev
4 changes: 2 additions & 2 deletions frontend/docs/builtins.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/docs/builtins.htmlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions frontend/docs/spec.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions frontend/docs/spec.htmlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/docs/syntax-by-example.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/docs/talks-and-papers.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/docs/usage.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion learn/pkg/learn/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func printAlert(quote *markdown.Quote, buf *bytes.Buffer, alertType string) {
buf.WriteString(`<svg viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="`)
buf.WriteString(alertIconPath[alertType])
buf.WriteString(`"></path></svg>`)
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.
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.
buf.WriteString(`</p>`)
for _, block := range quote.Blocks {
buf.WriteString(markdown.ToHTML(block))
Expand Down
2 changes: 1 addition & 1 deletion learn/pkg/learn/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func runEvy(source string, t ResultType) string {
cli.WithCls(textWriter.Reset),
cli.WithSVG("", "", "" /* root style, width, height */),
}
rt := cli.NewRuntime(opts...)
rt := cli.NewPlatform(opts...)
eval := evaluator.NewEvaluator(rt)
err := eval.Run(source)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (c *runCmd) Run() error {
if err != nil {
return err
}
rt := cli.NewRuntime(c.runtimeOptions()...)
rt := cli.NewPlatform(c.platformOptions()...)
if c.RandSeed != 0 {
evaluator.RandSource = rand.New(rand.NewSource(c.RandSeed)) //nolint:gosec // not for security
}
Expand Down Expand Up @@ -221,15 +221,15 @@ func (c *runCmd) fileBytes() ([]byte, error) {
return b, nil
}

func (c *runCmd) runtimeOptions() []cli.Option {
func (c *runCmd) platformOptions() []cli.Option {
opts := []cli.Option{cli.WithSkipSleep(c.SkipSleep)}
if c.SVGOut != "" {
opts = append(opts, cli.WithSVG(c.SVGStyle, c.SVGWidth, c.SVGHeight))
}
return opts
}

func (c *runCmd) writeSVG(rt *cli.Runtime) error {
func (c *runCmd) writeSVG(rt *cli.Platform) error {
if c.SVGOut == "" {
return nil
}
Expand Down
56 changes: 28 additions & 28 deletions pkg/cli/runtime.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build !tinygo

// Package cli provides an Evy runtime to for Evy CLI execution in terminal.
// Package cli provides an Evy platform to for Evy CLI execution in terminal.
package cli

import (
Expand All @@ -16,58 +16,58 @@ import (
"evylang.dev/evy/pkg/evaluator"
)

// Runtime implements evaluator.Runtime.
type Runtime struct {
evaluator.GraphicsRuntime
// Platform implements evaluator.Platform.
type Platform struct {
evaluator.GraphicsPlatform
reader *bufio.Reader
writer io.Writer
clsFn func()
SkipSleep bool
}

// Option is used on Runtime creation to set optional parameters.
type Option func(*Runtime)
// Option is used on Platform creation to set optional parameters.
type Option func(*Platform)

// WithSkipSleep sets the SkipSleep field Runtime and is intended to be used
// with NewRuntime.
// WithSkipSleep sets the SkipSleep field Platform and is intended to be used
// with NewPlatform.
func WithSkipSleep(skipSleep bool) Option {
return func(rt *Runtime) {
return func(rt *Platform) {
rt.SkipSleep = skipSleep
}
}

// WithSVG sets up an SVG graphics runtime and writes its output to the
// WithSVG sets up an SVG graphics platform and writes its output to the
// given writer.
func WithSVG(svgStyle string, svgWidth string, svgHeight string) Option {
return func(rt *Runtime) {
svgRT := svg.NewGraphicsRuntime()
return func(rt *Platform) {
svgRT := svg.NewGraphicsPlatform()
svgRT.SVG.Style = svgStyle
svgRT.SVG.Width = svgWidth
svgRT.SVG.Height = svgHeight
rt.GraphicsRuntime = svgRT
rt.GraphicsPlatform = svgRT
}
}

// WithOutputWriter sets the text output writer, which defaults to os.Stdout.
func WithOutputWriter(w io.Writer) Option {
return func(rt *Runtime) {
return func(rt *Platform) {
rt.writer = w
}
}

// WithCls sets the action to be done for `cls` command.
func WithCls(clsFn func()) Option {
return func(rt *Runtime) {
return func(rt *Platform) {
rt.clsFn = clsFn
}
}

// NewRuntime returns an initialized cli runtime.
func NewRuntime(options ...Option) *Runtime {
rt := &Runtime{
reader: bufio.NewReader(os.Stdin),
writer: os.Stdout,
GraphicsRuntime: &evaluator.UnimplementedRuntime{},
// NewPlatform returns an initialized cli platform.
func NewPlatform(options ...Option) *Platform {
rt := &Platform{
reader: bufio.NewReader(os.Stdin),
writer: os.Stdout,
GraphicsPlatform: &evaluator.UnimplementedPlatform{},
}
for _, opt := range options {
opt(rt)
Expand All @@ -76,12 +76,12 @@ func NewRuntime(options ...Option) *Runtime {
}

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

// Cls clears the screen.
func (rt *Runtime) Cls() {
func (rt *Platform) Cls() {
if rt.clsFn != nil {
rt.clsFn()
return
Expand All @@ -97,7 +97,7 @@ func (rt *Runtime) Cls() {
}

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

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

// WriteSVG writes the graphics output in SVG format to the writer set with
// option WithSVGWriter.
func (rt *Runtime) WriteSVG(w io.Writer) error {
graphicsRT := rt.GraphicsRuntime.(*svg.GraphicsRuntime)
func (rt *Platform) WriteSVG(w io.Writer) error {
graphicsRT := rt.GraphicsPlatform.(*svg.GraphicsPlatform)
return graphicsRT.WriteSVG(w)
}
10 changes: 5 additions & 5 deletions pkg/cli/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestGraphics(t *testing.T) {
t.Run(name, func(t *testing.T) {
style := "border: 1px solid red; width: 400px; height: 400px"
svgWriter := &bytes.Buffer{}
rt := NewRuntime(WithSVG(style, "", ""), WithSkipSleep(true))
rt := NewPlatform(WithSVG(style, "", ""), WithSkipSleep(true))

eval := evaluator.NewEvaluator(rt)
evyFilename := strings.TrimSuffix(file, filepath.Ext(file)) + ".evy"
Expand All @@ -45,10 +45,10 @@ func TestGraphics(t *testing.T) {
func TestPrintRead(t *testing.T) {
readBuffer := &bytes.Buffer{}
writeBuffer := &bytes.Buffer{}
rt := &Runtime{
reader: bufio.NewReader(readBuffer),
writer: writeBuffer,
GraphicsRuntime: &evaluator.UnimplementedRuntime{},
rt := &Platform{
reader: bufio.NewReader(readBuffer),
writer: writeBuffer,
GraphicsPlatform: &evaluator.UnimplementedPlatform{},
}
readBuffer.WriteString("Hello world\n")
s := rt.Read()
Expand Down
Loading
Loading