TurboWarp / scratch-vm

Scratch VM with a JIT compiler and more features
https://turbowarp.org/
Mozilla Public License 2.0
75 stars 72 forks source link

Extension loop/conditional support for the compiler #141

Closed CST1229 closed 1 year ago

CST1229 commented 1 year ago

https://github.com/TurboWarp/scratch-vm/assets/68464103/832f84f9-6c2b-4f3b-b580-4f178c641695

Test extension (uploaded as txt because github doesn't like uploading js files): loops-test.js.txt

Resolves

Resolves #98

Proposed Changes

Adds support for Scratch.BlockType.CONDITIONAL and Scratch.BlockType.LOOP extension blocks to the compiler. If you don't know: LOOP runs the inner script if it returns true and doesn't run it otherwise, and CONDITIONAL runs a branch (the branch count being specified by the branchCount block property) starting from 1 (0 to run none) based on the number it returns. For LOOP blocks, util.stackFrame is maintained between runs of the function (but not between runs of the block), so state can be maintained like the primitive repeat block.

Also exports some compiler-related objects. Not anymore.

Types will have to be updated to un-deprecate Scratch.BlockType.LOOP and CONDITIONAL.

Reason for Changes

Fixing bugs, making extensions more powerful and parity with the interpreter.

Test Coverage

Haven't added tests, don't really know how to do that. (I have updated the snapshot tests though) Test runs: 6 failing (there's like 70-something failing tests on develop with failing snapshot tests and 7 failing tests when excluding the snapshot tests so I might not have broken stuff?).

n-d-v commented 1 year ago

this seems like a good idea, as instead of having to do it like this scratchblocks you can do it with one operator block, and one actual like loop block

CST1229 commented 1 year ago

you can do it with one operator block, and one actual like loop block

Note that this PR does not add custom C blocks (it just makes extension-created C blocks work in the compiler), and that run branch () of block I showed in the video is just an example for extension C blocks.

GarboMuffin commented 1 year ago

thanks for your patience on this

GarboMuffin commented 1 year ago

Ignore git complaining about the snapshot tests

Also exports some compiler-related objects.

Do you have a use case in mind for this? The compiler is something I really don't want things touching right now

CST1229 commented 1 year ago

Do you have a use case in mind for this?

The main thing I was doing that for was compiler support for an Inline Blocks extension, but since custom reporters exist now, that probably isn't needed anymore.

GarboMuffin commented 1 year ago

for some reason github will not let me push to this pull request

CST1229 commented 1 year ago

for some reason github will not let me push to this pull request

Weird. image

GarboMuffin commented 1 year ago

Yeah I don't know what's up with that

$ git push CST1229 tw-ext-cblocks
ERROR: Permission to CST1229/scratch-vm.git denied to GarboMuffin.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I'm superseding this with https://github.com/TurboWarp/scratch-vm/pull/158