From e6ad30365e5c191ad0cb4b98f0d543414b8be7ef Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 10 Feb 2020 16:12:53 +0100 Subject: closures --- core/cell.moon | 2 +- core/invoke.moon | 6 +++--- init.moon | 1 - registry.moon | 1 + test.alv | 18 ++++++++++-------- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/cell.moon b/core/cell.moon index 1a25c0a..ae6eea4 100644 --- a/core/cell.moon +++ b/core/cell.moon @@ -36,7 +36,7 @@ class Cell @tag = cell.tag -- for writing back to file clone: (prefix) => - tag = Const.sym prefix\getc! .. @tag\getc! + tag = Const.sym prefix\getc! .. '.' .. @tag\getc! children = [child\clone prefix for child in *@children] Cell tag, children, @white diff --git a/core/invoke.moon b/core/invoke.moon index 6458f2b..9955bce 100644 --- a/core/invoke.moon +++ b/core/invoke.moon @@ -45,9 +45,9 @@ class fn_invoke extends Action true - eval: (scope, tail) => + eval: (outer_scope, tail) => assert @head.type == 'fndef', "cant fn-invoke #{@head}" - { :params, :body } = @head\getc! + { :params, :body, :scope } = @head\getc! assert #params == #tail, "argument count mismatch in #{@head}" @@ -56,7 +56,7 @@ class fn_invoke extends Action for i=1,#params name = params[i]\getc! argm = tail[i] - fn_scope\set name, L\push argm\eval, scope, @registry + fn_scope\set name, L\push argm\eval, outer_scope, @registry body = body\clone @tag diff --git a/init.moon b/init.moon index 5da1dd2..41acabe 100644 --- a/init.moon +++ b/init.moon @@ -25,7 +25,6 @@ delta = do if last target, current = (last + period), monotime! if current > target - print current, target L\warn 'Frame Skipped!' else sleep target - current diff --git a/registry.moon b/registry.moon index 7c03e1b..a946e9a 100644 --- a/registry.moon +++ b/registry.moon @@ -38,6 +38,7 @@ class Registry Const.num num eval: (ast) => + @map = {} -- in case we errored last time scope = Scope ast, @globals @root = ast\eval scope, @ diff --git a/test.alv b/test.alv index 9e7ad1f..6e4ee03 100644 --- a/test.alv +++ b/test.alv @@ -1,10 +1,12 @@ -([2]use ([1]require 'math')) -([4]use ([3]require 'osc')) -([6]use ([5]require 'time')) +([1]use ([2]require 'math')) +([3]use ([4]require 'osc')) +([5]use ([6]require 'time')) -([17]def sin-lfo ([13]fn ([11]f) - ([12]lfo f 'sin'))) +([7]def make-lfo ([8]fn (type) + ([11]fn ([9]f) ([10]lfo ([31]* f 0.5) type)))) -#([19]out '127.0.0.1' 9000 '/param/radius/set' ([18]lfo 0.2 'sin')) -([8]out '127.0.0.1' 9000 '/param/radius/set' ([18]sin-lfo 0.1)) -([10]out '127.0.0.1' 9000 '/param/offset/set' ([15]sin-lfo 1)) +([12]def sin-lfo ([13]make-lfo 'sin')) + + +([14]out '127.0.0.1' 9000 '/param/radius/set' ([15]sin-lfo 0.05)) +([16]out '127.0.0.1' 9000 '/param/offset/set' ([17]sin-lfo 0.2)) -- cgit v1.2.3