atomy 0.1.1 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +13 -0
- data/LICENSE.md +201 -0
- data/bin/atomy +16 -133
- data/kernel/array.ay +6 -0
- data/kernel/atomy.ay +18 -0
- data/kernel/condition.ay +171 -271
- data/kernel/control-flow.ay +197 -192
- data/kernel/core.ay +120 -0
- data/kernel/data.ay +83 -39
- data/kernel/define.ay +84 -93
- data/kernel/doc.ay +282 -449
- data/kernel/dynamic.ay +25 -29
- data/kernel/file.ay +9 -0
- data/kernel/grammar.ay +267 -0
- data/kernel/hash.ay +17 -0
- data/kernel/interpolation.ay +59 -0
- data/kernel/io.ay +70 -244
- data/kernel/let-macro.ay +24 -0
- data/kernel/let-pattern.ay +24 -0
- data/kernel/loop.ay +80 -0
- data/kernel/mutation.ay +53 -0
- data/kernel/particles.ay +176 -39
- data/kernel/patterns.ay +527 -191
- data/kernel/pretty.ay +311 -277
- data/kernel/quotes.ay +29 -0
- data/kernel/range.ay +4 -0
- data/kernel/regexp.ay +23 -0
- data/kernel/repl.ay +83 -109
- data/kernel/stack-local.ay +21 -0
- data/lib/atomy.rb +37 -0
- data/lib/atomy/bootstrap.rb +256 -0
- data/lib/atomy/code/assign.rb +64 -0
- data/lib/atomy/code/block.rb +98 -0
- data/lib/atomy/code/class_variable.rb +17 -0
- data/lib/atomy/code/constant.rb +21 -0
- data/lib/atomy/code/define.rb +242 -0
- data/lib/atomy/code/define_function.rb +51 -0
- data/lib/atomy/code/define_method.rb +20 -0
- data/lib/atomy/code/false.rb +9 -0
- data/lib/atomy/code/instance_variable.rb +15 -0
- data/lib/atomy/code/integer.rb +13 -0
- data/lib/atomy/code/list.rb +17 -0
- data/lib/atomy/code/nil.rb +9 -0
- data/lib/atomy/code/pattern.rb +23 -0
- data/lib/atomy/code/pattern/and.rb +61 -0
- data/lib/atomy/code/pattern/quasi_quote.rb +185 -0
- data/lib/atomy/code/pattern/splat.rb +29 -0
- data/lib/atomy/code/pattern/wildcard.rb +37 -0
- data/lib/atomy/code/quasi_quote.rb +118 -0
- data/lib/atomy/code/quote.rb +13 -0
- data/lib/atomy/code/self.rb +9 -0
- data/lib/atomy/code/send.rb +110 -0
- data/lib/atomy/code/sequence.rb +23 -0
- data/lib/atomy/code/string_literal.rb +53 -0
- data/lib/atomy/code/symbol.rb +13 -0
- data/lib/atomy/code/true.rb +9 -0
- data/lib/atomy/code/undefined.rb +9 -0
- data/lib/atomy/code/variable.rb +17 -0
- data/lib/atomy/codeloader.rb +218 -0
- data/lib/atomy/compiler.rb +57 -0
- data/lib/atomy/errors.rb +54 -0
- data/lib/atomy/grammar.rb +2278 -0
- data/lib/atomy/locals.rb +75 -0
- data/lib/atomy/message_structure.rb +277 -0
- data/lib/atomy/method.rb +343 -0
- data/lib/atomy/module.rb +144 -0
- data/lib/atomy/node/constructable.rb +169 -0
- data/lib/atomy/node/equality.rb +113 -0
- data/lib/atomy/node/meta.rb +206 -0
- data/lib/atomy/node/pretty.rb +108 -0
- data/lib/atomy/parser.rb +21 -0
- data/lib/atomy/pattern.rb +26 -0
- data/lib/atomy/pattern/and.rb +59 -0
- data/lib/atomy/pattern/attribute.rb +16 -0
- data/lib/atomy/pattern/class_variable.rb +15 -0
- data/lib/atomy/pattern/equality.rb +42 -0
- data/lib/atomy/pattern/instance_variable.rb +15 -0
- data/lib/atomy/pattern/kind_of.rb +20 -0
- data/lib/atomy/pattern/or.rb +48 -0
- data/lib/atomy/pattern/quasi_quote.rb +164 -0
- data/lib/atomy/pattern/splat.rb +15 -0
- data/lib/atomy/pattern/wildcard.rb +18 -0
- data/lib/atomy/rubygems.rb +48 -0
- data/lib/atomy/version.rb +3 -0
- metadata +169 -134
- data/COPYING +0 -30
- data/README.md +0 -1
- data/kernel/block.ay +0 -30
- data/kernel/boot.ay +0 -10
- data/kernel/comparison.ay +0 -61
- data/kernel/concurrency.ay +0 -84
- data/kernel/cosmetics.ay +0 -3
- data/kernel/data-delta.ay +0 -105
- data/kernel/documentation.ay +0 -135
- data/kernel/errors.ay +0 -6
- data/kernel/format.ay +0 -13
- data/kernel/format/data.ay +0 -89
- data/kernel/format/formatter.ay +0 -345
- data/kernel/format/parser.ay +0 -13
- data/kernel/hashes.ay +0 -39
- data/kernel/namespaces.ay +0 -63
- data/kernel/node.ay +0 -48
- data/kernel/operators.ay +0 -28
- data/kernel/precision.ay +0 -148
- data/kernel/therie.ay +0 -204
- data/lib/ast/binary_send.rb +0 -44
- data/lib/ast/block.rb +0 -268
- data/lib/ast/constant.rb +0 -88
- data/lib/ast/internal/assign.rb +0 -19
- data/lib/ast/internal/block_pass.rb +0 -21
- data/lib/ast/internal/catch.rb +0 -247
- data/lib/ast/internal/class.rb +0 -30
- data/lib/ast/internal/class_variable.rb +0 -23
- data/lib/ast/internal/define.rb +0 -174
- data/lib/ast/internal/ensure.rb +0 -135
- data/lib/ast/internal/file.rb +0 -14
- data/lib/ast/internal/global_variable.rb +0 -20
- data/lib/ast/internal/if_then_else.rb +0 -24
- data/lib/ast/internal/instance_variable.rb +0 -17
- data/lib/ast/internal/let_macro.rb +0 -35
- data/lib/ast/internal/macro_quote.rb +0 -23
- data/lib/ast/internal/match.rb +0 -53
- data/lib/ast/internal/module.rb +0 -30
- data/lib/ast/internal/pattern.rb +0 -17
- data/lib/ast/internal/return.rb +0 -29
- data/lib/ast/internal/set.rb +0 -19
- data/lib/ast/internal/singleton_class.rb +0 -18
- data/lib/ast/internal/splat.rb +0 -14
- data/lib/ast/internal/when.rb +0 -24
- data/lib/ast/list.rb +0 -25
- data/lib/ast/macro.rb +0 -37
- data/lib/ast/node.rb +0 -599
- data/lib/ast/operator.rb +0 -21
- data/lib/ast/particle.rb +0 -13
- data/lib/ast/primitive.rb +0 -20
- data/lib/ast/quasi_quote.rb +0 -20
- data/lib/ast/quote.rb +0 -13
- data/lib/ast/send.rb +0 -104
- data/lib/ast/splice.rb +0 -32
- data/lib/ast/string.rb +0 -23
- data/lib/ast/unary.rb +0 -44
- data/lib/ast/unquote.rb +0 -45
- data/lib/ast/variable.rb +0 -64
- data/lib/atomy.kpeg.rb +0 -3995
- data/lib/code_loader.rb +0 -137
- data/lib/compiler/compiler.rb +0 -155
- data/lib/compiler/stages.rb +0 -81
- data/lib/formatter.kpeg.rb +0 -1394
- data/lib/macros.rb +0 -317
- data/lib/method.rb +0 -261
- data/lib/namespace.rb +0 -236
- data/lib/parser.rb +0 -28
- data/lib/patterns.rb +0 -276
- data/lib/patterns/any.rb +0 -21
- data/lib/patterns/attribute.rb +0 -59
- data/lib/patterns/block_pass.rb +0 -54
- data/lib/patterns/constant.rb +0 -33
- data/lib/patterns/default.rb +0 -44
- data/lib/patterns/head_tail.rb +0 -63
- data/lib/patterns/list.rb +0 -77
- data/lib/patterns/match.rb +0 -45
- data/lib/patterns/named.rb +0 -55
- data/lib/patterns/named_class.rb +0 -46
- data/lib/patterns/named_global.rb +0 -46
- data/lib/patterns/named_instance.rb +0 -46
- data/lib/patterns/particle.rb +0 -29
- data/lib/patterns/quasi_quote.rb +0 -184
- data/lib/patterns/quote.rb +0 -33
- data/lib/patterns/singleton_class.rb +0 -31
- data/lib/patterns/splat.rb +0 -57
- data/lib/util.rb +0 -37
@@ -0,0 +1,64 @@
|
|
1
|
+
module Atomy
|
2
|
+
module Code
|
3
|
+
class Assign
|
4
|
+
def initialize(pattern, value)
|
5
|
+
@pattern = pattern
|
6
|
+
@value = value
|
7
|
+
end
|
8
|
+
|
9
|
+
def bytecode(gen, mod)
|
10
|
+
pattern = mod.pattern(@pattern)
|
11
|
+
|
12
|
+
# [value]
|
13
|
+
mod.compile(gen, @value)
|
14
|
+
|
15
|
+
# [value, value]
|
16
|
+
gen.dup
|
17
|
+
# [pattern, value, value]
|
18
|
+
mod.compile(gen, pattern)
|
19
|
+
# [value, pattern, value]
|
20
|
+
gen.swap
|
21
|
+
|
22
|
+
# [value, pattern, value, pattern, value]
|
23
|
+
gen.dup_many(2)
|
24
|
+
|
25
|
+
mismatch = gen.new_label
|
26
|
+
done = gen.new_label
|
27
|
+
|
28
|
+
# [bool, value, pattern, value]
|
29
|
+
gen.send(:matches?, 1)
|
30
|
+
|
31
|
+
# [value, pattern, value]
|
32
|
+
gen.gif(mismatch)
|
33
|
+
|
34
|
+
# [value, pattern, value]
|
35
|
+
pattern.assign(gen)
|
36
|
+
|
37
|
+
# [value]
|
38
|
+
gen.pop_many(2)
|
39
|
+
|
40
|
+
# [value]
|
41
|
+
gen.goto(done)
|
42
|
+
|
43
|
+
# [value, pattern, value]
|
44
|
+
mismatch.set!
|
45
|
+
|
46
|
+
# [::, value, pattern, value]
|
47
|
+
gen.push_cpath_top
|
48
|
+
# [::Atomy, value, pattern, value]
|
49
|
+
gen.find_const(:Atomy)
|
50
|
+
# [::Atomy::PatternMismatch, value, pattern, value]
|
51
|
+
gen.find_const(:PatternMismatch)
|
52
|
+
# [value, pattern, ::Atomy::PatternMismatch, value]
|
53
|
+
gen.move_down(2)
|
54
|
+
# [#<Atomy::PatternMismatch>, value]
|
55
|
+
gen.send(:new, 2)
|
56
|
+
# exception
|
57
|
+
gen.raise_exc
|
58
|
+
|
59
|
+
# [value]
|
60
|
+
done.set!
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Atomy
|
2
|
+
module Code
|
3
|
+
class Block
|
4
|
+
def initialize(body, args = [], proc_argument = nil, lambda_style = true)
|
5
|
+
@body = body
|
6
|
+
|
7
|
+
@arguments = args.dup
|
8
|
+
if args.last.is_a?(Atomy::Grammar::AST::Prefix) && args.last.operator == :*
|
9
|
+
@splat_argument = @arguments.pop
|
10
|
+
end
|
11
|
+
|
12
|
+
@proc_argument = proc_argument
|
13
|
+
|
14
|
+
@lambda_style = lambda_style
|
15
|
+
end
|
16
|
+
|
17
|
+
def bytecode(gen, mod)
|
18
|
+
blk = build_block(gen.state.scope, mod)
|
19
|
+
|
20
|
+
if @lambda_style
|
21
|
+
gen.push_cpath_top
|
22
|
+
gen.find_const :Proc
|
23
|
+
end
|
24
|
+
|
25
|
+
gen.create_block(blk)
|
26
|
+
|
27
|
+
if @lambda_style
|
28
|
+
gen.send(:__from_block__, 1)
|
29
|
+
gen.dup
|
30
|
+
gen.send(:lambda_style!, 0)
|
31
|
+
gen.pop
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def build_block(scope, mod)
|
38
|
+
Atomy::Compiler.generate(mod.file) do |blk|
|
39
|
+
# close over the outer scope
|
40
|
+
blk.state.scope.parent = scope
|
41
|
+
|
42
|
+
# for now, only allow a fixed set of arguments
|
43
|
+
blk.required_args = blk.total_args = @arguments.size
|
44
|
+
|
45
|
+
if @lambda_style
|
46
|
+
# discard extra arguments
|
47
|
+
blk.splat_index = @arguments.size
|
48
|
+
end
|
49
|
+
|
50
|
+
# this bubbles up to Proc#arity and BlockEnvironment, though it
|
51
|
+
# doesn't appear to change actual behavior of the block
|
52
|
+
if @splat_argument
|
53
|
+
# this is + 1 so that if there are no args the arity is -1, not -0
|
54
|
+
# (which is not a thing)
|
55
|
+
blk.arity = -(@arguments.size + 1)
|
56
|
+
else
|
57
|
+
blk.arity = @arguments.size
|
58
|
+
end
|
59
|
+
|
60
|
+
# create a local for each argument name
|
61
|
+
@arguments.each.with_index do |a, i|
|
62
|
+
blk.state.scope.new_local(:"arg:#{i}")
|
63
|
+
end
|
64
|
+
|
65
|
+
# local for discarded splat args
|
66
|
+
blk.state.scope.new_local(:"arg:extra")
|
67
|
+
|
68
|
+
# pattern-match all args
|
69
|
+
@arguments.each.with_index do |a, i|
|
70
|
+
Assign.new(a, Variable.new(:"arg:#{i}")).bytecode(blk, mod)
|
71
|
+
end
|
72
|
+
|
73
|
+
# pattern-match the splat arg
|
74
|
+
if @splat_argument
|
75
|
+
Assign.new(@splat_argument, Variable.new(:"arg:extra")).bytecode(blk, mod)
|
76
|
+
end
|
77
|
+
|
78
|
+
# pattern-match the proc arg
|
79
|
+
if @proc_argument
|
80
|
+
Assign.new(@proc_argument, PushProc.new).bytecode(blk, mod)
|
81
|
+
end
|
82
|
+
|
83
|
+
# build the block's body
|
84
|
+
mod.compile(blk, @body)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class PushProc
|
89
|
+
def initialize
|
90
|
+
end
|
91
|
+
|
92
|
+
def bytecode(gen, mod)
|
93
|
+
gen.push_proc
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Atomy
|
2
|
+
module Code
|
3
|
+
class ClassVariable
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
|
10
|
+
def bytecode(gen, mod)
|
11
|
+
gen.push_scope
|
12
|
+
gen.push_literal(:"@@#{@name}")
|
13
|
+
gen.send(:class_variable_get, 1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Atomy
|
2
|
+
module Code
|
3
|
+
class Constant
|
4
|
+
attr_reader :name, :parent
|
5
|
+
|
6
|
+
def initialize(name, parent = nil)
|
7
|
+
@name = name
|
8
|
+
@parent = parent
|
9
|
+
end
|
10
|
+
|
11
|
+
def bytecode(gen, mod)
|
12
|
+
if @parent
|
13
|
+
mod.compile(gen, @parent)
|
14
|
+
gen.find_const(@name)
|
15
|
+
else
|
16
|
+
gen.push_const(@name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
module Atomy
|
2
|
+
module Code
|
3
|
+
class Define
|
4
|
+
def initialize(name, body = nil, receiver = nil, arguments = [],
|
5
|
+
default_arguments = [], splat_argument = nil,
|
6
|
+
post_arguments = [], proc_argument = nil)
|
7
|
+
@name = name
|
8
|
+
@body = body
|
9
|
+
@receiver = receiver
|
10
|
+
@arguments = arguments
|
11
|
+
@default_arguments = default_arguments
|
12
|
+
@splat_argument = splat_argument
|
13
|
+
@post_arguments = post_arguments
|
14
|
+
@proc_argument = proc_argument
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def push_branch(gen, mod)
|
20
|
+
gen.push_cpath_top
|
21
|
+
gen.find_const(:Atomy)
|
22
|
+
gen.find_const(:Method)
|
23
|
+
gen.find_const(:Branch)
|
24
|
+
|
25
|
+
if @receiver
|
26
|
+
mod.compile(gen, receiver_pattern(mod))
|
27
|
+
else
|
28
|
+
gen.push_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
pre_argument_patterns(mod).each do |p|
|
32
|
+
mod.compile(gen, p)
|
33
|
+
end
|
34
|
+
gen.make_array(@arguments.size)
|
35
|
+
|
36
|
+
default_argument_patterns(mod).each do |d, p|
|
37
|
+
mod.compile(gen, p)
|
38
|
+
end
|
39
|
+
gen.make_array(@default_arguments.size)
|
40
|
+
|
41
|
+
if p = splat_argument_pattern(mod)
|
42
|
+
mod.compile(gen, p)
|
43
|
+
else
|
44
|
+
gen.push_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
post_argument_patterns(mod).each do |p|
|
48
|
+
mod.compile(gen, p)
|
49
|
+
end
|
50
|
+
gen.make_array(@post_arguments.size)
|
51
|
+
|
52
|
+
if p = proc_argument_pattern(mod)
|
53
|
+
mod.compile(gen, p)
|
54
|
+
else
|
55
|
+
gen.push_nil
|
56
|
+
end
|
57
|
+
|
58
|
+
gen.create_block(build_block(gen.state.scope, mod, @name, @body))
|
59
|
+
|
60
|
+
gen.send_with_block(:new, 6)
|
61
|
+
end
|
62
|
+
|
63
|
+
def build_block(scope, mod, name, body)
|
64
|
+
Atomy::Compiler.generate(mod.file) do |blk|
|
65
|
+
# set method name so calls to super work
|
66
|
+
blk.name = name
|
67
|
+
|
68
|
+
# close over the outer scope
|
69
|
+
blk.state.scope.parent = scope
|
70
|
+
|
71
|
+
total_patterns = 0
|
72
|
+
total_patterns += 1 if @receiver
|
73
|
+
total_patterns += @arguments.size + @default_arguments.size + @post_arguments.size
|
74
|
+
total_patterns += 1 if @splat_argument
|
75
|
+
total_patterns += 1 if @proc_argument
|
76
|
+
|
77
|
+
blk.total_args = total_patterns * 2
|
78
|
+
blk.required_args = blk.total_args
|
79
|
+
|
80
|
+
# this bubbles up to Proc#arity and BlockEnvironment, though it
|
81
|
+
# doesn't appear to change actual behavior of the block
|
82
|
+
blk.arity = blk.total_args
|
83
|
+
|
84
|
+
arg = 0
|
85
|
+
|
86
|
+
if @receiver
|
87
|
+
blk.state.scope.new_local("arg:self:pat")
|
88
|
+
blk.state.scope.new_local("arg:self")
|
89
|
+
end
|
90
|
+
|
91
|
+
@arguments.size.times do
|
92
|
+
blk.state.scope.new_local(:"arg:#{arg}:pat")
|
93
|
+
blk.state.scope.new_local(:"arg:#{arg}")
|
94
|
+
arg += 1
|
95
|
+
end
|
96
|
+
|
97
|
+
@default_arguments.size.times do
|
98
|
+
blk.state.scope.new_local(:"arg:#{arg}:pat")
|
99
|
+
blk.state.scope.new_local(:"arg:#{arg}")
|
100
|
+
arg += 1
|
101
|
+
end
|
102
|
+
|
103
|
+
if @splat_argument
|
104
|
+
blk.state.scope.new_local(:"arg:splat:pat")
|
105
|
+
blk.state.scope.new_local(:"arg:splat")
|
106
|
+
end
|
107
|
+
|
108
|
+
@post_arguments.size.times do
|
109
|
+
blk.state.scope.new_local(:"arg:#{arg}:pat")
|
110
|
+
blk.state.scope.new_local(:"arg:#{arg}")
|
111
|
+
arg += 1
|
112
|
+
end
|
113
|
+
|
114
|
+
if @proc_argument
|
115
|
+
blk.state.scope.new_local(:"arg:proc:pat")
|
116
|
+
blk.state.scope.new_local(:"arg:proc")
|
117
|
+
end
|
118
|
+
|
119
|
+
loc = 0
|
120
|
+
if p = receiver_pattern(mod)
|
121
|
+
blk.push_local(loc)
|
122
|
+
blk.push_local(loc+1)
|
123
|
+
p.assign(blk)
|
124
|
+
blk.pop_many(2)
|
125
|
+
|
126
|
+
loc += 2
|
127
|
+
end
|
128
|
+
|
129
|
+
pre_argument_patterns(mod).each do |p|
|
130
|
+
blk.push_local(loc)
|
131
|
+
blk.push_local(loc+1)
|
132
|
+
p.assign(blk)
|
133
|
+
blk.pop_many(2)
|
134
|
+
|
135
|
+
loc += 2
|
136
|
+
end
|
137
|
+
|
138
|
+
default_argument_patterns(mod).each do |d, p|
|
139
|
+
assign = blk.new_label
|
140
|
+
|
141
|
+
# [pat]
|
142
|
+
blk.push_local(loc)
|
143
|
+
|
144
|
+
# [val, pat]
|
145
|
+
blk.push_local(loc+1)
|
146
|
+
|
147
|
+
# [val, val, pat]
|
148
|
+
blk.dup
|
149
|
+
|
150
|
+
# [val, pat]
|
151
|
+
blk.goto_if_not_undefined(assign)
|
152
|
+
|
153
|
+
# [pat]
|
154
|
+
blk.pop
|
155
|
+
|
156
|
+
# [val, pat]
|
157
|
+
mod.compile(blk, d.default)
|
158
|
+
|
159
|
+
assign.set!
|
160
|
+
|
161
|
+
# [val, pat]
|
162
|
+
p.assign(blk)
|
163
|
+
|
164
|
+
# []
|
165
|
+
blk.pop_many(2)
|
166
|
+
|
167
|
+
loc += 2
|
168
|
+
end
|
169
|
+
|
170
|
+
if p = splat_argument_pattern(mod)
|
171
|
+
blk.push_local(loc)
|
172
|
+
blk.push_local(loc+1)
|
173
|
+
p.assign(blk)
|
174
|
+
blk.pop_many(2)
|
175
|
+
|
176
|
+
loc += 2
|
177
|
+
end
|
178
|
+
|
179
|
+
post_argument_patterns(mod).each do |p|
|
180
|
+
blk.push_local(loc)
|
181
|
+
blk.push_local(loc+1)
|
182
|
+
p.assign(blk)
|
183
|
+
blk.pop_many(2)
|
184
|
+
|
185
|
+
loc += 2
|
186
|
+
end
|
187
|
+
|
188
|
+
if p = proc_argument_pattern(mod)
|
189
|
+
blk.push_local(loc)
|
190
|
+
blk.push_local(loc+1)
|
191
|
+
p.assign(blk)
|
192
|
+
blk.pop_many(2)
|
193
|
+
|
194
|
+
loc += 2
|
195
|
+
end
|
196
|
+
|
197
|
+
# build the method branch's body
|
198
|
+
mod.compile(blk, body)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def receiver_pattern(mod)
|
203
|
+
return unless @receiver
|
204
|
+
|
205
|
+
@receiver_pattern ||= mod.pattern(@receiver)
|
206
|
+
end
|
207
|
+
|
208
|
+
def pre_argument_patterns(mod)
|
209
|
+
@pre_argument_patterns ||=
|
210
|
+
@arguments.collect do |a|
|
211
|
+
mod.pattern(a)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def default_argument_patterns(mod)
|
216
|
+
@default_argument_patterns ||=
|
217
|
+
@default_arguments.collect do |d|
|
218
|
+
[d, mod.pattern(d.node)]
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def post_argument_patterns(mod)
|
223
|
+
@post_argument_patterns ||=
|
224
|
+
@post_arguments.collect do |a|
|
225
|
+
mod.pattern(a)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def splat_argument_pattern(mod)
|
230
|
+
return unless @splat_argument
|
231
|
+
|
232
|
+
@splat_argument_pattern ||= mod.pattern(@splat_argument)
|
233
|
+
end
|
234
|
+
|
235
|
+
def proc_argument_pattern(mod)
|
236
|
+
return unless @proc_argument
|
237
|
+
|
238
|
+
@proc_argument_pattern ||= mod.pattern(@proc_argument)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "atomy/compiler"
|
2
|
+
require "atomy/code/define"
|
3
|
+
|
4
|
+
module Atomy
|
5
|
+
module Code
|
6
|
+
class DefineFunction < Define
|
7
|
+
def bytecode(gen, mod)
|
8
|
+
var = assignment_local(gen, :"#{@name}:function")
|
9
|
+
|
10
|
+
gen.push_rubinius
|
11
|
+
gen.find_const(:BlockEnvironment)
|
12
|
+
gen.find_const(:AsMethod)
|
13
|
+
|
14
|
+
gen.push_rubinius
|
15
|
+
gen.find_const(:BlockEnvironment)
|
16
|
+
gen.send(:new, 0)
|
17
|
+
|
18
|
+
if @body
|
19
|
+
gen.push_variables
|
20
|
+
|
21
|
+
gen.push_cpath_top
|
22
|
+
gen.find_const(:Atomy)
|
23
|
+
gen.push_scope
|
24
|
+
gen.push_literal(@name)
|
25
|
+
push_branch(gen, mod)
|
26
|
+
gen.send(:register_branch, 3)
|
27
|
+
gen.send(:first, 0)
|
28
|
+
gen.send(:build, 0)
|
29
|
+
|
30
|
+
gen.send(:under_context, 2)
|
31
|
+
end
|
32
|
+
|
33
|
+
gen.send(:new, 1)
|
34
|
+
|
35
|
+
var.set_bytecode(gen)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def assignment_local(gen, name)
|
41
|
+
var = gen.state.scope.search_local(name)
|
42
|
+
|
43
|
+
if var && var.depth == 0
|
44
|
+
var
|
45
|
+
else
|
46
|
+
gen.state.scope.new_local(name).nested_reference
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|