Skip to content

Commit dec74de

Browse files
authored
Merge pull request #54 from codefuse-ai/lhk_dev
[feat] upload source code of godel-script language
2 parents 0cf2f65 + 3190763 commit dec74de

File tree

99 files changed

+56590
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+56590
-0
lines changed

.github/workflows/godel_build.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: GodelScript Build
2+
3+
on:
4+
push:
5+
branches: [ main, lhk_dev ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
mac-aarch64-build:
11+
runs-on: macos-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
submodules: true
16+
- name: Update Git Env
17+
run: |
18+
git config --global user.name "$(git log -n 1 --pretty=format:%an)"
19+
git config --global user.email "$(git log -n 1 --pretty=format:%ae)"
20+
- name: Build
21+
run: |
22+
cd godel-script
23+
cd godel-backend/souffle
24+
git am ../0001-init-self-used-souffle-from-public-souffle.patch
25+
cd ../..
26+
mkdir build
27+
cd build
28+
cmake ..
29+
make -j6
30+
- name: Test
31+
run: |
32+
cd godel-script
33+
./build/godel
34+
./build/godel --version
35+
./build/godel -h --color-off
36+
37+
linux-x86_64-build:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
with:
42+
submodules: true
43+
- name: Update Git Env
44+
run: |
45+
git config --global user.name "$(git log -n 1 --pretty=format:%an)"
46+
git config --global user.email "$(git log -n 1 --pretty=format:%ae)"
47+
- name: Build
48+
run: |
49+
cd godel-script
50+
cd godel-backend/souffle
51+
git am ../0001-init-self-used-souffle-from-public-souffle.patch
52+
cd ../..
53+
mkdir build
54+
cd build
55+
cmake ..
56+
make -j6
57+
- name: Test
58+
run: |
59+
cd godel-script
60+
./build/godel
61+
./build/godel --version
62+
./build/godel -h --color-off

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ build/
3434
### VS Code ###
3535
.vscode/
3636
.cloudide
37+
38+
### Bazel ###
39+
bazel-bin
40+
bazel-CodeFuse-Query
41+
bazel-out
42+
bazel-testlogs

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "godel-script/godel-backend/souffle"]
2+
path = godel-script/godel-backend/souffle
3+
url = https://github.com/souffle-lang/souffle.git

godel-script/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# build directory
2+
build
3+
cmake-build

