loxxy 0.2.03 → 0.2.04

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: eb84858746525e4b5f6821e8168066f4af75b639e8320710cd36213ac72a65ed
4
- data.tar.gz: 6ef7b9c8edcfdd1cda3aadfedeff6fef99c1194e92782c3dfe1b1abcc8052e96
3
+ metadata.gz: d628b0737a29bab0869827af50a363846200bfab7baddc63279e0e3fb904fa75
4
+ data.tar.gz: d617939297fe24cf267fb66c198cbc172e05a7df4472eac546bd9b5e27eef0cd
5
5
  SHA512:
6
- metadata.gz: 901731bc9670cab315c53e864430636c14c70b9c15d2218d81ae5657b40e5261b79d7ae7ff7937a638931a0c89af8d75f99a65973dd4cbd9a3418588f6388e87
7
- data.tar.gz: fdedef4073b56af0e5bd2f348b15149dd80ab96d8814b5f0f114529372594ae661203509306603b6be8773976f577aaf73466d6a778a4596f11fd0d383c88dd6
6
+ metadata.gz: dde10867e0a0243a5c0e2349a37df2ec76178aa2a7da625abd42363175301bf773d8d56aa249dde380361b13af5181c33a8ed65a4cf1bd2bbdaf2c946b534f99
7
+ data.tar.gz: 204243d4d781f54820a66d483d791676d144b3a4af7febbb2a1a27041c651d2ea4a0015e2bf3408754c9ea31dc0f66b4c6b0d8ad6175edc5912391331f95e9e1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## [0.2.04] - 2021-04-25
2
+ - `Loxxy` passes the test suite for `for` statements
3
+
4
+ ### Fixed
5
+ - Method `BackEnd::Engine#after_for_stmt` now a for(;;) executes the body once; a for without test will execute forever
6
+ - Method `BackEnd::Resolver#after_for_stmt now accepts nil test expression
7
+
8
+ ## [0.2.03] - 2021-04-24
9
+ - Fixes for the set (field) expressions, `accept` methods for AST nodes are meta-programmed
10
+
11
+ ### New
12
+ - Module `Ast::Visitee` provides the `define_accept` method that generate `accept` method with meta-programming
13
+
14
+ ### Fixed
15
+ - Method `BackEnd::Engine#before_set_expr` methos method that ensure that the receiver is evaluated first, then the assigned value
16
+ - Method `BackEnd::Engine#after_set_expr` now pushes the value assigned to the field also onto the stack
17
+ - Class `BackEnd::Engine` a number of StnadardError exceptions are replaced by Loxxy::RuntimeError
18
+
19
+
1
20
  ## [0.2.02] - 2021-04-21
2
21
  - Improvements in the scanner class (escape sequence for quotes and newlines), error messages closer to jlox.
3
22
 
@@ -117,10 +117,19 @@ module Loxxy
117
117
  end
118
118
 
119
119
  def after_for_stmt(aForStmt, aVisitor)
120
+ iterating = false
121
+
120
122
  loop do
121
- aForStmt.test_expr.accept(aVisitor)
122
- condition = stack.pop
123
- break unless condition.truthy?
123
+ if aForStmt.test_expr
124
+ aForStmt.test_expr.accept(aVisitor)
125
+ condition = stack.pop
126
+ break unless condition.truthy?
127
+ elsif iterating
128
+ # when both test and update expressions are nil => execute body once
129
+ break unless aForStmt.update_expr
130
+ else
131
+ iterating = true
132
+ end
124
133
 
125
134
  aForStmt.body_stmt.accept(aVisitor)
126
135
  aForStmt.update_expr&.accept(aVisitor)
@@ -93,7 +93,7 @@ module Loxxy
93
93
  end
94
94
 
95
95
  def after_for_stmt(aForStmt, aVisitor)
96
- aForStmt.test_expr.accept(aVisitor)
96
+ aForStmt.test_expr&.accept(aVisitor)
97
97
  aForStmt.body_stmt.accept(aVisitor)
98
98
  aForStmt.update_expr&.accept(aVisitor)
99
99
  after_block_stmt(aForStmt)
@@ -46,7 +46,7 @@ module Loxxy
46
46
  # Stop if the parse failed...
47
47
  line1 = "Parsing failed\n"
48
48
  line2 = "Reason: #{result.failure_reason.message}"
49
- raise StandardError, line1 + line2
49
+ raise SyntaxError, line1 + line2
50
50
  end
51
51
 
52
52
  return engine.convert(result) # engine.to_ptree(result)
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.2.03'
4
+ VERSION = '0.2.04'
5
5
  end
@@ -431,6 +431,17 @@ LOX_END
431
431
  expect(result).to eq(3)
432
432
  end
433
433
 
434
+ it 'should support return within statements inside a function' do
435
+ program = <<-LOX_END
436
+ fun foo() {
437
+ for (;;) return "done";
438
+ }
439
+ print foo(); // output: done
440
+ LOX_END
441
+ expect { subject.evaluate(program) }.not_to raise_error
442
+ expect(sample_cfg[:ostream].string).to eq('done')
443
+ end
444
+
434
445
  # rubocop: disable Style/StringConcatenation
435
446
  it 'should support local functions and closures' do
436
447
  program = <<-LOX_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.2.03
4
+ version: 0.2.04
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-04-24 00:00:00.000000000 Z
11
+ date: 2021-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley