Skip to content

Commit

Permalink
Jtv/headers (#13)
Browse files Browse the repository at this point in the history
* Swapped out <> in local headers for double quotes.
* Call all the initialization bits from one place, and expect it to not be applied as a constructor.
* All con4m non-static functions and exported symbols are now prefixed with c4m_
* All con4m data types that aren't private to a file are now prefixed with c4m_
* Any macro in the con4m dir other than the 3rd party vararg stuff also should start w/ C4M_ at this point.
* Add in new initialization wrapper that should be called from a constructor.

Note that con4m_ is no longer a prefix; it is always c4m_ now. 
Also, hatrack is fairly reasonably name-spaced; that was left alone, so you'll still see some hatrack_* and flexarray_* on the con4m side.
  • Loading branch information
viega authored Apr 10, 2024
1 parent 70c02f0 commit c16f75c
Show file tree
Hide file tree
Showing 174 changed files with 7,932 additions and 8,364 deletions.
68 changes: 34 additions & 34 deletions include/con4m.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,70 @@ typedef void *object_t;
// Everything includes this; the ordering here is somewhat important
// due to interdependencies, though they can always be solved via
// prototyping.
#include <con4m/base.h>

#include <con4m/macros.h> // Helper macros, mostly 3rd party stuff.
#include <con4m/kargs.h> // Keyword arguments.
#include <con4m/random.h>
#include "con4m/base.h"
#include "con4m/init.h"
#include "con4m/macros.h" // Helper macros, mostly 3rd party stuff.
#include "con4m/kargs.h" // Keyword arguments.
#include "con4m/random.h"

// Memory management
#include <con4m/refcount.h>
#include <con4m/gc.h>
#include <con4m/object.h>
#include "con4m/refcount.h"
#include "con4m/gc.h"
#include "con4m/object.h"

#include <con4m/color.h>
#include "con4m/color.h"

// Basic "exclusive" (i.e., single threaded) list.
#include <con4m/xlist.h>
#include "con4m/xlist.h"

// Type system API.
#include <con4m/type.h>
#include "con4m/type.h"

// Extra data structure stuff.
#include <con4m/set.h>
#include <con4m/tree.h>
#include <con4m/buffer.h>
#include <con4m/tuple.h>
#include "con4m/set.h"
#include "con4m/tree.h"
#include "con4m/buffer.h"
#include "con4m/tuple.h"

// Basic string handling.
#include <con4m/codepoint.h>
#include <con4m/string.h>
#include <con4m/breaks.h>
#include <con4m/ansi.h>
#include <con4m/hex.h>
#include "con4m/codepoint.h"
#include "con4m/string.h"
#include "con4m/breaks.h"
#include "con4m/ansi.h"
#include "con4m/hex.h"

#include <con4m/style.h>
#include <con4m/styledb.h>
#include "con4m/style.h"
#include "con4m/styledb.h"

// Our grid API.
#include <con4m/grid.h>
#include "con4m/grid.h"

// IO primitives.
#include <con4m/term.h>
#include <con4m/switchboard.h>
#include <con4m/subproc.h>
#include "con4m/term.h"
#include "con4m/switchboard.h"
#include "con4m/subproc.h"

// Basic exception handling support.
#include <con4m/exception.h>
#include "con4m/exception.h"

// Stream IO API.
#include <con4m/stream.h>
#include "con4m/stream.h"

// Helper functions for object marshal implementations to
// marshal primitive values.
#include <con4m/marshal.h>
#include "con4m/marshal.h"

// Mixed data type API.
#include <con4m/mixed.h>
#include "con4m/mixed.h"

// Basic internal API to cache and access common string constants.
#include <con4m/conststr.h>
#include "con4m/conststr.h"

// Boxes for ordinal types
#include <con4m/box.h>
#include "con4m/box.h"

// A few prototypes for literal handling.
#include <con4m/literal.h>
#include "con4m/literal.h"

// Yes we use cryptographic hashes internally for type IDing.
#include <crypto/sha.h>
#include "crypto/sha.h"
20 changes: 14 additions & 6 deletions include/con4m/ansi.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#pragma once

#include <con4m.h>
#include "con4m.h"

extern void utf8_ansi_render(const utf8_t *s, stream_t *outstream);
extern void utf32_ansi_render(const utf32_t *s, int32_t start_ix, int32_t end_ix, stream_t *outstream);
extern void ansi_render(const any_str_t *s, stream_t *out);
extern void ansi_render_to_width(const any_str_t *s, int32_t width, int32_t hang, stream_t *out);
extern size_t ansi_render_len(const any_str_t *s);
extern void c4m_utf8_ansi_render(const c4m_utf8_t *s,
c4m_stream_t *outstream);
extern void c4m_utf32_ansi_render(const c4m_utf32_t *s,
int32_t start_ix,
int32_t end_ix,
c4m_stream_t *outstream);
extern void c4m_ansi_render(const c4m_str_t *s,
c4m_stream_t *out);
extern void c4m_ansi_render_to_width(const c4m_str_t *s,
int32_t width,
int32_t hang,
c4m_stream_t *out);
extern size_t c4m_ansi_render_len(const c4m_str_t *s);
9 changes: 6 additions & 3 deletions include/con4m/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ forkpty(int *, char *, struct termios *, struct winsize *);
#define max(a, b) ({ __typeof__ (a) _a = (a), _b = (b); \
_a > _b ? _a : _b; })

