Skip to content

Instantly share code, notes, and snippets.

@gingerBill
Last active June 26, 2017 14:55
Show Gist options
  • Save gingerBill/5b620b50a02930f4961075e3b4fd3e17 to your computer and use it in GitHub Desktop.
Save gingerBill/5b620b50a02930f4961075e3b4fd3e17 to your computer and use it in GitHub Desktop.
Jai-like Syntax Solution for Foreign Procedures
I'm using `proc` as a prefix to remove ambiguity in the syntax. The current syntax is ambiguous.
(int) // Is this a procedure that takes an int or is it just an int?
Current Jai Syntax:
name :: proc(); // type
name :: proc() {}; // declaration
name :: proc() #foreign lib; // foreign declaration
This syntax fails if you want have foreign variables too. Foreign variables would not have a consistent syntax.
// Example:
#foreign(lib, "name") var: type;
In order to make the syntax consistent you need the ability to state that that expression is a procedure literal without a body rather than a procedure type.
I propose the following:
name :: proc(); // Procedure type
name :: proc() {}; // Procedure literal with a body
name :: proc() ---; // Procedure literal without a body
Specifying the linking name can be done with a prefix tag and its library in a surrounding foreign block:
foreign lib {
#link_name "CloseHandle"
close_handle :: proc(h: Handle) -> i32;
}
This is syntax can be extended to foreign variables too:
foreign libc {
errno: i32;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment