loxxy 0.1.09 → 0.1.10
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/CHANGELOG.md +7 -0
- data/lib/loxxy/back_end/resolver.rb +15 -2
- data/lib/loxxy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fc5399ac3346487808eeb40403b3324cca384e3c6820d965b75f2e320759d2c
|
4
|
+
data.tar.gz: f9b6497d87036f6c88ed09a72113a1ea004df9db8fd9bb945672c370993f7fde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b0fa0313a0b37882d0398238a65f10b6ea8ab4325447e1f4690ea7100bdb85dead8cb15d8e1e56b422741697d636c7e2c114cf17ad43781dc23462ab51c93af
|
7
|
+
data.tar.gz: b93b3d01a0e80def496ecfeb955e64000cc88149229ceb97e2743ccda863ec23677958aad9423dd0ca433d72451e120be6fa40247db7cbc49710ac8c17ea8987
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.1.10] - 2021-03-31
|
2
|
+
- Flag return statements occurring outside functions as an error
|
3
|
+
|
4
|
+
### Changed
|
5
|
+
- Class `BackEnd::Resolver` Added attribute `current_function` to know whether the visited parse node is located inside a function
|
6
|
+
|
7
|
+
|
1
8
|
## [0.1.09] - 2021-03-28
|
2
9
|
- Fix and test suite for return statements
|
3
10
|
|
@@ -22,9 +22,14 @@ module Loxxy
|
|
22
22
|
# @return [Hash {LoxNode => Integer}]
|
23
23
|
attr_reader :locals
|
24
24
|
|
25
|
+
# An indicator that tells we're in the middle of a function declaration
|
26
|
+
# @return [Symbol] must be one of: :none, :function
|
27
|
+
attr_reader :current_function
|
28
|
+
|
25
29
|
def initialize
|
26
30
|
@scopes = []
|
27
31
|
@locals = {}
|
32
|
+
@current_function = :none
|
28
33
|
end
|
29
34
|
|
30
35
|
# Given an abstract syntax parse tree visitor, launch the visit
|
@@ -69,6 +74,11 @@ module Loxxy
|
|
69
74
|
msg = "Error at 'return': Can't return from top-level code."
|
70
75
|
raise StandardError, msg
|
71
76
|
end
|
77
|
+
|
78
|
+
if current_function == :none
|
79
|
+
msg = "Error at 'return': Can't return from outside a function."
|
80
|
+
raise StandardError, msg
|
81
|
+
end
|
72
82
|
end
|
73
83
|
|
74
84
|
def after_while_stmt(aWhileStmt, aVisitor)
|
@@ -112,7 +122,7 @@ module Loxxy
|
|
112
122
|
def before_fun_stmt(aFunStmt, aVisitor)
|
113
123
|
declare(aFunStmt.name)
|
114
124
|
define(aFunStmt.name)
|
115
|
-
resolve_function(aFunStmt, aVisitor)
|
125
|
+
resolve_function(aFunStmt, :function ,aVisitor)
|
116
126
|
end
|
117
127
|
|
118
128
|
private
|
@@ -162,7 +172,9 @@ module Loxxy
|
|
162
172
|
end
|
163
173
|
end
|
164
174
|
|
165
|
-
def resolve_function(aFunStmt, aVisitor)
|
175
|
+
def resolve_function(aFunStmt, funVisitState, aVisitor)
|
176
|
+
enclosing_function = current_function
|
177
|
+
@current_function = funVisitState
|
166
178
|
begin_scope
|
167
179
|
|
168
180
|
aFunStmt.params&.each do |param_name|
|
@@ -176,6 +188,7 @@ module Loxxy
|
|
176
188
|
end
|
177
189
|
|
178
190
|
end_scope
|
191
|
+
@current_function = enclosing_function
|
179
192
|
end
|
180
193
|
end # class
|
181
194
|
end # mmodule
|
data/lib/loxxy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loxxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rley
|