loxxy 0.1.08 → 0.1.09

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1724fce16b30fe2328ba31a725e92cc03f43ac7dee60fd54c68642c5a5639471
4
- data.tar.gz: 0f045add2ebf55375ee63e94f3a7316984588d0133200f3f4ce45de3ae118157
3
+ metadata.gz: 1d027baa99cb59b7a102b55d1dec07e75f7cb17a71c42708881507ae8bc83b75
4
+ data.tar.gz: 6f27ba42c296a5845185fb8d746fd8cf24d9b8b71c2c98d590fa8a9c22cac33f
5
5
  SHA512:
6
- metadata.gz: 5e4a67161f2d6f6a89b237bdda4e1d096df1183eeb3a9b8ff4f1506d8b053bae265de73857faf82a225b77fad5d32faddfe07873d74e0e71a2839f113659c61b
7
- data.tar.gz: 29d09adcb56231c4f7b7c911c16b978e4ec3e0608f754e8b80b971293b99ea96fcf2bb6cd55dec62a8acac00bde0fb9b93e86cc37ee11024faea8e8eb0a70d3f
6
+ metadata.gz: 0b71f56915f53a4ece5bcfde6b74ee7d407517b54038b3a00a945813acd3137c5da8800f8ac2fea71220b35557d18eb63fef25ac0b90297b1067a9ed65e70a55
7
+ data.tar.gz: b6faed818eff75c6beb32137cd97777b332b9a79994ab74ddb70cc4a257778e8a2571ab59d8c612fc89e5bf5f3c7a4e9f3868748ae737b3fe0cce1e404681460
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.1.09] - 2021-03-28
2
+ - Fix and test suite for return statements
3
+
4
+ ### Changed
5
+ - `Loxxy` reports an error when a return statement occurs in top-level scope
6
+
7
+ ### Fixed
8
+ - A return without explicit value genrated an exception in some cases.
9
+
1
10
  ## [0.1.08] - 2021-03-27
2
11
  - `Loxxy` implements variable resolving and binding as described in Chapter 11 of "Crafting Interpreters" book.
3
12
 
data/README.md CHANGED
@@ -13,10 +13,9 @@ a simple language defined in Bob Nystrom's online book [Crafting Interpreters](h
13
13
  a Lox interpreter written in Lox.
14
14
 
15
15
  ### Current status
16
- The interpreter currently it can execute all allowed __Lox__ expressions and statements except
16
+ The interpreter currently can execute all allowed __Lox__ expressions and statements except
17
17
  object-oriented feaures (classes and objects).
18
-
19
- Our intent is implement to these missing features in Q2 2021.
18
+ The goal is to implement these missing features in Q2 2021.
20
19
 
21
20
 
22
21
  ## What's the fuss about Lox?
@@ -8,7 +8,8 @@ module Loxxy
8
8
  # @param aPosition [Rley::Lexical::Position] Position of the entry in the input stream.
9
9
  # @param anExpression [Ast::LoxNode] expression to return
10
10
  def initialize(aPosition, anExpression)
11
- super(aPosition, [anExpression])
11
+ expr = anExpression || Datatype::Nil.instance
12
+ super(aPosition, [expr])
12
13
  end
13
14
 
14
15
  # Part of the 'visitee' role in Visitor design pattern.
@@ -64,6 +64,13 @@ module Loxxy
64
64
  anIfStmt.else_stmt&.accept(aVisitor)
65
65
  end
66
66
 
67
+ def before_return_stmt(_returnStmt)
68
+ if scopes.size < 2
69
+ msg = "Error at 'return': Can't return from top-level code."
70
+ raise StandardError, msg
71
+ end
72
+ end
73
+
67
74
  def after_while_stmt(aWhileStmt, aVisitor)
68
75
  aWhileStmt.body.accept(aVisitor)
69
76
  aWhileStmt.condition.accept(aVisitor)
@@ -122,6 +129,10 @@ module Loxxy
122
129
  return if scopes.empty?
123
130
 
124
131
  curr_scope = scopes.last
132
+ if curr_scope.include?(aVarName)
133
+ msg = "Error at '#{aVarName}': Already variable with this name in this scope."
134
+ raise StandardError, msg
135
+ end
125
136
 
126
137
  # The initializer is not yet processed.
127
138
  # Mark the variable as 'not yet ready' = exists but may not be referenced yet
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.08'
4
+ VERSION = '0.1.09'
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.08
4
+ version: 0.1.09
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-27 00:00:00.000000000 Z
11
+ date: 2021-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley