aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/pthreads/pthreads.tm14
-rw-r--r--src/parse.c49
2 files changed, 11 insertions, 52 deletions
diff --git a/examples/pthreads/pthreads.tm b/examples/pthreads/pthreads.tm
index ab802448..cfb58aa8 100644
--- a/examples/pthreads/pthreads.tm
+++ b/examples/pthreads/pthreads.tm
@@ -69,15 +69,12 @@ struct IntQueue(_queue:@[Int], _mutex:@pthread_mutex_t, _cond:@pthread_cond_t):
return IntQueue(@initial, pthread_mutex_t.new(), pthread_cond_t.new())
func give(q:IntQueue, n:Int):
- do_begin: q._mutex:lock()
- do_end: q._mutex:unlock()
- do: q._queue:insert(n)
+ do: q._mutex:lock(); defer: q._mutex:unlock()
+ q._queue:insert(n)
q._cond:signal()
func take(q:IntQueue -> Int):
- do_begin: q._mutex:lock()
- do_end: q._mutex:unlock()
- do:
+ do: q._mutex:lock(); defer: q._mutex:unlock()
repeat:
if n := q._queue:pop(1):
return n
@@ -90,9 +87,8 @@ func main():
say_mutex := pthread_mutex_t.new()
announce := func(speaker:Text, text:Text):
- do_begin: say_mutex:lock()
- do_end: say_mutex:unlock()
- do: say("$\033[2m[$speaker]$\033[m $text")
+ do: say_mutex:lock(); defer: say_mutex:unlock()
+ say("$\033[2m[$speaker]$\033[m $text")
worker := pthread_t.new(func():
say("I'm in the thread!")
diff --git a/src/parse.c b/src/parse.c
index 6a1b151c..4ace5a67 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -63,8 +63,8 @@ int op_tightness[] = {
static const char *keywords[] = {
"yes", "xor", "while", "when", "use", "unless", "struct", "stop", "skip", "return",
- "or", "not", "none", "no", "mutexed", "mod1", "mod", "pass", "lang", "inline", "in", "if", "holding",
- "func", "for", "extern", "enum", "do_end", "else", "do", "deserialize", "defer", "do_begin", "and",
+ "or", "not", "none", "no", "mutexed", "mod1", "mod", "pass", "lang", "inline", "in", "if",
+ "holding", "func", "for", "extern", "enum", "else", "do", "deserialize", "defer", "and",
"_min_", "_max_", NULL,
};
@@ -1106,48 +1106,11 @@ PARSER(parse_for) {
}
PARSER(parse_do) {
- // [do_begin: [<indent>] block] [do_end: [<indent>] block] do: [<indent>] body
+ // do: [<indent>] body
const char *start = pos;
- int64_t starting_indent = get_indent(ctx, pos);
- ast_t *begin = NULL, *end = NULL;
- if (match_word(&pos, "do_begin"))
- begin = optional(ctx, &pos, parse_block);
-
- const char *tmp = pos;
- whitespace(&tmp);
- if (get_indent(ctx, tmp) == starting_indent && match_word(&tmp, "do_end")) {
- pos = tmp;
- end = optional(ctx, &pos, parse_block);
- }
-
- tmp = pos;
- whitespace(&tmp);
- if (get_indent(ctx, tmp) == starting_indent && match_word(&tmp, "do")) {
- pos = tmp;
- ast_t *body = expect(ctx, start, &pos, parse_block, "I expected a body for this 'do'");
- if (begin && end) {
- ast_list_t *statements = Match(begin, Block)->statements;
- REVERSE_LIST(statements);
- statements = new(ast_list_t, .ast=WrapAST(end, Defer, .body=end), .next=statements);
- statements = new(ast_list_t, .ast=body, .next=statements);
- REVERSE_LIST(statements);
- return NewAST(ctx->file, start, pos, Block, .statements=statements);
- } else if (begin) {
- ast_list_t *statements = Match(begin, Block)->statements;
- REVERSE_LIST(statements);
- statements = new(ast_list_t, .ast=body, .next=statements);
- REVERSE_LIST(statements);
- return NewAST(ctx->file, start, pos, Block, .statements=statements);
- } else if (end) {
- return NewAST(ctx->file, start, pos, Block,
- .statements=new(ast_list_t, .ast=WrapAST(end, Defer, .body=end),
- .next=new(ast_list_t, .ast=body)));
- } else {
- return NewAST(ctx->file, start, pos, Block, .statements=Match(body, Block)->statements);
- }
- } else {
- return NULL;
- }
+ if (!match_word(&pos, "do")) return NULL;
+ ast_t *body = expect(ctx, start, &pos, parse_block, "I expected a body for this 'do'");
+ return NewAST(ctx->file, start, pos, Block, .statements=Match(body, Block)->statements);
}
PARSER(parse_while) {