Skip to content

Commit

Permalink
managed syncrhonization in try block
Browse files Browse the repository at this point in the history
  • Loading branch information
maniospas committed Nov 1, 2024
1 parent f9ed28d commit 97b860a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 37 deletions.
Binary file modified blombly
Binary file not shown.
4 changes: 2 additions & 2 deletions main.bb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "libs/final"
#include "libs/loop"

final functors(n) = {
Expand All @@ -20,4 +19,5 @@ final functors(n) = {
a = try {
values = functors("abc");
}
print(a);
catch(a)
print("found an error");
72 changes: 38 additions & 34 deletions main.bbvm
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
BEGIN _bb19
BEGIN _bb10
next n args
int n n
list ret
BUILTIN _bb23 I1
BUILTIN _bb25 F0.5
pow _bb24 n _bb25
add _bb22 _bb24 _bb23
int sqrtn _bb22
BUILTIN _bb28 I1
range _bbmacro0 _bb28 sqrtn
next _bb29 _bbmacro0
AS i _bb29
exists _bb30 i
BEGIN _bb31
BEGIN _bb32
BUILTIN _bb14 I1
BUILTIN _bb16 F0.5
pow _bb15 n _bb16
add _bb13 _bb15 _bb14
int sqrtn _bb13
BUILTIN _bb19 I1
range _bbmacro0 _bb19 sqrtn
next _bb20 _bbmacro0
AS i _bb20
exists _bb21 i
BEGIN _bb22
BEGIN _bb23
push # ret i
div _bb33 n i
int complement _bb33
BEGIN _bb35
div _bb24 n i
int complement _bb24
BEGIN _bb26
push # ret complement
END
neq _bb36 i complement
if # _bb36 _bb35
neq _bb27 i complement
if # _bb27 _bb26
END
BUILTIN _bb38 I0
mod _bb39 n i
eq _bb37 _bb39 _bb38
if # _bb37 _bb32
next _bb29 _bbmacro0
AS i _bb29
exists _bb30 i
BUILTIN _bb29 I0
mod _bb30 n i
eq _bb28 _bb30 _bb29
if # _bb28 _bb23
next _bb20 _bbmacro0
AS i _bb20
exists _bb21 i
END
while # _bb30 _bb31
while # _bb21 _bb22
return # ret
END
IS functors _bb19
IS functors _bb10
final # functors
BEGIN _bb42
BEGIN _bb44
BUILTIN _bb45 "abc"
list args _bb45
BEGIN _bb33
BEGIN _bb35
BUILTIN _bb36 "abc"
list args _bb36
END
call values _bb35 functors
END
call values _bb44 functors
try a _bb33
BEGIN _bb37
BUILTIN _bb38 "found an error"
print # _bb38
END
try a _bb42
print # a
catch # a _bb37
2 changes: 1 addition & 1 deletion src/data/future.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Result Future::getResult() const {
}

if (result->error) {
std::string error_message = (result->error->what());
std::string error_message = std::move(result->error->what());
result->error = nullptr;
result->value = Result(nullptr);
throw BBError(error_message);
Expand Down
2 changes: 2 additions & 0 deletions src/interpreter/functional/handle_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,14 @@ void handleCommand(std::vector<Command*>* program, int& i, BMemory* memory, bool
return;

case TRY: {
memory->detach(memory->parent);
try {
Data* condition = MEMGET(memory, 1);
bbassert(condition->getType()==CODE, "Can only inline a non-called code block for try condition");
auto codeCondition = static_cast<Code*>(condition);
bool tryReturnSignal(false);
Result returnedValue = executeBlock(codeCondition, memory, tryReturnSignal);
memory->detach(memory->parent);
result = returnedValue.get();
if(!tryReturnSignal)
result = nullptr;
Expand Down

0 comments on commit 97b860a

Please sign in to comment.