Skip to content

Commit 0d3f60d

Browse files
committed
Update core files containing code in the Truffle module to use frozen String literals.
1 parent 25ecf6d commit 0d3f60d

14 files changed

+78
-50
lines changed

src/main/ruby/core/truffle/boot.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:

src/main/ruby/core/truffle/exception_operations.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:

src/main/ruby/core/truffle/ffi/pointer.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved. This
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
46
#
@@ -93,7 +95,7 @@ def inspect
9395
# Return the address pointed to as an Integer
9496
def address
9597
Truffle.primitive :pointer_address
96-
raise PrimitiveFailure, 'FFI::Pointer#address primitive failed'
98+
raise PrimitiveFailure, +'FFI::Pointer#address primitive failed'
9799
end
98100

99101
alias_method :to_i, :address
@@ -110,7 +112,7 @@ def to_native
110112
# Set the address pointed to from an Integer
111113
def address=(address)
112114
Truffle.primitive :pointer_set_address
113-
raise PrimitiveFailure, 'FFI::Pointer#address= primitive failed'
115+
raise PrimitiveFailure, +'FFI::Pointer#address= primitive failed'
114116
end
115117

116118
def null?
@@ -120,7 +122,7 @@ def null?
120122
# Add +value+ to the address pointed to and return a new Pointer
121123
def +(value)
122124
Truffle.primitive :pointer_add
123-
raise PrimitiveFailure, 'FFI::Pointer#+ primitive failed'
125+
raise PrimitiveFailure, +'FFI::Pointer#+ primitive failed'
124126
end
125127

126128
# Indicates if +self+ and +other+ point to the same address
@@ -131,22 +133,22 @@ def ==(other)
131133

132134
def network_order(start, size)
133135
Truffle.primitive :pointer_network_order
134-
raise PrimitiveFailure, 'FFI::Pointer#network_order primitive failed'
136+
raise PrimitiveFailure, +'FFI::Pointer#network_order primitive failed'
135137
end
136138

137139
# Read +len+ bytes from the memory pointed to and return them as
138140
# a String
139141
def read_string_length(len)
140142
Truffle.primitive :pointer_read_string
141-
raise PrimitiveFailure, 'FFI::Pointer#read_string_length primitive failed'
143+
raise PrimitiveFailure, +'FFI::Pointer#read_string_length primitive failed'
142144
end
143145
alias :read_bytes :read_string_length
144146

145147
# Read bytes from the memory pointed to until a NULL is seen, return
146148
# the bytes as a String
147149
def read_string_to_null
148150
Truffle.primitive :pointer_read_string_to_null
149-
raise PrimitiveFailure, 'FFI::Pointer#read_string_to_null primitive failed'
151+
raise PrimitiveFailure, +'FFI::Pointer#read_string_to_null primitive failed'
150152
end
151153

152154
# Read bytes as a String from the memory pointed to
@@ -167,7 +169,7 @@ def get_bytes(offset, length)
167169
# write up to +len+ bytes.
168170
def write_string_length(str, len)
169171
Truffle.primitive :pointer_write_string
170-
raise PrimitiveFailure, 'FFI::Pointer#write_string_length primitive failed'
172+
raise PrimitiveFailure, +'FFI::Pointer#write_string_length primitive failed'
171173
end
172174

173175
# Write a String +str+ as bytes to the memory pointed to.
@@ -180,13 +182,13 @@ def write_string(str, len=nil)
180182
# Read bytes from +offset+ from the memory pointed to as type +type+
181183
def get_at_offset(offset, type)
182184
Truffle.primitive :pointer_get_at_offset
183-
raise PrimitiveFailure, 'FFI::Pointer#get_at_offset primitive failed'
185+
raise PrimitiveFailure, +'FFI::Pointer#get_at_offset primitive failed'
184186
end
185187

186188
# Write +val+ as type +type+ to bytes from +offset+
187189
def set_at_offset(offset, type, val)
188190
Truffle.primitive :pointer_set_at_offset
189-
raise PrimitiveFailure, 'FFI::Pointer#set_at_offset primitive failed'
191+
raise PrimitiveFailure, +'FFI::Pointer#set_at_offset primitive failed'
190192
end
191193

