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

Clear out the Reference vs Computation mess #27

Closed nsensfel closed 3 years ago

nsensfel commented 3 years ago

This is being done in the parser_rework branch. The compiler needs to output warnings when attempting to set! a non-reference computation>, and the documentation needs to be updated to clearly state if a computation operator's result can be used as a reference.

nsensfel commented 3 years ago

Actually, the result in parser_rework might be even more confusing for the end user. It would be fine if the compiler properly warned of potential mistakes, but this is not exactly trivially done. Indeed, in that branch, what actually determines whether something is a a reference or not is how it compiles to Wyrd: are the computations in the first argument of set! properly propagated using addresses (in which case it will properly reference what the user wants) or does the resolution of that argument actually refers to the value in a newly created register (in which case it will most likely not modify any variable, from the user's point of view). Thus, some computations might return references in some cases and not in others.

nsensfel commented 3 years ago

https://github.com/nsensfel/tonkadur/commit/7605eaa49bfdafa6d386440aa301c809245055ae adds a way to signal that a Fate computation is being used as a reference (use_as_reference() call on instruction build). By default, this triggers a warning about the computation not being a valid reference, but the behavior is overridden by the appropriate computation classes. Specification of what can be used as a reference is still done manually, but this should greatly help users figure out the cause of related issues.

nsensfel commented 3 years ago

I am currently satisfied with that solution.