Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosvm committed Mar 29, 2024
1 parent 8c41b00 commit c0fd9a0
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 105 deletions.
18 changes: 9 additions & 9 deletions cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
typedef struct
{
const char *cmd;
bool optHelp;
bool optVersion;
bool optEval;
bool optAnalyze;
bool optDump;
bool optCompile;
bool optRun;
int stackSize;
bool optHelp;
bool optVersion;
bool optEval;
bool optAnalyze;
bool optDump;
bool optCompile;
bool optRun;
int stackSize;
const char *input;
const char *output;
const char **args;
int numArgs;
int numArgs;
} ParsedArgs;

static inline void fatal_error(const char *fmt, ...);
Expand Down
4 changes: 2 additions & 2 deletions core/lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ typedef struct LinkedListNode
{
struct LinkedListNode *next;
struct LinkedListNode *prev;
HkValue elem;
HkValue elem;
} LinkedListNode;

typedef struct
{
HK_USERDATA_HEADER
int length;
int length;
LinkedListNode *head;
LinkedListNode *tail;
} LinkedList;
Expand Down
6 changes: 3 additions & 3 deletions core/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
typedef struct
{
HK_USERDATA_HEADER
int domain;
int type;
int protocol;
int domain;
int type;
int protocol;
Socket sock;
} SocketUserdata;

Expand Down
4 changes: 2 additions & 2 deletions extensions/curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
typedef struct
{
HK_USERDATA_HEADER
CURL *curl;
CURL *curl;
CURLcode res;
HkString *url;
HkArray *headers;
HkArray *headers;
} CurlWrapper;

static int initialized = 0;
Expand Down
4 changes: 2 additions & 2 deletions include/hook/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
typedef struct
{
HK_OBJECT_HEADER
int capacity;
int length;
int capacity;
int length;
HkValue *elements;
} HkArray;

Expand Down
30 changes: 16 additions & 14 deletions include/hook/callable.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,36 @@
#include "chunk.h"
#include "string.h"

typedef struct hk_function
typedef struct HkFunction
{
HK_OBJECT_HEADER
int arity;
HkString *name;
HkString *file;
HkChunk chunk;
uint8_t functionsCapacity;
uint8_t functionsLength;
struct hk_function **functions;
uint8_t numNonlocals;
int arity;
HkString *name;
HkString *file;
HkChunk chunk;
uint8_t functionsCapacity;
uint8_t functionsLength;
struct HkFunction **functions;
uint8_t numNonlocals;
} HkFunction;

typedef struct
{
HK_OBJECT_HEADER
HkFunction *fn;
HkValue nonlocals[1];
HkValue nonlocals[1];
} HkClosure;

struct hk_state;
struct HkState;

typedef void (*HkCallFn)(struct HkState *, HkValue *);

typedef struct
{
HK_OBJECT_HEADER
int arity;
int arity;
HkString *name;
void (*call)(struct hk_state *, HkValue *);
HkCallFn call;
} HkNative;

HkFunction *hk_function_new(int arity, HkString *name, HkString *file);
Expand All @@ -48,7 +50,7 @@ HkFunction *hk_function_deserialize(FILE *stream);
HkClosure *hk_closure_new(HkFunction *fn);
void hk_closure_free(HkClosure *cl);
void hk_closure_release(HkClosure *cl);
HkNative *hk_native_new(HkString *name, int arity, void (*call)(struct hk_state *, HkValue *));
HkNative *hk_native_new(HkString *name, int arity, HkCallFn call);
void hk_native_free(HkNative *native);
void hk_native_release(HkNative *native);

Expand Down
10 changes: 5 additions & 5 deletions include/hook/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ typedef struct

typedef struct
{
int codeCapacity;
int codeLength;
int codeCapacity;
int codeLength;
uint8_t *code;
int linesCapacity;
int linesLength;
HkLine *lines;
int linesCapacity;
int linesLength;
HkLine *lines;
HkArray *consts;
} HkChunk;

Expand Down
18 changes: 9 additions & 9 deletions include/hook/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
#include "value.h"

#define HK_ITERATOR_HEADER HK_OBJECT_HEADER \
void (*deinit)(struct hk_iterator *); \
bool (*isValid)(struct hk_iterator *); \
HkValue (*getCurrent)(struct hk_iterator *); \
struct hk_iterator *(*next)(struct hk_iterator *); \
void (*inplaceNext)(struct hk_iterator *);
void (*deinit)(struct HkIterator *); \
bool (*isValid)(struct HkIterator *); \
HkValue (*getCurrent)(struct HkIterator *); \
struct HkIterator *(*next)(struct HkIterator *); \
void (*inplaceNext)(struct HkIterator *);

typedef struct hk_iterator
typedef struct HkIterator
{
HK_ITERATOR_HEADER
} HkIterator;

void hk_iterator_init(HkIterator *it, void (*deinit)(struct hk_iterator *),
bool (*isValid)(struct hk_iterator *), HkValue (*getCurrent)(struct hk_iterator *),
struct hk_iterator *(*next)(struct hk_iterator *), void (*inplaceNext)(struct hk_iterator *));
void hk_iterator_init(HkIterator *it, void (*deinit)(HkIterator *),
bool (*isValid)(HkIterator *), HkValue (*getCurrent)(HkIterator *),
HkIterator *(*next)(HkIterator *), void (*inplaceNext)(HkIterator *));
void hk_iterator_free(HkIterator *it);
void hk_iterator_release(HkIterator *it);
bool hk_iterator_is_valid(HkIterator *it);
Expand Down
2 changes: 1 addition & 1 deletion include/hook/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
typedef struct
{
HK_OBJECT_HEADER
int step;
int step;
int64_t start;
int64_t end;
} HkRange;
Expand Down
13 changes: 7 additions & 6 deletions include/hook/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ typedef enum
HK_STATE_STATUS_ERROR
} HkSateStatus;

