diff options
| author | Marc Vertes <mvertes@free.fr> | 2026-01-08 23:46:02 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2026-01-08 23:46:02 +0100 |
| commit | 6ae0a2530c9a57fc093d2159591d9cae8140d641 (patch) | |
| tree | 8c445c99bf3140930ead8ad8c70ebbed9838074e /comp | |
| parent | 6875facb39de63eb6353be2f700b9eacb631e9fa (diff) | |
fix: improve composite literal for slices
Diffstat (limited to 'comp')
| -rw-r--r-- | comp/compiler.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/comp/compiler.go b/comp/compiler.go index 9d787b6..5d55be4 100644 --- a/comp/compiler.go +++ b/comp/compiler.go @@ -176,10 +176,18 @@ func (c *Compiler) Generate(tokens parser.Tokens) (err error) { showStack() pop() ks := pop() + ts := top() switch ks.Kind { case symbol.Const: - if v := ks.Value.Value; v.CanInt() { - emit(t, vm.FieldFset) + switch ts.Type.Rtype.Kind() { + case reflect.Struct: + if v := ks.Value.Value; v.CanInt() { + emit(t, vm.FieldFset) + } + case reflect.Slice: + if v := ks.Value.Value; v.CanInt() { + emit(t, vm.IndexSet) + } } case symbol.Unset: j := top().Type.FieldIndex(ks.Name) @@ -249,7 +257,11 @@ func (c *Compiler) Generate(tokens parser.Tokens) (err error) { c.Data = append(c.Data, s.Value) } if s.Kind == symbol.Type { - emit(t, vm.Fnew, s.Index) + if s.Type.Rtype.Kind() == reflect.Slice { + emit(t, vm.Fnew, s.Index, s.SliceLen) + } else { + emit(t, vm.Fnew, s.Index) + } } else { emit(t, vm.Dup, s.Index) } @@ -265,7 +277,6 @@ func (c *Compiler) Generate(tokens parser.Tokens) (err error) { s.Index = len(c.Data) c.Data = append(c.Data, s.Value) flen = append(flen, len(stack)) - log.Println("### func label:", lc, s.Index, s.Value.Value, c.Data[0].Value) } else { c.Data[s.Index] = s.Value } |
