did stuff

This commit is contained in:
IonutParau 2026-02-09 12:27:33 +01:00
parent a19dea513e
commit c0d965be26
3 changed files with 8 additions and 2 deletions

View File

@ -89,7 +89,7 @@ int main() {
while(true) { while(true) {
nn_Exit e = nn_tick(c); nn_Exit e = nn_tick(c);
if(e != NN_OK) { if(e != NN_OK && e != NN_EBUSY) {
nn_setErrorFromExit(c, e); nn_setErrorFromExit(c, e);
printf("error: %s\n", nn_getError(c)); printf("error: %s\n", nn_getError(c));
goto cleanup; goto cleanup;

View File

@ -1031,6 +1031,8 @@ nn_Exit nn_tick(nn_Computer *computer) {
req.localState = computer->archState; req.localState = computer->archState;
req.action = NN_ARCH_TICK; req.action = NN_ARCH_TICK;
err = computer->arch.handler(&req); err = computer->arch.handler(&req);
// dont crash on EBUSY because it just means go again
if(err == NN_EBUSY) return err;
if(err) { if(err) {
computer->state = NN_CRASHED; computer->state = NN_CRASHED;
nn_setErrorFromExit(computer, err); nn_setErrorFromExit(computer, err);
@ -1338,6 +1340,7 @@ void nn_resetCallBudget(nn_Computer *computer) {
} }
bool nn_componentsOverused(nn_Computer *computer) { bool nn_componentsOverused(nn_Computer *computer) {
if(computer->totalCallBudget == 0) return false;
return computer->callBudget == 0; return computer->callBudget == 0;
} }

View File

@ -206,6 +206,8 @@ typedef enum nn_Exit {
NN_EBADCALL, NN_EBADCALL,
// bad state, the function was called at the wrong time // bad state, the function was called at the wrong time
NN_EBADSTATE, NN_EBADSTATE,
// resource busy. If the result of nn_call, you should call it again later.
NN_EBUSY,
} nn_Exit; } nn_Exit;
// This stores necessary data between computers // This stores necessary data between computers
@ -481,6 +483,7 @@ const char *nn_getComponentDoc(nn_Computer *computer, const char *address, const
// this uses the call stack. // this uses the call stack.
// Component calls must not call other components, it just doesn't work. // Component calls must not call other components, it just doesn't work.
// The lack of an argument count is because the entire call stack is assumed to be the arguments. // The lack of an argument count is because the entire call stack is assumed to be the arguments.
// In the case of NN_EBUSY, you should call it again with the same arguments later.
nn_Exit nn_call(nn_Computer *computer, const char *address, const char *method); nn_Exit nn_call(nn_Computer *computer, const char *address, const char *method);
// Sets the call budget. // Sets the call budget.
@ -501,7 +504,7 @@ size_t nn_callBudgetRemaining(nn_Computer *computer);
void nn_resetCallBudget(nn_Computer *computer); void nn_resetCallBudget(nn_Computer *computer);
// returns whether there is no more call budget left. // returns whether there is no more call budget left.
// At this point, the architecture should exit from a yield. // At this point, the architecture should exit with a yield.
bool nn_componentsOverused(nn_Computer *computer); bool nn_componentsOverused(nn_Computer *computer);
// call stack operations. // call stack operations.