From 053aceec4d7ddc40065bdd95a340b54b841708e3 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sun, 31 Jul 2022 14:14:40 +0200 Subject: [PATCH] extended test case and made notes about multiple outputs --- src/block_compiler.rs | 23 +++++++++++++++++++++++ src/blocklang_def.rs | 12 ++++++++++++ tests/blocklang.rs | 10 +++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/block_compiler.rs b/src/block_compiler.rs index 1317b78..62251fa 100644 --- a/src/block_compiler.rs +++ b/src/block_compiler.rs @@ -123,6 +123,26 @@ impl Block2JITCompiler { } pub fn trans2bjit(&self, node: &ASTNodeRef) -> Result { + // TODO: Deal with multiple outputs. + // If we encounter a node with multiple outputs, assign each output + // to a temporary variable and save that. + // Store the name of the temporary in a id+output mapping. + // => XXX + // That means: If we have a single output, things are easy, just plug them into + // the JIT ast: + // outer(inner()) + // But if we have multiple outputs: + // assign(a = inner()) + // assign(b = %1) + // outer_x(a) + // outer_y(b) + + // TODO: Filter out -> nodes from the AST + // TODO: For ->2 and ->3, save the input in some variable + // and reserve a id+output variable for this. + + // XXX: SSA form of cranelift should take care of the rest! + match &node.0.borrow().typ[..] { "" => { if let Some(first) = node.first_child_ref() { @@ -173,6 +193,9 @@ impl Block2JITCompiler { i += 1; } + // TODO: Reorder the childs/arguments according to the input + // order in the BlockLanguage + Ok(BlkASTNode::new_node( node.0.borrow().id, &node.0.borrow().typ, diff --git a/src/blocklang_def.rs b/src/blocklang_def.rs index 822826a..5cc7762 100644 --- a/src/blocklang_def.rs +++ b/src/blocklang_def.rs @@ -202,6 +202,18 @@ pub fn setup_hxdsp_block_language() -> Rc> { color: 8, }); + lang.define(BlockType { + category: "arithmetics".to_string(), + name: "/%".to_string(), + rows: 2, + inputs: vec![Some("a".to_string()), Some("b".to_string())], + outputs: vec![Some("div".to_string()), Some("rem".to_string())], + area_count: 0, + user_input: BlockUserInput::None, + description: "Computes the integer division and remainder of a / b".to_string(), + color: 8, + }); + for fun_name in &["+", "-", "*", "/"] { lang.define(BlockType { category: "arithmetics".to_string(), diff --git a/tests/blocklang.rs b/tests/blocklang.rs index d111384..f9e2992 100644 --- a/tests/blocklang.rs +++ b/tests/blocklang.rs @@ -32,13 +32,21 @@ fn check_blocklang_1() { block_fun.instanciate_at(0, 2, 0, "set", Some("&sig1".to_string())); block_fun.instanciate_at(0, 3, 0, "get", Some("in1".to_string())); - block_fun.instanciate_at(0, 3, 1, "get", Some("in1".to_string())); + block_fun.instanciate_at(0, 3, 1, "get", Some("in2".to_string())); block_fun.instanciate_at(0, 4, 0, "-", None); block_fun.instanciate_at(0, 5, 0, "->3", None); block_fun.instanciate_at(0, 6, 1, "set", Some("*a".to_string())); block_fun.instanciate_at(0, 6, 2, "set", Some("x".to_string())); block_fun.instanciate_at(0, 6, 0, "->", None); block_fun.instanciate_at(0, 7, 0, "->2", None); + + block_fun.instanciate_at(0, 0, 3, "get", Some("in1".to_string())); + block_fun.instanciate_at(0, 0, 4, "get", Some("in2".to_string())); + block_fun.instanciate_at(0, 1, 3, "/%", None); + block_fun.instanciate_at(0, 2, 3, "->", None); + block_fun.instanciate_at(0, 3, 3, "/%", None); + block_fun.instanciate_at(0, 4, 3, "set", Some("&sig2".to_string())); + block_fun.instanciate_at(0, 4, 4, "set", Some("*ap".to_string())); } matrix.check_block_function(0);