pecan icon indicating copy to clipboard operation
pecan copied to clipboard

De/serialisation

Open Aurel300 opened this issue 4 years ago • 2 comments

It should be possible to automatically generate the Haxe de/serialisation methods for a coroutine. It should be enough to store:

  • the state (CFG position + flags)
  • any state-crossing locals (which are already detected anyway)

As an optimisation, only the state-crossing locals which are actually read by reachable states could be stored.

Serialisation of a coroutine that depends on a closure-captured variable should probably be forbidden as well.

Aurel300 avatar Feb 10 '21 10:02 Aurel300

but i think the big problem is local var inside they coroutine. the macro must change the mode declaration for save the local vars inside an object state

francescoagati avatar Feb 18 '21 21:02 francescoagati

@francescoagati As I said, state-crossing locals are already detected, e.g.:

co({
  var x = foo();
  suspend();
  trace(x);
});

Here x is declared in a state different from when it is used again. Currently such locals are all declared in a closure surrounding all three internal pecan functions (accept actions, yield actions, "normal" actions), so adding similar functions to dump all the locals into a serializer or load them from a deserializer is an easy change.

Aurel300 avatar Feb 18 '21 22:02 Aurel300