#include <vendor.h>
#include <hatrack.h>
#include <con4m/datatypes.h>
#include "vendor.h"
#include "hatrack.h"

typedef struct hatrack_dict_t c4m_dict_t;

#include "con4m/datatypes.h"

#if BYTE_ORDER == LITTLE_ENDIAN
#define little_64(x)
Expand Down
56 changes: 28 additions & 28 deletions include/con4m/box.h
Original file line number Diff line number Diff line change
@@ -1,140 +1,140 @@
#include <con4m.h>
#include "con4m.h"

static inline i64_box *
box_i64(int64_t n)
c4m_box_i64(int64_t n)
{
int64_t *result = con4m_new(tspec_i64());
int64_t *result = c4m_new(c4m_tspec_i64());
*result = n;

return result;
}

static inline int64_t
unbox_i64(i64_box *b)
c4m_unbox_i64(i64_box *b)
{
return *b;
}

static inline u64_box *
box_u64(uint64_t n)
c4m_box_u64(uint64_t n)
{
uint64_t *result = con4m_new(tspec_u64());
uint64_t *result = c4m_new(c4m_tspec_u64());
*result = n;

return result;
}

static inline uint64_t
unbox_u64(u64_box *b)
c4m_unbox_u64(u64_box *b)
{
return *b;
}

static inline i32_box *
box_i32(int32_t n)
c4m_box_i32(int32_t n)
{
int32_t *result = con4m_new(tspec_i32());
int32_t *result = c4m_new(c4m_tspec_i32());
*result = n;

return result;
}

static inline int32_t
unbox_i32(i32_box *b)
c4m_unbox_i32(i32_box *b)
{
return *b;
}

static inline u32_box *
box_u32(uint32_t n)
c4m_box_u32(uint32_t n)
{
uint32_t *result = con4m_new(tspec_u32());
uint32_t *result = c4m_new(c4m_tspec_u32());
*result = n;

return result;
}

static inline uint32_t
unbox_u32(u32_box *b)
c4m_unbox_u32(u32_box *b)
{
return *b;
}

#if 0 // I somehow have missed u16

static inline i16_box *
box_i16(int16_t n)
c4m_box_i16(int16_t n)
{
int16_t *result = con4m_new(tspec_i16());
int16_t *result = c4m_new(c4m_tspec_i16());
*result = n;

return result;
}

static inline int16_t
unbox_i16(i16_box *b)
c4m_unbox_i16(i16_box *b)
{
return *b;
}

static inline u16_box *
box_u16(uint16_t n)
c4m_box_u16(uint16_t n)
{
uint16_t *result = con4m_new(tspec_u16());
uint16_t *result = c4m_new(c4m_tspec_u16());
*result = n;

return result;
}