192194
# Number of bytes taken up by a pointer.
@@ -199,14 +201,14 @@ def self.size
199201
# free() on it's address when it is garbage collected.
200202
def autorelease=(val)
201203
Truffle.primitive :pointer_set_autorelease
202-
raise PrimitiveFailure, 'FFI::Pointer#autorelease= primitive failed'
204+
raise PrimitiveFailure, +'FFI::Pointer#autorelease= primitive failed'
203205
end
204206

205207
##
206208
# Returns true if autorelease is enabled, otherwise false.
207209
def autorelease?
208210
Truffle.primitive :pointer_autorelease_p
209-
raise PrimitiveFailure, 'FFI::Pointer#pointer_autorelease_p primitive failed'
211+
raise PrimitiveFailure, +'FFI::Pointer#pointer_autorelease_p primitive failed'
210212
end
211213

212214
NULL = Pointer.new(0x0)
@@ -270,7 +272,7 @@ def self.new(type, count=nil, clear=true)
270272

271273
def self.malloc(total)
272274
Truffle.primitive :pointer_malloc
273-
raise PrimitiveFailure, 'FFI::MemoryPointer.malloc primitive failed'
275+
raise PrimitiveFailure, +'FFI::MemoryPointer.malloc primitive failed'
274276
end
275277

276278
def self.from_string(str)
@@ -314,14 +316,14 @@ def copy
314316
# new_ptr = &ptr[9];
315317
#
316318
def [](which)
317-
raise ArgumentError, 'unknown type size' unless @type_size
319+
raise ArgumentError, +'unknown type size' unless @type_size
318320
self + (which * @type_size)
319321
end
320322

321323
# Release the memory pointed to back to the OS.
322324
def free
323325
Truffle.primitive :pointer_free
324-
raise PrimitiveFailure, 'FFI::MemoryPointer#free primitive failed'
326+
raise PrimitiveFailure, +'FFI::MemoryPointer#free primitive failed'
325327
end
326328
end
327329
end

src/main/ruby/core/truffle/internal.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved. This
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
46
#
@@ -39,7 +41,7 @@ def self.set_class(obj, cls)
3941
Truffle.primitive :vm_set_class
4042

4143
if obj.kind_of? ImmediateValue
42-
raise TypeError, 'Can not change the class of an immediate'
44+
raise TypeError, +'Can not change the class of an immediate'
4345
end
4446

4547
raise ArgumentError, "Class #{cls} is not compatible with #{obj.inspect}"

src/main/ruby/core/truffle/interop.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved. This
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
46
#
@@ -185,7 +187,7 @@ def self.special_form(receiver, name, *args)
185187
end
186188
when :to_str
187189
receiver = Truffle::Interop.unbox_if_needed(receiver)
188-
raise NameError, 'no method to_str' unless receiver.is_a?(String)
190+
raise NameError, +'no method to_str' unless receiver.is_a?(String)
189191
receiver
190192
when :is_a?, :kind_of?
191193
receiver = Truffle::Interop.unbox_if_needed(receiver)
@@ -196,7 +198,7 @@ def self.special_form(receiver, name, *args)
196198
Truffle::Interop.java_instanceof?(receiver, check_class)
197199
elsif Truffle::Interop.foreign?(check_class)
198200
# Checking a foreign (not Java) object against a foreign (not Java) class
199-
raise TypeError, 'cannot check if a foreign object is an instance of a foreign class'
201+
raise TypeError, +'cannot check if a foreign object is an instance of a foreign class'
200202
else
201203
# Checking a foreign or Java object against a Ruby class
202204
false
@@ -216,7 +218,7 @@ def self.inspect_foreign(object)
216218
if object.is_a?(String)
217219
object.inspect
218220
elsif Truffle::Interop.java?(object) && object.nil?
219-
'#<Java null>'
221+
+'#<Java null>'
220222
elsif Truffle::Interop.java?(object) && object.respond_to?(:size)
221223
"#<Java:#{hash_code} #{to_array(object).inspect}>"
222224
elsif Truffle::Interop.java?(object) && object.is_a?(::Java.type('java.util.Map'))
@@ -226,7 +228,7 @@ def self.inspect_foreign(object)
226228
elsif Truffle::Interop.java?(object)
227229
"#<Java:#{hash_code} object #{object.getClass.getName}>"
228230
elsif Truffle::Interop.null?(object)
229-
'#<Foreign null>'
231+
+'#<Foreign null>'
230232
elsif Truffle::Interop.pointer?(object)
231233
"#<Foreign pointer 0x#{Truffle::Interop.as_pointer(object).to_s(16)}>"
232234
elsif Truffle::Interop.size?(object)
@@ -266,7 +268,7 @@ def self.respond_to?(object, name)
266268

