1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-23 06:50:26 +00:00

Local changes.

This commit is contained in:
Calvin Rose 2018-08-07 00:54:47 -04:00
parent 7e66b37cff
commit 48c2654312
12 changed files with 269 additions and 224 deletions

View File

@ -32,7 +32,7 @@ BINDIR=$(PREFIX)/bin
# TODO - when api is finalized, only export public symbols instead of using rdynamic
# which exports all symbols. Saves a few KB in binary.
CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2
CFLAGS=-std=c99 -Wall -Wextra -Isrc/include -fpic -O2 -fvisibility=hidden
CLIBS=-lm -ldl
PREFIX=/usr/local
DST_TARGET=dst

View File

@ -23,8 +23,8 @@ init:
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
install:
- build
- build test
- build_win
- build_win test
build: off

View File

@ -1,7 +1,7 @@
@rem Build dst on windows
@rem
@rem Open a "Windows SDK Command Shell" in the dst directory
@rem and run this script
@rem Open a "Windows SDK Command Shell" and cd to the dst directory
@rem Then run this script with no arguments to build the executable
@echo off
@ -15,40 +15,44 @@
@rem Set compile and link options here
@setlocal
@set DST_COMPILE=cl /nologo /Isrc\include /c /O2 /W3 /D_CRT_SECURE_NO_WARNINGS
@set DST_COMPILE=cl /nologo /Isrc\include /c /O2 /W3 /LD /D_CRT_SECURE_NO_WARNINGS
@set DST_LINK=link /nologo
mkdir build
mkdir build\core
mkdir build\mainclient
@rem Build the xxd tool for generating sources
@cl /nologo /c src/tools/xxd.c /Foxxd.o
@cl /nologo /c src/tools/xxd.c /Fobuild\xxd.obj
@if errorlevel 1 goto :BUILDFAIL
@link /nologo /out:xxd.exe xxd.o
@link /nologo /out:build\xxd.exe build\xxd.obj
@if errorlevel 1 goto :BUILDFAIL
@rem Generate the headers
@xxd.exe src/core/core.dst src/include/generated/core.h dst_gen_core
@build\xxd.exe src\core\core.dst src\include\generated\core.h dst_gen_core
@if errorlevel 1 goto :BUILDFAIL
@xxd.exe src/mainclient/init.dst src/include/generated/init.h dst_gen_init
@build\xxd.exe src\mainclient\init.dst src\include\generated\init.h dst_gen_init
@if errorlevel 1 goto :BUILDFAIL
@rem Build the sources
for %%f in (src/core/*.c) do (
@%DST_COMPILE% src/core/%%f
for %%f in (src\core\*.c) do (
@%DST_COMPILE% /Fobuild\core\%%~nf.obj %%f
@if errorlevel 1 goto :BUILDFAIL
)
@rem Build the main client
for %%f in (src/mainclient/*.c) do (
@%DST_COMPILE% src/mainclient/%%f
for %%f in (src\mainclient\*.c) do (
@%DST_COMPILE% /Fobuild\mainclient\%%~nf.obj %%f
@if errorlevel 1 goto :BUILDFAIL
)
@rem Link everything to main client
%DST_LINK% /out:dst.exe *.obj
%DST_LINK% /out:dst.exe build\core\*.obj build\mainclient\*.obj
@if errorlevel 1 goto :BUILDFAIL
echo === Successfully built dst.exe for Windows ===
echo === Run 'build test' to run tests. ==
echo === Run 'build clean' to delete build artifacts. ===
echo === Run 'build_win test' to run tests. ==
echo === Run 'build_win clean' to delete build artifacts. ===
exit /b 0
@rem Not using correct command line
@ -67,11 +71,8 @@ exit /b 0
@rem Clean build artifacts
:CLEAN
del *.obj
del xxd.o
del xxd.exe
del dst.exe
del src\include\generated\*.h
del dst.exe dst.exp dst.lib
rd /s /q build
exit /b 0
@rem Run tests

View File

@ -44,7 +44,7 @@
"\n\n")
(emit-rule out "all" "${TARGET}")
(emit-rule out "%.o" @["%.c" "${HEADERS}"] "${CC} ${CFLAGS} -o $@ $< ${LDFLAGS}")
(emit-rule out "${TARGET}" "${SOURCES}" "${CC} ${CFLAGS} -o $@ $^ ${LDFLAGS}")
(emit-rule out "${TARGET}" "${OBJECTS}" "${CC} ${CFLAGS} -o $@ $^ ${LDFLAGS}")
(emit-rule out "clean" "" "rm ${OBJECTS}")
# Phony targets
(emit-rule out ".PHONY" @["all" "clean"])

View File

@ -1,34 +0,0 @@
# Copyright (c) 2017 Calvin Rose
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
cmake_minimum_required(VERSION 3.7)
project(hello)
# Set Some Variables
set(TARGET_NAME "hello")
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(SOURCES main.c)
include_directories(../../src/include)
# Build the module
add_library(${TARGET_NAME} SHARED ${SOURCES})

49
natives/hello/build.bat Normal file
View File

@ -0,0 +1,49 @@
@rem Build dst on windows
@rem
@rem Open a "Windows SDK Command Shell" and cd to the dst directory
@rem Then run this script with no arguments to build the executable
@echo off
@rem Ensure correct command prompt
@if not defined INCLUDE goto :BADCMD
@rem Subcommands
@if "%1"=="clean" goto CLEAN
@rem Set compile and link options here
@setlocal
@set DST_COMPILE=cl /nologo /I..\..\src\include /c /O2 /W3
@set DST_LINK=link /nologo /dll ..\..\dst.lib
@rem Build the sources
for %%f in (*.c) do (
@%DST_COMPILE% %%f
@if errorlevel 1 goto :BUILDFAIL
)
%DST_LINK% /out:hello.dll *.obj
@if errorlevel 1 goto :BUILDFAIL
echo === Successfully built hello.dll for Windows ===
echo === Run 'build clean' to delete build artifacts. ===
exit /b 0
@rem Not using correct command line
:BADCMD
@echo Use a Visual Studio Developer Command Prompt to run this script
exit /b 1
@rem Clean build artifacts
:CLEAN
del *.obj
del hello.*
exit /b 0
@rem Build failed
:BUILDFAIL
@echo.
@echo *******************************************************
@echo *** Build FAILED -- Please check the error messages ***
@echo *******************************************************
exit /b 1

View File

@ -35,7 +35,7 @@ static const DstReg cfuns[] = {
{NULL, NULL}
};
int _dst_init(DstArgs args) {
DST_MODULE_ENTRY (DstArgs args) {
DstTable *env = dst_env_arg(args);
dst_env_cfuns(env, cfuns);
return 0;

View File

@ -1138,8 +1138,8 @@
"./?/init.dst"
"./dst_modules/?.dst"
"./dst_modules/?/init.dst"
(string syspath VERSION "/?.dst")
(string syspath VERSION "/?/init.dst")
(string syspath dst.version "/?.dst")
(string syspath dst.version "/?/init.dst")
(string syspath "/?.dst")
(string syspath "/?/init.dst")])
(defglobal 'module.native-paths
@ -1147,10 +1147,18 @@
"./?/??.so"
"./dst_modules/?.so"
"./dst_modules/?/??.so"
(string syspath VERSION "/?.so")
(string syspath VERSION "/?/??.so")
(string syspath dst.version "/?.so")
(string syspath dst.version "/?/??.so")
(string syspath "/?.so")
(string syspath "/?/??.so")]))
(if (= :windows (os.which))
(loop [i :range [0 (length module.native-paths)]]
(def x (get module.native-paths i))
(put
module.native-paths
i
(string.replace ".so" ".dll" x))))
(defn module.find
[path paths]

View File

@ -540,7 +540,8 @@ DstTable *dst_core_env(void) {
templatize_comparator(env, DST_FUN_EQ, "==", 0, DOP_NUMERIC_EQUAL);
templatize_comparator(env, DST_FUN_NEQ, "not==", 1, DOP_NUMERIC_EQUAL);
dst_env_def(env, "VERSION", dst_cstringv(DST_VERSION));
/* Platform detection */
dst_env_def(env, "dst.version", dst_cstringv(DST_VERSION));
/* Set as gc root */
dst_gcroot(dst_wrap_table(env));

View File

@ -34,6 +34,16 @@
#include <stdio.h>
#endif
static int os_which(DstArgs args) {
#ifdef DST_WINDOWS
DST_RETURN_CSYMBOL(args, ":windows");
#elif __APPLE__
DST_RETURN_CSYMBOL(args, ":macos");
#else
DST_RETURN_CSYMBOL(args, ":posix");
#endif
}
#ifdef DST_WINDOWS
static int os_execute(DstArgs args) {
DST_MINARITY(args, 1);
@ -259,6 +269,7 @@ static int os_cwd(DstArgs args) {
}
static const DstReg cfuns[] = {
{"os.which", os_which},
{"os.execute", os_execute},
{"os.shell", os_shell},
{"os.exit", os_exit},

View File

@ -109,6 +109,15 @@ extern "C" {
#define DST_DYNAMIC_MODULES
#endif
/* How to export symbols */
#ifndef DST_API
#ifdef DST_WINDOWS
#define DST_API __declspec(dllexport)
#else
#define DST_API __attribute__((visibility ("default")))
#endif
#endif
/* Handle runtime errors */
#ifndef dst_exit
#include <stdio.h>
@ -387,13 +396,13 @@ union Dst {
? dst_nanbox_isreal(x) \
: dst_nanbox_checkauxtype((x), (t)))
void *dst_nanbox_to_pointer(Dst x);
void dst_nanbox_memempty(DstKV *mem, int32_t count);
void *dst_nanbox_memalloc_empty(int32_t count);
Dst dst_nanbox_from_pointer(void *p, uint64_t tagmask);
Dst dst_nanbox_from_cpointer(const void *p, uint64_t tagmask);
Dst dst_nanbox_from_double(double d);
Dst dst_nanbox_from_bits(uint64_t bits);
DST_API void *dst_nanbox_to_pointer(Dst x);
DST_API void dst_nanbox_memempty(DstKV *mem, int32_t count);
DST_API void *dst_nanbox_memalloc_empty(int32_t count);
DST_API Dst dst_nanbox_from_pointer(void *p, uint64_t tagmask);
DST_API Dst dst_nanbox_from_cpointer(const void *p, uint64_t tagmask);
DST_API Dst dst_nanbox_from_double(double d);
DST_API Dst dst_nanbox_from_bits(uint64_t bits);
#define dst_memempty(mem, len) dst_nanbox_memempty((mem), (len))
#define dst_memalloc_empty(count) dst_nanbox_memalloc_empty(count)
@ -492,23 +501,23 @@ struct Dst {
#define dst_unwrap_integer(x) ((x).as.integer)
#define dst_unwrap_real(x) ((x).as.real)
Dst dst_wrap_nil(void);
Dst dst_wrap_real(double x);
Dst dst_wrap_integer(int32_t x);
Dst dst_wrap_true(void);
Dst dst_wrap_false(void);
Dst dst_wrap_boolean(int x);
Dst dst_wrap_string(const uint8_t *x);
Dst dst_wrap_symbol(const uint8_t *x);
Dst dst_wrap_array(DstArray *x);
Dst dst_wrap_tuple(const Dst *x);
Dst dst_wrap_struct(const DstKV *x);
Dst dst_wrap_fiber(DstFiber *x);
Dst dst_wrap_buffer(DstBuffer *x);
Dst dst_wrap_function(DstFunction *x);
Dst dst_wrap_cfunction(DstCFunction x);
Dst dst_wrap_table(DstTable *x);
Dst dst_wrap_abstract(void *x);
DST_API Dst dst_wrap_nil(void);
DST_API Dst dst_wrap_real(double x);
DST_API Dst dst_wrap_integer(int32_t x);
DST_API Dst dst_wrap_true(void);
DST_API Dst dst_wrap_false(void);
DST_API Dst dst_wrap_boolean(int x);
DST_API Dst dst_wrap_string(const uint8_t *x);
DST_API Dst dst_wrap_symbol(const uint8_t *x);
DST_API Dst dst_wrap_array(DstArray *x);
DST_API Dst dst_wrap_tuple(const Dst *x);
DST_API Dst dst_wrap_struct(const DstKV *x);
DST_API Dst dst_wrap_fiber(DstFiber *x);
DST_API Dst dst_wrap_buffer(DstBuffer *x);
DST_API Dst dst_wrap_function(DstFunction *x);
DST_API Dst dst_wrap_cfunction(DstCFunction x);
DST_API Dst dst_wrap_table(DstTable *x);
DST_API Dst dst_wrap_abstract(void *x);
/* End of tagged union implementation */
#endif
@ -827,14 +836,14 @@ extern enum DstInstructionType dst_instructions[DOP_INSTRUCTION_COUNT];
/***** START SECTION MAIN *****/
/* Parsing */
void dst_parser_init(DstParser *parser);
void dst_parser_deinit(DstParser *parser);
int dst_parser_consume(DstParser *parser, uint8_t c);
enum DstParserStatus dst_parser_status(DstParser *parser);
Dst dst_parser_produce(DstParser *parser);
const char *dst_parser_error(DstParser *parser);
void dst_parser_flush(DstParser *parser);
DstParser *dst_check_parser(Dst x);
DST_API void dst_parser_init(DstParser *parser);
DST_API void dst_parser_deinit(DstParser *parser);
DST_API int dst_parser_consume(DstParser *parser, uint8_t c);
DST_API enum DstParserStatus dst_parser_status(DstParser *parser);
DST_API Dst dst_parser_produce(DstParser *parser);
DST_API const char *dst_parser_error(DstParser *parser);
DST_API void dst_parser_flush(DstParser *parser);
DST_API DstParser *dst_check_parser(Dst x);
/* Assembly */
typedef struct DstAssembleResult DstAssembleResult;
@ -848,9 +857,9 @@ struct DstAssembleResult {
const uint8_t *error;
enum DstAssembleStatus status;
};
DstAssembleResult dst_asm(Dst source, int flags);
Dst dst_disasm(DstFuncDef *def);
Dst dst_asm_decode_instruction(uint32_t instr);
DST_API DstAssembleResult dst_asm(Dst source, int flags);
DST_API Dst dst_disasm(DstFuncDef *def);
DST_API Dst dst_asm_decode_instruction(uint32_t instr);
/* Compilation */
typedef struct DstCompileOptions DstCompileOptions;
@ -866,44 +875,44 @@ struct DstCompileResult {
DstSourceMapping error_mapping;
enum DstCompileStatus status;
};
DstCompileResult dst_compile(Dst source, DstTable *env, const uint8_t *where);
DST_API DstCompileResult dst_compile(Dst source, DstTable *env, const uint8_t *where);
/* Get the default environment for dst */
DstTable *dst_core_env(void);
DST_API DstTable *dst_core_env(void);
int dst_dobytes(DstTable *env, const uint8_t *bytes, int32_t len, const char *sourcePath);
int dst_dostring(DstTable *env, const char *str, const char *sourcePath);
DST_API int dst_dobytes(DstTable *env, const uint8_t *bytes, int32_t len, const char *sourcePath);
DST_API int dst_dostring(DstTable *env, const char *str, const char *sourcePath);
/* Number scanning */
Dst dst_scan_number(const uint8_t *src, int32_t len);
int32_t dst_scan_integer(const uint8_t *str, int32_t len, int *err);
double dst_scan_real(const uint8_t *str, int32_t len, int *err);
DST_API Dst dst_scan_number(const uint8_t *src, int32_t len);
DST_API int32_t dst_scan_integer(const uint8_t *str, int32_t len, int *err);
DST_API double dst_scan_real(const uint8_t *str, int32_t len, int *err);
/* Array functions */
DstArray *dst_array(int32_t capacity);
DstArray *dst_array_n(const Dst *elements, int32_t n);
DstArray *dst_array_init(DstArray *array, int32_t capacity);
void dst_array_deinit(DstArray *array);
void dst_array_ensure(DstArray *array, int32_t capacity);
void dst_array_setcount(DstArray *array, int32_t count);
void dst_array_push(DstArray *array, Dst x);
Dst dst_array_pop(DstArray *array);
Dst dst_array_peek(DstArray *array);
DST_API DstArray *dst_array(int32_t capacity);
DST_API DstArray *dst_array_n(const Dst *elements, int32_t n);
DST_API DstArray *dst_array_init(DstArray *array, int32_t capacity);
DST_API void dst_array_deinit(DstArray *array);
DST_API void dst_array_ensure(DstArray *array, int32_t capacity);
DST_API void dst_array_setcount(DstArray *array, int32_t count);
DST_API void dst_array_push(DstArray *array, Dst x);
DST_API Dst dst_array_pop(DstArray *array);
DST_API Dst dst_array_peek(DstArray *array);
/* Buffer functions */
DstBuffer *dst_buffer(int32_t capacity);
DstBuffer *dst_buffer_init(DstBuffer *buffer, int32_t capacity);
void dst_buffer_deinit(DstBuffer *buffer);
void dst_buffer_ensure(DstBuffer *buffer, int32_t capacity);
void dst_buffer_setcount(DstBuffer *buffer, int32_t count);
int dst_buffer_extra(DstBuffer *buffer, int32_t n);
int dst_buffer_push_bytes(DstBuffer *buffer, const uint8_t *string, int32_t len);
int dst_buffer_push_string(DstBuffer *buffer, const uint8_t *string);
int dst_buffer_push_cstring(DstBuffer *buffer, const char *cstring);
int dst_buffer_push_u8(DstBuffer *buffer, uint8_t x);
int dst_buffer_push_u16(DstBuffer *buffer, uint16_t x);
int dst_buffer_push_u32(DstBuffer *buffer, uint32_t x);
int dst_buffer_push_u64(DstBuffer *buffer, uint64_t x);
DST_API DstBuffer *dst_buffer(int32_t capacity);
DST_API DstBuffer *dst_buffer_init(DstBuffer *buffer, int32_t capacity);
DST_API void dst_buffer_deinit(DstBuffer *buffer);
DST_API void dst_buffer_ensure(DstBuffer *buffer, int32_t capacity);
DST_API void dst_buffer_setcount(DstBuffer *buffer, int32_t count);
DST_API int dst_buffer_extra(DstBuffer *buffer, int32_t n);
DST_API int dst_buffer_push_bytes(DstBuffer *buffer, const uint8_t *string, int32_t len);
DST_API int dst_buffer_push_string(DstBuffer *buffer, const uint8_t *string);
DST_API int dst_buffer_push_cstring(DstBuffer *buffer, const char *cstring);
DST_API int dst_buffer_push_u8(DstBuffer *buffer, uint8_t x);
DST_API int dst_buffer_push_u16(DstBuffer *buffer, uint16_t x);
DST_API int dst_buffer_push_u32(DstBuffer *buffer, uint32_t x);
DST_API int dst_buffer_push_u64(DstBuffer *buffer, uint64_t x);
/* Tuple */
#define dst_tuple_raw(t) ((int32_t *)(t) - 4)
@ -911,40 +920,40 @@ int dst_buffer_push_u64(DstBuffer *buffer, uint64_t x);
#define dst_tuple_hash(t) ((dst_tuple_raw(t)[1]))
#define dst_tuple_sm_line(t) ((dst_tuple_raw(t)[2]))
#define dst_tuple_sm_col(t) ((dst_tuple_raw(t)[3]))
Dst *dst_tuple_begin(int32_t length);
const Dst *dst_tuple_end(Dst *tuple);
const Dst *dst_tuple_n(const Dst *values, int32_t n);
int dst_tuple_equal(const Dst *lhs, const Dst *rhs);
int dst_tuple_compare(const Dst *lhs, const Dst *rhs);
DST_API Dst *dst_tuple_begin(int32_t length);
DST_API const Dst *dst_tuple_end(Dst *tuple);
DST_API const Dst *dst_tuple_n(const Dst *values, int32_t n);
DST_API int dst_tuple_equal(const Dst *lhs, const Dst *rhs);
DST_API int dst_tuple_compare(const Dst *lhs, const Dst *rhs);
/* String/Symbol functions */
#define dst_string_raw(s) ((int32_t *)(s) - 2)
#define dst_string_length(s) (dst_string_raw(s)[0])
#define dst_string_hash(s) ((dst_string_raw(s)[1]))
uint8_t *dst_string_begin(int32_t length);
const uint8_t *dst_string_end(uint8_t *str);
const uint8_t *dst_string(const uint8_t *buf, int32_t len);
const uint8_t *dst_cstring(const char *cstring);
int dst_string_compare(const uint8_t *lhs, const uint8_t *rhs);
int dst_string_equal(const uint8_t *lhs, const uint8_t *rhs);
int dst_string_equalconst(const uint8_t *lhs, const uint8_t *rhs, int32_t rlen, int32_t rhash);
const uint8_t *dst_string_unique(const uint8_t *buf, int32_t len);
const uint8_t *dst_cstring_unique(const char *s);
const uint8_t *dst_description(Dst x);
const uint8_t *dst_to_string(Dst x);
void dst_to_string_b(DstBuffer *buffer, Dst x);
void dst_to_description_b(DstBuffer *buffer, Dst x);
const char *dst_to_zerostring(Dst x);
DST_API uint8_t *dst_string_begin(int32_t length);
DST_API const uint8_t *dst_string_end(uint8_t *str);
DST_API const uint8_t *dst_string(const uint8_t *buf, int32_t len);
DST_API const uint8_t *dst_cstring(const char *cstring);
DST_API int dst_string_compare(const uint8_t *lhs, const uint8_t *rhs);
DST_API int dst_string_equal(const uint8_t *lhs, const uint8_t *rhs);
DST_API int dst_string_equalconst(const uint8_t *lhs, const uint8_t *rhs, int32_t rlen, int32_t rhash);
DST_API const uint8_t *dst_string_unique(const uint8_t *buf, int32_t len);
DST_API const uint8_t *dst_cstring_unique(const char *s);
DST_API const uint8_t *dst_description(Dst x);
DST_API const uint8_t *dst_to_string(Dst x);
DST_API void dst_to_string_b(DstBuffer *buffer, Dst x);
DST_API void dst_to_description_b(DstBuffer *buffer, Dst x);
DST_API const char *dst_to_zerostring(Dst x);
#define dst_cstringv(cstr) dst_wrap_string(dst_cstring(cstr))
#define dst_stringv(str, len) dst_wrap_string(dst_string((str), (len)))
const uint8_t *dst_formatc(const char *format, ...);
void dst_puts(const uint8_t *str);
DST_API const uint8_t *dst_formatc(const char *format, ...);
DST_API void dst_puts(const uint8_t *str);
/* Symbol functions */
const uint8_t *dst_symbol(const uint8_t *str, int32_t len);
const uint8_t *dst_symbol_from_string(const uint8_t *str);
const uint8_t *dst_csymbol(const char *str);
const uint8_t *dst_symbol_gen(void);
DST_API const uint8_t *dst_symbol(const uint8_t *str, int32_t len);
DST_API const uint8_t *dst_symbol_from_string(const uint8_t *str);
DST_API const uint8_t *dst_csymbol(const char *str);
DST_API const uint8_t *dst_symbol_gen(void);
#define dst_symbolv(str, len) dst_wrap_symbol(dst_symbol((str), (len)))
#define dst_csymbolv(cstr) dst_wrap_symbol(dst_csymbol(cstr))
@ -954,76 +963,76 @@ const uint8_t *dst_symbol_gen(void);
#define dst_struct_capacity(t) (dst_struct_raw(t)[1])
#define dst_struct_hash(t) (dst_struct_raw(t)[2])
/* Do something with the 4th header slot - flags? */
DstKV *dst_struct_begin(int32_t count);
void dst_struct_put(DstKV *st, Dst key, Dst value);
const DstKV *dst_struct_end(DstKV *st);
Dst dst_struct_get(const DstKV *st, Dst key);
const DstKV *dst_struct_next(const DstKV *st, const DstKV *kv);
DstTable *dst_struct_to_table(const DstKV *st);
int dst_struct_equal(const DstKV *lhs, const DstKV *rhs);
int dst_struct_compare(const DstKV *lhs, const DstKV *rhs);
const DstKV *dst_struct_find(const DstKV *st, Dst key);
DST_API DstKV *dst_struct_begin(int32_t count);
DST_API void dst_struct_put(DstKV *st, Dst key, Dst value);
DST_API const DstKV *dst_struct_end(DstKV *st);
DST_API Dst dst_struct_get(const DstKV *st, Dst key);
DST_API const DstKV *dst_struct_next(const DstKV *st, const DstKV *kv);
DST_API DstTable *dst_struct_to_table(const DstKV *st);
DST_API int dst_struct_equal(const DstKV *lhs, const DstKV *rhs);
DST_API int dst_struct_compare(const DstKV *lhs, const DstKV *rhs);
DST_API const DstKV *dst_struct_find(const DstKV *st, Dst key);
/* Table functions */
DstTable *dst_table(int32_t capacity);
DstTable *dst_table_init(DstTable *table, int32_t capacity);
void dst_table_deinit(DstTable *table);
Dst dst_table_get(DstTable *t, Dst key);
Dst dst_table_rawget(DstTable *t, Dst key);
Dst dst_table_remove(DstTable *t, Dst key);
void dst_table_put(DstTable *t, Dst key, Dst value);
const DstKV *dst_table_next(DstTable *t, const DstKV *kv);
const DstKV *dst_table_to_struct(DstTable *t);
void dst_table_merge_table(DstTable *table, DstTable *other);
void dst_table_merge_struct(DstTable *table, const DstKV *other);
DstKV *dst_table_find(DstTable *t, Dst key);
DST_API DstTable *dst_table(int32_t capacity);
DST_API DstTable *dst_table_init(DstTable *table, int32_t capacity);
DST_API void dst_table_deinit(DstTable *table);
DST_API Dst dst_table_get(DstTable *t, Dst key);
DST_API Dst dst_table_rawget(DstTable *t, Dst key);
DST_API Dst dst_table_remove(DstTable *t, Dst key);
DST_API void dst_table_put(DstTable *t, Dst key, Dst value);
DST_API const DstKV *dst_table_next(DstTable *t, const DstKV *kv);
DST_API const DstKV *dst_table_to_struct(DstTable *t);
DST_API void dst_table_merge_table(DstTable *table, DstTable *other);
DST_API void dst_table_merge_struct(DstTable *table, const DstKV *other);
DST_API DstKV *dst_table_find(DstTable *t, Dst key);
/* Fiber */
DstFiber *dst_fiber(DstFunction *callee, int32_t capacity);
DST_API DstFiber *dst_fiber(DstFunction *callee, int32_t capacity);
#define dst_fiber_status(f) (((f)->flags & DST_FIBER_STATUS_MASK) >> DST_FIBER_STATUS_OFFSET)
/* Treat similar types through uniform interfaces for iteration */
int dst_indexed_view(Dst seq, const Dst **data, int32_t *len);
int dst_bytes_view(Dst str, const uint8_t **data, int32_t *len);
int dst_dictionary_view(Dst tab, const DstKV **data, int32_t *len, int32_t *cap);
DST_API int dst_indexed_view(Dst seq, const Dst **data, int32_t *len);
DST_API int dst_bytes_view(Dst str, const uint8_t **data, int32_t *len);
DST_API int dst_dictionary_view(Dst tab, const DstKV **data, int32_t *len, int32_t *cap);
/* 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)
void *dst_abstract(const DstAbstractType *type, size_t size);
DST_API void *dst_abstract(const DstAbstractType *type, size_t size);
/* Native */
DstCFunction dst_native(const char *name, const uint8_t **error);
DST_API DstCFunction dst_native(const char *name, const uint8_t **error);
/* GC */
void dst_mark(Dst x);
void dst_sweep(void);
void dst_collect(void);
void dst_clear_memory(void);
void dst_gcroot(Dst root);
int dst_gcunroot(Dst root);
int dst_gcunrootall(Dst root);
int dst_gclock(void);
void dst_gcunlock(int handle);
DST_API void dst_mark(Dst x);
DST_API void dst_sweep(void);
DST_API void dst_collect(void);
DST_API void dst_clear_memory(void);
DST_API void dst_gcroot(Dst root);
DST_API int dst_gcunroot(Dst root);
DST_API int dst_gcunrootall(Dst root);
DST_API int dst_gclock(void);
DST_API void dst_gcunlock(int handle);
/* Functions */
DstFuncDef *dst_funcdef_alloc(void);
DstFunction *dst_thunk(DstFuncDef *def);
int dst_verify(DstFuncDef *def);
DST_API DstFuncDef *dst_funcdef_alloc(void);
DST_API DstFunction *dst_thunk(DstFuncDef *def);
DST_API int dst_verify(DstFuncDef *def);
/* Misc */
int dst_equals(Dst x, Dst y);
int32_t dst_hash(Dst x);
int dst_compare(Dst x, Dst y);
int dst_cstrcmp(const uint8_t *str, const char *other);
DST_API int dst_equals(Dst x, Dst y);
DST_API int32_t dst_hash(Dst x);
DST_API int dst_compare(Dst x, Dst y);
DST_API int dst_cstrcmp(const uint8_t *str, const char *other);
/* VM functions */
int dst_init(void);
void dst_deinit(void);
DstSignal dst_continue(DstFiber *fiber, Dst in, Dst *out);
DST_API int dst_init(void);
DST_API void dst_deinit(void);
DST_API DstSignal dst_continue(DstFiber *fiber, Dst in, Dst *out);
#define dst_run(F,O) dst_continue(F, dst_wrap_nil(), O)
DstSignal dst_call(DstFunction *fun, int32_t argn, const Dst *argv, Dst *out, DstFiber **f);
DST_API DstSignal dst_call(DstFunction *fun, int32_t argn, const Dst *argv, Dst *out, DstFiber **f);
/* Env helpers */
typedef enum {
@ -1032,35 +1041,35 @@ typedef enum {
DST_BINDING_VAR,
DST_BINDING_MACRO
} DstBindingType;
void dst_env_def(DstTable *env, const char *name, Dst val);
void dst_env_var(DstTable *env, const char *name, Dst val);
void dst_env_cfuns(DstTable *env, const DstReg *cfuns);
DstBindingType dst_env_resolve(DstTable *env, const uint8_t *sym, Dst *out);
DstTable *dst_env_arg(DstArgs args);
DST_API void dst_env_def(DstTable *env, const char *name, Dst val);
DST_API void dst_env_var(DstTable *env, const char *name, Dst val);
DST_API void dst_env_cfuns(DstTable *env, const DstReg *cfuns);
DST_API DstBindingType dst_env_resolve(DstTable *env, const uint8_t *sym, Dst *out);
DST_API DstTable *dst_env_arg(DstArgs args);
/* C Function helpers */
int dst_arity_err(DstArgs args, int32_t n, const char *prefix);
int dst_type_err(DstArgs args, int32_t n, DstType expected);
int dst_typemany_err(DstArgs args, int32_t n, int expected);
int dst_typeabstract_err(DstArgs args, int32_t n, const DstAbstractType *at);
DST_API int dst_arity_err(DstArgs args, int32_t n, const char *prefix);
DST_API int dst_type_err(DstArgs args, int32_t n, DstType expected);
DST_API int dst_typemany_err(DstArgs args, int32_t n, int expected);
DST_API int dst_typeabstract_err(DstArgs args, int32_t n, const DstAbstractType *at);
/* Initialize builtin libraries */
int dst_lib_io(DstArgs args);
int dst_lib_math(DstArgs args);
int dst_lib_array(DstArgs args);
int dst_lib_tuple(DstArgs args);
int dst_lib_buffer(DstArgs args);
int dst_lib_table(DstArgs args);
int dst_lib_fiber(DstArgs args);
int dst_lib_os(DstArgs args);
int dst_lib_string(DstArgs args);
int dst_lib_marsh(DstArgs args);
int dst_lib_parse(DstArgs args);
int dst_lib_asm(DstArgs args);
int dst_lib_compile(DstArgs args);
DST_API int dst_lib_io(DstArgs args);
DST_API int dst_lib_math(DstArgs args);
DST_API int dst_lib_array(DstArgs args);
DST_API int dst_lib_tuple(DstArgs args);
DST_API int dst_lib_buffer(DstArgs args);
DST_API int dst_lib_table(DstArgs args);
DST_API int dst_lib_fiber(DstArgs args);
DST_API int dst_lib_os(DstArgs args);
DST_API int dst_lib_string(DstArgs args);
DST_API int dst_lib_marsh(DstArgs args);
DST_API int dst_lib_parse(DstArgs args);
DST_API int dst_lib_asm(DstArgs args);
DST_API int dst_lib_compile(DstArgs args);
/* Helpers for writing modules */
#define DST_MODULE_ENTRY int _dst_init
#define DST_MODULE_ENTRY DST_API int _dst_init
/***** END SECTION MAIN *****/

View File

@ -23,7 +23,7 @@
-- Stop handling options`)
(os.exit 0)
1)
"v" (fn @[] (print VERSION) (os.exit 0) 1)
"v" (fn @[] (print dst.version) (os.exit 0) 1)
"s" (fn @[] (:= *raw-stdin* true) (:= *should-repl* true) 1)
"r" (fn @[] (:= *should-repl* true) 1)
"p" (fn @[] (:= *exit-on-error* false) 1)
@ -53,7 +53,7 @@
(if *raw-stdin*
(repl nil identity)
(do
(print (string "Dst " VERSION " Copyright (C) 2017-2018 Calvin Rose"))
(print (string "Dst " dst.version " Copyright (C) 2017-2018 Calvin Rose"))
(repl (fn [buf p]
(def [line] (parser.where p))
(def prompt (string "dst:" line ":" (parser.state p) "> "))