halunke 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/examples/hello.hal +19 -0
- data/examples/web.hal +20 -0
- data/exe/halunke +11 -7
- data/halunke.gemspec +2 -0
- data/lib/halunke/grammar.y +16 -32
- data/lib/halunke/interpreter.rb +56 -2
- data/lib/halunke/lexer.rb +95 -80
- data/lib/halunke/lexer.rl +7 -3
- data/lib/halunke/nodes.rb +24 -25
- data/lib/halunke/parser.rb +97 -112
- data/lib/halunke/runtime.rb +11 -222
- data/lib/halunke/runtime/false.hal +18 -0
- data/lib/halunke/runtime/harray.rb +30 -0
- data/lib/halunke/runtime/hclass.rb +96 -0
- data/lib/halunke/runtime/hdictionary.rb +26 -0
- data/lib/halunke/runtime/hfunction.rb +27 -0
- data/lib/halunke/runtime/hnative_object.rb +21 -0
- data/lib/halunke/runtime/hnumber.rb +41 -0
- data/lib/halunke/runtime/hobject.rb +30 -0
- data/lib/halunke/runtime/hstdout.rb +16 -0
- data/lib/halunke/runtime/hstring.rb +35 -0
- data/lib/halunke/runtime/hunassigned_bareword.rb +19 -0
- data/lib/halunke/runtime/hweb.rb +40 -0
- data/lib/halunke/runtime/true.hal +18 -0
- data/lib/halunke/version.rb +1 -1
- metadata +31 -2
@@ -0,0 +1,41 @@
|
|
1
|
+
module Halunke
|
2
|
+
module Runtime
|
3
|
+
HNumber = HClass.new(
|
4
|
+
"Number",
|
5
|
+
[],
|
6
|
+
{
|
7
|
+
"+" => HFunction.new([:self, :other], lambda { |context|
|
8
|
+
HNumber.create_instance(context["self"].ruby_value + context["other"].ruby_value)
|
9
|
+
}),
|
10
|
+
"<" => HFunction.new([:self, :other], lambda { |context|
|
11
|
+
if context["self"].ruby_value < context["other"].ruby_value
|
12
|
+
context["true"]
|
13
|
+
else
|
14
|
+
context["false"]
|
15
|
+
end
|
16
|
+
}),
|
17
|
+
">" => HFunction.new([:self, :other], lambda { |context|
|
18
|
+
if context["self"].ruby_value > context["other"].ruby_value
|
19
|
+
context["true"]
|
20
|
+
else
|
21
|
+
context["false"]
|
22
|
+
end
|
23
|
+
}),
|
24
|
+
"=" => HFunction.new([:self, :other], lambda { |context|
|
25
|
+
if context["self"].ruby_value == context["other"].ruby_value
|
26
|
+
context["true"]
|
27
|
+
else
|
28
|
+
context["false"]
|
29
|
+
end
|
30
|
+
}),
|
31
|
+
"inspect" => HFunction.new([:self], lambda { |context|
|
32
|
+
float_value = context["self"].ruby_value.to_f
|
33
|
+
float_value = float_value.to_i if float_value.to_i == float_value
|
34
|
+
HString.create_instance(float_value.to_s)
|
35
|
+
})
|
36
|
+
},
|
37
|
+
{},
|
38
|
+
true
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Halunke
|
2
|
+
module Runtime
|
3
|
+
class HObject
|
4
|
+
attr_reader :dict
|
5
|
+
|
6
|
+
def initialize(runtime_class, dict)
|
7
|
+
@runtime_class = runtime_class
|
8
|
+
@dict = {}
|
9
|
+
dict.each_pair do |hkey, value|
|
10
|
+
key = hkey.ruby_value
|
11
|
+
raise "Unknown attribute '#{key}' for #{@runtime_class.name}" unless @runtime_class.allowed_attribute? key
|
12
|
+
@dict[key] = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def receive_message(context, message_name, message_value)
|
17
|
+
if message_name == "@ else"
|
18
|
+
@dict.fetch(message_value[0].ruby_value, message_value[1])
|
19
|
+
else
|
20
|
+
m = @runtime_class.lookup(message_name)
|
21
|
+
m.receive_message(context, "call", [HArray.create_instance([self].concat(message_value))])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect(context)
|
26
|
+
receive_message(context, "inspect", []).ruby_value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Halunke
|
2
|
+
module Runtime
|
3
|
+
HString = HClass.new(
|
4
|
+
"String",
|
5
|
+
[],
|
6
|
+
{
|
7
|
+
"reverse" => HFunction.new([:self], lambda { |context|
|
8
|
+
HString.create_instance(context["self"].ruby_value.reverse)
|
9
|
+
}),
|
10
|
+
"replace with" => HFunction.new([:self, :searchword, :replacement], lambda { |context|
|
11
|
+
result = context["self"].ruby_value.gsub(
|
12
|
+
context["searchword"].ruby_value,
|
13
|
+
context["replacement"].ruby_value
|
14
|
+
)
|
15
|
+
HString.create_instance(result)
|
16
|
+
}),
|
17
|
+
"=" => HFunction.new([:self, :other], lambda { |context|
|
18
|
+
if context["self"].ruby_value == context["other"].ruby_value
|
19
|
+
context["true"]
|
20
|
+
else
|
21
|
+
context["false"]
|
22
|
+
end
|
23
|
+
}),
|
24
|
+
"+" => HFunction.new([:self, :other], lambda { |context|
|
25
|
+
HString.create_instance(context["self"].ruby_value + context["other"].ruby_value)
|
26
|
+
}),
|
27
|
+
"inspect" => HFunction.new([:self], lambda { |context|
|
28
|
+
HString.create_instance(context["self"].ruby_value.inspect)
|
29
|
+
})
|
30
|
+
},
|
31
|
+
{},
|
32
|
+
true
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Halunke
|
2
|
+
module Runtime
|
3
|
+
HUnassignedBareword = HClass.new(
|
4
|
+
"UnassignedBareword",
|
5
|
+
[],
|
6
|
+
{
|
7
|
+
"=" => HFunction.new([:self, :other], lambda { |context|
|
8
|
+
context.parent[context["self"].ruby_value] = context["other"]
|
9
|
+
context["true"]
|
10
|
+
}),
|
11
|
+
"inspect" => HFunction.new([:self], lambda { |context|
|
12
|
+
HString.create_instance("'#{context["self"].ruby_value}")
|
13
|
+
})
|
14
|
+
},
|
15
|
+
{},
|
16
|
+
true
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Halunke
|
2
|
+
module Runtime
|
3
|
+
HWeb = HClass.new(
|
4
|
+
"Web",
|
5
|
+
[],
|
6
|
+
{
|
7
|
+
"run on" => HFunction.new([:self, :app, :host_port], lambda { |context|
|
8
|
+
require "rack"
|
9
|
+
|
10
|
+
host, port = context["host_port"].ruby_value.split(":")
|
11
|
+
|
12
|
+
# TODO: Body, Headers
|
13
|
+
Rack::Handler::WEBrick.run(lambda { |env|
|
14
|
+
henv = context["Dictionary"].create_instance(
|
15
|
+
context["String"].create_instance("request_method") => context["String"].create_instance(env["REQUEST_METHOD"]),
|
16
|
+
context["String"].create_instance("path") => context["String"].create_instance(env["PATH_INFO"]),
|
17
|
+
context["String"].create_instance("query") => context["String"].create_instance(env["QUERY_STRING"])
|
18
|
+
)
|
19
|
+
result = context["app"].receive_message(context, "call", [henv]).ruby_value
|
20
|
+
|
21
|
+
status = result[0].ruby_value
|
22
|
+
|
23
|
+
headers = {}
|
24
|
+
result[1].ruby_value.each_pair do |key, value|
|
25
|
+
headers[key.ruby_value] = value.ruby_value
|
26
|
+
end
|
27
|
+
|
28
|
+
body = result[2].ruby_value.map(&:ruby_value)
|
29
|
+
|
30
|
+
[status, headers, body]
|
31
|
+
}, { Host: host, Port: port })
|
32
|
+
|
33
|
+
env["host_port"]
|
34
|
+
})
|
35
|
+
},
|
36
|
+
{},
|
37
|
+
true
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
(Class new 'True
|
2
|
+
methods @[
|
3
|
+
"and" { |'self 'other|
|
4
|
+
other
|
5
|
+
}
|
6
|
+
"or" { |'self 'other|
|
7
|
+
self
|
8
|
+
}
|
9
|
+
"then else" { |'self 'true_branch 'false_branch|
|
10
|
+
(true_branch call [])
|
11
|
+
}
|
12
|
+
"inspect" { |'self 'other|
|
13
|
+
"true"
|
14
|
+
}
|
15
|
+
]
|
16
|
+
)
|
17
|
+
|
18
|
+
('true = (True new))
|
data/lib/halunke/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: halunke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Dohmen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.4
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,6 +100,8 @@ files:
|
|
86
100
|
- Rakefile
|
87
101
|
- bin/console
|
88
102
|
- bin/setup
|
103
|
+
- examples/hello.hal
|
104
|
+
- examples/web.hal
|
89
105
|
- exe/halunke
|
90
106
|
- halunke.gemspec
|
91
107
|
- lib/halunke.rb
|
@@ -96,6 +112,19 @@ files:
|
|
96
112
|
- lib/halunke/nodes.rb
|
97
113
|
- lib/halunke/parser.rb
|
98
114
|
- lib/halunke/runtime.rb
|
115
|
+
- lib/halunke/runtime/false.hal
|
116
|
+
- lib/halunke/runtime/harray.rb
|
117
|
+
- lib/halunke/runtime/hclass.rb
|
118
|
+
- lib/halunke/runtime/hdictionary.rb
|
119
|
+
- lib/halunke/runtime/hfunction.rb
|
120
|
+
- lib/halunke/runtime/hnative_object.rb
|
121
|
+
- lib/halunke/runtime/hnumber.rb
|
122
|
+
- lib/halunke/runtime/hobject.rb
|
123
|
+
- lib/halunke/runtime/hstdout.rb
|
124
|
+
- lib/halunke/runtime/hstring.rb
|
125
|
+
- lib/halunke/runtime/hunassigned_bareword.rb
|
126
|
+
- lib/halunke/runtime/hweb.rb
|
127
|
+
- lib/halunke/runtime/true.hal
|
99
128
|
- lib/halunke/version.rb
|
100
129
|
homepage: https://github.com/moonglum/halunke
|
101
130
|
licenses:
|