Skip to content

Commit

Permalink
Clean up trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 19, 2015
1 parent 8127031 commit 1628bbf
Show file tree
Hide file tree
Showing 17 changed files with 343 additions and 345 deletions.
24 changes: 12 additions & 12 deletions builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static jv f_plus(jq_state *jq, jv input, jv a, jv b) {
jv_free(b);
return a;
} else if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
return jv_number(jv_number_value(a) +
return jv_number(jv_number_value(a) +
jv_number_value(b));
} else if (jv_get_kind(a) == JV_KIND_STRING && jv_get_kind(b) == JV_KIND_STRING) {
return jv_string_concat(a, b);
Expand Down Expand Up @@ -238,7 +238,7 @@ static jv f_multiply(jq_state *jq, jv input, jv a, jv b) {
return jv_object_merge_recursive(a, b);
} else {
return type_error2(a, b, "cannot be multiplied");
}
}
}

static jv f_divide(jq_state *jq, jv input, jv a, jv b) {
Expand All @@ -251,7 +251,7 @@ static jv f_divide(jq_state *jq, jv input, jv a, jv b) {
return jv_string_split(a, b);
} else {
return type_error2(a, b, "cannot be divided");
}
}
}

static jv f_mod(jq_state *jq, jv input, jv a, jv b) {
Expand All @@ -262,7 +262,7 @@ static jv f_mod(jq_state *jq, jv input, jv a, jv b) {
return jv_number((intmax_t)jv_number_value(a) % (intmax_t)jv_number_value(b));
} else {
return type_error2(a, b, "cannot be divided (remainder)");
}
}
}

