Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Functions / Closures #16

Open
9 tasks
sunjay opened this issue Jan 22, 2017 · 0 comments
Open
9 tasks

Functions / Closures #16

sunjay opened this issue Jan 22, 2017 · 0 comments

Comments

@sunjay
Copy link
Owner

sunjay commented Jan 22, 2017

Functions can only be defined at the top level of modules and have access to global variables and their function arguments.

Closures are anonymous functions that capture values of variables from their outer scope(s).

Without a more advanced jump instruction, we really have no choice but to inline all functions. Recursive functions cannot be inlined, so we will have to implement some sort of tail recursion or something for those (or disallow recursion completely).

Low priority until MVP.

  • Disallow code outside of a function, make main() the entry point
  • Automatically declaring stdin/stdout may not be viable anymore because that runs code and allocates memory so we may have to define some std functions to create them just like in Rust
  • Function type definitions in grammar
  • Store literals in a temporary memory location when passing to non-built-in functions
  • Store functions in an IR that is independent of the position of each of the function's arguments
  • Use TypeIds to make sure the types used in that function cannot be accidentally overridden by later declarations
    • If Foo is declared in the same module as a function and then another Foo is declared in another module, the first Foo should still be used in the function no matter what context the function is called in
  • Make sure functions can be declared in variables
  • Error when wrong number of arguments is applied to a method
  • Functions can be assigned to variables with type fn(foo) -> ReturnType like Rust
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant