loxxy 0.2.00 → 0.2.05

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +47 -11
  3. data/CHANGELOG.md +81 -0
  4. data/README.md +188 -90
  5. data/bin/loxxy +54 -6
  6. data/lib/loxxy.rb +1 -0
  7. data/lib/loxxy/ast/all_lox_nodes.rb +0 -1
  8. data/lib/loxxy/ast/ast_builder.rb +27 -4
  9. data/lib/loxxy/ast/ast_visitee.rb +53 -0
  10. data/lib/loxxy/ast/ast_visitor.rb +2 -10
  11. data/lib/loxxy/ast/lox_assign_expr.rb +1 -5
  12. data/lib/loxxy/ast/lox_binary_expr.rb +1 -6
  13. data/lib/loxxy/ast/lox_block_stmt.rb +1 -5
  14. data/lib/loxxy/ast/lox_call_expr.rb +1 -5
  15. data/lib/loxxy/ast/lox_class_stmt.rb +1 -5
  16. data/lib/loxxy/ast/lox_fun_stmt.rb +1 -5
  17. data/lib/loxxy/ast/lox_get_expr.rb +1 -6
  18. data/lib/loxxy/ast/lox_grouping_expr.rb +1 -5
  19. data/lib/loxxy/ast/lox_if_stmt.rb +2 -6
  20. data/lib/loxxy/ast/lox_literal_expr.rb +1 -5
  21. data/lib/loxxy/ast/lox_logical_expr.rb +1 -6
  22. data/lib/loxxy/ast/lox_node.rb +9 -1
  23. data/lib/loxxy/ast/lox_print_stmt.rb +1 -5
  24. data/lib/loxxy/ast/lox_return_stmt.rb +1 -5
  25. data/lib/loxxy/ast/lox_seq_decl.rb +1 -5
  26. data/lib/loxxy/ast/lox_set_expr.rb +1 -5
  27. data/lib/loxxy/ast/lox_super_expr.rb +2 -6
  28. data/lib/loxxy/ast/lox_this_expr.rb +1 -5
  29. data/lib/loxxy/ast/lox_unary_expr.rb +1 -6
  30. data/lib/loxxy/ast/lox_var_stmt.rb +1 -5
  31. data/lib/loxxy/ast/lox_variable_expr.rb +1 -5
  32. data/lib/loxxy/ast/lox_while_stmt.rb +2 -6
  33. data/lib/loxxy/back_end/engine.rb +13 -22
  34. data/lib/loxxy/back_end/lox_instance.rb +1 -1
  35. data/lib/loxxy/back_end/resolver.rb +1 -12
  36. data/lib/loxxy/cli_parser.rb +68 -0
  37. data/lib/loxxy/error.rb +3 -0
  38. data/lib/loxxy/front_end/parser.rb +1 -1
  39. data/lib/loxxy/front_end/scanner.rb +37 -12
  40. data/lib/loxxy/version.rb +1 -1
  41. data/loxxy.gemspec +5 -1
  42. data/spec/front_end/scanner_spec.rb +41 -0
  43. data/spec/interpreter_spec.rb +23 -0
  44. metadata +8 -4
  45. data/lib/loxxy/ast/lox_for_stmt.rb +0 -41
@@ -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
@@ -480,6 +491,18 @@ LOX_END
480
491
  snippet
481
492
  end
482
493
 
494
+ it 'should support field assignment expression' do
495
+ program = <<-LOX_END
496
+ class Foo {}
497
+
498
+ var foo = Foo();
499
+
500
+ print foo.bar = "bar value"; // expect: bar value
501
+ LOX_END
502
+ expect { subject.evaluate(program) }.not_to raise_error
503
+ expect(sample_cfg[:ostream].string).to eq('bar value')
504
+ end
505
+
483
506
  it 'should support class declaration' do
484
507
  program = <<-LOX_END
485
508
  #{duck_class}
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.00
4
+ version: 0.2.05
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-17 00:00:00.000000000 Z
11
+ date: 2021-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley
@@ -66,7 +66,10 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
- description: An implementation of the Lox programming language.
69
+ description: |2
70
+ A Ruby implementation of the Lox programming language. Lox is a dynamically typed,
71
+ object-oriented programming language that features first-class functions, closures,
72
+ classes, and inheritance.
70
73
  email:
71
74
  - famished.tiger@yahoo.com
72
75
  executables:
@@ -88,6 +91,7 @@ files:
88
91
  - lib/loxxy.rb
89
92
  - lib/loxxy/ast/all_lox_nodes.rb
90
93
  - lib/loxxy/ast/ast_builder.rb
94
+ - lib/loxxy/ast/ast_visitee.rb
91
95
  - lib/loxxy/ast/ast_visitor.rb
92
96
  - lib/loxxy/ast/lox_assign_expr.rb
93
97
  - lib/loxxy/ast/lox_binary_expr.rb
@@ -95,7 +99,6 @@ files:
95
99
  - lib/loxxy/ast/lox_call_expr.rb
96
100
  - lib/loxxy/ast/lox_class_stmt.rb
97
101
  - lib/loxxy/ast/lox_compound_expr.rb
98
- - lib/loxxy/ast/lox_for_stmt.rb
99
102
  - lib/loxxy/ast/lox_fun_stmt.rb
100
103
  - lib/loxxy/ast/lox_get_expr.rb
101
104
  - lib/loxxy/ast/lox_grouping_expr.rb
@@ -125,6 +128,7 @@ files:
125
128
  - lib/loxxy/back_end/symbol_table.rb
126
129
  - lib/loxxy/back_end/unary_operator.rb
127
130
  - lib/loxxy/back_end/variable.rb
131
+ - lib/loxxy/cli_parser.rb
128
132
  - lib/loxxy/datatype/all_datatypes.rb
129
133
  - lib/loxxy/datatype/boolean.rb
130
134
  - lib/loxxy/datatype/builtin_datatype.rb
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lox_compound_expr'
4
-
5
- module Loxxy
6
- module Ast
7
- class LoxForStmt < LoxCompoundExpr
8
- # @return [LoxNode] test expression
9
- attr_reader :test_expr
10
-
11
- # @return [LoxNode] update expression
12
- attr_reader :update_expr
13
-
14
- # @return [LoxNode] body statement
15
- attr_accessor :body_stmt
16
-
17
- # @param aPosition [Rley::Lexical::Position] Position of the entry in the input stream.
18
- # @param initialization [Loxxy::Ast::LoxNode]
19
- # @param testExpr [Loxxy::Ast::LoxNode]
20
- # @param updateExpr [Loxxy::Ast::LoxNode]
21
- def initialize(aPosition, initialization, testExpr, updateExpr)
22
- child = initialization ? [initialization] : []
23
- super(aPosition, child)
24
- @test_expr = testExpr
25
- @update_expr = updateExpr
26
- end
27
-
28
- # Part of the 'visitee' role in Visitor design pattern.
29
- # @param visitor [Ast::ASTVisitor] the visitor
30
- def accept(visitor)
31
- visitor.visit_for_stmt(self)
32
- end
33
-
34
- # Accessor to the condition expression
35
- # @return [LoxNode]
36
- def condition
37
- subnodes[0]
38
- end
39
- end # class
40
- end # module
41
- end # module