Class: PLang::VM::PObject

Inherits:
Object
  • Object
show all
Defined in:
lib/vm/pobject.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, params) ⇒ PObject

Returns a new instance of PObject.



7
8
9
10
# File 'lib/vm/pobject.rb', line 7

def initialize(id, params)
  @id = id
  @params = params
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/vm/pobject.rb', line 4

def id
  @id
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/vm/pobject.rb', line 5

def params
  @params
end

Instance Method Details

#to_sObject



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
# File 'lib/vm/pobject.rb', line 12

def to_s
  case @id
    when :integer, :decimal, :char, :string, :boolean
      return params[0].to_s
    when :empty
      return "'()"
    when :list
      str = "'("
      params = @params
      ok = false
      while params and params != []
        str += "#{params[0].to_s}, "
        params = params[1].params
        ok = true
      end
      if ok
        str[-2] = ')'
      else
        str += ')'
      end
      return str.strip
    else
      str = "{#{@id}"
      if @params.length > 0
        str += ": "
        @params.each do |param|
          str += "#{param.to_s}, "
        end
        str[-2] = "}"
      else
        str += "}"
      end
      return str.strip
  end
end