Skip to content

[feat] upload source code of godel-script language #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 25, 2024
Merged
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
62 changes: 62 additions & 0 deletions .github/workflows/godel_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: GodelScript Build

on:
push:
branches: [ main, lhk_dev ]
pull_request:
branches: [ main ]

jobs:
mac-aarch64-build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Update Git Env
run: |
git config --global user.name "$(git log -n 1 --pretty=format:%an)"
git config --global user.email "$(git log -n 1 --pretty=format:%ae)"
- name: Build
run: |
cd godel-script
cd godel-backend/souffle
git am ../0001-init-self-used-souffle-from-public-souffle.patch
cd ../..
mkdir build
cd build
cmake ..
make -j6
- name: Test
run: |
cd godel-script
./build/godel
./build/godel --version
./build/godel -h --color-off

linux-x86_64-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Update Git Env
run: |
git config --global user.name "$(git log -n 1 --pretty=format:%an)"
git config --global user.email "$(git log -n 1 --pretty=format:%ae)"
- name: Build
run: |
cd godel-script
cd godel-backend/souffle
git am ../0001-init-self-used-souffle-from-public-souffle.patch
cd ../..
mkdir build
cd build
cmake ..
make -j6
- name: Test
run: |
cd godel-script
./build/godel
./build/godel --version
./build/godel -h --color-off
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ build/
### VS Code ###
.vscode/
.cloudide

### Bazel ###
bazel-bin
bazel-CodeFuse-Query
bazel-out
bazel-testlogs
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "godel-script/godel-backend/souffle"]
path = godel-script/godel-backend/souffle
url = https://github.com/souffle-lang/souffle.git
3 changes: 3 additions & 0 deletions godel-script/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# build directory
build
cmake-build
138 changes: 138 additions & 0 deletions godel-script/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
cmake_minimum_required(VERSION 3.1)

project("GodelScript" VERSION 0.1 DESCRIPTION "GodelScript compiler")

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()

set(GODEL_FRONTEND_HDR_FILES
godel-frontend/src/cli.h
godel-frontend/src/engine.h
godel-frontend/src/lexer.h
godel-frontend/src/parse.h
godel-frontend/src/semantic.h
godel-frontend/src/symbol.h
godel-frontend/src/ir/aggregator_inline_remark.h
godel-frontend/src/ir/flatten_block.h
godel-frontend/src/ir/ir_gen.h
godel-frontend/src/ir/ir_context.h
godel-frontend/src/ir/lir.h
godel-frontend/src/ir/inst_combine.h
godel-frontend/src/ir/name_mangling.h
godel-frontend/src/ir/pass.h
godel-frontend/src/ir/pass_manager.h
godel-frontend/src/ir/remove_unused.h
godel-frontend/src/error/error.h
godel-frontend/src/ast/ast_node.h
godel-frontend/src/ast/ast_root.h
godel-frontend/src/ast/ast_visitor.h
godel-frontend/src/ast/decl.h
godel-frontend/src/ast/expr.h
godel-frontend/src/ast/stmt.h
godel-frontend/src/ast/ast_dumper.h
godel-frontend/src/ast/template_extractor.h
godel-frontend/src/sema/ungrounded_checker.h
godel-frontend/src/sema/fact_statement_checker.h
godel-frontend/src/sema/self_reference_check.h
godel-frontend/src/sema/context.h
godel-frontend/src/sema/global_symbol_loader.h
godel-frontend/src/sema/symbol_import.h
godel-frontend/src/sema/data_structure_construct.h
godel-frontend/src/sema/inherit_schema.h
godel-frontend/src/sema/function_declaration.h
godel-frontend/src/sema/annotation_checker.h
godel-frontend/src/util/util.h
godel-frontend/src/package/package.h
godel-frontend/src/package/module_tree.h)