267269
def self.to_array(object)
268270
unless Truffle::Interop.size?(object)
269-
raise 'foreign object does not have a size to turn it into an array'
271+
raise(+'foreign object does not have a size to turn it into an array')
270272
end
271273

272274
Array.new(Truffle::Interop.size(object)) do |n|

src/main/ruby/core/truffle/io_operations.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
@@ -18,7 +20,7 @@ def self.set_last_line(value, a_binding)
1820

1921
def self.print(io, args, last_line_binding)
2022
if args.empty?
21-
raise 'last_line_binding is required' if last_line_binding.nil?
23+
raise(+'last_line_binding is required') if last_line_binding.nil?
2224
io.write Truffle::IOOperations.last_line(last_line_binding).to_s
2325
else
2426
args.each { |o| io.write o.to_s }

src/main/ruby/core/truffle/kernel_operations.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
@@ -48,7 +50,7 @@ def self.define_read_only_global(name, getter)
4850
:$/,
4951
-> { global_variable_get(:$/) },
5052
-> v { if v && !Truffle::Type.object_kind_of?(v, String)
51-
raise TypeError, '$/ must be a String'
53+
raise TypeError, +'$/ must be a String'
5254
end
5355
global_variable_set(:$/, v) })
5456

@@ -60,7 +62,7 @@ def self.define_read_only_global(name, getter)
6062
:'$,',
6163
-> { global_variable_get(:$,) },
6264
-> v { if v && !Truffle::Type.object_kind_of?(v, String)
63-
raise TypeError, '$, must be a String'
65+
raise TypeError, +'$, must be a String'
6466
end
6567
global_variable_set(:$,, v) })
6668

@@ -115,19 +117,19 @@ def self.internal_raise(exc, msg, ctx, internal)
115117
if exc
116118
skip = true
117119
else
118-
exc = RuntimeError.new('No current exception')
120+
exc = RuntimeError.new(+'No current exception')
119121
end
120122
elsif exc.respond_to? :exception
121123
if undefined.equal? msg
122124
exc = exc.exception
123125
else
124126
exc = exc.exception msg
125127
end
126-
raise TypeError, 'exception class/object expected' unless exc.kind_of?(Exception)
128+
raise TypeError, +'exception class/object expected' unless exc.kind_of?(Exception)
127129
elsif exc.kind_of? String
128130
exc = RuntimeError.exception exc
129131
else
130-
raise TypeError, 'exception class/object expected'
132+
raise TypeError, +'exception class/object expected'
131133
end
132134

133135
unless skip

src/main/ruby/core/truffle/numeric_operations.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:
@@ -85,7 +87,7 @@ def self.stepping_forever?(limit, step, asc)
8587
end
8688

8789
def self.step_fetch_args(value, limit, step, by)
88-
raise ArgumentError, 'step cannot be 0' if undefined.equal?(by) && step == 0
90+
raise ArgumentError, +'step cannot be 0' if undefined.equal?(by) && step == 0
8991

9092
asc = step > 0
9193
if value.kind_of? Float or limit.kind_of? Float or step.kind_of? Float

src/main/ruby/core/truffle/platform.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:

src/main/ruby/core/truffle/polyglot.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. This
24
# code is released under a tri EPL/GPL/LGPL license. You can use it,
35
# redistribute it and/or modify it under the terms of the:

0 commit comments

Comments
 (0)