Skip to content

Commit 9b05943

Browse files
committed
IR, beatch
1 parent 4f51112 commit 9b05943

6 files changed

Lines changed: 623 additions & 127 deletions

File tree

examples/program1.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# A function declaration
2-
math_atan = extern atan2 (a Float, b Float) Float
2+
atan2 = extern atan2 (a Float, b Float) Float
33

44
# A function definition
5-
foo = func (x, y Float) Float, Float ->
6-
6 + x + foo 5 (foo y 4.0)
5+
foo = func (x, y Float) Float -> 7.2 * x
6+
# 6 + x + foo 5 (foo y 4.0)
77

88
# Call the foo function with a number argument of 40
9-
foo 10 (foo 10 20) 20
9+
M = foo 1.0 2.0
1010

1111
# Alias 1983 as "Year"
12-
Year Int = 1983
13-
x = 4.9
14-
y = 3.1 + atan2 x 0.3
15-
Month = 5
12+
Year = 1983
13+
#x = 4.9
14+
#y = 3.1 + atan2 x 0.3
15+
Month = Year + M
1616

17-
#Day MUTABLE = foo 3 4.1
17+
#Day MUTABLE = foo 3.1 4.1
1818

1919
#x Int, y MUTABLE, z MUTABLE Float = ninja2000 34.4
2020
#MUTABLE y = 8

src/ast/Function.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@ class Argument {
2525
// Represents the "prototype" for a function, which captures its name, and its
2626
// argument names (thus implicitly the number of arguments the function takes).
2727
class FunctionInterface : public Node {
28-
VariableList *args_;
29-
TypeDeclarationList *returnTypes_;
3028
public:
31-
FunctionInterface(VariableList *args = 0, TypeDeclarationList *returnTypes = 0)
32-
: Node(TFunctionInterface), args_(args), returnTypes_(returnTypes) {}
29+
FunctionInterface(VariableList *args = 0,
30+
TypeDeclarationList *returnTypes = 0,
31+
bool isPublic = false)
32+
: Node(TFunctionInterface), args_(args), returnTypes_(returnTypes), isPublic_(isPublic) {}
3333

3434
VariableList *args() const { return args_; }
3535
TypeDeclarationList *returnTypes() const { return returnTypes_; }
36+
37+
bool isPublic() const { return isPublic_; }
38+
void setIsPublic(bool isPublic) { isPublic_ = isPublic; }
39+
40+
bool declaresReturnTypes() const {
41+
return returnTypes_ != 0 && returnTypes_->size() != 0;
42+
}
3643

3744
virtual std::string toString(int level = 0) const {
3845
std::ostringstream ss;
@@ -59,6 +66,11 @@ class FunctionInterface : public Node {
5966
ss << '>';
6067
return ss.str();
6168
}
69+
70+
private:
71+
VariableList *args_;
72+
TypeDeclarationList *returnTypes_;
73+
bool isPublic_;
6274
};
6375

6476
// Represents a function definition.

src/ast/TypeDeclaration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class TypeDeclaration {
1818
TypeDeclaration(Type type) : type(type) {}
1919
TypeDeclaration(const std::string& name) : type(Named), name_(name) {}
2020

21+
const std::string& name() const { return name_; }
22+
2123
std::string toString() const {
2224
switch (type) {
2325
case Named: return name_;

src/ast/Variable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class Variable : public Node {
1515
const std::string& name() const { return name_; }
1616

1717
TypeDeclaration *type() const { return type_; }
18+
bool hasUnknownType() const { return !type_ || type_->type == TypeDeclaration::Unknown; }
19+
1820
void setType(TypeDeclaration *type) {
1921
TypeDeclaration *old = type_;
2022
type_ = type;

0 commit comments

Comments
 (0)