-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2339 from natalie-lang/fix-arg-default-eval
- Loading branch information
Showing
10 changed files
with
106 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
lib/natalie/compiler/instructions/array_is_empty_instruction.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require_relative './base_instruction' | ||
|
||
module Natalie | ||
class Compiler | ||
class ArrayIsEmptyInstruction < BaseInstruction | ||
def to_s | ||
'array_is_empty' | ||
end | ||
|
||
def generate(transform) | ||
ary = transform.peek | ||
transform.exec_and_push(:is_empty, "bool_object(#{ary}->as_array()->is_empty())") | ||
end | ||
|
||
def execute(vm) | ||
ary = vm.peek | ||
vm.push(ary.empty?) | ||
end | ||
|
||
def serialize(_) | ||
[instruction_number].pack('C') | ||
end | ||
|
||
def self.deserialize(_, _) | ||
new | ||
end | ||
end | ||
end | ||
end |
24 changes: 0 additions & 24 deletions
24
lib/natalie/compiler/instructions/array_pop_with_default_instruction.rb
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
lib/natalie/compiler/instructions/array_shift_with_default_instruction.rb
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
lib/natalie/compiler/instructions/hash_delete_with_default_instruction.rb
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
lib/natalie/compiler/instructions/hash_has_key_instruction.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require_relative './base_instruction' | ||
|
||
module Natalie | ||
class Compiler | ||
class HashHasKeyInstruction < BaseInstruction | ||
def initialize(key) | ||
raise "expected symbol but got: #{key.inspect}" unless key.is_a?(Symbol) | ||
|
||
@key = key | ||
end | ||
|
||
def to_s | ||
"hash_has_key #{@key.inspect}" | ||
end | ||
|
||
def generate(transform) | ||
hash = transform.peek | ||
transform.exec_and_push( | ||
:has_key, | ||
"bool_object(#{hash}->as_hash()->has_key(env, #{@key.to_s.inspect}_s))" | ||
) | ||
end | ||
|
||
def execute(vm) | ||
hash = vm.peek | ||
vm.push(hash.key?(@key)) | ||
end | ||
|
||
def serialize(rodata) | ||
position = rodata.add(@key.to_s) | ||
[ | ||
instruction_number, | ||
position, | ||
].pack('Cw') | ||
end | ||
|
||
def self.deserialize(io, rodata) | ||
position = io.read_ber_integer | ||
key = rodata.get(position, convert: :to_sym) | ||
new(key) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters