about summary refs log tree commit diff
path: root/src/bootstrap/codegen.pry
diff options
context:
space:
mode:
authorBaitinq <[email protected]>2025-07-13 10:21:12 +0200
committerBaitinq <[email protected]>2025-07-13 10:21:33 +0200
commit45dae6d0e3482e5ffa01ffa3ea260b75c0078429 (patch)
treeedaaff959b0f160cd32e6b50485e7ccb4bd2bf7a /src/bootstrap/codegen.pry
parentBoostrap: Fuction recursive functions (diff)
downloadpry-lang-45dae6d0e3482e5ffa01ffa3ea260b75c0078429.tar.gz
pry-lang-45dae6d0e3482e5ffa01ffa3ea260b75c0078429.tar.bz2
pry-lang-45dae6d0e3482e5ffa01ffa3ea260b75c0078429.zip
Boostrap: Support funtion args
Diffstat (limited to 'src/bootstrap/codegen.pry')
-rw-r--r--src/bootstrap/codegen.pry35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/bootstrap/codegen.pry b/src/bootstrap/codegen.pry
index 4a3786a..207c611 100644
--- a/src/bootstrap/codegen.pry
+++ b/src/bootstrap/codegen.pry
@@ -338,18 +338,33 @@ let codegen_generate_expression_value = (c: *codegen, expression: *Node, name: *
 	if ((*expression).type == NODE_PRIMARY_EXPRESSION_IDENTIFIER) {
 		let identifier = *cast(*NODE_PRIMARY_EXPRESSION_IDENTIFIER_DATA, (*expression).data);
 		let variable = environment_get_variable((*c).environment, identifier.name);
-		if variable == cast(*Variable, null) {
-			return cast(*Variable, null);
-		};
+		assert(variable != cast(*Variable, null));
+		let param_value = (*variable).value;
 		let v_type = (*variable).node_type;
-		/* TODO */
-		assert((*v_type).type != NODE_TYPE_FUNCTION_TYPE);
-		let param_type = codegen_get_llvm_type(c, v_type);
-		assert(param_type != cast(*LLVMTypeRef, null));
-		if (*v_type).type == NODE_TYPE_FUNCTION_TYPE {
-			(*param_type) = LLVMPointerType(*param_type, 0);
+
+		let done = false;
+		if (*v_type).type != NODE_TYPE_FUNCTION_TYPE {
+			let param_type = codegen_get_llvm_type(c, v_type);
+			assert(param_type != cast(*LLVMTypeRef, null));
+			if (*v_type).type == NODE_TYPE_FUNCTION_TYPE {
+				(*param_type) = LLVMPointerType(*param_type, 0);
+			};
+			param_value = LLVMBuildLoad2((*c).builder, *param_type, (*variable).value, "");
+			done = true;
+		};
+
+		if !done {
+			if (*(*variable).stack_level) != 0 {
+				let param_type = codegen_get_llvm_type(c, v_type);
+				assert(param_type != cast(*LLVMTypeRef, null));
+				if (*v_type).type == NODE_TYPE_FUNCTION_TYPE {
+					(*param_type) = LLVMPointerType(*param_type, 0);
+				};
+				param_value = LLVMBuildLoad2((*c).builder, *param_type, (*variable).value, "");
+				done = true;
+			};
+
 		};
-		let param_value = LLVMBuildLoad2((*c).builder, *param_type, (*variable).value, "");
 
 		return codegen_generate_literal(c, param_value, name, expression, (*variable).node_type);
 	};