extended test case and made notes about multiple outputs

This commit is contained in:
Weird Constructor 2022-07-31 14:14:40 +02:00
parent f5f8ed545c
commit 053aceec4d
3 changed files with 44 additions and 1 deletions

View file

@ -123,6 +123,26 @@ impl Block2JITCompiler {
}
pub fn trans2bjit(&self, node: &ASTNodeRef) -> Result<BlkASTRef, BlkJITCompileError> {
// 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[..] {
"<r>" => {
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,

View file

@ -202,6 +202,18 @@ pub fn setup_hxdsp_block_language() -> Rc<RefCell<BlockLanguage>> {
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(),

View file

@ -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);