move Parser.mkFnDecl => ast.Node.mkFnDecl
This commit is contained in:
parent
d69365ba92
commit
250631ff41
3 changed files with 31 additions and 23 deletions
|
@ -7,5 +7,5 @@ fn add(a: i32, b: i32) i32 {
|
|||
// type is void by default
|
||||
fn main() {
|
||||
std.fmt.print("piss\n");
|
||||
// std.fmt.print("2 + 2 = %d\n", add(1, 2));
|
||||
std.fmt.print("2 + 2 = %d\n", add(1, 2));
|
||||
}
|
||||
|
|
22
src/ast.zig
22
src/ast.zig
|
@ -284,6 +284,28 @@ pub const Node = union(NodeType) {
|
|||
return node;
|
||||
}
|
||||
|
||||
pub fn mkFnDecl(
|
||||
allocator: *std.mem.Allocator,
|
||||
name: Token,
|
||||
params: ParamList,
|
||||
return_type: Token,
|
||||
block: StmtList,
|
||||
method: ?*MethodData,
|
||||
) !*Node {
|
||||
var node = try allocator.create(Node);
|
||||
|
||||
node.* = Node{
|
||||
.FnDecl = FnDecl{
|
||||
.func_name = name,
|
||||
.params = params,
|
||||
.return_type = return_type,
|
||||
.body = block,
|
||||
.method = method,
|
||||
},
|
||||
};
|
||||
return node;
|
||||
}
|
||||
|
||||
pub fn mkStructDecl(allocator: *std.mem.Allocator, name: Token, fields: FieldList) !*Node {
|
||||
var node = try allocator.create(Node);
|
||||
node.* = Node{
|
||||
|
|
|
@ -175,27 +175,6 @@ pub const Parser = struct {
|
|||
|
||||
// TODO maybe move helper functions to ast_helper.zig?
|
||||
|
||||
fn mkFnDecl(
|
||||
self: *Parser,
|
||||
name: Token,
|
||||
params: ast.ParamList,
|
||||
return_type: Token,
|
||||
block: ast.StmtList,
|
||||
method: ?*ast.MethodData,
|
||||
) !*ast.Node {
|
||||
var node = try self.allocator.create(Node);
|
||||
node.* = Node{
|
||||
.FnDecl = ast.FnDecl{
|
||||
.func_name = name,
|
||||
.params = params,
|
||||
.return_type = return_type,
|
||||
.body = block,
|
||||
.method = method,
|
||||
},
|
||||
};
|
||||
return node;
|
||||
}
|
||||
|
||||
fn mkConstDecl(self: *Parser, consts: ast.ConstList) !*ast.Node {
|
||||
var node = try self.allocator.create(Node);
|
||||
node.* = Node{ .ConstDecl = consts };
|
||||
|
@ -486,7 +465,14 @@ pub const Parser = struct {
|
|||
}
|
||||
|
||||
var block_node = try self.parseBlock();
|
||||
return try self.mkFnDecl(name, param_list, return_type, block_node.Block, method);
|
||||
return try Node.mkFnDecl(
|
||||
self.allocator,
|
||||
name,
|
||||
param_list,
|
||||
return_type,
|
||||
block_node.Block,
|
||||
method,
|
||||
);
|
||||
}
|
||||
|
||||
/// parse the (v [mut] T) part of the method (defined here
|
||||
|
|
Loading…
Reference in a new issue