godel-script/CMakeLists.txt

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
3+
project("GodelScript" VERSION 0.1 DESCRIPTION "GodelScript compiler")
4+
5+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
6+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
7+
8+
set(CMAKE_CXX_STANDARD 17)
9+
set(CMAKE_CXX_STANDARD_REQUIRED True)
10+
11+
if(UNIX AND NOT APPLE)
12+
set(LINUX TRUE)
13+
endif()
14+
15+
set(GODEL_FRONTEND_HDR_FILES
16+
godel-frontend/src/cli.h
17+
godel-frontend/src/engine.h
18+
godel-frontend/src/lexer.h
19+
godel-frontend/src/parse.h
20+
godel-frontend/src/semantic.h
21+
godel-frontend/src/symbol.h
22+
godel-frontend/src/ir/aggregator_inline_remark.h
23+
godel-frontend/src/ir/flatten_block.h
24+
godel-frontend/src/ir/ir_gen.h
25+
godel-frontend/src/ir/ir_context.h
26+
godel-frontend/src/ir/lir.h
27+
godel-frontend/src/ir/inst_combine.h
28+
godel-frontend/src/ir/name_mangling.h
29+
godel-frontend/src/ir/pass.h
30+
godel-frontend/src/ir/pass_manager.h
31+
godel-frontend/src/ir/remove_unused.h
32+
godel-frontend/src/error/error.h
33+
godel-frontend/src/ast/ast_node.h
34+
godel-frontend/src/ast/ast_root.h
35+
godel-frontend/src/ast/ast_visitor.h
36+
godel-frontend/src/ast/decl.h
37+
godel-frontend/src/ast/expr.h
38+
godel-frontend/src/ast/stmt.h
39+
godel-frontend/src/ast/ast_dumper.h
40+
godel-frontend/src/ast/template_extractor.h
41+
godel-frontend/src/sema/ungrounded_checker.h
42+
godel-frontend/src/sema/fact_statement_checker.h
43+
godel-frontend/src/sema/self_reference_check.h
44+
godel-frontend/src/sema/context.h
45+
godel-frontend/src/sema/global_symbol_loader.h
46+
godel-frontend/src/sema/symbol_import.h
47+
godel-frontend/src/sema/data_structure_construct.h
48+
godel-frontend/src/sema/inherit_schema.h
49+
godel-frontend/src/sema/function_declaration.h
50+
godel-frontend/src/sema/annotation_checker.h
51+
godel-frontend/src/util/util.h
52+
godel-frontend/src/package/package.h
53+
godel-frontend/src/package/module_tree.h)
54+
55+
set(GODEL_FRONTEND_SRC_FILES
56+
godel-frontend/src/cli.cpp
57+
godel-frontend/src/engine.cpp
58+
godel-frontend/src/lexer.cpp
59+
godel-frontend/src/parse.cpp
60+
godel-frontend/src/semantic.cpp
61+
godel-frontend/src/symbol.cpp
62+
godel-frontend/src/ir/aggregator_inline_remark.cpp
63+
godel-frontend/src/ir/flatten_block.cpp
64+
godel-frontend/src/ir/ir_gen.cpp
65+
godel-frontend/src/ir/ir_context.cpp
66+
godel-frontend/src/ir/lir.cpp
67+
godel-frontend/src/ir/inst_combine.cpp
68+
godel-frontend/src/ir/name_mangling.cpp
69+
godel-frontend/src/ir/pass.cpp
70+
godel-frontend/src/ir/pass_manager.cpp
71+
godel-frontend/src/ir/remove_unused.cpp
72+
godel-frontend/src/error/error.cpp
73+
godel-frontend/src/ast/ast_visitor.cpp
74+
godel-frontend/src/ast/ast_root.cpp
75+
godel-frontend/src/ast/decl.cpp
76+
godel-frontend/src/ast/expr.cpp
77+
godel-frontend/src/ast/stmt.cpp
78+
godel-frontend/src/ast/ast_dumper.cpp
79+
godel-frontend/src/ast/template_extractor.cpp
80+
godel-frontend/src/sema/ungrounded_checker.cpp
81+
godel-frontend/src/sema/fact_statement_checker.cpp
82+
godel-frontend/src/sema/self_reference_check.cpp
83+
godel-frontend/src/sema/context.cpp
84+
godel-frontend/src/sema/global_symbol_loader.cpp
85+
godel-frontend/src/sema/symbol_import.cpp
86+
godel-frontend/src/sema/data_structure_construct.cpp
87+
godel-frontend/src/sema/inherit_schema.cpp
88+
godel-frontend/src/sema/function_declaration.cpp
89+
godel-frontend/src/sema/annotation_checker.cpp
90+
godel-frontend/src/util/util.cpp
91+
godel-frontend/src/package/package.cpp
92+
godel-frontend/src/package/module_tree.cpp)
93+
94+
execute_process(COMMAND mkdir -p install)
95+
set(ENV{CC} cc)
96+
set(ENV{CXX} c++)
97+
# build bison
98+
set(BISON_PKG bison-3.8.2)
99+
execute_process(COMMAND tar -xf ${CMAKE_CURRENT_SOURCE_DIR}/godel-backend/tools/${BISON_PKG}.tar)
100+
execute_process(COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/install WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${BISON_PKG})
101+
execute_process(COMMAND make -j install WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${BISON_PKG})
102+
103+
# build flex
104+
set(FLEX_PKG flex-2.6.4)
105+
execute_process(COMMAND tar -xf ${CMAKE_CURRENT_SOURCE_DIR}/godel-backend/tools/${FLEX_PKG}.tar)
106+
execute_process(COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/install WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${FLEX_PKG})
107+
execute_process(COMMAND make -j install WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${FLEX_PKG})
108+
109+
# set variables for souffle target
110+
set(FLEX_EXECUTABLE ${CMAKE_BINARY_DIR}/install/bin/flex)
111+
set(BISON_EXECUTABLE ${CMAKE_BINARY_DIR}/install/bin/bison)
112+
113+
set(SOUFFLE_DOMAIN_64BIT ON)
114+
set(SOUFFLE_USE_CURSES OFF)
115+
set(SOUFFLE_ENABLE_TESTING OFF)
116+
117+
add_subdirectory(godel-backend/souffle)
118+
add_subdirectory(godel-backend/extension)
119+
120+
add_library(godel-frontend STATIC
121+
${GODEL_FRONTEND_SRC_FILES})
122+
123+
target_link_libraries(godel-frontend PUBLIC
124+
libsouffle souffle_ext)
125+
126+
target_include_directories(godel-frontend PUBLIC
127+
${PROJECT_SOURCE_DIR})
128+
129+
# add binary target godel
130+
add_executable(godel godel-frontend/src/main.cpp)
131+
# avoid easylogging to generate myeasylog.log automatically
132+
add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)
133+
# link static library
134+
target_link_libraries(godel
135+
PRIVATE godel-frontend)
136+
# link dynamic library
137+
target_link_libraries(godel PUBLIC
138+
libsouffle-shared souffle_ext)

