Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Binary file modified GlowScriptOffline/glowscript_libraries/RSrun.3.1.min.js
Binary file not shown.
2 changes: 1 addition & 1 deletion GlowScriptOffline/glowscript_libraries/compiler.3.1.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion GlowScriptOffline/glowscript_libraries/glow.3.1.min.js

Large diffs are not rendered by default.

Binary file modified GlowScriptOffline3.1.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion build_original.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def minify(inlibs, inlibs_nomin, outlib):
minify( glowscript_libraries["RScompile"], [], "package/RScompiler." + version + ".min.js" )
print('Finished RapydScript compiler package\n')

# For GlowScript 2.6 runtime.js had the encoding "UCS-2 LE BOM" which the Uglify
# For GlowScript 3.1 runtime.js had the encoding "UCS-2 LE BOM" which the Uglify
# machinery could not handle. Using (on Windows) notepad++ the encoding was changed
# to "UTF-8" which solved the problem.
minify( glowscript_libraries["RSrun"], [], "package/RSrun." + version + ".min.js" )
Expand Down
74 changes: 59 additions & 15 deletions lib/compiling/GScompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ the rapydscript-ng runtime library (but see below for an alternative procedure):
var a;
a = 1;
6) Copy the file to lib/rapydscript/runtime.js.
For GlowScript 3.1 runtime.js had the encoding "UCS-2 LE BOM" which the Uglify
machinery could not handle. Using (on Windows) notepad++ the encoding was changed
to "UTF-8" which solved the problem.

The instructions above for building the two RapydScript files are adequate if it is not necessary to
get the very latest version from the rapydscript-ng repository. If there have been commits to the
Expand Down Expand Up @@ -188,7 +191,7 @@ where compile() was called, in untrusted/run.js.
const instpatt = new RegExp('(\\w+)\\s*\\(') // find a constructor of a Python class
const defpatt = new RegExp('^def\\s+(\\w+)\\s*\\(') // find a Python def
const asyncpatt1 = new RegExp('\\Wfunction\\s*(\\w+)\\s*\\(') // find "function f(...."
const awaitpatt = new RegExp('\\W(\\w+)\\s*\\(') // find a function call
const awaitpatt = new RegExp('\\W([ρσ\\w]+)\\s*\\(') // find a function call
//const jsasyncpatt1 = new RegExp('\\Wfunction\\s*([\\w\.]+)\\s*\\(') // find "function f(...."

// fcts is a list of GlowScript functions that need "await" and of all user functions that are not
Expand Down Expand Up @@ -570,7 +573,7 @@ where compile() was called, in untrusted/run.js.
// Check whether this line contains function calls inside strings, which will not need "await"
start = 0
while (true) {
// const awaitpatt = new RegExp('\\W(\\w+)\\s*\\(') // find a function call
// const awaitpatt = new RegExp('\\W([ρσ\\w]+)\\s*\\(') // find a function call
var m = line.slice(start).match(awaitpatt)
if (m !== null) {
start += m.index
Expand Down Expand Up @@ -926,7 +929,7 @@ where compile() was called, in untrusted/run.js.
start = initialstart

// VPython_import is the prefix of VPython objects, with value 'null' if no import statement
// const awaitpatt = new RegExp('\\W(\\w+)\\s*\\(') // find a function call
// const awaitpatt = new RegExp('\\W([ρσ\\w]+)\\s*\\(') // find a function call
while (true) {
m = prog.slice(start).match(awaitpatt)
var period = false
Expand All @@ -943,22 +946,22 @@ where compile() was called, in untrusted/run.js.
continue
}

// Might start with 'ρσ_' or be "....".option(...)
//if ( name.slice(0,3) == 'ρσ_' || (period && (prog[start+m.index-1] == '"')) ) {
// Might start with 'ρσ_'
if ( name.slice(0,3) == 'ρσ_') {
start += m.index+name.length+1
continue
}

// find the beginning of ....f()
var ptr = start+m.index+1
var brackets = 0
var parens = 0
let ptr = start+m.index+1
let brackets = 0
let parens = 0
let singlequote = false
let doublequote = false
let char
while (true) {
ptr--
let char = prog[ptr]
char = prog[ptr]
if (char == '"') {
singlequote = !singlequote
}else if (char == "'") {
Expand All @@ -979,10 +982,51 @@ where compile() was called, in untrusted/run.js.
}
}

var pstart = ptr+1 // start of ....f()
var prefix = ''
if (period) {
let pstart = ptr+1 // start of ....f()
let prefix = ''
if (period) {
// paths and shapes are lists which need to be converted to RapydScript lists to have methods such as insert
// This requires wrapping 'ρσ_interpolate_kwargs.call(paths,...' inside 'ρσ_list_decorate('
const inter = 'ρσ_interpolate_kwargs'
const deco = 'ρσ_list_decorate('
prefix = prog.slice(pstart,start+m.index)
if (prefix == inter && name == 'call') {
let comma = prog.slice(start+m.index+6).search(',')
let f = prog.slice(start+m.index+6,start+m.index+6+comma)
if (f == 'paths' || f == 'shapes') {
comma += start+m.index+6
parens = 1
while (true) {
char = prog[comma]
if (char == '(') parens++
else if (char == ')') {
parens--
if (parens === 0) break
}
comma++
}
prog = prog.slice(0,pstart)+deco+prog.slice(pstart,comma)+')'+prog.slice(comma)
start = deco.length+comma
} else {
start += m.index+name.length+2
}
continue
} else if (prefix == 'paths' || prefix == 'shapes') {
ptr = prog.slice(start+m.index+name.length+1).search('\\(')+start+m.index+name.length+2
parens = 1
while (true) {
char = prog[ptr]
if (char == '(') parens++
else if (char == ')') {
parens--
if (parens === 0) break
}
ptr++
}
prog = prog.slice(0,pstart)+deco+prog.slice(pstart,ptr)+')'+prog.slice(ptr)
start = ptr+deco.length
continue
}
}
// RapydScript-NG leaves string.replace unchanged from JavaScript, so for
// VPython we invoke string.__GSrep(), implemented in vectors.js, to mimic Python:
Expand All @@ -993,7 +1037,7 @@ where compile() was called, in untrusted/run.js.
}

// Python and VPython and RapydScript and JavaScript key words that can precede '(':
var no_await = ['if', 'elif', 'return', 'for', 'while', 'function', 'else', 'dict', 'str',
let no_await = ['if', 'elif', 'return', 'for', 'while', 'function', 'else', 'dict', 'str',
'float', 'hex', 'int', 'iter', 'len', 'list', 'vec', 'vector', 'catch', 'enumerate',
'oct', 'ord', 'print', 'range', 'arange', 'update', 'print', 'GSprint', 'clock', 'msclock',
'canvas', 'graph', 'gcurve', 'gdots', 'gvbars', 'ghbars', 'rotate', 'box', 'cylinder',
Expand All @@ -1008,10 +1052,10 @@ where compile() was called, in untrusted/run.js.
// Python and VPython key words that can be preceded by 'xxx.'
// 'defineProperties' is a RapydScript-NG element.
// slice is part of the RapydScript-generated JavaScript for list comprehensions.
var no_await2 = ['remove', 'select', 'append_to_title', 'append_to_caption', 'bind', 'unbind', 'call', 'append',
let no_await2 = ['remove', 'select', 'append_to_title', 'append_to_caption', 'bind', 'unbind', 'call', 'append',
'rgb_to_hsv', 'hsv_to_rgb', 'mag', 'mag2', 'norm', 'hat', 'rotate', 'random', 'pow', 'equals',
'format', 'trigger', 'follow', 'defineProperties', 'textures', 'bumpmaps', 'slice', 'plot',
'pop', 'pypop']
'pop', 'pypop', 'insert']

// If not a user function, nor pause/waitfor/rate/sleep/read_local_file/get_library,
// nor prefix is VPython_import, don't prepend await to this function call.
Expand Down
2 changes: 1 addition & 1 deletion lib/glow/primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
if (jv !== undefined) { // location in Jupyter VPython of texture files: "/nbextensions/vpython_data/"
name = jv+name.slice(1)
} else {
name = "../lib/FilesInAWS/"+name.slice(1)
name = "https://s3.amazonaws.com/glowscript/textures/"+name.slice(1)
}
}
obj.canvas.__renderer.initTexture(name, obj, isbump)
Expand Down
Binary file modified lib/rapydscript/runtime.js
Binary file not shown.
2 changes: 1 addition & 1 deletion package/RScompiler.3.1.min.js

Large diffs are not rendered by default.

Binary file modified package/RSrun.3.1.min.js
Binary file not shown.
2 changes: 1 addition & 1 deletion package/compiler.3.1.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package/glow.3.1.min.js

Large diffs are not rendered by default.