Functions and Function Calls
Description how Siml functions work on the Python level.
Whiteboard
Even newer proposal:
Implement apply(...) function that interprets SIML-functions. SIML-functions would become pure data; making them callable could be done as a pure convenience.
New proposed state:
Callable protocol:
- All functions inherit from a common base class: *CallableObject*
- They have a Python method __call__(self, *args, **kwargs)
- Siml objects (InterpreterObject, ast.Node) are passed as arguments.
- The “__call__” method performs the function's algorithm.
- Unknown values, unevaluated expressions: The “__call__” method must be able to work with unknowns.
- Raise exception: UnknownArgument
- Return an unevaluated expression (function call, simplified expression)
Unevaluated function calls in a expression statement, or in an assignment are stored for the code generator. The functions used in unevaluated expressions must therefore be functions that the code generator knows. This also implies: Functions that raise UnknownArgument
Arguments are parsed with the interpreter.
The class works with positional and keyword arguments; it does type checking if types are given.
Callable objects can be used naturally in Python code, for writing good looking test cases:
w_sin(W_Float(0.0)) == W_Float(0.0)
Operators are implemented with specially named methods like in Python. For details see:
http://
Classes are no longer callable in Siml, they can only appear in 'data' statements. (The class objects are however callable from Python.)
---
References:
Description from PyPy with some useful ideas:
http://
PyPy has an object that stores the arguments of a function definition, and that parses these arguments when a function call is performed:
http://
Work Items
Dependency tree
* Blueprints in grey have been implemented.