Skip to content

Commit

Permalink
Minor changes in generated Javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreQuentel committed Sep 27, 2024
1 parent 8367ec6 commit 4d83ba2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 31 deletions.
6 changes: 3 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import urllib.parse
import socketserver

from server_modular_send_head import CGIHTTPRequestHandler
from server_modular_send_head import CGIHTTPRequestHandler, SimpleHTTPRequestHandler

import http.cookiejar

Expand Down Expand Up @@ -231,7 +231,7 @@ def end_headers(self):

args = parser.parse_args()

port = int(args.port) if args.port else 8000
port = int(args.port) if args.port else 8001
ip = str(args.ip) if args.port else "0.0.0.0"

if not args.no_docs:
Expand All @@ -248,7 +248,7 @@ def end_headers(self):

cgi_dir = os.path.join(os.path.dirname(os.getcwd()), 'cgi-bin')

server_address, handler = (ip, port), CompressedHandler
server_address, handler = (ip, port), SimpleHTTPRequestHandler
httpd = socketserver.ThreadingTCPServer(server_address, handler)
httpd.server_name = "Brython built-in server"
httpd.server_port = port
Expand Down
16 changes: 6 additions & 10 deletions www/src/ast_to_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -2570,8 +2570,7 @@ $B.ast.FunctionDef.prototype.to_js = function(scopes){
js += `function ${name2}(){\n`

var locals_name = make_scope_name(scopes, func_scope)
js += `var ${locals_name},
locals\n`
js += `var locals\n`

parse_args.push('arguments')

Expand All @@ -2583,13 +2582,13 @@ $B.ast.FunctionDef.prototype.to_js = function(scopes){
if(positional.length == 0 && slots.length == 0 &&
this.args.vararg === undefined &&
this.args.kwarg === undefined){
js += `${locals_name} = locals = {};\n`
js += `var ${locals_name} = locals = {};\n`
// generate error message
js += `if(arguments.length !== 0){\n` +
`${name2}.$args_parser(${parse_args.join(', ')})\n` +
`}\n`
}else{
js += `${locals_name} = locals = ${name2}.$args_parser(${parse_args.join(', ')})\n`
js += `var ${locals_name} = locals = ${name2}.$args_parser(${parse_args.join(', ')})\n`
}

js += `var frame = ["${this.$is_lambda ? '<lambda>': this.name}", ` +
Expand Down Expand Up @@ -2666,8 +2665,6 @@ $B.ast.FunctionDef.prototype.to_js = function(scopes){

scopes.pop()

//var in_class = func_name_scope.ast instanceof $B.ast.ClassDef

var qualname = in_class ? `${func_name_scope.name}.${this.name}` :
this.name

Expand Down Expand Up @@ -3377,8 +3374,7 @@ $B.ast.Module.prototype.to_js = function(scopes){
global_name = make_scope_name(scopes),
mod_name = module_name(scopes)

var js = `// Javascript code generated from ast\n` +
`var $B = __BRYTHON__,\n_b_ = $B.builtins,\n`
var js = `var $B = __BRYTHON__,\n_b_ = $B.builtins,\n`
if(! namespaces){
js += `${global_name} = $B.imported["${mod_name}"],\n` +
`locals = ${global_name},\n` +
Expand All @@ -3402,8 +3398,8 @@ $B.ast.Module.prototype.to_js = function(scopes){
}


// for exec(), frame is put on top of the stack inside
// py_builtin_functions.js / $$eval()
// for exec(), frame is put on top of the stack inside
// py_builtin_functions.js / $eval()
if(! namespaces){
js += `$B.enter_frame(frame, __file__, 1)\n`
js += '\nvar _frame_obj = $B.frame_obj\n'
Expand Down
17 changes: 6 additions & 11 deletions www/src/brython.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ $B.unicode_bidi_whitespace=[9,10,11,12,13,28,29,30,31,32,133,5760,8192,8193,8194
;
__BRYTHON__.implementation=[3,12,5,'dev',0]
__BRYTHON__.version_info=[3,12,0,'final',0]
__BRYTHON__.compiled_date="2024-09-15 17:57:21.556286"
__BRYTHON__.timestamp=1726415841556
__BRYTHON__.compiled_date="2024-09-27 16:52:40.318531"
__BRYTHON__.timestamp=1727448760317
__BRYTHON__.builtin_module_names=["_ajax","_ast","_base64","_binascii","_io_classes","_json","_jsre","_locale","_multiprocessing","_posixsubprocess","_profile","_random","_sre","_sre_utils","_string","_strptime","_svg","_symtable","_tokenize","_webcomponent","_webworker","_zlib_utils","_zlib_utils1","_zlib_utils_kozh","array","builtins","dis","encoding_cp932","encoding_cp932_v2","hashlib","html_parser","marshal","math","modulefinder","posix","pyexpat","python_re","python_re_new","unicodedata","xml_helpers","xml_parser","xml_parser_backup"]
;

Expand Down Expand Up @@ -3630,9 +3630,6 @@ req.onreadystatechange=function(){if(this.readyState !=4){return}
var status=this.status
if(status==404){result.error=_b_.FileNotFoundError.$factory(file)}else if(status !=200){result.error=_b_.IOError.$factory('Could not open file '+
file+' : status '+status)}else{var bytes=[]
var flag=0
var t0=performance.now()
var response=this.response
for(var codePoint of this.response){var cp=codePoint.codePointAt(0)
if(cp > 0xf700){cp-=0xf700}
bytes[bytes.length]=cp}
Expand Down Expand Up @@ -12396,18 +12393,17 @@ var js=`$B.set_lineno(frame, ${this.lineno})\n`
if(is_async && ! is_generator){js+='async '}
js+=`function ${name2}(){\n`
var locals_name=make_scope_name(scopes,func_scope)
js+=`var ${locals_name},
locals\n`
js+=`var locals\n`
parse_args.push('arguments')
var args_vararg=this.args.vararg===undefined ? 'null' :
"'"+mangle_arg(this.args.vararg.arg)+"'",args_kwarg=this.args.kwarg===undefined ? 'null':
"'"+mangle_arg(this.args.kwarg.arg)+"'"
if(positional.length==0 && slots.length==0 &&
this.args.vararg===undefined &&
this.args.kwarg===undefined){js+=`${locals_name} = locals = {};\n`
this.args.kwarg===undefined){js+=`var ${locals_name} = locals = {};\n`
js+=`if(arguments.length !== 0){\n`+
`${name2}.$args_parser(${parse_args.join(', ')})\n`+
`}\n`}else{js+=`${locals_name} = locals = ${name2}.$args_parser(${parse_args.join(', ')})\n`}
`}\n`}else{js+=`var ${locals_name} = locals = ${name2}.$args_parser(${parse_args.join(', ')})\n`}
js+=`var frame = ["${this.$is_lambda ? '<lambda>': this.name}", `+
`locals, "${gname}", ${globals_name}, ${name2}]
$B.enter_frame(frame, __file__, ${this.lineno})\n`
Expand Down Expand Up @@ -12744,8 +12740,7 @@ this.value instanceof $B.ast.Attribute){return `value: ${$B.js_from_ast(this.val
$B.ast.Module.prototype.to_js=function(scopes){mark_parents(this)
var name=init_scopes.bind(this)('module',scopes),namespaces=scopes.namespaces
var module_id=name,global_name=make_scope_name(scopes),mod_name=module_name(scopes)
var js=`// Javascript code generated from ast\n`+
`var $B = __BRYTHON__,\n_b_ = $B.builtins,\n`
var js=`var $B = __BRYTHON__,\n_b_ = $B.builtins,\n`
if(! namespaces){js+=`${global_name} = $B.imported["${mod_name}"],\n`+
`locals = ${global_name},\n`+
`frame = ["${module_id}", locals, "${module_id}", locals]`}else{
Expand Down
2 changes: 1 addition & 1 deletion www/src/brython_stdlib.js

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions www/src/py_builtin_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3057,9 +3057,6 @@ _b_.open = function(){
file + ' : status ' + status)
}else{
var bytes = []
var flag = 0
var t0 = performance.now()
var response = this.response
for(var codePoint of this.response){
var cp = codePoint.codePointAt(0)
if(cp > 0xf700){
Expand Down Expand Up @@ -3243,7 +3240,7 @@ $B.function.__dir__ = function(self){
}

$B.function.__get__ = function(self, obj){
// adapated from
// adapted from
// https://docs.python.org/3/howto/descriptor.html#functions-and-methods
if(obj === _b_.None){
return self
Expand Down
4 changes: 2 additions & 2 deletions www/src/version_info.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__BRYTHON__.implementation = [3, 12, 5, 'dev', 0]
__BRYTHON__.version_info = [3, 12, 0, 'final', 0]
__BRYTHON__.compiled_date = "2024-09-15 17:57:21.556286"
__BRYTHON__.timestamp = 1726415841556
__BRYTHON__.compiled_date = "2024-09-27 16:52:40.318531"
__BRYTHON__.timestamp = 1727448760317
__BRYTHON__.builtin_module_names = ["_ajax",
"_ast",
"_base64",
Expand Down

0 comments on commit 4d83ba2

Please sign in to comment.