Skip to content

Commit eb05c3b

Browse files
committed
fix bug in while expr
1 parent 0bfab5d commit eb05c3b

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

TUTORIAL.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ class String
6262
def blank?(string)
6363
char *s = string
6464
int i = 0
65+
int a = string.size
6566

66-
while i < string.size do
67+
while i < a do
6768
return false if s[i] != ' '
69+
i += 1
6870
end
6971

7072
return true

lib/rubex/ast/statement/while.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def initialize(expr, statements, location)
1010

1111
def analyse_statement(local_scope)
1212
@expr.analyse_types local_scope
13-
@expr.release_temps local_scope
13+
@expr.allocate_temps local_scope
1414
@statements.each do |stat|
1515
stat.analyse_statement local_scope
1616
end

spec/examples_spec.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require 'spec_helper'
22

3-
describe Rubex do
3+
describe Rubex, hell: true do
44
test_case = 'examples'
55

6-
examples = ['rcsv', 'array_to_hash'].each do |example|
6+
examples = ['rcsv', 'array_to_hash', "blank"].each do |example|
77
context "Case: #{test_case}/#{example}" do
88
before do
99
@path = path_str test_case, example
@@ -41,6 +41,11 @@ def array_to_hash
4141
expect(a.each_with_index.to_h).to eq(Array2Hash.convert(a))
4242
end
4343

44+
def blank
45+
a = " "
46+
expect(a.blank?(a)).to eq(true)
47+
end
48+
4449
setup_and_teardown_compiled_files(test_case, example) do |dir|
4550
require_relative "#{dir}/#{example}/#{example}.#{os_extension}"
4651
self.send(example.to_sym)

spec/fixtures/examples/blank.rubex

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class String
2+
def blank?(string)
3+
char *s = string
4+
int i = 0
5+
int a = string.size
6+
7+
while i < a do
8+
return false if s[i] != ' '
9+
i += 1
10+
end
11+
12+
return true
13+
end
14+
end

0 commit comments

Comments
 (0)