diff --git a/reid-llvm-lib/src/compile.rs b/reid-llvm-lib/src/compile.rs index 680d71a..7bfdbe8 100644 --- a/reid-llvm-lib/src/compile.rs +++ b/reid-llvm-lib/src/compile.rs @@ -1075,7 +1075,7 @@ impl ConstValue { ConstValue::U32(val) => LLVMConstInt(t, *val as u64, 1), ConstValue::U64(val) => LLVMConstInt(t, *val as u64, 1), ConstValue::U128(val) => LLVMConstInt(t, *val as u64, 1), - ConstValue::StringPtr(val) => LLVMBuildGlobalString( + ConstValue::Str(val) => LLVMBuildGlobalString( module.builder_ref, into_cstring(val).as_ptr(), c"string".as_ptr(), diff --git a/reid-llvm-lib/src/lib.rs b/reid-llvm-lib/src/lib.rs index 5867c1d..215843a 100644 --- a/reid-llvm-lib/src/lib.rs +++ b/reid-llvm-lib/src/lib.rs @@ -439,7 +439,7 @@ pub enum ConstValue { U64(u64), U128(u128), Bool(bool), - StringPtr(String), + Str(String), F16(f32), F32B(f32), F32(f32), @@ -505,12 +505,12 @@ impl InstructionValue { ArrayAlloca(ty, _) => Ok(Type::Ptr(Box::new(ty.clone()))), GetElemPtr(instr, _) => { let instr_ty = instr.get_type(builder)?; - let Type::Ptr(inner_ty) = instr_ty else { + let Type::Ptr(inner_ty) = &instr_ty else { panic!("GetStructElemPtr on non-pointer! ({:?})", &instr_ty) }; - match *inner_ty { + match *inner_ty.clone() { Type::Array(elem_ty, _) => Ok(Type::Ptr(Box::new(*elem_ty.clone()))), - _ => Ok(*inner_ty), + _ => Ok(instr_ty), } } GetStructElemPtr(instr, idx) => { @@ -562,7 +562,7 @@ impl ConstValue { ConstValue::U32(_) => U32, ConstValue::U64(_) => U64, ConstValue::U128(_) => U128, - ConstValue::StringPtr(_) => Ptr(Box::new(I8)), + ConstValue::Str(_) => Type::Ptr(Box::new(I8)), ConstValue::Bool(_) => Bool, ConstValue::F16(_) => F16, ConstValue::F32B(_) => F32B, diff --git a/reid/src/codegen.rs b/reid/src/codegen.rs index 367ecb0..aab4cfb 100644 --- a/reid/src/codegen.rs +++ b/reid/src/codegen.rs @@ -490,7 +490,7 @@ impl mir::Statement { .block .build( name, - Instr::Alloca(ty.get_type(scope.type_values, scope.types)), + Instr::Alloca(value.1.get_type(scope.type_values, scope.types)), ) .unwrap() .maybe_location(&mut scope.block, location); @@ -1167,7 +1167,7 @@ impl mir::Literal { mir::Literal::U64(val) => ConstValue::U64(val), mir::Literal::U128(val) => ConstValue::U128(val), mir::Literal::Bool(val) => ConstValue::Bool(val), - mir::Literal::String(val) => ConstValue::StringPtr(val.clone()), + mir::Literal::String(val) => ConstValue::Str(val.clone()), mir::Literal::Vague(VagueLiteral::Number(val)) => ConstValue::I32(val as i32), mir::Literal::Vague(VagueLiteral::Decimal(val)) => ConstValue::F32(val as f32), mir::Literal::F16(val) => ConstValue::F16(val), @@ -1216,9 +1216,9 @@ impl TypeKind { let type_val = type_vals.get(n).unwrap().clone(); Type::CustomType(type_val) } - TypeKind::UserPtr(type_kind) => Type::Ptr(Box::new(Type::Ptr(Box::new( - type_kind.get_type(type_vals, typedefs), - )))), + TypeKind::UserPtr(type_kind) => { + Type::Ptr(Box::new(type_kind.get_type(type_vals, typedefs))) + } TypeKind::CodegenPtr(type_kind) => { Type::Ptr(Box::new(type_kind.get_type(type_vals, typedefs))) } diff --git a/reid_src/hello_world.reid b/reid_src/hello_world.reid index af7b28b..89c62f7 100644 --- a/reid_src/hello_world.reid +++ b/reid_src/hello_world.reid @@ -1,10 +1,7 @@ - import std::print; fn main() -> i32 { - let hello = "hello world"; - - print(hello); + print("hello world"); return 0; }