aboutsummaryrefslogtreecommitdiffstats
path: root/alv/init.moon
blob: 0637c5cf39db9dce2ed60cca1d3c536f51058ac3 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
----
-- `alive` public API.
--
-- @module init
if _VERSION == 'Lua 5.1'
  export assert
  assert = (a, msg, ...) ->
    if not a
      error msg
    a, msg, ...

cycle = require 'alv.cycle'

version = require 'alv.version'
import Logger from require 'alv.logger'

import T, Primitive, Struct, Array from require 'alv.type'
import Constant, SigStream, EvtStream from require 'alv.result'
import RTNode from require 'alv.rtnode'
import Scope from require 'alv.scope'
import Error from require 'alv.error'
import Registry, SimpleRegistry from require 'alv.registry'
import Tag from require 'alv.tag'

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

cycle\resolve!

globals = require 'alv.builtins'

cycle\resolve!

--- exports
-- @table exports
-- @tfield version version
-- @tfield Constant Constant
-- @tfield SigStream SigStream
-- @tfield EvtStream EvtStream
-- @tfield type.T T
-- @tfield type.Primitive Primitive
-- @tfield type.Array Array
-- @tfield type.Struct Struct
-- @tfield RTNode RTNode
-- @tfield Cell Cell
-- @tfield RootCell RootCell
-- @tfield Scope Scope
-- @tfield Error Error
-- @tfield Registry Registry
-- @tfield Tag Tag
-- @tfield Logger Logger
-- @tfield Scope globals global definitons
-- @tfield parse function to turn a `string` into a root `Cell`
{
  :version

  :Constant, :SigStream, :EvtStream
  :Cell, :RootCell
  :RTNode, :Scope, :Error

  :T, :Primitive, :Struct, :Array

  :Registry, :SimpleRegistry, :Tag
  :Logger

  globals: globals!

  parse: (str) ->
    assert (program\match str), Error 'syntax', "failed to parse"

  eval: (str, inject) ->
    scope = Scope globals!
    scope\use inject if inject

    ast = assert (program\match str), "failed to parse"
    result = ast\eval scope
    result\const!
}