@@ -1024,7 +1024,20 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
1024
1024
throw CodeGenError (" Only string(a:b) for a==b supported for now." , x.base .base .loc );
1025
1025
}
1026
1026
} else {
1027
- throw CodeGenError (" Only string(a:b) for a,b variables for now." , x.base .base .loc );
1027
+ // throw CodeGenError("Only string(a:b) for a,b variables for now.", x.base.base.loc);
1028
+ // Use the "right" index for now
1029
+ this ->visit_expr_wrapper (x.m_args [0 ].m_right , true );
1030
+ llvm::Value *idx = tmp;
1031
+ idx = builder->CreateSub (idx, llvm::ConstantInt::get (context, llvm::APInt (32 , 1 )));
1032
+ // std::vector<llvm::Value*> idx_vec = {llvm::ConstantInt::get(context, llvm::APInt(32, 0)), idx};
1033
+ std::vector<llvm::Value*> idx_vec = {idx};
1034
+ llvm::Value *str = builder->CreateLoad (array);
1035
+ llvm::Value *p = builder->CreateGEP (str, idx_vec);
1036
+ // TODO: Currently the string starts at the right location, but goes to the end of the original string.
1037
+ // We have to allocate a new string, copy it and add null termination.
1038
+
1039
+ tmp = builder->CreateAlloca (character_type, nullptr );
1040
+ builder->CreateStore (p, tmp);
1028
1041
}
1029
1042
} else {
1030
1043
throw CodeGenError (" Only string(a:b) supported for now." , x.base .base .loc );
0 commit comments