FFI between StackTalk and Javascript
StackTalk uses the ffi command to setup up words thatcommunicate between StackTalk and JS. The stack effect is like so:
[ name effect language definition -- ]As an example, the definition of + in StackTalk is:
+: [ @ @ -- @ ] js: "(a,b) => a+b" ffiTaking this item by item, the first item is the name, in this case +.
The second item is a quotation of the stack effect StackTalk uses this quotation to build up wrapper code that pulls items off the stack and passes them to the JS function you provide. Right now, the JS ffi compiler only supports having 0 or 1 returned values.
The third item is a (programming) language tag. I have hopes for StackTalk to be implemented in language other than JavaScript. A given implementation can ignore ffi definitions that are tagged with language it doesn't know how to run/compile, which should allow for polyglot libraries that target multiple platforms So js-based StackTalk only creates FFI bindings that are tagged as being for JS
Finally, the fourth item is a string of the code to be bound up in an FFI call. For JS, this should be a function with the same number of arguments as inputs in the stack effects, and the same number of return values as outputs For the time being, the FFI compiler only supports 0 or 1 return values.