summaryrefslogtreecommitdiff
path: root/actinide/builtin.py
diff options
context:
space:
mode:
Diffstat (limited to 'actinide/builtin.py')
-rw-r--r--actinide/builtin.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/actinide/builtin.py b/actinide/builtin.py
index 06623b3..68ed698 100644
--- a/actinide/builtin.py
+++ b/actinide/builtin.py
@@ -2,8 +2,24 @@
from functools import wraps
+dunder_names = {
+ '__add__': '+',
+ '__sub__': '-',
+ '__mul__': '*',
+ '__floordiv__': '/',
+ '__eq__': '=',
+ '__ne__': '!=',
+ '__lt__': '<',
+ '__le__': '<=',
+ '__gt__': '>',
+ '__ge__': '>',
+}
+
# Derives the lisp name of a python function or method handle, as follows:
#
+# * Python dunder names are translated to their corresponding operator or
+# symbol usind the ``dunder_names`` table.
+#
# * A trailing '_p' in the Python name is converted into a question mark in the
# lisp name.
#
@@ -17,6 +33,9 @@ def lisp_name(fn):
if name == '<lambda>':
return None
+ if name in dunder_names:
+ return dunder_names[name]
+
# Trailing _p is a predicate, translate to ?
if name.endswith('_p'):
name = name[:-2] + '?'
@@ -42,3 +61,27 @@ def wrap_fn(fn):
def wrapper(*args):
return fn(*args),
return wrapper
+
+def make_registry():
+ bindings = []
+ voids = []
+ fns = []
+ builtins = []
+
+ def bind(name, val):
+ bindings.append((name, val))
+ return val
+
+ def void(f):
+ voids.append(f)
+ return f
+
+ def fn(f):
+ fns.append(f)
+ return f
+
+ def builtin(f):
+ builtins.append(f)
+ return f
+
+ return bindings, voids, fns, builtins, bind, void, fn, builtin