Commit 0b516646 authored by Tom Niget's avatar Tom Niget

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

parent a98a3941
...@@ -61,14 +61,18 @@ class BlockVisitor(NodeVisitor): ...@@ -61,14 +61,18 @@ class BlockVisitor(NodeVisitor):
yield f"{node.name}_inner::" yield f"{node.name}_inner::"
yield "operator()" yield "operator()"
yield "(" 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: if skip_first_arg:
next(args_iter) next(args_iter)
for i, (arg, argty) in enumerate(args_iter): for i, (arg, argty, default) in enumerate(args_iter):
if i != 0: if i != 0:
yield ", " yield ", "
yield from self.visit(argty) yield from self.visit(argty)
yield arg.arg yield arg.arg
if emission == FunctionEmissionKind.DECLARATION and default:
yield " = "
yield from self.expr().visit(default)
yield ")" yield ")"
inner_scope = node.inner_scope inner_scope = node.inner_scope
......
...@@ -156,7 +156,9 @@ class ScoperBlockVisitor(ScoperVisitor): ...@@ -156,7 +156,9 @@ class ScoperBlockVisitor(ScoperVisitor):
scope.function = scope scope.function = scope
node.inner_scope = scope node.inner_scope = scope
node.type = ftype 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): for arg, ty in zip(node.args.args, argtypes):
scope.vars[arg.arg] = VarDecl(VarKind.LOCAL, ty) scope.vars[arg.arg] = VarDecl(VarKind.LOCAL, ty)
self.fdecls.append((node, rtype.return_type)) 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