myco 0.1.0.dev
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 +7 -0
- data/LICENSE +2 -0
- data/bin/myco +7 -0
- data/lib/myco/backtrace.rb +56 -0
- data/lib/myco/bootstrap/component.rb +142 -0
- data/lib/myco/bootstrap/empty_object.rb +4 -0
- data/lib/myco/bootstrap/file_toplevel.rb +5 -0
- data/lib/myco/bootstrap/find_constant.rb +86 -0
- data/lib/myco/bootstrap/instance.rb +52 -0
- data/lib/myco/bootstrap/meme.rb +160 -0
- data/lib/myco/bootstrap/void.rb +40 -0
- data/lib/myco/bootstrap.my +15 -0
- data/lib/myco/bootstrap.rb +10 -0
- data/lib/myco/command.my +33 -0
- data/lib/myco/core/BasicObject.my +46 -0
- data/lib/myco/core/Category.my +5 -0
- data/lib/myco/core/Decorator.my +18 -0
- data/lib/myco/core/FileToplevel.my +23 -0
- data/lib/myco/core/Object.my +24 -0
- data/lib/myco/core/Switch.my +31 -0
- data/lib/myco/eval.rb +63 -0
- data/lib/myco/parser/ast/constant_access.rb +29 -0
- data/lib/myco/parser/ast/constant_define.rb +40 -0
- data/lib/myco/parser/ast/constant_reopen.rb +47 -0
- data/lib/myco/parser/ast/declare_category.rb +51 -0
- data/lib/myco/parser/ast/declare_decorator.rb +35 -0
- data/lib/myco/parser/ast/declare_file.rb +54 -0
- data/lib/myco/parser/ast/declare_meme.rb +44 -0
- data/lib/myco/parser/ast/declare_object.rb +75 -0
- data/lib/myco/parser/ast/declare_string.rb +37 -0
- data/lib/myco/parser/ast/invoke.rb +66 -0
- data/lib/myco/parser/ast/local_variable_access_ambiguous.rb +38 -0
- data/lib/myco/parser/ast/misc.rb +61 -0
- data/lib/myco/parser/ast/myco_module_scope.rb +58 -0
- data/lib/myco/parser/ast/quest.rb +82 -0
- data/lib/myco/parser/ast.rb +15 -0
- data/lib/myco/parser/builder.output +3995 -0
- data/lib/myco/parser/builder.racc +585 -0
- data/lib/myco/parser/builder.rb +1592 -0
- data/lib/myco/parser/lexer.rb +2306 -0
- data/lib/myco/parser/lexer.rl +393 -0
- data/lib/myco/parser/lexer_char_classes.rl +56 -0
- data/lib/myco/parser/lexer_common.rb +95 -0
- data/lib/myco/parser/lexer_skeleton.rl +154 -0
- data/lib/myco/parser/peg_parser.kpeg +759 -0
- data/lib/myco/parser/peg_parser.rb +7094 -0
- data/lib/myco/parser.rb +40 -0
- data/lib/myco/tools/OptionParser.my +38 -0
- data/lib/myco/tools/mycompile.my +51 -0
- data/lib/myco/toolset.rb +16 -0
- data/lib/myco/version.rb +22 -0
- data/lib/myco.rb +15 -0
- metadata +247 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
module CodeTools::AST
|
3
|
+
|
4
|
+
module ProcessorMethods
|
5
|
+
def process_null line
|
6
|
+
NullLiteral.new line
|
7
|
+
end
|
8
|
+
|
9
|
+
def process_void line
|
10
|
+
VoidLiteral.new line
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class NullLiteral < NilLiteral
|
15
|
+
def to_sexp
|
16
|
+
[:null]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Replace NilLiteral with NullLiteral and let original NilLiteral "disappear"
|
21
|
+
NilLiteral = NullLiteral
|
22
|
+
|
23
|
+
class VoidLiteral < Node
|
24
|
+
def bytecode(g)
|
25
|
+
pos(g)
|
26
|
+
|
27
|
+
# TODO: create push_void helper to abstract this out (and elsewhere)
|
28
|
+
g.push_cpath_top
|
29
|
+
g.find_const :Myco
|
30
|
+
g.find_const :Void
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_sexp
|
34
|
+
[:void]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
# Patch the And (and Or) Node bytecode to use .false? to determine falsehood
|
40
|
+
# This accomodates treating Void (or any other non-builtin) as falsey
|
41
|
+
# TODO: use new branch instruction when it gets added to Rubinius
|
42
|
+
class And
|
43
|
+
def bytecode(g, use_git=true)
|
44
|
+
@left.bytecode(g)
|
45
|
+
g.dup
|
46
|
+
lbl = g.new_label
|
47
|
+
|
48
|
+
g.send :false?, 0
|
49
|
+
if use_git
|
50
|
+
g.git lbl
|
51
|
+
else
|
52
|
+
g.gif lbl
|
53
|
+
end
|
54
|
+
|
55
|
+
g.pop
|
56
|
+
@right.bytecode(g)
|
57
|
+
lbl.set!
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
module CodeTools::AST
|
3
|
+
|
4
|
+
class MycoModuleScope < ModuleScope
|
5
|
+
def initialize(line, body)
|
6
|
+
@line = line
|
7
|
+
@name = :MycoModuleScope # TODO: remove/fix
|
8
|
+
@body = body
|
9
|
+
end
|
10
|
+
|
11
|
+
def bytecode(g)
|
12
|
+
pos(g)
|
13
|
+
|
14
|
+
attach_and_call g, :__myco_module_init__, true
|
15
|
+
end
|
16
|
+
|
17
|
+
# TODO: figure out how to keep in sync with ClosedScope#attach_and_call impl
|
18
|
+
def attach_and_call(g, arg_name, scoped=false, pass_block=false)
|
19
|
+
name = @name || arg_name
|
20
|
+
meth = new_generator(g, name)
|
21
|
+
|
22
|
+
meth.push_state self
|
23
|
+
meth.for_module_body = true
|
24
|
+
|
25
|
+
if scoped
|
26
|
+
meth.push_self
|
27
|
+
meth.add_scope
|
28
|
+
end
|
29
|
+
|
30
|
+
meth.state.push_name name
|
31
|
+
|
32
|
+
body_bytecode meth # (@body.bytecode meth) in original implementation
|
33
|
+
|
34
|
+
meth.state.pop_name
|
35
|
+
|
36
|
+
meth.ret
|
37
|
+
meth.close
|
38
|
+
|
39
|
+
meth.local_count = local_count
|
40
|
+
meth.local_names = local_names
|
41
|
+
|
42
|
+
meth.pop_state
|
43
|
+
|
44
|
+
g.create_block meth
|
45
|
+
g.swap
|
46
|
+
g.push_scope
|
47
|
+
g.push_true
|
48
|
+
g.send :call_under, 3
|
49
|
+
|
50
|
+
return meth
|
51
|
+
end
|
52
|
+
|
53
|
+
def body_bytecode g
|
54
|
+
@body.bytecode g
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
module CodeTools::AST
|
3
|
+
|
4
|
+
module ProcessorMethods
|
5
|
+
def process_quest line, receiver, questable
|
6
|
+
Quest.new line, receiver, questable
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Quest < Node
|
11
|
+
attr_accessor :receiver
|
12
|
+
attr_accessor :questable
|
13
|
+
|
14
|
+
def initialize line, receiver, questable
|
15
|
+
@line = line
|
16
|
+
@receiver = receiver
|
17
|
+
@questable = questable
|
18
|
+
|
19
|
+
@void_literal = VoidLiteral.new @line
|
20
|
+
|
21
|
+
@questable.receiver = FakeReceiver.new @line
|
22
|
+
end
|
23
|
+
|
24
|
+
def bytecode g
|
25
|
+
pos(g)
|
26
|
+
|
27
|
+
##
|
28
|
+
# unless @receiver.respond_to?(@questable.name).false?
|
29
|
+
# execute_statement @questable
|
30
|
+
# else
|
31
|
+
# return void
|
32
|
+
# end
|
33
|
+
|
34
|
+
else_label = g.new_label
|
35
|
+
end_label = g.new_label
|
36
|
+
|
37
|
+
@receiver.bytecode g
|
38
|
+
g.dup_top # dup the receiver to save it for later
|
39
|
+
g.push_literal @questable.name
|
40
|
+
g.send :respond_to?, 1
|
41
|
+
g.send :false?, 0
|
42
|
+
g.goto_if_true else_label
|
43
|
+
|
44
|
+
# The duped receiver is still at the top of the stack,
|
45
|
+
# and @questable.receiver has been set to an instance of FakeReceiver
|
46
|
+
# to let the true receiver pass through instead.
|
47
|
+
@questable.bytecode g
|
48
|
+
g.goto end_label
|
49
|
+
|
50
|
+
else_label.set!
|
51
|
+
g.pop # pop the duped receiver - it won't be used after all
|
52
|
+
g.push_cpath_top
|
53
|
+
g.find_const :Myco
|
54
|
+
g.find_const :Void
|
55
|
+
|
56
|
+
end_label.set!
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_sexp
|
60
|
+
[:quest, @receiver.to_sexp, @questable.to_sexp]
|
61
|
+
end
|
62
|
+
|
63
|
+
class FakeReceiver < Node
|
64
|
+
def initialize line
|
65
|
+
@line = line
|
66
|
+
end
|
67
|
+
|
68
|
+
def bytecode g
|
69
|
+
pos(g)
|
70
|
+
# Do nothing here - this would normally be ill-advised,
|
71
|
+
# because Nodes are expected to push an item onto the stack,
|
72
|
+
# but here we are intentionally not doing so because
|
73
|
+
# the real receiver should already at the top of the stack
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_sexp
|
77
|
+
[:qrcvr]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
require_relative "ast/constant_access"
|
3
|
+
require_relative "ast/constant_define"
|
4
|
+
require_relative "ast/constant_reopen"
|
5
|
+
require_relative "ast/declare_category"
|
6
|
+
require_relative "ast/declare_decorator"
|
7
|
+
require_relative "ast/declare_file"
|
8
|
+
require_relative "ast/declare_meme"
|
9
|
+
require_relative "ast/declare_object"
|
10
|
+
require_relative "ast/declare_string"
|
11
|
+
require_relative "ast/invoke"
|
12
|
+
require_relative "ast/local_variable_access_ambiguous"
|
13
|
+
require_relative "ast/quest"
|
14
|
+
|
15
|
+
require_relative "ast/misc"
|