Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Use LLVM as a base and customize from there
BasedOnStyle: LLVM
Language: Cpp

# Indentation and spacing
IndentWidth: 4
TabWidth: 4
UseTab: Never
ContinuationIndentWidth: 8
ColumnLimit: 80
AccessModifierOffset: -4
NamespaceIndentation: All
IndentCaseLabels: true
IndentGotoLabels: false
IndentPPDirectives: AfterHash

# Braces and layout
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false

# Spaces
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpacesInParentheses: false
SpacesInAngles: false
SpacesInSquareBrackets: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpaceBeforeAssignmentOperators: true

# Pointers and references
DerivePointerAlignment: false
PointerAlignment: Left # "int* ptr" rather than "int *ptr"
ReferenceAlignment: Left

# Includes
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<.*>$'
Priority: 1
- Regex: '^".*"$'
Priority: 2
SortIncludes: true

# Line breaking
BreakConstructorInitializers: BeforeColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
BinPackParameters: false
BinPackArguments: false
PenaltyBreakBeforeFirstCallParameter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60

# C++ specific
Standard: Latest
Cpp11BracedListStyle: true
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveDeclarations: Consecutive
AlignOperands: Align
AlignAfterOpenBracket: Align
76 changes: 76 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms

on:
push:
branches: [ "First" ]
pull_request:
branches: [ "First" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl

steps:
- uses: actions/checkout@v4

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}

- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}
path: ${{ steps.strings.outputs.build-output-dir }}

12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.vs/
build/
bin/

**/Thumbs.db
**/desktop.ini

*.swp
*~

examples/*
!examples/*.cppsp
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.15)
project(cppsp)
option(CPPSP_BUILD_EXAMPLES "Build cppsp examples" OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(cppsp_compiler "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
if(CPPSP_BUILD_EXAMPLES)
add_custom_command(
TARGET cppsp_compiler
POST_BUILD
COMMAND "$<TARGET_FILE:cppsp_compiler>" ../examples/helloworld.cppsp
COMMAND "$<TARGET_FILE:cppsp_compiler>" ../examples/advanced.cppsp
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Building examples..."
)
endif()
82 changes: 48 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,65 @@
# cppsp<img src="cppsp.png" width="5%" alt="cppsp logo"/>
cppsp -a scripting language base on c++
# cppsp<img src="./res/cppsp.png" width="5%" alt="cppsp logo"/>

cppsp -- a transpiled language based on C++

## Install
Download the cppsp_compiler.exe or compiler the sourcecode by yourself
* Requirement:prepare your own c++ compiler and set it's folder to environment path(environment variable)
* Requirement:a 64bits c++ compiler to make sure exe can be open
* Optional: put the folder path of exe to environment

Build from source using CMake or download a release. Keep it somewhere and optionally add it to your environment variables.

## Usage
* Use cmd or other console to compiler .cppsp file:
cppsp_compiler(if not in environment path:.\cppsp_compiler.exe or c:\...\cppsp_compiler.exe) script.cppsp
* Setting c++ include/lib folder by .ini file

- Use a terminal to build .cppsp file:

`cppsp_compiler script.cppsp`

- Setting c++ include/lib folder by .ini file
include.ini:C:\...\include1,c:\...\include2
lib.ini:C:\...\lib1,c:\...\lib2
## Feature
* can compile when there is only print("hello world") in .cppsp
* can use almost c++ header by import
* can use c++ code by @inject and @function
* enable indentation and multi-line after v1.3
## Keyword
* #useclang or #usegcc : use clang++ or g++ compile command
* @command("..."): add command when compile like:-Os、-m64
* #overwrite:make @command() overwrite g++ .... or clang++ compile command like @command("g++ -Os -m64 -nostdlib -shared -o dll.dll dll.cpp") and add "*/" in the end of int main{..} but you'll need @funcion<</\*>> to make comment work
* import :import header in c++ and accept import x,y,.....
* @funcuion<<...>>: inject everything(void()、int()、bool()、even #define and using namespace) in <<...>> to the space under #include above int main()
* @inject(...) :inject everything in (...) to int main{...}
* print(): print content to console like print("12\n"," ",1," ",2.1,true,false," ")
* input(): input data to variables,but need @inject() to declare varibles
* //:comment

## Features

- Can compile with only `print("hello world")` in .cppsp
- Can use almost any C++ header by import
- Can use C++ code by @inject and @function
- Enable indentation and multi-line after v1.3

## Keywords

- `#useclang` or `#usegcc` : use `clang++` or `g++` compile command
- `@command("...")`: add command when compile like: `-Os、-m64`
- #overwrite:make @command() overwrite g++ .... or clang++ compile command like @command("g++ -Os -m64 -nostdlib -shared -o dll.dll dll.cpp") and add "*/" in the end of int main{..} but you'll need @funcion<</\*>> to make comment work
- `import`: import header in c++ and accept import x,y,.....
- @funcuion<<...>>: inject everything(void()、int()、bool()、even #define and using namespace) in <<...>> to the space under #include above int main()
- `@inject(...)`: inject everything in (...) to int main{...}
- print(): print content to console like print("12\n"," ",1," ",2.1,true,false," ")
- `input()`: input data to variables, but need `@inject()` to declare varibles
- `//`:comment

### Warning ⚠️
* Cannot accept any space/blank before keyword before v1.2!
* No multi-line before v1.3!
* @command() will never be multi-line but you can use following as an alternative

- Cannot accept any space/blank before keyword before v1.2!
- No multi-line before v1.3!
- `@command()` will never be multi-line but you can use following as an alternative:

```
@command("-f1 -f2 ..... -f5")
@command("-f6 -f7 ....-f10")
```

under #overwritender #overwrite

```
@command("g++ -Os -m64 -nostdlib -shared ")
@command(" -o dll.dll dll.cpp")
```
## Example
```cpp
```

## Examples

```
print("hello world")
```
* another exmaple:
```cpp

```
@command("-mtune=native -fomit-frame-pointer -static-libgcc -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--as-needed -s -Wl,--strip-all -Os -m64")
import iostream,vector
@function<<using namespace std;>>
Expand All @@ -57,8 +72,7 @@ input(x,y,z)
@function<<class cls{vector< string> cars = {"Volvo", "BMW", "Ford", "Mazda"};};>>
print(x+y+z)
```
* simple dll
```cpp
```
#overwrite
@command("g++ -Os -m64 -nostdlib -shared -o dll.dll dll.cpp")
@function<<extern "C" __declspec(dllexport) int add(int a, int b) { return a * b;}>>
Expand Down
Loading