Super hacky way to resolve type of given variables

This commit is contained in:
Michael Miller 2018-09-06 22:08:32 -06:00
parent 7c8be54e5c
commit 45261c419f
1 changed files with 21 additions and 6 deletions

View File

@ -42,7 +42,10 @@ module Spectator
include Locals
{% unless given_vars.empty? %}
def initialize({{ var_names.map { |v| "@#{v}" }.join(", ").id }})
def initialize({{ var_names.join(", ").id }})
{% for var_name in var_names %}
self.{{var_name}} = {{var_name}}
{% end %}
end
{% end %}
@ -50,10 +53,6 @@ module Spectator
Source.new({{source_file}}, {{source_line}})
end
def num
0
end
def run
{{block.body}}
end
@ -113,7 +112,23 @@ module Spectator
{% var_name = block.args.empty? ? "value" : block.args.first %}
module Locals
getter {{var_name.id}}
@%wrapper : ValueWrapper?
private def %collection
{{collection}}
end
private def %collection_first
%collection.first
end
def {{var_name.id}}
@%wrapper.as(TypedValueWrapper(typeof(%collection_first))).value
end
private def {{var_name.id}}=(value)
@%wrapper = TypedValueWrapper(typeof(%collection_first)).new(value)
end
end
{% GIVEN_VARIABLES << {var_name, collection} %}