@@ -857,7 +857,15 @@ class LValue : public Expr
857857 {
858858 if (stringLiteral)
859859 {
860- this ->type = TYPE_BYTE_ARRAY;
860+ if (!indices.empty ()) {
861+ if (indices.size () > 1 ) {
862+ semantic_error (line, column, " String literal can only be indexed once." );
863+ }
864+ indices[0 ]->check_type (TYPE_INT);
865+ this ->type = TYPE_BYTE;
866+ } else {
867+ this ->type = TYPE_BYTE_ARRAY;
868+ }
861869 return ;
862870 }
863871
@@ -935,11 +943,21 @@ class LValue : public Expr
935943
936944 gvar->setAlignment (llvm::Align (1 ));
937945
938- // Pointer to first character
939946 llvm::Constant *zero = AST::c32 (0 );
940- std::vector<llvm::Constant *> idxList = {zero, zero};
947+
948+ llvm::Value* charIdx = zero;
949+
950+ /* TODO: Fix this for issue #44
951+ if(!indices.empty()) {
952+ llvm::Value *v = indices[0]->igen();
953+ if (!v->getType()->isIntegerTy(32))
954+ v = AST::Builder.CreateZExtOrTrunc(v, AST::i32, "idx");
955+ charIdx = v;
956+ }
957+ */
958+
941959 llvm::Constant *strPtr = llvm::ConstantExpr::getGetElementPtr (
942- strConst->getType (), gvar, idxList );
960+ strConst->getType (), gvar, {zero, charIdx} );
943961
944962 return strPtr;
945963 }
0 commit comments