Class: Dhallish::Ast::FunctionDefinitionNode

Inherits:
Object
  • Object
show all
Defined in:
lib/ast.rb

Overview

argname should be the name of the argument. argtype should be an Ast-Node, as does body.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argname, argtype, body) ⇒ FunctionDefinitionNode

Returns a new instance of FunctionDefinitionNode.



198
199
200
201
202
# File 'lib/ast.rb', line 198

def initialize(argname, argtype, body)
	@argname = argname
	@argtype = argtype
	@body = body
end

Instance Attribute Details

#argnameObject

Returns the value of attribute argname.



196
197
198
# File 'lib/ast.rb', line 196

def argname
  @argname
end

#bodyObject

Returns the value of attribute body.



197
198
199
# File 'lib/ast.rb', line 197

def body
  @body
end

Instance Method Details

#compute_type(ctx) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/ast.rb', line 204

def compute_type(ctx)
	argtype = @argtype.compute_type ctx
	assert("expected type as argument annotation: #{argtype}") { argtype.is_a? Types::Type }
	argtype = argtype.

	unres = nil
	if argtype.is_a? Types::Type
		assert("DEBUG: wann passiert sowas? #{argtype.inspect}") { argtype..nil? }
		argtype = Types::Type.new(Types::Unresolved.new(@argname))
		unres = @argname
	end

	newctx = Context.new ctx
	newctx[@argname] = argtype

	Types::Function.new(argtype, @body.compute_type(newctx), unres)
end

#evaluate(ctx) ⇒ Object



222
223
224
# File 'lib/ast.rb', line 222

def evaluate(ctx)
	Function.new(@argname, @body, ctx)
end