Skip to content

Commit 012ba89

Browse files
committed
nifs.c: use RAISE() macro instead of writing registers
RAISE()/RAISE_ERROR() is more maintainable than directly writing to registers. Signed-off-by: Davide Bettio <[email protected]>
1 parent 593b3ee commit 012ba89

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/libAtomVM/nifs.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,9 +3060,7 @@ static term nif_erlang_system_flag(Context *ctx, int argc, term argv[])
30603060
int new_value = term_to_int(value);
30613061
int nb_processors = smp_get_online_processors();
30623062
if (UNLIKELY(new_value < 1) || UNLIKELY(new_value > nb_processors)) {
3063-
argv[0] = ERROR_ATOM;
3064-
argv[1] = BADARG_ATOM;
3065-
return term_invalid_term();
3063+
RAISE_ERROR(BADARG_ATOM);
30663064
}
30673065
while (!ATOMIC_COMPARE_EXCHANGE_WEAK_INT(&ctx->global->online_schedulers, &old_value, new_value)) {
30683066
};
@@ -3607,11 +3605,7 @@ static term nif_erlang_throw(Context *ctx, int argc, term argv[])
36073605
{
36083606
UNUSED(argc);
36093607

3610-
term t = argv[0];
3611-
3612-
ctx->x[0] = THROW_ATOM;
3613-
ctx->x[1] = t;
3614-
return term_invalid_term();
3608+
RAISE(THROW_ATOM, argv[0]);
36153609
}
36163610

36173611
static term nif_erlang_raise(Context *ctx, int argc, term argv[])
@@ -3622,10 +3616,8 @@ static term nif_erlang_raise(Context *ctx, int argc, term argv[])
36223616
if (UNLIKELY(ex_class != ERROR_ATOM && ex_class != LOWERCASE_EXIT_ATOM && ex_class != THROW_ATOM)) {
36233617
return BADARG_ATOM;
36243618
}
3625-
ctx->x[0] = ex_class;
3626-
ctx->x[1] = argv[1];
3627-
ctx->x[2] = term_nil();
3628-
return term_invalid_term();
3619+
ctx->exception_stacktrace = term_nil();
3620+
RAISE(ex_class, argv[1]);
36293621
}
36303622

36313623
static term nif_ets_new(Context *ctx, int argc, term argv[])

0 commit comments

Comments
 (0)