Module: Mulang::Sexp

Defined in:
lib/mulang/sexp.rb

Instance Method Summary collapse

Instance Method Details

#application(name, args) ⇒ Object



72
73
74
# File 'lib/mulang/sexp.rb', line 72

def application(name, args)
  ms :Application, [ms(:Reference, name), args]
end

#binary_application(operator, left, right) ⇒ Object



76
77
78
# File 'lib/mulang/sexp.rb', line 76

def binary_application(operator, left, right)
  application operator, [left, right]
end

#callable(type, name, args, body) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mulang/sexp.rb', line 50

def callable(type, name, args, body)
  {
      tag: type,
      contents: [
          name,
          [
              [ args, {tag: :UnguardedBody, contents: body }]
          ]
      ]
  }
end

#ms(tag, *contents) ⇒ Object

Basic S-expression



6
7
8
9
10
11
12
13
14
# File 'lib/mulang/sexp.rb', line 6

def ms(tag, *contents)
  if contents.empty?
    {tag: tag}
  elsif contents.size == 1
    {tag: tag, contents: contents.first}
  else
    {tag: tag, contents: contents}
  end
end

#noneObject



32
33
34
# File 'lib/mulang/sexp.rb', line 32

def none
  ms(:None)
end

#primitive(operator) ⇒ Object

Basic elements



18
19
20
# File 'lib/mulang/sexp.rb', line 18

def primitive(operator)
  ms(:Primitive, operator)
end

#primitive_method(name, args, body) ⇒ Object



46
47
48
# File 'lib/mulang/sexp.rb', line 46

def primitive_method(name, args, body)
  callable :PrimitiveMethod, name, args, body
end

#primitive_send(sender, op, args) ⇒ Object

Applications



64
65
66
# File 'lib/mulang/sexp.rb', line 64

def primitive_send(sender, op, args)
  ms(:Send, sender, primitive(op), args)
end

#sequence(*contents) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/mulang/sexp.rb', line 22

def sequence(*contents)
  if contents.empty?
    none
  elsif contents.size == 1
    contents[0]
  else
    ms(:Sequence, *contents)
  end
end

#simple_function(name, args, body) ⇒ Object

Callables



38
39
40
# File 'lib/mulang/sexp.rb', line 38

def simple_function(name, args, body)
  callable :Function, name, args, body
end

#simple_method(name, args, body) ⇒ Object



42
43
44
# File 'lib/mulang/sexp.rb', line 42

def simple_method(name, args, body)
  callable :Method, name, args, body
end

#simple_send(sender, message, args) ⇒ Object



68
69
70
# File 'lib/mulang/sexp.rb', line 68

def simple_send(sender, message, args)
  ms(:Send, sender, ms(:Reference, message), args)
end