diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-02-01 23:51:40 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-02-01 23:55:30 +0000 |
| commit | 177cd265947bfd9db20ad1a99ae07c76b6b4f147 (patch) | |
| tree | 49af71e06770925abb0ab1fd2e89be077281b74c /lib | |
| parent | first-class scopes (diff) | |
| download | alive-177cd265947bfd9db20ad1a99ae07c76b6b4f147.tar.gz alive-177cd265947bfd9db20ad1a99ae07c76b6b4f147.zip | |
macros and scopes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/builtin.moon | 29 | ||||
| -rw-r--r-- | lib/gui.moon | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/builtin.moon b/lib/builtin.moon new file mode 100644 index 0000000..e7586da --- /dev/null +++ b/lib/builtin.moon @@ -0,0 +1,29 @@ +import Const from require 'base' +import Scope from require 'scope' + +module = { + def: (scope, xpr) -> + assert #xpr > 2, "'def' requires at least 3 arguments" + assert #xpr % 2 == 1, "'def' requires an even number of arguments" + for i=2,#xpr,2 + assert xpr[i].atom_type == 'sym', "'def's argument ##{i} has to be a symbol" + xpr[i+1]\expand xpr.scope + scope\set xpr[i].raw, xpr[i+1].value + + use: (scope, xpr) -> + for value in *xpr[2,] + value\expand xpr.scope + assert value.value.type == 'scope', "'use' only works on scopes" + scope\use value.value\getc! + + require: (scope, xpr) -> + assert #xpr == 2, "'require' takes only one parameter" + + xpr[2]\expand xpr.scope + name = xpr[2].value + assert name.type == 'str', "'require' only works on strings" + + xpr.value = Const 'scope', Scope.from_table require "lib.#{name\getc!}" +} + +{ k, Const 'macro', v for k, v in pairs module } diff --git a/lib/gui.moon b/lib/gui.moon index 979854f..20d3bcc 100644 --- a/lib/gui.moon +++ b/lib/gui.moon @@ -1,5 +1,6 @@ { graphics: lg } = love import Op from require 'base' +import Registry from require 'registry' import Copilot from require 'copilot' class out extends Op @@ -31,6 +32,7 @@ class out extends Op lg.print name, x, MARGIN + HEIGHT + MARGIN x += WIDTH + MARGIN +env = Registry! copilot = Copilot arg[#arg], env love.update = (dt) -> |
