loxxy 0.1.09 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d027baa99cb59b7a102b55d1dec07e75f7cb17a71c42708881507ae8bc83b75
4
- data.tar.gz: 6f27ba42c296a5845185fb8d746fd8cf24d9b8b71c2c98d590fa8a9c22cac33f
3
+ metadata.gz: 1fc5399ac3346487808eeb40403b3324cca384e3c6820d965b75f2e320759d2c
4
+ data.tar.gz: f9b6497d87036f6c88ed09a72113a1ea004df9db8fd9bb945672c370993f7fde
5
5
  SHA512:
6
- metadata.gz: 0b71f56915f53a4ece5bcfde6b74ee7d407517b54038b3a00a945813acd3137c5da8800f8ac2fea71220b35557d18eb63fef25ac0b90297b1067a9ed65e70a55
7
- data.tar.gz: b6faed818eff75c6beb32137cd97777b332b9a79994ab74ddb70cc4a257778e8a2571ab59d8c612fc89e5bf5f3c7a4e9f3868748ae737b3fe0cce1e404681460
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Loxxy
4
- VERSION = '0.1.09'
4
+ VERSION = '0.1.10'
5
5
  end
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.09
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-28 00:00:00.000000000 Z
11
+ date: 2021-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley