Compare commits

..

No commits in common. "a12e42681a7966741c05ac1de14a5c342ff0c07c" and "8d6f8086f549ab690f9394973a49af902bd28ae4" have entirely different histories.

3 changed files with 0 additions and 188 deletions

60
Cargo.lock generated
View File

@ -698,9 +698,7 @@ dependencies = [
"egui_plot", "egui_plot",
"libloading 0.8.5", "libloading 0.8.5",
"nac3core", "nac3core",
"num-complex",
"parking_lot", "parking_lot",
"rustfft",
"tempfile", "tempfile",
] ]
@ -2215,30 +2213,12 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
[[package]]
name = "num-complex"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "num-conv" name = "num-conv"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.19" version = "0.2.19"
@ -2693,15 +2673,6 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa"
[[package]]
name = "primal-check"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc0d895b311e3af9902528fbb8f928688abbd95872819320517cc24ca6b2bd08"
dependencies = [
"num-integer",
]
[[package]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "1.3.1" version = "1.3.1"
@ -2893,21 +2864,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustfft"
version = "6.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43806561bc506d0c5d160643ad742e3161049ac01027b5e6d7524091fd401d86"
dependencies = [
"num-complex",
"num-integer",
"num-traits",
"primal-check",
"strength_reduce",
"transpose",
"version_check",
]
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.37.27" version = "0.37.27"
@ -3197,12 +3153,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strength_reduce"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82"
[[package]] [[package]]
name = "strict-num" name = "strict-num"
version = "0.1.1" version = "0.1.1"
@ -3478,16 +3428,6 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "transpose"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad61aed86bc3faea4300c7aee358b4c6d0c8d6ccc36524c96e4c92ccf26e77e"
dependencies = [
"num-integer",
"strength_reduce",
]
[[package]] [[package]]
name = "ttf-parser" name = "ttf-parser"
version = "0.24.1" version = "0.24.1"

View File

@ -10,8 +10,6 @@ egui_plot = "0.28"
parking_lot = "0.12" parking_lot = "0.12"
tempfile = "3.12" tempfile = "3.12"
libloading = "0.8" libloading = "0.8"
num-complex = "0.4"
rustfft = "6.2"
[dependencies.nac3core] [dependencies.nac3core]
git = "https://git.m-labs.hk/M-Labs/nac3" git = "https://git.m-labs.hk/M-Labs/nac3"

View File

@ -229,41 +229,6 @@ fn handle_global_var(
} }
} }
fn register_cells_function(
composer: &mut composer::TopLevelComposer,
resolver: Arc<dyn nac3core::symbol_resolver::SymbolResolver + Send + Sync>,
internal_resolver: &ResolverInternal,
name: &str,
signature: typedef::FunSignature,
) {
let ty = composer.unifier.add_ty(typedef::TypeEnum::TFunc(signature));
let name_ref = name.into();
let mut function_def = composer::TopLevelComposer::make_top_level_function_def(
name.to_string(),
name_ref,
ty,
Some(resolver.clone()),
None,
);
if let toplevel::TopLevelDef::Function {
ref mut instance_to_symbol,
..
} = function_def
{
instance_to_symbol.insert("".to_string(), "__nac3_cells_".to_string() + name);
} else {
unreachable!();
};
composer
.definition_ast_list
.push((RwLock::new(function_def).into(), None));
internal_resolver.add_id_def(
name_ref,
toplevel::DefinitionId(composer.definition_ast_list.len() - 1),
);
internal_resolver.add_id_type(name_ref, ty);
}
fn compile(code: &String, run_symbol: &String, output_filename: &Path) -> Result<(), String> { fn compile(code: &String, run_symbol: &String, output_filename: &Path) -> Result<(), String> {
let mut target_machine_options = codegen::CodeGenTargetMachineOptions::from_host(); let mut target_machine_options = codegen::CodeGenTargetMachineOptions::from_host();
target_machine_options.reloc_mode = inkwell::targets::RelocMode::PIC; target_machine_options.reloc_mode = inkwell::targets::RelocMode::PIC;
@ -298,80 +263,6 @@ fn compile(code: &String, run_symbol: &String, output_filename: &Path) -> Result
as Arc<dyn nac3core::symbol_resolver::SymbolResolver + Send + Sync>; as Arc<dyn nac3core::symbol_resolver::SymbolResolver + Send + Sync>;
let irrt = codegen::irrt::load_irrt(&context, resolver.as_ref()); let irrt = codegen::irrt::load_irrt(&context, resolver.as_ref());
let list_tvar = if let typedef::TypeEnum::TObj { params, .. } =
&*composer.unifier.get_ty_immutable(primitive.list)
{
typedef::iter_type_vars(params).nth(0).unwrap()
} else {
unreachable!()
};
let list_float = composer
.unifier
.subst(
primitive.list,
&typedef::into_var_map([typedef::TypeVar {
id: list_tvar.id,
ty: primitive.float,
}]),
)
.unwrap();
register_cells_function(
&mut composer,
resolver.clone(),
internal_resolver.as_ref(),
"slider",
typedef::FunSignature {
args: vec![typedef::FuncArg {
name: "prev".into(),
ty: primitive.float,
default_value: None,
is_vararg: false,
}],
ret: primitive.float,
vars: typedef::VarMap::new(),
},
);
register_cells_function(
&mut composer,
resolver.clone(),
internal_resolver.as_ref(),
"plot",
typedef::FunSignature {
args: vec![typedef::FuncArg {
name: "data".into(),
ty: list_float,
default_value: None,
is_vararg: false,
}],
ret: primitive.none,
vars: typedef::VarMap::new(),
},
);
register_cells_function(
&mut composer,
resolver.clone(),
internal_resolver.as_ref(),
"fft",
typedef::FunSignature {
args: vec![
typedef::FuncArg {
name: "reals".into(),
ty: list_float,
default_value: None,
is_vararg: false,
},
typedef::FuncArg {
name: "imags".into(),
ty: list_float,
default_value: None,
is_vararg: false,
},
],
ret: primitive.none,
vars: typedef::VarMap::new(),
},
);
let parser_result = let parser_result =
match nac3parser::parser::parse_program(code.as_str(), String::from("cell1").into()) { match nac3parser::parser::parse_program(code.as_str(), String::from("cell1").into()) {
Ok(parser_result) => parser_result, Ok(parser_result) => parser_result,
@ -682,23 +573,6 @@ pub extern "C" fn __nac3_cells_plot(data: *const List) {
.show(ui, |plot_ui| plot_ui.line(line)); .show(ui, |plot_ui| plot_ui.line(line));
} }
#[no_mangle]
pub extern "C" fn __nac3_cells_fft(reals: *mut List, imags: *mut List) {
let reals_slice = unsafe { std::slice::from_raw_parts_mut((*reals).data, (*reals).length) };
let imags_slice = unsafe { std::slice::from_raw_parts_mut((*imags).data, (*imags).length) };
let mut planner = rustfft::FftPlanner::<f64>::new();
let fft = planner.plan_fft_forward(reals_slice.len());
let mut buffer = vec![num_complex::Complex { re: 0.0, im: 0.0 }; reals_slice.len()];
for (buf, (re, im)) in buffer.iter_mut().zip(reals_slice.iter().zip(imags_slice.iter())) {
*buf = num_complex::Complex { re: *re, im: *im };
}
fft.process(&mut buffer);
for (buf, (re, im)) in buffer.iter().zip(reals_slice.iter_mut().zip(imags_slice.iter_mut())) {
*re = buf.re;
*im = buf.im;
}
}
impl Cells { impl Cells {
fn new() -> Self { fn new() -> Self {
Self { Self {