Skip to content

Commit

Permalink
Merge pull request #60 from ValKmjolnir/develop
Browse files Browse the repository at this point in the history
✨ create a demo formater
  • Loading branch information
ValKmjolnir authored Jan 11, 2025
2 parents 4035c6c + 89826da commit fc2bb80
Show file tree
Hide file tree
Showing 30 changed files with 1,103 additions and 329 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ jobs:
git push -f origin next_macOS
- name: Build
run: |
make -j4
cd module
make all -j4
cd ..
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release
make -j6
- name: Test
run: make test
- name: Package
Expand All @@ -33,7 +31,7 @@ jobs:
prerelease: true
draft: false
files: |
nasal-Darwin.tar
nasal-macOS-aarch64.tar
linux-x86_64-build:
runs-on: ubuntu-latest
Expand All @@ -46,10 +44,8 @@ jobs:
git push -f origin next_linux_x86_64
- name: Build
run: |
make -j4
cd module
make all -j4
cd ..
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release
make -j6
- name: Test
run: make test
- name: Package
Expand All @@ -62,4 +58,4 @@ jobs:
prerelease: true
draft: false
files: |
nasal-Linux.tar
nasal-linux-x86_64.tar
12 changes: 4 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ jobs:
- uses: actions/checkout@v4
- name: Build
run: |
make -j4
cd module
make all -j4
cd ..
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release
make -j6
- name: Test
run: make test

Expand All @@ -27,9 +25,7 @@ jobs:
- uses: actions/checkout@v4
- name: Build
run: |
make -j4
cd module
make all -j4
cd ..
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release
make -j6
- name: Test
run: make test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ cmake-windows-*
*.out
*.app
nasal
nasal-format
nasal.exe
nasal-format.exe

# Visual Studio specific
*.sln
Expand Down
22 changes: 18 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-Wshadow -Wall")

add_compile_options(-fPIC)
# MSVC does not need -fPIC
if (NOT MSVC)
add_compile_options(-fPIC)
endif()

# MSVC needs this command option to really enable utf-8 output
if (MSVC)
add_compile_options(/utf-8)
Expand All @@ -19,9 +23,6 @@ if (APPLE)
add_compile_options(-mmacosx-version-min=10.15)
endif()

# generate release executables
set(CMAKE_BUILD_TYPE "Release")