static jv f_equal(jq_state *jq, jv input, jv a, jv b) {
Expand Down Expand Up @@ -572,7 +572,7 @@ static jv f_sort(jq_state *jq, jv input){
}

static jv f_sort_by_impl(jq_state *jq, jv input, jv keys) {
if (jv_get_kind(input) == JV_KIND_ARRAY &&
if (jv_get_kind(input) == JV_KIND_ARRAY &&
jv_get_kind(keys) == JV_KIND_ARRAY &&
jv_array_length(jv_copy(input)) == jv_array_length(jv_copy(keys))) {
return jv_sort(input, keys);
Expand All @@ -582,7 +582,7 @@ static jv f_sort_by_impl(jq_state *jq, jv input, jv keys) {
}

static jv f_group_by_impl(jq_state *jq, jv input, jv keys) {
if (jv_get_kind(input) == JV_KIND_ARRAY &&
if (jv_get_kind(input) == JV_KIND_ARRAY &&
jv_get_kind(keys) == JV_KIND_ARRAY &&
jv_array_length(jv_copy(input)) == jv_array_length(jv_copy(keys))) {
return jv_group(input, keys);
Expand Down Expand Up @@ -668,7 +668,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
}
}
jv_free(modarray);
} else if (jv_get_kind(modifiers) != JV_KIND_NULL) {
} else if (jv_get_kind(modifiers) != JV_KIND_NULL) {
// If it isn't a string or null, then it is the wrong type...
jv_free(input);
jv_free(regex);
Expand All @@ -695,7 +695,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
const UChar* end = start + length;
region = onig_region_new();
do {
onigret = onig_search(reg,
onigret = onig_search(reg,
(const UChar*)jv_string_value(input), end, /* string boundaries */
start, end, /* search boundaries */
region, ONIG_OPTION_NONE);
Expand Down Expand Up @@ -1238,7 +1238,7 @@ static jv f_current_line(jq_state *jq) {
#define LIBM_DDD(name) \
{(cfunction_ptr)f_ ## name, "_" #name, 3},
#define LIBM_DDD_NO(name)

static const struct cfunction function_list[] = {
#include "libm.h"
{(cfunction_ptr)f_plus, "_plus", 3},
Expand Down Expand Up @@ -1326,7 +1326,7 @@ static block bind_bytecoded_builtins(block b) {
}
{
struct bytecoded_builtin builtin_def_1arg[] = {
{"path", BLOCK(gen_op_simple(PATH_BEGIN),
{"path", BLOCK(gen_op_simple(PATH_BEGIN),
gen_call("arg", gen_noop()),
gen_op_simple(PATH_END))},
};
Expand All @@ -1340,14 +1340,14 @@ static block bind_bytecoded_builtins(block b) {
// Note that we can now define `range` as a jq-coded function
block rangevar = gen_op_var_fresh(STOREV, "rangevar");
block init = BLOCK(gen_op_simple(DUP), gen_call("start", gen_noop()), rangevar);
block range = BLOCK(init,
block range = BLOCK(init,
gen_call("end", gen_noop()),
gen_op_bound(RANGE, rangevar));
builtins = BLOCK(builtins, gen_function("range",
BLOCK(gen_param("start"), gen_param("end")),
range));
}

return block_bind_referenced(builtins, b, OP_IS_CALL_PSEUDO);
}

Expand Down
10 changes: 5 additions & 5 deletions bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ void dump_operation(struct bytecode* bc, uint16_t* codeptr) {
jv name;
if (idx & ARG_NEWCLOSURE) {
idx &= ~ARG_NEWCLOSURE;
name = jv_object_get(jv_copy(getlevel(bc,level)->subfunctions[idx]->debuginfo),
name = jv_object_get(jv_copy(getlevel(bc,level)->subfunctions[idx]->debuginfo),
jv_string("name"));
} else {
name = jv_array_get(jv_object_get(jv_copy(getlevel(bc,level)->debuginfo),
name = jv_array_get(jv_object_get(jv_copy(getlevel(bc,level)->debuginfo),
jv_string("params")), idx);
}
printf(" %s:%d",
Expand All @@ -133,8 +133,8 @@ void dump_operation(struct bytecode* bc, uint16_t* codeptr) {
} else if (op->flags & OP_HAS_VARIABLE) {
uint16_t v = bc->code[pc++];
jv name = jv_array_get(jv_object_get(jv_copy(getlevel(bc,imm)->debuginfo), jv_string("locals")), v);
printf(" $%s:%d",
jv_string_value(name),
printf(" $%s:%d",
jv_string_value(name),
v);
jv_free(name);
if (imm) {
Expand All @@ -143,7 +143,7 @@ void dump_operation(struct bytecode* bc, uint16_t* codeptr) {
} else {
printf(" %d", imm);
}
}
}
}

void bytecode_free(struct bytecode* bc) {
Expand Down
2 changes: 1 addition & 1 deletion bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef enum {
} opcode;

enum {
NUM_OPCODES =
NUM_OPCODES =
#define OP(name, imm, in, out) +1
#include "opcode_list.h"
#undef OP
Expand Down
18 changes: 9 additions & 9 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/*
The intermediate representation for jq filters is as a sequence of
struct inst, which form a doubly-linked list via the next and prev
pointers.
pointers.
A "block" represents a sequence of "struct inst", which may be
empty.
Expand All @@ -28,7 +28,7 @@ struct inst {
struct inst* prev;

opcode op;

struct {
uint16_t intval;
struct inst* target;
Expand All @@ -45,7 +45,7 @@ struct inst {
// inst->bound_by = NULL - Unbound free variable
// inst->bound_by = inst - This instruction binds a variable
// inst->bound_by = other - Uses variable bound by other instruction
// Unbound instructions (references to other things that may or may not
// Unbound instructions (references to other things that may or may not
// exist) are created by "gen_foo_unbound", and bindings are created by
// block_bind(definition, body), which binds all instructions in
// body which are unboudn and refer to "definition" by name.
Expand Down Expand Up @@ -288,7 +288,7 @@ static int block_count_actuals(block b) {
for (inst* i = b.first; i; i = i->next) {
switch (i->op) {
default: assert(0 && "Unknown function type"); break;
case CLOSURE_CREATE:
case CLOSURE_CREATE:
case CLOSURE_PARAM:
case CLOSURE_CREATE_C:
args++;
Expand Down Expand Up @@ -462,7 +462,7 @@ block block_drop_unreferenced(block body) {

jv block_take_imports(block* body) {
jv imports = jv_array();

inst* top = NULL;
if (body->first && body->first->op == TOP) {
top = block_take(body);
Expand Down Expand Up @@ -808,7 +808,7 @@ block gen_condbranch(block iftrue, block iffalse) {

block gen_and(block a, block b) {
// a and b = if a then (if b then true else false) else false
return BLOCK(gen_op_simple(DUP), a,
return BLOCK(gen_op_simple(DUP), a,
gen_condbranch(BLOCK(gen_op_simple(POP),
b,
gen_condbranch(gen_const(jv_true()),
Expand Down Expand Up @@ -870,7 +870,7 @@ static block gen_wildvar_binding(block var, const char* name, block body) {
}

block gen_cond(block cond, block iftrue, block iffalse) {
return BLOCK(gen_op_simple(DUP), cond,
return BLOCK(gen_op_simple(DUP), cond,
gen_condbranch(BLOCK(gen_op_simple(POP), iftrue),
BLOCK(gen_op_simple(POP), iffalse)));
}
Expand Down Expand Up @@ -988,7 +988,7 @@ static int expand_call_arglist(block* b) {
// We expand the argument list as a series of instructions
switch (curr->bound_by->op) {
default: assert(0 && "Unknown function type"); break;
case CLOSURE_CREATE:
case CLOSURE_CREATE:
case CLOSURE_PARAM: {
block callargs = gen_noop();
for (inst* i; (i = block_take(&curr->arglist));) {
Expand Down Expand Up @@ -1137,7 +1137,7 @@ static int compile(struct bytecode* bc, block b) {
curr->bound_by->op == CLOSURE_PARAM);
code[pos++] = (uint16_t)curr->imm.intval;
code[pos++] = nesting_level(bc, curr->bound_by);
code[pos++] = curr->bound_by->imm.intval |
code[pos++] = curr->bound_by->imm.intval |
(curr->bound_by->op == CLOSURE_CREATE ? ARG_NEWCLOSURE : 0);
for (inst* arg = curr->arglist.first; arg; arg = arg->next) {
assert(arg->op == CLOSURE_REF && arg->bound_by->op == CLOSURE_CREATE);
Expand Down
2 changes: 1 addition & 1 deletion exec_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static stack_ptr* stack_block_next(struct stack* s, stack_ptr p) {
static void stack_reallocate(struct stack* s, size_t sz) {
int old_mem_length = -(s->bound) + ALIGNMENT;
char* old_mem_start = s->mem_end - old_mem_length;

int new_mem_length = align_round_up((old_mem_length + sz + 256) * 2);
char* new_mem_start = jv_mem_realloc(old_mem_start, new_mem_length);
memmove(new_mem_start + (new_mem_length - old_mem_length),
Expand Down
16 changes: 8 additions & 8 deletions execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static struct closure make_closure(struct jq_state* jq, uint16_t* pc) {
}
}

static struct frame* frame_push(struct jq_state* jq, struct closure callee,
static struct frame* frame_push(struct jq_state* jq, struct closure callee,
uint16_t* argdef, int nargs) {
stack_ptr new_frame_idx = stack_push_block(&jq->stk, jq->curr_frame, frame_size(callee.bc));
struct frame* new_frame = stack_block(&jq->stk, new_frame_idx);
Expand Down Expand Up @@ -208,7 +208,7 @@ void stack_save(jq_state *jq, uint16_t* retaddr, struct stack_pos sp){
struct forkpoint* fork = stack_block(&jq->stk, jq->fork_top);
fork->saved_data_stack = jq->stk_top;
fork->saved_curr_frame = jq->curr_frame;
fork->path_len =
fork->path_len =
jv_get_kind(jq->path) == JV_KIND_ARRAY ? jv_array_length(jv_copy(jq->path)) : 0;
fork->subexp_nest = jq->subexp_nest;
fork->return_address = retaddr;
Expand Down Expand Up @@ -397,7 +397,7 @@ jv jq_next(jq_state *jq) {
stack_push(jq, b);
break;
}

case POP: {
jv_free(stack_pop(jq));
break;
Expand Down Expand Up @@ -604,8 +604,8 @@ jv jq_next(jq_state *jq) {
break;
}

case EACH:
case EACH_OPT:
case EACH:
case EACH_OPT:
stack_push(jq, jv_number(-1));
// fallthrough
case ON_BACKTRACK(EACH):
Expand Down Expand Up @@ -708,7 +708,7 @@ jv jq_next(jq_state *jq) {
pc += offset;
break;
}

case CALL_BUILTIN: {
int nargs = *pc++;
jv top = stack_pop(jq);
Expand All @@ -733,7 +733,7 @@ jv jq_next(jq_state *jq) {
// because the compiler should not generate this error.
default: return jv_invalid_with_msg(jv_string("Function takes too many arguments"));
}

if (jv_is_valid(top)) {
stack_push(jq, top);
} else if (jv_invalid_has_msg(jv_copy(top))) {
Expand Down Expand Up @@ -908,7 +908,7 @@ void jq_set_nomem_handler(jq_state *jq, void (*nomem_handler)(void *), void *dat
void jq_start(jq_state *jq, jv input, int flags) {
jv_nomem_handler(jq->nomem_handler, jq->nomem_handler_data);
jq_reset(jq);

struct closure top = {jq->bc, -1};
struct frame* top_frame = frame_push(jq, top, 0, 0);
top_frame->retdata = 0;
Expand Down
6 changes: 3 additions & 3 deletions jq_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static void jv_test() {
assert(jv_get_kind(a) == JV_KIND_ARRAY);
assert(jv_array_length(jv_copy(a)) == 0);
assert(jv_array_length(jv_copy(a)) == 0);

a = jv_array_append(a, jv_number(42));
assert(jv_array_length(jv_copy(a)) == 1);
assert(jv_number_value(jv_array_get(jv_copy(a), 0)) == 42);
Expand Down Expand Up @@ -300,13 +300,13 @@ static void jv_test() {
jv_free(shortstr);
jv_free(longstr);


char a1s[] = "hello", a2s[] = "hello", bs[] = "goodbye";
jv a1 = jv_string(a1s), a2 = jv_string(a2s), b = jv_string(bs);
assert(jv_equal(jv_copy(a1), jv_copy(a2)));
assert(jv_equal(jv_copy(a2), jv_copy(a1)));
assert(!jv_equal(jv_copy(a1), jv_copy(b)));

assert(jv_string_hash(jv_copy(a1)) == jv_string_hash(jv_copy(a1)));
assert(jv_string_hash(jv_copy(a1)) == jv_string_hash(jv_copy(a2)));
assert(jv_string_hash(jv_copy(b)) != jv_string_hash(jv_copy(a1)));
Expand Down
Loading

0 comments on commit 1628bbf

Please sign in to comment.