Commit a440a0d0 authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Add clang-format

parent 467487ec
Pipeline #38898 failed with stage
Showing with 58 additions and 38 deletions
+58 -38
---
# We'll use defaults from the Google style, but with 4 columns indentation.
BasedOnStyle: Google
# Never allow single-line functions
AllowShortFunctionsOnASingleLine: None
# Put "else" on a new line
BreakBeforeBraces: Custom
BraceWrapping:
BeforeElse: true
# Allow lines up to 90 characters
ColumnLimit: 90
# Indent each block by 4 spaces
IndentWidth: 4
TabWidth: 4
# Require 1 space before a comment on the same line
SpacesBeforeTrailingComments: 1
# Put a space after a cast, e.g. `(void) arg;`
SpaceAfterCStyleCast: true
---
#!/bin/bash
if loc="$(type -p "clang-format")" && [[ -x $loc ]]; then
for name in $(git diff --cached --name-only --diff-filter=ACM); do
if echo $name | grep -Eq "\.[ch]$"; then
echo "Formatting ${name}..."
clang-format -i $name
fi
done
else
echo "You do not have clang-format installed; so, we were unable to unify the formatting in your files."
fi
......@@ -11,16 +11,7 @@
#include <stdint.h>
/** The types of AST nodes */
typedef enum {
NUM,
BINARY_OP,
VAR,
SEQUENCE,
PRINT,
LET,
IF,
WHILE
} node_type_t;
typedef enum { NUM, BINARY_OP, VAR, SEQUENCE, PRINT, LET, IF, WHILE } node_type_t;
/** The type of a TeenyBASIC variable name */
typedef char var_name_t;
......
#ifndef PARSER_H
#define PARSER_H
#include <stdio.h>
#include "ast.h"
/** Parses the next statement from the provided TeenyBASIC file into an AST */
......
#include <inttypes.h>
#include <stdio.h>
#include "ast.h"
// A function that can be called from assembly to print an integer
void print_int(value_t value) {
printf("%" PRId64 "\n", value);
// Clobber all caller-save registers
asm(
"movq $0x6A2CFE91073BD845, %%rax\n"
asm("movq $0x6A2CFE91073BD845, %%rax\n"
"movq $0x03BAD7C14F2E6589, %%rdi\n"
"movq $0x5D41EA960C72F8B3, %%rsi\n"
"movq $0xEC364B2D5A7F9810, %%rdx\n"
......@@ -16,6 +16,7 @@ void print_int(value_t value) {
"movq $0x92E1587A4BDCF630, %%r9\n"
"movq $0x47DC36501F89AEB2, %%r10\n"
"movq $0xAF4B29785C61ED30, %%r11\n"
: : : "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r10", "r11"
);
:
:
: "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r10", "r11");
}
#include <assert.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
......@@ -51,9 +51,7 @@ int main(int argc, char *argv[]) {
printf(
"test_name,mean_log_duration,variance_log_duration\n"
"%s,%f,%e\n",
test_name, mean_log_duration, variance_log_duration
);
fprintf(stderr, "%s mean duration: %e seconds (+/- %e x)\n",
test_name, exp(mean_log_duration), expm1(sqrt(variance_log_duration))
);
test_name, mean_log_duration, variance_log_duration);
fprintf(stderr, "%s mean duration: %e seconds (+/- %e x)\n", test_name,
exp(mean_log_duration), expm1(sqrt(variance_log_duration)));
}
#include "ast.h"
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "ast.h"
node_t *init_num_node(value_t value) {
num_node_t *node = malloc(sizeof(num_node_t));
assert(node != NULL);
......
#include <stdlib.h>
#include <stdio.h>
#include "compile.h"
#include <stdio.h>
#include <stdlib.h>
bool compile_ast(node_t *node) {
/* You should remove this cast to void in your solution.
* It is just here so the code compiles without warnings. */
......
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include "parser.h"
#include "compile.h"
#include "parser.h"
void usage(char *program) {
fprintf(stderr, "USAGE: %s <program file>\n", program);
......@@ -20,8 +20,7 @@ void header(void) {
".text\n"
".globl basic_main\n"
"basic_main:\n"
" # The main() function\n"
);
" # The main() function\n");
}
/**
......@@ -30,9 +29,7 @@ void header(void) {
* goes between the header and the footer.
*/
void footer(void) {
printf(
" ret\n"
);
printf(" ret\n");
}
int main(int argc, char *argv[]) {
......
#include "parser.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
......@@ -6,8 +8,6 @@
#include <stdlib.h>
#include <string.h>
#include "parser.h"
// maxint = -9223372036854775808
const size_t MAX_KEYWORD_LENGTH = 100;
const value_t DEFAULT_STEP = 1;
......@@ -35,8 +35,8 @@ bool is_comparison_op(char c) {
return c == '<' || c == '=' || c == '>';
}
bool is_operator(char c) {
return is_open_paren(c) || is_close_paren(c) ||
is_factor_op(c) || is_term_op(c) || is_comparison_op(c);
return is_open_paren(c) || is_close_paren(c) || is_factor_op(c) || is_term_op(c) ||
is_comparison_op(c);
}
bool is_comment_start(char c) {
return c == '#';
......@@ -340,7 +340,7 @@ node_t *sequence(parser_state_t *state) {
if (statement_count == statement_capacity) {
statement_capacity = statement_capacity > 0 ? statement_capacity * 2 : 1;
statements = realloc(statements, sizeof(node_t*[statement_capacity]));
statements = realloc(statements, sizeof(node_t *[statement_capacity]));
assert(statements != NULL);
}
statements[statement_count++] = next;
......@@ -354,7 +354,7 @@ node_t *sequence(parser_state_t *state) {
}
if (statement_count > 0) {
statements = realloc(statements, sizeof(node_t*[statement_count]));
statements = realloc(statements, sizeof(node_t *[statement_count]));
assert(statements != NULL);
}
return init_sequence_node(statement_count, statements);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment