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

Commit 27b5b5b

Browse files
authored
Merge pull request #85 from seq-lang/develop
Develop
2 parents 91994b9 + ac5f4ec commit 27b5b5b

Some content is hidden

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

81 files changed

+4935
-1214
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ addons:
1313
- libsnappy-dev
1414
- binutils-dev
1515
- libomp-dev
16+
- libunwind-dev
1617
- texinfo
1718
- python3
1819
- python3-pip
@@ -48,7 +49,7 @@ before_install:
4849
-DLLVM_ENABLE_RTTI=ON \
4950
-DCMAKE_BUILD_TYPE=Release \
5051
-DLLVM_TARGETS_TO_BUILD=host
51-
cmake --build .
52+
cmake --build . --config Release
5253
cd -
5354
fi
5455
@@ -93,7 +94,7 @@ install:
9394
# install htslib:
9495
- wget -c https://github.com/samtools/htslib/releases/download/1.9/htslib-1.9.tar.bz2 -O - | tar -xj
9596
- cd htslib-1.9
96-
- ./configure CFLAGS="-fPIC" --disable-libcurl
97+
- ./configure CFLAGS="-fPIC" --disable-libcurl --without-curses
9798
- make
9899
- sudo make install
99100
- cd -

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ add_library(seq SHARED compiler/include/seq/any.h
133133
compiler/include/seq/optional.h
134134
compiler/include/seq/parser.h
135135
compiler/include/seq/patterns.h
136+
compiler/include/seq/pipeline.h
136137
compiler/include/seq/ptr.h
137138
compiler/include/seq/record.h
138139
compiler/include/seq/ref.h
@@ -147,6 +148,7 @@ add_library(seq SHARED compiler/include/seq/any.h
147148
compiler/lang/lang.cpp
148149
compiler/lang/ops.cpp
149150
compiler/lang/patterns.cpp
151+
compiler/lang/pipeline.cpp
150152
compiler/lang/seq.cpp
151153
compiler/lang/stmt.cpp
152154
compiler/lang/var.cpp

compiler/include/seq/expr.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class FuncExpr : public Expr {
298298
FuncExpr(BaseFunc *func, Expr *orig, std::vector<types::Type *> types = {});
299299
explicit FuncExpr(BaseFunc *func, std::vector<types::Type *> types = {});
300300
BaseFunc *getFunc();
301+
std::vector<types::Type *> getTypes() const;
301302
bool isRealized() const;
302303
void setRealizeTypes(std::vector<types::Type *> types);
303304
void resolveTypes() override;
@@ -481,6 +482,7 @@ class CallExpr : public Expr {
481482
CallExpr(Expr *func, std::vector<Expr *> args,
482483
std::vector<std::string> names = {});
483484
Expr *getFuncExpr() const;
485+
std::vector<Expr *> getArgs() const;
484486
void setFuncExpr(Expr *func);
485487
void resolveTypes() override;
486488
llvm::Value *codegen0(BaseFunc *base, llvm::BasicBlock *&block) override;
@@ -498,6 +500,7 @@ class PartialCallExpr : public Expr {
498500
PartialCallExpr(Expr *func, std::vector<Expr *> args,
499501
std::vector<std::string> names = {});
500502
Expr *getFuncExpr() const;
503+
std::vector<Expr *> getArgs() const;
501504
void setFuncExpr(Expr *func);
502505
void resolveTypes() override;
503506
llvm::Value *codegen0(BaseFunc *base, llvm::BasicBlock *&block) override;
@@ -593,22 +596,6 @@ class TypeOfExpr : public Expr {
593596
TypeOfExpr *clone(Generic *ref) override;
594597
};
595598

596-
class PipeExpr : public Expr {
597-
private:
598-
std::vector<Expr *> stages;
599-
std::vector<bool> parallel;
600-
601-
public:
602-
static const unsigned SCHED_WIDTH = 16;
603-
explicit PipeExpr(std::vector<Expr *> stages,
604-
std::vector<bool> parallel = {});
605-
void setParallel(unsigned which);
606-
void resolveTypes() override;
607-
llvm::Value *codegen0(BaseFunc *base, llvm::BasicBlock *&block) override;
608-
types::Type *getType0() const override;
609-
PipeExpr *clone(Generic *ref) override;
610-
};
611-
612599
} // namespace seq
613600

614601
#endif /* SEQ_EXPR_H */

compiler/include/seq/func.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "generic.h"
77
#include "stmt.h"
88
#include "types.h"
9+
#include <unordered_map>
910

1011
namespace seq {
1112
class Expr;
@@ -52,6 +53,9 @@ class BaseFunc {
5253
*/
5354
class Func : public BaseFunc, public Generic, public SrcObject {
5455
private:
56+
/// Cache of built-in functions
57+
static std::unordered_map<std::string, Func *> builtins;
58+
5559
/// Whether this function is externally-defined (e.g. via `cdef`)
5660
bool external;
5761

@@ -172,6 +176,8 @@ class Func : public BaseFunc, public Generic, public SrcObject {
172176
void setArgNames(std::vector<std::string> argNames);
173177

174178
Func *clone(Generic *ref) override;
179+
180+
static Func *getBuiltin(const std::string &name);
175181
};
176182

177183
/**

compiler/include/seq/generic.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ static bool typeMatch(const std::vector<T *> &v1, const std::vector<T *> &v2,
2222

2323
for (unsigned i = 0; i < v1.size(); i++) {
2424
if (strict) {
25-
types::RecordType *r1 = v1[i]->asRec();
26-
types::RecordType *r2 = v2[i]->asRec();
25+
auto *r1 = dynamic_cast<types::RecordType *>(v1[i]);
26+
auto *r2 = dynamic_cast<types::RecordType *>(v2[i]);
2727
if (r1 && r2) {
28-
return r1->isStrict(r2);
28+
if (!r1->isStrict(r2))
29+
return false;
30+
continue;
2931
}
3032
}
3133
if (!types::is(v1[i], v2[i]))
@@ -43,19 +45,28 @@ static bool typeMatch(const std::vector<T *> &v1, const std::vector<T *> &v2,
4345
template <typename T> class RCache {
4446
private:
4547
std::vector<std::pair<std::vector<types::Type *>, T *>> cache;
48+
std::vector<std::vector<types::Type *>> inProgress;
4649

4750
public:
48-
RCache() : cache() {}
51+
RCache() : cache(), inProgress() {}
4952

5053
void add(std::vector<types::Type *> types, T *t) {
5154
cache.emplace_back(std::move(types), t);
5255
}
5356

5457
T *find(const std::vector<types::Type *> &types) {
58+
for (auto &v : inProgress) {
59+
if (v == types)
60+
return nullptr;
61+
}
62+
inProgress.push_back(types);
5563
for (auto &v : cache) {
56-
if (typeMatch<>(v.first, types, /*strict=*/true))
64+
if (typeMatch<>(v.first, types, /*strict=*/true)) {
65+
inProgress.pop_back();
5766
return v.second;
67+
}
5868
}
69+
inProgress.pop_back();
5970
return nullptr;
6071
}
6172
};
@@ -150,7 +161,8 @@ class GenericType : public Type {
150161
void initOps() override;
151162
void initFields() override;
152163
Type *magicOut(const std::string &name, std::vector<Type *> args,
153-
bool nullOnMissing = false) override;
164+
bool nullOnMissing = false,
165+
bool overloadsOnly = false) override;
154166
llvm::Value *callMagic(const std::string &name, std::vector<Type *> argTypes,
155167
llvm::Value *self, std::vector<llvm::Value *> args,
156168
llvm::BasicBlock *&block, TryCatch *tc) override;

compiler/include/seq/pipeline.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef SEQ_PIPELINE_H
2+
#define SEQ_PIPELINE_H
3+
4+
#include "expr.h"
5+
6+
namespace seq {
7+
8+
class PipeExpr : public Expr {
9+
private:
10+
std::vector<Expr *> stages;
11+
std::vector<bool> parallel;
12+
13+
public:
14+
static const unsigned SCHED_WIDTH = 16;
15+
explicit PipeExpr(std::vector<Expr *> stages,
16+
std::vector<bool> parallel = {});
17+
void setParallel(unsigned which);
18+
void resolveTypes() override;
19+
llvm::Value *codegen0(BaseFunc *base, llvm::BasicBlock *&block) override;
20+
types::Type *getType0() const override;
21+
PipeExpr *clone(Generic *ref) override;
22+
};
23+
24+
} // namespace seq
25+
26+
#endif /* SEQ_PIPELINE_H */

compiler/include/seq/record.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class RecordType : public Type {
2121
void operator=(RecordType const &) = delete;
2222

2323
void setContents(std::vector<Type *> types, std::vector<std::string> names);
24+
bool named() const;
2425
bool empty() const;
2526
std::vector<Type *> getTypes();
2627

compiler/include/seq/seq.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "lang.h"
1414
#include "ops.h"
1515
#include "patterns.h"
16+
#include "pipeline.h"
1617
#include "var.h"
1718

1819
#include "any.h"
@@ -34,7 +35,7 @@
3435

3536
#define SEQ_VERSION_MAJOR 0
3637
#define SEQ_VERSION_MINOR 9
37-
#define SEQ_VERSION_PATCH 1
38+
#define SEQ_VERSION_PATCH 2
3839

3940
namespace seq {
4041
namespace types {

compiler/include/seq/types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ class Type {
227227
/// exception if magic is missing
228228
/// @return output type of specified magic method
229229
virtual Type *magicOut(const std::string &name, std::vector<Type *> args,
230-
bool nullOnMissing = false);
230+
bool nullOnMissing = false,
231+
bool overloadsOnly = false);
231232

232233
/// Codegens a call to the specified magic method. Throws
233234
/// an exception if the specified magic method does not

0 commit comments

Comments
 (0)