Functions and Function Calls

Registered by Eike

Description how Siml functions work on the Python level.

Blueprint information

Status:
Complete
Approver:
None
Priority:
Essential
Drafter:
Eike
Direction:
Approved
Assignee:
Eike
Definition:
Obsolete
Series goal:
Accepted for trunk
Implementation:
Informational Informational
Milestone target:
None
Completed by
Eike

Related branches

Sprints

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: UnknownArgumentsException. The interpreter will then create an unevaluated function call (or operator).
    - 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 UnknownArgumentsException must be known to the code generator.

Arguments are parsed with the interpreter.Argument class.
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://docs.python.org/reference/datamodel.html#emulating-numeric-types

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://codespeak.net/pypy/dist/pypy/doc/interpreter.html#function-and-method-classes

PyPy has an object that stores the arguments of a function definition, and that parses these arguments when a function call is performed:
http://codespeak.net/pypy/dist/pypy/interpreter/argument.py

(?)

Work Items

Dependency tree

* Blueprints in grey have been implemented.

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.