<!--¶
author: Ivan Ogasawara summary: This tutorial describes a brief steps in order to compile and test arx for the first time. author_gh_user: xmnlab read_time: 5 mins
publish_date: 2022-09-29¶
-->
Getting Started¶
This tutorial describes a brief steps in order to compile and test arx for the first time.
Arx relies totally on conda environment, so, first you should create a new conda environment:
$ mamba env create --file conda/dev.yaml
Note: In this tutorial we use mamba instead of conda for environment creation, but it should also works for conda as well.
It creates a new conda environment called arx.
Now, activate the new environment:
$ conda activate arx
Next, let's build the arx:
In [1]:
Copied!
!cd ../.. && make build-dev CLEAN=1
!cd ../.. && make build-dev CLEAN=1
set -ex make build ARGS="-Ddev=enabled -Db_coverage=true -Db_sanitize=address" + make build ARGS=-Ddev=enabled -Db_coverage=true -Db_sanitize=address make[1]: Entering directory '/mnt/sda1/storage/dev/arxlang/arx' bash ./scripts/optclean.sh mkdir -p build set -ex meson setup \ --prefix /home/xmn/mambaforge/envs/arx \ --libdir /home/xmn/mambaforge/envs/arx/lib \ --includedir /home/xmn/mambaforge/envs/src \ --buildtype=release \ --native-file meson.native -Ddev=enabled -Db_coverage=true -Db_sanitize=address \ build . meson compile -C build + meson setup --prefix /home/xmn/mambaforge/envs/arx --libdir /home/xmn/mambaforge/envs/arx/lib --includedir /home/xmn/mambaforge/envs/src --buildtype=release --native-file meson.native -Ddev=enabled -Db_coverage=true -Db_sanitize=address build . The Meson build system Version: 0.63.2 Source dir: /mnt/sda1/storage/dev/arxlang/arx Build dir: /mnt/sda1/storage/dev/arxlang/arx/build Build type: native build Project name: arx Project version: 1.4.0 C compiler for the host machine: clang (clang 13.0.1 "clang version 13.0.1 (https://github.com/conda-forge/clangdev-feedstock b741c7551b48482d08d2f65a791b7602c1f23c9d)") C linker for the host machine: clang ld.lld 13.0.1 C++ compiler for the host machine: clang++ (clang 13.0.1 "clang version 13.0.1 (https://github.com/conda-forge/clangdev-feedstock b741c7551b48482d08d2f65a791b7602c1f23c9d)") C++ linker for the host machine: clang++ ld.lld 13.0.1 Host machine cpu family: x86_64 Host machine cpu: x86_64 Found pkg-config: /home/xmn/mambaforge/envs/arx/bin/pkg-config (0.29.2) Run-time dependency arrow found: YES 8.0.0 Found CMake: /home/xmn/mambaforge/envs/arx/bin/cmake (3.24.2) WARNING: Ignoring LLVM CMake dependency because dynamic was requested llvm-config found: YES (/home/xmn/mambaforge/envs/arx/bin/llvm-config) 13.0.1 Run-time dependency LLVM found: YES 13.0.1 Run-time dependency cli11 found: YES 2.2.0 Run-time dependency glog found: YES 0.6.0 Run-time dependency GTest found: YES 1.11.0 Run-time dependency GMock found: YES 1.11.0 Program clang-tidy found: YES (/home/xmn/mambaforge/envs/arx/bin/clang-tidy) Build targets in project: 9 meson.build:55: WARNING: Trying to use address sanitizer on Clang with b_lundef. This will probably not work. Try setting b_lundef to false instead. arx 1.4.0 User defined options Native files: meson.native buildtype : release includedir : /home/xmn/mambaforge/envs/src libdir : /home/xmn/mambaforge/envs/arx/lib prefix : /home/xmn/mambaforge/envs/arx b_coverage : true b_sanitize : address dev : enabled Found ninja-1.11.0 at /home/xmn/mambaforge/envs/arx/bin/ninja LLVM (http://llvm.org/): LLVM version 13.0.1 Optimized build. Default target: x86_64-unknown-linux-gnu Host CPU: skylake lcov: LCOV version 1.15 genhtml: LCOV version 1.15 + meson compile -C build ninja: Entering directory `/mnt/sda1/storage/dev/arxlang/arx/build' [9/35] Compiling C++ object tests/liba...e_dev_arxlang_arx_arx_src_parser.cpp.o In file included from /mnt/sda1/storage/dev/arxlang/src/parser.cpp:12: ../src/parser.h:57:63: warning: unused parameter 'ind' [-Wunused-parameter] virtual llvm::raw_ostream& dump(llvm::raw_ostream& out, int ind) { ^ /mnt/sda1/storage/dev/arxlang/src/parser.cpp:48:10: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move] return std::move(Result); ^ /mnt/sda1/storage/dev/arxlang/src/parser.cpp:48:10: note: remove std::move call here return std::move(Result); ^~~~~~~~~~ ~ 2 warnings generated. [13/35] Compiling C++ object tests/arx...ev_arxlang_arx_tests_test_parser.cpp.o In file included from /mnt/sda1/storage/dev/arxlang/arx/tests/test_parser.cpp:9: ../tests/../src/parser.h:57:63: warning: unused parameter 'ind' [-Wunused-parameter] virtual llvm::raw_ostream& dump(llvm::raw_ostream& out, int ind) { ^ 1 warning generated. [18/35] Compiling C++ object tests/arx...v_arxlang_arx_tests_test_codegen.cpp.o In file included from /mnt/sda1/storage/dev/arxlang/arx/tests/test_codegen.cpp:2: In file included from ../src/codegen.h:27: ../src/parser.h:57:63: warning: unused parameter 'ind' [-Wunused-parameter] virtual llvm::raw_ostream& dump(llvm::raw_ostream& out, int ind) { ^ 1 warning generated. [24/35] Compiling C++ object arx.p/_mn...e_dev_arxlang_arx_arx_src_parser.cpp.o In file included from /mnt/sda1/storage/dev/arxlang/src/parser.cpp:12: ../src/parser.h:57:63: warning: unused parameter 'ind' [-Wunused-parameter] virtual llvm::raw_ostream& dump(llvm::raw_ostream& out, int ind) { ^ /mnt/sda1/storage/dev/arxlang/src/parser.cpp:48:10: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move] return std::move(Result); ^ /mnt/sda1/storage/dev/arxlang/src/parser.cpp:48:10: note: remove std::move call here return std::move(Result); ^~~~~~~~~~ ~ 2 warnings generated. [25/35] Compiling C++ object tests/lib..._dev_arxlang_arx_arx_src_codegen.cpp.o In file included from /mnt/sda1/storage/dev/arxlang/src/codegen.cpp:56: In file included from ../src/codegen.h:27: ../src/parser.h:57:63: warning: unused parameter 'ind' [-Wunused-parameter] virtual llvm::raw_ostream& dump(llvm::raw_ostream& out, int ind) { ^ /mnt/sda1/storage/dev/arxlang/src/codegen.cpp:124:64: warning: unused parameter 'Unit' [-Wunused-parameter] static auto CreateFunctionType(unsigned NumArgs, llvm::DIFile* Unit) ^ /mnt/sda1/storage/dev/arxlang/src/codegen.cpp:200:19: warning: 'CreateLoad' is deprecated: Use the version that explicitly specifies the loaded type instead [-Wdeprecated-declarations] return Builder->CreateLoad(V, Name.c_str()); ^ /home/xmn/mambaforge/envs/src/llvm/IR/IRBuilder.h:1670:3: note: 'CreateLoad' has been explicitly marked deprecated here LLVM_ATTRIBUTE_DEPRECATED(LoadInst *CreateLoad(Value *Ptr, ^ /home/xmn/mambaforge/envs/src/llvm/Support/Compiler.h:320:52: note: expanded from macro 'LLVM_ATTRIBUTE_DEPRECATED' #define LLVM_ATTRIBUTE_DEPRECATED(decl, message) [[deprecated(message)]] decl ^ /mnt/sda1/storage/dev/arxlang/src/codegen.cpp:431:34: warning: 'CreateLoad' is deprecated: Use the version that explicitly specifies the loaded type instead [-Wdeprecated-declarations] llvm::Value* CurVar = Builder->CreateLoad(Alloca, VarName.c_str()); ^ /home/xmn/mambaforge/envs/src/llvm/IR/IRBuilder.h:1670:3: note: 'CreateLoad' has been explicitly marked deprecated here LLVM_ATTRIBUTE_DEPRECATED(LoadInst *CreateLoad(Value *Ptr, ^ /home/xmn/mambaforge/envs/src/llvm/Support/Compiler.h:320:52: note: expanded from macro 'LLVM_ATTRIBUTE_DEPRECATED' #define LLVM_ATTRIBUTE_DEPRECATED(decl, message) [[deprecated(message)]] decl ^ 4 warnings generated. [33/35] Compiling C++ object arx.p/_mn..._dev_arxlang_arx_arx_src_codegen.cpp.o In file included from /mnt/sda1/storage/dev/arxlang/src/codegen.cpp:56: In file included from ../src/codegen.h:27: ../src/parser.h:57:63: warning: unused parameter 'ind' [-Wunused-parameter] virtual llvm::raw_ostream& dump(llvm::raw_ostream& out, int ind) { ^ /mnt/sda1/storage/dev/arxlang/src/codegen.cpp:124:64: warning: unused parameter 'Unit' [-Wunused-parameter] static auto CreateFunctionType(unsigned NumArgs, llvm::DIFile* Unit) ^ /mnt/sda1/storage/dev/arxlang/src/codegen.cpp:200:19: warning: 'CreateLoad' is deprecated: Use the version that explicitly specifies the loaded type instead [-Wdeprecated-declarations] return Builder->CreateLoad(V, Name.c_str()); ^ /home/xmn/mambaforge/envs/src/llvm/IR/IRBuilder.h:1670:3: note: 'CreateLoad' has been explicitly marked deprecated here LLVM_ATTRIBUTE_DEPRECATED(LoadInst *CreateLoad(Value *Ptr, ^ /home/xmn/mambaforge/envs/src/llvm/Support/Compiler.h:320:52: note: expanded from macro 'LLVM_ATTRIBUTE_DEPRECATED' #define LLVM_ATTRIBUTE_DEPRECATED(decl, message) [[deprecated(message)]] decl ^ /mnt/sda1/storage/dev/arxlang/src/codegen.cpp:431:34: warning: 'CreateLoad' is deprecated: Use the version that explicitly specifies the loaded type instead [-Wdeprecated-declarations] llvm::Value* CurVar = Builder->CreateLoad(Alloca, VarName.c_str()); ^ /home/xmn/mambaforge/envs/src/llvm/IR/IRBuilder.h:1670:3: note: 'CreateLoad' has been explicitly marked deprecated here LLVM_ATTRIBUTE_DEPRECATED(LoadInst *CreateLoad(Value *Ptr, ^ /home/xmn/mambaforge/envs/src/llvm/Support/Compiler.h:320:52: note: expanded from macro 'LLVM_ATTRIBUTE_DEPRECATED' #define LLVM_ATTRIBUTE_DEPRECATED(decl, message) [[deprecated(message)]] decl ^ 4 warnings generated. [34/35] Compiling C++ object arx.p/_mn...age_dev_arxlang_arx_arx_src_main.cpp.o In file included from /mnt/sda1/storage/dev/arxlang/src/main.cpp:23: In file included from ../src/codegen.h:27: ../src/parser.h:57:63: warning: unused parameter 'ind' [-Wunused-parameter] virtual llvm::raw_ostream& dump(llvm::raw_ostream& out, int ind) { ^ /mnt/sda1/storage/dev/arxlang/src/main.cpp:38:26: warning: unused parameter 'count' [-Wunused-parameter] auto main_open_shell(int count) { ^ /mnt/sda1/storage/dev/arxlang/src/main.cpp:49:25: warning: unused parameter 'count' [-Wunused-parameter] auto main_show_llvm(int count) { ^ /mnt/sda1/storage/dev/arxlang/src/main.cpp:60:28: warning: unused parameter 'count' [-Wunused-parameter] auto main_show_version(int count) { ^ 4 warnings generated. [35/35] Linking target arx make[1]: Leaving directory '/mnt/sda1/storage/dev/arxlang/arx'
Now, we can test the arx compiler with some test file:
In [2]:
Copied!
!cat ../../examples/test_fibonacci.arx
!cat ../../examples/test_fibonacci.arx
function fib(x): if x < 3: 1 else: fib(x-1)+fib(x-2); fib(10)
In [3]:
Copied!
!../../build/arx --show-llvm < ../../examples/test_fibonacci.arx
!../../build/arx --show-llvm < ../../examples/test_fibonacci.arx
Error: Expected function name in prototype ; ModuleID = 'arx-module' source_filename = "arx-module" target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" define double @__anon_expr() !dbg !4 { entry: ret double 1.000000e+00, !dbg !8 } !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "Arx Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3) !2 = !DIFile(filename: "", directory: ".") !3 = !{} !4 = distinct !DISubprogram(name: "__anon_expr", scope: !2, file: !2, line: 1, type: !5, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !1, retainedNodes: !3) !5 = !DISubroutineType(types: !6) !6 = !{!7} !7 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float) !8 = !DILocation(line: 1, column: 2, scope: !4)
In [4]:
Copied!
!../../build/arx --output /tmp/fibonacci < ../../examples/test_fibonacci.arx
!../../build/arx --output /tmp/fibonacci < ../../examples/test_fibonacci.arx
arx version: 1.4.1