nsensfel / tonkadur

Narrative scripting/programming tool. Write stories in your favorite editor using a feature-rich language, compile them into a very small and simple language to easily integrate them into your game.
https://tonkadur.of.tacticians.online
Apache License 2.0
2 stars 0 forks source link

Procedure/Sequence reference #14

Closed nsensfel closed 3 years ago

nsensfel commented 3 years ago

Procedures/Sequences should be able to be stored in variables or passed as parameter just like lambda functions are.

nsensfel commented 3 years ago

Small hurdle: (sequence my_sequence) returns a computation that corresponds to the sequence my_sequence, but since my_sequence might not have been defined yet, its full type (which should include the sequence's signature) isn't available. This isn't an issue with the call or jump instructions, since those instructions have parameters which indicate the expected signature. The (sequence my_sequence) computation does not.

nsensfel commented 3 years ago

Added in https://github.com/nsensfel/tonkadur/commit/22ec7b935d4fbac94ddff580b9649f6748d7444d. Aforementioned issue resolved by having the sequence type accept "proposed signatures". Basically, whenever the sequence type needs to fit a signature, that targeted signature is first proposed to the sequence type. If that sequence type already has a signature, nothing happens. Otherwise, it becomes the sequence type's signature. There's also a check at the end of the compilation to make sure all uses of a procedure accept the signature that the procedure in question is defined with (same system as with the call and jump instructions).