Merge pull request #33 from birth-software/mul-div
Implement multiplication and division
This commit is contained in:
		
						commit
						d4307f7de3
					
				@ -3248,6 +3248,12 @@ fn TypeIndex compute_type_integer_binary(Thread* thread, NodeIndex node_index)
 | 
				
			|||||||
            case NODE_INTEGER_SUBSTRACT:
 | 
					            case NODE_INTEGER_SUBSTRACT:
 | 
				
			||||||
                result = left_value - right_value;
 | 
					                result = left_value - right_value;
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					            case NODE_INTEGER_MULTIPLY:
 | 
				
			||||||
 | 
					                result = left_value * right_value;
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case NODE_INTEGER_SIGNED_DIVIDE:
 | 
				
			||||||
 | 
					                result = left_value * right_value;
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
            case NODE_INTEGER_AND:
 | 
					            case NODE_INTEGER_AND:
 | 
				
			||||||
                result = left_value & right_value;
 | 
					                result = left_value & right_value;
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
@ -3321,6 +3327,12 @@ global const NodeVirtualTable node_functions[NODE_COUNT] = {
 | 
				
			|||||||
    [NODE_INTEGER_SUBSTRACT] = {
 | 
					    [NODE_INTEGER_SUBSTRACT] = {
 | 
				
			||||||
        .compute_type = &compute_type_integer_binary,
 | 
					        .compute_type = &compute_type_integer_binary,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    [NODE_INTEGER_SIGNED_DIVIDE] = {
 | 
				
			||||||
 | 
					        .compute_type = &compute_type_integer_binary,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    [NODE_INTEGER_MULTIPLY] = {
 | 
				
			||||||
 | 
					        .compute_type = &compute_type_integer_binary,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    [NODE_INTEGER_AND] = {
 | 
					    [NODE_INTEGER_AND] = {
 | 
				
			||||||
        .compute_type = &compute_type_integer_binary,
 | 
					        .compute_type = &compute_type_integer_binary,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@ -4384,10 +4396,10 @@ fn NodeIndex analyze_multiplication(Thread* thread, Parser* parser, FunctionBuil
 | 
				
			|||||||
        switch (src.pointer[parser->i])
 | 
					        switch (src.pointer[parser->i])
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            case '*':
 | 
					            case '*':
 | 
				
			||||||
                node_id = NODE_INTEGER_ADD;
 | 
					                node_id = NODE_INTEGER_MULTIPLY;
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case '/':
 | 
					            case '/':
 | 
				
			||||||
                node_id = NODE_INTEGER_SUBSTRACT;
 | 
					                node_id = NODE_INTEGER_SIGNED_DIVIDE;
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case '%':
 | 
					            case '%':
 | 
				
			||||||
                todo();
 | 
					                todo();
 | 
				
			||||||
 | 
				
			|||||||
@ -11,6 +11,8 @@ no_optimization_flags=""
 | 
				
			|||||||
test_names=(
 | 
					test_names=(
 | 
				
			||||||
    "first"
 | 
					    "first"
 | 
				
			||||||
    "add_sub"
 | 
					    "add_sub"
 | 
				
			||||||
 | 
					    "mul"
 | 
				
			||||||
 | 
					    "div"
 | 
				
			||||||
    "and"
 | 
					    "and"
 | 
				
			||||||
    "or"
 | 
					    "or"
 | 
				
			||||||
    "xor"
 | 
					    "xor"
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										4
									
								
								tests/div.nat
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								tests/div.nat
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					fn main() s32
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return 0 / 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										4
									
								
								tests/mul.nat
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								tests/mul.nat
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					fn main() s32
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return 1 * 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user