@@ -398,14 +398,14 @@ func (fc *funcContext) translateExpr(expr ast.Expr) *expression {
398
398
if isUnsigned (basic ) {
399
399
shift = ">>>"
400
400
}
401
- return fc .formatExpr (`(%1s = %2e / %3e, (%1s === %1s && %1s !== 1/0 && %1s !== -1/0) ? %1s %4s 0 : $throwRuntimeError("integer divide by zero"))` , fc .newVariable ("_q" ), e .X , e .Y , shift )
401
+ return fc .formatExpr (`(%1s = %2e / %3e, (%1s === %1s && %1s !== 1/0 && %1s !== -1/0) ? %1s %4s 0 : $throwRuntimeError("integer divide by zero"))` , fc .newLocalVariable ("_q" ), e .X , e .Y , shift )
402
402
}
403
403
if basic .Kind () == types .Float32 {
404
404
return fc .fixNumber (fc .formatExpr ("%e / %e" , e .X , e .Y ), basic )
405
405
}
406
406
return fc .formatExpr ("%e / %e" , e .X , e .Y )
407
407
case token .REM :
408
- return fc .formatExpr (`(%1s = %2e %% %3e, %1s === %1s ? %1s : $throwRuntimeError("integer divide by zero"))` , fc .newVariable ("_r" ), e .X , e .Y )
408
+ return fc .formatExpr (`(%1s = %2e %% %3e, %1s === %1s ? %1s : $throwRuntimeError("integer divide by zero"))` , fc .newLocalVariable ("_r" ), e .X , e .Y )
409
409
case token .SHL , token .SHR :
410
410
op := e .Op .String ()
411
411
if e .Op == token .SHR && isUnsigned (basic ) {
@@ -421,7 +421,7 @@ func (fc *funcContext) translateExpr(expr ast.Expr) *expression {
421
421
if e .Op == token .SHR && ! isUnsigned (basic ) {
422
422
return fc .fixNumber (fc .formatParenExpr ("%e >> $min(%f, 31)" , e .X , e .Y ), basic )
423
423
}
424
- y := fc .newVariable ("y" )
424
+ y := fc .newLocalVariable ("y" )
425
425
return fc .fixNumber (fc .formatExpr ("(%s = %f, %s < 32 ? (%e %s %s) : 0)" , y , e .Y , y , e .X , op , y ), basic )
426
426
case token .AND , token .OR :
427
427
if isUnsigned (basic ) {
@@ -444,7 +444,7 @@ func (fc *funcContext) translateExpr(expr ast.Expr) *expression {
444
444
if fc .Blocking [e .Y ] {
445
445
skipCase := fc .caseCounter
446
446
fc .caseCounter ++
447
- resultVar := fc .newVariable ("_v" )
447
+ resultVar := fc .newLocalVariable ("_v" )
448
448
fc .Printf ("if (!(%s)) { %s = false; $s = %d; continue s; }" , fc .translateExpr (e .X ), resultVar , skipCase )
449
449
fc .Printf ("%s = %s; case %d:" , resultVar , fc .translateExpr (e .Y ), skipCase )
450
450
return fc .formatExpr ("%s" , resultVar )
@@ -454,7 +454,7 @@ func (fc *funcContext) translateExpr(expr ast.Expr) *expression {
454
454
if fc .Blocking [e .Y ] {
455
455
skipCase := fc .caseCounter
456
456
fc .caseCounter ++
457
- resultVar := fc .newVariable ("_v" )
457
+ resultVar := fc .newLocalVariable ("_v" )
458
458
fc .Printf ("if (%s) { %s = true; $s = %d; continue s; }" , fc .translateExpr (e .X ), resultVar , skipCase )
459
459
fc .Printf ("%s = %s; case %d:" , resultVar , fc .translateExpr (e .Y ), skipCase )
460
460
return fc .formatExpr ("%s" , resultVar )
@@ -513,15 +513,15 @@ func (fc *funcContext) translateExpr(expr ast.Expr) *expression {
513
513
if _ , isTuple := exprType .(* types.Tuple ); isTuple {
514
514
return fc .formatExpr (
515
515
`(%1s = $mapIndex(%2e,%3s), %1s !== undefined ? [%1s.v, true] : [%4e, false])` ,
516
- fc .newVariable ("_entry" ),
516
+ fc .newLocalVariable ("_entry" ),
517
517
e .X ,
518
518
key ,
519
519
fc .zeroValue (t .Elem ()),
520
520
)
521
521
}
522
522
return fc .formatExpr (
523
523
`(%1s = $mapIndex(%2e,%3s), %1s !== undefined ? %1s.v : %4e)` ,
524
- fc .newVariable ("_entry" ),
524
+ fc .newLocalVariable ("_entry" ),
525
525
e .X ,
526
526
key ,
527
527
fc .zeroValue (t .Elem ()),
@@ -689,13 +689,13 @@ func (fc *funcContext) translateExpr(expr ast.Expr) *expression {
689
689
case "Call" :
690
690
if id , ok := fc .identifierConstant (e .Args [0 ]); ok {
691
691
if e .Ellipsis .IsValid () {
692
- objVar := fc .newVariable ("obj" )
692
+ objVar := fc .newLocalVariable ("obj" )
693
693
return fc .formatExpr ("(%s = %s, %s.%s.apply(%s, %s))" , objVar , recv , objVar , id , objVar , externalizeExpr (e .Args [1 ]))
694
694
}
695
695
return fc .formatExpr ("%s(%s)" , globalRef (id ), externalizeArgs (e .Args [1 :]))
696
696
}
697
697
if e .Ellipsis .IsValid () {
698
- objVar := fc .newVariable ("obj" )
698
+ objVar := fc .newLocalVariable ("obj" )
699
699
return fc .formatExpr ("(%s = %s, %s[$externalize(%e, $String)].apply(%s, %s))" , objVar , recv , objVar , e .Args [0 ], objVar , externalizeExpr (e .Args [1 ]))
700
700
}
701
701
return fc .formatExpr ("%s[$externalize(%e, $String)](%s)" , recv , e .Args [0 ], externalizeArgs (e .Args [1 :]))
@@ -842,7 +842,7 @@ func (fc *funcContext) translateCall(e *ast.CallExpr, sig *types.Signature, fun
842
842
fc .caseCounter ++
843
843
returnVar := "$r"
844
844
if sig .Results ().Len () != 0 {
845
- returnVar = fc .newVariable ("_r" )
845
+ returnVar = fc .newLocalVariable ("_r" )
846
846
}
847
847
fc .Printf ("%[1]s = %[2]s(%[3]s); /* */ $s = %[4]d; case %[4]d: if($c) { $c = false; %[1]s = %[1]s.$blk(); } if (%[1]s && %[1]s.$blk !== undefined) { break s; }" , returnVar , fun , strings .Join (args , ", " ), resumeCase )
848
848
if sig .Results ().Len () != 0 {
@@ -873,9 +873,8 @@ func (fc *funcContext) delegatedCall(expr *ast.CallExpr) (callable *expression,
873
873
case * ast.SelectorExpr :
874
874
isJs = typesutil .IsJsPackage (fc .pkgCtx .Uses [fun .Sel ].Pkg ())
875
875
}
876
- sig := fc .typeOf (expr .Fun ).Underlying ().(* types.Signature )
877
- sigTypes := signatureTypes {Sig : sig }
878
- args := fc .translateArgs (sig , expr .Args , expr .Ellipsis .IsValid ())
876
+ sig := typesutil.Signature {Sig : fc .typeOf (expr .Fun ).Underlying ().(* types.Signature )}
877
+ args := fc .translateArgs (sig .Sig , expr .Args , expr .Ellipsis .IsValid ())
879
878
880
879
if ! isBuiltin && ! isJs {
881
880
// Normal function calls don't require wrappers.
@@ -892,12 +891,12 @@ func (fc *funcContext) delegatedCall(expr *ast.CallExpr) (callable *expression,
892
891
ellipsis := expr .Ellipsis
893
892
894
893
for i := range expr .Args {
895
- v := fc .newVariable ("_arg" )
894
+ v := fc .newLocalVariable ("_arg" )
896
895
vars [i ] = v
897
896
// Subtle: the proxy lambda argument needs to be assigned with the type
898
897
// that the original function expects, and not with the argument
899
898
// expression result type, or we may do implicit type conversion twice.
900
- callArgs [i ] = fc .newIdent (v , sigTypes .Param (i , ellipsis .IsValid ()))
899
+ callArgs [i ] = fc .newIdent (v , sig .Param (i , ellipsis .IsValid ()))
901
900
}
902
901
wrapper := & ast.CallExpr {
903
902
Fun : expr .Fun ,
@@ -1173,8 +1172,8 @@ func (fc *funcContext) translateConversion(expr ast.Expr, desiredType types.Type
1173
1172
}
1174
1173
if ptr , isPtr := fc .typeOf (expr ).(* types.Pointer ); fc .pkgCtx .Pkg .Path () == "syscall" && isPtr {
1175
1174
if s , isStruct := ptr .Elem ().Underlying ().(* types.Struct ); isStruct {
1176
- array := fc .newVariable ("_array" )
1177
- target := fc .newVariable ("_struct" )
1175
+ array := fc .newLocalVariable ("_array" )
1176
+ target := fc .newLocalVariable ("_struct" )
1178
1177
fc .Printf ("%s = new Uint8Array(%d);" , array , sizes32 .Sizeof (s ))
1179
1178
fc .Delayed (func () {
1180
1179
fc .Printf ("%s = %s, %s;" , target , fc .translateExpr (expr ), fc .loadStruct (array , target , s ))
@@ -1222,8 +1221,8 @@ func (fc *funcContext) translateConversion(expr ast.Expr, desiredType types.Type
1222
1221
// struct pointer when handling syscalls.
1223
1222
// TODO(nevkontakte): Add a runtime assertion that the unsafe.Pointer is
1224
1223
// indeed pointing at a byte array.
1225
- array := fc .newVariable ("_array" )
1226
- target := fc .newVariable ("_struct" )
1224
+ array := fc .newLocalVariable ("_array" )
1225
+ target := fc .newLocalVariable ("_struct" )
1227
1226
return fc .formatExpr ("(%s = %e, %s = %e, %s, %s)" , array , expr , target , fc .zeroValue (t .Elem ()), fc .loadStruct (array , target , ptrElType ), target )
1228
1227
}
1229
1228
// Convert between structs of different types but identical layouts,
@@ -1245,7 +1244,7 @@ func (fc *funcContext) translateConversion(expr ast.Expr, desiredType types.Type
1245
1244
// type iPtr *int; var c int = 42; println((iPtr)(&c));
1246
1245
// TODO(nevkontakte): Are there any other cases that fall into this case?
1247
1246
exprTypeElem := exprType .Underlying ().(* types.Pointer ).Elem ()
1248
- ptrVar := fc .newVariable ("_ptr" )
1247
+ ptrVar := fc .newLocalVariable ("_ptr" )
1249
1248
getterConv := fc .translateConversion (fc .setType (& ast.StarExpr {X : fc .newIdent (ptrVar , exprType )}, exprTypeElem ), t .Elem ())
1250
1249
setterConv := fc .translateConversion (fc .newIdent ("$v" , t .Elem ()), exprTypeElem )
1251
1250
return fc .formatExpr ("(%1s = %2e, new %3s(function() { return %4s; }, function($v) { %1s.$set(%5s); }, %1s.$target))" , ptrVar , expr , fc .typeName (desiredType ), getterConv , setterConv )
@@ -1312,7 +1311,7 @@ func (fc *funcContext) translateConversionToSlice(expr ast.Expr, desiredType typ
1312
1311
}
1313
1312
1314
1313
func (fc * funcContext ) loadStruct (array , target string , s * types.Struct ) string {
1315
- view := fc .newVariable ("_view" )
1314
+ view := fc .newLocalVariable ("_view" )
1316
1315
code := fmt .Sprintf ("%s = new DataView(%s.buffer, %s.byteOffset)" , view , array , array )
1317
1316
var fields []* types.Var
1318
1317
var collectFields func (s * types.Struct , path string )
@@ -1442,7 +1441,7 @@ func (fc *funcContext) formatExprInternal(format string, a []interface{}, parens
1442
1441
out .WriteByte ('(' )
1443
1442
parens = false
1444
1443
}
1445
- v := fc .newVariable ("x" )
1444
+ v := fc .newLocalVariable ("x" )
1446
1445
out .WriteString (v + " = " + fc .translateExpr (e .(ast.Expr )).String () + ", " )
1447
1446
vars [i ] = v
1448
1447
}
0 commit comments