Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #79 from seq-lang/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
arshajii committed Nov 21, 2019
2 parents cf00cbd + 854cb81 commit f4b2e4a
Show file tree
Hide file tree
Showing 119 changed files with 10,873 additions and 3,994 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -46,6 +46,7 @@ Thumbs.db
#######################
.idea
.mypy_cache
.vscode

# Doxygen #
###########
Expand All @@ -59,3 +60,7 @@ dox
*.dSYM
*.conflicts
.merlin

# Testing playground #
######################
scratch.seq
23 changes: 13 additions & 10 deletions .travis.yml
Expand Up @@ -75,24 +75,24 @@ install:
- cd -

# install Boehm GC:
- wget -c https://github.com/ivmai/bdwgc/releases/download/v7.6.12/gc-7.6.12.tar.gz -O - | tar -xz
- cd gc-7.6.12
- wget -c https://github.com/ivmai/libatomic_ops/releases/download/v7.6.10/libatomic_ops-7.6.10.tar.gz -O - | tar -xz
- mv libatomic_ops-7.6.10 libatomic_ops
- wget -c https://github.com/ivmai/bdwgc/releases/download/v8.0.4/gc-8.0.4.tar.gz -O - | tar -xz
- cd gc-8.0.4
- mkdir release
- |
./configure CFLAGS="-fPIC" --enable-threads=posix \
--enable-cplusplus \
--enable-thread-local-alloc \
--enable-large-config
--enable-large-config \
--prefix=`pwd`/release
- make LDFLAGS="-static"
- make check
- sudo make install
- make install
- cd -

# install htslib:
- wget -c https://github.com/samtools/htslib/releases/download/1.9/htslib-1.9.tar.bz2 -O - | tar -xj
- cd htslib-1.9
- ./configure CFLAGS="-fPIC"
- ./configure CFLAGS="-fPIC" --disable-libcurl
- make
- sudo make install
- cd -
Expand All @@ -102,9 +102,11 @@ install:
- sudo pip3 install wheel sphinx sphinx-rtd-theme breathe exhale

before_script:
- export SEQ_PATH="${TRAVIS_BUILD_DIR}/stdlib"
- export PYTHONPATH="${TRAVIS_BUILD_DIR}/test/python"
- export LDFLAGS="-L/usr/local/lib"
- export GCLIB=$(realpath gc-8.0.4/release/lib/libgc.a)
- export CPATH=`pwd`/gc-8.0.4/release/include:${CPATH}
- export SEQ_PYTHON=$(python3 test/python/find-python-library.py)
- if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then sudo ldconfig; fi

script:
Expand All @@ -113,9 +115,10 @@ script:
(cd build && cmake .. -DSEQ_THREADED=ON \
-DLLVM_DIR=`${TRAVIS_BUILD_DIR}/Tapir-LLVM/build/bin/llvm-config --cmakedir` \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++)
-DCMAKE_CXX_COMPILER=clang++ \
-DGC_LIB=${GCLIB})
- cmake --build build --config Release
- build/seqtest 2> /dev/null
- build/seqtest
- build/seqc test/core/helloworld.seq
- (cd docs/sphinx && make html 2> /dev/null)

Expand Down
35 changes: 16 additions & 19 deletions CMakeLists.txt
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.10)
project(Seq)

set(CMAKE_CXX_STANDARD 11)
Expand All @@ -10,32 +10,39 @@ find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)


# Seq runtime library
option(SEQ_THREADED "compile runtime library for multithreading" OFF)
option(SEQ_PYBRIDGE "support Python interoperability" ON)
option(SEQ_JITBRIDGE "support JIT interoperability" OFF)
find_package(ZLIB REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GC REQUIRED bdw-gc)

find_library(HTS_LIB NAMES libhts.a libhts)
if(NOT HTS_LIB)
message(FATAL_ERROR "HTSlib not found")
else()
message(STATUS "Found HTSlib: ${HTS_LIB}")
endif()

