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

builtins: Fix rand and sleep functions #417

Merged
merged 3 commits into from
Aug 22, 2024
Merged

Conversation

juliaogris
Copy link
Member

@juliaogris juliaogris commented Aug 22, 2024

Fix rand and sleep functions to not crash when used with bad arguments: In
the case of rand we ensure the argument is >= 1, and in the case of sleep we
ensure we sleep a minimum of 1 millisecond.

Add a minor unrelated typo fix.

This PR has cherry-picked from two other PRs created from forked repo, which
cannot run CI.

Related-pull-request: #412
Related-pull-request: #413


@phy1um - I've manually tested it after the fix with max, just like you described in
your PR 🙏 .
Code sample

  • ✅ on PR
  • 💥 on main (crashes tab!)

Docs update:
https://evy-lang-stage-docs--417-lffgt2s0.web.app/builtins.html#sleep

Fix typo in SVG struct field name: `StorkeDashArray` should be
`StrokeDashArray`. The XML field tag used for exporting the content to SVG is
correctly spelled.
juliaogris and others added 2 commits August 22, 2024 14:02
Fix the Evy builtin `rand` function for bad argument (< 1). This must
have been a typo or just lapse of concentration because the comment
states the correct condition for valid rand arguments.
When calling `sleep` in the JS runtime, enforce a minimum allowed
interval of 1 millisecond.

This change is motivated by watching students use Evy. I found they
experimented with very large and very small numbers. When writing a loop
with 10,000,000,000+ iterations containing `sleep 0`, their browser tabs
crashed. For example, run this program against `main`:

	i:num

	clear "blue"
	while i < 100000
	    move i 50
	    color "yellow"
	    circle 5
	    i = i + 0.1
	    sleep 0
	end

This is enough to freeze the browser tab on my PC for a few seconds, and
the Evy UI is unresponsive even after the render finishes. In my branch,
it runs smoothly - and slowly - with the STOP button still functional.

I experimented with a few values and found a minimum sleep of 1
millisecond (0.001 seconds) is enough to ensure that the browser remains
responsive.
Copy link
Member

@camh- camh- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛

@juliaogris juliaogris merged commit 7dbd68c into main Aug 22, 2024
3 checks passed
@juliaogris juliaogris deleted the builtin-improvements branch August 22, 2024 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants