Skip to content

Commit

Permalink
[cpp] now that string literals are a thing, added set_output_name i…
Browse files Browse the repository at this point in the history
…n buildmeta
  • Loading branch information
harrand committed May 23, 2024
1 parent c4d2d97 commit 3ede2f8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cpp/src/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ void set_build_type(std::int64_t build_type_value)
cur_build_info->config = static_cast<build::config_type>(build_type_value);
}

void set_output_name(const char* name)
{
cur_build_info->link_name = name;
}

void install_functions(llvm::ExecutionEngine& exe)
{
exe.addGlobalMapping("set_linkage_type", reinterpret_cast<std::uintptr_t>(&set_linkage_type));
exe.addGlobalMapping("set_build_type", reinterpret_cast<std::uintptr_t>(&set_build_type));
exe.addGlobalMapping("set_output_name", reinterpret_cast<std::uintptr_t>(&set_output_name));
}


Expand Down Expand Up @@ -205,6 +211,24 @@ namespace build
.is_extern = true
}
});
ret.root.children.push_back(ast::node
{
.payload = ast::function_definition
{
.func_name = "set_output_name",
.params =
{
ast::variable_declaration
{
.var_name = "outname",
.type_name = "i8&",
.initialiser = ast::expression{.expr = ast::null_literal{}}
},
},
.ret_type = "u0",
.is_extern = true
}
});

// same with some globals.
for(int i = 0; i < (int)build::linkage_type::_count; i++)
Expand Down
16 changes: 16 additions & 0 deletions cpp/src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,22 @@ namespace parse
maybe_expr = ast::expression{.expr = maybe_decimal_literal.value()};
return maybe_expr;
}
this->undo();
// char literal
auto maybe_char_literal = this->retrieve<ast::char_literal>();
if(maybe_char_literal.has_value())
{
maybe_expr = ast::expression{.expr = maybe_char_literal.value()};
return maybe_expr;
}
this->undo();
// string literal
auto maybe_string_literal = this->retrieve<ast::string_literal>();
if(maybe_string_literal.has_value())
{
maybe_expr = ast::expression{.expr = maybe_string_literal.value()};
return maybe_expr;
}
}
return maybe_expr;
}
Expand Down
1 change: 1 addition & 0 deletions samples/scratchpad.psy
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ main :: () -> i64
{
set_build_type(debug);
set_linkage_type(executable);
set_output_name("scratchpad.exe");
}

0 comments on commit 3ede2f8

Please sign in to comment.