-
Notifications
You must be signed in to change notification settings - Fork 22
/
eval.go
684 lines (609 loc) · 18.3 KB
/
eval.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
//
// Copyright (c) 2019-2024 Markku Rossi
//
// All rights reserved.
//
package ast
import (
"fmt"
"math"
"github.com/markkurossi/mpc/compiler/mpa"
"github.com/markkurossi/mpc/compiler/ssa"
"github.com/markkurossi/mpc/types"
)
const (
debugEval = false
)
// Eval implements the compiler.ast.AST.Eval for list statements.
func (ast List) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
return ssa.Undefined, false, ctx.Errorf(ast, "List.Eval not implemented")
}
// Eval implements the compiler.ast.AST.Eval for function definitions.
func (ast *Func) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
return ssa.Undefined, false, nil
}
// Eval implements the compiler.ast.AST.Eval for variable definitions.
func (ast *VariableDef) Eval(env *Env, ctx *Codegen,
gen *ssa.Generator) (ssa.Value, bool, error) {
return ssa.Undefined, false, nil
}
// Eval implements the compiler.ast.AST.Eval for assignment expressions.
func (ast *Assign) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
var values []interface{}
for _, expr := range ast.Exprs {
val, ok, err := expr.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
// XXX multiple return values.
values = append(values, val)
}
if len(ast.LValues) != len(values) {
return ssa.Undefined, false, ctx.Errorf(ast,
"assignment mismatch: %d variables but %d values",
len(ast.LValues), len(values))
}
arrType := types.Info{
Type: types.TArray,
IsConcrete: true,
ArraySize: types.Size(len(values)),
}
if ast.Define {
for idx, lv := range ast.LValues {
constVal := gen.Constant(values[idx], types.Undefined)
gen.AddConstant(constVal)
arrType.ElementType = &constVal.Type
ref, ok := lv.(*VariableRef)
if !ok {
return ssa.Undefined, false,
ctx.Errorf(ast, "cannot assign to %s", lv)
}
// XXX package.name below
lValue := gen.NewVal(ref.Name.Name, constVal.Type, ctx.Scope())
env.Set(lValue, &constVal)
}
} else {
for idx, lv := range ast.LValues {
ref, ok := lv.(*VariableRef)
if !ok {
return ssa.Undefined, false,
ctx.Errorf(ast, "cannot assign to %s", lv)
}
// XXX package.name below
b, ok := env.Get(ref.Name.Name)
if !ok {
return ssa.Undefined, false,
ctx.Errorf(ast, "undefined variable '%s'", ref.Name)
}
lValue := gen.NewVal(b.Name, b.Type, ctx.Scope())
constVal := gen.Constant(values[idx], b.Type)
gen.AddConstant(constVal)
arrType.ElementType = &constVal.Type
env.Set(lValue, &constVal)
}
}
return gen.Constant(values, arrType), true, nil
}
// Eval implements the compiler.ast.AST.Eval for if statements.
func (ast *If) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
return ssa.Undefined, false, nil
}
// Eval implements the compiler.ast.AST.Eval for call expressions.
func (ast *Call) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
if debugEval {
fmt.Printf("Call.Eval: %s(", ast.Ref)
for idx, expr := range ast.Exprs {
if idx > 0 {
fmt.Print(", ")
}
fmt.Printf("%v", expr)
}
fmt.Println(")")
}
// Resolve called.
var pkgName string
if len(ast.Ref.Name.Package) > 0 {
pkgName = ast.Ref.Name.Package
} else {
pkgName = ast.Ref.Name.Defined
}
pkg, ok := ctx.Packages[pkgName]
if !ok {
return ssa.Undefined, false,
ctx.Errorf(ast, "package '%s' not found", pkgName)
}
_, ok = pkg.Functions[ast.Ref.Name.Name]
if ok {
return ssa.Undefined, false, nil
}
// Check builtin functions.
bi, ok := builtins[ast.Ref.Name.Name]
if ok && bi.Eval != nil {
return bi.Eval(ast.Exprs, env, ctx, gen, ast.Location())
}
// Resolve name as type.
typeName := &TypeInfo{
Point: ast.Point,
Type: TypeName,
Name: ast.Ref.Name,
}
typeInfo, err := typeName.Resolve(env, ctx, gen)
if err != nil {
return ssa.Undefined, false, err
}
if len(ast.Exprs) != 1 {
return ssa.Undefined, false, nil
}
constVal, ok, err := ast.Exprs[0].Eval(env, ctx, gen)
if err != nil {
return ssa.Undefined, false, err
}
if !ok {
return ssa.Undefined, false, nil
}
switch typeInfo.Type {
case types.TInt, types.TUint:
switch constVal.Type.Type {
case types.TInt, types.TUint:
if !typeInfo.Concrete() {
typeInfo.Bits = constVal.Type.Bits
typeInfo.SetConcrete(true)
}
if constVal.Type.MinBits > typeInfo.Bits {
typeInfo.MinBits = typeInfo.Bits
} else {
typeInfo.MinBits = constVal.Type.MinBits
}
cast := constVal
cast.Type = typeInfo
if constVal.HashCode() != cast.HashCode() {
panic("const cast changes value HashCode")
}
if !constVal.Equal(&cast) {
panic("const cast changes value equality")
}
return cast, true, nil
default:
return ssa.Undefined, false,
ctx.Errorf(ast.Ref, "casting %T not supported", constVal.Type)
}
}
return ssa.Undefined, false, nil
}
// Eval implements the compiler.ast.AST.Eval.
func (ast *ArrayCast) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
typeInfo, err := ast.TypeInfo.Resolve(env, ctx, gen)
if err != nil {
return ssa.Undefined, false, err
}
if !typeInfo.Type.Array() {
return ssa.Undefined, false,
ctx.Errorf(ast.Expr, "array cast to non-array type %v", typeInfo)
}
cv, ok, err := ast.Expr.Eval(env, ctx, gen)
if err != nil {
return ssa.Undefined, false, err
}
if !ok {
return ssa.Undefined, false, nil
}
switch cv.Type.Type {
case types.TString:
if cv.Type.Bits%8 != 0 {
return ssa.Undefined, false,
ctx.Errorf(ast.Expr, "invalid string length %v", cv.Type.Bits)
}
chars := cv.Type.Bits / 8
et := typeInfo.ElementType
if et.Bits != 8 || et.Type != types.TUint {
return ssa.Undefined, false,
ctx.Errorf(ast.Expr, "cast from %v to %v",
cv.Type, ast.TypeInfo)
}
if typeInfo.Concrete() {
if typeInfo.ArraySize != chars || typeInfo.Bits != cv.Type.Bits {
return ssa.Undefined, false,
ctx.Errorf(ast.Expr, "cast from %v to %v",
cv.Type, ast.TypeInfo)
}
} else {
typeInfo.Bits = cv.Type.Bits
typeInfo.ArraySize = chars
typeInfo.SetConcrete(true)
}
cast := cv
cast.Type = typeInfo
if cv.HashCode() != cast.HashCode() {
panic("const array cast changes value HashCode")
}
if !cv.Equal(&cast) {
panic("const array cast changes value equality")
}
return cast, true, nil
}
return ssa.Undefined, false, nil
}
// Eval implements the compiler.ast.AST.Eval for return statements.
func (ast *Return) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
return ssa.Undefined, false, nil
}
// Eval implements the compiler.ast.AST.Eval for for statements.
func (ast *For) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
return ssa.Undefined, false, nil
}
// Eval implements the compiler.ast.AST.Eval.
func (ast *ForRange) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
return ssa.Undefined, false, nil
}
// Eval implements the compiler.ast.AST.Eval for binary expressions.
func (ast *Binary) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
l, ok, err := ast.Left.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
r, ok, err := ast.Right.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
if debugEval {
fmt.Printf("%s: Binary.Eval: %v[%v:%v] %v %v[%v:%v]\n",
ast.Location().ShortString(),
ast.Left, l, l.Type, ast.Op, ast.Right, r, r.Type)
}
// Resolve result type.
rt, err := ast.resultType(ctx, l, r)
if err != nil {
return ssa.Undefined, false, err
}
switch lval := l.ConstValue.(type) {
case bool:
rval, ok := r.ConstValue.(bool)
if !ok {
return ssa.Undefined, false, ctx.Errorf(ast.Right,
"%s %v %s: invalid r-value %v (%T)", l, ast.Op, r, rval, rval)
}
switch ast.Op {
case BinaryEq:
return gen.Constant(lval == rval, types.Bool), true, nil
case BinaryNeq:
return gen.Constant(lval != rval, types.Bool), true, nil
case BinaryAnd:
return gen.Constant(lval && rval, types.Bool), true, nil
case BinaryOr:
return gen.Constant(lval || rval, types.Bool), true, nil
}
case *mpa.Int:
rval, ok := r.ConstValue.(*mpa.Int)
if !ok {
return ssa.Undefined, false, ctx.Errorf(ast.Right,
"%s %v %s: invalid r-value %v (%T)", l, ast.Op, r, rval, rval)
}
switch ast.Op {
case BinaryMul:
return gen.Constant(mpa.New(rt.Bits).Mul(lval, rval), rt),
true, nil
case BinaryDiv:
return gen.Constant(mpa.New(rt.Bits).Div(lval, rval), rt),
true, nil
case BinaryMod:
return gen.Constant(mpa.New(rt.Bits).Mod(lval, rval), rt),
true, nil
case BinaryLshift:
return gen.Constant(mpa.New(rt.Bits).Lsh(lval, uint(rval.Int64())),
rt), true, nil
case BinaryRshift:
return gen.Constant(mpa.New(rt.Bits).Rsh(lval, uint(rval.Int64())),
rt), true, nil
case BinaryBand:
return gen.Constant(mpa.New(rt.Bits).And(lval, rval), rt),
true, nil
case BinaryBclear:
return gen.Constant(mpa.New(rt.Bits).AndNot(lval, rval), rt),
true, nil
case BinaryBor:
return gen.Constant(mpa.New(rt.Bits).Or(lval, rval), rt),
true, nil
case BinaryBxor:
return gen.Constant(mpa.New(rt.Bits).Xor(lval, rval), rt),
true, nil
case BinaryAdd:
return gen.Constant(mpa.New(rt.Bits).Add(lval, rval), rt),
true, nil
case BinarySub:
return gen.Constant(mpa.New(rt.Bits).Sub(lval, rval), rt),
true, nil
case BinaryEq:
return gen.Constant(lval.Cmp(rval) == 0, types.Bool), true, nil
case BinaryNeq:
return gen.Constant(lval.Cmp(rval) != 0, types.Bool), true, nil
case BinaryLt:
return gen.Constant(lval.Cmp(rval) == -1, types.Bool), true, nil
case BinaryLe:
return gen.Constant(lval.Cmp(rval) != 1, types.Bool), true, nil
case BinaryGt:
return gen.Constant(lval.Cmp(rval) == 1, types.Bool), true, nil
case BinaryGe:
return gen.Constant(lval.Cmp(rval) != -1, types.Bool), true, nil
}
case string:
rval, ok := r.ConstValue.(string)
if !ok {
return ssa.Undefined, false, ctx.Errorf(ast.Right,
"%s %v %s: invalid r-value %v (%T)", l, ast.Op, r, rval, rval)
}
switch ast.Op {
case BinaryAdd:
return gen.Constant(lval+rval, types.Undefined), true, nil
}
}
return ssa.Undefined, false, ctx.Errorf(ast.Right,
"invalid operation: operator %s not defined on %v (%v)",
ast.Op, l, l.Type)
}
// Eval implements the compiler.ast.AST.Eval for unary expressions.
func (ast *Unary) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
expr, ok, err := ast.Expr.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
switch val := expr.ConstValue.(type) {
case bool:
switch ast.Type {
case UnaryNot:
return gen.Constant(!val, types.Bool), true, nil
}
case *mpa.Int:
switch ast.Type {
case UnaryMinus:
r := mpa.NewInt(0, expr.Type.Bits)
return gen.Constant(r.Sub(r, val), expr.Type), true, nil
}
}
return ssa.Undefined, false, ctx.Errorf(ast.Expr,
"invalid unary expression: %s%T", ast.Type, ast.Expr)
}
// Eval implements the compiler.ast.AST.Eval for slice expressions.
func (ast *Slice) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
expr, ok, err := ast.Expr.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
from := 0
to := math.MaxInt32
if ast.From != nil {
val, ok, err := ast.From.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
from, err = intVal(val)
if err != nil {
return ssa.Undefined, false, ctx.Errorf(ast.From, err.Error())
}
}
if ast.To != nil {
val, ok, err := ast.To.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
to, err = intVal(val)
if err != nil {
return ssa.Undefined, false, ctx.Errorf(ast.To, err.Error())
}
}
if to < from {
return ssa.Undefined, false, ctx.Errorf(ast.Expr,
"invalid slice range %d:%d", from, to)
}
if !expr.Type.Type.Array() {
return ssa.Undefined, false, ctx.Errorf(ast.Expr,
"invalid operation: cannot slice %v (%v)", expr, expr.Type)
}
arr, err := expr.ConstArray()
if err != nil {
return ssa.Undefined, false, err
}
if to == math.MaxInt32 {
to = int(expr.Type.ArraySize)
}
if to > int(expr.Type.ArraySize) || from > to {
return ssa.Undefined, false, ctx.Errorf(ast.From,
"slice bounds out of range [%d:%d] in slice of length %v",
from, to, expr.Type.ArraySize)
}
numElements := to - from
switch val := arr.(type) {
case []interface{}:
ti := expr.Type
ti.ArraySize = types.Size(numElements)
// The gen.Constant will set the bit sizes.
return gen.Constant(val[from:to], ti), true, nil
case []byte:
constVal := make([]interface{}, numElements)
for i := 0; i < numElements; i++ {
constVal[i] = int64(val[from+i])
}
ti := expr.Type
ti.ArraySize = types.Size(numElements)
// The gen.Constant will set the bit sizes.
return gen.Constant(constVal, ti), true, nil
default:
return ssa.Undefined, false, ctx.Errorf(ast.Expr,
"invalid operation: cannot slice %T array", arr)
}
}
func intVal(val interface{}) (int, error) {
switch v := val.(type) {
case *mpa.Int:
return int(v.Int64()), nil
case ssa.Value:
if !v.Const {
return 0, fmt.Errorf("non-const slice index: %v", v)
}
return intVal(v.ConstValue)
default:
return 0, fmt.Errorf("invalid slice index: %T", v)
}
}
// Eval implements the compiler.ast.AST.Eval() for index expressions.
func (ast *Index) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
expr, ok, err := ast.Expr.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
val, ok, err := ast.Index.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
index, err := intVal(val)
if err != nil {
return ssa.Undefined, false, ctx.Errorf(ast.Index, err.Error())
}
switch expr.Type.Type {
case types.TArray, types.TSlice:
if index < 0 || index >= int(expr.Type.ArraySize) {
return ssa.Undefined, false, ctx.Errorf(ast.Index,
"invalid array index %d (out of bounds for %d-element array)",
index, expr.Type.ArraySize)
}
arr, err := expr.ConstArray()
if err != nil {
return ssa.Undefined, false, err
}
switch val := arr.(type) {
case []interface{}:
return gen.Constant(val[index], *expr.Type.ElementType), true, nil
case []byte:
return gen.Constant(int64(val[index]), *expr.Type.ElementType),
true, nil
}
case types.TString:
numBytes := expr.Type.Bits / types.ByteBits
if index < 0 || index >= int(numBytes) {
return ssa.Undefined, false, ctx.Errorf(ast.Index,
"invalid array index %d (out of bounds for %d-element string)",
index, numBytes)
}
str, err := expr.ConstString()
if err != nil {
return ssa.Undefined, false, err
}
bytes := []byte(str)
return gen.Constant(int64(bytes[index]), types.Byte), true, nil
}
return ssa.Undefined, false, ctx.Errorf(ast.Expr,
"invalid operation: cannot index %v (%v)", expr, expr.Type)
}
// Eval implements the compiler.ast.AST.Eval for variable references.
func (ast *VariableRef) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
lrv, ok, _, err := ctx.LookupVar(nil, gen, env.Bindings, ast)
if err != nil {
return ssa.Undefined, false, ctx.Error(ast, err.Error())
}
if !ok {
return ssa.Undefined, ok, nil
}
return lrv.ConstValue()
}
// Eval implements the compiler.ast.AST.Eval for constant values.
func (ast *BasicLit) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
return gen.Constant(ast.Value, types.Undefined), true, nil
}
// Eval implements the compiler.ast.AST.Eval for constant values.
func (ast *CompositeLit) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
// XXX the init values might be short so we must pad them with
// zero values so that we create correctly sized values.
typeInfo, err := ast.Type.Resolve(env, ctx, gen)
if err != nil {
return ssa.Undefined, false, err
}
switch typeInfo.Type {
case types.TStruct:
// Check if all elements are constants.
var values []interface{}
for _, el := range ast.Value {
// XXX check if el.Key is specified
v, ok, err := el.Element.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
// XXX check that v is assignment compatible with typeInfo.Struct[i]
values = append(values, v)
}
return gen.Constant(values, typeInfo), true, nil
case types.TArray, types.TSlice:
// Check if all elements are constants.
var values []interface{}
for _, el := range ast.Value {
// XXX check if el.Key is specified
v, ok, err := el.Element.Eval(env, ctx, gen)
if err != nil || !ok {
return ssa.Undefined, ok, err
}
// XXX check that v is assignment compatible with array.
values = append(values, v)
}
typeInfo.ArraySize = types.Size(len(values))
typeInfo.Bits = typeInfo.ArraySize * typeInfo.ElementType.Bits
typeInfo.MinBits = typeInfo.Bits
return gen.Constant(values, typeInfo), true, nil
default:
fmt.Printf("CompositeLit.Eval: not implemented yet: %v, Value: %v\n",
typeInfo, ast.Value)
return ssa.Undefined, false, nil
}
}
// Eval implements the compiler.ast.AST.Eval for the builtin function make.
func (ast *Make) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
if len(ast.Exprs) != 1 {
return ssa.Undefined, false, ctx.Errorf(ast,
"invalid amount of argument in call to make")
}
typeInfo, err := ast.Type.Resolve(env, ctx, gen)
if err != nil {
return ssa.Undefined, false, ctx.Errorf(ast.Type, "%s is not a type",
ast.Type)
}
if typeInfo.Type.Array() {
// Arrays are made in Make.SSA.
return ssa.Undefined, false, nil
}
if typeInfo.Bits != 0 {
return ssa.Undefined, false, ctx.Errorf(ast.Type,
"can't make specified type %s", typeInfo)
}
constVal, _, err := ast.Exprs[0].Eval(env, ctx, gen)
if err != nil {
return ssa.Undefined, false, ctx.Error(ast.Exprs[0], err.Error())
}
length, err := constVal.ConstInt()
if err != nil {
return ssa.Undefined, false, ctx.Errorf(ast.Exprs[0],
"non-integer (%T) len argument in %s: %s", constVal, ast, err)
}
typeInfo.IsConcrete = true
typeInfo.Bits = length
// Create typeref constant.
return gen.Constant(typeInfo, types.Undefined), true, nil
}
// Eval implements the compiler.ast.AST.Eval for the builtin function copy.
func (ast *Copy) Eval(env *Env, ctx *Codegen, gen *ssa.Generator) (
ssa.Value, bool, error) {
return ssa.Undefined, false, nil
}