Skip to content

Commit

Permalink
Update 5 (#5)
Browse files Browse the repository at this point in the history
- split README.md
- extended script converter to transcompiler with optimization
  • Loading branch information
SebastianBach committed Mar 29, 2024
1 parent d596780 commit 57c34e7
Show file tree
Hide file tree
Showing 30 changed files with 1,776 additions and 476 deletions.
152 changes: 2 additions & 150 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Coverage: https://sebastianbach.github.io/full-stack/coverage.html

# About

You have a simple, nice, useful C++ function. How do you make it available to users?
You have a simple, nice, useful C++ function. How do you make it available to consumers?

# Content

Expand Down Expand Up @@ -178,152 +178,4 @@ See also ```.github/workflows/build.yml```.

# Usage

## Command Line Tool *title_case*

This command line tool takes the given command line argument, converts the data, and prints the result to ```std::cout```.

```
title_case "this is some text"
# prints
This is Some Text
```

## Command Line Tool *title_case_console*

Interactive command line tool. Enter the text to convert or "exit" to end the program.

## Command Line Tool *title_case_files*

The first command line argument is the file to read the data from, the second is the file to save the result to.

```sh
title_case_file source_file.txt target_file.txt
```

## Web App

Start the ```web.py``` script by providing the location of the resource files and the folder containing the ```title_case``` tool.

```sh
python web.py C:\web\resources C:\build\product
```

Open ```localhost:5000``` for a synchronous web app. Open ```localhost:5000/interactive``` for an asynchronous web app.

## Container

Build the *docker* image with:

```sh
docker build --tag title-case-web .
```

The multi-stage build process will build the ```title_case``` tool and copy all necessary files.


To start the container, run:

```sh
docker run --rm -it -p 5000:5000 title-case-web
```

Open ```localhost:5000``` for a synchronous web app. Open ```localhost:5000/interactive``` for an asynchronous web app.


## WebAssembly

WebAssembly requires to access the HTML document via a web server. A simple server can be started with Python:

```sh
python -m http.server
```

Open ```http://localhost:8000/``` to start the WebAssembly app.


## Scripting Language

The domain-specific scripting language is a simple language designed to perform basic tasks. The language consists of five commands:

| Command | Operand (optional) | Description |
| --- | --- | --- |
| ```text``` | *text to load and store in memory* | Stores the given text in the program's memory. |
| ```process``` | - | Processes the text in memory. |
| ```print``` | - | Prints the text in memory to the screen. |
| ```load``` | *path to text file* | Reads the specified text file and stores the text in memory. |
| ```save``` | *path to text file* | Saves the text in memory to the specified text file. |

An example program is:

```
text this is a headline
process
print
```

This will print ```This Is a Headline```.

### Command Line Tool *console*

The scripting **console** allows to enter and execute code. The console application can be closed by entering ```exit``` or pressing ```CTRL+C```.

### Command Line Tool *interpreter*

The **interpreter** loads and executes a script stored in the specified source file.

```sh
interpreter script.txt
```

### Command Line Tool *compiler* & *runtime*

The **compiler** loads a source file and generates byte-code, that can be executed by the **runtime**.

```sh
compiler script.txt bytecode.code

runtime bytecode.code
```

### Command Line Tool *converter*

The **converter** loads a source file and generates equivalent C++ or Python source code.
In Python the generated code uses the ```text_conversion``` module, in C++ the generated code uses the static library.

```sh
converter script.txt python_script.py py
```

The arguments are:

* Path to the script source file.
* Path to the target file to create.
* The target language, either ```py``` for Python or ```cpp``` for C++.


## Java Command Line Tool

Execute the command line tool (JAR) like this:

```sh
java -jar text_conversion.jar "this is a headline"
```

Make sure the ```libjava_text_conversion``` shared library can be found by Java. Set the command line argument ```java.library.path``` if needed.

## Jupyter Notebook

Start the Jupyter Notebook by simply running the ```start_notebook.sh``` script. It will start the notebook server with the notebook selected.

## Assembly Command Line Tool

The command line tool written in assembly is used like this:

```shell
title_case "this is a headline"

# will print
# Input: this is a headline
# Output: This Is a Headline
```
See the [user guide](user_guide.md) on how to use the included software.
59 changes: 59 additions & 0 deletions scripts/test_transcompiler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
echo test transcompiler

cd ..

cd build
cmake -DCMAKE_BUILD_TYPE=Release -DADD_SCRIPT_TOOLS=ON -DADD_PYTHON_MODULE=ON ..

cmake --build . -j --config Release
ctest -C Release
cmake --install .

cd temp
mkdir test_transcompiler
cd test_transcompiler


mkdir cpp
cd cpp

./../../../src/script_transcompiler/transcompiler "../../../../src/script_resources/script_test.txt" "result.cpp" "cpp"

g++ result.cpp -o transcompiler_result -ltext_conversion -L../../../product/lib/lib -I../../../product/lib/header

echo run binary:

./transcompiler_result


cd ..
mkdir intermediate
cd intermediate

./../../../src/script_transcompiler/transcompiler "../../../../src/script_resources/script_test.txt" "result.txt" "i"


cd ..
mkdir py
cd py

./../../../src/script_transcompiler/transcompiler "../../../../src/script_resources/script_test.txt" "result.py" "py"

echo run python script:

export PYTHONPATH=$PYTHONPATH:../../../product/python
python3 result.py

cd ..
mkdir linux_x86_64
cd linux_x86_64

echo build linux_x86_64

./../../../src/script_transcompiler/transcompiler "../../../../src/script_resources/script_test.txt" "result.s" "linux_x86_64"

gcc -o result result.s ../../../product/rust/libtext_conversion_c.a -m64 -lc -nostartfiles

echo run binary from assembly:

./result
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_subdirectory(lib)
add_subdirectory(lib_resources)
add_subdirectory(test_lib)
add_subdirectory(lib_c)
add_subdirectory(test_lib_c)

if(ADD_ASSEMBLY_PROGRAM)
add_subdirectory(asm)
Expand Down Expand Up @@ -41,12 +42,11 @@ if(ADD_SCRIPT_TOOLS)
add_subdirectory(script_interpreter)
add_subdirectory(script_compiler)
add_subdirectory(script_runtime)
add_subdirectory(script_converter)
add_subdirectory(script_transcompiler)
add_subdirectory(script_ide)
endif()

if(ADD_RUST_APP)
add_subdirectory(test_lib_c)
add_subdirectory(rust_cmdl)
endif()

Expand Down
8 changes: 6 additions & 2 deletions src/asm/build_and_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ if [ "$TARGET" = "Release" ]; then

elif [ "$TARGET" = "Debug" ]; then

echo "-> build debug and run gdb"
echo "-> build debug"
echo ""

gcc -o $BUILD_FOLDER/$BINARY $SOURCE_FILE $LIB_TITLE_CASE -nostartfiles -no-pie -g -lc -lstdc++

if [ "$RUN" = "r-> un" ]; then
if [ "$RUN" = "run" ]; then
echo "-> debug $BINARY";
echo "---------------------------------"
gdb --args $BUILD_FOLDER/$BINARY "$TEST_ARG"
echo "---------------------------------"
fi

else
Expand Down
1 change: 0 additions & 1 deletion src/asm/linux_x86_64/tool.s
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ _start:
# rax: length of the string
string_length:
xor %rcx, %rcx # clear rcx, which will hold the length
xor %rax, %rax # clear rax, which will be used for the null terminator comparison

.next_char:
cmpb $0, (%rsi, %rcx) # compare to null terminator
Expand Down
4 changes: 3 additions & 1 deletion src/lib_resources/BUILD.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Commit: @GIT_COMMIT_ID@

@CMAKE_SYSTEM_NAME@ - @CMAKE_SYSTEM_PROCESSOR@
@CURRENT_DATE@ - @CURRENT_TIME@

@CMAKE_SYSTEM@
@CMAKE_SYSTEM@
7 changes: 7 additions & 0 deletions src/lib_resources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d")
string(TIMESTAMP CURRENT_TIME "%H:%M:%S")

execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_ID
OUTPUT_STRIP_TRAILING_WHITESPACE
)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/BUILD.txt
${CMAKE_INSTALL_PREFIX}/product/lib/BUILD.txt
@ONLY)
Expand Down
57 changes: 0 additions & 57 deletions src/script_converter/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 57c34e7

Please sign in to comment.