diff --git a/compiler/compiler/compiler.go b/compiler/compiler/compiler.go index 8aaec22..10ade14 100644 --- a/compiler/compiler/compiler.go +++ b/compiler/compiler/compiler.go @@ -371,13 +371,14 @@ func (c *Compiler) compileValue(node parser.Node) value.Value { if ty, ok := src.Type.(*types.Slice); ok { src.Type = ty.Type + return c.compileSliceArray(src, v, true) } // array type as pointer receriver if ptr, ok := src.Type.(*types.Pointer); ok { src.Type = ptr.Type src.Value = c.contextBlock.NewLoad(pointer.ElemType(src.Value), src.Value) } - return c.compileSliceArray(src, v) + return c.compileSliceArray(src, v, false) case *parser.InitializeStructNode: return c.compileInitStructWithValues(v) case *parser.TypeCastInterfaceNode: diff --git a/compiler/compiler/slice.go b/compiler/compiler/slice.go index 721fa66..b43c245 100644 --- a/compiler/compiler/slice.go +++ b/compiler/compiler/slice.go @@ -97,7 +97,7 @@ func (c *Compiler) compileSubstring(src value.Value, v *parser.SliceArrayNode) v } } -func (c *Compiler) compileSliceArray(src value.Value, v *parser.SliceArrayNode) value.Value { +func (c *Compiler) compileSliceArray(src value.Value, v *parser.SliceArrayNode, isSliceSlice bool) value.Value { sliceType := internal.Slice(src.Type.LLVM()) alloc := c.contextBlock.NewAlloca(sliceType) @@ -109,7 +109,12 @@ func (c *Compiler) compileSliceArray(src value.Value, v *parser.SliceArrayNode) endIndexValue = c.compileValue(v.End) } else { srcVal := internal.LoadIfVariable(c.contextBlock, src) - endIndexValue.Value = c.contextBlock.NewExtractValue(srcVal, 1) + if isSliceSlice { + endIndexValue.Value = c.contextBlock.NewExtractValue(srcVal, 1) + } else { + arrTy := src.Type.LLVM().(*llvmTypes.ArrayType) + endIndexValue.Value = constant.NewInt(llvmTypes.I32, int64(arrTy.Len)) + } } endIndex := internal.LoadIfVariable(c.contextBlock, endIndexValue)