Skip to content

Commit 091ad5c

Browse files
committed
Fix add with two carries
1 parent d8621dc commit 091ad5c

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

sedlisp.sed

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ s/\([^ ()]\)(/\1 (/g
1919

2020
s/ */ /g
2121

22-
## i *** loop ***
23-
## p
24-
## x
25-
## i *** stack ***
26-
## p
27-
## x
22+
# i *** loop ***
23+
# p
24+
# x
25+
# i *** stack ***
26+
# p
27+
# x
2828

2929
#s/( *)/nil/g
3030

@@ -322,9 +322,9 @@ s/\n.*//
322322
s/\(.*\) \([0-9]*\)\(\n\(-\)\)\?/\1@ \2@ 9876543210 9876543210\n\4/
323323

324324
:add_loop
325-
s/\(.\)@\(.*\)\(.\)@\(.\)\? \(.*\1\(.*\)\) .*\3\(.*\)\n/@\2; \4\6\7\5 \5 \5\n/
325+
s/\(.\)@\(.*\)\(.\)@\(.\)\? \(.*\1\(.*\)\) .*\(\3.*\)\n/@\2; \4\6\7\5 \5 \5\n/
326326

327-
s/; .\{9\}\(.\)\([0-9]\{9\}\([0-9]\)\)\?[0-9]* \(.*\)\n\(.*\)/@\3 \4\n\1\5/
327+
s/; .\{10\}\(.\)\([0-9]\{9\}\([0-9]\)\)\?[0-9]* \(.*\)\n\(.*\)/@\3 \4\n\1\5/
328328

329329
/^@ @/{
330330
s/@ @. .*\n/\n1/

test.l

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(+ 98 2 )
44
(+ 38 2 )
55
(+ -19 -99)
6+
(+ 99 99)
67

78
(- 3 -17)
89
(- -3 29)
@@ -49,7 +50,7 @@
4950

5051
(+(- 9 2) 1)
5152

52-
(- (- 9 2) (- 3 7))
53+
(- (- 9 2) (- 3 6))
5354

5455
(+ (+ (+ 1 2) 3) 4)
5556
(+ 1 (+ 2 (+ 3 4)))
@@ -117,6 +118,7 @@
117118
(cons 42 (quote ()))
118119
(cons 1 (quote (2)))
119120
(cons (quote (1 2)) (quote (3 ((5 6)) 4)))
121+
(cons 2 (cons 3 ()))
120122

121123
(atom ())
122124
(atom nil)

test.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@
1313
end
1414

1515
ref_lisp = ARGV[0] || 'purelisp.rb'
16-
test_lisp = ARGV[1] || 'sedlisp.sed'
16+
test_lisp = ARGV[1]
17+
test_lisp ||= File.exist?('sedlisp.sed') ? 'sedlisp.sed' : 'beflisp.bef'
1718

1819
COMMANDS = {
1920
'purelisp.rb' => ['ruby', 'purelisp.rb'],
2021
'rblisp.rb' => ['ruby', 'rblisp.rb'],
2122
'sedlisp.sed' => ['sed', '-f', 'sedlisp.sed'],
23+
'lisp.bef' => ['./befunge', 'lisp.bef'],
24+
'beflisp.bef' => ['./befunge', 'beflisp.bef'],
25+
'lisp' => ['./lisp'],
26+
'makelisp.mk' => ['make', '-f', 'makelisp.mk'],
27+
'makelisp2.mk' => ['make', '-f', 'makelisp2.mk'],
2228
}
2329

2430
def getResult(cmd, line)
@@ -64,9 +70,9 @@ def getResult(cmd, line)
6470
end
6571

6672
expected = getResult(COMMANDS[ref_lisp], $eval_test ? line : orig)
67-
expected = expected.lines[-1].chomp
73+
expected = expected.lines.to_a[-1].to_s.chomp
6874
output = getResult(COMMANDS[test_lisp], line)
69-
actual = output.lines[-1].chomp
75+
actual = output.lines.to_a[-1].to_s.chomp
7076

7177
if expected == actual
7278
puts "#{orig}: OK (#{expected})"

0 commit comments

Comments
 (0)