in generation of main function, fix case that input/output buffer is a nullterm string

This commit is contained in:
Michael Sippel 2025-05-10 15:16:51 +02:00
parent 1116457bcc
commit a58ac1a69c
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 20 additions and 12 deletions

View file

@ -21,18 +21,23 @@ pub fn generate_lib(
uint8_t bufIn[4096];
uint8_t bufOut[4096];"#));
let (src_top, src_floor) = inst.ty.src_type.get_floor_type();
if src_floor == dict.parse_desugared("<Seq~<ValueTerminated 0> native.UInt8>").expect("").sugar(dict) {
if let Ok(_) = laddertypes::subtype_unify(
&inst.ty.src_type,
&dict.parse("<Seq~<ValueTerminated 0> Char~Ascii~native.UInt8>").expect("")
) {
c_source.push_str("scanf(\"%s\", bufIn);");
} else {
c_source.push_str("read(0, bufIn, sizeof(bufIn));");
}
c_source.push_str(&format!(r#"FUSE( {}, (void const*)bufIn, (void*)bufOut );"#, inst.instantiated_symbol_name(dict, &HashMap::new())));
c_source.push_str(
&format!(r#"FUSE( {}, (void const*)bufIn, (void*)bufOut );"#,
inst.instantiated_symbol_name(dict, &HashMap::new()))
);
if let Ok(ψ) = laddertypes::constraint_system::subtype_unify(
&inst.ty.src_type,
&dict.parse_desugared("<Seq~<ValueTerminated 0> native.UInt8>").expect("").sugar(dict)
if let Ok(ψ) = laddertypes::subtype_unify(
&inst.ty.dst_type,
&dict.parse("<Seq~<ValueTerminated 0> native.UInt8>").expect("")
) {
c_source.push_str("printf(\"%s\\n\", bufOut);");
} else {

View file

@ -9,12 +9,15 @@ use {
crate::{
morphism::LdmcPrimMorph,
parser::morphism_base_parser,
}, ariadne::{Color, Label, Report, ReportKind, Source}, chumsky::prelude::*, clap::{Parser, Subcommand}, laddertypes::{
morphism::MorphismType,
parser::ParseLadderType, BimapTypeDict
}, parser::morphism_type_parser, std::{path::PathBuf,
sync::{Arc, RwLock}}, tiny_ansi::TinyAnsi,
walkdir::WalkDir
},
laddertypes::{
morphism::MorphismType, BimapTypeDict
}, parser::morphism_type_parser,
ariadne::{Color, Label, Report, ReportKind, Source},
clap::Parser,
walkdir::WalkDir,
tiny_ansi::TinyAnsi,
std::{path::PathBuf, sync::{Arc, RwLock}},
};
#[derive(Parser, Debug)]