find_library(GC_LIB NAMES libgc.a libgc)
if(NOT GC_LIB)
message(FATAL_ERROR "GC not found")
else()
message(STATUS "Found GC: ${GC_LIB}")
endif()

add_library(seqrt SHARED runtime/lib.h
runtime/lib.cpp
runtime/exc.cpp
runtime/ksw2/ksw2.h
runtime/ksw2/ksw2_extd2_sse.cpp
runtime/ksw2/ksw2_exts2_sse.cpp
runtime/ksw2/ksw2_extz2_sse.cpp
runtime/ksw2/ksw2_gg2_sse.cpp
runtime/pybridge.cpp)
target_link_libraries(seqrt PUBLIC curl bz2 lzma ssl crypto ${ZLIB_LIBRARIES} ${GC_LINK_LIBRARIES} ${HTS_LIB})
target_include_directories(seqrt PRIVATE ${GC_INCLUDE_DIRS})
target_compile_options(seqrt PRIVATE ${GC_CFLAGS_OTHER} -O3)
runtime/ksw2/ksw2_gg2_sse.cpp)
target_link_libraries(seqrt PUBLIC bz2 lzma ${ZLIB_LIBRARIES} ${GC_LIB} ${HTS_LIB} Threads::Threads)
target_compile_options(seqrt PRIVATE -O3)

if(SEQ_THREADED)
find_package(OpenMP REQUIRED)
Expand All @@ -45,16 +52,6 @@ else()
target_compile_definitions(seqrt PRIVATE THREADED=0)
endif()

if(SEQ_PYBRIDGE)
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(seqrt PUBLIC ${PYTHON_LIBRARIES})
target_compile_definitions(seqrt PRIVATE PYBRIDGE=1)
else()
target_compile_definitions(seqrt PRIVATE PYBRIDGE=0)
endif()


# Seq parsing library
find_program(OCAMLFIND NAMES ocamlfind)
Expand Down
27 changes: 2 additions & 25 deletions README.md
Expand Up @@ -83,30 +83,7 @@ This will install Seq in a new ``.seq`` directory within your home directory. Be

### Build from source

#### Dependencies

