Skip to content

Commit

Permalink
Make debug() a standard, dynamic @context_func
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanhogg committed Feb 6, 2024
1 parent fa50520 commit c2f593e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/flitter/language/functions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def context_func(func):
return func


@context_func
def debug(Context context, Vector value):
context.logs.add(value.repr())
return value


cdef class Uniform(Vector):
def __cinit__(self, value=None):
self._hash = self.hash(True)
Expand Down Expand Up @@ -916,6 +922,7 @@ STATIC_FUNCTIONS = {
}

DYNAMIC_FUNCTIONS = {
'debug': Vector(debug),
'counter': Vector(counter),
'csv': Vector(read_csv),
'read': Vector(read_text),
Expand Down
17 changes: 1 addition & 16 deletions src/flitter/language/vm.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ logger = name_patch(logger, __name__)

cdef const char* ContextFunc = "context_func\0"

cdef dict dynamic_builtins = DYNAMIC_FUNCTIONS
cdef dict static_builtins = {
'true': true_,
'false': false_,
Expand All @@ -46,18 +47,6 @@ cdef dict static_builtins = {
static_builtins.update(STATIC_FUNCTIONS)
static_builtins.update(NOISE_FUNCTIONS)


def debug(value):
return value


cdef object _debug_func = debug

cdef dict dynamic_builtins = {
'debug': Vector(_debug_func),
}
dynamic_builtins.update(DYNAMIC_FUNCTIONS)

cdef dict all_builtins = {}
all_builtins.update(dynamic_builtins)
all_builtins.update(static_builtins)
Expand Down Expand Up @@ -640,10 +629,6 @@ cdef inline void call_helper(Context context, VectorStack stack, object function
assert lnames.top == lnames_top, "Bad function return lnames"
drop(lnames, m)
context.path = saved_path
elif function is _debug_func and n == 1 and kwargs is None:
obj = PyTuple_GET_ITEM(args, 0)
PySet_Add(context.logs, (<Vector>obj).repr())
push(stack, <Vector>obj)
else:
if PyObject_HasAttrString(function, ContextFunc):
context_args = PyTuple_New(n+1)
Expand Down

0 comments on commit c2f593e

Please sign in to comment.