-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "builtin.hpp" | ||
#include <array> | ||
|
||
std::array<const char*, (int)builtin::_count> builtin_names | ||
{ | ||
"malloc", | ||
"free" | ||
}; | ||
|
||
std::array<semal::function_t, (int)builtin::_count> builtin_functions | ||
{ | ||
semal::function_t | ||
{ | ||
.return_ty = type::from_primitive(primitive_type::i8).pointer_to(), | ||
.name = "malloc", | ||
.params = | ||
{ | ||
semal::local_variable_t | ||
{ | ||
.ty = type::from_primitive(primitive_type::u64), | ||
.name = "size_bytes", | ||
.ctx = {}, | ||
} | ||
}, | ||
.ctx = {}, | ||
.is_method = false | ||
}, | ||
semal::function_t | ||
{ | ||
.return_ty = type::from_primitive(primitive_type::u0), | ||
.name = "free", | ||
.params = | ||
{ | ||
semal::local_variable_t | ||
{ | ||
.ty = type::from_primitive(primitive_type::i8).pointer_to(), | ||
.name = "ptr", | ||
.ctx = {}, | ||
} | ||
}, | ||
.ctx = {}, | ||
.is_method = false | ||
}, | ||
}; | ||
|
||
builtin try_find_builtin(std::string_view funcname) | ||
{ | ||
for(int i = 0; i < (int)builtin::_count; i++) | ||
{ | ||
if(std::format("__builtin_{}", builtin_names[i]) == funcname) | ||
{ | ||
return (builtin)i; | ||
} | ||
} | ||
return builtin::_undefined; | ||
} | ||
|
||
semal::function_t& get_builtin_function(builtin b) | ||
{ | ||
return builtin_functions[(int)b]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef PSYC_BUILTIN_HPP | ||
#define PSYC_BUILTIN_HPP | ||
#include "ast.hpp" | ||
#include "semal.hpp" | ||
|
||
enum class builtin | ||
{ | ||
malloc, | ||
free, | ||
_count, | ||
_undefined, | ||
}; | ||
|
||
// return builtin::_undefined if funcname doesnt correspond to a builtin. | ||
builtin try_find_builtin(std::string_view funcname); | ||
semal::function_t& get_builtin_function(builtin b); | ||
#endif // PSYC_BUILTIN_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters