befunge98 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/befunge98.gemspec +1 -1
- data/bin/befunge98 +1 -1
- data/lib/befunge98.rb +15 -15
- data/test.rb +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 820a474f794f67a9cbbacea6b3142d41bdc86783
|
4
|
+
data.tar.gz: fcfbaaf5cc90ad71f8cd6284ef7664091b9e68da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 751e2be52b36af30dcf99bb8c199f29c28150a9eff24d431aa19afc79f3dd01dfbdaa6464c03f179bffc20f5327c09400535d2c6c20ad77554665ce3175dd501
|
7
|
+
data.tar.gz: 4e9818eda68e4d969a6ac73d8d48207b48504f5c543e543acc67ac25806eed7a794dc187f9fa94bc344fe40ac90f3ab25d50569d7fb2dd842a799a90b58bd899
|
data/befunge98.gemspec
CHANGED
data/bin/befunge98
CHANGED
data/lib/befunge98.rb
CHANGED
@@ -18,24 +18,24 @@ def Befunge98 source, stdout = StringIO.new, stdin = STDIN
|
|
18
18
|
move = lambda do
|
19
19
|
y, x = y + dy, x + dx
|
20
20
|
next if sy + oy + y >= 0 && code[sy + oy + y] && sx + ox + x >= 0 && code[sy + oy + y][sx + ox + x]
|
21
|
-
top = code. index{ |l|
|
22
|
-
bottom = code.rindex{ |l|
|
23
|
-
left = code.map{ |l| l. index{ |c| c && c != 32 } }.compact.min
|
24
|
-
right = code.map{ |l| l.rindex{ |c| c && c != 32 } }.compact.max
|
25
|
-
STDERR.puts [
|
21
|
+
top = code. index{ |l| l.any?{ |i| i && i != 32 } }
|
22
|
+
bottom = code.rindex{ |l| l.any?{ |i| i && i != 32 } }
|
23
|
+
left = code.map{ |l| l && l. index{ |c| c && c != 32 } }.compact.min
|
24
|
+
right = code.map{ |l| l && l.rindex{ |c| c && c != 32 } }.compact.max
|
25
|
+
STDERR.puts [top..bottom, left..right, [y, x], [dy, dx], code].inspect if ENV["DEBUG"]
|
26
26
|
ty, tx = y, x
|
27
27
|
next if loop do
|
28
28
|
zy, zx = sy + oy + ty, sx + ox + tx
|
29
|
-
break unless
|
29
|
+
break unless top <= zy && zy <= bottom && left <= zx && zx <= right
|
30
30
|
break true if code[zy] && code[zy][zx] && code[zy][zx] != 32
|
31
31
|
ty, tx = ty + dy, tx + dx
|
32
32
|
end
|
33
33
|
ty, tx = y - dy, x - dx
|
34
34
|
loop do
|
35
|
-
STDERR.puts [ty, tx].inspect if ENV["DEBUG"]
|
36
35
|
zy, zx = sy + oy + ty, sx + ox + tx
|
37
|
-
break
|
38
|
-
|
36
|
+
break if dy > 0 && zy < top || dy < 0 && zy > bottom ||
|
37
|
+
dx > 0 && zx < left || dx < 0 && zx > right
|
38
|
+
y, x = ty, tx if code[zy] && code[zy][zx] && code[zy][zx] != 32 # TODO: should this execute if it's in a 'hole'?
|
39
39
|
ty, tx = ty - dy, tx - dx
|
40
40
|
end
|
41
41
|
end
|
@@ -47,13 +47,13 @@ def Befunge98 source, stdout = StringIO.new, stdin = STDIN
|
|
47
47
|
loop do
|
48
48
|
if iterate.zero?
|
49
49
|
move[]
|
50
|
-
char = get[]
|
51
50
|
else
|
52
51
|
iterate -= 1
|
53
52
|
end
|
53
|
+
char = get[]
|
54
54
|
STDERR.puts [[y, x], char.chr, stack].inspect if ENV["DEBUG"]
|
55
55
|
|
56
|
-
next stack << char if stringmode && char.chr != ?"
|
56
|
+
next stack << char if stringmode && char.chr != ?" # TODO: "SGML-style"
|
57
57
|
next unless (33..126).include? char
|
58
58
|
next if jump_over && char.chr != ?;
|
59
59
|
case char.chr
|
@@ -123,7 +123,7 @@ def Befunge98 source, stdout = StringIO.new, stdin = STDIN
|
|
123
123
|
code[sy + oy + y][sx + ox + x] = pop[]
|
124
124
|
when ?[ ; dy, dx = ds[(ds.index([dy, dx]) - 1) % 4]
|
125
125
|
when ?] ; dy, dx = ds[(ds.index([dy, dx]) + 1) % 4]
|
126
|
-
when ?w ; dy, dx = ds[(ds.index([dy, dx])
|
126
|
+
when ?w ; dy, dx = ds[(ds.index([dy, dx]) - (pop[] <=> pop[])) % 4]
|
127
127
|
when ?r ; reflect[]
|
128
128
|
when ?x ; dy, dx = [pop[], pop[]]
|
129
129
|
when ?j
|
@@ -131,14 +131,14 @@ def Befunge98 source, stdout = StringIO.new, stdin = STDIN
|
|
131
131
|
t.times{ move[] }
|
132
132
|
else
|
133
133
|
reflect[]
|
134
|
-
t.times{ move[] }
|
134
|
+
(-t).times{ move[] }
|
135
135
|
reflect[]
|
136
136
|
end
|
137
137
|
when ?k
|
138
138
|
iterate = pop[]
|
139
|
-
fail if char != 32 || char.chr != ?;
|
140
139
|
move[]
|
141
140
|
char = get[]
|
141
|
+
fail if char == 32 || char == ?;.ord
|
142
142
|
when ?{
|
143
143
|
toss = if 0 > n = pop[]
|
144
144
|
stack.concat [0] * -n
|
@@ -150,7 +150,7 @@ def Befunge98 source, stdout = StringIO.new, stdin = STDIN
|
|
150
150
|
ox += x + dx
|
151
151
|
oy += y + dy
|
152
152
|
stacks << stack = toss
|
153
|
-
when ?
|
153
|
+
when ?}
|
154
154
|
if 1 == stacks.size
|
155
155
|
reflect[]
|
156
156
|
elsif 0 > n = pop[]
|
data/test.rb
CHANGED
@@ -121,6 +121,33 @@ describe "lib" do
|
|
121
121
|
assert_equal 0, Befunge98(?@).exitcode
|
122
122
|
end
|
123
123
|
|
124
|
+
it "n" do
|
125
|
+
assert_equal [], Befunge98("1n@", StringIO.new, StringIO.new).stack
|
126
|
+
end
|
127
|
+
it "'" do
|
128
|
+
assert_equal "'@".bytes, Befunge98("'''@@").stack
|
129
|
+
end
|
130
|
+
it "s with 1 and \"" do
|
131
|
+
assert_equal "@1s\1s\0".bytes, Befunge98("1ssss\"@").stack
|
132
|
+
end
|
133
|
+
it "j" do
|
134
|
+
assert_equal [9], Befunge98("2j789@").stack
|
135
|
+
end
|
136
|
+
it "j with -" do
|
137
|
+
assert_equal [2, 3], Befunge98("6-j123@").stack
|
138
|
+
end
|
139
|
+
it "w with 123, # and ." do
|
140
|
+
assert_equal "1 2 3 ", Befunge98( (
|
141
|
+
<<~HEREDOC
|
142
|
+
\#@w1.21\#@w3.@
|
143
|
+
@ 2
|
144
|
+
.
|
145
|
+
1
|
146
|
+
#
|
147
|
+
@
|
148
|
+
HEREDOC
|
149
|
+
), StringIO.new).stdout.string
|
150
|
+
end
|
124
151
|
it "~" do
|
125
152
|
assert_equal [2], Befunge98("~1@2", StringIO.new, StringIO.new).stack
|
126
153
|
assert_equal [0, 10, 255, 0], Befunge98("~~~~@", StringIO.new,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: befunge98
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov aka Nakilon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|