Commit Graph
58 Commits
Author SHA1 Message Date
Thomas Weber d8c095271f Improve some compiler internals
- fix procedures being compiled more than once
- remove Cast dependency from execute
2020-06-23 23:00:53 -05:00
Thomas Weber 417fe21215 Get quicksort to run
- add control_stop
- fix control_repeatuntil
- fix control_while
- add data_hidelist
- add data_showlist
- add data_deletealloflist
- add data_addtolist
- add data_replaceitemoflist
- add data_lengthoflist
- add data_itemoflist
- add motion_xposition
- add motion_yposition
- fix procedures_call
2020-06-23 18:57:37 -05:00
Thomas Weber 85d34f03ac Improve procedure support
Supports string arguments
Supports warp
2020-06-22 22:02:28 -05:00
Thomas Weber b93558f850 Basic procedure support 2020-06-22 21:34:47 -05:00
Thomas Weber 4a4ba718c6 pen, colors, thread state 2020-06-22 19:34:30 -05:00
Thomas Weber c10a631d2e get some more simple things to sortof work 2020-06-22 16:55:46 -05:00
Thomas Weber 99c570f459 New compiler/runtime model
Use continuations instead of generators
Lots of things taken quite directly from forkphorus/phosphorus
2020-06-14 20:53:09 -05:00
Thomas Weber 92da52e4fc This is progress
- if compilation errors, fallback to interpreter
- retire compiled threads once done
- add control_repeat
- add math_whole_number
2020-06-09 20:00:17 -05:00
Thomas Weber 4a93dab4fa What if we compiled the blocks? 2020-06-08 17:59:23 -05:00
Karishma Chadha c499106f85 Revert "Raise params to the next frame when pushing" 2019-07-22 12:59:48 -04:00
Michael "Z" Goddard 50b55a489b fix stopThisScript inside procedures 2019-07-17 15:02:44 -04:00
Michael "Z" Goddard e1254bd8c7 elevate stack block id and frame info into thread
- Add pointer member to thread. This is the current executing block.
- Add stackFrame member to thread. This is the current frame
  information like procedure parameters.

This is a step potentially towards stack-less threads. With further
modifications we could have stack and stackFrames be null if a script
does not call a procedure.
2019-06-03 18:13:01 -04:00
Michael "Z" Goddard 20ff75b776 fix: initialize stack frame params for all procedures
A previous change fixed compatibility with Scratch 2 removing 3's
unintentional scope leaking. This furthers that change so that
procedures with no parameters will also not accidentally use values in
other procedure stacks.
2018-12-13 10:51:44 -05:00
Michael "Z" Goddard fcafcbdd0a return 0 from parameters outside of their procedure 2018-10-23 15:14:31 -04:00
Michael "Z" Goddard d2c637a621 fix asynchronous block execution
Freeze promise waiting blocks into an array of reported values. Thaw
those reported values into parent values of matching blocks by id. If
the reporting block was waiting on a promise and reported a value
assign it to its parent value at that future time.
2018-07-13 00:04:49 -04:00
Michael "Z" Goddard 05291aa254 turn reporter tree into instruction sequence
Turn the reporter tree execute walks into a sequence of block
functions. After calling a block function store the reported value in
the arguments object its depending block will use.

- Set the reported value on the thread. There is only ever one "just"
  reported value, which is read and stored elsewhere after being
  reported.
2018-06-12 14:21:40 -04:00
Michael "Z" Goddard 0634e962a8 Add Thread.StackFrame class
Use a private StackFrame class to help internally manage use of Stack
Frame values and memory. Create params, reported, and executionContext
on demand.
2018-05-07 11:20:26 -04:00
Michael "Z" Goddard 02dd9a8c22 Unset justReported after reading its value
Avoid justReported values leaking to other argValues by setting back to the
default null value.
2018-04-24 19:05:20 -04:00
Michael "Z" Goddard d04d6b2c6a Revert "Revert "Push reported""
This reverts commit 107adad647.
2018-04-16 13:21:53 -04:00
kchadha 107adad647 Revert "Push reported" 2018-02-02 12:42:09 -05:00
Michael "Z" Goddard 4286e3e982 Add Thread.blockContainer
Store the thread's blocks at blockContainer letting execute quickly
determine the block source. Monitor threads are a monitor thread. They
do not become a target thread suddenly.
2018-01-24 17:00:35 -05:00
Michael "Z" Goddard 6b7582f1c7 Report block result to stackFrame.justReported
- Add stackFrame.justReported

