mirror of
				https://github.com/nicbarker/clay.git
				synced 2025-11-04 00:26:17 +00:00 
			
		
		
		
	Remove generator directory
This commit is contained in:
		
							parent
							
								
									c7b8ff15ec
								
							
						
					
					
						commit
						0604e3a87e
					
				| 
						 | 
					@ -1,7 +0,0 @@
 | 
				
			||||||
$TYPE$ *$NAME$_Add($NAME$ *array, $TYPE$ item) {
 | 
					 | 
				
			||||||
	if (Clay__Array_AddCapacityCheck(array->length, array->capacity)) {
 | 
					 | 
				
			||||||
		array->internalArray[array->length++] = item;
 | 
					 | 
				
			||||||
		return &array->internalArray[array->length - 1];
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return $DEFAULT_VALUE$;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,5 +0,0 @@
 | 
				
			||||||
void $NAME$_Add($NAME$ *array, $TYPE$ item) {
 | 
					 | 
				
			||||||
	if (Clay__Array_AddCapacityCheck(array->length, array->capacity)) {
 | 
					 | 
				
			||||||
		array->internalArray[array->length++] = item;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,3 +0,0 @@
 | 
				
			||||||
$NAME$ $NAME$_Allocate_Arena(int32_t capacity, Clay_Arena *arena) {
 | 
					 | 
				
			||||||
    return CLAY__INIT($NAME$){.capacity = capacity, .length = 0, .internalArray = ($TYPE$ *)Clay__Array_Allocate_Arena(capacity, sizeof($TYPE$), CLAY__ALIGNMENT($TYPE$), arena)};
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,3 +0,0 @@
 | 
				
			||||||
$NAME$ $NAME$_Allocate_Arena(int32_t capacity, Clay_Arena *arena) {
 | 
					 | 
				
			||||||
    return CLAY__INIT($NAME$){.capacity = capacity, .length = 0, .internalArray = ($TYPE$ *)Clay__Array_Allocate_Arena(capacity, sizeof($TYPE$), CLAY__POINTER_ALIGNMENT, arena)};
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,6 +0,0 @@
 | 
				
			||||||
typedef struct
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int32_t capacity;
 | 
					 | 
				
			||||||
	int32_t length;
 | 
					 | 
				
			||||||
	$TYPE$ *internalArray;
 | 
					 | 
				
			||||||
} $NAME$;
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,5 +0,0 @@
 | 
				
			||||||
typedef struct
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int32_t length;
 | 
					 | 
				
			||||||
	$TYPE$ *internalArray;
 | 
					 | 
				
			||||||
} $NAME$Slice;
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,3 +0,0 @@
 | 
				
			||||||
$TYPE$ *$NAME$_Get($NAME$ *array, int32_t index) {
 | 
					 | 
				
			||||||
    return Clay__Array_RangeCheck(index, array->length) ? &array->internalArray[index] : $DEFAULT_VALUE$;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,3 +0,0 @@
 | 
				
			||||||
$TYPE$ *$NAME$Slice_Get($NAME$Slice *slice, int32_t index) {
 | 
					 | 
				
			||||||
    return Clay__Array_RangeCheck(index, slice->length) ? &slice->internalArray[index] : $DEFAULT_VALUE$;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,3 +0,0 @@
 | 
				
			||||||
$TYPE$ $NAME$_Get($NAME$ *array, int32_t index) {
 | 
					 | 
				
			||||||
    return Clay__Array_RangeCheck(index, array->length) ? array->internalArray[index] : $DEFAULT_VALUE$;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,9 +0,0 @@
 | 
				
			||||||
$TYPE$ $NAME$_RemoveSwapback($NAME$ *array, int32_t index) {
 | 
					 | 
				
			||||||
	if (Clay__Array_RangeCheck(index, array->length)) {
 | 
					 | 
				
			||||||
		array->length--;
 | 
					 | 
				
			||||||
		$TYPE$ removed = array->internalArray[index];
 | 
					 | 
				
			||||||
		array->internalArray[index] = array->internalArray[array->length];
 | 
					 | 
				
			||||||
		return removed;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return $DEFAULT_VALUE$;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,6 +0,0 @@
 | 
				
			||||||
void $NAME$_Set($NAME$ *array, int32_t index, $TYPE$ value) {
 | 
					 | 
				
			||||||
	if (Clay__Array_RangeCheck(index, array->capacity)) {
 | 
					 | 
				
			||||||
		array->internalArray[index] = value;
 | 
					 | 
				
			||||||
		array->length = index < array->length ? array->length : index + 1;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,69 +0,0 @@
 | 
				
			||||||
const fs = require('fs');
 | 
					 | 
				
			||||||
const path = require('path');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
let files = ['../clay.h'];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
let templates = ['./'];
 | 
					 | 
				
			||||||
function readCTemplatesRecursive(directory) {
 | 
					 | 
				
			||||||
    fs.readdirSync(directory).forEach(template => {
 | 
					 | 
				
			||||||
        const absolute = path.join(directory, template);
 | 
					 | 
				
			||||||
        if (fs.statSync(absolute).isDirectory()) return readCTemplatesRecursive(absolute);
 | 
					 | 
				
			||||||
        else if (template.endsWith('template.c')) {
 | 
					 | 
				
			||||||
            return templates.push(absolute);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
readCTemplatesRecursive(__dirname);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
for (const file of files) {
 | 
					 | 
				
			||||||
    const contents = fs.readFileSync(file, 'utf8');
 | 
					 | 
				
			||||||
    const lines = contents.split('\n');
 | 
					 | 
				
			||||||
    for (let i = 0; i < lines.length; i++) {
 | 
					 | 
				
			||||||
        const line = lines[i];
 | 
					 | 
				
			||||||
        if (line.startsWith('// __GENERATED__ template')) {
 | 
					 | 
				
			||||||
            const [comment, generated, templateOpen, templateNames, ...args] = line.split(" ");
 | 
					 | 
				
			||||||
            let matchingEndingLine = -1;
 | 
					 | 
				
			||||||
            for (let j = i + 1; j < lines.length; j++) {
 | 
					 | 
				
			||||||
                if (lines[j].startsWith('// __GENERATED__ template')) {
 | 
					 | 
				
			||||||
                    matchingEndingLine = j;
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (matchingEndingLine !== -1) {
 | 
					 | 
				
			||||||
                i++;
 | 
					 | 
				
			||||||
                lines.splice(i, matchingEndingLine - (i));
 | 
					 | 
				
			||||||
                lines.splice(i, 0, ['#pragma region generated']);
 | 
					 | 
				
			||||||
                i++;
 | 
					 | 
				
			||||||
                for (const templateName of templateNames.split(',')) {
 | 
					 | 
				
			||||||
                    var matchingTemplate = templates.find(t => t.endsWith(`${templateName}.template.c`));
 | 
					 | 
				
			||||||
                    if (matchingTemplate) {
 | 
					 | 
				
			||||||
                        let templateContents = fs.readFileSync(matchingTemplate, 'utf8');
 | 
					 | 
				
			||||||
                        for (const arg of args) {
 | 
					 | 
				
			||||||
                            [argName, argValue] = arg.split('=');
 | 
					 | 
				
			||||||
                            templateContents = templateContents.replaceAll(`\$${argName}\$`, argValue);
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                        let remainingTokens = templateContents.split('$');
 | 
					 | 
				
			||||||
                        if (remainingTokens.length > 1) {
 | 
					 | 
				
			||||||
                            console.log(`Error at ${file}:${i}: Template is missing parameter ${remainingTokens[1]}`)
 | 
					 | 
				
			||||||
                            process.exit();
 | 
					 | 
				
			||||||
                        } else {
 | 
					 | 
				
			||||||
                            templateContents = templateContents.split('\n');
 | 
					 | 
				
			||||||
                            lines.splice(i, 0, ...templateContents);
 | 
					 | 
				
			||||||
                            i += templateContents.length;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    } else {
 | 
					 | 
				
			||||||
                        console.log(`Error at ${file}:${i + 1}: no template with name ${templateName}.template.c was found.`);
 | 
					 | 
				
			||||||
                        process.exit();
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                lines.splice(i, 0, ['#pragma endregion']);
 | 
					 | 
				
			||||||
                i++;
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                console.log(`Error at ${file}:${i + 1}: template was opened and not closed again.`);
 | 
					 | 
				
			||||||
                process.exit();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    fs.writeFileSync(file, lines.join('\n'));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in a new issue