godel-script/README.md

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# GödelScript
2+
3+
## Content
4+
5+
* 简介 | [Introduction](#introduction)
6+
* 文档 | [Documents](#documents)
7+
* 编译 | [Compilation](#compilation)
8+
* 用法 | [Usage](#usage)
9+
10+
## Introduction
11+
12+
GödelScript is designed for creating code analysis libraries and programs,
13+
and compiling them to soufflé more easily. With it's Object-Oriented features,
14+
it has great maintainability and readability.
15+
16+
```rust
17+
@output
18+
pub fn hello() -> string {
19+
return "Hello World!"
20+
}
21+
```
22+
23+
## Documents
24+
25+
* GödelScript Language Reference
26+
* GödelScript [Program](./docs/language-reference/program.md)
27+
* GödelScript [Type](./docs/language-reference/type.md)
28+
* GödelScript [Schema](./docs/language-reference/schemas.md)
29+
* GödelScript [Database](./docs/language-reference/databases.md)
30+
* GödelScript [Enum](./docs/language-reference/enums.md)
31+
* GödelScript [Impl](./docs/language-reference/impl.md)
32+
* GödelScript [Function](./docs/language-reference/functions.md)
33+
* GödelScript [Import](./docs/language-reference/import.md)
34+
* GödelScript [Query](./docs/language-reference/queries.md)
35+
* GödelScript [Statement](./docs/language-reference/functions.md#statement)
36+
* GödelScript [Expression](./docs/language-reference/functions.md#expression)
37+
* GödelScript [Query Example](../example)
38+
* GödelScript [Syntax Definition](./docs/syntax.md)
39+
40+
## Compilation
41+
42+
Structure of this project:
43+
44+
```
45+
.
46+
|-- docs godel-script documents
47+
|-- godel-backend godel-script backend
48+
| |-- extension godel-script souffle extension
49+
| |-- souffle souffle source code
50+
| +-- tools souffle build tools
51+
+-- godel-frontend godel-script frontend
52+
+-- src godel-frontend source code
53+
```
54+
55+
Need C++ standard at least `-std=c++17`.
56+
57+
### Apply Patch On Soufflé Submodule
58+
59+
GödelScript uses a self-modified soufflé from a much older branch of public soufflé,
60+
now we use patch to make sure it could be built successfully.
61+
62+
Use this command to apply patch:
63+
64+
```bash
65+
cd souffle
66+
git am ../../0001-init-self-used-souffle-from-public-souffle.patch
67+
```
68+
69+
Use these commands to revert:
70+
71+
```bash
72+
cd souffle
73+
git apply -R ../0001-init-self-used-souffle-from-public-souffle.patch
74+
git reset HEAD~
75+
```
76+
77+
### Build GödelScript
78+
79+
Use command below:
80+
81+
```bash
82+
mkdir build
83+
cd build
84+
cmake ..
85+
make -j
86+
```
87+
88+
After building, you'll find `build/godel` in the `build` folder.
89+
90+
## Usage
91+
92+
Use this command for help:
93+
94+
> ./build/godel -h
95+
96+
### Compile Target Soufflé
97+
98+
> ./build/godel -p {godel library directory} {input file} -s {soufflé output file} -Of
99+
100+
`-Of` is an optimization for join order, we suggest to switch it on.
101+
102+
### Directly Run Soufflé
103+
104+
> ./build/godel -p {godel library directory} {input file} -r -Of -f {database directory}
105+
106+
`-Of` is an optimization for join order, we suggest to switch it on.
107+
108+
`-r` means directly run soufflé.
109+
110+
`-v` could be used for getting verbose info.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# GödelScript Database
2+
3+
Back to [README.md](../../README.md#documents)
4+
5+
## Declaration
6+
7+
```rust
8+
database School {
9+
student: *Student,
10+
classes: *Class as "class"
11+
...
12+
}
13+
```
14+
15+
Tables in databases should be set type, which uses `*` before the type name.
16+
And the table type must be `schema`.
17+
And for table name `student`, when running soufflé directly, we read sqlite database
18+
using the same table name.
19+
20+
If the table name conflicts with a keyword, try using `as "real_table"`, and
21+
GödelScript will find the data from sqlite table `real_table`.
22+
23+
## Initializing
24+
25+
Database has a native method `fn load(dbname: string) -> Self`.
26+
The argument string must be a string literal.
27+
28+
```rust
29+
fn default_db() -> School {
30+
return School::load("example_db_school.db") // must use string literal
31+
}
32+
```
33+
34+
Then GödelScript will give you the input database.
35+
36+
## Get Schema From Database
37+
38+
It's quite easy to fetch schema data from database.
39+
For example in `Student::__all__(db: School) -> *School`,
40+
we could fetch the data by directly using `db.student`.
41+
42+
```rust
43+
impl Student {
44+
pub fn __all__(db: School) -> *Student {
45+
return db.student
46+
}
47+
}
48+
```
49+
50+
Back to [README.md](../../README.md#documents)

0 commit comments

Comments
 (0)