static inline uint16_t
unbox_u16(u16_box *b)
c4m_unbox_u16(u16_box *b)
{
return *b;
}

#endif

static inline i8_box *
box_i8(int8_t n)
c4m_box_i8(int8_t n)
{
int8_t *result = con4m_new(tspec_i8());
int8_t *result = c4m_new(c4m_tspec_i8());
*result = n;

return result;
}

static inline int8_t
unbox_i8(i8_box *b)
c4m_unbox_i8(i8_box *b)
{
return *b;
}

static inline u8_box *
box_u8(uint8_t n)
c4m_box_u8(uint8_t n)
{
uint8_t *result = con4m_new(tspec_u8());
uint8_t *result = c4m_new(c4m_tspec_u8());
*result = n;

return result;
}

static inline uint8_t
unbox_u8(u8_box *b)
c4m_unbox_u8(u8_box *b)
{
return *b;
}

static inline double_box *
box_double(double d)
c4m_box_double(double d)
{
double *result = con4m_new(tspec_f64());
double *result = c4m_new(c4m_tspec_f64());
*result = d;

return result;
}

static inline double
unbox_double(double_box *b)
c4m_unbox_double(double_box *b)
{
return *b;
}
42 changes: 22 additions & 20 deletions include/con4m/breaks.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
#pragma once

#include <con4m.h>
#include "con4m.h"

// break_info_t is in datatypes/strings.h
// c4m_break_info_t is in datatypes/strings.h

extern const int minimum_break_slots;
extern const int c4m_minimum_break_slots;

extern break_info_t *get_grapheme_breaks(const any_str_t *, int32_t, int32_t);
extern break_info_t *get_line_breaks(const any_str_t *);
extern break_info_t *get_all_line_break_ops(const any_str_t *);
extern break_info_t *wrap_text(const any_str_t *, int32_t, int32_t);
extern c4m_break_info_t *c4m_get_grapheme_breaks(const c4m_str_t *,
int32_t,
int32_t);
extern c4m_break_info_t *c4m_get_line_breaks(const c4m_str_t *);
extern c4m_break_info_t *c4m_get_all_line_break_ops(const c4m_str_t *);
extern c4m_break_info_t *c4m_wrap_text(const c4m_str_t *, int32_t, int32_t);

static inline break_info_t *
alloc_break_structure(const any_str_t *s, int shift)
static inline c4m_break_info_t *
c4m_alloc_break_structure(const c4m_str_t *s, int shift)
{
break_info_t *result;
int32_t alloc_slots = max(string_codepoint_len(s) >> shift,
minimum_break_slots);
c4m_break_info_t *result;
int32_t alloc_slots = max(c4m_str_codepoint_len(s) >> shift,
c4m_minimum_break_slots);

result = gc_flex_alloc(break_info_t, int32_t, alloc_slots, NULL);
result = c4m_gc_flex_alloc(c4m_break_info_t, int32_t, alloc_slots, NULL);

result->num_slots = alloc_slots;
result->num_breaks = 0;

return result;
}

static inline break_info_t *
grow_break_structure(break_info_t *breaks)
static inline c4m_break_info_t *
c4m_grow_break_structure(c4m_break_info_t *breaks)
{
int32_t new_slots = breaks->num_slots * 2;

break_info_t *res;
c4m_break_info_t *res;

res = gc_flex_alloc(break_info_t, int32_t, new_slots, NULL);
res = c4m_gc_flex_alloc(c4m_break_info_t, int32_t, new_slots, NULL);

res->num_slots = new_slots;
res->num_breaks = breaks->num_breaks;
Expand All @@ -44,12 +46,12 @@ grow_break_structure(break_info_t *breaks)
}

static inline void
add_break(break_info_t **listp, int32_t br)
c4m_add_break(c4m_break_info_t **listp, int32_t br)
{
break_info_t *breaks = *listp;
c4m_break_info_t *breaks = *listp;

if (breaks->num_slots == breaks->num_breaks) {
breaks = grow_break_structure(breaks);
breaks = c4m_grow_break_structure(breaks);
*listp = breaks;
}

Expand Down
Loading

0 comments on commit c16f75c

Please sign in to comment.