1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-29 22:53:03 +00:00

More compiler bug fixes. Added some features and functions like varargs.

This commit is contained in:
bakpakin
2018-01-03 21:36:10 -05:00
parent f273aa8b1b
commit e4735e14d2
23 changed files with 1155 additions and 743 deletions

View File

@@ -133,7 +133,6 @@ DstValue dst_fiber_popvalue(DstFiber *fiber);
void dst_fiber_funcframe(DstFiber *fiber, DstFunction *func);
void dst_fiber_funcframe_tail(DstFiber *fiber, DstFunction *func);
void dst_fiber_cframe(DstFiber *fiber);
void dst_fiber_cframe_tail(DstFiber *fiber);
void dst_fiber_popframe(DstFiber *fiber);
/* Functions */
@@ -143,16 +142,17 @@ void dst_function_detach(DstFunction *func);
DstAssembleResult dst_asm(DstAssembleOptions opts);
DstFunction *dst_asm_func(DstAssembleResult result);
DstValue dst_disasm(DstFuncDef *def);
DstValue dst_asm_decode_instruction(uint32_t instr);
/* Treat similar types through uniform interfaces for iteration */
int dst_seq_view(DstValue seq, const DstValue **data, int32_t *len);
int dst_chararray_view(DstValue str, const uint8_t **data, int32_t *len);
int dst_hashtable_view(DstValue tab, const DstValue **data, int32_t *len, int32_t *cap);
/* Userdata */
#define dst_userdata_header(u) ((DstUserdataHeader *)(u) - 1)
#define dst_userdata_type(u) (dst_userdata_header(u)->type)
#define dst_userdata_size(u) (dst_userdata_header(u)->size)
/* Abstract */
#define dst_abstract_header(u) ((DstAbstractHeader *)(u) - 1)
#define dst_abstract_type(u) (dst_abstract_header(u)->type)
#define dst_abstract_size(u) (dst_abstract_header(u)->size)
/* Value functions */
int dst_equals(DstValue x, DstValue y);

View File

@@ -116,6 +116,6 @@
#define DST_RECURSION_GUARD 1000
/* Use nanboxed values - uses 8 bytes per value instead of 12 or 16. */
#define DST_NANBOX
//#define DST_NANBOX
#endif /* DST_CONFIG_H_defined */

View File

@@ -47,10 +47,19 @@ int dst_sqrt(int32_t argn, DstValue *argv, DstValue *ret);
int dst_ceil(int32_t argn, DstValue *argv, DstValue *ret);
int dst_fabs(int32_t argn, DstValue *argv, DstValue *ret);
int dst_floor(int32_t argn, DstValue *argv, DstValue *ret);
int dst_pow(int32_t argn, DstValue *argv, DstValue *ret);
int dst_stl_table(int32_t argn, DstValue *argv, DstValue *ret);
int dst_stl_array(int32_t argn, DstValue *argv, DstValue *ret);
int dst_stl_struct(int32_t argn, DstValue *argv, DstValue *ret);
int dst_stl_tuple(int32_t argn, DstValue *argv, DstValue *ret);
int dst_band(int32_t argn, DstValue *argv, DstValue *ret);
int dst_bor(int32_t argn, DstValue *argv, DstValue *ret);
int dst_bxor(int32_t argn, DstValue *argv, DstValue *ret);
int dst_lshift(int argn, DstValue *argv, DstValue *ret);
int dst_rshift(int argn, DstValue *argv, DstValue *ret);
int dst_lshiftu(int argn, DstValue *argv, DstValue *ret);
#endif /* DST_MATH_H_defined */

View File

