Apply new formatting

This commit is contained in:
Tom Willemse 2022-08-14 16:13:49 -07:00
parent cb42c81121
commit e91006b59a
8 changed files with 20 additions and 18 deletions

1
clox/src/.clang-format Normal file
View file

@ -0,0 +1 @@
BreakBeforeBinaryOperators: All

View file

@ -23,8 +23,8 @@ void writeChunk(Chunk *chunk, uint8_t byte, int line) {
if (chunk->capacity < chunk->count + 1) { if (chunk->capacity < chunk->count + 1) {
int oldCapacity = chunk->capacity; int oldCapacity = chunk->capacity;
chunk->capacity = GROW_CAPACITY(oldCapacity); chunk->capacity = GROW_CAPACITY(oldCapacity);
chunk->code = chunk->code
GROW_ARRAY(uint8_t, chunk->code, oldCapacity, chunk->capacity); = GROW_ARRAY(uint8_t, chunk->code, oldCapacity, chunk->capacity);
chunk->lines = GROW_ARRAY(int, chunk->lines, oldCapacity, chunk->capacity); chunk->lines = GROW_ARRAY(int, chunk->lines, oldCapacity, chunk->capacity);
} }

View file

@ -208,8 +208,8 @@ static void initCompiler(Compiler *compiler, FunctionType type) {
compiler->function = newFunction(); compiler->function = newFunction();
current = compiler; current = compiler;
if (type != TYPE_SCRIPT) { if (type != TYPE_SCRIPT) {
current->function->name = current->function->name
copyString(parser.previous.start, parser.previous.length); = copyString(parser.previous.start, parser.previous.length);
} }
Local *local = &current->locals[current->localCount++]; Local *local = &current->locals[current->localCount++];
@ -245,8 +245,9 @@ static void beginScope() { current->scopeDepth++; }
static void endScope() { static void endScope() {
current->scopeDepth--; current->scopeDepth--;
while (current->localCount > 0 && while (current->localCount > 0
current->locals[current->localCount - 1].depth > current->scopeDepth) { && current->locals[current->localCount - 1].depth
> current->scopeDepth) {
if (current->locals[current->localCount - 1].isCaptured) { if (current->locals[current->localCount - 1].isCaptured) {
emitByte(OP_CLOSE_UPVALUE); emitByte(OP_CLOSE_UPVALUE);
} else { } else {
@ -399,8 +400,8 @@ static void method() {
uint8_t constant = identifierConstant(&parser.previous); uint8_t constant = identifierConstant(&parser.previous);
FunctionType type = TYPE_METHOD; FunctionType type = TYPE_METHOD;
if (parser.previous.length == 4 && if (parser.previous.length == 4
memcmp(parser.previous.start, "init", 4) == 0) { && memcmp(parser.previous.start, "init", 4) == 0) {
type = TYPE_INITIALIZER; type = TYPE_INITIALIZER;
} }

View file

@ -3,7 +3,7 @@
#include "chunk.h" #include "chunk.h"
void disassembleChunk(Chunk* chunk, const char* name); void disassembleChunk(Chunk *chunk, const char *name);
int disassembleInstruction(Chunk* chunk, int offset); int disassembleInstruction(Chunk *chunk, int offset);
#endif #endif

View file

@ -49,8 +49,8 @@ void markObject(Obj *object) {
if (vm.grayCapacity < vm.grayCount + 1) { if (vm.grayCapacity < vm.grayCount + 1) {
vm.grayCapacity = GROW_CAPACITY(vm.grayCapacity); vm.grayCapacity = GROW_CAPACITY(vm.grayCapacity);
vm.grayStack = vm.grayStack
(Obj **)realloc(vm.grayStack, sizeof(Obj *) * vm.grayCapacity); = (Obj **)realloc(vm.grayStack, sizeof(Obj *) * vm.grayCapacity);
if (vm.grayStack == NULL) if (vm.grayStack == NULL)
exit(1); exit(1);
} }

View file

@ -97,8 +97,8 @@ static void skipWhitespace() {
static TokenType checkKeyword(int start, int length, const char *rest, static TokenType checkKeyword(int start, int length, const char *rest,
TokenType type) { TokenType type) {
if (scanner.current - scanner.start == start + length && if (scanner.current - scanner.start == start + length
memcmp(scanner.start + start, rest, length) == 0) { && memcmp(scanner.start + start, rest, length) == 0) {
return type; return type;
} }

View file

@ -131,8 +131,8 @@ ObjString *tableFindString(Table *table, const char *chars, int length,
/* Stop if we find an empty non-tombstone entry. */ /* Stop if we find an empty non-tombstone entry. */
if (IS_NIL(entry->value)) if (IS_NIL(entry->value))
return NULL; return NULL;
} else if (entry->key->length == length && entry->key->hash == hash && } else if (entry->key->length == length && entry->key->hash == hash
memcmp(entry->key->chars, chars, length) == 0) { && memcmp(entry->key->chars, chars, length) == 0) {
/* We found it. */ /* We found it. */
return entry->key; return entry->key;
} }

View file

@ -15,8 +15,8 @@ void writeValueArray(ValueArray *array, Value value) {
if (array->capacity < array->count + 1) { if (array->capacity < array->count + 1) {
int oldCapacity = array->capacity; int oldCapacity = array->capacity;
array->capacity = GROW_CAPACITY(oldCapacity); array->capacity = GROW_CAPACITY(oldCapacity);
array->values = array->values
GROW_ARRAY(Value, array->values, oldCapacity, array->capacity); = GROW_ARRAY(Value, array->values, oldCapacity, array->capacity);
} }
array->values[array->count] = value; array->values[array->count] = value;