Commit 00e40e91 authored by Tom Niget's avatar Tom Niget

Add type checking for default values and emit them in C++

parent 7c2abca0
......@@ -61,14 +61,18 @@ class BlockVisitor(NodeVisitor):
yield f"{node.name}_inner::"
yield "operator()"
yield "("
args_iter = zip(node.args.args, node.type.parameters)
padded_defaults = [None] * node.type.optional_at + node.args.defaults
args_iter = zip(node.args.args, node.type.parameters, padded_defaults)
if skip_first_arg:
next(args_iter)
for i, (arg, argty) in enumerate(args_iter):
for i, (arg, argty, default) in enumerate(args_iter):
if i != 0:
yield ", "
yield from self.visit(argty)
yield arg.arg
if emission == FunctionEmissionKind.DECLARATION and default:
yield " = "
yield from self.expr().visit(default)
yield ")"
inner_scope = node.inner_scope
......
......@@ -156,7 +156,9 @@ class ScoperBlockVisitor(ScoperVisitor):
scope.function = scope
node.inner_scope = scope
node.type = ftype
ftype.optional_at = 1 + len(node.args.args) - len(node.args.defaults)
ftype.optional_at = len(node.args.args) - len(node.args.defaults)
for ty, default in zip(argtypes[ftype.optional_at:], node.args.defaults):
self.expr().visit(default).unify(ty)
for arg, ty in zip(node.args.args, argtypes):
scope.vars[arg.arg] = VarDecl(VarKind.LOCAL, ty)
self.fdecls.append((node, rtype.return_type))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment