Skip to content

Commit

Permalink
lone: move lone value structures to lone/types.h
Browse files Browse the repository at this point in the history
It seemed like a good idea at first but it got annoying.
Time to undo it.
  • Loading branch information
matheusmoreira committed Nov 23, 2023
1 parent 816df7a commit bb82255
Show file tree
Hide file tree
Showing 37 changed files with 97 additions and 231 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,10 @@ the successful status code `0` is expected.
│ ├── math.h # Mathematical functions
│ └── text.h # Text manipulation functions
├── struct/ # Lone structure definitions
│ ├── bytes.h # Memory segments of known size
│ ├── function.h # Reusable code blocks
│ ├── heap.h # Heap from where values are allocated
│ ├── lisp.h # Lone lisp interpreter
│ ├── list.h # Linked list of lone values
│ ├── memory.h # Memory blocks managed by lone
│ ├── module.h # Modules
│ ├── pointer.h # Typed pointers
│ ├── primitive.h # Functions implemented in C
│ ├── reader.h # Reader state and buffer
│ ├── table.h # Hash table with prototypal inheritance
│ ├── value.h # Tagged and flagged union of all value types
│ └── vector.h # Contiguous arrays of lone values
│ └── reader.h # Reader state and buffer
├── value/ # Functions for each type of value
│ ├── bytes.h # Creation and transfer functions
│ ├── function.h # Function and closure instantiation
Expand Down
24 changes: 0 additions & 24 deletions include/lone/struct/function.h

This file was deleted.

1 change: 0 additions & 1 deletion include/lone/struct/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#define LONE_STRUCT_HEAP_HEADER

#include <lone/types.h>
#include <lone/struct/value.h>

struct lone_heap {
struct lone_heap *next;
Expand Down
13 changes: 0 additions & 13 deletions include/lone/struct/list.h

This file was deleted.

14 changes: 0 additions & 14 deletions include/lone/struct/module.h

This file was deleted.

13 changes: 0 additions & 13 deletions include/lone/struct/pointer.h

This file was deleted.

15 changes: 0 additions & 15 deletions include/lone/struct/primitive.h

This file was deleted.

20 changes: 0 additions & 20 deletions include/lone/struct/table.h

This file was deleted.

38 changes: 0 additions & 38 deletions include/lone/struct/value.h

This file was deleted.

14 changes: 0 additions & 14 deletions include/lone/struct/vector.h

This file was deleted.

111 changes: 90 additions & 21 deletions include/lone/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ struct lone_auxiliary_vector {
struct lone_auxiliary_value value;
};

struct lone_bytes {
size_t count;
unsigned char *pointer;
};
struct lone_lisp;
struct lone_memory;
struct lone_reader;


/* ╭──────────────────────────┨ LONE LISP TYPES ┠───────────────────────────╮
│ │
Expand All @@ -62,8 +62,8 @@ struct lone_bytes {
│ ◦ Symbol the keyword and interned string type │
│ ◦ Text the UTF-8 encoded text type │
│ ◦ Bytes the binary data and low level string type │
│ ◦ Integer the signed integer type │
│ ◦ Pointer the memory addressing and dereferencing type │
│ ◦ Integer the signed integer type │
│ │
╰────────────────────────────────────────────────────────────────────────╯ */

Expand All @@ -77,8 +77,8 @@ enum lone_type {
LONE_SYMBOL,
LONE_TEXT,
LONE_BYTES,
LONE_INTEGER,
LONE_POINTER,
LONE_INTEGER,
};

enum lone_pointer_type {
Expand All @@ -90,30 +90,99 @@ enum lone_pointer_type {
LONE_TO_U64, LONE_TO_I64,
};

struct lone_value;
struct lone_module;
struct lone_function;
struct lone_function_flags;
struct lone_list;
struct lone_vector;
struct lone_table;
struct lone_text;
struct lone_bytes;
struct lone_pointer;
struct lone_module {
struct lone_value *name;
struct lone_value *environment;
struct lone_value *exports;
};

struct lone_lisp;
struct lone_memory;
struct lone_reader;
/* https://dl.acm.org/doi/10.1145/947941.947948
* https://user.ceng.metu.edu.tr/~ucoluk/research/lisp/lispman/node24.html
*/
struct lone_function_flags {
bool evaluate_arguments: 1;
bool evaluate_result: 1;
bool variable_arguments: 1;
};

typedef bool (*lone_predicate)(struct lone_value *);
typedef bool (*lone_comparator)(struct lone_value *, struct lone_value *);
struct lone_function {
struct lone_value *arguments; /* the bindings */
struct lone_value *code; /* the lambda */
struct lone_value *environment; /* the closure */
struct lone_function_flags flags; /* how to evaluate & apply */
};

typedef struct lone_value *(*lone_primitive)(struct lone_lisp *lone,
struct lone_value *module,
struct lone_value *environment,
struct lone_value *arguments,
struct lone_value *closure);

struct lone_primitive {
struct lone_value *name;
lone_primitive function;
struct lone_value *closure;
struct lone_function_flags flags; /* primitives always accept variable arguments */
};

struct lone_list {
struct lone_value *first;
struct lone_value *rest;
};

struct lone_vector {
struct lone_value **values;
size_t count;
size_t capacity;
};

struct lone_table_entry {
struct lone_value *key;
struct lone_value *value;
};

struct lone_bytes {
size_t count;
unsigned char *pointer;
};

struct lone_table {
size_t count;
size_t capacity;
struct lone_table_entry *entries;
struct lone_value *prototype;
};

struct lone_pointer {
enum lone_pointer_type type;
void *address;
};

struct lone_value {
struct {
bool live: 1;
bool marked: 1;
bool should_deallocate_bytes: 1;
};

enum lone_type type;

union {
struct lone_module module;
struct lone_function function;
struct lone_primitive primitive;
struct lone_list list;
struct lone_vector vector;
struct lone_table table;
struct lone_bytes bytes; /* also used by texts and symbols */
struct lone_pointer pointer;
long integer;
};
};

typedef bool (*lone_predicate)(struct lone_value *);
typedef bool (*lone_comparator)(struct lone_value *, struct lone_value *);

/* ╭────────────────────────────────────────────────────────────────────────╮
│ │
│ Type predicate functions. │
Expand Down
2 changes: 1 addition & 1 deletion source/lone/hash.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* SPDX-License-Identifier: AGPL-3.0-or-later */

#include <lone/types.h>
#include <lone/hash.h>
#include <lone/hash/fnv_1a.h>

#include <lone/linux.h>

#include <lone/struct/lisp.h>
#include <lone/struct/value.h>

void lone_hash_initialize(struct lone_lisp *lone, struct lone_bytes random)
{
Expand Down
1 change: 0 additions & 1 deletion source/lone/lisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <lone/value/symbol.h>

#include <lone/struct/lisp.h>
#include <lone/struct/function.h>

void lone_lisp_initialize(struct lone_lisp *lone, struct lone_bytes memory, size_t heap_size, void *stack, struct lone_bytes random)
{
Expand Down
3 changes: 1 addition & 2 deletions source/lone/lisp/evaluator.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* SPDX-License-Identifier: AGPL-3.0-or-later */

#include <lone/types.h>
#include <lone/lisp/evaluator.h>

#include <lone/value/list.h>
#include <lone/value/vector.h>
#include <lone/value/table.h>

#include <lone/struct/value.h>

#include <lone/linux.h>

static struct lone_value *lone_evaluate_form_index(struct lone_lisp *lone, struct lone_value *module, struct lone_value *environment, struct lone_value *collection, struct lone_value *arguments)
Expand Down
3 changes: 1 addition & 2 deletions source/lone/lisp/printer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: AGPL-3.0-or-later */

#include <lone/types.h>
#include <lone/lisp/printer.h>
#include <lone/memory/allocator.h>
#include <lone/memory/functions.h>
Expand All @@ -11,8 +12,6 @@

#include <lone/linux.h>

#include <lone/struct/value.h>

static void lone_print_integer(int fd, long n)
{
static char digits[DECIMAL_DIGITS_PER_LONG + 1]; /* digits, sign */
Expand Down
Loading

0 comments on commit bb82255

Please sign in to comment.