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

Extension loop/conditional support for the compiler #141

Closed
wants to merge 10 commits into from

Conversation

CST1229
Copy link

@CST1229 CST1229 commented Jun 22, 2023

ytmsOZFM3Z.mp4

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
Copy link

n-d-v commented Aug 4, 2023

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
Copy link
Author

CST1229 commented Aug 4, 2023

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
Copy link
Member

thanks for your patience on this

@GarboMuffin
Copy link
Member

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
Copy link
Author

CST1229 commented Aug 9, 2023

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
Copy link
Member

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

@CST1229
Copy link
Author

CST1229 commented Aug 22, 2023

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

Weird.
image

@GarboMuffin
Copy link
Member

GarboMuffin commented Aug 22, 2023

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 #158

GarboMuffin added a commit to TurboWarp/extensions that referenced this pull request Aug 22, 2023
GarboMuffin added a commit to TurboWarp/extensions that referenced this pull request Aug 22, 2023
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.

Compiler does not support custom extension C-blocks
3 participants