vtereshkov / umka-lang

Umka: a statically typed embeddable scripting language
BSD 2-Clause "Simplified" License
1k stars 53 forks source link

Convenience functions/macros for accessing function parameters from C #417

Closed vtereshkov closed 4 days ago

vtereshkov commented 1 week ago

Too many questions like In what stack slot can I find my dynamic array parameter?

And overall, mixing the API with ABI is not good, even if documented.

skejeton commented 1 week ago

While we can, I think the direct stack slot API should be replaced with as single parameter:

void externalFunction(UmkaCall *call) {
  int firstArg = umkaArg(call, 0);
  int secondArg = umkaArg(call, 1);
  umkaReturn(call, firstArg+secondArg);
}

What I am not sure about here is how we handle types, umkaArg needs to return some type where we can select the type, like an UmkaStackSlot, but this also needs to work for dynarrays. One idea is to have a separate function for each type, but it can get pretty cumbersome.