Skip to content

Commit

Permalink
(stdlib) Add C++-based stdlib project (#407)
Browse files Browse the repository at this point in the history
This commit also contains local modifications to the fmt lib. For the full details about these modifications, see the
(now-squashed) separate commit in the original pull request: #407
  • Loading branch information
perlun authored Sep 27, 2023
1 parent 85be93f commit d66c6a4
Show file tree
Hide file tree
Showing 20 changed files with 10,170 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -3
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: MultiLine
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Never
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterUnion: true
BeforeCatch: false
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 4
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Left
ReflowComments: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never
3 changes: 3 additions & 0 deletions .github/workflows/publish-release-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
- name: Re-generate auto-generated files
run: make auto-generated

- name: Rebuild stdlib
run: make stdlib

#
# Build releases
#
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ jobs:
- name: Re-generate auto-generated files
run: make auto-generated

# Needed to run tests, when they are running in compilation mode
# (PERLANG_EXPERIMENTAL_COMPILATION=true)
- name: Rebuild stdlib
run: make stdlib

- name: Run test suite
run: dotnet test --configuration Release --verbosity normal
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,4 @@ _site/
docfx/*.dll
docfx/docfx.exe
docfx/docfx.exe.config
lib/
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ run: auto-generated
dotnet build
src/Perlang.ConsoleApp/bin/Debug/net7.0/perlang

stdlib:
# Creating a subdirectory is important, since cmake will otherwise clutter the stdlib directory with its auto-generated
# build scripts
cd src/stdlib && mkdir -p out && cd out && cmake -DCMAKE_INSTALL_PREFIX:PATH=../../../lib/stdlib -G "Unix Makefiles" .. && make stdlib install

test:
dotnet test --configuration Release

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ editor](https://github.com/mono/mono/blob/main/mcs/tools/csharp/getline.cs),
dual-licensed under the terms of the MIT X11 license or the Apache License 2.0.
Copyright (c) 2008 Novell, Inc. Copyright (c) 2016 Xamarin Inc.

[src/stdlib/src/double-conversion](src/stdlib/src/double-conversion) includes
content from the Google `double-conversion` library, available at
https://github.com/google/double-conversion, licensed under the BSD 3-Clause
"New" or "Revised" License. Copyright 2006-2011, the V8 project authors.

[src/stdlib/src/fmt](src/stdlib/src/fmt) includes content from the `{fmt}`
library, available at https://github.com/fmtlib/fmt, licensed under the MIT
license. Copyright (c) 2012 - present, Victor Zverovich and `{fmt}`
contributors.

## Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Expand Down
Empty file added lib/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion release-notes/v0.3.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [0.3.0] - 2023-02-26
- The third public release of Perlang. The most notable changes are the added support for the `float` data type, and that the system has been upgraded to .NET 7.
- The REPL is also noticeably nicer to use now, particularly for those of us used to bash/Emacs like keybindings. [[#354][354]], [[#356][356]]
- The REPL is also noticeably nicer to use now, particularly for those of us used to bash/Emacs-like keybindings. [[#354][354]], [[#356][356]]
- API docs on the website was broken since the v0.2.0 release for unknown reasons. [[#344][344]] has more details.
- Based on community feedback, the project README was also slightly improved. [[#371][371]]

Expand Down
3 changes: 3 additions & 0 deletions release-notes/v0.4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- The fourth public release of Perlang.

### Added
#### Experimental compilation
- Add C++-based stdlib project [[#407][407]]

### Changed
#### Data types
Expand All @@ -28,3 +30,4 @@
[385]: https://github.com/perlang-org/perlang/pull/385
[386]: https://github.com/perlang-org/perlang/pull/386
[389]: https://github.com/perlang-org/perlang/pull/389
[407]: https://github.com/perlang-org/perlang/pull/407
72 changes: 72 additions & 0 deletions src/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
cmake_minimum_required(VERSION 3.0)
project(stdlib VERSION 0.1.0)

set(headers
src/stdlib.hpp
src/double-conversion/utils.h
)

add_library(
stdlib
src/Base64.cpp
src/print.cpp
)

# Enable C++ 17 support. This is required on e.g. AppleClang 13
set_property(TARGET stdlib PROPERTY CXX_STANDARD 17)

target_include_directories(
stdlib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

include(GNUInstallDirs)

install(
TARGETS stdlib
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(
FILES ${headers}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

# The testing code is not yet ready for macOS, since it uses a different linker which doesnät support --wrap. We'll
# live with only building/running the tests on other platforms for now.
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
enable_testing()
include(CTest)

set(CCTEST_SRC
test/print.cc
test/double-conversion/cctest.cc
)

add_executable(
cctest
${CCTEST_SRC}
)

target_include_directories(
cctest
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

target_link_libraries(cctest stdlib)

# We enable wrapping for fwrite(), to be able to capture its output in tests. The reason why we don't do this on
# macOS is because it does not use GNU ld, so the --wrap linker option isn't available.
target_link_options(cctest PRIVATE -Wl,--wrap=fwrite)

add_test(NAME test_fast_dtoa
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND $<TARGET_FILE:cctest> test-fast-dtoa)

add_test(NAME test_print
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND $<TARGET_FILE:cctest> print)
endif()
10 changes: 10 additions & 0 deletions src/stdlib/src/Base64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "stdlib.hpp"

namespace perlang::stdlib
{
const char *Base64::to_string()
{
// Poor-man's FQCN. :-)
return "Perlang.Stdlib.Base64";
}
}
Loading

0 comments on commit d66c6a4

Please sign in to comment.