initial commit
This commit is contained in:
58
.clang-format
Normal file
58
.clang-format
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
BasedOnStyle: WebKit
|
||||||
|
IndentWidth: 8
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
PointerAlignment: Right
|
||||||
|
ColumnLimit: 80
|
||||||
|
AlignAfterOpenBracket: AlwaysBreak
|
||||||
|
AlignConsecutiveAssignments: None
|
||||||
|
AlignConsecutiveBitFields: None
|
||||||
|
AlignConsecutiveDeclarations: None
|
||||||
|
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: AlignAfterOperator
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllArgumentsOnNextLine: false
|
||||||
|
AllowAllConstructorInitializersOnNextLine: false
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: Empty
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortEnumsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: false
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLambdasOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
|
BreakBeforeBinaryOperators: All
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: BeforeComma
|
||||||
|
BreakInheritanceList: BeforeComma
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ContinuationIndentWidth: 8
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
IncludeBlocks: Regroup
|
||||||
|
SortIncludes: true
|
||||||
|
IndentRequires: true
|
||||||
|
NamespaceIndentation: Inner
|
||||||
|
ReflowComments: true
|
||||||
|
SpacesBeforeTrailingComments: 3
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: AlignWithSpaces
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 1000000
|
||||||
|
PenaltyExcessCharacter: 5
|
||||||
|
PenaltyBreakOpenParenthesis: 5
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 5
|
||||||
|
PenaltyIndentedWhitespace: 0
|
||||||
|
AttributeMacros:
|
||||||
|
- BLUELIB_API
|
||||||
|
ForEachMacros:
|
||||||
|
- b_btree_foreach
|
||||||
|
- b_queue_foreach
|
||||||
145
.gitignore
vendored
Normal file
145
.gitignore
vendored
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/linux,vim,c,cmake,macos
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,vim,c,cmake,macos
|
||||||
|
|
||||||
|
### C ###
|
||||||
|
# Prerequisites
|
||||||
|
*.d
|
||||||
|
|
||||||
|
# Object files
|
||||||
|
*.o
|
||||||
|
*.ko
|
||||||
|
*.obj
|
||||||
|
*.elf
|
||||||
|
|
||||||
|
# Linker output
|
||||||
|
*.ilk
|
||||||
|
*.map
|
||||||
|
*.exp
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Libraries
|
||||||
|
*.lib
|
||||||
|
*.a
|
||||||
|
*.la
|
||||||
|
*.lo
|
||||||
|
|
||||||
|
# Shared objects (inc. Windows DLLs)
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
*.i*86
|
||||||
|
*.x86_64
|
||||||
|
*.hex
|
||||||
|
|
||||||
|
# Debug files
|
||||||
|
*.dSYM/
|
||||||
|
*.su
|
||||||
|
*.idb
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# Kernel Module Compile Results
|
||||||
|
*.mod*
|
||||||
|
*.cmd
|
||||||
|
.tmp_versions/
|
||||||
|
modules.order
|
||||||
|
Module.symvers
|
||||||
|
Mkfile.old
|
||||||
|
dkms.conf
|
||||||
|
|
||||||
|
### CMake ###
|
||||||
|
CMakeLists.txt.user
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles
|
||||||
|
CMakeScripts
|
||||||
|
Testing
|
||||||
|
Makefile
|
||||||
|
cmake_install.cmake
|
||||||
|
install_manifest.txt
|
||||||
|
compile_commands.json
|
||||||
|
CTestTestfile.cmake
|
||||||
|
_deps
|
||||||
|
|
||||||
|
### CMake Patch ###
|
||||||
|
# External projects
|
||||||
|
*-prefix/
|
||||||
|
|
||||||
|
### Linux ###
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
### macOS ###
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
### macOS Patch ###
|
||||||
|
# iCloud generated files
|
||||||
|
*.icloud
|
||||||
|
|
||||||
|
### Vim ###
|
||||||
|
# Swap
|
||||||
|
[._]*.s[a-v][a-z]
|
||||||
|
!*.svg # comment out if you don't need vector files
|
||||||
|
[._]*.sw[a-p]
|
||||||
|
[._]s[a-rt-v][a-z]
|
||||||
|
[._]ss[a-gi-z]
|
||||||
|
[._]sw[a-p]
|
||||||
|
|
||||||
|
# Session
|
||||||
|
Session.vim
|
||||||
|
Sessionx.vim
|
||||||
|
|
||||||
|
# Temporary
|
||||||
|
.netrwhist
|
||||||
|
# Auto-generated tag files
|
||||||
|
tags
|
||||||
|
# Persistent undo
|
||||||
|
[._]*.un~
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/linux,vim,c,cmake,macos
|
||||||
|
|
||||||
|
build/
|
||||||
9
CMakeLists.txt
Normal file
9
CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
project(ivy C)
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||||
|
|
||||||
|
set(Bluelib_STATIC TRUE)
|
||||||
|
find_package(Bluelib REQUIRED)
|
||||||
|
|
||||||
|
add_subdirectory(ivy)
|
||||||
153
cmake/FindBluelib.cmake
Normal file
153
cmake/FindBluelib.cmake
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
#[=======================================================================[.rst:
|
||||||
|
FindBluelib
|
||||||
|
------------
|
||||||
|
|
||||||
|
Find the Bluelib library and header directories
|
||||||
|
|
||||||
|
Imported Targets
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
This module defines the following :prop_tgt:`IMPORTED` target:
|
||||||
|
|
||||||
|
``Bluelib::Bluelib``
|
||||||
|
The Bluelib library, if found
|
||||||
|
|
||||||
|
Result Variables
|
||||||
|
^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
This module will set the following variables in your project:
|
||||||
|
|
||||||
|
``Bluelib_FOUND``
|
||||||
|
true if the Bluelib C headers and libraries were found
|
||||||
|
``Bluelib_INCLUDE_DIR``
|
||||||
|
directories containing the Bluelib C headers.
|
||||||
|
|
||||||
|
``Bluelib_LIBRARY``
|
||||||
|
the C library to link against
|
||||||
|
|
||||||
|
Hints
|
||||||
|
^^^^^
|
||||||
|
|
||||||
|
The user may set the environment variable ``Bluelib_PREFIX`` to the root
|
||||||
|
directory of a Bluelib library installation.
|
||||||
|
#]=======================================================================]
|
||||||
|
|
||||||
|
set (Bluelib_SEARCH_PATHS
|
||||||
|
~/Library/Frameworks
|
||||||
|
/Library/Frameworks
|
||||||
|
/usr/local
|
||||||
|
/usr/local/share
|
||||||
|
/usr
|
||||||
|
/sw # Fink
|
||||||
|
/opt/local # DarwinPorts
|
||||||
|
/opt/csw # Blastwave
|
||||||
|
/opt
|
||||||
|
${Bluelib_PREFIX}
|
||||||
|
$ENV{Bluelib_PREFIX})
|
||||||
|
|
||||||
|
if (Bluelib_STATIC)
|
||||||
|
set(_lib_suffix "-s")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
set(supported_components Core Object Term Cmd)
|
||||||
|
set(components ${Bluelib_FIND_COMPONENTS})
|
||||||
|
string(REPLACE ";" ", " supported_components_string_list "${supported_components}")
|
||||||
|
|
||||||
|
if (NOT components)
|
||||||
|
set(components ${supported_components})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
set(required_vars)
|
||||||
|
|
||||||
|
foreach (component ${components})
|
||||||
|
if (NOT "${component}" IN_LIST supported_components)
|
||||||
|
message(FATAL_ERROR "'${component}' is not a valid Bluelib module.\nSupported modules: ${supported_components_string_list}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
string(TOLOWER ${component} header_name)
|
||||||
|
set(lib_name ${header_name}${_lib_suffix})
|
||||||
|
|
||||||
|
if (NOT Bluelib_${component}_INCLUDE_DIR)
|
||||||
|
find_path(Bluelib_${component}_INCLUDE_DIR
|
||||||
|
NAMES blue/${header_name}.h ${Bluelib_FIND_ARGS}
|
||||||
|
PATH_SUFFIXES include
|
||||||
|
PATHS ${Bluelib_SEARCH_PATHS})
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (NOT Bluelib_${component}_LIBRARY)
|
||||||
|
find_library(Bluelib_${component}_LIBRARY
|
||||||
|
NAMES blue-${lib_name} ${Bluelib_FIND_ARGS}
|
||||||
|
PATH_SUFFIXES lib
|
||||||
|
PATHS ${Bluelib_SEARCH_PATHS})
|
||||||
|
else ()
|
||||||
|
# on Windows, ensure paths are in canonical format (forward slahes):
|
||||||
|
file(TO_CMAKE_PATH "${Bluelib_${component}_LIBRARY}" Bluelib_${component}_LIBRARY)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
list(APPEND required_vars Bluelib_${component}_INCLUDE_DIR Bluelib_${component}_LIBRARY)
|
||||||
|
endforeach (component)
|
||||||
|
|
||||||
|
unset(Bluelib_FIND_ARGS)
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
find_package_handle_standard_args(Bluelib
|
||||||
|
REQUIRED_VARS ${required_vars})
|
||||||
|
|
||||||
|
if (Bluelib_FOUND)
|
||||||
|
set(created_targets)
|
||||||
|
foreach (component ${components})
|
||||||
|
string(TOLOWER ${component} header_name)
|
||||||
|
set(lib_name ${header_name}${_lib_suffix})
|
||||||
|
|
||||||
|
if(NOT TARGET Bluelib::${component})
|
||||||
|
add_library(Bluelib::${component} UNKNOWN IMPORTED)
|
||||||
|
set_target_properties(Bluelib::${component} PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${Bluelib_${component}_INCLUDE_DIR}")
|
||||||
|
target_compile_definitions(Bluelib::${component} INTERFACE _CRT_SECURE_NO_WARNINGS=1)
|
||||||
|
|
||||||
|
set_target_properties(Bluelib::${component} PROPERTIES
|
||||||
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||||
|
IMPORTED_LOCATION "${Bluelib_${component}_LIBRARY}")
|
||||||
|
set(created_targets ${created_targets} ${component})
|
||||||
|
endif ()
|
||||||
|
endforeach (component)
|
||||||
|
|
||||||
|
foreach (component ${created_targets})
|
||||||
|
if ("${component}" STREQUAL "Object")
|
||||||
|
if (NOT TARGET Bluelib::Core)
|
||||||
|
message(FATAL_ERROR "Bluelib: Module 'Object' depends on 'Core', which was not specified in find_package()")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
target_link_libraries(Bluelib::Object INTERFACE Bluelib::Core)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if ("${component}" STREQUAL "Term")
|
||||||
|
if (NOT TARGET Bluelib::Core)
|
||||||
|
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Core', which was not specified in find_package()")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (NOT TARGET Bluelib::Object)
|
||||||
|
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Object', which was not specified in find_package()")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
target_link_libraries(Bluelib::Term INTERFACE Bluelib::Core Bluelib::Object)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if ("${component}" STREQUAL "Cmd")
|
||||||
|
if (NOT TARGET Bluelib::Core)
|
||||||
|
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Core', which was not specified in find_package()")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (NOT TARGET Bluelib::Object)
|
||||||
|
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Object', which was not specified in find_package()")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (NOT TARGET Bluelib::Term)
|
||||||
|
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Term', which was not specified in find_package()")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
target_link_libraries(Bluelib::Cmd INTERFACE Bluelib::Core Bluelib::Object Bluelib::Term)
|
||||||
|
endif ()
|
||||||
|
endforeach (component)
|
||||||
|
endif()
|
||||||
8
ivy/CMakeLists.txt
Normal file
8
ivy/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
file(GLOB_RECURSE ivy_sources *.c *.h)
|
||||||
|
|
||||||
|
add_executable(ivy ${ivy_sources})
|
||||||
|
target_link_libraries(
|
||||||
|
ivy
|
||||||
|
Bluelib::Core
|
||||||
|
Bluelib::Object
|
||||||
|
Bluelib::Cmd)
|
||||||
14
ivy/cmd/assemble.c
Normal file
14
ivy/cmd/assemble.c
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#include "cmd.h"
|
||||||
|
|
||||||
|
#include <blue/cmd.h>
|
||||||
|
|
||||||
|
B_COMMAND(CMD_ASSEMBLE, CMD_ROOT)
|
||||||
|
{
|
||||||
|
B_COMMAND_NAME("assemble");
|
||||||
|
B_COMMAND_SHORT_NAME('A');
|
||||||
|
B_COMMAND_DESC(
|
||||||
|
"assemble one or more Ivy source files into Ivy object files.");
|
||||||
|
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||||
|
|
||||||
|
B_COMMAND_HELP_OPTION();
|
||||||
|
}
|
||||||
10
ivy/cmd/cmd.h
Normal file
10
ivy/cmd/cmd.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef CMD_CMD_H_
|
||||||
|
#define CMD_CMD_H_
|
||||||
|
|
||||||
|
enum command_id {
|
||||||
|
CMD_ROOT,
|
||||||
|
CMD_ASSEMBLE,
|
||||||
|
CMD_REPL,
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
0
ivy/cmd/exec.c
Normal file
0
ivy/cmd/exec.c
Normal file
3
ivy/cmd/repl.c
Normal file
3
ivy/cmd/repl.c
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#include "cmd.h"
|
||||||
|
|
||||||
|
#include <blue/cmd.h>
|
||||||
40
ivy/main.c
Normal file
40
ivy/main.c
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include "cmd/cmd.h"
|
||||||
|
|
||||||
|
#include <blue/cmd.h>
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ARG_FILE
|
||||||
|
};
|
||||||
|
|
||||||
|
B_COMMAND(CMD_ROOT, B_COMMAND_INVALID_ID)
|
||||||
|
{
|
||||||
|
B_COMMAND_NAME("ivy");
|
||||||
|
B_COMMAND_DESC("evaluate an Ivy source file or Ivy object file.");
|
||||||
|
B_COMMAND_HELP_OPTION();
|
||||||
|
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
|
||||||
|
|
||||||
|
B_COMMAND_ARG(ARG_FILE)
|
||||||
|
{
|
||||||
|
B_ARG_NAME("file");
|
||||||
|
B_ARG_DESC("The file to execute.");
|
||||||
|
B_ARG_NR_VALUES(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
B_COMMAND_USAGE()
|
||||||
|
{
|
||||||
|
B_COMMAND_USAGE_OPT_PLACEHOLDER();
|
||||||
|
B_COMMAND_USAGE_ARG(ARG_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
B_COMMAND_USAGE()
|
||||||
|
{
|
||||||
|
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
|
||||||
|
B_COMMAND_USAGE_OPT_PLACEHOLDER();
|
||||||
|
B_COMMAND_USAGE_ARG_PLACEHOLDER();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, const char **argv)
|
||||||
|
{
|
||||||
|
return b_command_dispatch(CMD_ROOT, argc, argv);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user