Add build for platform function.
This commit is contained in:
parent
938391ae09
commit
c54e005b62
5
sketching/may_2025/print.dm
Normal file
5
sketching/may_2025/print.dm
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
ns std::core;
|
||||||
|
|
||||||
|
platform fn print(msg: Any) -> Void;
|
||||||
|
|
||||||
|
platform fn println(msg: Any) -> Void;
|
@ -594,7 +594,46 @@ fn build_platform_function_declaration(
|
|||||||
file_id: usize,
|
file_id: usize,
|
||||||
platform_function_pair: Pair<Rule>,
|
platform_function_pair: Pair<Rule>,
|
||||||
) -> PlatformFunctionDeclaration {
|
) -> PlatformFunctionDeclaration {
|
||||||
todo!()
|
let mut is_public = false;
|
||||||
|
let mut modifier = None;
|
||||||
|
let mut generics = GenericParameters::default();
|
||||||
|
let mut identifier = None;
|
||||||
|
let mut parameters = Parameters::default();
|
||||||
|
let mut return_type = None;
|
||||||
|
|
||||||
|
for inner_pair in platform_function_pair.into_inner() {
|
||||||
|
match inner_pair.as_rule() {
|
||||||
|
Rule::Pub => {
|
||||||
|
is_public = true;
|
||||||
|
}
|
||||||
|
Rule::FunctionModifier => {
|
||||||
|
modifier = Some(build_function_modifier(file_id, inner_pair));
|
||||||
|
}
|
||||||
|
Rule::Platform | Rule::Fn => {},
|
||||||
|
Rule::GenericParameters => {
|
||||||
|
generics = build_generic_parameters(file_id, inner_pair);
|
||||||
|
}
|
||||||
|
Rule::Identifier => {
|
||||||
|
identifier = Some(build_identifier(file_id, inner_pair));
|
||||||
|
}
|
||||||
|
Rule::Parameters => {
|
||||||
|
parameters = build_parameters(file_id, inner_pair);
|
||||||
|
}
|
||||||
|
Rule::ReturnType => {
|
||||||
|
return_type = Some(build_return_type(file_id, inner_pair));
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PlatformFunctionDeclaration {
|
||||||
|
is_public,
|
||||||
|
modifier,
|
||||||
|
generics,
|
||||||
|
identifier: identifier.unwrap(),
|
||||||
|
parameters,
|
||||||
|
return_type: return_type.unwrap(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_interface_function_declaration(
|
fn build_interface_function_declaration(
|
||||||
@ -1798,4 +1837,9 @@ mod tests {
|
|||||||
fn use_list() {
|
fn use_list() {
|
||||||
assert_builds("use std::core::{print, println};");
|
assert_builds("use std::core::{print, println};");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn platform_function() {
|
||||||
|
assert_builds("platform fn println(msg: Any) -> Void;");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -574,6 +574,7 @@ impl Unparse for PlatformFunctionDeclaration {
|
|||||||
self.parameters.unparse(writer)?;
|
self.parameters.unparse(writer)?;
|
||||||
writer.write(" ")?;
|
writer.write(" ")?;
|
||||||
self.return_type.unparse(writer)?;
|
self.return_type.unparse(writer)?;
|
||||||
|
writer.write(";")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ mod tests {
|
|||||||
let file_id = files.add(file_name, source);
|
let file_id = files.add(file_name, source);
|
||||||
let parse_result = DeimosParser::parse(Rule::CompilationUnit, source);
|
let parse_result = DeimosParser::parse(Rule::CompilationUnit, source);
|
||||||
if let Err(err) = &parse_result {
|
if let Err(err) = &parse_result {
|
||||||
panic!("{:?}", err);
|
panic!("{}", err);
|
||||||
}
|
}
|
||||||
let mut pairs = parse_result.unwrap();
|
let mut pairs = parse_result.unwrap();
|
||||||
if pairs.as_str().trim() != source.trim() {
|
if pairs.as_str().trim() != source.trim() {
|
||||||
@ -148,7 +148,7 @@ mod tests {
|
|||||||
indoc! {"
|
indoc! {"
|
||||||
ns std::core;
|
ns std::core;
|
||||||
|
|
||||||
declare platform fn println(msg: String) -> Void
|
platform fn println(msg: String) -> Void;
|
||||||
"},
|
"},
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
@ -385,6 +385,7 @@ PlatformFunction = {
|
|||||||
~ Identifier
|
~ Identifier
|
||||||
~ Parameters
|
~ Parameters
|
||||||
~ ReturnType
|
~ ReturnType
|
||||||
|
~ ";"
|
||||||
}
|
}
|
||||||
|
|
||||||
InterfaceFunction = {
|
InterfaceFunction = {
|
||||||
|
Loading…
Reference in New Issue
Block a user