# build nasal used object
set(NASAL_OBJECT_SOURCE_FILE
${CMAKE_SOURCE_DIR}/src/cli/cli.cpp
Expand All @@ -40,6 +41,7 @@ set(NASAL_OBJECT_SOURCE_FILE
${CMAKE_SOURCE_DIR}/src/util/fs.cpp
${CMAKE_SOURCE_DIR}/src/util/util.cpp
${CMAKE_SOURCE_DIR}/src/ast_dumper.cpp
${CMAKE_SOURCE_DIR}/src/ast_format.cpp
${CMAKE_SOURCE_DIR}/src/ast_visitor.cpp
${CMAKE_SOURCE_DIR}/src/nasal_ast.cpp
${CMAKE_SOURCE_DIR}/src/nasal_codegen.cpp
Expand All @@ -61,12 +63,18 @@ target_include_directories(nasal-object PRIVATE ${CMAKE_SOURCE_DIR}/src)
add_executable(nasal ${CMAKE_SOURCE_DIR}/src/main.cpp)
target_link_libraries(nasal nasal-object)

# build nasal-format
add_executable(nasal-format ${CMAKE_SOURCE_DIR}/src/format.cpp)
target_link_libraries(nasal-format nasal-object)

# link ldl and lpthread
if(NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
target_link_libraries(nasal dl)
target_link_libraries(nasal pthread)
target_link_libraries(nasal-format pthread)
endif()
target_include_directories(nasal PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(nasal-format PRIVATE ${CMAKE_SOURCE_DIR}/src)

# copy nasal from build dir to the outside dir
if(NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
Expand All @@ -76,6 +84,12 @@ if(NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
${CMAKE_SOURCE_DIR}/build/nasal
${CMAKE_SOURCE_DIR}/nasal
)
add_custom_command(
TARGET nasal-format POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/build/nasal-format
${CMAKE_SOURCE_DIR}/nasal-format
)
endif()

# build module
Expand Down
2 changes: 1 addition & 1 deletion doc/windows-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Valid on powershell:
mkdir cmake-windows-msvc
cd cmake-windows-msvc
cmake .. -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 17 2022"
MSbuild.exe nasal.sln /p:Configuration=Release /p:Platform=x64
MSBuild.exe nasal.sln /p:Configuration=Release /p:Platform=x64
```

## MingW-W64
Expand Down
10 changes: 5 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ test:
@ ./nasal -t -d test/regex_test.nas
@ ./nasal -t -d test/replace_test.nas
@ ./nasal -e test/scalar.nas hello world
@ ./nasal test/subprocess_test.nas
@ ./nasal -e test/trait.nas
@ ./nasal -t test/subprocess_test.nas
@ ./nasal -t test/trait.nas
@ ./nasal -t -d test/turingmachine.nas
@ ./nasal -d test/wavecollapse.nas
@ ./nasal -d test/wavecity.nas
@ ./nasal test/word_collector.nas test/md5compare.nas
@ ./nasal -t -d test/wavecollapse.nas
@ ./nasal -t -d test/wavecity.nas
@ ./nasal -t test/word_collector.nas test/md5compare.nas
@ ./nasal -t -d test/ycombinator.nas
12 changes: 6 additions & 6 deletions module/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ ifndef OS
OS = $(shell uname)
endif
ifeq ($(OS), Darwin)
CXXFLAGS = -std=$(STD) -c -O3 -fPIC -mmacosx-version-min=10.15
CXXFLAGS = -std=$(STD) -c -O3 -fPIC -mmacosx-version-min=10.15 -I ../src
else
CXXFLAGS = -std=$(STD) -c -O3 -fPIC
CXXFLAGS = -std=$(STD) -c -O3 -fPIC -I ../src
endif

all: $(dynamic_libs_so)
Expand All @@ -29,7 +29,7 @@ libfib.so: fib.cpp $(used_header) $(used_object)
@ rm fib.o
libfib.dll: fib.cpp $(used_header) $(used_object)
@ echo [Compiling] libfib.dll
@ $(CXX) -std=$(STD) -c -O3 fib.cpp -fPIC -o fib.o
@ $(CXX) -std=$(STD) -c -O3 fib.cpp -fPIC -o fib.o -I ../src
@ $(CXX) -shared -o libfib.dll fib.o $(used_object) -static
@ del fib.o

Expand All @@ -40,7 +40,7 @@ libkey.so: keyboard.cpp $(used_header) $(used_object)
@ rm keyboard.o
libkey.dll: keyboard.cpp $(used_header) $(used_object)
@ echo [Compiling] libkey.dll
@ $(CXX) -std=$(STD) -c -O3 keyboard.cpp -fPIC -o keyboard.o -static
@ $(CXX) -std=$(STD) -c -O3 keyboard.cpp -fPIC -o keyboard.o -static -I ../src
@ $(CXX) -shared -o libkey.dll keyboard.o $(used_object) -static
@ del keyboard.o

Expand All @@ -51,7 +51,7 @@ libnasock.so: nasocket.cpp $(used_header) $(used_object)
@ rm nasocket.o
libnasock.dll: nasocket.cpp $(used_header) $(used_object)
@ echo [Compiling] libnasock.dll
@ $(CXX) -std=$(STD) -c -O3 nasocket.cpp -fPIC -o nasocket.o -lwsock32 -static
@ $(CXX) -std=$(STD) -c -O3 nasocket.cpp -fPIC -I ../src -o nasocket.o -lwsock32 -static
@ $(CXX) -shared -o libnasock.dll nasocket.o $(used_object) -lwsock32 -static
@ del nasocket.o

Expand All @@ -62,7 +62,7 @@ libmat.so: matrix.cpp $(used_header) $(used_object)
@ rm matrix.o
libmat.dll: matrix.cpp $(used_header) $(used_object)
@ echo [Compiling] libmat.dll
@ $(CXX) -std=$(STD) -c -O3 matrix.cpp -fPIC -o matrix.o -static
@ $(CXX) -std=$(STD) -c -O3 matrix.cpp -fPIC -I ../src -o matrix.o -static
@ $(CXX) -shared -o libmat.dll matrix.o $(used_object) -static
@ del matrix.o

Expand Down
2 changes: 1 addition & 1 deletion src/ast_dumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ast_dumper: public ast_visitor {
if (indent.size() && indent.back()=="") {
indent.back() = "├──";
}
for(const auto& i : indent) {
for (const auto& i : indent) {
std::cout << i;
}
}
Expand Down
Loading

0 comments on commit fc2bb80

Please sign in to comment.