set(GODEL_FRONTEND_SRC_FILES
godel-frontend/src/cli.cpp
godel-frontend/src/engine.cpp
godel-frontend/src/lexer.cpp
godel-frontend/src/parse.cpp
godel-frontend/src/semantic.cpp
godel-frontend/src/symbol.cpp
godel-frontend/src/ir/aggregator_inline_remark.cpp
godel-frontend/src/ir/flatten_block.cpp
godel-frontend/src/ir/ir_gen.cpp
godel-frontend/src/ir/ir_context.cpp
godel-frontend/src/ir/lir.cpp
godel-frontend/src/ir/inst_combine.cpp
godel-frontend/src/ir/name_mangling.cpp
godel-frontend/src/ir/pass.cpp
godel-frontend/src/ir/pass_manager.cpp
godel-frontend/src/ir/remove_unused.cpp
godel-frontend/src/error/error.cpp
godel-frontend/src/ast/ast_visitor.cpp
godel-frontend/src/ast/ast_root.cpp
godel-frontend/src/ast/decl.cpp
godel-frontend/src/ast/expr.cpp
godel-frontend/src/ast/stmt.cpp
godel-frontend/src/ast/ast_dumper.cpp
godel-frontend/src/ast/template_extractor.cpp
godel-frontend/src/sema/ungrounded_checker.cpp
godel-frontend/src/sema/fact_statement_checker.cpp
godel-frontend/src/sema/self_reference_check.cpp
godel-frontend/src/sema/context.cpp
godel-frontend/src/sema/global_symbol_loader.cpp
godel-frontend/src/sema/symbol_import.cpp
godel-frontend/src/sema/data_structure_construct.cpp
godel-frontend/src/sema/inherit_schema.cpp
godel-frontend/src/sema/function_declaration.cpp
godel-frontend/src/sema/annotation_checker.cpp
godel-frontend/src/util/util.cpp
godel-frontend/src/package/package.cpp
godel-frontend/src/package/module_tree.cpp)

execute_process(COMMAND mkdir -p install)
set(ENV{CC} cc)
set(ENV{CXX} c++)
# build bison
set(BISON_PKG bison-3.8.2)
execute_process(COMMAND tar -xf ${CMAKE_CURRENT_SOURCE_DIR}/godel-backend/tools/${BISON_PKG}.tar)
execute_process(COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/install WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${BISON_PKG})
execute_process(COMMAND make -j install WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${BISON_PKG})

# build flex
set(FLEX_PKG flex-2.6.4)
execute_process(COMMAND tar -xf ${CMAKE_CURRENT_SOURCE_DIR}/godel-backend/tools/${FLEX_PKG}.tar)
execute_process(COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/install WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${FLEX_PKG})
execute_process(COMMAND make -j install WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${FLEX_PKG})

# set variables for souffle target
set(FLEX_EXECUTABLE ${CMAKE_BINARY_DIR}/install/bin/flex)
set(BISON_EXECUTABLE ${CMAKE_BINARY_DIR}/install/bin/bison)

set(SOUFFLE_DOMAIN_64BIT ON)
set(SOUFFLE_USE_CURSES OFF)
set(SOUFFLE_ENABLE_TESTING OFF)

add_subdirectory(godel-backend/souffle)
add_subdirectory(godel-backend/extension)

add_library(godel-frontend STATIC
${GODEL_FRONTEND_SRC_FILES})

target_link_libraries(godel-frontend PUBLIC
libsouffle souffle_ext)

target_include_directories(godel-frontend PUBLIC
${PROJECT_SOURCE_DIR})

# add binary target godel
add_executable(godel godel-frontend/src/main.cpp)
# avoid easylogging to generate myeasylog.log automatically
add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)
# link static library
target_link_libraries(godel
PRIVATE godel-frontend)
# link dynamic library
target_link_libraries(godel PUBLIC
libsouffle-shared souffle_ext)
110 changes: 110 additions & 0 deletions godel-script/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# GödelScript