@@ -41,11 +41,11 @@ typedef struct DstFiber DstFiber;
/* Other structs */
typedef struct DstReg DstReg;
typedef struct DstUserdataHeader DstUserdataHeader;
typedef struct DstAbstractHeader DstAbstractHeader;
typedef struct DstFuncDef DstFuncDef;
typedef struct DstFuncEnv DstFuncEnv;
typedef struct DstStackFrame DstStackFrame;
typedef struct DstUserType DstUserType;
typedef struct DstAbstractType DstAbstractType;
typedef int (*DstCFunction)(int32_t argn, DstValue *argv, DstValue *ret);
typedef enum DstAssembleStatus DstAssembleStatus;
@@ -74,7 +74,7 @@ typedef enum DstType {
DST_BUFFER,
DST_FUNCTION,
DST_CFUNCTION,
DST_USERDATA
DST_ABSTRACT
} DstType;
/* We provide two possible implemenations of DstValues. The preferred
@@ -205,8 +205,7 @@ DstValue dst_nanbox_from_bits(uint64_t bits);
#define dst_wrap_buffer(s) dst_nanbox_wrap_((s), DST_BUFFER)
#define dst_wrap_string(s) dst_nanbox_wrap_c((s), DST_STRING)
#define dst_wrap_symbol(s) dst_nanbox_wrap_c((s), DST_SYMBOL)
#define dst_wrap_userdata(s) dst_nanbox_wrap_((s), DST_USERDATA)
#define dst_wrap_pointer(s) dst_nanbox_wrap_((s), DST_USERDATA)
#define dst_wrap_abstract(s) dst_nanbox_wrap_((s), DST_ABSTRACT)
#define dst_wrap_function(s) dst_nanbox_wrap_((s), DST_FUNCTION)
#define dst_wrap_cfunction(s) dst_nanbox_wrap_((s), DST_CFUNCTION)
@@ -219,7 +218,7 @@ DstValue dst_nanbox_from_bits(uint64_t bits);
#define dst_unwrap_buffer(x) ((DstBuffer *)dst_nanbox_to_pointer(x))
#define dst_unwrap_string(x) ((const uint8_t *)dst_nanbox_to_pointer(x))
#define dst_unwrap_symbol(x) ((const uint8_t *)dst_nanbox_to_pointer(x))
#define dst_unwrap_userdata(x) (dst_nanbox_to_pointer(x))
#define dst_unwrap_abstract(x) (dst_nanbox_to_pointer(x))
#define dst_unwrap_pointer(x) (dst_nanbox_to_pointer(x))
#define dst_unwrap_function(x) ((DstFunction *)dst_nanbox_to_pointer(x))
#define dst_unwrap_cfunction(x) ((DstCFunction)dst_nanbox_to_pointer(x))
@@ -255,7 +254,7 @@ struct DstValue {
#define dst_unwrap_buffer(x) ((DstBuffer *)(x).as.pointer)
#define dst_unwrap_string(x) ((const uint8_t *)(x).as.pointer)
#define dst_unwrap_symbol(x) ((const uint8_t *)(x).as.pointer)
#define dst_unwrap_userdata(x) ((x).as.pointer)
#define dst_unwrap_abstract(x) ((x).as.pointer)
#define dst_unwrap_pointer(x) ((x).as.pointer)
#define dst_unwrap_function(x) ((DstFunction *)(x).as.pointer)
#define dst_unwrap_cfunction(x) ((DstCFunction)(x).as.pointer)
@@ -279,8 +278,7 @@ DstValue dst_wrap_buffer(DstBuffer *x);
DstValue dst_wrap_function(DstFunction *x);
DstValue dst_wrap_cfunction(DstCFunction x);
DstValue dst_wrap_table(DstTable *x);
DstValue dst_wrap_userdata(void *x);
DstValue dst_wrap_pointer(void *x);
DstValue dst_wrap_abstract(void *x);
/* End of tagged union implementation */
#endif
@@ -297,7 +295,7 @@ struct DstFiber {
DstValue *data;
DstFiber *parent;
int32_t frame; /* Index of the stack frame */
int32_t frametop; /* Index of top of stack frame */
int32_t stackstart; /* Beginning of next args */
int32_t stacktop; /* Top of stack. Where values are pushed and popped from. */
int32_t capacity;
enum {
@@ -347,7 +345,8 @@ struct DstTable {
/* A function definition. Contains information needed to instantiate closures. */
struct DstFuncDef {
int32_t *environments; /* Which environments to capture from parent. */
DstValue *constants; /* Contains strings, FuncDefs, etc. */
DstValue *constants;
DstFuncDef **defs;
uint32_t *bytecode;
/* Various debug information */
@@ -361,6 +360,7 @@ struct DstFuncDef {
int32_t constants_length;
int32_t bytecode_length;
int32_t environments_length;
int32_t defs_length;
};
/* A fuction environment */
@@ -381,8 +381,8 @@ struct DstFunction {
DstFuncEnv **envs;
};
/* Defines a type for userdata */
struct DstUserType {
/* Defines an abstract type */
struct DstAbstractType {
const char *name;
int (*serialize)(void *data, size_t len);
int (*deserialize)();
@@ -390,8 +390,8 @@ struct DstUserType {
};
/* Contains information about userdata */
struct DstUserdataHeader {
const DstUserType *type;
struct DstAbstractHeader {
const DstAbstractType *type;
size_t size;
};
@@ -402,7 +402,6 @@ enum DstAssembleStatus {
};
struct DstAssembleOptions {
const DstValue *sourcemap;
DstValue source;
uint32_t flags;
};
@@ -410,8 +409,6 @@ struct DstAssembleOptions {
struct DstAssembleResult {
DstFuncDef *funcdef;
const uint8_t *error;
int32_t error_start;
int32_t error_end;
DstAssembleStatus status;
};