Giter VIP home page Giter VIP logo

scratch-vm's Introduction

TurboWarp/scratch-vm

Modified Scratch VM with a JIT compiler and more features.

This is a drop-in replacement for LLK/scratch-vm.

Setup

See https://github.com/TurboWarp/scratch-gui/wiki/Getting-Started to setup the complete TurboWarp environment.

If you just want to play with the VM then it's the same process as upstream scratch-vm.

Extension authors

If you only use the standard reporter, boolean, and command block types, everything should just work without any changes.

Compiler Overview

For a high-level overview of how the compiler works, see https://docs.turbowarp.org/how

For more technical information, read the code in src/compiler.

Public API

This section was too out of date to be useful. We hope to re-add it as some point.

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

This program is based on scratchfoundation/scratch-vm, which is under this license:

Copyright (c) 2016, Massachusetts Institute of Technology
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

scratch-vm's People

Contributors

adroitwhiz avatar apple502j avatar chrisgarrity avatar cwillisf avatar dependabot-preview[bot] avatar ericrosenbaum avatar evhan55 avatar fsih avatar garbomuffin avatar gnarf avatar greenkeeper[bot] avatar griffpatch avatar hyperobject avatar joker314 avatar kchadha avatar kenny2github avatar khanning avatar knandersen avatar ktbee avatar mzgoddard avatar paulkaplan avatar picklesrus avatar renovate-bot avatar renovate[bot] avatar rschamp avatar semantic-release-bot avatar thebrokenrail avatar thisandagain avatar tmickel avatar towerofnix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scratch-vm's Issues

Get the extension worker to work

Expected Behavior

Extension worker should work

Actual Behavior

No idea if it works, probably not. I'm guessing that it shouldn't be hard because we already have the compatibility layer?

Precompile scripts

Expected Behavior

All script compiling should happen when the project first starts to avoid stutters later

Actual Behavior

Script compiling can cause stutters because it happens lazily

Track variable types

Expected Behavior

The compiler should be able to reason about the types of variables.

Actual Behavior

The compiler is unable to reason about variable types -- everything is TYPE_UNKNOWN

Clone-based multithreading

See if it's possible to make clones opt into some form of Worker-based multithreading

  • only mutate local variables
  • no interacting with rendering
  • need some special API to postMessage to the main thread

Compat layer by default

Instead of maintaining a list of opcodes to run in compat, we should just assume that everything will work just fine

Potential edge case with clones and variables

// If the sprite being compiled right now is a clone, we should also create the variable in the original sprite.
// This is necessary because the script cache is shared between clones, and clones won't inherit this variable.
if (!target.isOriginal) {
// The original sprite will usually be the first item of `clones`, but it's possible that it might not be.
const original = this.target.sprite.clones.find(t => t.isOriginal);
if (original && !original.variables.hasOwnProperty(id)) {
original.variables[id] = new Variable(id, name, type, false);
}
}

Need to see if we also need to create the var in all other existing clones, not just any new ones going forward

Support for Scratch lab stuff?

There are a bunch of Turbowarp repos so I wasn't sure where to go.

Scratch has released Scratch Lab with two new features. These will probably be improved and eventually added to normal Scratch. Should Turbowarp include these?

Compile to WASM

It may be possible to compile a subset of Scratch blocks to webassembly for performance.

"Play sound" blocks don't end in project 53005142

Expected Behavior

Sound should work and this should run well

Actual Behavior

Seems to run at full framerate, but the sound is absolutely horrible.

Steps to Reproduce

  1. Open Scratch project 53005142 in Turbowarp
  2. Play project
  3. Listen

Operating System and Browser

Windows 10, Edge 86.0.622.38

Highlighting procedure execution

Right now only the entrypoint script can get highlighted.

This should be changed so that (non-warp?) procedures can also get highlighted. This should be more possible now because topBlockId is in IntermediateScript

Cloud

A question. Will using cloud allow users to bypass the usual restrictions on editing a project while still updating cloud variables? It feels like this has the potential to make it too easy for users to hack and break our cloud high scores, etc? Or does it work a different way? With great power comes great responsibility!

Complete KEY PRESSED? and WHEN KEY PRESSED blocks behavior

Expected Behavior