Report the block result to a known key `justReported` instead of a
dynamic key on `reported`. Assuming blocks with a promised value are
relatively infrequent the most common recursive input flow immediately
reads the value "just" reported. In the assumed uncommon case of a
promised thread status, empty the already argValues assigned values
onto the currentStackFrame's reported member. In the next execute call
on this stackFrame, values assigned to reported are read back off onto
argValues, and execute will returned to the assumed common case. This
is a safe assumption since a thread in the promise state will not exit
that state until the next frame when javascript has a chance to call
the resolve handle, setting the thread's state back to another
executable state.

Using direct assignment to `justReported` saves building an object
dynamically. Instead of always building `reported` and `argValues` only
`argValues` is built until a promised state is reached. This also gives
a known time when `reported` is used, allowing cleanup of a
stackFrame's reported to only happen when it was used to persist
already reported values.
2018-01-24 17:00:12 -05:00
Paul Kaplan 34dfbb50ba Update naming and implementation for custom procedure blocks 2017-11-16 14:17:08 -05:00
Wang Yu 6ec231db9d Fix the next thread is skipped after clone deleted
Problem:
When a clone is deleted, its thread is removed from the thread
list; but the index "i" in the execution for-loop will still +1,
making the next thread skipped.

Changes:
Added a flag "isKilled" on a thread;
Set the flag when a thread is removed from the thread list;
reduce the "i" counter if the thread of the current loop is removed.
2017-05-12 14:01:37 +08:00
Ray Schamp a4f095db5e Use ES6 style classes 2017-04-17 19:42:48 -04:00
Ray Schamp e01c4ae108 Pass with --fix 2017-04-17 15:10:04 -04:00
griffpatch 9cb595312e Implement "Stop this script" function
Existing implementation incorrectly terminates the entire thread.
See: http://llk.github.io/scratch-vm/#144142535
2017-02-08 09:44:10 +00:00
Ray Schamp 727fcc7875 Lint for eslint-config-scratch@3 2017-02-01 16:27:55 -05:00
Andrew Sliwinski c2a488a197 Merge pull request #408 from griffpatch/optimisation/avoid-negative-index-lookups
Optimisation - Avoid negative index lookups #407
2017-01-30 15:06:02 -05:00
griffpatch fbf2c0c345 Optimisation - Recycle Stack Frame for cosecutive blocks
This saves popping, destroying, recreating, and pushing the stack frame,
and then reassigning the warp mode attribute for every block to block
step in the execution.
2017-01-28 17:06:07 +00:00
griffpatch bd9159b9fb More negative index checks 2017-01-28 14:39:22 +00:00
griffpatch a25e117412 optimisation/avoid negative index lookups #407
Run-time Optimisation

