Skip to content

Commit

Permalink
pipeless generator syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
borisbat committed Nov 2, 2024
1 parent 62febdd commit 445a1b1
Show file tree
Hide file tree
Showing 9 changed files with 34,244 additions and 34,002 deletions.
46 changes: 46 additions & 0 deletions examples/test/misc/hello_world.das
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,52 @@ def test_lambda_capture ( a : int ) {
};
}

////////////
// generator

[export]
def test_generator ( a : int ) {
// passing block as argument
var g1 <- generator<int> (${
for ( x in range(1,a) ) {
yield x;
}
return false;
});
var G1 <- generator<int> capture(=a) (${
for ( x in range(1,a) ) {
yield x;
}
return false;
});
// simplified syntax
var g2 <- generator<int> {
for ( x in range(1,a) ) {
yield x;
}
return false;
};
var G2 <- generator<int> capture(=a) {
for ( x in range(1,a) ) {
yield x;
}
return false;
};
// via pipe
var g3 <- generator<int>() <| ${
for ( x in range(1,a) ) {
yield x;
}
return false;
};
var G3 <- generator<int> capture(=a) () <| ${
for ( x in range(1,a) ) {
yield x;
}
return false;
};
}

///////
// main

Expand Down
4 changes: 2 additions & 2 deletions src/ast/ast_infer_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2774,10 +2774,10 @@ namespace das {
return Visitor::visit(expr);
}
if ( expr->arguments.size()!=1 ) {
error("expecting generator(closure)", "", "",
error("generator can only have one argument", "", "",
expr->at, CompilationError::invalid_argument_count);
} else if ( !expr->arguments[0]->rtti_isMakeBlock() ) {
error("expecting generator(closure)", "", "",
error("expecting generator(closure), got " + string(expr->arguments[0]->__rtti) + " instead", "", "",
expr->at, CompilationError::invalid_argument_type);
} else {
auto mkBlock = static_pointer_cast<ExprMakeBlock>(expr->arguments[0]);
Expand Down
24 changes: 24 additions & 0 deletions src/builtin/builtin.das.inc
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ static unsigned char builtin_das[] = {
0x69,0x74,0x56,0x61,0x6c,0x75,0x65,0x0a,
0x0a,
0x0a,
0x5b,0x75,0x6e,0x75,0x73,0x65,0x64,0x5f,
0x61,0x72,0x67,0x75,0x6d,0x65,0x6e,0x74,
0x28,0x41,0x72,0x72,0x2c,0x20,0x6e,0x65,
0x77,0x53,0x69,0x7a,0x65,0x29,0x5d,0x0a,
0x64,0x65,0x66,0x20,0x72,0x65,0x73,0x69,
0x7a,0x65,0x5f,0x6e,0x6f,0x5f,0x69,0x6e,
0x69,0x74,0x28,0x76,0x61,0x72,0x20,0x41,
Expand Down Expand Up @@ -469,6 +473,10 @@ static unsigned char builtin_das[] = {
0x6e,0x65,0x67,0x61,0x74,0x69,0x76,0x65,
0x0a,
0x0a,
0x5b,0x75,0x6e,0x75,0x73,0x65,0x64,0x5f,
0x61,0x72,0x67,0x75,0x6d,0x65,0x6e,0x74,
0x28,0x41,0x72,0x72,0x2c,0x20,0x76,0x61,
0x6c,0x75,0x65,0x29,0x5d,0x0a,
0x64,0x65,0x66,0x20,0x70,0x75,0x73,0x68,
0x28,0x76,0x61,0x72,0x20,0x41,0x72,0x72,
0x3a,0x61,0x72,0x72,0x61,0x79,0x3c,0x61,
Expand Down Expand Up @@ -516,6 +524,10 @@ static unsigned char builtin_das[] = {
0x6e,0x27,0x74,0x20,0x62,0x65,0x20,0x63,
0x6f,0x70,0x69,0x65,0x64,0x22,0x29,0x0a,
0x0a,
0x5b,0x75,0x6e,0x75,0x73,0x65,0x64,0x5f,
0x61,0x72,0x67,0x75,0x6d,0x65,0x6e,0x74,
0x28,0x41,0x72,0x72,0x2c,0x20,0x76,0x61,
0x6c,0x75,0x65,0x29,0x5d,0x0a,
0x64,0x65,0x66,0x20,0x70,0x75,0x73,0x68,
0x28,0x76,0x61,0x72,0x20,0x41,0x72,0x72,
0x3a,0x61,0x72,0x72,0x61,0x79,0x3c,0x61,
Expand Down Expand Up @@ -562,6 +574,10 @@ static unsigned char builtin_das[] = {
0x6e,0x27,0x74,0x20,0x62,0x65,0x20,0x63,
0x6f,0x70,0x69,0x65,0x64,0x22,0x29,0x0a,
0x0a,
0x5b,0x75,0x6e,0x75,0x73,0x65,0x64,0x5f,
0x61,0x72,0x67,0x75,0x6d,0x65,0x6e,0x74,
0x28,0x41,0x72,0x72,0x2c,0x20,0x76,0x61,
0x6c,0x75,0x65,0x29,0x5d,0x0a,
0x64,0x65,0x66,0x20,0x70,0x75,0x73,0x68,
0x28,0x76,0x61,0x72,0x20,0x41,0x72,0x72,
0x3a,0x61,0x72,0x72,0x61,0x79,0x3c,0x61,
Expand Down Expand Up @@ -612,6 +628,10 @@ static unsigned char builtin_das[] = {
0x6e,0x27,0x74,0x20,0x62,0x65,0x20,0x63,
0x6f,0x70,0x69,0x65,0x64,0x22,0x29,0x0a,
0x0a,
0x5b,0x75,0x6e,0x75,0x73,0x65,0x64,0x5f,
0x61,0x72,0x67,0x75,0x6d,0x65,0x6e,0x74,
0x28,0x41,0x72,0x72,0x2c,0x20,0x76,0x61,
0x6c,0x75,0x65,0x29,0x5d,0x0a,
0x64,0x65,0x66,0x20,0x70,0x75,0x73,0x68,
0x28,0x76,0x61,0x72,0x20,0x41,0x72,0x72,
0x3a,0x61,0x72,0x72,0x61,0x79,0x3c,0x61,
Expand Down Expand Up @@ -662,6 +682,10 @@ static unsigned char builtin_das[] = {
0x6e,0x27,0x74,0x20,0x62,0x65,0x20,0x63,
0x6f,0x70,0x69,0x65,0x64,0x22,0x29,0x0a,
0x0a,
0x5b,0x75,0x6e,0x75,0x73,0x65,0x64,0x5f,
0x61,0x72,0x67,0x75,0x6d,0x65,0x6e,0x74,
0x28,0x41,0x72,0x72,0x2c,0x20,0x76,0x61,
0x6c,0x75,0x65,0x29,0x5d,0x0a,
0x64,0x65,0x66,0x20,0x70,0x75,0x73,0x68,
0x28,0x76,0x61,0x72,0x20,0x41,0x72,0x72,
0x3a,0x61,0x72,0x72,0x61,0x79,0x3c,0x61,
Expand Down
5,058 changes: 2,540 additions & 2,518 deletions src/parser/ds2_parser.cpp

Large diffs are not rendered by default.

Loading

0 comments on commit 445a1b1

Please sign in to comment.