Class: RBlade::CompilesStatements::CompilesStacks

Inherits:
Object
  • Object
show all
Defined in:
lib/rblade/compiler/statements/compiles_stacks.rb

Instance Method Summary collapse

Constructor Details

#initializeCompilesStacks

Returns a new instance of CompilesStacks.



4
5
6
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 4

def initialize
  @push_counter = 0
end

Instance Method Details

#compileEndPrepend(args) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 26

def compileEndPrepend args
  unless args.nil?
    raise StandardError.new "End prepend statement: wrong number of arguments (given #{args&.count}, expecting 0)"
  end

  @push_counter -= 1

  "RBlade::StackManager.prepend(_p_#{@push_counter + 1}, _out);_out=_p_#{@push_counter + 1}_b;"
end

#compileEndPrependIf(args) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 44

def compileEndPrependIf args
  unless args.nil?
    raise StandardError.new "End prepend if statement: wrong number of arguments (given #{args.count}, expecting 0)"
  end

  "end;" + compileEndPush(nil)
end

#compileEndPush(args) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 70

def compileEndPush args
  unless args.nil?
    raise StandardError.new "End push statement: wrong number of arguments (given #{args.count}, expecting 0)"
  end

  @push_counter -= 1

  "RBlade::StackManager.push(_p_#{@push_counter + 1}, _out);_out=_p_#{@push_counter + 1}_b;"
end

#compileEndPushIf(args) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 80

def compileEndPushIf args
  unless args.nil?
    raise StandardError.new "End push if statement: wrong number of arguments (given #{args.count}, expecting 0)"
  end

  "end;" + compileEndPush(nil)
end

#compilePrepend(args) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 16

def compilePrepend args
  if args&.count != 1
    raise StandardError.new "Prepend statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  @push_counter += 1

  "_p_#{@push_counter}=#{args[0]};_p_#{@push_counter}_b=_out;_out='';"
end

#compilePrependIf(args) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 36

def compilePrependIf args
  if args&.count != 2
    raise StandardError.new "Prepend if statement: wrong number of arguments (given #{args&.count}, expecting 2)"
  end

  "if #{args[0]};" + compilePrepend([args[1]])
end

#compilePush(args) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 52

def compilePush args
  if args&.count != 1
    raise StandardError.new "Push statement: wrong number of arguments (given #{args&.count}, expecting 1)"
  end

  @push_counter += 1

  "_p_#{@push_counter}=#{args[0]};_p_#{@push_counter}_b=_out;_out='';"
end

#compilePushIf(args) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 62

def compilePushIf args
  if args&.count != 2
    raise StandardError.new "Push if statement: wrong number of arguments (given #{args&.count || 0}, expecting 2)"
  end

  "if #{args[0]};" + compilePush([args[1]])
end

#compileStack(args) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/rblade/compiler/statements/compiles_stacks.rb', line 8

def compileStack args
  if args&.count != 1
    raise StandardError.new "Stack statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "RBlade::StackManager.initialize(#{args[0]}, _out);_stacks.push(#{args[0]});_out = '';"
end