<commit_before>#include "scope.h"
#include "details/grammar/nany.h"
#include "details/ir/emit.h"

using namespace Yuni;


namespace ny {
namespace ir {
namespace Producer {


bool Scope::visitASTExprReturn(AST::Node& node) {
	assert(node.rule == AST::rgReturn);
	// assert(not node.children.empty()); -- a return may be empty
	bool success = true;
	bool hasReturnValue = false;
	auto& irout = ircode();
	for (auto& child : node.children) {
		switch (child.rule) {
			case AST::rgExpr: {
				ir::emit::ScopeLocker opscope{irout};
				uint32_t localvar = 0;
				success &= visitASTExpr(child, localvar);
				// generate error on the begining of the expr and not the return itself
				emitDebugpos(child);
				ir::emit::ret(irout, localvar, ir::emit::alloc(irout, nextvar()));
				hasReturnValue = true;
				break;
			}
			default:
				return unexpectedNode(child, "[ir/return]");
		}
	}
	if (not hasReturnValue) {
		emitDebugpos(node);
		ir::emit::ret(irout);
	}
	return success;
}


} // namespace Producer
} // namespace ir
} // namespace ny
<commit_msg>ast2ir: return: rename localvar to retlvid<commit_after>#include "scope.h"
#include "details/grammar/nany.h"
#include "details/ir/emit.h"

using namespace Yuni;


namespace ny {
namespace ir {
namespace Producer {


bool Scope::visitASTExprReturn(AST::Node& node) {
	assert(node.rule == AST::rgReturn);
	// assert(not node.children.empty()); -- a return may be empty
	bool success = true;
	bool hasReturnValue = false;
	auto& irout = ircode();
	for (auto& child : node.children) {
		switch (child.rule) {
			case AST::rgExpr: {
				ir::emit::ScopeLocker opscope{irout};
				uint32_t retlvid = 0;
				success &= visitASTExpr(child, retlvid);
				// generate error on the begining of the expr and not the return itself
				emitDebugpos(child);
				ir::emit::ret(irout, retlvid, ir::emit::alloc(irout, nextvar()));
				hasReturnValue = true;
				break;
			}
			default:
				return unexpectedNode(child, "[ir/return]");
		}
	}
	if (not hasReturnValue) {
		emitDebugpos(node);
		ir::emit::ret(irout);
	}
	return success;
}


} // namespace Producer
} // namespace ir
} // namespace ny

{'fraction_non_alphanumeric': 0.14339268978444236, 'fraction_numerical': 0.0032802249297094657, 'mean_word_length': 3.896788990825688, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1886573', 'n_tokens_mistral': 813, 'n_tokens_neox': 727, 'n_words': 185}