Class: Builder

Inherits:
Object show all
Includes:
RubyHelpers
Defined in:
lib/ruby_vm.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.set_globals(b) ⇒ Object



29
30
31
32
33
34
# File 'lib/ruby_vm.rb', line 29

def self.set_globals(b)
  @@stack = b.alloca(VALUE, 100)
  @@stack_ptr = b.alloca(P_VALUE, 0)
  b.store(@@stack, @@stack_ptr)
  @@locals = b.alloca(VALUE, 100)
end

Instance Method Details

#localsObject



71
72
73
# File 'lib/ruby_vm.rb', line 71

def locals
  @@locals
end

#peek(n = 1) ⇒ Object



58
59
60
61
62
# File 'lib/ruby_vm.rb', line 58

def peek(n = 1)
  sp = load(stack_ptr)
  peek_sp = gep(sp, (-n).llvm)
  load(peek_sp)
end

#popObject



51
52
53
54
55
56
# File 'lib/ruby_vm.rb', line 51

def pop
  sp = load(stack_ptr)
  new_sp = gep(sp, -1.llvm)
  store(new_sp, stack_ptr)
  load(new_sp)
end

#push(val) ⇒ Object



44
45
46
47
48
49
# File 'lib/ruby_vm.rb', line 44

def push(val)
  sp = load(stack_ptr)
  store(val, sp)
  new_sp = gep(sp, 1.llvm)
  store(new_sp, stack_ptr)
end

#stackObject



36
37
38
# File 'lib/ruby_vm.rb', line 36

def stack
  @@stack
end

#stack_ptrObject



40
41
42
# File 'lib/ruby_vm.rb', line 40

def stack_ptr
  @@stack_ptr
end

#topn(n) ⇒ Object



64
65
66
67
68
69
# File 'lib/ruby_vm.rb', line 64

def topn(n)
  sp = load(stack_ptr)
  idx = sub((-1).llvm(Type::Int32Ty), n)
  top_sp = gep(sp, idx)
  load(top_sp)
end