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

Func statement solution #28

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*/build/**
*/dist/**
*/.idea/**
.idea
2 changes: 1 addition & 1 deletion block-lexical-variables/src/blocks/lexical-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ Blockly.Blocks['local_declaration_expression'] = {
this.setStyle('variables_blocks');
this.initLocals();
// this.appendIndentedValueInput('RETURN')
this.appendValueInput('RETURN')
this.appendStatementInput('STACK')
.appendField(
Blockly.Msg.LANG_VARIABLES_LOCAL_DECLARATION_EXPRESSION_IN_RETURN);
// Create plug for expression output
Expand Down
9 changes: 9 additions & 0 deletions block-lexical-variables/src/blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,3 +1056,12 @@ Blockly.Blocks['procedures_callreturn'] = {
removeProcedureValue:
Blockly.Blocks.procedures_callnoreturn.removeProcedureValue,
};

Blockly.Blocks['procedures_ifreturn'] = {
init: function() {
this.appendValueInput('VALUE').appendField(
"RETURN");
this.setPreviousStatement(true);
this.setStyle('procedure_blocks');
},
};
25 changes: 22 additions & 3 deletions block-lexical-variables/src/generators/lexical-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,26 @@ javascriptGenerator['local_declaration_statement'] = function() {
return code;
};

javascriptGenerator['local_declaration_expression'] = function() {
// TODO
return 'NOT IMPLEMENTED YET';

Blockly.JavaScript['local_declaration_expression'] = function() {
let code = '(function() {\n ';
let hasVar = this.getFieldValue('VAR0')
if(hasVar) {
code += 'let '
for (let i=0; this.getFieldValue('VAR' + i); i++) {
code += (Shared.usePrefixInCode ? 'local_' : '') +
this.getFieldValue('VAR' + i);
code += ' = ' + ( Blockly.JavaScript.valueToCode(this,
'DECL' + i, Blockly.JavaScript.ORDER_NONE) || '0' );
code += ', ';
}
// Get rid of the last comma
code = code.slice(0, -2);
code += ';\n';
}

code += Blockly.JavaScript.statementToCode(this, 'STACK',
Blockly.JavaScript.ORDER_NONE);
code += '\n})()\n';
return [code, Blockly.JavaScript.ORDER_NONE];
};
5 changes: 5 additions & 0 deletions block-lexical-variables/src/generators/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ javascriptGenerator['procedures_callreturn'] = function(block) {
const code = funcName + '(' + args.join(', ') + ')';
return [code, javascriptGenerator.ORDER_FUNCTION_CALL];
};

Blockly.JavaScript['procedures_ifreturn'] = function (block) {
let retVal = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_ATOMIC);
return '\nreturn ' + retVal + ';\n'
};