Foreign language chars (e.g. Italian accented chars à è é ì ò ù ) are recognized by the KEY PRESSED? and WHEN KEY PRESSED blocks

Actual Behavior

Foreign language chars (e.g. Italian accented chars à è é ì ò ù ) are not recognized by the KEY PRESSED? and WHEN KEY PRESSED blocks

Steps to Reproduce

Operating System and Browser

e.g. Mac OS 10.15.7 Chrome 88

Don't hardcode menus in irgen

Upstream does this:

        // Store the current shadow value if there is a shadow value.
        const fieldKeys = Object.keys(fields);
        this._isShadowBlock = (
            !this._definedBlockFunction &&
            fieldKeys.length === 1 &&
            Object.keys(inputs).length === 0
        );
        this._shadowValue = this._isShadowBlock && fields[fieldKeys[0]].value;

Glow with compiler enabled

Expected Behavior

https://turbowarp.org/453148564/editor works with compiler enabled

Actual Behavior

Scripts do not glow if the compiler is enabled

Steps to Reproduce

Go to https://turbowarp.org/453148564/editor, enable turbo mode, zoom out all the way (necessary due to an upstream performance issue), run. Note that the pixels do not glow. Disable compiler, note that pixels do glow. Shudder in horror at the abomination.

Operating System and Browser

Linux, Chromium

Notes

I'd be happy to write the necessary patch, though I'm not quite sure why this is happening - if you can give me some pointers to whereish you think the patch should be, I'll take a stab at this.

It's probably a good idea to make glow optional, it has some performance issues.

Reuse more objects in AST generation

AST generation currently creates a large amount of objects. A lot of these objects, such as motion.x. don't need to be new nodes, but could just be pointers to a single global instance of that node.

Support compiling scripts where the root is an "input" or "nested block"

Expected Behavior

A script that starts with "touching color red" or "is compiled?" should be compiled.

Actual Behavior

Any script that doesn't start with a non-stacked block cannot be compiled.

This presents an awkward situation where the "is compiled?" block will return 0 when users click on it on its own, but true when they use it in their scripts.

Wait block behaves differently

Expected Behavior

The wait _ seconds block should behave as it does in the official Scratch player.

Actual Behavior

The wait _ seconds block does not wait as long as it should.

Steps to Reproduce

Run this project in both Scratch and TurboWarp: https://scratch.mit.edu/projects/416669082/

Operating System and Browser

Windows 10 2004 Edge 84.0.522.52

How do you run this?

Sorry, this is not an issue. I would really like to know how TurboWarp can be installed and run locally or on a web server. Every configuration you used, even specific to your installation, would be good enough for me. Thanks in advance.

Maximum recursion of procedures is much lower than Scratch

Expected Behavior

https://scratch.mit.edu/projects/116680081/ should work

Actual Behavior

It errors with Uncaught RangeError: Maximum call stack size exceeded

This seems to be caused by the project using recursion as an alternative to repeat something 40,000 times.

We are limited by the call stack size of the browser because we use actual JS recursion, whereas Scratch's interpreter uses a list that allows essentially infinite recursion.

Steps to Reproduce

https://turbowarp.org/116680081

Operating System and Browser

Happens in all browsers.

Variable type analysis can be better

Expected Behavior

Given this script:

image

The compiler should be able to conclude that first, second, nth, i will always be numbers and optimize accordingly:

b1.value = 0;
b2.value = 1;
b3.value = 1;
b4.value = 2;
while (b4.value > p0) {
    b3.value = b1.value + b2.value;
    b1.value = b2.value;
    b2.value = b3.value;
    b4.value = b4.value + 1;
}
b0.value = b3.value;

Actual Behavior

It's not very smart. The script is compiled as:

b1.value = 0;
b2.value = 1;
b3.value = 1;
b4.value = 2;
while (!compareGreaterThan(b4.value, p0)) {
    b3.value = ((+b1.value || 0) + (+b2.value || 0));
    b1.value = b2.value;
    b2.value = b3.value;
    b4.value = ((+b4.value || 0) + 1);
}

https://share.firefox.dev/2V2lI9z

Move warp tracking to procedure call

Move it from being hardcoded into the definition to being set when going from a non-warp -> warp procedure.

This might be a a couple % improvement

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.