## Content

* 简介 | [Introduction](#introduction)
* 文档 | [Documents](#documents)
* 编译 | [Compilation](#compilation)
* 用法 | [Usage](#usage)

## Introduction

GödelScript is designed for creating code analysis libraries and programs,
and compiling them to soufflé more easily. With it's Object-Oriented features,
it has great maintainability and readability.

```rust
@output
pub fn hello() -> string {
return "Hello World!"
}
```

## Documents

* GödelScript Language Reference
* GödelScript [Program](./docs/language-reference/program.md)
* GödelScript [Type](./docs/language-reference/type.md)
* GödelScript [Schema](./docs/language-reference/schemas.md)
* GödelScript [Database](./docs/language-reference/databases.md)
* GödelScript [Enum](./docs/language-reference/enums.md)
* GödelScript [Impl](./docs/language-reference/impl.md)
* GödelScript [Function](./docs/language-reference/functions.md)
* GödelScript [Import](./docs/language-reference/import.md)
* GödelScript [Query](./docs/language-reference/queries.md)
* GödelScript [Statement](./docs/language-reference/functions.md#statement)
* GödelScript [Expression](./docs/language-reference/functions.md#expression)
* GödelScript [Query Example](../example)
* GödelScript [Syntax Definition](./docs/syntax.md)

## Compilation

Structure of this project:

```
.
|-- docs godel-script documents
|-- godel-backend godel-script backend
| |-- extension godel-script souffle extension
| |-- souffle souffle source code
| +-- tools souffle build tools
+-- godel-frontend godel-script frontend
+-- src godel-frontend source code
```

Need C++ standard at least `-std=c++17`.

### Apply Patch On Soufflé Submodule

GödelScript uses a self-modified soufflé from a much older branch of public soufflé,
now we use patch to make sure it could be built successfully.

Use this command to apply patch:

```bash
cd souffle
git am ../../0001-init-self-used-souffle-from-public-souffle.patch
```

Use these commands to revert:

```bash
cd souffle
git apply -R ../0001-init-self-used-souffle-from-public-souffle.patch
git reset HEAD~
```

### Build GödelScript

Use command below:

```bash
mkdir build
cd build
cmake ..
make -j
```

After building, you'll find `build/godel` in the `build` folder.

## Usage

Use this command for help:

> ./build/godel -h

### Compile Target Soufflé

> ./build/godel -p {godel library directory} {input file} -s {soufflé output file} -Of

`-Of` is an optimization for join order, we suggest to switch it on.

### Directly Run Soufflé

> ./build/godel -p {godel library directory} {input file} -r -Of -f {database directory}

`-Of` is an optimization for join order, we suggest to switch it on.

`-r` means directly run soufflé.

`-v` could be used for getting verbose info.
50 changes: 50 additions & 0 deletions godel-script/docs/language-reference/databases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# GödelScript Database

Back to [README.md](../../README.md#documents)

## Declaration

```rust
database School {
student: *Student,
classes: *Class as "class"
...
}
```

Tables in databases should be set type, which uses `*` before the type name.
And the table type must be `schema`.
And for table name `student`, when running soufflé directly, we read sqlite database
using the same table name.

If the table name conflicts with a keyword, try using `as "real_table"`, and
GödelScript will find the data from sqlite table `real_table`.

## Initializing

Database has a native method `fn load(dbname: string) -> Self`.
The argument string must be a string literal.

```rust
fn default_db() -> School {
return School::load("example_db_school.db") // must use string literal
}
```

Then GödelScript will give you the input database.

## Get Schema From Database

It's quite easy to fetch schema data from database.
For example in `Student::__all__(db: School) -> *School`,
we could fetch the data by directly using `db.student`.

```rust
impl Student {
pub fn __all__(db: School) -> *Student {
return db.student
}
}
```

Back to [README.md](../../README.md#documents)
Loading