- Linux or macOS
- [CMake](https://cmake.org) 3.12+
- [LLVM](https://llvm.org) 6.0
- [OCaml](https://ocaml.org) 4.08
- [Boehm GC](https://github.com/ivmai/bdwgc) 7.6+
- [HTSlib](https://htslib.org) 1.9+
- [libffi](https://sourceware.org/libffi) 3.2+

The following packages must be installed with `opam`: core, dune, ctypes, ctypes-foreign, menhir, ppx_deriving

#### Build

Make sure the `LLVM_DIR` environment variable is set (to the result of `llvm-config --cmakedir`). Then:

```bash
mkdir seq/build
cd seq/builld
cmake ..
cmake --build .
```

This will produce a `seqc` executable for compiling/running Seq programs, and a `seqtest` executable for running the test suite.
See [Building from Source](docs/sphinx/build.rst).

#### Documentation

Expand All @@ -123,7 +100,7 @@ You can then open `_build/html/index.html` with your browser.

If you use Seq in your research, please cite:

> Ariya Shajii, Ibrahim Numanagić, Riyadh Baghdadi, Bonnie Berger, and Saman Amarasinghe. 2019. Seq: a high-performance language for bioinformatics. *Proc. ACM Program. Lang.* 3, OOPSLA, Article 125 (October 2019), 29 pages. DOI: https://doi.org/10.1145/3360551
> Ariya Shajii, Ibrahim Numanagić, Riyadh Baghdadi, Bonnie Berger, and Saman Amarasinghe. 2019. Seq: a high-performance language for bioinformatics. *Proc. ACM Program. Lang.* 3, OOPSLA, Article 125 (October 2019), 29 pages. DOI: https://doi.org/10.1145/3360551
BibTeX:

Expand Down
24 changes: 8 additions & 16 deletions compiler/include/seq/expr.h
Expand Up @@ -412,20 +412,6 @@ class ArrayLookupExpr : public Expr {
ArrayLookupExpr *clone(Generic *ref) override;
};

class ArraySliceExpr : public Expr {
private:
Expr *arr;
Expr *from;
Expr *to;

public:
ArraySliceExpr(Expr *arr, Expr *from, Expr *to);
void resolveTypes() override;
llvm::Value *codegen0(BaseFunc *base, llvm::BasicBlock *&block) override;
types::Type *getType0() const override;
ArraySliceExpr *clone(Generic *ref) override;
};

class ArrayContainsExpr : public Expr {
private:
Expr *val;
Expand Down Expand Up @@ -489,9 +475,11 @@ class CallExpr : public Expr {
private:
mutable Expr *func;
std::vector<Expr *> args;
std::vector<std::string> names;

public:
CallExpr(Expr *func, std::vector<Expr *> args);
CallExpr(Expr *func, std::vector<Expr *> args,
std::vector<std::string> names = {});
Expr *getFuncExpr() const;
void setFuncExpr(Expr *func);
void resolveTypes() override;
Expand All @@ -504,9 +492,11 @@ class PartialCallExpr : public Expr {
private:
mutable Expr *func;
std::vector<Expr *> args;
std::vector<std::string> names;

public:
PartialCallExpr(Expr *func, std::vector<Expr *> args);
PartialCallExpr(Expr *func, std::vector<Expr *> args,
std::vector<std::string> names = {});
Expr *getFuncExpr() const;
void setFuncExpr(Expr *func);
void resolveTypes() override;
Expand Down Expand Up @@ -552,6 +542,8 @@ class ConstructExpr : public Expr {

public:
ConstructExpr(types::Type *type, std::vector<Expr *> args);
types::Type *getConstructType();
std::vector<Expr *> getArgs();
void resolveTypes() override;
llvm::Value *codegen0(BaseFunc *base, llvm::BasicBlock *&block) override;
types::Type *getType0() const override;
Expand Down
7 changes: 7 additions & 0 deletions compiler/include/seq/func.h
Expand Up @@ -67,6 +67,9 @@ class Func : public BaseFunc, public Generic, public SrcObject {
/// Original function return type, before deduction
types::Type *outType0;

/// Default arguments, or null if none (corresponds to `inTypes` vector)
std::vector<Expr *> defaultArgs;

/// Block representing this function's body
Block *scope;

Expand Down Expand Up @@ -136,6 +139,9 @@ class Func : public BaseFunc, public Generic, public SrcObject {
Func *realize(std::vector<types::Type *> types);
std::vector<types::Type *>
deduceTypesFromArgTypes(std::vector<types::Type *> argTypes);
std::vector<Expr *> rectifyCallArgs(std::vector<Expr *> args,
std::vector<std::string> names,
bool methodCall = false);

void setEnclosingFunc(Func *parentFunc);
void sawReturn(Return *ret);
Expand All @@ -160,6 +166,7 @@ class Func : public BaseFunc, public Generic, public SrcObject {
void setExternal();
void setIns(std::vector<types::Type *> inTypes);
void setOut(types::Type *outType);
void setDefaults(std::vector<Expr *> defaultArgs);
void setName(std::string name);
std::vector<std::string> getArgNames();
void setArgNames(std::vector<std::string> argNames);
Expand Down
1 change: 1 addition & 0 deletions compiler/include/seq/funct.h
Expand Up @@ -25,6 +25,7 @@ class FuncType : public Type {

llvm::Value *defaultValue(llvm::BasicBlock *block) override;

void initOps() override;
bool is(Type *type) const override;
unsigned numBaseTypes() const override;
Type *getBaseType(unsigned idx) const override;
Expand Down
6 changes: 4 additions & 2 deletions compiler/include/seq/generic.h
Expand Up @@ -163,7 +163,8 @@ class GenericType : public Type {
static GenericType *get(Expr *expr);

GenericType *clone(Generic *ref) override;
bool findInType(types::Type *type, std::vector<unsigned> &path);
bool findInType(types::Type *type, std::vector<unsigned> &path,
bool unwrapOptionals);
};
} // namespace types

Expand Down Expand Up @@ -195,7 +196,8 @@ class Generic {
Generic *realizeGeneric(std::vector<types::Type *> types);
std::vector<types::Type *>
deduceTypesFromArgTypes(const std::vector<types::Type *> &inTypes,
const std::vector<types::Type *> &argTypes);
const std::vector<types::Type *> &argTypes,
bool unwrapOptionals = true);
};
} // namespace seq

Expand Down
70 changes: 64 additions & 6 deletions compiler/include/seq/parser.h
Expand Up @@ -8,13 +8,71 @@
#include <iostream>
#include <string>

#ifdef __APPLE__
#include <mach-o/dyld.h>
std::string executable_path(const char *argv0) {
typedef std::vector<char> char_vector;
char_vector buf(1024, 0);
uint32_t size = static_cast<uint32_t>(buf.size());
bool havePath = false;
bool shouldContinue = true;
do {
int result = _NSGetExecutablePath(&buf[0], &size);
if (result == -1) {
buf.resize(size + 1);
std::fill(std::begin(buf), std::end(buf), 0);
} else {
shouldContinue = false;
if (buf.at(0) != 0) {
havePath = true;
}
}
} while (shouldContinue);
if (!havePath) {
return std::string(argv0);
}
return std::string(&buf[0], size);
}
#elif __linux__
#include <unistd.h>
std::string executable_path(const char *argv0) {
typedef std::vector<char> char_vector;
typedef std::vector<char>::size_type size_type;
char_vector buf(1024, 0);
size_type size = buf.size();
bool havePath = false;
bool shouldContinue = true;
do {
ssize_t result = readlink("/proc/self/exe", &buf[0], size);
if (result < 0) {
shouldContinue = false;
} else if (static_cast<size_type>(result) < size) {
havePath = true;
shouldContinue = false;
size = result;
} else {
size *= 2;
buf.resize(size);
std::fill(std::begin(buf), std::end(buf), 0);
}
} while (shouldContinue);
if (!havePath) {
return std::string(argv0);
}
return std::string(&buf[0], size);
}
#else
std::string executable_path(const char *argv0) { return std::string(argv0); }
#endif

namespace seq {
class SeqModule;

value *init(bool repl) {
value *init(const char *argv0, bool repl) {
static value *closure_f = nullptr;
if (!closure_f) {
static char *caml_argv[] = {(char *)"main.exe", (char *)"--parse", nullptr};
std::string s = executable_path(argv0);
static char *caml_argv[] = {(char *)s.c_str(), (char *)"--parse", nullptr};
if (repl)
caml_argv[1] = nullptr;
caml_startup(caml_argv);
Expand All @@ -23,8 +81,8 @@ value *init(bool repl) {
return closure_f;
}

SeqModule *parse(const std::string &file) {
value *closure_f = init(false);
SeqModule *parse(const char *argv0, const std::string &file) {
value *closure_f = init(argv0, false);
try {
auto *module = (SeqModule *)Nativeint_val(
caml_callback(*closure_f, caml_copy_string(file.c_str())));
Expand All @@ -37,8 +95,8 @@ SeqModule *parse(const std::string &file) {
}
}

void repl() {
static value *closure_f = init(true);
void repl(const char *argv0) {
static value *closure_f = init(argv0, true);
Nativeint_val(caml_callback(*closure_f, caml_copy_string("")));
}

Expand Down

0 comments on commit f4b2e4a

Please sign in to comment.