diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index f79b72020..e0b89de0d --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,35 +21,32 @@ # Require CMake 2.8. I know for sure that this will not work with CMake 2.6 # due to the use of the FILE command we use when creating the bundle # hierarchy. -#cmake_minimum_required(VERSION 2.8.12) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) +# This is the default from cmake 3.0 # Mac OS X: Setting policy CMP0042 to the new behavior generates dylibs with # RPATH-relative install name that is better suited for Mac OS X applications # embedding Io in their bundle. -if(POLICY CMP0042) - cmake_policy(SET CMP0042 NEW) -endif() # Project name, this gets prefixed to a bunch of stuff under the hood. No # spaces, or anything silly like that please. project(IoLanguage C) # Default config when building with gcc variants -IF(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang")) - SET(CMAKE_BUILD_TYPE_DebugFast) - SET(CMAKE_CXX_FLAGS_DEBUGFAST "-g -O0") - SET(CMAKE_C_FLAGS_DEBUGFAST "-g -O0") - +IF((CMAKE_C_COMPILER_ID STREQUAL "GNU") OR (CMAKE_C_COMPILER_ID MATCHES "Clang")) + SET(CMAKE_C_FLAGS_DEBUGFAST "-g -O") + if (NOT DEFINED HAS_SSE2) + cmake_host_system_information(RESULT HAS_SSE2 QUERY HAS_SSE2) + endif() # Only use -msse2 flag for x86/x86_64 architectures. - if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64") + if(HAS_SSE2) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2") endif() if(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "DebugFast") endif(NOT CMAKE_BUILD_TYPE) -ENDIF(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang")) +ENDIF() MESSAGE(STATUS "Configuration set to: ${CMAKE_BUILD_TYPE}") @@ -57,95 +54,28 @@ MESSAGE(STATUS "Configuration set to: ${CMAKE_BUILD_TYPE}") # so dark it's illegible. set(CMAKE_COLOR_MAKEFILE off) -# We want our binaries to go here -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/_build/binaries) - -# Macro to create the _build directory hierarchy. -# Note: I'm not sure we need lib/ or objs/ in there. But I'll leave them in -# anyway, I'm just not going to do anything with them unless it breaks doing -# nothing breaks something. -macro(make_build_bundle NAME) - file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${NAME}/binaries ${CMAKE_CURRENT_BINARY_DIR}/${NAME}/objs ${CMAKE_CURRENT_BINARY_DIR}/${NAME}/headers ${CMAKE_CURRENT_BINARY_DIR}/${NAME}/lib ${CMAKE_CURRENT_BINARY_DIR}/${NAME}/dll) -endmacro(make_build_bundle) - -# Generic macro to copy files mattching GLOBPAT in the current source -# directory into another directory. -macro(copy_files NAME GLOBPAT DSTDIR) - # Get a list of the filenames mattching the pattern GLOBPAT - file(GLOB ${NAME} ${GLOBPAT}) - - # Create a custom copy target and display a message - add_custom_target(copy_${NAME} ALL COMMENT "Copying files: ${CMAKE_CURRENT_SOURCE_DIR}/${GLOBPAT} to ${DSTDIR}") - - foreach(FILENAME ${${NAME}}) - # Finally, copy the files. - add_custom_command( - TARGET copy_${NAME} - COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${DSTDIR} - ) - endforeach(FILENAME) -endmacro(copy_files) - -# Binary suffix is used to append things like .exe to binary names, for -# windows support. +# Set library prefix to "lib" on Windows +# to match unix. if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") - set(BINARY_SUFFIX ".exe") set(CMAKE_STATIC_LIBRARY_PREFIX "lib") set(CMAKE_SHARED_LIBRARY_PREFIX "lib") set(CMAKE_IMPORT_LIBRARY_PREFIX "lib") -else() - set(BINARY_SUFFIX "") endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") # Definitions on where we can find headers and whatnot. Convenience definitions. set(BASEKIT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/libs/basekit/source) set(GARBAGECOLLECTOR_SOURCE_DIR ${PROJECT_SOURCE_DIR}/libs/garbagecollector/source) set(IOVM_SOURCE_DIR ${PROJECT_SOURCE_DIR}/libs/iovm/source) +set(PARSON_SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/parson) # Subdirectories. These directories should have their own CMakeLists.txt. add_subdirectory(libs) add_subdirectory(tools) -# Ensure the _build hierarchy is created top-level, this is where our -# binaries go. -make_build_bundle(_build) - -# Next we NEED to copy all the libs headers into one single dir in the bundle. -copy_files(basekit_headers ${PROJECT_SOURCE_DIR}/libs/basekit/source/*.h ${CMAKE_CURRENT_BINARY_DIR}/_build/headers) -copy_files(garbagecollector_headers ${PROJECT_SOURCE_DIR}/libs/garbagecollector/source/*.h ${CMAKE_CURRENT_BINARY_DIR}/_build/headers) -copy_files(iovm_headers ${PROJECT_SOURCE_DIR}/libs/iovm/source/*.h ${CMAKE_CURRENT_BINARY_DIR}/_build/headers) - -# Packaging stuff - -#Modified from: http://www.mail-archive.com/cmake@cmake.org/msg32916.html -MACRO (TODAY RESULT) - IF (WIN32) - EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT}) - string(REGEX REPLACE "(..)/(..)/(....).*" "\\1.\\2.\\3" ${RESULT} -${${RESULT}}) - ELSEIF(UNIX) - EXECUTE_PROCESS(COMMAND "date" "+%d/%m/%Y" OUTPUT_VARIABLE ${RESULT}) - string(REGEX REPLACE "(..)/(..)/(....).*" "\\1.\\2.\\3" ${RESULT} -${${RESULT}}) - ELSE (WIN32) - MESSAGE(SEND_ERROR "date not implemented") - SET(${RESULT} 00.00.0000) - ENDIF (WIN32) -ENDMACRO (TODAY) - -TODAY(CMD_DATE) -STRING(SUBSTRING ${CMD_DATE} 0 2 CMD_DATE_DAY) -STRING(SUBSTRING ${CMD_DATE} 3 2 CMD_DATE_MON) -STRING(SUBSTRING ${CMD_DATE} 6 4 CMD_DATE_YEAR) -SET(CMD_DATE "${CMD_DATE_YEAR}.${CMD_DATE_MON}.${CMD_DATE_DAY}") - -# If source tree is not a git repository this will not work -#IF(WIN32 AND NOT CYGWIN) -# execute_process(COMMAND "cmd" " /C git rev-parse --short HEAD" OUTPUT_VARIABLE IO_GIT_REV) -#ELSE(WIN32 AND NOT CYGWIN) -# execute_process(COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE IO_GIT_REV) -#ENDIF(WIN32 AND NOT CYGWIN) -#string(REGEX REPLACE "(.......)." "\\1" IO_GIT_REV ${IO_GIT_REV}) +string(TIMESTAMP CMD_DATE_YEAR "%Y") +string(TIMESTAMP CMD_DATE_MON "%m") +string(TIMESTAMP CMD_DATE_DAY "%d") +string(TIMESTAMP CMD_DATE "%Y.%m.%d") SET(CPACK_PACKAGE_NAME ${PROJECT_NAME}) SET(CPACK_PACKAGE_VENDOR "iolanguage.com") diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index fab09ca06..ef62448cf 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -1,89 +1,20 @@ # Base Io build system # Written by Jeremy Tregunna # -# This file is a stub, here only as required. +# +# CMake file for libs subdirectory. +# # Add a definition -- explicitly required on Windows, but shouldn't # hurt other platforms. If it does, let me know. add_definitions("-DBUILDING_IOVMALL_DLL") -# Output our static library to the top-level _build hierarchy -set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/_build/lib) - -# Our Io source files to be "compiled" into a C source file. -#file(GLOB IO_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/iovm/io/*.io") -set(IO_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/io/List_bootstrap.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/OperatorTable.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Object.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/List.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Exception.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Actor.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/AddonLoader.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Sequence.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Block.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/CFunction.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Date.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Debugger.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Directory.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/DynLib.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Error.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/File.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/List_schwartzian.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Map.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Message.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Number.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Profiler.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Sandbox.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Serialize.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/System.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/UnitTest.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Vector.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Path.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/CLI.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Importer.io -) - -# Object files from every lib. Used to create iovmall static library. -file(GLOB BASEKIT_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/basekit/source/*.c") -file(GLOB GARBAGECOLLECTOR_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/garbagecollector/source/*.c") -file(GLOB IOVM_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/iovm/source/*.c") -list(REMOVE_ITEM IOVM_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/iovm/source/IoState_iterative_fast.c") -list(APPEND IOVM_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../deps/parson/parson.c) - -# Marvelous flags, likely compiler dependent. -#add_definitions(-DBUILDING_IOVM_DLL)# -DINSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}") - -set(IOVMALL_STATIC_SRCS - ${BASEKIT_SRCS} - ${GARBAGECOLLECTOR_SRCS} - ${IOVM_SRCS} -) - -# The custom command to generate source/IoVMInit.c which is our -# "compiled" Io to C source code. -add_custom_command( - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/iovm/source/IoVMInit.c - COMMAND ${PROJECT_BINARY_DIR}/_build/binaries/io2c VMCode IoState_doString_ ${IO_SRCS} > ${CMAKE_CURRENT_SOURCE_DIR}/iovm/source/IoVMInit.c - DEPENDS io2c -) - -# Include dirs, -I flags and whatnot -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/iovm/source - ${CMAKE_CURRENT_SOURCE_DIR}/../deps/parson - ${CMAKE_CURRENT_SOURCE_DIR}/basekit/source - ${CMAKE_CURRENT_SOURCE_DIR}/basekit/source/simd_cph/include - ${CMAKE_CURRENT_SOURCE_DIR}/garbagecollector/source -) - -# Add a file to our library sources. -list(APPEND IOVMALL_STATIC_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/iovm/source/IoVMInit.c) # Because we generate it - -# ...And the static library. Refer to IOVMALL_STATIC_SRCS definition -# up top. -add_library(iovmall_static STATIC ${IOVMALL_STATIC_SRCS}) -add_dependencies(iovmall_static io2c basekit garbagecollector iovmall) +# Hackery for CMake's horrible ASM support +if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") + # Always include asm.S for all architectures + set(ASM_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/coroutine/source/asm.S) + set_source_files_properties(${ASM_SOURCES} PROPERTIES LANGUAGE C) +endif() # Define the subdirectories we can reach from here that we want # to go into and build stuff. diff --git a/libs/basekit/CMakeLists.txt b/libs/basekit/CMakeLists.txt index cb57b5464..cbeb1de4d 100644 --- a/libs/basekit/CMakeLists.txt +++ b/libs/basekit/CMakeLists.txt @@ -3,21 +3,19 @@ # # Build the garbage collector library. -# Output our dynamic library to the top-level _build hierarchy -set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/_build/dll) - # Marvelous flags, likely compiler dependent. add_definitions("-DBUILDING_BASEKIT_DLL") # Include dirs, -I flags and whatnot include_directories(${CMAKE_CURRENT_SOURCE_DIR}/source/simd_cph/include) -set(BASEKIT_LIBS) +set(BASEKIT_LIBS ${CMAKE_DL_LIBS}) -# Add dynamic loader library for those who need it -if(${CMAKE_SYSTEM_NAME} MATCHES "(Darwin|Linux|SunOS|syllable)") - list(APPEND BASEKIT_LIBS dl m) -endif(${CMAKE_SYSTEM_NAME} MATCHES "(Darwin|Linux|SunOS|syllable)") +# Add math library for those who need it +find_library(MATH_LIBRARY m) +if (MATH_LIBRARY) + list(APPEND BASEKIT_LIBS ${MATH_LIBRARY}) +endif() # Our library sources. file(GLOB SRCS "source/*.c") @@ -28,19 +26,15 @@ add_library(basekit SHARED ${SRCS}) set_target_properties(basekit PROPERTIES PUBLIC_HEADER "${HEADERS}") target_link_libraries(basekit ${BASEKIT_LIBS}) -# ...And the static library -#add_library(basekit_static STATIC ${SRCS}) +# Now build the static library +add_library(basekit_static STATIC ${SRCS}) +set_target_properties(basekit_static PROPERTIES PUBLIC_HEADER "${HEADERS}") +target_link_libraries(basekit_static ${BASEKIT_LIBS}) # The following add the install target, so we put libbasekit.* in our # install prefix. -if(WIN32) - install(TARGETS basekit - RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} - PUBLIC_HEADER DESTINATION include/io - ) -else() - install(TARGETS basekit - LIBRARY DESTINATION lib - PUBLIC_HEADER DESTINATION include/io - ) -endif(WIN32) + install ( + TARGETS basekit + FILE_SET HEADERS +) + diff --git a/libs/basekit/source/CHash.h b/libs/basekit/source/CHash.h index 2c6d7b0e9..b91000177 100644 --- a/libs/basekit/source/CHash.h +++ b/libs/basekit/source/CHash.h @@ -7,6 +7,7 @@ #include "Common.h" #include #include "PortableStdint.h" +#include #ifdef __cplusplus extern "C" { @@ -14,7 +15,7 @@ extern "C" { #define CHASH_MAXLOOP 5 -typedef int(CHashEqualFunc)(void *, void *); +typedef bool(CHashEqualFunc)(void *, void *); typedef intptr_t(CHashHashFunc)(void *); typedef struct { diff --git a/libs/basekit/source/Common.h b/libs/basekit/source/Common.h index f07e08547..a8f98ce73 100644 --- a/libs/basekit/source/Common.h +++ b/libs/basekit/source/Common.h @@ -18,7 +18,7 @@ These defines are helpful for doing OS specific checks in the code. #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__DragonFly__) #include -#elif !defined(__SYMBIAN32__) && !defined(_MSC_VER) && !defined(__NeXT__) +#elif !defined(__SYMBIAN32__) && !defined(__NeXT__) #include #else typedef unsigned char uint8_t; @@ -70,7 +70,10 @@ typedef long long int64_t; #if defined(WIN32) || defined(__WINS__) || defined(__MINGW32__) || \ defined(_MSC_VER) #define inline __inline -#define snprintf _snprintf +// Do not do this on UCRT (Windows 10 and later) +//#define snprintf _snprintf +// Needed as Windows stdint.h does not have ssize_t +typedef ptrdiff_t ssize_t; #ifndef __MINGW32__ #define usleep(x) Sleep(((x) + 999) / 1000) #endif diff --git a/libs/basekit/source/PortableStdint.h b/libs/basekit/source/PortableStdint.h index 9c1ca772c..b1ca90c16 100644 --- a/libs/basekit/source/PortableStdint.h +++ b/libs/basekit/source/PortableStdint.h @@ -3,7 +3,7 @@ * BSD License: **************************************************************************** * - * Copyright (c) 2005-2007 Paul Hsieh + * Copyright (c) 2005-2016 Paul Hsieh * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,30 +31,28 @@ * **************************************************************************** * - * Version 0.1.11 + * Version 0.1.16.0 * * The ANSI C standard committee, for the C99 standard, specified the * inclusion of a new standard include file called stdint.h. This is * a very useful and long desired include file which contains several - * very precise definitions for integer scalar types that is - * critically important for making portable several classes of - * applications including cryptography, hashing, variable length - * integer libraries and so on. But for most developers its likely - * useful just for programming sanity. - * - * The problem is that most compiler vendors have decided not to - * implement the C99 standard, and the next C++ language standard - * (which has a lot more mindshare these days) will be a long time in - * coming and its unknown whether or not it will include stdint.h or - * how much adoption it will have. Either way, it will be a long time - * before all compilers come with a stdint.h and it also does nothing - * for the extremely large number of compilers available today which - * do not include this file, or anything comparable to it. - * - * So that's what this file is all about. Its an attempt to build a + * very precise definitions for integer scalar types that is critically + * important for making several classes of applications portable + * including cryptography, hashing, variable length integer libraries + * and so on. But for most developers its likely useful just for + * programming sanity. + * + * The problem is that some compiler vendors chose to ignore the C99 + * standard and some older compilers have no opportunity to be updated. + * Because of this situation, simply including stdint.h in your code + * makes it unportable. + * + * So that's what this file is all about. It's an attempt to build a * single universal include file that works on as many platforms as - * possible to deliver what stdint.h is supposed to. A few things - * that should be noted about this file: + * possible to deliver what stdint.h is supposed to. Even compilers + * that already come with stdint.h can use this file instead without + * any loss of functionality. A few things that should be noted about + * this file: * * 1) It is not guaranteed to be portable and/or present an identical * interface on all platforms. The extreme variability of the @@ -73,7 +71,7 @@ * include stdint.h. The hope is that one or the other can be * used with no real difference. * - * 5) In the current verison, if your platform can't represent + * 5) In the current version, if your platform can't represent * int32_t, int16_t and int8_t, it just dumps out with a compiler * error. * @@ -154,7 +152,12 @@ * PRINTF_INT64_DEC_WIDTH * PRINTF_INT32_DEC_WIDTH * PRINTF_INT16_DEC_WIDTH - * PRINTF_INT8_DEC_WIDTH + * PRINTF_UINT8_DEC_WIDTH + * PRINTF_UINTMAX_DEC_WIDTH + * PRINTF_UINT64_DEC_WIDTH + * PRINTF_UINT32_DEC_WIDTH + * PRINTF_UINT16_DEC_WIDTH + * PRINTF_UINT8_DEC_WIDTH * * Which specifies the maximum number of characters required to * print the number of that type in either hexadecimal or decimal. @@ -178,12 +181,13 @@ * Chris Howie * John Steele Scott * Dave Thorup + * John Dill + * Florian Wobbe + * Christopher Sean Morrison + * Mikkel Fahnoe Jorgensen * */ -/* Use sys/stdint.h on Modern BSDs */ -#ifndef _SYS_STDINT_H_ - #include #include #include @@ -193,20 +197,38 @@ * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_. */ -#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || \ +#if ((defined(__SUNPRO_C) && __SUNPRO_C >= 0x570) || \ + (defined(_MSC_VER) && _MSC_VER >= 1600) || \ + (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 199901L) || \ (defined(__WATCOMC__) && \ (defined(_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || \ - (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)))) && \ - !defined(_PSTDINT_H_INCLUDED) || \ - defined(__FreeBSD__) || defined(__OpenBSD__) + (defined(__GNUC__) && \ + (__GNUC__ > 3 || defined(_STDINT_H) || defined(_STDINT_H_) || \ + defined(__UINT_FAST64_TYPE__)))) && \ + !defined(_PSTDINT_H_INCLUDED) #include #define _PSTDINT_H_INCLUDED +#if defined(__GNUC__) && (defined(__x86_64__) || defined(__ppc64__)) && \ + !(defined(__APPLE__) && defined(__MACH__)) +#ifndef PRINTF_INT64_MODIFIER +#define PRINTF_INT64_MODIFIER "l" +#endif +#ifndef PRINTF_INT32_MODIFIER +#define PRINTF_INT32_MODIFIER "" +#endif +#else #ifndef PRINTF_INT64_MODIFIER #define PRINTF_INT64_MODIFIER "ll" #endif #ifndef PRINTF_INT32_MODIFIER +#if (UINT_MAX == UINT32_MAX) +#define PRINTF_INT32_MODIFIER "" +#else #define PRINTF_INT32_MODIFIER "l" #endif +#endif +#endif #ifndef PRINTF_INT16_MODIFIER #define PRINTF_INT16_MODIFIER "h" #endif @@ -216,32 +238,62 @@ #ifndef PRINTF_INT64_HEX_WIDTH #define PRINTF_INT64_HEX_WIDTH "16" #endif +#ifndef PRINTF_UINT64_HEX_WIDTH +#define PRINTF_UINT64_HEX_WIDTH "16" +#endif #ifndef PRINTF_INT32_HEX_WIDTH #define PRINTF_INT32_HEX_WIDTH "8" #endif +#ifndef PRINTF_UINT32_HEX_WIDTH +#define PRINTF_UINT32_HEX_WIDTH "8" +#endif #ifndef PRINTF_INT16_HEX_WIDTH #define PRINTF_INT16_HEX_WIDTH "4" #endif +#ifndef PRINTF_UINT16_HEX_WIDTH +#define PRINTF_UINT16_HEX_WIDTH "4" +#endif #ifndef PRINTF_INT8_HEX_WIDTH #define PRINTF_INT8_HEX_WIDTH "2" #endif +#ifndef PRINTF_UINT8_HEX_WIDTH +#define PRINTF_UINT8_HEX_WIDTH "2" +#endif #ifndef PRINTF_INT64_DEC_WIDTH -#define PRINTF_INT64_DEC_WIDTH "20" +#define PRINTF_INT64_DEC_WIDTH "19" +#endif +#ifndef PRINTF_UINT64_DEC_WIDTH +#define PRINTF_UINT64_DEC_WIDTH "20" #endif #ifndef PRINTF_INT32_DEC_WIDTH #define PRINTF_INT32_DEC_WIDTH "10" #endif +#ifndef PRINTF_UINT32_DEC_WIDTH +#define PRINTF_UINT32_DEC_WIDTH "10" +#endif #ifndef PRINTF_INT16_DEC_WIDTH #define PRINTF_INT16_DEC_WIDTH "5" #endif +#ifndef PRINTF_UINT16_DEC_WIDTH +#define PRINTF_UINT16_DEC_WIDTH "5" +#endif #ifndef PRINTF_INT8_DEC_WIDTH #define PRINTF_INT8_DEC_WIDTH "3" #endif +#ifndef PRINTF_UINT8_DEC_WIDTH +#define PRINTF_UINT8_DEC_WIDTH "3" +#endif #ifndef PRINTF_INTMAX_HEX_WIDTH -#define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH +#define PRINTF_INTMAX_HEX_WIDTH PRINTF_UINT64_HEX_WIDTH +#endif +#ifndef PRINTF_UINTMAX_HEX_WIDTH +#define PRINTF_UINTMAX_HEX_WIDTH PRINTF_UINT64_HEX_WIDTH #endif #ifndef PRINTF_INTMAX_DEC_WIDTH -#define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH +#define PRINTF_INTMAX_DEC_WIDTH PRINTF_UINT64_DEC_WIDTH +#endif +#ifndef PRINTF_UINTMAX_DEC_WIDTH +#define PRINTF_UINTMAX_DEC_WIDTH PRINTF_UINT64_DEC_WIDTH #endif /* @@ -295,11 +347,26 @@ #endif #endif +/* + * I have no idea what is the truly correct thing to do on older Solaris. + * From some online discussions, this seems to be what is being + * recommended. For people who actually are developing on older Solaris, + * what I would like to know is, does this define all of the relevant + * macros of a complete stdint.h? Remember, in pstdint.h 64 bit is + * considered optional. + */ + +#if (defined(__SUNPRO_C) && __SUNPRO_C >= 0x420) && \ + !defined(_PSTDINT_H_INCLUDED) +#include +#define _PSTDINT_H_INCLUDED +#endif + #ifndef _PSTDINT_H_INCLUDED #define _PSTDINT_H_INCLUDED #ifndef SIZE_MAX -#define SIZE_MAX (~(size_t)0) +#define SIZE_MAX ((size_t)-1) #endif /* @@ -311,7 +378,7 @@ #ifndef UINT8_MAX #define UINT8_MAX 0xff #endif -#ifndef uint8_t +#if !defined(uint8_t) && !defined(_UINT8_T) && !defined(vxWorks) #if (UCHAR_MAX == UINT8_MAX) || defined(S_SPLINT_S) typedef unsigned char uint8_t; #define UINT8_C(v) ((uint8_t)v) @@ -326,7 +393,7 @@ typedef unsigned char uint8_t; #ifndef INT8_MIN #define INT8_MIN INT8_C(0x80) #endif -#ifndef int8_t +#if !defined(int8_t) && !defined(_INT8_T) && !defined(vxWorks) #if (SCHAR_MAX == INT8_MAX) || defined(S_SPLINT_S) typedef signed char int8_t; #define INT8_C(v) ((int8_t)v) @@ -338,7 +405,7 @@ typedef signed char int8_t; #ifndef UINT16_MAX #define UINT16_MAX 0xffff #endif -#ifndef uint16_t +#if !defined(uint16_t) && !defined(_UINT16_T) && !defined(vxWorks) #if (UINT_MAX == UINT16_MAX) || defined(S_SPLINT_S) typedef unsigned int uint16_t; #ifndef PRINTF_INT16_MODIFIER @@ -362,7 +429,7 @@ typedef unsigned short uint16_t; #ifndef INT16_MIN #define INT16_MIN INT16_C(0x8000) #endif -#ifndef int16_t +#if !defined(int16_t) && !defined(_INT16_T) && !defined(vxWorks) #if (INT_MAX == INT16_MAX) || defined(S_SPLINT_S) typedef signed int int16_t; #define INT16_C(v) ((int16_t)(v)) @@ -383,7 +450,7 @@ typedef signed short int16_t; #ifndef UINT32_MAX #define UINT32_MAX (0xffffffffUL) #endif -#ifndef uint32_t +#if !defined(uint32_t) && !defined(_UINT32_T) && !defined(vxWorks) #if (ULONG_MAX == UINT32_MAX) || defined(S_SPLINT_S) typedef unsigned long uint32_t; #define UINT32_C(v) v##UL @@ -413,7 +480,7 @@ typedef unsigned short uint32_t; #ifndef INT32_MIN #define INT32_MIN INT32_C(0x80000000) #endif -#ifndef int32_t +#if !defined(int32_t) && !defined(_INT32_T) && !defined(vxWorks) #if (LONG_MAX == INT32_MAX) || defined(S_SPLINT_S) typedef signed long int32_t; #define INT32_C(v) v##L @@ -446,7 +513,7 @@ typedef signed short int32_t; #undef stdint_int64_defined #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined(S_SPLINT_S) -#if (__STDC__ && __STDC_VERSION >= 199901L) || defined(S_SPLINT_S) +#if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined(S_SPLINT_S) #define stdint_int64_defined typedef long long int64_t; typedef unsigned long long uint64_t; @@ -459,7 +526,7 @@ typedef unsigned long long uint64_t; #endif #if !defined(stdint_int64_defined) -#if defined(__GNUC__) +#if defined(__GNUC__) && !defined(vxWorks) #define stdint_int64_defined __extension__ typedef long long int64_t; __extension__ typedef unsigned long long uint64_t; @@ -527,9 +594,8 @@ typedef unsigned __int64 uint64_t; #ifndef PRINTF_INT8_HEX_WIDTH #define PRINTF_INT8_HEX_WIDTH "2" #endif - #ifndef PRINTF_INT64_DEC_WIDTH -#define PRINTF_INT64_DEC_WIDTH "20" +#define PRINTF_INT64_DEC_WIDTH "19" #endif #ifndef PRINTF_INT32_DEC_WIDTH #define PRINTF_INT32_DEC_WIDTH "10" @@ -540,6 +606,18 @@ typedef unsigned __int64 uint64_t; #ifndef PRINTF_INT8_DEC_WIDTH #define PRINTF_INT8_DEC_WIDTH "3" #endif +#ifndef PRINTF_UINT64_DEC_WIDTH +#define PRINTF_UINT64_DEC_WIDTH "20" +#endif +#ifndef PRINTF_UINT32_DEC_WIDTH +#define PRINTF_UINT32_DEC_WIDTH "10" +#endif +#ifndef PRINTF_UINT16_DEC_WIDTH +#define PRINTF_UINT16_DEC_WIDTH "5" +#endif +#ifndef PRINTF_UINT8_DEC_WIDTH +#define PRINTF_UINT8_DEC_WIDTH "3" +#endif /* * Ok, lets not worry about 128 bit integers for now. Moore's law says @@ -619,14 +697,12 @@ typedef uint64_t uint_least64_t; #undef stdint_least_defined /* - * The ANSI C committee pretending to know or specify anything about - * performance is the epitome of misguided arrogance. The mandate of - * this file is to *ONLY* ever support that absolute minimum - * definition of the fast integer types, for compatibility purposes. - * No extensions, and no attempt to suggest what may or may not be a - * faster integer type will ever be made in this file. Developers are - * warned to stay away from these types when using this or any other - * stdint.h. + * The ANSI C committee has defined *int*_fast*_t types as well. This, + * of course, defies rationality -- you can't know what will be fast + * just from the type itself. Even for a given architecture, compatible + * implementations might have different performance characteristics. + * Developers are warned to stay away from these types when using this + * or any other stdint.h. */ typedef int_least8_t int_fast8_t; @@ -659,13 +735,14 @@ typedef uint_least64_t uint_fast64_t; * type limits. */ -#if defined(__WATCOMC__) || defined(_MSC_VER) || defined(__GNUC__) +#if defined(__WATCOMC__) || defined(_MSC_VER) || \ + defined(__GNUC__) && !defined(vxWorks) #include #ifndef WCHAR_MIN #define WCHAR_MIN 0 #endif #ifndef WCHAR_MAX -#define WCHAR_MAX ((wchar_t)-1) +#define WCHAR_MAX ((wchar_t) - 1) #endif #endif @@ -674,13 +751,13 @@ typedef uint_least64_t uint_fast64_t; * (u)intptr_t types and limits. */ -#if defined(_MSC_VER) && defined(_UINTPTR_T_DEFINED) +#if (defined(_MSC_VER) && defined(_UINTPTR_T_DEFINED)) || defined(_UINTPTR_T) #define STDINT_H_UINTPTR_T_DEFINED #endif #ifndef STDINT_H_UINTPTR_T_DEFINED #if defined(__alpha__) || defined(__ia64__) || defined(__x86_64__) || \ - defined(_WIN64) + defined(_WIN64) || defined(__ppc64__) #define stdint_intptr_bits 64 #elif defined(__WATCOMC__) || defined(__TURBOC__) #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__) @@ -688,10 +765,13 @@ typedef uint_least64_t uint_fast64_t; #else #define stdint_intptr_bits 32 #endif -#elif defined(__i386__) || defined(_WIN32) || defined(WIN32) +#elif defined(__i386__) || defined(_WIN32) || defined(WIN32) || \ + defined(__ppc64__) #define stdint_intptr_bits 32 #elif defined(__INTEL_COMPILER) -/* TODO -- what will Intel do about x86-64? */ +/* TODO -- what did Intel do about x86-64? */ +#else +/* #error "This platform might not be supported yet" */ #endif #ifdef stdint_intptr_bits @@ -746,8 +826,8 @@ typedef ptrdiff_t intptr_t; #if defined(__TEST_PSTDINT_FOR_CORRECTNESS) /* - * Please compile with the maximum warning settings to make sure macros are not - * defined more than once. + * Please compile with the maximum warning settings to make sure macros are + * not defined more than once. */ #include @@ -758,18 +838,30 @@ typedef ptrdiff_t intptr_t; #define glue3(x, y, z) glue3_aux(x, y, z) #define DECLU(bits) \ - glue3(uint, bits, _t) glue3(u, bits, =) glue3(UINT, bits, _C)(0); + glue3(uint, bits, _t) glue3(u, bits, ) = glue3(UINT, bits, _C)(0); #define DECLI(bits) \ - glue3(int, bits, _t) glue3(i, bits, =) glue3(INT, bits, _C)(0); + glue3(int, bits, _t) glue3(i, bits, ) = glue3(INT, bits, _C)(0); #define DECL(us, bits) glue3(DECL, us, )(bits) #define TESTUMAX(bits) \ - glue3(u, bits, =) glue3(~, u, bits); \ - if (glue3(UINT, bits, _MAX) glue3(!=, u, bits)) \ + glue3(u, bits, ) = ~glue3(u, bits, ); \ + if (glue3(UINT, bits, _MAX) != glue3(u, bits, )) \ printf("Something wrong with UINT%d_MAX\n", bits) +#define REPORTERROR(msg) \ + { \ + err_n++; \ + if (err_first <= 0) \ + err_first = __LINE__; \ + printf msg; \ + } + +#define X_SIZE_MAX ((size_t)-1) + int main() { + int err_n = 0; + int err_first = 0; DECL(I, 8) DECL(U, 8) DECL(I, 16) @@ -784,37 +876,69 @@ int main() { uintmax_t umax = UINTMAX_C(0); char str0[256], str1[256]; + sprintf(str0, "%" PRINTF_INT32_MODIFIER "d", INT32_C(2147483647)); + if (0 != strcmp(str0, "2147483647")) + REPORTERROR( + ("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0)); + if (atoi(PRINTF_INT32_DEC_WIDTH) != (int)strlen(str0)) + REPORTERROR(("Something wrong with PRINTF_INT32_DEC_WIDTH : %s\n", + PRINTF_INT32_DEC_WIDTH)); + sprintf(str0, "%" PRINTF_INT32_MODIFIER "u", UINT32_C(4294967295)); + if (0 != strcmp(str0, "4294967295")) + REPORTERROR( + ("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str0)); + if (atoi(PRINTF_UINT32_DEC_WIDTH) != (int)strlen(str0)) + REPORTERROR(("Something wrong with PRINTF_UINT32_DEC_WIDTH : %s\n", + PRINTF_UINT32_DEC_WIDTH)); +#ifdef INT64_MAX + sprintf(str1, "%" PRINTF_INT64_MODIFIER "d", INT64_C(9223372036854775807)); + if (0 != strcmp(str1, "9223372036854775807")) + REPORTERROR( + ("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1)); + if (atoi(PRINTF_INT64_DEC_WIDTH) != (int)strlen(str1)) + REPORTERROR(("Something wrong with PRINTF_INT64_DEC_WIDTH : %s, %d\n", + PRINTF_INT64_DEC_WIDTH, (int)strlen(str1))); + sprintf(str1, "%" PRINTF_INT64_MODIFIER "u", + UINT64_C(18446744073709550591)); + if (0 != strcmp(str1, "18446744073709550591")) + REPORTERROR( + ("Something wrong with PRINTF_INT32_MODIFIER : %s\n", str1)); + if (atoi(PRINTF_UINT64_DEC_WIDTH) != (int)strlen(str1)) + REPORTERROR(("Something wrong with PRINTF_UINT64_DEC_WIDTH : %s, %d\n", + PRINTF_UINT64_DEC_WIDTH, (int)strlen(str1))); +#endif + sprintf(str0, "%d %x\n", 0, ~0); sprintf(str1, "%d %x\n", i8, ~0); if (0 != strcmp(str0, str1)) - printf("Something wrong with i8 : %s\n", str1); + REPORTERROR(("Something wrong with i8 : %s\n", str1)); sprintf(str1, "%u %x\n", u8, ~0); if (0 != strcmp(str0, str1)) - printf("Something wrong with u8 : %s\n", str1); + REPORTERROR(("Something wrong with u8 : %s\n", str1)); sprintf(str1, "%d %x\n", i16, ~0); if (0 != strcmp(str0, str1)) - printf("Something wrong with i16 : %s\n", str1); + REPORTERROR(("Something wrong with i16 : %s\n", str1)); sprintf(str1, "%u %x\n", u16, ~0); if (0 != strcmp(str0, str1)) - printf("Something wrong with u16 : %s\n", str1); + REPORTERROR(("Something wrong with u16 : %s\n", str1)); sprintf(str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0); if (0 != strcmp(str0, str1)) - printf("Something wrong with i32 : %s\n", str1); + REPORTERROR(("Something wrong with i32 : %s\n", str1)); sprintf(str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0); if (0 != strcmp(str0, str1)) - printf("Something wrong with u32 : %s\n", str1); + REPORTERROR(("Something wrong with u32 : %s\n", str1)); #ifdef INT64_MAX sprintf(str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0); if (0 != strcmp(str0, str1)) - printf("Something wrong with i64 : %s\n", str1); + REPORTERROR(("Something wrong with i64 : %s\n", str1)); #endif sprintf(str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0); if (0 != strcmp(str0, str1)) - printf("Something wrong with imax : %s\n", str1); + REPORTERROR(("Something wrong with imax : %s\n", str1)); sprintf(str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0); if (0 != strcmp(str0, str1)) - printf("Something wrong with umax : %s\n", str1); + REPORTERROR(("Something wrong with umax : %s\n", str1)); TESTUMAX(8); TESTUMAX(16); @@ -823,9 +947,33 @@ int main() { TESTUMAX(64); #endif - return EXIT_SUCCESS; -} +#define STR(v) #v +#define Q(v) printf("sizeof " STR(v) " = %u\n", (unsigned)sizeof(v)); + if (err_n) { + printf("pstdint.h is not correct. Please use sizes below to correct " + "it:\n"); + } + + Q(int) + Q(unsigned) + Q(long int) + Q(short int) + Q(int8_t) + Q(int16_t) + Q(int32_t) +#ifdef INT64_MAX + Q(int64_t) +#endif +#if UINT_MAX < X_SIZE_MAX + printf("UINT_MAX < X_SIZE_MAX\n"); +#else + printf("UINT_MAX >= X_SIZE_MAX\n"); #endif + printf("%" PRINTF_INT64_MODIFIER "u vs %" PRINTF_INT64_MODIFIER "u\n", + UINT_MAX, X_SIZE_MAX); + + return EXIT_SUCCESS; +} -#endif /* _SYS_STDINT_H_ */ +#endif \ No newline at end of file diff --git a/libs/garbagecollector/CMakeLists.txt b/libs/garbagecollector/CMakeLists.txt index 39c3b18c0..fae0c3ee6 100644 --- a/libs/garbagecollector/CMakeLists.txt +++ b/libs/garbagecollector/CMakeLists.txt @@ -3,9 +3,6 @@ # # Build the garbage collector library. -# Output our dynamic library to the top-level _build hierarchy -set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/_build/dll) - # Marvelous flags, likely compiler dependent. add_definitions("-DBUILDING_COLLECTOR_DLL") @@ -22,19 +19,15 @@ add_dependencies(garbagecollector basekit) set_target_properties(garbagecollector PROPERTIES PUBLIC_HEADER "${HEADERS}") target_link_libraries(garbagecollector basekit) -# ...And the static library -#add_library(garbagecollector_static STATIC ${SRCS}) +# Now build the static library +add_library(garbagecollector_static STATIC ${SRCS}) +add_dependencies(garbagecollector_static basekit_static) +set_target_properties(garbagecollector_static PROPERTIES PUBLIC_HEADER "${HEADERS}") +target_link_libraries(garbagecollector_static basekit_static) # The following add the install target, so we put libgarbagecollector.* # in our install prefix. -if(WIN32) - install(TARGETS garbagecollector - RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} - PUBLIC_HEADER DESTINATION include/io - ) -else() - install(TARGETS garbagecollector - LIBRARY DESTINATION lib - PUBLIC_HEADER DESTINATION include/io - ) -endif(WIN32) +install( + TARGETS garbagecollector + FILE_SET HEADERS +) diff --git a/libs/iovm/CMakeLists.txt b/libs/iovm/CMakeLists.txt index 162b1b323..0b474ddcd 100644 --- a/libs/iovm/CMakeLists.txt +++ b/libs/iovm/CMakeLists.txt @@ -1,59 +1,60 @@ # Base Io build system # Written by Jeremy Tregunna # +# CMake file for libs/iovm subdirectory. +# # Build the Io VM. # Need to go in and build io2c first. We need it to build our library. add_subdirectory(tools) -# Output our dynamic library to the top-level _build hierarchy -set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/_build/dll) - # Our Io source files to be "compiled" into a C source file. -#file(GLOB IO_SRCS "io/*.io") set(IO_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/io/List_bootstrap.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Object_bootstrap.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/OperatorTable.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Object.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/List.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Exception.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Actor.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/AddonLoader.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Sequence.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Block.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/CFunction.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Date.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Debugger.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Directory.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/DynLib.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Error.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/File.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/List_schwartzian.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Map.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Message.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Number.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Profiler.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Sandbox.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Serialize.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/System.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/UnitTest.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Vector.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Path.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/CLI.io - ${CMAKE_CURRENT_SOURCE_DIR}/io/Importer.io + List_bootstrap.io + Object_bootstrap.io + OperatorTable.io + Object.io + List.io + Exception.io + Actor.io + AddonLoader.io + Sequence.io + Block.io + CFunction.io + Date.io + Debugger.io + Directory.io + DynLib.io + Error.io + File.io + List_schwartzian.io + Map.io + Message.io + Number.io + Profiler.io + Sandbox.io + Serialize.io + System.io + UnitTest.io + Vector.io + Path.io + CLI.io + Importer.io ) +# Prepend the source location to every file +list(TRANSFORM IO_SRCS PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/io/) # Create a header file which defines our install prefix. This is # only needed because GCC is batshit insane. -file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/source/IoInstallPrefix.h "#define INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\"") +configure_file(IoInstallPrefix.h.in IoInstallPrefix.h) # The custom command to generate source/IoVMInit.c which is our # "compiled" Io to C source code. +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/source) add_custom_command( - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/source/IoVMInit.c - COMMAND ${PROJECT_BINARY_DIR}/_build/binaries/io2c VMCode IoState_doString_ ${IO_SRCS} > ${CMAKE_CURRENT_SOURCE_DIR}/source/IoVMInit.c - DEPENDS io2c + OUTPUT IoVMInit.c + COMMAND io2c VMCode IoState_doString_ ${IO_SRCS} > IoVMInit.c + DEPENDS io2c ${IO_SRCS} ) # Handle annoying NAN @@ -79,41 +80,36 @@ add_definitions("-DBUILDING_IOVM_DLL")# -DINSTALL_PREFIX="${CMAKE_INSTALL_PREFIX # Include dirs, -I flags and whatnot include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/../../deps/parson - ${CMAKE_CURRENT_SOURCE_DIR}/../basekit/source - ${CMAKE_CURRENT_SOURCE_DIR}/../garbagecollector/source - ) + ${BASEKIT_SOURCE_DIR} + ${BASEKIT_SOURCE_DIR}/simd_cph/include + ${GARBAGECOLLECTOR_SOURCE_DIR} + ${IOVM_SOURCE_DIR} + ${PARSON_SOURCE_DIR}) # Our library sources. -file(GLOB SRCS "source/*.c") -list(REMOVE_ITEM SRCS "${CMAKE_CURRENT_SOURCE_DIR}/source/IoState_iterative_fast.c") -list(APPEND SRCS source/IoVMInit.c) -list(APPEND SRCS ../../deps/parson/parson.c) +file(GLOB IOVM_SRCS "${IOVM_SOURCE_DIR}/*.c") +list(REMOVE_ITEM IOVM_SRCS "${IOVM_SOURCE_DIR}/IoState_iterative_fast.c") +list(APPEND IOVM_SRCS + ${CMAKE_CURRENT_BINARY_DIR}/IoVMInit.c + ${PARSON_SOURCE_DIR}/parson.c) + file(GLOB HEADERS "source/*.h") # Now build the shared library -add_library(iovmall SHARED ${SRCS}) -add_dependencies(iovmall io2c basekit garbagecollector) +add_library(iovmall SHARED ${IOVM_SRCS}) set_target_properties(iovmall PROPERTIES PUBLIC_HEADER "${HEADERS}") target_link_libraries(iovmall basekit garbagecollector) +target_include_directories(iovmall PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + +# Now build the static library +add_library(iovmall_static STATIC ${IOVM_SRCS}) +target_link_libraries(iovmall_static basekit_static) +target_link_libraries(iovmall_static garbagecollector_static) +target_include_directories(iovmall_static PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # The following add the install target, so we put libvmall.* in our # install prefix. -if(WIN32) - install(TARGETS iovmall - RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} - PUBLIC_HEADER DESTINATION include/io - ) -else() - install(TARGETS iovmall - LIBRARY DESTINATION lib - PUBLIC_HEADER DESTINATION include/io - ) -endif(WIN32) - -# Test for iterative evaluator -add_executable(test_iterative_eval tests/test_iterative_eval.c) -target_link_libraries(test_iterative_eval iovmall) -set_target_properties(test_iterative_eval PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/_build/binaries +install ( + TARGETS iovmall iovmall_static + FILE_SET HEADERS ) diff --git a/libs/iovm/IoInstallPrefix.h.in b/libs/iovm/IoInstallPrefix.h.in new file mode 100644 index 000000000..182f16478 --- /dev/null +++ b/libs/iovm/IoInstallPrefix.h.in @@ -0,0 +1,5 @@ + +#define INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" + + + diff --git a/libs/iovm/source/IoCoroutine.c b/libs/iovm/source/IoCoroutine.c index 5d9744d6a..078fb10f1 100644 --- a/libs/iovm/source/IoCoroutine.c +++ b/libs/iovm/source/IoCoroutine.c @@ -19,7 +19,9 @@ Now implemented using frame-based evaluation (no platform-specific assembly). #ifdef IO_CALLCC #include "IoContinuation.h" #endif +#ifdef __GLIBC__ #include +#endif //#define DEBUG diff --git a/libs/iovm/source/IoFile.c b/libs/iovm/source/IoFile.c index c61aa064f..c939e9d7a 100644 --- a/libs/iovm/source/IoFile.c +++ b/libs/iovm/source/IoFile.c @@ -812,7 +812,7 @@ UArray *IoFile_readUArrayOfLength_(IoFile *self, IoObject *locals, size_t length = IoMessage_locals_sizetArgAt_(m, locals, 0); UArray *ba = UArray_new(); IoFile_assertOpen(self, locals, m); - if (IOSTATE->errorRaised) return IONIL(self); + if (IOSTATE->errorRaised) return NULL; UArray_readNumberOfItems_fromCStream_(ba, length, DATA(self)->stream); diff --git a/libs/iovm/source/IoObject.c b/libs/iovm/source/IoObject.c index ada1b3d5e..06f2fe531 100644 --- a/libs/iovm/source/IoObject.c +++ b/libs/iovm/source/IoObject.c @@ -1913,14 +1913,14 @@ IoNumber *IoObject_getNumberSlot(IoObject *self, UArray *IoObject_rawGetUArraySlot(IoObject *self, IoObject *locals, IoMessage *m, IoSymbol *slotName) { IoSeq *seq = IoObject_getSlot_(self, slotName); - IOASSERT(ISSEQ(seq), CSTRING(slotName)); + IOASSERT0(ISSEQ(seq), CSTRING(slotName)); return IoSeq_rawUArray(seq); } UArray *IoObject_rawGetMutableUArraySlot(IoObject *self, IoObject *locals, IoMessage *m, IoSymbol *slotName) { IoSeq *seq = IoObject_getSlot_(self, slotName); - IOASSERT(ISSEQ(seq), CSTRING(slotName)); + IOASSERT0(ISSEQ(seq), CSTRING(slotName)); return IoSeq_rawUArray(seq); } diff --git a/libs/iovm/source/IoState.c b/libs/iovm/source/IoState.c index 03b49095e..af88f54cf 100644 --- a/libs/iovm/source/IoState.c +++ b/libs/iovm/source/IoState.c @@ -46,9 +46,9 @@ void IoVMCodeInit(IoObject *context); // Called once during init after all protos are registered. // Aliases (e.g., false.elseif := Object getSlot("if")) automatically // inherit the flag since they reference the same CFunction object. -static void IoState_markSlotLazyArgs_(IoState *self, const char *protoId, +static void IoState_markSlotLazyArgs_(IoState *self, IoObject *object, const char *slotName) { - IoObject *proto = IoState_protoWithId_(self, protoId); + IoObject *proto = IoObject_firstProto(object); if (!proto) return; IoObject *f = IoObject_rawGetSlot_(proto, SIOSYMBOL(slotName)); if (f && ISCFUNCTION(f)) { @@ -58,36 +58,44 @@ static void IoState_markSlotLazyArgs_(IoState *self, const char *protoId, static void IoState_markLazyArgsCFunctions_(IoState *self) { // Control flow - IoState_markSlotLazyArgs_(self, "Object", "if"); - IoState_markSlotLazyArgs_(self, "Object", "while"); - IoState_markSlotLazyArgs_(self, "Object", "for"); - IoState_markSlotLazyArgs_(self, "Object", "loop"); + IoObject *an_object = IoObject_new(self); + IoObject *a_list = IoList_new(self); + IoObject *a_number = + IoNumber_newWithDouble_(self, 0.0); + IoObject *a_date = IoDate_new(self); + IoObject *a_sequence = IoSeq_new(self); + IoObject *a_map = IoMap_new(self); + IoObject *a_file = IoFile_new(self); + IoState_markSlotLazyArgs_(self, an_object, "if"); + IoState_markSlotLazyArgs_(self, an_object, "while"); + IoState_markSlotLazyArgs_(self, an_object, "for"); + IoState_markSlotLazyArgs_(self, an_object, "loop"); #ifdef IO_CALLCC - IoState_markSlotLazyArgs_(self, "Object", "callcc"); + IoState_markSlotLazyArgs_(self, an_object, "callcc"); #endif // Block/method construction - IoState_markSlotLazyArgs_(self, "Object", "method"); - IoState_markSlotLazyArgs_(self, "Object", "block"); + IoState_markSlotLazyArgs_(self, an_object, "method"); + IoState_markSlotLazyArgs_(self, an_object, "block"); // Evaluation (body is lazy) - IoState_markSlotLazyArgs_(self, "Object", "do"); - IoState_markSlotLazyArgs_(self, "Object", "lexicalDo"); - IoState_markSlotLazyArgs_(self, "Object", "message"); - IoState_markSlotLazyArgs_(self, "Object", "foreachSlot"); + IoState_markSlotLazyArgs_(self, an_object, "do"); + IoState_markSlotLazyArgs_(self, an_object, "lexicalDo"); + IoState_markSlotLazyArgs_(self, an_object, "message"); + IoState_markSlotLazyArgs_(self, an_object, "foreachSlot"); // List - IoState_markSlotLazyArgs_(self, "List", "foreach"); - IoState_markSlotLazyArgs_(self, "List", "reverseForeach"); - IoState_markSlotLazyArgs_(self, "List", "sortInPlace"); + IoState_markSlotLazyArgs_(self, a_list, "foreach"); + IoState_markSlotLazyArgs_(self, a_list, "reverseForeach"); + IoState_markSlotLazyArgs_(self, a_list, "sortInPlace"); // Number - IoState_markSlotLazyArgs_(self, "Number", "repeat"); + IoState_markSlotLazyArgs_(self, a_number, "repeat"); // Date - IoState_markSlotLazyArgs_(self, "Date", "cpuSecondsToRun"); + IoState_markSlotLazyArgs_(self, a_date, "cpuSecondsToRun"); // Sequence - IoState_markSlotLazyArgs_(self, "Sequence", "foreach"); + IoState_markSlotLazyArgs_(self, a_sequence, "foreach"); // Map - IoState_markSlotLazyArgs_(self, "Map", "foreach"); + IoState_markSlotLazyArgs_(self, a_map, "foreach"); // File - IoState_markSlotLazyArgs_(self, "File", "foreach"); - IoState_markSlotLazyArgs_(self, "File", "foreachLine"); + IoState_markSlotLazyArgs_(self, a_file, "foreach"); + IoState_markSlotLazyArgs_(self, a_file, "foreachLine"); } void IoState_new_atAddress(void *address) { @@ -357,7 +365,8 @@ void IoState_setupSingletons(IoState *self) { IoObject_setSlot_to_(core, SIOSYMBOL("Call"), IoCall_proto(self)); // Cache Call tag/proto for inline allocation in block activation - self->callProto = IoState_protoWithId_(self, "Call"); + IoCall *dummy = IoCall_new(self); + self->callProto = IoObject_firstProto(dummy); self->callTag = IoObject_tag(self->callProto); self->blockLocalsPoolSize = 0; self->callPoolSize = 0; diff --git a/libs/iovm/source/IoState_inline.h b/libs/iovm/source/IoState_inline.h index b10bd7ba9..d3ee70acd 100644 --- a/libs/iovm/source/IoState_inline.h +++ b/libs/iovm/source/IoState_inline.h @@ -18,6 +18,11 @@ IoState_error_(IOSTATE, m, "Io Assertion '%s'", message); \ return IONIL(self); \ } +#define IOASSERT0(value, message) \ + if (!(value)) { \ + IoState_error_(IOSTATE, m, "Io Assertion '%s'", message); \ + return NULL; \ + } #define IOCOLLECTOR (IOSTATE->collector) diff --git a/libs/iovm/source/IoState_symbols.c b/libs/iovm/source/IoState_symbols.c index 413c08cd9..1e241081a 100644 --- a/libs/iovm/source/IoState_symbols.c +++ b/libs/iovm/source/IoState_symbols.c @@ -17,14 +17,15 @@ void IoState_setupCachedNumbers(IoState *self) { self->cachedNumbers = List_new(); + IoNumber *number; for (i = MIN_CACHED_NUMBER; i < MAX_CACHED_NUMBER + 1; i++) { - IoNumber *number = IoNumber_newWithDouble_(self, i); + number = IoNumber_newWithDouble_(self, i); List_append_(self->cachedNumbers, number); IoState_retain_(self, number); } // Cache Number proto and tag for fast inline allocation - self->numberProto = IoState_protoWithId_(self, "Number"); + self->numberProto = IoObject_firstProto(number); self->numberTag = IoObject_tag(self->numberProto); self->numberDataFreeList = NULL; self->numberDataFreeListSize = 0; diff --git a/libs/iovm/tools/io2c.c b/libs/iovm/tools/io2c.c index 144fea68c..4f909feda 100644 --- a/libs/iovm/tools/io2c.c +++ b/libs/iovm/tools/io2c.c @@ -7,9 +7,9 @@ All rights reserved. See _License.txt. #include void showUsage(void) { - printf("usage: io2c ObjectName ParseFunctionName ioFile1 ioFile2 ...\n"); - printf("output is sent to standard output\n"); - printf("ParseFunctionName is either IoState_on_doCString_withLabel_ or " + fprintf(stderr, "usage: io2c ObjectName ParseFunctionName ioFile1 ioFile2 ...\n"); + fprintf(stderr, "output is sent to standard output\n"); + fprintf(stderr, "ParseFunctionName is either IoState_on_doCString_withLabel_ or " "IoState_on_doPackedCString_withLabel_\n\n"); } @@ -42,13 +42,12 @@ void quoteStream(FILE *in, FILE *out) { fputs("\";\n\n", out); } -void processFile(const char *objectName, const char *fileName, +void processFile(FILE* out, const char *objectName, const char *fileName, const char *parseFunctionName) { FILE *in = fopen(fileName, "r"); - FILE *out = stdout; if (!in) { - printf("unable to open input file %s\n", fileName); + fprintf(stderr, "unable to open input file %s\n", fileName); exit(-1); } @@ -84,7 +83,7 @@ int main(int argc, const char *argv[]) { for (i = 3; i < argc; i++) { const char *fileName = argv[i]; - processFile(objectName, fileName, parseFunctionName); + processFile(out, objectName, fileName, parseFunctionName); } fputs("}\n\n", out); diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt old mode 100755 new mode 100644 index 746fd7936..6a3a4050d --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,6 +1,8 @@ # Base Io build system # Written by Jeremy Tregunna # +# CMake file for tools subdirectory. +# # Creates the io_static and io binaries. These are different, only # in so much as io_static depends on the *_static libraries, and # io uses dynamic libraries. Use whichever floats your boat, we @@ -21,30 +23,28 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "(Darwin|FreeBSD|NetBSD)") endif(${CMAKE_SYSTEM_NAME} MATCHES "(Darwin|FreeBSD|NetBSD)") # We want the binaries to go other places than here. -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/_build/binaries) +#set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/_build/binaries) # Include locations include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/../libs/basekit/source - ${CMAKE_CURRENT_SOURCE_DIR}/../libs/garbagecollector/source - ${CMAKE_CURRENT_SOURCE_DIR}/../libs/iovm/source + ${COROUTINE_SOURCE_DIR} + ${BASEKIT_SOURCE_DIR} + ${GARBAGECOLLECTOR_SOURCE_DIR} + ${IOVM_SOURCE_DIR} ) # Only one file, main.c set(SRCS source/main.c) # Set up an empty LIBS so we can append to it things we may need to link in. -set(LIBS) - # Add dynamic loader library for those who need it -if(${CMAKE_SYSTEM_NAME} MATCHES "(Darwin|Linux|SunOS|syllable)") - list(APPEND LIBS "-ldl") -endif(${CMAKE_SYSTEM_NAME} MATCHES "(Darwin|Linux|SunOS|syllable)") +set(LIBS ${CMAKE_DL_LIBS}) # Add math library for those who need it -if(${CMAKE_SYSTEM_NAME} MATCHES "(OpenBSD|FreeBSD|Linux|NetBSD|DragonFly)") - list(APPEND LIBS "-lm") -endif(${CMAKE_SYSTEM_NAME} MATCHES "(OpenBSD|FreeBSD|Linux|NetBSD|DragonFly)") +find_library(MATH_LIBRARY m) +if(MATH_LIBRARY) + list(APPEND LIBS ${MATH_LIBRARY}) +endif() # Add curses library for readline needs it if(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") @@ -66,11 +66,13 @@ target_link_libraries(io basekit garbagecollector iovmall ${LIBS}) # The following add the install target, so we put io and io_static in our # install prefix. -if(WIN32) - install(TARGETS io io_static DESTINATION ${CMAKE_INSTALL_PREFIX}) -else() - install(TARGETS io io_static DESTINATION bin) -endif(WIN32) +install(TARGETS io io_static) + +#if(WIN32) +# install(TARGETS io io_static DESTINATION ${CMAKE_INSTALL_PREFIX}) +#else() +# install(TARGETS io io_static DESTINATION bin) +#endif(WIN32) # Eerie