Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 329c05f

Browse files
committed
feat: Add support for typing annotation
1 parent 2349e1a commit 329c05f

31 files changed

Lines changed: 484 additions & 197 deletions

.makim.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 1.0.0
22
env:
33
CFLAGS_EXTRA: "\
4-
-fsanitize\
4+
-fsanitize=address\
55
"
66
# use it for ASAN and LSAN
77
SAN_OPTIONS_DEFAULT: "\
@@ -19,8 +19,9 @@ env:
1919
:print_legend=1\
2020
:detect_leaks=1\
2121
"
22-
MESON_EXTRA: "-Db_coverage=true \
23-
-Doptimization=0 \
22+
MESON_EXTRA_DEBUG: "-Db_coverage=true \
23+
--optimization=0 \
24+
--debug \
2425
-Db_sanitize=address \
2526
"
2627
groups:
@@ -104,7 +105,7 @@ groups:
104105
- target: build.release
105106
args:
106107
build-type: "debug"
107-
meson-extra: {{ env.MESON_EXTRA }}
108+
meson-extra: {{ env.MESON_EXTRA_DEBUG }}
108109
clean: {{ args.clean }}
109110
asan-options: {{ env.SAN_OPTIONS_DEFAULT }}
110111
lsan-options: {{ env.SAN_OPTIONS_DEFAULT }}
@@ -120,7 +121,7 @@ groups:
120121
- target: build.release
121122
args:
122123
build-type: "debug"
123-
meson-extra: {{ env.MESON_EXTRA }} -Ddev=enabled
124+
meson-extra: {{ env.MESON_EXTRA_DEBUG }} -Ddev=enabled
124125
clean: {{ args.clean }}
125126
asan-options: {{ env.SAN_OPTIONS_DEFAULT }}
126127
lsan-options: {{ env.SAN_OPTIONS_DEFAULT }}
@@ -231,7 +232,7 @@ groups:
231232
232233
if [[ "{{ args.debug }}" == "True" ]]; then
233234
GDB="gdb --args"
234-
DEBUG_FLAGS="-g"
235+
DEBUG_FLAGS="-Og"
235236
fi
236237
237238
TEST_DIR_PATH="./tests"
@@ -261,7 +262,7 @@ groups:
261262
print_header "${test_name}"
262263
OBJECT_FILE="${TMP_DIR}/${test_name}.o"
263264
264-
${ARX} --output "${OBJECT_FILE}" --input "examples/${test_name}.arx"
265+
${ARX} --output "${OBJECT_FILE}" --input "examples/${test_name}.arx --build-lib"
265266
266267
set -x
267268
clang++ \
@@ -381,4 +382,5 @@ groups:
381382
gdb \
382383
--args build/arx \
383384
--input `pwd`/examples/{{ args.test_name }}.arx \
385+
--build-lib \
384386
--output "/tmp/{{ args.test_name }}" {{ args.meson_extra }}

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,14 @@ source:
188188

189189
As this project uses the `squash and merge` strategy, ensure to apply
190190
the commit message format to the PR's title.
191+
192+
193+
## Development Tips and Resources
194+
195+
### Memory Leak
196+
197+
If you are facing any memory leak issue, please consider to check the following
198+
pages:
199+
200+
- https://github.com/google/sanitizers/wiki/AddressSanitizerFlags
201+
- https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer

conda/dev-linux-64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ dependencies:
4040
- lcov
4141
- mkdocs
4242
- mkdocs-jupyter
43-
- nodejs
43+
- nodejs >=18
4444
- pre-commit
4545
- pip
4646
- pip:

examples/average.arx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
function average(x y):
2-
(x + y) * 0.5;
1+
fn average(x: float, y: float) -> float:
2+
return (x + y) * 0.5;

examples/constant.arx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
function get_constant(x):
2-
x;
1+
fn get_constant(x: float) -> float:
2+
return x;

examples/fibonacci.arx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function fib(x):
2-
if x < 3:
3-
1
1+
fn fib(x: float) -> float:
2+
if x <= 1:
3+
return x;
44
else:
5-
fib(x-1)+fib(x-2)
5+
return fib(x-1)+fib(x-2);

examples/print-star.arx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
extern putchard(char);
1+
extern putchard(char) -> void;
22

3-
function print_star(n):
3+
fn print_star(n: float) -> void:
44
for i = 1, i < n, 1.0 in
5-
putchard(42); # ascii 42 = '*'
5+
return putchard(42); # ascii 42 = '*'

examples/sum.arx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
function sum(a b):
2-
a + b;
1+
fn sum(a: float, b: float) -> float:
2+
return a + b;

meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ project('arx', 'cpp', 'c',
22
license : 'Apache-2.0',
33
version : '1.6.0', # semantic-release
44
default_options : [
5-
'warning_level=everything',
5+
#'warning_level=everything',
6+
'warning_level=1',
67
'cpp_std=c++20',
78
]
89
)

src/codegen/arx-llvm.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <string>
12

23
#include <llvm/IR/DIBuilder.h> // for DIBuilder
34
#include <llvm/IR/IRBuilder.h> // for IRBuilder
@@ -22,5 +23,25 @@ llvm::Type* ArxLLVM::DOUBLE_TYPE;
2223
llvm::Type* ArxLLVM::FLOAT_TYPE;
2324
llvm::Type* ArxLLVM::INT8_TYPE;
2425
llvm::Type* ArxLLVM::INT32_TYPE;
26+
llvm::Type* ArxLLVM::VOID_TYPE;
27+
28+
auto ArxLLVM::get_data_type(std::string type_name) -> llvm::Type* {
29+
if (type_name == "float") {
30+
return ArxLLVM::FLOAT_TYPE;
31+
} else if (type_name == "double") {
32+
return ArxLLVM::DOUBLE_TYPE;
33+
} else if (type_name == "int8") {
34+
return ArxLLVM::INT8_TYPE;
35+
} else if (type_name == "int32") {
36+
return ArxLLVM::INT32_TYPE;
37+
} else if (type_name == "char") {
38+
return ArxLLVM::INT8_TYPE;
39+
} else if (type_name == "void") {
40+
return ArxLLVM::VOID_TYPE;
41+
}
42+
43+
llvm::errs() << "[EE] type_name not valid.\n";
44+
return nullptr;
45+
}
2546

2647
extern bool IS_BUILD_LIB = false; // default value

0 commit comments

Comments
 (0)