Skip to content

Commit 52652c8

Browse files
committed
Apply clang-format to all files
1 parent 0598a2e commit 52652c8

30 files changed

Lines changed: 225 additions & 389 deletions

src/commandlanguage/command_exec.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#ifndef COMMAND_EXEC_H
22
#define COMMAND_EXEC_H
33

4-
#include "src/runtime/runtime.h"
5-
64
#include "src/commandlanguage/command_parser.h"
5+
#include "src/runtime/runtime.h"
76

87
/**
98
* Execute a single top-level command in the given runtime.

src/commandlanguage/command_parser.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ ShowKeyword command_parse_show_type(Parser *p) {
292292
return SHOW_KW_STATE;
293293
}
294294

295-
parser_error(
296-
p, "expected 'Context', 'Proof', 'Goal', or 'State' after 'Show'");
295+
parser_error(p, "expected 'Context', 'Proof', 'Goal', or 'State' after 'Show'");
297296

298297
// Unreachable, but avoids compiler warning.
299298
return SHOW_KW_STATE;
@@ -348,8 +347,8 @@ Command *command_parse_inductive(Parser *p) {
348347
while (parser_expect_no_consume(p, TOK_PIPE)) {
349348
InductiveConstructor *ctor = command_parse_constructor(p);
350349

351-
constructors = realloc(constructors, sizeof(InductiveConstructor *) *
352-
(constructor_count + 1));
350+
constructors =
351+
realloc(constructors, sizeof(InductiveConstructor *) * (constructor_count + 1));
353352
constructors[constructor_count] = ctor;
354353
constructor_count++;
355354
}

src/commandlanguage/command_parser.h

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ typedef struct {
3030

3131
char *stmt_keyword_to_string(StmtKeyword kw);
3232

33-
typedef enum {
34-
SHOW_KW_CONTEXT,
35-
SHOW_KW_PROOF,
36-
SHOW_KW_GOAL,
37-
SHOW_KW_STATE
38-
} ShowKeyword;
33+
typedef enum { SHOW_KW_CONTEXT, SHOW_KW_PROOF, SHOW_KW_GOAL, SHOW_KW_STATE } ShowKeyword;
3934

4035
typedef struct {
4136
ShowKeyword kw;
@@ -211,20 +206,18 @@ typedef struct {
211206
CommandParseFunc parse_func;
212207
} CommandDispatchEntry;
213208

214-
static CommandDispatchEntry command_dispatch_table[] = {
215-
{TOK_AXIOM, command_parse_declaration},
216-
{TOK_VARIABLE, command_parse_declaration},
217-
{TOK_DEFINITION, command_parse_definition},
218-
{TOK_THEOREM, command_parse_statement},
219-
{TOK_LEMMA, command_parse_statement},
220-
{TOK_CHECK, command_parse_check},
221-
{TOK_PRINT, command_parse_print},
222-
{TOK_INDUCTIVE, command_parse_inductive},
223-
{TOK_SHOW, command_parse_show}};
209+
static CommandDispatchEntry command_dispatch_table[] = {{TOK_AXIOM, command_parse_declaration},
210+
{TOK_VARIABLE, command_parse_declaration},
211+
{TOK_DEFINITION, command_parse_definition},
212+
{TOK_THEOREM, command_parse_statement},
213+
{TOK_LEMMA, command_parse_statement},
214+
{TOK_CHECK, command_parse_check},
215+
{TOK_PRINT, command_parse_print},
216+
{TOK_INDUCTIVE, command_parse_inductive},
217+
{TOK_SHOW, command_parse_show}};
224218

225219
#define CMD_DISPATCH_TABLE (command_dispatch_table)
226-
#define CMD_DISPATCH_TABLE_SIZE \
227-
(sizeof(command_dispatch_table) / sizeof(command_dispatch_table[0]))
220+
#define CMD_DISPATCH_TABLE_SIZE (sizeof(command_dispatch_table) / sizeof(command_dispatch_table[0]))
228221

229222
/**
230223
* Macro to iterate over all entries in the command dispatch table.

src/common/lexer.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
static inline char peek_char(Lexer *lx) { return lx->src[lx->pos]; }
1010

1111
static void debug_print_token(Lexer *lx, Token *t) {
12-
if (!lx->options || !lx->options->debug ||
13-
!lx->options->debug__print_tokens) {
12+
if (!lx->options || !lx->options->debug || !lx->options->debug__print_tokens) {
1413
return;
1514
}
1615

@@ -157,13 +156,13 @@ static void debug_print_token(Lexer *lx, Token *t) {
157156
name = "UNKNOWN";
158157
}
159158

160-
fprintf(stderr, YEL "[LEX]" DIM " %-12s at %-4d %s" CRESET "\n", name,
161-
t->pos, t->lexeme ? t->lexeme : "");
159+
fprintf(stderr, YEL "[LEX]" DIM " %-12s at %-4d %s" CRESET "\n", name, t->pos,
160+
t->lexeme ? t->lexeme : "");
162161
}
163162

164163
void skip_whitespace(Lexer *lx) {
165-
while (lx->src[lx->pos] == ' ' || lx->src[lx->pos] == '\t' ||
166-
lx->src[lx->pos] == '\n' || lx->src[lx->pos] == '\r') {
164+
while (lx->src[lx->pos] == ' ' || lx->src[lx->pos] == '\t' || lx->src[lx->pos] == '\n' ||
165+
lx->src[lx->pos] == '\r') {
167166
lx->pos++;
168167
}
169168
}
@@ -201,9 +200,7 @@ char *skip_comment(Lexer *lx) {
201200

202201
char next_char(Lexer *lx) { return lx->src[lx->pos++]; }
203202

204-
bool is_alpha(char c) {
205-
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
206-
}
203+
bool is_alpha(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); }
207204

208205
bool is_digit(char c) { return (c >= '0' && c <= '9'); }
209206

src/common/options.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ typedef struct {
77
bool debug; // Gate all debug options
88
bool debug__print_tokens; // Print tokens during lexing
99
bool debug__print_ast; // Print AST after parsing
10-
bool debug__print_mode; // Print the current runtime mode and relevant info
11-
// after each update to the mode.
10+
bool debug__print_mode; // Print the current runtime mode and relevant info
11+
// after each update to the mode.
1212
} MEngineOptions;
1313

1414
#endif // OPTIONS_H

src/common/parser_base.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ Token *parser_next(Parser *p) {
3232
return old_current;
3333
}
3434

35-
bool parser_eof(Parser *p) {
36-
return p->current == NULL || p->current->type == TOK_EOF;
37-
}
35+
bool parser_eof(Parser *p) { return p->current == NULL || p->current->type == TOK_EOF; }
3836

3937
Token *parser_peek(Parser *p) { return p->current; }
4038

src/engine/rewrite_proof.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include <stdlib.h>
44

55
RewriteProof *init_rewrite_proof(Expression *expr, Expression *rewritten_expr,
6-
Expression *equality_proof,
7-
DoublyLinkedList *remaining_goals) {
6+
Expression *equality_proof, DoublyLinkedList *remaining_goals) {
87
RewriteProof *proof = malloc(sizeof(RewriteProof));
98
proof->expr = expr;
109
proof->rewritten_expr = rewritten_expr;
@@ -19,8 +18,7 @@ void free_rewrite_proof(RewriteProof *proof) {
1918
}
2019
}
2120

22-
RewrittenGoal *init_rewritten_goal(Expression *new_goal,
23-
DoublyLinkedList *remaining_open) {
21+
RewrittenGoal *init_rewritten_goal(Expression *new_goal, DoublyLinkedList *remaining_open) {
2422
RewrittenGoal *rewritten_goal = malloc(sizeof(RewrittenGoal));
2523
rewritten_goal->new_goal = new_goal;
2624
rewritten_goal->remaining_open = remaining_open;

src/engine/rewrite_proof.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ typedef struct RewriteProof {
1313
} RewriteProof;
1414

1515
RewriteProof *init_rewrite_proof(Expression *expr, Expression *rewritten_expr,
16-
Expression *equality_proof,
17-
DoublyLinkedList *remaining_goals);
16+
Expression *equality_proof, DoublyLinkedList *remaining_goals);
1817
void free_rewrite_proof(RewriteProof *proof);
1918

2019
typedef struct {
2120
Expression *new_goal;
2221
DoublyLinkedList *remaining_open;
2322
} RewrittenGoal;
2423

25-
RewrittenGoal *init_rewritten_goal(Expression *new_goal,
26-
DoublyLinkedList *remaining_open);
24+
RewrittenGoal *init_rewritten_goal(Expression *new_goal, DoublyLinkedList *remaining_open);
2725
void free_rewritten_goal(RewrittenGoal *rewritten_goal);
2826

2927
typedef struct {

src/engine/tactics.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#ifndef NEW_TACTICS_H
22
#define NEW_TACTICS_H
33

4-
#include "src/kernel/expression.h"
54
#include "src/kernel/context.h"
5+
#include "src/kernel/expression.h"
66

77
typedef struct {
8-
bool success; // true if the tactic was successful, false otherwise
8+
bool success; // true if the tactic was successful, false otherwise
99
DoublyLinkedList *new_goals; // If success, the new goals, otherwise NULL
1010
char *error_message; // If success, NULL, otherwise the error message
1111
} TacticResult;
@@ -17,27 +17,28 @@ void free_tactic_result(TacticResult *result);
1717
// DoublyLinkedList *eapply(Expression *goal, Expression *lemma);
1818
// Expression *eexists(Expression *goal);
1919

20-
// Given a hole with expected type "forall (x : A), B" and a name,
20+
// Given a hole with expected type "forall (x : A), B" and a name,
2121
// fill the hole with the term "λ x : A, ?B" and the result of the tactic is returned.
2222
TacticResult *intro_tactic(Expression *goal, char *name);
2323

2424
// Given a hole with expected type "forall (x : A), B" and a list of names,
2525
// fill the hole with the term "λ x : A, ?B" and the result of the tactic is returned.
2626
TacticResult *intros_tactic(Expression *goal, char **names, size_t name_count);
2727

28-
// Given a hole and a lemma, use unification to match the expected type of the hole with the type of the lemma,
29-
// and instantiate the lemma with the variables in the hole.
28+
// Given a hole and a lemma, use unification to match the expected type of the hole with the type of
29+
// the lemma, and instantiate the lemma with the variables in the hole.
3030
TacticResult *apply_tactic(Expression *goal, Expression *lemma);
3131

32-
// Given a hole and a lemma, use unification to match the expected type of the hole with the type of the lemma,
33-
// and instantiate the lemma with the variables in the hole. For any binders in the lemma,
34-
// this will create existential variables if necessary to match the goal.
32+
// Given a hole and a lemma, use unification to match the expected type of the hole with the type of
33+
// the lemma, and instantiate the lemma with the variables in the hole. For any binders in the
34+
// lemma, this will create existential variables if necessary to match the goal.
3535
TacticResult *eapply_tactic(Expression *goal, Expression *lemma);
3636

3737
// Search the context for a variable whose type matches the goal, and fill the hole with it.
3838
TacticResult *assumption_tactic(Expression *goal);
3939

40-
// Given a hole and a proof term, check if the term's type matches the goal, and fill the hole with it.
40+
// Given a hole and a proof term, check if the term's type matches the goal, and fill the hole with
41+
// it.
4142
TacticResult *exact_tactic(Expression *goal, Expression *proof_term);
4243

4344
typedef struct {
@@ -47,8 +48,9 @@ typedef struct {
4748
Expression *original_to_rewritten_proof;
4849
} RewriteResult;
4950

50-
// Given a hole and a lemma, where the hole's expected type has the form eq A x y. The eventual goal is to
51-
// generalize this to any equivalence relation. See: https://sozeau.gitlabpages.inria.fr/www/research/publications/A_New_Look_at_Generalized_Rewriting_in_Type_Theory.pdf
51+
// Given a hole and a lemma, where the hole's expected type has the form eq A x y. The eventual goal
52+
// is to generalize this to any equivalence relation. See:
53+
// https://sozeau.gitlabpages.inria.fr/www/research/publications/A_New_Look_at_Generalized_Rewriting_in_Type_Theory.pdf
5254
TacticResult *rewrite_tactic(Expression *goal, Expression *lemma);
5355

5456
#endif // NEW_TACTICS

src/engine/unify.c

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Expression *instantiate_lemma_type(Context *context, Expression *lemma_ty) {
88
case (FORALL_EXPRESSION): {
99
Expression *bound_var = lemma_ty->as.forall.bound_variable;
1010
Expression *bound_var_ty = get_expression_type(bound_var);
11-
Expression *hole = init_hole_expression(get_var_name(bound_var),
12-
bound_var_ty, context);
11+
Expression *hole = init_hole_expression(get_var_name(bound_var), bound_var_ty, context);
1312
Expression *lemma_ty_body = lemma_ty->as.forall.body;
1413
// lemma_ty_body is closed under context(bound_var), which contains bound_var
1514
Expression *new_body = new_subst(bound_var, lemma_ty_body, bound_var, hole);
@@ -31,14 +30,12 @@ Expression *instantiate_lemma(Context *context, Expression *lemma) {
3130
DoublyLinkedList *_list_holes(Expression *expr, DoublyLinkedList *curr) {
3231
switch (expr->tag) {
3332
case (LAMBDA_EXPRESSION): {
34-
curr = _list_holes(
35-
get_expression_type(expr->as.lambda.bound_variable), curr);
33+
curr = _list_holes(get_expression_type(expr->as.lambda.bound_variable), curr);
3634
curr = _list_holes(expr->as.lambda.body, curr);
3735
return curr;
3836
}
3937
case (FORALL_EXPRESSION): {
40-
curr = _list_holes(
41-
get_expression_type(expr->as.forall.bound_variable), curr);
38+
curr = _list_holes(get_expression_type(expr->as.forall.bound_variable), curr);
4239
curr = _list_holes(expr->as.forall.body, curr);
4340
return curr;
4441
}
@@ -71,8 +68,7 @@ int num_holes(Expression *expr) {
7168
return num_holes;
7269
}
7370

74-
Expression *_unify2(Expression *exprA, Expression *exprB,
75-
Expression *var_to_fill) {
71+
Expression *_unify2(Expression *exprA, Expression *exprB, Expression *var_to_fill) {
7672
if (exprA == exprB) {
7773
return NULL;
7874
}
@@ -96,14 +92,12 @@ Expression *_unify2(Expression *exprA, Expression *exprB,
9692
return NULL;
9793
}
9894

99-
Expression *new_func =
100-
_unify2(exprA->as.app.func, exprB->as.app.func, var_to_fill);
95+
Expression *new_func = _unify2(exprA->as.app.func, exprB->as.app.func, var_to_fill);
10196
if (new_func != NULL && new_func->tag != HOLE_EXPRESSION) {
10297
return new_func;
10398
}
10499

105-
Expression *new_arg =
106-
_unify2(exprA->as.app.arg, exprB->as.app.arg, var_to_fill);
100+
Expression *new_arg = _unify2(exprA->as.app.arg, exprB->as.app.arg, var_to_fill);
107101
if (new_arg != NULL) {
108102
return new_arg;
109103
}
@@ -115,9 +109,7 @@ Expression *_unify2(Expression *exprA, Expression *exprB,
115109
}
116110
}
117111

118-
Expression *instantiate_lemma_with_bindings(Expression *lemma,
119-
Expression *lemma_ty,
120-
Map *binders) {
112+
Expression *instantiate_lemma_with_bindings(Expression *lemma, Expression *lemma_ty, Map *binders) {
121113
Expression *final_expr = lemma;
122114
Expression *curr_forall = lemma_ty;
123115
while (curr_forall->tag == FORALL_EXPRESSION) {
@@ -128,8 +120,7 @@ Expression *instantiate_lemma_with_bindings(Expression *lemma,
128120
Context *app_ctx = (final_expr_ctx->ctx_size >= binding_result_ctx->ctx_size)
129121
? final_expr_ctx
130122
: binding_result_ctx;
131-
final_expr =
132-
init_app_expression_wc(final_expr, binding_result, app_ctx);
123+
final_expr = init_app_expression_wc(final_expr, binding_result, app_ctx);
133124
Expression *curr_forall_body = curr_forall->as.forall.body;
134125
// curr_forall_body is closed under context(binding_var), which contains binding_var
135126
curr_forall = new_subst(binding_var, curr_forall_body, binding_var, binding_result);
@@ -139,8 +130,7 @@ Expression *instantiate_lemma_with_bindings(Expression *lemma,
139130

140131
UnificationResult *init_unification_result(Expression *lemma_instantiation,
141132
DoublyLinkedList *new_goals) {
142-
UnificationResult *unification_result =
143-
(UnificationResult *)malloc(sizeof(UnificationResult));
133+
UnificationResult *unification_result = (UnificationResult *)malloc(sizeof(UnificationResult));
144134
unification_result->lemma_instantiation = lemma_instantiation;
145135
unification_result->new_goals = new_goals;
146136
return unification_result;
@@ -166,50 +156,41 @@ UnificationResult *eunify2(Expression *lemma, Expression *goal) {
166156
Expression *current_lemma_app_ty = get_expression_type(current_lemma_app);
167157
DoublyLinkedList *remaining_open = dll_create();
168158
while (current_lemma_app_ty->tag == FORALL_EXPRESSION) {
169-
Expression *bound_variable =
170-
current_lemma_app_ty->as.forall.bound_variable;
171-
Expression *hole_subst = _unify2(
172-
get_innermost_body(current_lemma_app_ty), expr, bound_variable);
159+
Expression *bound_variable = current_lemma_app_ty->as.forall.bound_variable;
160+
Expression *hole_subst =
161+
_unify2(get_innermost_body(current_lemma_app_ty), expr, bound_variable);
173162

174163
if (hole_subst == NULL) {
175164
Expression *hole_to_fill = init_hole_expression(
176-
get_var_name(bound_variable),
177-
get_expression_type(bound_variable), goal_context);
178-
current_lemma_app = init_app_expression_wc(
179-
current_lemma_app, hole_to_fill, goal_context);
165+
get_var_name(bound_variable), get_expression_type(bound_variable), goal_context);
166+
current_lemma_app =
167+
init_app_expression_wc(current_lemma_app, hole_to_fill, goal_context);
180168
dll_insert_at_tail(remaining_open, dll_new_node(hole_to_fill));
181169
} else {
182-
current_lemma_app = init_app_expression_wc(
183-
current_lemma_app, hole_subst, goal_context);
170+
current_lemma_app = init_app_expression_wc(current_lemma_app, hole_subst, goal_context);
184171
}
185172
current_lemma_app_ty = get_expression_type(current_lemma_app);
186173
}
187174
return init_unification_result(current_lemma_app, remaining_open);
188175
}
189176

190-
UnificationResult *bad_unify_for_eq(Context *goal_context, Expression *lemma,
191-
Expression *expr) {
177+
UnificationResult *bad_unify_for_eq(Context *goal_context, Expression *lemma, Expression *expr) {
192178
Expression *current_lemma_app = lemma;
193179
Expression *current_lemma_app_ty = get_expression_type(current_lemma_app);
194180
DoublyLinkedList *remaining_open = dll_create();
195181
while (current_lemma_app_ty->tag == FORALL_EXPRESSION) {
196-
Expression *current_lemma_ty_lhs =
197-
_get_lhs_eq(get_innermost_body(current_lemma_app_ty));
198-
Expression *bound_variable =
199-
current_lemma_app_ty->as.forall.bound_variable;
200-
Expression *hole_subst =
201-
_unify2(current_lemma_ty_lhs, expr, bound_variable);
182+
Expression *current_lemma_ty_lhs = _get_lhs_eq(get_innermost_body(current_lemma_app_ty));
183+
Expression *bound_variable = current_lemma_app_ty->as.forall.bound_variable;
184+
Expression *hole_subst = _unify2(current_lemma_ty_lhs, expr, bound_variable);
202185

203186
if (hole_subst == NULL) {
204187
Expression *hole_to_fill = init_hole_expression(
205-
get_var_name(bound_variable),
206-
get_expression_type(bound_variable), goal_context);
207-
current_lemma_app = init_app_expression_wc(
208-
current_lemma_app, hole_to_fill, goal_context);
188+
get_var_name(bound_variable), get_expression_type(bound_variable), goal_context);
189+
current_lemma_app =
190+
init_app_expression_wc(current_lemma_app, hole_to_fill, goal_context);
209191
dll_insert_at_tail(remaining_open, dll_new_node(hole_to_fill));
210192
} else {
211-
current_lemma_app = init_app_expression_wc(
212-
current_lemma_app, hole_subst, goal_context);
193+
current_lemma_app = init_app_expression_wc(current_lemma_app, hole_subst, goal_context);
213194
}
214195
current_lemma_app_ty = get_expression_type(current_lemma_app);
215196
}

0 commit comments

Comments
 (0)