-
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 #2275 from natalie-lang/rb/argument-forwarding
Implement anonymous splat and keyword splat forwarding
- Loading branch information
Showing
9 changed files
with
180 additions
and
8 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
31 changes: 31 additions & 0 deletions
31
lib/natalie/compiler/instructions/anonymous_keyword_splat_get_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,31 @@ | ||
require_relative './base_instruction' | ||
|
||
module Natalie | ||
class Compiler | ||
class AnonymousKeywordSplatGetInstruction < BaseInstruction | ||
def to_s | ||
'anonymous_keyword_splat_get' | ||
end | ||
|
||
def generate(transform) | ||
transform.push('anon_keyword_splat') | ||
end | ||
|
||
def execute(vm) | ||
if (var = vm.find_var(:anon_keyword_splat)) | ||
vm.push(var.fetch(:value)) | ||
else | ||
raise "anonymous keyword splat was not defined #{@name}" | ||
end | ||
end | ||
|
||
def serialize(_) | ||
[instruction_number].pack('C') | ||
end | ||
|
||
def self.deserialize(_, _) | ||
new | ||
end | ||
end | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
lib/natalie/compiler/instructions/anonymous_keyword_splat_set_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,28 @@ | ||
require_relative './base_instruction' | ||
|
||
module Natalie | ||
class Compiler | ||
class AnonymousKeywordSplatSetInstruction < BaseInstruction | ||
def to_s | ||
'anonymous_keyword_splat_set' | ||
end | ||
|
||
def generate(transform) | ||
value = transform.pop | ||
transform.exec("Value anon_keyword_splat = #{value}") | ||
end | ||
|
||
def execute(vm) | ||
vm.scope[:vars][:anon_keyword_splat] = { value: vm.pop } | ||
end | ||
|
||
def serialize(_) | ||
[instruction_number].pack('C') | ||
end | ||
|
||
def self.deserialize(_, _) | ||
new | ||
end | ||
end | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
lib/natalie/compiler/instructions/anonymous_splat_get_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,31 @@ | ||
require_relative './base_instruction' | ||
|
||
module Natalie | ||
class Compiler | ||
class AnonymousSplatGetInstruction < BaseInstruction | ||
def to_s | ||
'anonymous_splat_get' | ||
end | ||
|
||
def generate(transform) | ||
transform.push('anon_splat') | ||
end | ||
|
||
def execute(vm) | ||
if (var = vm.find_var(:anon_splat)) | ||
vm.push(var.fetch(:value)) | ||
else | ||
raise "anonymous splat was not defined #{@name}" | ||
end | ||
end | ||
|
||
def serialize(_) | ||
[instruction_number].pack('C') | ||
end | ||
|
||
def self.deserialize(_, _) | ||
new | ||
end | ||
end | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
lib/natalie/compiler/instructions/anonymous_splat_set_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,28 @@ | ||
require_relative './base_instruction' | ||
|
||
module Natalie | ||
class Compiler | ||
class AnonymousSplatSetInstruction < BaseInstruction | ||
def to_s | ||
'anonymous_splat_set' | ||
end | ||
|
||
def generate(transform) | ||
value = transform.pop | ||
transform.exec("Value anon_splat = #{value}") | ||
end | ||
|
||
def execute(vm) | ||
vm.scope[:vars][:anon_splat] = { value: vm.pop } | ||
end | ||
|
||
def serialize(_) | ||
[instruction_number].pack('C') | ||
end | ||
|
||
def self.deserialize(_, _) | ||
new | ||
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