aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-02-02 18:34:18 +0000
committers-ol <s-ol@users.noreply.github.com>2020-02-02 18:35:58 +0000
commit1fb8e4b2e621128e043ae4091f3e25d56b9d7cc2 (patch)
tree9b95ff4e17784aaee4c14372741f2a65d76d02fb /lib
parentadd logger (diff)
downloadalive-1fb8e4b2e621128e043ae4091f3e25d56b9d7cc2.tar.gz
alive-1fb8e4b2e621128e043ae4091f3e25d56b9d7cc2.zip
clean out old patching implementation
Diffstat (limited to 'lib')
-rw-r--r--lib/builtin.moon70
-rw-r--r--lib/debug.moon2
2 files changed, 47 insertions, 25 deletions
diff --git a/lib/builtin.moon b/lib/builtin.moon
index e7586da..369c3b3 100644
--- a/lib/builtin.moon
+++ b/lib/builtin.moon
@@ -1,29 +1,51 @@
-import Const from require 'base'
+import Macro, 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
+class def extends Macro
+ expand: (scope) =>
+ assert #@node > 2, "'def' requires at least 3 arguments"
+ assert #@node % 2 == 1, "'def' requires an even number of arguments"
+
+ L\trace @
+ L\push ->
+ for i=2,#@node,2
+ name, val = @node[i], @node[i+1]
+ assert name.atom_type == 'sym', "'def's argument ##{i} has to be a symbol"
+ val\expand @node.scope
+ scope\set name.raw, val.value
+
+ nil
+
+class _require extends Macro
+ expand: (scope) =>
+ assert #@node == 2, "'require' takes only one parameter"
+
+ L\trace @
+ L\push ->
+ for child in *@node[2,]
+ child\expand @node.scope
+
+ name = @node\tail!
assert name.type == 'str', "'require' only works on strings"
- xpr.value = Const 'scope', Scope.from_table require "lib.#{name\getc!}"
-}
+ L\trace @, "loading module #{name}"
+ scope = Scope.from_table require "lib.#{name\getc!}"
+ Const 'scope', scope
+
+class use extends Macro
+ expand: (scope) =>
+ L\trace @
+ L\push ->
+ for child in *@node[2,]
+ value = child\expand @node.scope
+ L\trace @, "merging #{value} into #{scope}"
+ assert value.type == 'scope', "'use' only works on scopes"
+ scope\use value\getc!
-{ k, Const 'macro', v for k, v in pairs module }
+ nil
+
+{
+ :def
+ require: _require
+ :use
+}
diff --git a/lib/debug.moon b/lib/debug.moon
index c2d0d52..3b5df47 100644
--- a/lib/debug.moon
+++ b/lib/debug.moon
@@ -5,7 +5,7 @@ class out extends Op
@name = name\getc!
update: =>
- print "#{@name} << ", @chld\get!
+ L\print "@name", @chld\get!
{
:out