aboutsummaryrefslogtreecommitdiffstats
path: root/main.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-01-31 13:54:19 +0000
committers-ol <s-ol@users.noreply.github.com>2020-01-31 13:54:19 +0000
commit227c2f0ed83dda049173700ebfa39b664cc84065 (patch)
tree38057dfb393a89f7de6b8fdeb822adac8e34e222 /main.moon
parentmore types &c (diff)
downloadalive-227c2f0ed83dda049173700ebfa39b664cc84065.tar.gz
alive-227c2f0ed83dda049173700ebfa39b664cc84065.zip
comments, actual working things
Diffstat (limited to 'main.moon')
-rw-r--r--main.moon82
1 files changed, 7 insertions, 75 deletions
diff --git a/main.moon b/main.moon
index a301101..9d15f34 100644
--- a/main.moon
+++ b/main.moon
@@ -1,20 +1,7 @@
-lfs = require 'lfs'
sleep = require 'sleep'
-import program from require 'parsing'
+import Copilot from require 'copilot'
-filename = arg[1]
-
-slurp = (file) ->
- file = io.open file, 'r'
- with file\read '*all'
- file\close!
-
-spit = (file, str) ->
- file = io.open file, 'w'
- file\write str
- file\close!
-
-class Runtime
+class Environment
spawn: (sexpr) =>
print "spawning [#{sexpr.tag}]"
@@ -24,64 +11,9 @@ class Runtime
destroy: (sexpr) =>
print "destroying [#{sexpr.tag}]"
-runtime = Runtime!
-
-class Registry
- new: =>
- @last_tag = 0
- @map = {}
-
- spawn: (sexpr) =>
- @last_tag += 1
-
- sexpr.tag or= @last_tag
- @map[sexpr.tag] = sexpr
-
- runtime\spawn sexpr
- sexpr.tag
-
- patch: (sexpr) =>
- old = @map[sexpr.tag]
-
- if not old
- return @spawn sexpr
-
- @map[sexpr.tag] = sexpr
-
- runtime\patch sexpr, old
- sexpr.tag
-
- patch_root: (root) =>
- seen = {}
-
- for sexpr in root\walk_sexpr!
- tag = if not sexpr.tag
- @spawn sexpr
- else
- @patch sexpr
- seen[tag] = true
-
- for tag, expr in pairs @map
- if not seen[tag]
- runtime\destroy expr
- @map[tag] = nil
-
-registry = Registry!
-last_modification = 0
-
-while true
- sleep 10
-
- { :mode, :modification } = (lfs.attributes filename) or {}
- if mode != 'file'
- return
-
- if last_modification >= modification
- continue
-
- last_modification = modification
-
- root = assert (program\match slurp filename), "error parsing"
- registry\patch_root root
+env = Environment!
+copilot = Copilot arg[1], env
- spit filename, root\stringify!
+while True
+ sleep 0.01
+ copilot\patch!