faultier-esoteric 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.
- data/ChangeLog +7 -0
- data/README +9 -6
- data/Rakefile +5 -3
- data/bin/bf +9 -0
- data/bin/dt +5 -5
- data/bin/esoc +48 -0
- data/bin/tetete +9 -0
- data/bin/ws +9 -0
- data/lib/esoteric.rb +2 -2
- data/lib/esoteric/brainfuck.rb +10 -0
- data/lib/esoteric/brainfuck/parser.rb +71 -0
- data/lib/esoteric/dt.rb +10 -0
- data/lib/esoteric/dt/parser.rb +147 -0
- data/lib/esoteric/easyvm.rb +25 -0
- data/lib/esoteric/parser.rb +149 -0
- data/lib/esoteric/runner.rb +20 -19
- data/lib/esoteric/tetete.rb +10 -0
- data/lib/esoteric/tetete/parser.rb +87 -0
- data/lib/esoteric/vm.rb +6 -74
- data/lib/esoteric/whitespace.rb +10 -0
- data/lib/esoteric/whitespace/parser.rb +139 -0
- metadata +40 -18
- data/bin/esm +0 -8
- data/bin/whitespace +0 -9
- data/lib/esoteric/compiler.rb +0 -60
- data/lib/esoteric/compiler/dt.rb +0 -101
- data/lib/esoteric/compiler/whitespace.rb +0 -94
- data/lib/esoteric/version.rb +0 -16
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faultier-esoteric
|
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
|
- faultier
|
@@ -9,16 +9,27 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-21 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ruby2ruby
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.2
|
24
|
+
version:
|
25
|
+
description: Esoteric langage compilers and virtual machines
|
17
26
|
email: roteshund+github@gmail.com
|
18
27
|
executables:
|
19
|
-
-
|
20
|
-
- whitespace
|
28
|
+
- bf
|
21
29
|
- dt
|
30
|
+
- esoc
|
31
|
+
- tetete
|
32
|
+
- ws
|
22
33
|
extensions: []
|
23
34
|
|
24
35
|
extra_rdoc_files:
|
@@ -28,21 +39,32 @@ files:
|
|
28
39
|
- README
|
29
40
|
- ChangeLog
|
30
41
|
- Rakefile
|
31
|
-
- bin/
|
42
|
+
- bin/bf
|
32
43
|
- bin/dt
|
33
|
-
- bin/
|
34
|
-
-
|
44
|
+
- bin/esoc
|
45
|
+
- bin/tetete
|
46
|
+
- bin/ws
|
35
47
|
- spec/esoteric_spec.rb
|
36
48
|
- spec/spec.opts
|
37
|
-
-
|
49
|
+
- spec/spec_helper.rb
|
38
50
|
- lib/esoteric
|
39
|
-
- lib/esoteric/
|
40
|
-
- lib/esoteric/
|
41
|
-
- lib/esoteric/
|
42
|
-
- lib/esoteric/
|
43
|
-
- lib/esoteric/
|
44
|
-
- lib/esoteric/
|
51
|
+
- lib/esoteric/brainfuck
|
52
|
+
- lib/esoteric/brainfuck/parser.rb
|
53
|
+
- lib/esoteric/brainfuck.rb
|
54
|
+
- lib/esoteric/dt
|
55
|
+
- lib/esoteric/dt/parser.rb
|
56
|
+
- lib/esoteric/dt.rb
|
57
|
+
- lib/esoteric/easyvm.rb
|
58
|
+
- lib/esoteric/parser.rb
|
45
59
|
- lib/esoteric/runner.rb
|
60
|
+
- lib/esoteric/tetete
|
61
|
+
- lib/esoteric/tetete/parser.rb
|
62
|
+
- lib/esoteric/tetete.rb
|
63
|
+
- lib/esoteric/vm.rb
|
64
|
+
- lib/esoteric/whitespace
|
65
|
+
- lib/esoteric/whitespace/parser.rb
|
66
|
+
- lib/esoteric/whitespace.rb
|
67
|
+
- lib/esoteric.rb
|
46
68
|
has_rdoc: true
|
47
69
|
homepage: http://blog.livedoor.jp/faultier/
|
48
70
|
post_install_message:
|
@@ -79,6 +101,6 @@ rubyforge_project:
|
|
79
101
|
rubygems_version: 1.2.0
|
80
102
|
signing_key:
|
81
103
|
specification_version: 2
|
82
|
-
summary:
|
104
|
+
summary: Esoteric langage compilers and virtual machines
|
83
105
|
test_files: []
|
84
106
|
|
data/bin/esm
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# vim: filetype=ruby fileencoding=utf-8 :
|
3
|
-
|
4
|
-
require 'esoteric'
|
5
|
-
ESOTERIC_BIN_VERSION = "essembler #{Esoteric::VERSION::STRING}" unless defined?(ESOTERIC_BIN_VERSION)
|
6
|
-
|
7
|
-
require 'esoteric/runner'
|
8
|
-
Esoteric::Runner.run($source, nil, Esoteric::VM, $opitons)
|
data/bin/whitespace
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# vim: filetype=ruby fileencoding=utf-8 :
|
3
|
-
|
4
|
-
require 'esoteric'
|
5
|
-
require 'esoteric/compiler/whitespace'
|
6
|
-
ESOTERIC_BIN_VERSION = Esoteric::Compiler::Whitespace::VERSION unless defined?(ESOTERIC_BIN_VERSION)
|
7
|
-
|
8
|
-
require 'esoteric/runner'
|
9
|
-
Esoteric::Runner.run($source, Esoteric::Compiler::Whitespace, Esoteric::VM, $options)
|
data/lib/esoteric/compiler.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
module Esoteric
|
6
|
-
module Compiler
|
7
|
-
class Base
|
8
|
-
def self.compile(src, logger=nil)
|
9
|
-
new(src, logger).compile
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize(src, logger=nil)
|
13
|
-
@src = normalize(src)
|
14
|
-
unless @logger = logger
|
15
|
-
@logger = Logger.new(STDOUT)
|
16
|
-
@logger.level = Logger::ERROR
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def compile
|
21
|
-
insns = []
|
22
|
-
while st = step
|
23
|
-
insns.push st
|
24
|
-
end
|
25
|
-
insns.map {|c,a| a.nil? ? c.to_s : "#{c}\t#{a}"}.join("\n")
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def normalize(src)
|
31
|
-
src
|
32
|
-
end
|
33
|
-
|
34
|
-
def step
|
35
|
-
nil
|
36
|
-
end
|
37
|
-
|
38
|
-
def command(name, arg=nil)
|
39
|
-
case name
|
40
|
-
when :push,:copy,:slide then [name, numeric(arg)]
|
41
|
-
when :label,:call,:jump,:jumpz,:jumpn then [name, string(arg)]
|
42
|
-
when :dup,:swap,:discard then [name]
|
43
|
-
when :add,:sub,:mul,:div,:mod then [name]
|
44
|
-
when :hwrite,:hread then [name]
|
45
|
-
when :return,:exit then [name]
|
46
|
-
when :cout,:nout,:cin,:nin then [name]
|
47
|
-
else raise SyntaxError
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def numeric(value)
|
52
|
-
value.to_i
|
53
|
-
end
|
54
|
-
|
55
|
-
def string(value)
|
56
|
-
value.to_s
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/esoteric/compiler/dt.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
if RUBY_VERSION =~ /^1\.8\./
|
4
|
-
$KCODE = 'u'
|
5
|
-
require 'jcode'
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'strscan'
|
9
|
-
|
10
|
-
module Esoteric
|
11
|
-
module Compiler
|
12
|
-
class DT < Base
|
13
|
-
VERSION = "#{Esoteric::VERSION::SUMMARY}, dt 0.0.1"
|
14
|
-
|
15
|
-
NVAL = /((?:ど|童貞ちゃうわっ!)+)…/
|
16
|
-
LVAL = NVAL
|
17
|
-
PUSH = /どど#{NVAL}/
|
18
|
-
DUP = /ど…ど/
|
19
|
-
COPY = /ど童貞ちゃうわっ!ど#{NVAL}/
|
20
|
-
SWAP = /ど…童貞ちゃうわっ!/
|
21
|
-
DISCARD = /ど……/
|
22
|
-
SLIDE = /ど童貞ちゃうわっ!…#{NVAL}/
|
23
|
-
ADD = /童貞ちゃうわっ!どどど/
|
24
|
-
SUB = /童貞ちゃうわっ!どど童貞ちゃうわっ!/
|
25
|
-
MUL = /童貞ちゃうわっ!どど…/
|
26
|
-
DIV = /童貞ちゃうわっ!ど童貞ちゃうわっ!ど/
|
27
|
-
MOD = /童貞ちゃうわっ!ど童貞ちゃうわっ!童貞ちゃうわっ!/
|
28
|
-
HWRITE = /童貞ちゃうわっ!童貞ちゃうわっ!ど/
|
29
|
-
HREAD = /童貞ちゃうわっ!童貞ちゃうわっ!童貞ちゃうわっ!/
|
30
|
-
LABEL = /…どど#{LVAL}/
|
31
|
-
CALL = /…ど童貞ちゃうわっ!#{LVAL}/
|
32
|
-
JUMP = /…ど…#{LVAL}/
|
33
|
-
JUMPZ = /…童貞ちゃうわっ!ど#{LVAL}/
|
34
|
-
JUMPN = /…童貞ちゃうわっ!童貞ちゃうわっ!#{LVAL}/
|
35
|
-
RETURN = /…童貞ちゃうわっ!…/
|
36
|
-
EXIT = /………/
|
37
|
-
COUT = /童貞ちゃうわっ!…どど/
|
38
|
-
NOUT = /童貞ちゃうわっ!…ど童貞ちゃうわっ!/
|
39
|
-
CIN = /童貞ちゃうわっ!…童貞ちゃうわっ!ど/
|
40
|
-
NIN = /童貞ちゃうわっ!…童貞ちゃうわっ!童貞ちゃうわっ!/
|
41
|
-
|
42
|
-
def initialize(src, logger=nil)
|
43
|
-
super
|
44
|
-
@s = StringScanner.new(@src)
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def normalize(src)
|
50
|
-
normalized = ''
|
51
|
-
normalized << $1 while src.sub!(/(ど|童貞ちゃうわっ!|…)/, '*')
|
52
|
-
normalized
|
53
|
-
end
|
54
|
-
|
55
|
-
def step
|
56
|
-
case
|
57
|
-
when @s.eos? then nil
|
58
|
-
when @s.scan(PUSH) then command :push, @s[1]
|
59
|
-
when @s.scan(DUP) then command :dup
|
60
|
-
when @s.scan(COPY) then command :copy, @s[1]
|
61
|
-
when @s.scan(SWAP) then command :swap
|
62
|
-
when @s.scan(DISCARD) then command :discard
|
63
|
-
when @s.scan(SLIDE) then command :slide, @s[1]
|
64
|
-
when @s.scan(ADD) then command :add
|
65
|
-
when @s.scan(SUB) then command :sub
|
66
|
-
when @s.scan(MUL) then command :mul
|
67
|
-
when @s.scan(DIV) then command :div
|
68
|
-
when @s.scan(MOD) then command :mod
|
69
|
-
when @s.scan(HWRITE) then command :hwrite
|
70
|
-
when @s.scan(HREAD) then command :hread
|
71
|
-
when @s.scan(LABEL) then command :label, @s[1]
|
72
|
-
when @s.scan(CALL) then command :call, @s[1]
|
73
|
-
when @s.scan(JUMP) then command :jump, @s[1]
|
74
|
-
when @s.scan(JUMPZ) then command :jumpz, @s[1]
|
75
|
-
when @s.scan(JUMPN) then command :jumpn, @s[1]
|
76
|
-
when @s.scan(RETURN) then command :return
|
77
|
-
when @s.scan(EXIT) then command :exit
|
78
|
-
when @s.scan(COUT) then command :cout
|
79
|
-
when @s.scan(NOUT) then command :nout
|
80
|
-
when @s.scan(CIN) then command :cin
|
81
|
-
when @s.scan(NIN) then command :nin
|
82
|
-
else raise ::Esoteric::SyntaxError
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def numeric(value)
|
87
|
-
raise ArgumentError if "#{value}…" !~ /\A#{NVAL}\z/
|
88
|
-
n = value.sub(/\Aど/, '+').
|
89
|
-
sub(/\A童貞ちゃうわっ!/, '-').
|
90
|
-
gsub(/ど/, '0').
|
91
|
-
gsub(/童貞ちゃうわっ!/, '1')
|
92
|
-
n.to_i(2)
|
93
|
-
end
|
94
|
-
|
95
|
-
def string(value)
|
96
|
-
raise ArgumentError if "#{value}…" !~ /\A#{LVAL}\z/
|
97
|
-
value.sub(/ど/, '0').sub(/童貞ちゃうわっ!/, '1')
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'strscan'
|
4
|
-
|
5
|
-
module Esoteric
|
6
|
-
module Compiler
|
7
|
-
class Whitespace < Base
|
8
|
-
VERSION = "#{Esoteric::VERSION::SUMMARY}, whitespace 0.0.1"
|
9
|
-
|
10
|
-
NVAL = /([ \t]+)\n/
|
11
|
-
LVAL = NVAL
|
12
|
-
PUSH = / #{NVAL}/
|
13
|
-
DUP = / \n /
|
14
|
-
COPY = / \t #{NVAL}/
|
15
|
-
SWAP = / \n\t/
|
16
|
-
DISCARD = / \n\n/
|
17
|
-
SLIDE = / \t\n#{NVAL}/
|
18
|
-
ADD = /\t /
|
19
|
-
SUB = /\t \t/
|
20
|
-
MUL = /\t \n/
|
21
|
-
DIV = /\t \t /
|
22
|
-
MOD = /\t \t\t/
|
23
|
-
HWRITE = /\t\t /
|
24
|
-
HREAD = /\t\t\t/
|
25
|
-
LABEL = /\n #{LVAL}/
|
26
|
-
CALL = /\n \t#{LVAL}/
|
27
|
-
JUMP = /\n \n#{LVAL}/
|
28
|
-
JUMPZ = /\n\t #{LVAL}/
|
29
|
-
JUMPN = /\n\t\t#{LVAL}/
|
30
|
-
RETURN = /\n\t\n/
|
31
|
-
EXIT = /\n\n\n/
|
32
|
-
COUT = /\t\n /
|
33
|
-
NOUT = /\t\n \t/
|
34
|
-
CIN = /\t\n\t /
|
35
|
-
NIN = /\t\n\t\t/
|
36
|
-
|
37
|
-
def initialize(src,logger=nil)
|
38
|
-
super
|
39
|
-
@s = StringScanner.new(@src)
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def normalize(src)
|
45
|
-
src.gsub(/[^ \t\n]/, '')
|
46
|
-
end
|
47
|
-
|
48
|
-
def step
|
49
|
-
case
|
50
|
-
when @s.eos? then nil
|
51
|
-
when @s.scan(PUSH) then command :push, @s[1]
|
52
|
-
when @s.scan(DUP) then command :dup
|
53
|
-
when @s.scan(COPY) then command :copy, @s[1]
|
54
|
-
when @s.scan(SWAP) then command :swap
|
55
|
-
when @s.scan(DISCARD) then command :discard
|
56
|
-
when @s.scan(SLIDE) then command :slide, @s[1]
|
57
|
-
when @s.scan(ADD) then command :add
|
58
|
-
when @s.scan(SUB) then command :sub
|
59
|
-
when @s.scan(MUL) then command :mul
|
60
|
-
when @s.scan(DIV) then command :div
|
61
|
-
when @s.scan(MOD) then command :mod
|
62
|
-
when @s.scan(HWRITE) then command :hwrite
|
63
|
-
when @s.scan(HREAD) then command :hread
|
64
|
-
when @s.scan(LABEL) then command :label, @s[1]
|
65
|
-
when @s.scan(CALL) then command :call, @s[1]
|
66
|
-
when @s.scan(JUMP) then command :jump, @s[1]
|
67
|
-
when @s.scan(JUMPZ) then command :jumpz, @s[1]
|
68
|
-
when @s.scan(JUMPN) then command :jumpn, @s[1]
|
69
|
-
when @s.scan(RETURN) then command :return
|
70
|
-
when @s.scan(EXIT) then command :exit
|
71
|
-
when @s.scan(COUT) then command :cout
|
72
|
-
when @s.scan(NOUT) then command :nout
|
73
|
-
when @s.scan(CIN) then command :cin
|
74
|
-
when @s.scan(NIN) then command :nin
|
75
|
-
else raise SyntaxError
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def numeric(value)
|
80
|
-
raise ArgumentError if "#{value}\n" !~ /\A#{NVAL}\z/
|
81
|
-
n = value.sub(/\A /, '+').
|
82
|
-
sub(/\A\t/, '-').
|
83
|
-
gsub(/ /, '0').
|
84
|
-
gsub(/\t/, '1')
|
85
|
-
n.to_i(2)
|
86
|
-
end
|
87
|
-
|
88
|
-
def string(value)
|
89
|
-
raise ArgumentError if "#{value}\n" !~ /\A#{LVAL}\z/
|
90
|
-
value.gsub(/ /, '0').gsub(/\t/, '1')
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
data/lib/esoteric/version.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
module Esoteric
|
4
|
-
module VERSION
|
5
|
-
unless defined? MAJOR
|
6
|
-
MAJOR = 0
|
7
|
-
MINOR = 0
|
8
|
-
TINY = 1
|
9
|
-
MINESCULE = nil
|
10
|
-
|
11
|
-
STRING = [MAJOR, MINOR, TINY, MINESCULE].compact.join('.')
|
12
|
-
|
13
|
-
SUMMARY = "esoteric #{STRING}"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|