Skip to content

Commit

Permalink
Merge branch 'main' into ee7/add-initial-test-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ee7 committed Jun 19, 2024
2 parents 64c7c01 + 5f4d4b3 commit 3c09320
Show file tree
Hide file tree
Showing 46 changed files with 897 additions and 408 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ subprojects/*/
.meson_last
.vscode
.cache
deps/local
Binary file added deps/Darwin-arm64/libffi.a
Binary file not shown.
Binary file added deps/linux-amd64/libffi.a
Binary file not shown.
Binary file added deps/linux-arm64/libffi.a
Binary file not shown.
5 changes: 5 additions & 0 deletions dev
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ function color {
}

OS=$(uname -o 2>/dev/null)
ARCH=$(uname -m 2>/dev/null)
PWD=$(pwd)

if [[ $? -ne 0 ]] ; then
# Older macOS/OSX versions of uname don't support -o
OS=$(uname -s)
Expand All @@ -32,6 +35,8 @@ function log {
function meson_build {

echo ${1} > .meson_last
rm deps/local 2>/dev/null
ln -s ${PWD}/deps/${OS}-${ARCH} ${PWD}/deps/local


if [[ ! -d ${1} ]]; then
Expand Down
3 changes: 3 additions & 0 deletions include/compiler/datatypes/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ typedef enum {
c4m_err_augmented_assign_to_slice,
c4m_warn_cant_export,
c4m_err_assigned_void,
c4m_err_callback_no_match,
c4m_err_callback_bad_target,
c4m_err_callback_type_mismatch,
c4m_err_last,
} c4m_compile_error_t;

Expand Down
2 changes: 2 additions & 0 deletions include/compiler/datatypes/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ typedef struct c4m_file_compile_ctx {
c4m_xlist_t *fn_def_syms; // Cache of fns defined.
c4m_zmodule_info_t *module_object;
c4m_xlist_t *call_patch_locs;
c4m_xlist_t *callback_literals;
c4m_xlist_t *extern_decls;
int32_t static_size;
uint32_t num_params;
uint16_t local_module_id;
Expand Down
63 changes: 0 additions & 63 deletions include/compiler/datatypes/nodeinfo.h
Original file line number Diff line number Diff line change
@@ -1,69 +1,6 @@
#pragma once
#include "con4m.h"

typedef struct {
c4m_utf8_t *litmod;
c4m_lit_syntax_t st;
c4m_type_t *cast_to;
c4m_builtin_t base_type; // only set for containers from here down.
int num_items;
c4m_type_t *type;
} c4m_lit_info_t;

typedef struct {
c4m_type_t *full_type;
c4m_scope_t *fn_scope;
c4m_scope_t *formals;
c4m_fn_param_info_t *param_info;
c4m_fn_param_info_t return_info;
int num_params;
unsigned int pure : 1;
unsigned int void_return : 1;
} c4m_sig_info_t;

typedef struct {
c4m_utf8_t *short_doc;
c4m_utf8_t *long_doc;
c4m_sig_info_t *signature_info;
struct c4m_cfg_node_t *cfg;
int32_t frame_size;
// sc = 'short circuit'
// If we are a 'once' function, this is the offset into static data,
// where we will place:
//
// - A boolean.
// - A pthread_mutex_t
// - A void *
//
// The idea is, if the boolean is true, we only ever read and
// return the cached (memoized) result, stored in the void *. If
// it's false, we grab the lock, check the boolean a second time,
// run thecm function, set the memo and the boolean, and then
// unlock.
int32_t sc_lock_offset;
int32_t sc_bool_offset;
int32_t sc_memo_offset;
int32_t local_id;
int32_t offset;
int32_t module_id;

unsigned int private : 1;
unsigned int once : 1;
} c4m_fn_decl_t;

typedef struct {
c4m_utf8_t *short_doc;
c4m_utf8_t *long_doc;
c4m_utf8_t *local_name;
c4m_sig_info_t *local_params;
int num_params;
c4m_utf8_t *external_name;
uint8_t *external_params;
uint8_t external_return_type;
int holds;
int allocs;
} c4m_ffi_decl_t;

// This data structure is the first bytes of the extra_info field for anything
// that might be a jump target, including loops, conditionals, case statements,
// etc.
Expand Down
10 changes: 0 additions & 10 deletions include/compiler/datatypes/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ typedef struct {
c4m_utf8_t *specified_uri;
} c4m_module_info_t;

// For extern entries, the data structure will be in the `value`
// field.

typedef struct {
c4m_utf8_t *name;
c4m_type_t *type;
unsigned int ffi_holds : 1;
unsigned int ffi_allocs : 1;
} c4m_fn_param_info_t;

typedef struct c4m_scope_entry_t {
// The `value` field gets the proper value for vars and enums, but
// for other types, it gets a pointer to one of the specific data
Expand Down
1 change: 1 addition & 0 deletions include/compiler/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ typedef struct pass1_ctx {
c4m_file_compile_ctx *file_ctx;
c4m_scope_t *static_scope;
bool in_func;
c4m_xlist_t *extern_decls;
} pass1_ctx;

static inline c4m_tree_node_t *
Expand Down
2 changes: 2 additions & 0 deletions include/con4m.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@
#include "compiler/codegen.h"

#include "con4m/set.h"

#include "con4m/ffi.h"
8 changes: 5 additions & 3 deletions include/con4m/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ typedef struct hatrack_set_st c4m_set_t;
#include "con4m/datatypes/box.h"
#include "con4m/datatypes/memory.h"
#include "con4m/datatypes/kargs.h"
#include "con4m/datatypes/literals.h"
#include "con4m/datatypes/objects.h"
#include "con4m/datatypes/literals.h"
#include "con4m/datatypes/colors.h"
#include "con4m/datatypes/codepoints.h"
#include "con4m/datatypes/styles.h"
Expand All @@ -23,14 +23,16 @@ typedef struct hatrack_set_st c4m_set_t;
#include "con4m/datatypes/exceptions.h"
#include "con4m/datatypes/mixed.h"
#include "con4m/datatypes/tuples.h"
#include "con4m/datatypes/callbacks.h"
#include "con4m/datatypes/streams.h"
#include "con4m/datatypes/format.h"
#include "con4m/datatypes/vm.h"
#include "compiler/datatypes/lex.h"
#include "compiler/datatypes/error.h"
#include "compiler/datatypes/parse.h"
#include "compiler/datatypes/scope.h"
#include "con4m/datatypes/ffi.h"
#include "con4m/datatypes/ufi.h"
#include "con4m/datatypes/vm.h"
#include "con4m/datatypes/callbacks.h"
#include "compiler/datatypes/nodeinfo.h"
#include "compiler/datatypes/spec.h"
#include "compiler/datatypes/cfg.h"
Expand Down
51 changes: 4 additions & 47 deletions include/con4m/datatypes/callbacks.h
Original file line number Diff line number Diff line change
@@ -1,54 +1,11 @@
#pragma once

typedef enum {
FFI_ABI_0 = 0,
FFI_ABI_1 = 1,
FFI_ABI_2 = 2,
} c4m_ffi_abi;

typedef struct _c4m_ffi_type {
size_t size;
unsigned short alignment;
unsigned short type;
struct _c4m_ffi_type **elements;
} c4m_ffi_type;

typedef enum {
FFI_OK = 0,
FFI_BAD_TYPEDEF,
FFI_BAD_ABI
} c4m_ffi_status;

typedef struct {
c4m_ffi_abi abi;
unsigned nargs;
c4m_ffi_type **arg_types;
c4m_ffi_type *rtype;
unsigned bytes;
unsigned flags;
} c4m_ffi_cif;

#include "con4m.h"

typedef struct {
c4m_ffi_cif call_interface;
c4m_ffi_abi abi;
c4m_ffi_type return_type;
unsigned int fixedargs;
c4m_ffi_type *arg_types;
} c4m_ffi_info_t;

typedef struct {
void *fn; // Can point into the VM or to ELF fn
c4m_ffi_info_t *ffi;
c4m_type_t *type;
char *name;
uint8_t flags;
} c4m_funcinfo_t;

typedef struct {
c4m_funcinfo_t *info; // Shared when possible.
bool bound;
c4m_utf8_t *target_symbol_name;
c4m_type_t *target_type;
c4m_funcinfo_t binding;
c4m_tree_node_t *decl_loc;
} c4m_callback_t;

#define C4M_CB_FLAG_FFI 1
Expand Down
98 changes: 98 additions & 0 deletions include/con4m/datatypes/ffi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#pragma once
#include "con4m.h"

// For the foreign function interface, it's easier to redeclare
// libffi's structures than to deal w/ ensuring we have the right .h
// on each architecture. The only thing we need that might be
// different on different platforms is the ABI; hopefully
// FFI_DEFAUL T_ABI is the same everywhere, but if it isn't, that's
// easier to deal with than the header file situation.
//

typedef enum {
C4M_FFI_FIRST_ABI = 0,
C4M_FFI_DEFAULT_ABI,
C4M_FFI_LAST_ABI,
} c4m_ffi_abi;

// This is libffi's `ffi_type`.
typedef struct c4m_ffi_type {
size_t size;
unsigned short alignment;
unsigned short ffitype;
struct c4m_ffi_type **elements;
} c4m_ffi_type;

// This is libffi's `ffi_cif` type.
typedef struct {
c4m_ffi_abi abi;
unsigned nargs;
c4m_ffi_type **arg_types;
c4m_ffi_type *rtype;
unsigned bytes;
unsigned flags;
// Currently, no platform in libffi takes more than two 'unsigned int's
// worth of space, so only one of these should be necessary, but
// adding an extra one just in case; enough platforms take two fields
// that I can see there eventually being a platform w/ 2 64-bit slots.
// We alloc ourselves based on this size, so no worries there.
uint64_t extra_cif1;
uint64_t extra_cif2;
} c4m_ffi_cif;

typedef struct {
void *fptr;
c4m_utf8_t *local_name;
c4m_utf8_t *extern_name;
uint64_t str_convert;
uint64_t hold_info;
uint64_t alloc_info;
c4m_ffi_cif cif;
c4m_ffi_type **args;
c4m_ffi_type *ret;
} c4m_zffi_cif;

typedef enum {
C4M_FFI_OK = 0,
C4M_FFI_BAD_TYPEDEF,
C4M_FFI_BAD_ABI,
C4M_FFI_BAD_ARGTYPE
} c4m_ffi_status;

typedef struct c4m_ffi_decl_t {
c4m_utf8_t *short_doc;
c4m_utf8_t *long_doc;
c4m_utf8_t *local_name;
struct c4m_sig_info_t *local_params;
int num_ext_params;
int global_ffi_call_ix;
c4m_utf8_t *external_name;
uint8_t *external_params;
uint8_t external_return_type;
c4m_xlist_t *dll_list;
c4m_zffi_cif cif;
} c4m_ffi_decl_t;

extern c4m_ffi_type ffi_type_void;
extern c4m_ffi_type ffi_type_uint8;
extern c4m_ffi_type ffi_type_sint8;
extern c4m_ffi_type ffi_type_uint16;
extern c4m_ffi_type ffi_type_sint16;
extern c4m_ffi_type ffi_type_uint32;
extern c4m_ffi_type ffi_type_sint32;
extern c4m_ffi_type ffi_type_uint64;
extern c4m_ffi_type ffi_type_sint64;
extern c4m_ffi_type ffi_type_float;
extern c4m_ffi_type ffi_type_double;
extern c4m_ffi_type ffi_type_pointer;

#define ffi_type_uchar ffi_type_uint8
#define ffi_type_schar ffi_type_sint8
#define ffi_type_ushort ffi_type_uint16
#define ffi_type_sshort ffi_type_sint16
#define ffi_type_ushort ffi_type_uint16
#define ffi_type_sshort ffi_type_sint16
#define ffi_type_uint ffi_type_uint32
#define ffi_type_sint ffi_type_sint32
#define ffi_type_ulong ffi_type_uint64
#define ffi_type_slong ffi_type_sint64
9 changes: 9 additions & 0 deletions include/con4m/datatypes/literals.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ typedef enum {
ST_Tuple = 8,
ST_MAX = 9
} c4m_lit_syntax_t;

typedef struct {
struct c4m_str_t *litmod;
c4m_lit_syntax_t st;
struct c4m_type_t *cast_to;
c4m_builtin_t base_type; // only set for containers from here down.
struct c4m_type_t *type;
int num_items;
} c4m_lit_info_t;
1 change: 1 addition & 0 deletions include/con4m/datatypes/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ typedef struct c4m_finalizer_info_t {
typedef struct c4m_arena_t {
c4m_alloc_hdr *next_alloc;
c4m_dict_t *roots;
c4m_set_t *external_holds;
// queue_t *late_mutations;
uint64_t *heap_end;
c4m_finalizer_info_t *to_finalize;
Expand Down
2 changes: 1 addition & 1 deletion include/con4m/datatypes/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
** NOT to distinguish whether strings are UTF-8 (the high bit will
** always be 0 with UTF-8).
**/
typedef struct {
typedef struct c4m_str_t {
// clang-format off
alignas(8)
int32_t codepoints;
Expand Down
Loading

0 comments on commit 3c09320

Please sign in to comment.