SpacemanDMM icon indicating copy to clipboard operation
SpacemanDMM copied to clipboard

Expose parser and AST to external programs

Open Karolis2011 opened this issue 3 years ago • 2 comments

So, this is a suggestion to add FFI that would allow understanding DM from other languages.

I have started working on mine, myself, https://github.com/Karolis2011/dremamaker-ffi But it would require more work to expose all internal rust structs also as alternative I tried using json serialization but that requres that all structs be serializable.

Why would this be useful? Let's say I want to write myown dream checker in python, then I could use FFI and use already build rust code base logic to do heavy lifting of lexing and parsing while peaple could care only for analysis code.

Karolis2011 avatar Mar 23 '21 20:03 Karolis2011

I'm hopeful that SpacemanDMM's parser can be useful to other projects as it was useful to StrongDMM. But in order to keep SpacemanDMM flexible enough to adapt to BYOND changes and to improve over time, I don't want to commit to API stability. Also, maintaining complicated code and making binary releases for a C FFI layer that doesn't see much use isn't something I want to commit to.

You could try to maintain your own C FFI but it's probably not worth it given the 'one and done' nature of parsing an environment. You suggest JSON serialization, and this is also the strategy StrongDMM uses. While I would accept a patch to mark SpacemanDMM's structs as Serializable, I similarly do not want to commit to keeping the output of that serialization stable. I would recommend doing like StrongDMM does: use Rust code to adapt SpacemanDMM's structures into structures of your own, which you then export as desired.

SpaceManiac avatar Mar 24 '21 00:03 SpaceManiac

On this note, I've been interested in writing mlua bindings, I wanted to write tg specific lints with very little overhead in terms of distribution, but are too complicated for basic greps (such as requiring SIGNAL_HANDLER on signal handlers). The best way to do this seemed to be just adding a very simple Lua interface, which is solid as an embedded language for this purpose.

Mothblocks avatar Apr 02 '21 02:04 Mothblocks