The thread.stackFrames array is accessed all the time to retrieve the
'parent' stack frame. This is done using as index of [this.stack.length
- 1]. However, a lot of the time this evaluated to [-1]. Although this
results in null, which is fine, to get to this javascript actually
defers from a numeric array lookup to an object lookup using the string
"-1". This is roughly 100 times slower to compute and so a simple catch
for negative indexes is well worth the extra check.
2017-01-28 14:38:13 +00:00
Ray Schamp f6c0064235 All linting other than console statements 2016-10-23 22:20:29 -04:00
Ray Schamp 68ed110b49 Pass with eslint --fix
Resolved whitespace issues, e.g., space-before-function-paren and key-spacing
2016-10-23 12:41:45 -04:00
Tim Mickel e49f076fa1 Interpreter fixes, enhancements, features (#280)
* Thread stepping rework; interp.redraw equivalent

* Add turbo mode and pause mode

* Yielding behavior to match Scratch 2.0

* Implement warp-mode procedure threads

* Add check for recursive call

* Inline wait block timer

* Revert to setInterval and always drawing

* Restore yielding in glide

* 30TPS compatibility mode

* 5-call count recursion limit

* Removing dead primitive code

* To simplify, access runtime.threads inline in `stepThreads`.

* Warp mode/timer fixes; recursive check fixes; clean-up

* Add basic single-stepping

* Add single-stepping speed slider

* Allow yielding threads to run in single-stepping

* Restore inactive threads tracking for block glows

* Add clock pausing during pause mode

* Documentation and clean-up throughout

* Don't look for block glows in `thread.topBlock`.

* Add null check for block glows; rename `_updateScriptGlows` to reflect block glowing

* Use the current executed block for glow, instead of stack

* Add more comments to `stepToProcedure`, and re-arrange to match 2.0

* Tweak to Blocks.prototype.getTopLevelScript

* Revert previous

* Fix threads array to be resilient to changes during `stepThreads`

* Restore inactive threads filtering

* Fix typo in "procedure"

* !! instead of == true
2016-10-17 23:23:16 -04:00
Tim Mickel 8c654bbe60 Procedure blocks (#264) 2016-10-13 13:11:26 -04:00
Tim Mickel 9744bcbb70 Clones (#150)
* Provide property to Clone to distinguish "original" clones

* Provide method to clone a clone's properties

* Don't report clones in the UI target list

* Add target info to Thread

* Allow hats to skip clones (for green flag)

* Green flag skips clones

* Implement "create clone" and hat

* Pass the runtime to sprites and clones (for start hats)

* Clone disposal; trigger hats after drawable initializes.

* Separate stop threads for target; fix handling of stop button

* Remove extraneous `skipClones` property

* Add global clone limit

* Don't allow a non-clone to delete itself.

* Rename `cloneClone` -> `makeClone`

* Variable updates in runtime.js

* Synchronous drawable initialization (until we put it back to promises)
2016-09-15 19:37:12 -04:00
Tim Mickel 5df0acc895 Better glows (#152)
* Strip out old script glowing in thread management

* Add new tracking mechanism for glowing scripts

* Track parents and use them to determine script glows

* Use top-block for a thread if there's nothing on the stack

* Remove `console.log`
2016-09-08 09:40:53 -04:00
Tim Mickel 39fdbaf983 Add atStackTop helper to Thread 2016-08-23 18:12:19 -04:00
Tim Mickel de6ba08866 Add single-frame yield mode 2016-07-01 10:44:43 -04:00
Tim Mickel ec4567aa8a Simplify logic for Thread status 2016-06-30 18:56:31 -04:00
Tim Mickel ab6e0d3839 Remove YieldTimers, unused WeDo blocks 2016-06-30 18:56:31 -04:00
Tim Mickel 6daee9a70e Remove VM-locking yield mode per discussion 2016-06-30 18:56:23 -04:00
Tim Mickel d44b806b4f Add blocking yield mode 2016-06-30 18:56:23 -04:00
Tim Mickel 6181bcd5cb Refactor Thread.peekParentStackFrame 2016-06-30 18:56:23 -04:00
Tim Mickel d15c93af05 Keep "waiting reporter name" on the stack frame.
Also add highlighting for inputs.
2016-06-30 18:56:23 -04:00
Tim Mickel 97f7571c6f Prototype implementation of yielding reporters 2016-06-30 18:56:23 -04:00
Tim Mickel 190208b620 Clean up yield-timers: support multiple, move logic to Threads. 2016-06-30 18:56:23 -04:00
Tim Mickel 526a260101 Simplify execution by removing nextBlock
Everything is managed by the stack, including what the execute() function does.
2016-06-09 17:08:30 -04:00
Tim Mickel 9df470255e Add helpers to thread object 2016-06-09 14:22:58 -04:00