2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
29 static void program_callback(void attr_unused
*callback_cookie
, pointer_t ptr
)
31 if (likely(!pointer_is_empty(ptr
))) {
32 if (unlikely(pointer_is_thunk(ptr
))) {
33 struct thunk
*t
= pointer_get_thunk(ptr
);
34 struct thunk_exception
*te
= &t
->u
.exception
;
35 if (te
->err
.error_class
== EC_EXIT
&& te
->err
.error_type
== AJLA_ERROR_EXIT
) {
36 if (unlikely(te
->err
.error_aux
< 0) || unlikely(te
->err
.error_aux
>= 256))
37 retval
= EXCEPTION_RETVAL
;
39 retval
= te
->err
.error_aux
;
41 stderr_msg("%s", te
->msg
);
43 thunk_exception_print(t
);
44 retval
= EXCEPTION_RETVAL
;
47 tag_t attr_unused tag
= da_tag(pointer_get_data(ptr
));
48 ajla_assert_lo(tag
== DATA_TAG_option
, (file_line
, "program_callback: data tag %02x", tag
));
51 task_program_exited();
54 void name(program_run
)(void)
56 struct data
*function_reference
;
59 function_reference
= data_alloc_function_reference_mayfail(0, NULL pass_file_line
);
60 da(function_reference
,function_reference
)->is_indirect
= false;
61 da(function_reference
,function_reference
)->u
.direct
= start_fn
;
63 thunk_alloc_function_call(pointer_data(function_reference
), 1, &thunk
, NULL
);
65 task_program_started();
66 function_evaluate_submit(function_evaluate_prepare(NULL
), pointer_thunk(thunk
), program_callback
, NULL
);