loxxy 0.1.05 → 0.1.06
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/loxxy/ast/ast_builder.rb +5 -1
- data/lib/loxxy/back_end/engine.rb +9 -9
- data/lib/loxxy/back_end/{function.rb → lox_function.rb} +5 -1
- data/lib/loxxy/error.rb +3 -0
- data/lib/loxxy/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 293bf5f6fb0eb5a1daf2723484a2867909c03cc99b20270e562d288d334f0bdc
|
4
|
+
data.tar.gz: 9e26854c6d4334f9869d0cd420ebd4365c0f978666e7ede8310d25e600cf5834
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ac692f16a41b162001fee869d426abf634f1a2bb82bf17eac26d8c35939a8ca63234246a6ff88cc04db3833057b445e2650773652ce102a0dcc4f3aa90182e8
|
7
|
+
data.tar.gz: 2764cb3d1703fdc948180cb2060f93a0ef72148f2877f5b711ecacd17d2ba52a9d3b9f7736eb53130850635cb0d127f2a5161a8361cb4a2268fc6275d15a6b1c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [0.1.06] - 2021-03-06
|
2
|
+
- Parameters/arguments checks in function declaration and call
|
3
|
+
|
4
|
+
### Changed
|
5
|
+
- Method `Ast::AstBuilder#reduce_call_arglist` raises a `Loxxy::RuntimeError` when more than 255 arguments are used.
|
6
|
+
- Method `BackEnd::Engine#after_call_expr` raises a `Loxxy::RuntimeError` when argument count doesn't match the arity of function.
|
7
|
+
|
8
|
+
- Class `BackEnd::Function` renamed to `LoxFunction`
|
9
|
+
|
1
10
|
## [0.1.05] - 2021-03-05
|
2
11
|
- Test for Fibbonacci recursive function is now passing.
|
3
12
|
|
@@ -273,7 +273,7 @@ module Loxxy
|
|
273
273
|
def reduce_call_arglist(_production, _range, tokens, theChildren)
|
274
274
|
args = theChildren[1] || []
|
275
275
|
if args.size > 255
|
276
|
-
raise
|
276
|
+
raise Loxxy::RuntimeError, "Can't have more than 255 arguments."
|
277
277
|
end
|
278
278
|
|
279
279
|
LoxCallExpr.new(tokens[0].position, args)
|
@@ -303,6 +303,10 @@ module Loxxy
|
|
303
303
|
def reduce_function(_production, _range, _tokens, theChildren)
|
304
304
|
first_child = theChildren.first
|
305
305
|
pos = first_child.token.position
|
306
|
+
if theChildren[2] && theChildren[2].size > 255
|
307
|
+
msg = "Can't have more than 255 parameters."
|
308
|
+
raise Loxxy::SyntaxError, msg
|
309
|
+
end
|
306
310
|
LoxFunStmt.new(pos, first_child.token.lexeme, theChildren[2], theChildren[4])
|
307
311
|
end
|
308
312
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# Load all the classes implementing AST nodes
|
4
4
|
require_relative '../ast/all_lox_nodes'
|
5
5
|
require_relative 'binary_operator'
|
6
|
-
require_relative '
|
6
|
+
require_relative 'lox_function'
|
7
7
|
require_relative 'symbol_table'
|
8
8
|
require_relative 'unary_operator'
|
9
9
|
|
@@ -199,18 +199,18 @@ module Loxxy
|
|
199
199
|
case callee
|
200
200
|
when NativeFunction
|
201
201
|
stack.push callee.call # Pass arguments
|
202
|
-
when
|
202
|
+
when LoxFunction
|
203
|
+
arg_count = aCallExpr.arguments.size
|
204
|
+
if arg_count != callee.arity
|
205
|
+
msg = "Expected #{callee.arity} arguments but got #{arg_count}."
|
206
|
+
raise Loxxy::RuntimeError, msg
|
207
|
+
end
|
203
208
|
callee.call(self, aVisitor)
|
204
209
|
else
|
205
210
|
raise Loxxy::RuntimeError, 'Can only call functions and classes.'
|
206
211
|
end
|
207
212
|
end
|
208
213
|
|
209
|
-
def complete_call
|
210
|
-
callee = ret_stack.pop
|
211
|
-
symbol_table.leave_environment if callee.kind_of?(Function)
|
212
|
-
end
|
213
|
-
|
214
214
|
def after_grouping_expr(_groupingExpr)
|
215
215
|
# Do nothing: work was already done by visiting /evaluating the subexpression
|
216
216
|
end
|
@@ -234,7 +234,7 @@ module Loxxy
|
|
234
234
|
end
|
235
235
|
|
236
236
|
def after_fun_stmt(aFunStmt, _visitor)
|
237
|
-
function =
|
237
|
+
function = LoxFunction.new(aFunStmt.name, aFunStmt.params, aFunStmt.body, stack)
|
238
238
|
new_var = Variable.new(aFunStmt.name, function)
|
239
239
|
symbol_table.insert(new_var)
|
240
240
|
end
|
@@ -260,7 +260,7 @@ module Loxxy
|
|
260
260
|
unary_operators[:-@] = negate_op
|
261
261
|
|
262
262
|
negation_op = UnaryOperator.new('!', [Datatype::BuiltinDatatype,
|
263
|
-
BackEnd::
|
263
|
+
BackEnd::LoxFunction])
|
264
264
|
unary_operators[:!] = negation_op
|
265
265
|
end
|
266
266
|
|
@@ -7,7 +7,7 @@ module Loxxy
|
|
7
7
|
# rubocop: disable Style/AccessorGrouping
|
8
8
|
# Representation of a Lox function.
|
9
9
|
# It is a named slot that can be associated with a value at the time.
|
10
|
-
class
|
10
|
+
class LoxFunction
|
11
11
|
# @return [String]
|
12
12
|
attr_reader :name
|
13
13
|
|
@@ -26,6 +26,10 @@ module Loxxy
|
|
26
26
|
@stack = aStack
|
27
27
|
end
|
28
28
|
|
29
|
+
def arity
|
30
|
+
parameters ? parameters.size : 0
|
31
|
+
end
|
32
|
+
|
29
33
|
def accept(_visitor)
|
30
34
|
stack.push self
|
31
35
|
end
|
data/lib/loxxy/error.rb
CHANGED
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.06
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rley
|
@@ -113,7 +113,7 @@ files:
|
|
113
113
|
- lib/loxxy/back_end/engine.rb
|
114
114
|
- lib/loxxy/back_end/entry.rb
|
115
115
|
- lib/loxxy/back_end/environment.rb
|
116
|
-
- lib/loxxy/back_end/
|
116
|
+
- lib/loxxy/back_end/lox_function.rb
|
117
117
|
- lib/loxxy/back_end/symbol_table.rb
|
118
118
|
- lib/loxxy/back_end/unary_operator.rb
|
119
119
|
- lib/loxxy/back_end/variable.rb
|