question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generate code for single block in stack only?

See original GitHub issue

Problem statement

I have a stack of blocks, but I only want to generate code for a single block in that stack. Blockly however appends the generated code of subsequent blocks to the one I call Blockly.JavaScript.blockToCode() for.

The only workaround I’ve found is to detach child blocks, generate the code for the block I actually want, and then reattach them. Is there an easier way to do this?

Expected Behavior

I would like some way of getting Blockly.JavaScript.blockToCode(block) not to call the generators of all subsequent blocks in the same stack as the one I want to generate.

Actual Behavior

All child block code is generated and automatically attached to the block’s code that I’m interested in. This causes me all sorts of issues as in on my use case I only want the code for that very specific block even though it has multiple child blocks in its stack.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Marclev78commented, Sep 25, 2018

Yes, so in the example I would want to get all the generated code for [B] (including any the in list it encloses) but not have the generator automatically generate and append the code for [C] to it.

My actual use case is letting my user step through a stack of blocks one by one, so I want to generate and evaluate each block individually.

0reactions
ewpattoncommented, Sep 25, 2018

@rachel-fenichel The feature is accessed through two menu items Generate YAIL (admin only) and Do It (sends to phone REPL). This relies on a function called blockToCode1 in the YAIL generator, which basically is like blockToCode except it passes an additional argument to scrub_ that turns off concatenating the nextConnection block.

To back port, I think it might make sense to add the optional opt_thisOnly argument to blockToCode and scrub_ so that we can collapse the two code paths. In the case of providing a menu option, one might also need a method to tell the system which language to generate. We don’t have this coded since we only have one target language.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to org-babel-tangle only one code block? - Stack Overflow
Is there any way to only tangle one specific code block without changing the header options? I'm generating these files for Sphinx and...
Read more >
Type Checks | Blockly - Google Developers
This block has an input that expects a number, and an output that returns a boolean. Here is the code that specifies this:....
Read more >
A Preliminary Exploration of Optimized Stack Code Generation
This paper presents an experimental code generator that performs intra-block stack scheduling for a stack-based execution model. For small test programs, ...
Read more >
Basic Blocks in Compiler Design - GeeksforGeeks
Basic Block is a straight line code sequence that has no branches in and out branches except to the entry and at the...
Read more >
Stack Block - Scratch Wiki
Stack blocks make up the majority of the blocks available in ... just using a loop, it actually is not all executed in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found