aboutsummaryrefslogtreecommitdiffstats
path: root/core/init.moon
blob: c8f02653ed3c7830de490d69ef6a2b742964d1a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
L or= setmetatable {}, __index: => ->

import Op, Action, FnDef from require 'core.base'

import Const, load_ from require 'core.const'
import Scope from require 'core.scope'
load_!

import Registry from require 'core.registry'

import Cell, RootCell from require 'core.cell'
import cell, program from require 'core.parsing'

globals = Scope.from_table require 'core.builtin'

{
  :Const, :Cell, :RootCell
  :Op, :Action, :FnDef
  :Scope

  :Registry
  :globals

  parse: program\match
  eval: do
    class BuiltinRegistry
      new: =>
        @cnt = 1

      init: (tag, expr) =>
        tag\set @cnt
        @cnt += 1

      last: (index) =>
      replace: (index, expr) =>

    registry = BuiltinRegistry!

    (str, inject) ->
      scope = Scope nil, globals
      scope\use inject if inject

      ast = assert (cell\match str), "failed to parse: #{str}"
      Const.wrap ast\eval scope, registry
}