<commit_before>// 
// In C, it's difficult to have code that is variadic based on run time
// parameters. For instance you can't make C easily create a long as variable
// "a" in some cases and a byte as variable "a" in other cases based on some
// runtime variable's contents. You have to switch based on the type, often
// allocate memory and do a lot of extra work, and that makes everything
// complicated and time consuming to write.
//
// This code creates some macros that make it easier to write C code that
// varies by type.
//
// TODO VARY_*() macros need to handle general list more robustly
// TODO VARY_*() should be able to cast to best sizes in some circumstances
// TODO consider switching to ribosome of these kinds of scripts
//
var lib = require('./common.js');
function skip(t) {
	t=t[1];
	return (lib.dontcast.indexOf(t)!=-1)?true:false;
}
console.log(lib.prelude + 
	"// vary on a single element. unpacks x[i] into a C variable \n"+
	"// called _x, of the correct c native type. then executes \n"+
	"// your code (stmt). If it's a type that can't be unpacked, \n"+
	"// the TAG of the type is set in failvar, you can handle it. \n\n"+
	"// VARY_EL varies over one element: x[i]. \n"+
	"#define VARY_EL(x,i,stmt,failvar) ({ \\");
var tmpls=[
	"\tif(x->t=={{x0}}){/*cant vary {{x2}}*/ failvar={{x0}};}\\",
	"\tif(x->t=={{x0}}){/*{{x2}}*/{{x3}} _x=AS_{{x1}}(x,i); stmt;}\\" 
];
lib.each(lib.types,function(tx) {
	if(skip(tx))tmpl=tmpls[0];
	else tmpl=tmpls[1];
	var a=[];
	for(var i in tx)a["x"+i]=tx[i];
	console.log(lib.exhaust(lib.projr(lib.repl,a),tmpl));
});
console.log("})");

console.log("#define VARY_EACH(x,stmt,failvar) ({ \\\n" +
	"\tint _i=0,_xn=x->n,_xt=x->t; /*PF(\"VE\");DUMP(x);*/\\");
var tmpl="\tif(_xt=={{x0}}){/*cant vary {{x2}}*/ failvar={{x0}}; }\\";
lib.each(lib.types,function(tx) {
	if(skip(tx)){
		var a=[];<commit_msg>make vary macro output more verbose - absolutely zero help with debugging<commit_after>// 
// In C, it's difficult to have code that is variadic based on run time
// parameters. For instance you can't make C easily create a long as variable
// "a" in some cases and a byte as variable "a" in other cases based on some
// runtime variable's contents. You have to switch based on the type, often
// allocate memory and do a lot of extra work, and that makes everything
// complicated and time consuming to write.
//
// This code creates some macros that make it easier to write C code that
// varies by type.
//
// TODO VARY_*() macros need to handle general list more robustly
// TODO VARY_*() should be able to cast to best sizes in some circumstances
// TODO consider switching to ribosome of these kinds of scripts
//
var lib = require('./common.js');
function skip(t) {
	t=t[1];
	return (lib.dontcast.indexOf(t)!=-1)?true:false;
}
console.log(lib.prelude + 
	"// vary on a single element. unpacks x[i] into a C variable \n"+
	"// called _x, of the correct c native type. then executes \n"+
	"// your code (stmt). If it's a type that can't be unpacked, \n"+
	"// the TAG of the type is set in failvar, you can handle it. \n\n"+
	"// VARY_EL varies over one element: x[i]. \n"+
	"#define VARY_EL(x,i,stmt,failvar) ({ \\");
var tmpls=[
	"\tif(x->t=={{x0}}){/*cant vary {{x2}}*/ failvar={{x0}};}\\",
	"\tif(x->t=={{x0}}){/*{{x2}}*/\\\n"+
	"\t\t{{x3}} _x=AS_{{x1}}(x,i);\\\n"+
	"\t\tstmt;}\\" 
];
lib.each(lib.types,function(tx) {
	if(skip(tx))tmpl=tmpls[0];
	else tmpl=tmpls[1];
	var a=[];
	for(var i in tx)a["x"+i]=tx[i];
	console.log(lib.exhaust(lib.projr(lib.repl,a),tmpl));
});
console.log("})");

console.log("#define VARY_EACH(x,stmt,failvar) ({ \\\n" +
	"\tint _i=0,_xn=x->n,_xt=x->t; /*PF(\"VE\");DUMP(x);*/\\");
var tmpl="\tif(_xt=={{x0}}){/*cant vary {{x2}}*/ failvar={{x0}}; }\\";
lib.each(lib.types,function(tx) {
	if(skip(tx)){
		var a=[];
{'fraction_non_alphanumeric': 0.20041917736442233, 'fraction_numerical': 0.007859575582918523, 'mean_word_length': 3.7844611528822054, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6654999', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1408, 'n_words': 466}