-
Notifications
You must be signed in to change notification settings - Fork 7
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: Implement stop #67
Conversation
firebase-deployment: https://evy-lang--67-4souifjv.web.app (aba3e29) |
6bad444
to
2eeac0a
Compare
c9407b6
to
f100376
Compare
Refactor access to builtin functions and decls so that we can create the evaluator in wasm main and hold on to it in global state. This will later be needed so that we can set a cancel flag in the evaluator during execution in a JS exported function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥗 LGTM
pkg/evaluator/evaluator.go
Outdated
if e.Stopped { | ||
return ErrStopped | ||
} | ||
e.yield() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a comment here to say why this yield exists?
// Yield to give JavaScript/browser events a chance to run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
print func(string) | ||
builtins map[string]Builtin | ||
|
||
scope *scope // Current top of scope stack | ||
} | ||
|
||
type Yielder interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a comment perhaps?
// Yielder abstracts the method of yielding the CPU so that JavaScript/browser
// events get a chance to be processed. Currently (Feb 2023) it seems that you
// can only yield to JS by sleeping for at least 1ms but having that delay is
// not ideal. Other methods of yielding can be explored by implementing a
// different Yielder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice thanks. done.
pkg/wasm/main.go
Outdated
@@ -24,6 +27,26 @@ func getSource() string { | |||
return getString(ptr, length) | |||
} | |||
|
|||
type yielder struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps call this sleepingYielder
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
Implement stop in frontend by turning the Run button into a Stop button during execution. For this we also need an onExit callback into JS from go when execution finishes so that the button label gets reset. Additionally we need to occasionally yield to JS event processing via a `time.Sleep` in the evaluator code. This operation is abstracted via the Yielder interface. Execution is stopped in Eval if the Stopped flag is set, which gets set on click via the exported Go function stop(). The access to the stop flag is not synchronized, but as JS is single threaded so we don't need to worry about it.
Implement stop in frontend by turning the Run button into a Stop button
during execution. For this we also need an onExit callback into JS from
go when execution finishes so that the button label gets reset.
Additionally we need to occasionally yield to JS event processing via a
time.Sleep
in the evaluator code. This operation is abstracted viathe Yielder interface.
Execution is stopped in Eval if the Stopped flag is set, which gets set
on click via the exported Go function stop(). The access to the stop
flag is not synchronised, but as JS is single threaded so we don't need
to worry about it.
In a preparatory commit refactor evaluator and builtins so that there is
a separate
NewEvaluator
function ande.Run
method. This allows forwasm/main.go
to hold an evaluator as global variable on which we set theevaluator.Stopped
flag.Evy program for testing.
another one with sleep: