@@ -910,6 +910,11 @@ where compile() was called, in untrusted/run.js.
910
910
var initialstart = prog . search ( lineno_string )
911
911
start = initialstart
912
912
913
+ // console.log('fcts', fcts)
914
+ // console.log('classes', classes)
915
+ // console.log('classinstances', classinstances)
916
+ // console.log('classmethods', classmethods)
917
+
913
918
// Prepend 'async ' to all user functions
914
919
let filter_functions = [ ]
915
920
while ( true ) { // locate Python filter(name, list)
@@ -938,9 +943,10 @@ where compile() was called, in untrusted/run.js.
938
943
prog = prog . slice ( 0 , start + m . index + 1 ) + 'async function ' + name + string_insert + prog . slice ( start + m . index + m [ 0 ] . length )
939
944
start += m . index + 'async function ' . length + m [ 1 ] . length + string_insert . length + 1
940
945
}
941
- } // end of prepending 'async' to user functions
942
-
943
- // Prepend "await " to calls to user functions and the GlowScript async functions (all user functions and class methods are marked async).
946
+ }
947
+ // ===================== End of prepending 'async' to user functions =====================
948
+ // Next, prepend "await " to calls to user functions and the GlowScript async functions (all user functions and class methods are marked async).
949
+
944
950
start = initialstart
945
951
946
952
// VPython_import is the prefix of VPython objects, with value 'null' if no import statement
@@ -1094,23 +1100,20 @@ where compile() was called, in untrusted/run.js.
1094
1100
// be difficult in the transpiling to know whether "obj" is a user object or a VPython object,
1095
1101
// both of which have rotate methods, but only the user object needs await.
1096
1102
1097
-
1098
-
1099
1103
if ( // Test for cases that need await:
1100
1104
( period && prefix == 'self' ) || // in self.f, f may be a function passed to __init__
1101
1105
( period && prefix . slice ( 0 , 10 ) == 'ρσ_getitem' && classmethods . indexOf ( name ) >= 0 ) || // ρσ_getitem(...).usermethod
1102
1106
( period && classes . indexOf ( prefix ) >= 0 && classmethods . indexOf ( name ) >= 0 ) || // userclass.usermethod()
1103
1107
( period && classinstances . indexOf ( prefix ) < 0 && vpfcts . indexOf ( name ) >= 0 ) || // scene.pause(), scene.waitfor(), scene.capture()
1104
1108
( period && prefix === VPython_import && vpwaits . indexOf ( name ) >= 0 ) || // vp.rate/vp.sleep/vp.get_library/vp.read_local_file
1105
1109
( period && classinstances . indexOf ( prefix ) >= 0 && classmethods . indexOf ( name ) >= 0 ) || // userinstance.usermethod()
1106
- ( period && classinstances . indexOf ( name ) < 0 && no_await2 . indexOf ( name ) < 0 ) || // scene.bind()
1110
+ ( period && classinstances . indexOf ( prefix ) >= 0 && no_await2 . indexOf ( name ) < 0 ) || // scene.bind()
1107
1111
( ! period && fcts . indexOf ( name ) >= 0 ) || // f()
1108
1112
( ! period && classmethods . indexOf ( name ) >= 0 ) || // usermethod(), preceded by usermethod = userclass.method()
1109
1113
( ! period && classes . indexOf ( name ) >= 0 ) || // userclass()
1110
1114
( ! period && no_await . indexOf ( name ) < 0 ) || // cos()
1111
1115
( ! period && no_await . indexOf ( name ) < 0 && no_await2 . indexOf ( name ) < 0 &&
1112
1116
fcts . indexOf ( name ) < 0 ) ) { // probably a user function has been passed to a function
1113
- ;
1114
1117
} else { // probably no need to prepend await
1115
1118
if ( period && prefix == 'ρσ_interpolate_kwargs' && name == 'call' ) { // ρσ_interpolate_kwargs.call(this, f, ....)
1116
1119
let end = prog . slice ( start + m . index ) . search ( '\n' )
@@ -1222,16 +1225,16 @@ where compile() was called, in untrusted/run.js.
1222
1225
// s = " ρσ_list_decorate.prototype.pop = function(arg) {return this.pypop(arg)}\n"
1223
1226
// program = program.slice(0,sc)+s+program.slice(sc,program.length)
1224
1227
1225
- // var p = program.split('\n')
1226
- // for (var i=0; i<p.length; i++) console.log(i, p[i])
1228
+ // let p = program.split('\n')
1229
+ // for (let i=0; i<p.length; i++) console.log(i, p[i])
1227
1230
// console.log('fcts', fcts)
1228
1231
// console.log('vpfcts', vpfcts)
1229
1232
// console.log('classes', classes)
1230
1233
// console.log('classinstances', classinstances)
1231
1234
// console.log('classmethods', classmethods)
1232
1235
// console.log('============================================================================')
1233
- // var i = program.search('"2";')
1234
- // var i = program.search('async function __main__')
1236
+ // let i = program.search('"2";')
1237
+ // let i = program.search('async function __main__')
1235
1238
// console.log(program.slice(i))
1236
1239
// console.log(program)
1237
1240
return program
0 commit comments