typedef struct hk_state
typedef struct HkState
{
int stackEnd;
int stackTop;
HkValue *stackSlots;
int flags;
int stackEnd;
int stackTop;
HkValue *stackSlots;
int flags;
HkSateStatus status;
} HkState;

Expand Down Expand Up @@ -74,7 +74,8 @@ void hk_state_push_instance(HkState *state, HkInstance *inst);
void hk_state_push_iterator(HkState *state, HkIterator *it);
void hk_state_push_closure(HkState *state, HkClosure *cl);
void hk_state_push_native(HkState *state, HkNative *native);
void hk_state_push_new_native(HkState *state, const char *name, int arity, void (*call)(HkState *, HkValue *));
void hk_state_push_new_native(HkState *state, const char *name, int arity,
HkCallFn call);
void hk_state_push_userdata(HkState *state, HkUserdata *udata);
void hk_state_array(HkState *state, int length);
void hk_state_struct(HkState *state, int length);
Expand Down
6 changes: 3 additions & 3 deletions include/hook/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
typedef struct
{
HK_OBJECT_HEADER
int capacity;
int length;
char *chars;
int capacity;
int length;
char *chars;
int64_t hash;
} HkString;

Expand Down
14 changes: 7 additions & 7 deletions include/hook/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@
typedef struct
{
HkString *name;
int index;
int index;
} HkField;

typedef struct
{
HK_OBJECT_HEADER
int capacity;
int mask;
int length;
int capacity;
int mask;
int length;
HkString *name;
HkField *fields;
HkField **table;
HkField *fields;
HkField **table;
} HkStruct;

typedef struct
{
HK_OBJECT_HEADER
HkStruct *ztruct;
HkValue values[1];
HkValue values[1];
} HkInstance;

HkStruct *hk_struct_new(HkString *name);
Expand Down
8 changes: 4 additions & 4 deletions include/hook/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ typedef enum

typedef struct
{
HkType type;
int flags;
HkType type;
int flags;
union
{
bool boolean;
bool boolean;
double number;
void *pointer;
void *pointer;
} as;
} HkValue;

Expand Down
2 changes: 1 addition & 1 deletion src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef struct
{
HK_ITERATOR_HEADER
HkArray *arr;
int current;
int current;
} ArrayIterator;

static inline HkArray *array_allocate(int minCapacity);
Expand Down
2 changes: 1 addition & 1 deletion src/callable.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void hk_closure_release(HkClosure *cl)
hk_closure_free(cl);
}

HkNative *hk_native_new(HkString *name, int arity, void (*call)(struct hk_state *, HkValue *))
HkNative *hk_native_new(HkString *name, int arity, HkCallFn call)
{
HkNative *native = (HkNative *) hk_allocate(sizeof(*native));
native->refCount = 0;
Expand Down
40 changes: 20 additions & 20 deletions src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,34 @@ typedef enum

typedef struct
{
bool isLocal;
int depth;
bool isLocal;
int depth;
uint8_t index;
int length;
char *start;
bool isMutable;
int length;
char *start;
bool isMutable;
} Variable;

typedef struct Loop
{
struct Loop *parent;
int scopeDepth;
uint16_t jump;
int numOffsets;
int offsets[MAX_BREAKS];
int scopeDepth;
uint16_t jump;
int numOffsets;
int offsets[MAX_BREAKS];
} Loop;

typedef struct compiler
{
struct compiler *parent;
int flags;
Scanner *scan;
int scopeDepth;
int numVariables;
uint8_t nextIndex;
Variable variables[MAX_VARIABLES];
Loop *loop;
HkFunction *fn;
typedef struct Compiler
{
struct Compiler *parent;
int flags;
Scanner *scan;
int scopeDepth;
int numVariables;
uint8_t nextIndex;
Variable variables[MAX_VARIABLES];
Loop *loop;
HkFunction *fn;
} Compiler;

static inline void syntax_error(HkString *fnName, const char *file, int line,
Expand Down
6 changes: 3 additions & 3 deletions src/iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <hook/iterator.h>
#include <stdlib.h>

void hk_iterator_init(HkIterator *it, void (*deinit)(struct hk_iterator *),
bool (*isValid)(struct hk_iterator *), HkValue (*getCurrent)(struct hk_iterator *),
struct hk_iterator *(*next)(struct hk_iterator *), void (*inplaceNext)(struct hk_iterator *))
void hk_iterator_init(HkIterator *it, void (*deinit)(HkIterator *),
bool (*isValid)(HkIterator *), HkValue (*getCurrent)(HkIterator *),
HkIterator *(*next)(HkIterator *), void (*inplaceNext)(HkIterator *))
{
it->refCount = 0;
it->deinit = deinit;
Expand Down
8 changes: 4 additions & 4 deletions src/record.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
typedef struct
{
HkString *key;
HkValue value;
HkValue value;
} RecordEntry;

typedef struct
{
int capacity;
int mask;
int length;
int capacity;
int mask;
int length;
RecordEntry *entries;
} Record;

Expand Down
Loading

0 comments on commit c0fd9a0

Please sign in to comment.