Compare commits

...

10 Commits

14 changed files with 124 additions and 41 deletions
+5
View File
@@ -11,6 +11,10 @@ if (NOT DEFINED bshell_verbose)
set(bshell_verbose 0)
endif ()
if (NOT DEFINED bshell_enable_floating_point)
set(bshell_enable_floating_point 1)
endif ()
set(required_fx_assemblies fx.runtime fx.collections)
if (bshell_interactive)
@@ -23,6 +27,7 @@ find_package(FX REQUIRED COMPONENTS ${required_fx_assemblies})
execute_process(
COMMAND ${Python_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/build-id.py
--source-dir "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE bshell_version)
message(STATUS "B Shell version: ${bshell_version}")
+1
View File
@@ -16,4 +16,5 @@ add_library(bshell.core SHARED ${sources})
target_link_libraries(bshell.core bshell.runtime FX::Runtime FX::Collections)
target_include_directories(bshell.core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_definitions(bshell.core PUBLIC
BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point}
BSHELL_VERSION="${bshell_version}")
+1
View File
@@ -24,5 +24,6 @@ endif ()
target_include_directories(bshell.runtime PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_definitions(bshell.runtime PUBLIC
BSHELL_VERSION="${bshell_version}"
BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point}
BSHELL_INTERACTIVE=${bshell_interactive}
BSHELL_VERBOSE=${bshell_verbose})
+4 -1
View File
@@ -1,8 +1,11 @@
#include <bshell/format.h>
#include <fx/term/print.h>
#include <fx/type.h>
#include <fx/value-type.h>
#if BSHELL_INTERACTIVE == 1
#include <fx/term/print.h>
#endif
static void format_value_fallback(const fx_value *value, fx_stream *dest)
{
#if BSHELL_INTERACTIVE == 1
+4 -1
View File
@@ -3,9 +3,12 @@
#include <fx/iterator.h>
#include <fx/reflection/type.h>
#include <fx/stringstream.h>
#include <fx/value.h>
#if BSHELL_INTERACTIVE == 1
#include <fx/term/print.h>
#include <fx/term/tty.h>
#include <fx/value.h>
#endif
static fx_namemap bshell_tables = FX_NAMEMAP_INIT;
+1
View File
@@ -20,5 +20,6 @@ enum bshell_status {
};
extern enum bshell_status bshell_status_from_errno(int err);
extern const char *bshell_status_get_description(int err);
#endif
+10 -8
View File
@@ -653,6 +653,7 @@ bool string_is_valid_number(
}
char *ep = NULL;
#if BSHELL_ENABLE_FLOATING_POINT == 1
double dvalue = strtod(s, &ep);
if (string_could_be_double(s) && *ep == '\0') {
if (out) {
@@ -665,6 +666,7 @@ bool string_is_valid_number(
return true;
}
#endif
int base = get_int_base_by_prefix(&s);
@@ -1178,13 +1180,13 @@ int compare_token_types(unsigned int a, unsigned int b)
if (BETWEEN(a, __BSHELL_KW_INDEX_BASE, __BSHELL_KW_INDEX_LIMIT)) {
a_type = BSHELL_TOK_KEYWORD;
} else if (BETWEEN(a,
} else if (
BETWEEN(a,
__BSHELL_TKOP_INDEX_BASE,
__BSHELL_TKOP_INDEX_LIMIT)) {
a_type = BSHELL_TOK_OPERATOR;
} else if (BETWEEN(a,
__BSHELL_SYM_INDEX_BASE,
__BSHELL_SYM_INDEX_LIMIT)) {
} else if (
BETWEEN(a, __BSHELL_SYM_INDEX_BASE, __BSHELL_SYM_INDEX_LIMIT)) {
a_type = BSHELL_TOK_SYMBOL;
} else {
a_type = a;
@@ -1192,13 +1194,13 @@ int compare_token_types(unsigned int a, unsigned int b)
if (BETWEEN(b, __BSHELL_KW_INDEX_BASE, __BSHELL_KW_INDEX_LIMIT)) {
b_type = BSHELL_TOK_KEYWORD;
} else if (BETWEEN(b,
} else if (
BETWEEN(b,
__BSHELL_TKOP_INDEX_BASE,
__BSHELL_TKOP_INDEX_LIMIT)) {
b_type = BSHELL_TOK_OPERATOR;
} else if (BETWEEN(b,
__BSHELL_SYM_INDEX_BASE,
__BSHELL_SYM_INDEX_LIMIT)) {
} else if (
BETWEEN(b, __BSHELL_SYM_INDEX_BASE, __BSHELL_SYM_INDEX_LIMIT)) {
b_type = BSHELL_TOK_SYMBOL;
} else {
b_type = b;
+4 -1
View File
@@ -9,9 +9,12 @@
#include <fx/reflection/function.h>
#include <fx/reflection/type.h>
#include <fx/string.h>
#include <fx/term/print.h>
#include <fx/vector.h>
#if BSHELL_INTERACTIVE == 1
#include <fx/term/print.h>
#endif
enum cmdcall_type {
CMDCALL_NONE = 0,
CMDCALL_CMDLET,
+38
View File
@@ -17,3 +17,41 @@ enum bshell_status bshell_status_from_errno(int err)
return BSHELL_ERR_INTERNAL_FAILURE;
}
}
const char *bshell_status_get_description(int err)
{
switch (err) {
case BSHELL_SUCCESS:
return "Success";
case BSHELL_ERR_EOF:
return "Unexpected end-of-file";
case BSHELL_ERR_BAD_SYNTAX:
return "Bad syntax";
case BSHELL_ERR_BAD_FORMAT:
return "Bad data format";
case BSHELL_ERR_BAD_STATE:
return "Object is in bad state";
case BSHELL_ERR_INVALID_VALUE:
return "Invalid value";
case BSHELL_ERR_INVALID_ARGUMENT:
return "Invalid argument";
case BSHELL_ERR_NO_MEMORY:
return "Out of memory";
case BSHELL_ERR_NO_ENTRY:
return "No such file or directory";
case BSHELL_ERR_NO_DATA:
return "No data available";
case BSHELL_ERR_NAME_EXISTS:
return "File or object already exists";
case BSHELL_ERR_NOT_SUPPORTED:
return "Operation not supported";
case BSHELL_ERR_IO_FAILURE:
return "I/O failure";
case BSHELL_ERR_ACCESS_DENIED:
return "Access denied";
case BSHELL_ERR_INTERNAL_FAILURE:
return "Internal failure";
default:
return "Unknown error";
}
}
+2
View File
@@ -29,7 +29,9 @@ target_link_libraries(bshell
if (bshell_interactive)
target_link_libraries(bshell FX::Term)
endif ()
target_compile_definitions(bshell PUBLIC
BSHELL_VERSION="${bshell_version}"
BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point}
BSHELL_INTERACTIVE=${bshell_interactive}
BSHELL_VERBOSE=${bshell_verbose})
+4 -1
View File
@@ -5,9 +5,12 @@
#include <bshell/runtime/opcode.h>
#include <bshell/runtime/script-block.h>
#include <fx/string.h>
#include <fx/term/print.h>
#include <stdio.h>
#if BSHELL_INTERACTIVE == 1
#include <fx/term/print.h>
#endif
#if BSHELL_INTERACTIVE == 1
#define RED "[red]"
#define YELLOW "[yellow]"
+13 -1
View File
@@ -1,5 +1,4 @@
#include "debug.h"
#include "line-ed/line-ed.h"
#include <bshell/ast.h>
#include <bshell/compile.h>
@@ -12,6 +11,10 @@
#include <bshell/verb.h>
#include <stdio.h>
#if BSHELL_INTERACTIVE == 1
#include "line-ed/line-ed.h"
#endif
extern const fx_assembly *bshell_assembly_get(void);
extern const fx_assembly *bshell_runtime_assembly_get(void);
extern const fx_assembly *bshell_core_assembly_get(void);
@@ -74,6 +77,15 @@ int main(int argc, const char **argv)
status = bshell_file_open(argv[1], &file);
linesrc = &file->f_base;
interactive = false;
if (!FX_OK(status)) {
fprintf(stderr,
"%s: cannot open '%s': %s\n",
argv[0],
argv[1],
bshell_status_get_description(status));
return -1;
}
} else {
#if BSHELL_INTERACTIVE == 1
ed = line_ed_create();
+18 -10
View File
@@ -51,15 +51,7 @@ endif ()
set(assemblies ${FX_FIND_COMPONENTS})
set(required_vars)
if (NOT FX_INCLUDE_DIR)
find_path(FX_INCLUDE_DIR
NAMES fx/misc.h ${FX_FIND_ARGS}
PATH_SUFFIXES include
PATHS ${FX_SEARCH_PATHS})
endif ()
set(required_vars FX_INCLUDE_DIR)
set(in_tree FALSE)
foreach (assembly ${assemblies})
string(TOLOWER ${assembly} header_name)
@@ -69,10 +61,15 @@ foreach (assembly ${assemblies})
set(lib_name ${assembly}${_lib_suffix})
if (NOT ${macro_name}_LIBRARY)
if (TARGET ${assembly})
set (${macro_name}_LIBRARY ${assembly})
set(in_tree TRUE)
else ()
find_library(${macro_name}_LIBRARY
NAMES ${lib_name} ${FX_FIND_ARGS}
PATH_SUFFIXES lib
PATHS ${FX_SEARCH_PATHS})
endif ()
else ()
# on Windows, ensure paths are in canonical format (forward slahes):
file(TO_CMAKE_PATH "${${macro_name}_LIBRARY}" ${macro_name}_LIBRARY)
@@ -81,6 +78,14 @@ foreach (assembly ${assemblies})
list(APPEND required_vars ${macro_name}_LIBRARY)
endforeach (assembly)
if (NOT FX_INCLUDE_DIR AND NOT in_tree)
list(APPEND required_vars FX_INCLUDE_DIR)
find_path(FX_INCLUDE_DIR
NAMES fx/misc.h ${FX_FIND_ARGS}
PATH_SUFFIXES include
PATHS ${FX_SEARCH_PATHS})
endif ()
unset(FX_FIND_ARGS)
include(FindPackageHandleStandardArgs)
@@ -106,6 +111,9 @@ if (FX_FOUND)
set(lib_name ${assembly}${_lib_suffix})
if (NOT TARGET FX::${target_name})
if (TARGET ${assembly})
add_library(FX::${target_name} ALIAS ${assembly})
else ()
add_library(FX::${target_name} UNKNOWN IMPORTED)
set_target_properties(FX::${target_name} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${FX_INCLUDE_DIR}")
@@ -114,10 +122,10 @@ if (FX_FOUND)
if (FX_STATIC)
target_compile_definitions(FX::${target_name} INTERFACE FX_STATIC=1)
endif ()
set_target_properties(FX::${target_name} PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${${macro_name}_LIBRARY}")
endif ()
set(created_targets ${created_targets} ${assembly})
endif ()
endforeach (assembly)
+2 -1
View File
@@ -26,7 +26,8 @@ def get_arg(name):
return ''
current_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).decode('utf-8').strip()
source_dir = get_arg('source-dir')
current_tag = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0'], cwd=source_dir).decode('utf-8').strip()
build_id = '{}'.format(current_tag)