Ponds,Functions and Call Targets in KoiFish

A couple posts ago, I spilled my conundrum about linking with the KoiFish Compiler (KFC).  KoiA and KoiB need some portal of communication if they both so desire to be public facing with public facing functions.  So, it begs the question:

If KoiA calls a function on KoiB, how does the KFC know that KoiB even exists, and if it does, that the function KoiA is calling exists, and if it does, it has access to do so?

If you’ve already read the post dealing with my short introduction to my linking problem, my solution was Ponds. Pond files (.pond) are a collection of KoiFish source code files (.koi). Their purpose is to outline the program as a whole which could span many Kois, and therefore many Koi files.  The KoiFish Compiler takes the Pond file, and pulls in all the Koi files to scan and parse each.  I said last time that a language like  uses header files to accomplish this but that I had no desire to replicate these as they’re tedious and potentially confusing (to language newcomers).  So, the KFC does this for us!  After each Koi is scanned and parsed, the collection of parsed Kois are then consumed by the linker which extracts all Kois with their respective access along with all the functions that belong to that Koi and their respective access.

So where does this leave us?  Call Targets.

A call target is the Koi instance (or Koi itself in static cases) that when making a function call.  Here is some syntax showing function calls in KoiFish

#without call targets call SomeFunction; 
call SomeFunction :arg1 :arg2;

#with call targets
call SomeFunction@KoiB;
call SomeFunction@KoiB :arg1 :arg2;

#calls as expressions
def x = call SomeFunction@KoiB :arg;

In KoiFish, a function call can be both a statement or an expression. In the latter, as you would expect, the function call is evaluated and it’s result used in the left hand side.  The first two in the above example show function calls without call targets.  When the KFC comes across this, it will make the assumption that you’re referring to a function within the koi that is making the call.  I’ll talk about function arguments in more detail in a minute, but the second line shows a function (SomeFunction, in this case) being called with the arguments(arg1 and arg2). Next we see 2 functions with call targets using the ‘@’ operator, appropriately named the Call Target Operator. This simply means that you want to call a function on a specific target–In our example, we’re saying that we want to call KoiB‘s version of SomeFunction.  Lastly, we have an example of a function being used as an expression where the return value of KoiB‘s SomeFunction with :arg is evaluated and assigned to x.

Now that we know how to call functions in KoiFish, there’s a good chance that we need to handle function arguments.  The grammar rules of KoiFish demand that we signify an argument with an identifier with a ‘:’ prefix and that they are space delimited.  How much space is left up to programmer, however it’s a KoiFish standard to have a single space between arguments.  

When referring to an argument outside of a function call or in the definition of a function, the ‘:’ is dropped and just the identifier is used to refer to it.

This entry was posted in KoiFish and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s