Module: Mulang::Ruby::Sexp

Included in:
AstProcessor
Defined in:
lib/mulang/ruby/sexp.rb

Instance Method Summary collapse

Instance Method Details

#ms(tag, *contents) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/mulang/ruby/sexp.rb', line 13

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

#mu_method(tag, args, body) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/mulang/ruby/sexp.rb', line 35

def mu_method(tag, args, body)
  {
    tag: tag,
    contents: [
      [ args, {tag: :UnguardedBody, contents: body }]
    ]
  }
end

#sequence(*contents) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/mulang/ruby/sexp.rb', line 3

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

#simple_method(name, args, body) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mulang/ruby/sexp.rb', line 23

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

#simple_send(sender, message, args) ⇒ Object



44
45
46
# File 'lib/mulang/ruby/sexp.rb', line 44

def simple_send(sender, message, args)
  ms(:Send, sender, {tag: :Reference, contents: message}, args)
end