From fde9751eab65d0ee63a7da5960e65f2a41707406 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 29 Jun 2018 22:52:55 -0400 Subject: [PATCH] Move asm into core and rename to asm/disasm (no prefix) --- CMakeLists.txt | 11 +------ Makefile | 4 +-- examples/error.dst | 2 +- src/compiler/boot.dst | 2 +- src/compiler/stl.c | 1 - src/{assembler => core}/asm.c | 9 +++--- src/include/dst/dst.h | 16 ++++++++++ src/include/dst/dstasm.h | 56 ----------------------------------- src/include/dst/dstcorelib.h | 2 +- 9 files changed, 25 insertions(+), 78 deletions(-) rename src/{assembler => core}/asm.c (99%) delete mode 100644 src/include/dst/dstasm.h diff --git a/CMakeLists.txt b/CMakeLists.txt index fc5d4ce1..54bbf45e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,10 +34,6 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") include_directories(src/include) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -set(ASSEMBLER_SOURCES -src/assembler/asm.c -) - set(COMPILER_SOURCES src/compiler/compile.c src/compiler/cfuns.c @@ -52,6 +48,7 @@ src/compiler/compile.h set(CORE_SOURCES src/core/abstract.c src/core/array.c +src/core/asm.c src/core/buffer.c src/core/bytecode.c src/core/corelib.c @@ -88,12 +85,7 @@ src/mainclient/line.c src/mainclient/line.h ) -set(TESTLIB_SOURCES -src/testlib/testlib.c -) - set(REPL_SOURCES -${ASSEMBLER_SOURCES} ${COMPILER_SOURCES} ${CORE_SOURCES} ${MAINCLIENT_SOURCES} @@ -102,7 +94,6 @@ ${MAINCLIENT_SOURCES} # Set Public headers set(DST_PUBLIC_HEADERS src/include/dst/dst.h -src/include/dst/dstasm.h src/include/dst/dstcompile.h src/include/dst/dstconfig.h src/include/dst/dstcorelib.h diff --git a/Makefile b/Makefile index 16cb977b..47909b8a 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,6 @@ DST_ALL_HEADERS=$(DST_HEADERS) \ $(DST_GENERATED_HEADERS) # Source files -DST_ASM_SOURCES=$(sort $(wildcard src/assembler/*.c)) DST_COMPILER_SOURCES=$(sort $(wildcard src/compiler/*.c)) DST_CORE_SOURCES=$(sort $(wildcard src/core/*.c)) DST_MAINCLIENT_SOURCES=$(sort $(wildcard src/mainclient/*.c)) @@ -86,8 +85,7 @@ src/compiler/dststlbootstrap.gen.h: src/compiler/boot.dst xxd ##### The main interpreter program and shared object ##### ########################################################## -DST_LIB_SOURCES=$(DST_ASM_SOURCES) \ - $(DST_COMPILER_SOURCES) \ +DST_LIB_SOURCES=$(DST_COMPILER_SOURCES) \ $(DST_CONTEXT_SOURCES) \ $(DST_CORE_SOURCES) diff --git a/examples/error.dst b/examples/error.dst index 23ffee88..cb688734 100644 --- a/examples/error.dst +++ b/examples/error.dst @@ -16,4 +16,4 @@ (bork 3) 1) -(pupper) +(do (pupper) 1) diff --git a/src/compiler/boot.dst b/src/compiler/boot.dst index 9e20267d..787a8ad2 100644 --- a/src/compiler/boot.dst +++ b/src/compiler/boot.dst @@ -247,7 +247,7 @@ value." (error ("unexpected loop predicate: " verb))) (switch verb - :in-while (do + :iterate (do (def preds @['and (tuple ':= bindings object)]) (def subloop (doone (+ i 3) preds)) (tuple 'do diff --git a/src/compiler/stl.c b/src/compiler/stl.c index 8e3bc1f7..afdd4535 100644 --- a/src/compiler/stl.c +++ b/src/compiler/stl.c @@ -23,7 +23,6 @@ #include #include #include -#include #include /* Generated header */ diff --git a/src/assembler/asm.c b/src/core/asm.c similarity index 99% rename from src/assembler/asm.c rename to src/core/asm.c index 485e0e3e..1f7e3b75 100644 --- a/src/assembler/asm.c +++ b/src/core/asm.c @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -904,7 +903,7 @@ Dst dst_disasm(DstFuncDef *def) { } /* C Function for assembly */ -int dst_asm_cfun(DstArgs args) { +static int cfun_asm(DstArgs args) { DstAssembleResult res; DST_FIXARITY(args, 1); res = dst_asm(args.v[0], 0); @@ -915,7 +914,7 @@ int dst_asm_cfun(DstArgs args) { } } -int dst_disasm_cfun(DstArgs args) { +int cfun_disasm(DstArgs args) { DstFunction *f; DST_FIXARITY(args, 1); DST_ARG_FUNCTION(f, args, 0); @@ -923,8 +922,8 @@ int dst_disasm_cfun(DstArgs args) { } static const DstReg cfuns[] = { - {"asm.asm", dst_asm_cfun}, - {"asm.disasm", dst_disasm_cfun}, + {"asm", cfun_asm}, + {"disasm", cfun_disasm}, {NULL, NULL} }; diff --git a/src/include/dst/dst.h b/src/include/dst/dst.h index dba86be0..c579d5da 100644 --- a/src/include/dst/dst.h +++ b/src/include/dst/dst.h @@ -46,6 +46,22 @@ const char *dst_parser_error(DstParser *parser); void dst_parser_flush(DstParser *parser); DstParser *dst_check_parser(Dst x); +/* Assembly */ +typedef struct DstAssembleResult DstAssembleResult; +typedef struct DstAssembleOptions DstAssembleOptions; +enum DstAssembleStatus { + DST_ASSEMBLE_OK, + DST_ASSEMBLE_ERROR +}; +struct DstAssembleResult { + DstFuncDef *funcdef; + 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); + /* 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); diff --git a/src/include/dst/dstasm.h b/src/include/dst/dstasm.h deleted file mode 100644 index 34da1325..00000000 --- a/src/include/dst/dstasm.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* Copyright (c) 2018 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. -*/ - -#ifndef DST_ASM_H_defined -#define DST_ASM_H_defined - -#ifdef __cplusplus -extern "C" { -#endif - -#include "dsttypes.h" - -/* Assembly */ -typedef struct DstAssembleResult DstAssembleResult; -typedef struct DstAssembleOptions DstAssembleOptions; -enum DstAssembleStatus { - DST_ASSEMBLE_OK, - DST_ASSEMBLE_ERROR -}; -struct DstAssembleResult { - DstFuncDef *funcdef; - 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); -int dst_asm_cfun(DstArgs args); -int dst_disasm_cfun(DstArgs args); - -int dst_lib_asm(DstArgs args); - -#ifdef __cplusplus -} -#endif - -#endif /* DST_ASM_H_defined */ diff --git a/src/include/dst/dstcorelib.h b/src/include/dst/dstcorelib.h index e2ba4ef5..19989872 100644 --- a/src/include/dst/dstcorelib.h +++ b/src/include/dst/dstcorelib.h @@ -101,7 +101,7 @@ 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); /* Useful for compiler */ Dst dst_op_add(Dst lhs, Dst rhs);