diff options
author | Sunil Shetye | 2018-08-24 17:24:01 +0530 |
---|---|---|
committer | Sunil Shetye | 2018-08-27 16:43:40 +0530 |
commit | 5cffbe3aa309e242255b96fe954688c6f1380811 (patch) | |
tree | 188788c4003a454783b7b06c667d521dc925dcc6 | |
parent | 249d7545a79bcc66003a80ca393994feb40c5f34 (diff) | |
download | sci2js-5cffbe3aa309e242255b96fe954688c6f1380811.tar.gz sci2js-5cffbe3aa309e242255b96fe954688c6f1380811.tar.bz2 sci2js-5cffbe3aa309e242255b96fe954688c6f1380811.zip |
check for root of variable in global and local lists
check for variable in var type list
-rw-r--r-- | combined.js | 8 | ||||
-rw-r--r-- | js/Sources/GEN_SQR.js | 4 | ||||
-rw-r--r-- | js/Sources/GEN_SQR.pickle | 20 | ||||
-rw-r--r-- | js/Sources/PULSE_SC.js | 4 | ||||
-rw-r--r-- | js/Sources/PULSE_SC.pickle | 12 | ||||
-rwxr-xr-x | sci2jsyacc.py | 43 |
6 files changed, 42 insertions, 49 deletions
diff --git a/combined.js b/combined.js index c14aabae..5440e974 100644 --- a/combined.js +++ b/combined.js @@ -20676,7 +20676,7 @@ function GEN_SQR() { var Exprs0 = [["Amin"],["Amax"],["rule"],["F"]]; this.Bitems = [["Minimum Value"],["Maximum Value"],["Initial Value( 1= Minimum Value 2= Maximum Value)"],["Period (sec)"]]; var Ss = list("mat",[-1,-1],"mat",[-1,-1],"pol",-1,"pol",-1); - var scicos_context = struct(); + this.scicos_context = struct(); var ok = false; while (!ok) { var ok = true; @@ -20687,7 +20687,7 @@ function GEN_SQR() { if (!ok) { return; } - var PREVAR_scicos_context = scicos_context; + var PREVAR_scicos_context = this.scicos_context; var sblock = this.x.model.rpar; var tmpvar0 = script2var(sblock.props.context,PREVAR_scicos_context); var PREVAR_scicos_context = tmpvar0[0]; @@ -21014,7 +21014,7 @@ function PULSE_SC() { var Exprs0 = [["E"],["W"],["F"],["A"]]; this.Bitems = [["Phase delay (secs):"],["Pulse Width (% of period):"],["Period (secs):"],["Amplitude:"]]; var Ss = list("pol",-1,"pol",-1,"pol",-1,"mat",[-1,-1]); - var scicos_context = struct(); + this.scicos_context = struct(); var ok = false; while (!ok) { var ok = true; @@ -21025,7 +21025,7 @@ function PULSE_SC() { if (!ok) { return; } - var PREVAR_scicos_context = scicos_context; + var PREVAR_scicos_context = this.scicos_context; var sblock = this.x.model.rpar; var tmpvar0 = script2var(sblock.props.context,PREVAR_scicos_context); var PREVAR_scicos_context = tmpvar0[0]; diff --git a/js/Sources/GEN_SQR.js b/js/Sources/GEN_SQR.js index 6f06ae0f..62b33975 100644 --- a/js/Sources/GEN_SQR.js +++ b/js/Sources/GEN_SQR.js @@ -70,7 +70,7 @@ function GEN_SQR() { var Exprs0 = [["Amin"],["Amax"],["rule"],["F"]]; this.Bitems = [["Minimum Value"],["Maximum Value"],["Initial Value( 1= Minimum Value 2= Maximum Value)"],["Period (sec)"]]; var Ss = list("mat",[-1,-1],"mat",[-1,-1],"pol",-1,"pol",-1); - var scicos_context = struct(); + this.scicos_context = struct(); var ok = false; while (!ok) { var ok = true; @@ -81,7 +81,7 @@ function GEN_SQR() { if (!ok) { return; } - var PREVAR_scicos_context = scicos_context; + var PREVAR_scicos_context = this.scicos_context; var sblock = this.x.model.rpar; var tmpvar0 = script2var(sblock.props.context,PREVAR_scicos_context); var PREVAR_scicos_context = tmpvar0[0]; diff --git a/js/Sources/GEN_SQR.pickle b/js/Sources/GEN_SQR.pickle index 33ff1d06..045c12de 100644 --- a/js/Sources/GEN_SQR.pickle +++ b/js/Sources/GEN_SQR.pickle @@ -6,24 +6,18 @@ S'needcompile' p2 aS'Bitems' p3 -aS'scicos_context.Amax' +aS'scicos_context' p4 -aS'scicos_context.rule' -p5 aS'graphics' -p6 +p5 aS'Btitre' -p7 +p6 aS'x' -p8 +p7 aS'model' -p9 -aS'scicos_context.F' -p10 -aS'scicos_context.Amin' -p11 -atp12 -Rp13 +p8 +atp9 +Rp10 .(dp0 S'model.odstate' p1 diff --git a/js/Sources/PULSE_SC.js b/js/Sources/PULSE_SC.js index 18cf7949..f8aba75b 100644 --- a/js/Sources/PULSE_SC.js +++ b/js/Sources/PULSE_SC.js @@ -65,7 +65,7 @@ function PULSE_SC() { var Exprs0 = [["E"],["W"],["F"],["A"]]; this.Bitems = [["Phase delay (secs):"],["Pulse Width (% of period):"],["Period (secs):"],["Amplitude:"]]; var Ss = list("pol",-1,"pol",-1,"pol",-1,"mat",[-1,-1]); - var scicos_context = struct(); + this.scicos_context = struct(); var ok = false; while (!ok) { var ok = true; @@ -76,7 +76,7 @@ function PULSE_SC() { if (!ok) { return; } - var PREVAR_scicos_context = scicos_context; + var PREVAR_scicos_context = this.scicos_context; var sblock = this.x.model.rpar; var tmpvar0 = script2var(sblock.props.context,PREVAR_scicos_context); var PREVAR_scicos_context = tmpvar0[0]; diff --git a/js/Sources/PULSE_SC.pickle b/js/Sources/PULSE_SC.pickle index 4071d08e..4764e864 100644 --- a/js/Sources/PULSE_SC.pickle +++ b/js/Sources/PULSE_SC.pickle @@ -6,7 +6,7 @@ S'needcompile' p2 aS'Bitems' p3 -aS'scicos_context.W' +aS'scicos_context' p4 aS'graphics' p5 @@ -16,14 +16,8 @@ aS'x' p7 aS'model' p8 -aS'scicos_context.A' -p9 -aS'scicos_context.F' -p10 -aS'scicos_context.E' -p11 -atp12 -Rp13 +atp9 +Rp10 .(dp0 S'model.odstate' p1 diff --git a/sci2jsyacc.py b/sci2jsyacc.py index bda86d9a..c36e099d 100755 --- a/sci2jsyacc.py +++ b/sci2jsyacc.py @@ -139,8 +139,8 @@ def p_jobfunctionblock_jobfunctionstatement_statementblock_endfunction(p): jset = JOB_BLOCKS['"set"'] jtitle = JOB_BLOCKS['"title"'] - jdefine = '%s%s.prototype.define = function %s() {\n%s%sreturn new %s(this.x);\n%s}\n' % (indent, fname, fname, jdefine, indent2, blocktype, indent) - jdetails = '%s%s.prototype.details = function %s() {\n%sreturn this.x;\n%s}\n' % (indent, fname, fname, indent2, indent) + jdefine = '%s%s.prototype.define = function %s() {\n%s%sreturn new %s(%s);\n%s}\n' % (indent, fname, fname, jdefine, indent2, blocktype, print_var('x'), indent) + jdetails = '%s%s.prototype.details = function %s() {\n%sreturn %s;\n%s}\n' % (indent, fname, fname, indent2, print_var('x'), indent) jget = '%s%s.prototype.get = function %s() {\n%s%s}\n' % (indent, fname, fname, jget, indent) if jgetinputs != '': jgetinputs = '%s%s.prototype.getinputs = function %s() {\n%s%s}\n' % (indent, fname, fname, jgetinputs, indent) @@ -150,7 +150,7 @@ def p_jobfunctionblock_jobfunctionstatement_statementblock_endfunction(p): jgetoutputs = '%s%s.prototype.getoutputs = function %s() {\n%s%s}\n' % (indent, fname, fname, jgetoutputs, indent) if jplot != '': jplot = '%s%s.prototype.plot = function %s() {\n%s%s}\n' % (indent, fname, fname, jplot, indent) - jset = '%s%s.prototype.set = function %s() {\n%s%sreturn new %s(this.x);\n%s}\n' % (indent, fname, fname, jset, indent2, blocktype, indent) + jset = '%s%s.prototype.set = function %s() {\n%s%sreturn new %s(%s);\n%s}\n' % (indent, fname, fname, jset, indent2, blocktype, print_var('x'), indent) jtitle = '%s%s.prototype.get_popup_title = function %s() {\n%svar set_param_popup_title = %s;\n%sreturn set_param_popup_title;\n%s}\n' % (indent, fname, fname, indent2, jtitle, indent2, indent) INDENT_LEVEL -= 1 @@ -615,7 +615,7 @@ def p_modelvar_modelvar_expression_expression(p): def p_assignment_model_modelvar_assignment_modelexpression(p): '''assignment : GRAPHICS DOT modelvar ASSIGNMENT modelexpression EOL | MODEL DOT modelvar ASSIGNMENT modelexpression EOL''' - var = 'this.%s.%s' % (p[1], p[3]) + var = '%s.%s' % (print_var(p[1]), p[3]) value = p[5][0] vartype = p[5][1] add_var_vartype(var, vartype) @@ -711,7 +711,7 @@ def p_getvalueassignment_getvalue_arguments(p): continue add_global_var(basevar, force=True) var = print_var(basevar) - vartype = VAR_TYPES.get(basevar, STRING_TYPE) + vartype = get_var_vartype(basevar, STRING_TYPE) parsefunction = PARSE_MAP.get(vartype, '') if parsefunction != '': parsecall = '%s(arguments[%d][\"%s\"])' % (parsefunction, 0, basevar) @@ -1413,17 +1413,9 @@ def p_termvar_termvar_dot_var(p): | termvar DOT GRAPHICS | termvar DOT MODEL''' var = p[1][0] - if var[:5] == 'this.': - basevar = var[5:] - else: - basevar = var - add_object_var(basevar) + add_object_var(var) var = '%s.%s' % (var, p[3]) - if var[:5] == 'this.': - basevar = var[5:] - else: - basevar = var - vartype = VAR_TYPES[basevar] if basevar in VAR_TYPES else None + vartype = get_var_vartype(var) p[0] = (var, vartype) # A @@ -1433,7 +1425,7 @@ def p_termvar_var(p): | MODEL''' var = p[1] add_global_var(var) - vartype = VAR_TYPES[var] if var in VAR_TYPES else None + vartype = get_var_vartype(var) p[0] = ('%s' % (print_var(var)), vartype) # in @@ -1441,7 +1433,7 @@ def p_termvar_in(p): 'termvar : IN' var = p[1] + '1' add_global_var(var) - vartype = VAR_TYPES[var] if var in VAR_TYPES else None + vartype = get_var_vartype(var) p[0] = ('%s' % (print_var(var)), vartype) # 5 @@ -1474,7 +1466,7 @@ def getblocktype(module): def printblocktypejs(module): blocktype = getblocktype(module) print('%s.prototype.importset = function %s() {\n /* TODO */\n}' % (module, module)) - print('%s.prototype.getContainer = function %s() { return new %s(this.x); }' % (module, module, blocktype)) + print('%s.prototype.getContainer = function %s() { return new %s(%s); }' % (module, module, blocktype, print_var('x'))) def add_local_var(var, force=False): '''If a variable is not global, add it to local list @@ -1485,6 +1477,9 @@ def add_local_var(var, force=False): if var[:5] == 'this.': print('Syntax error: cannot add local variable:', var) return + l = var.find('.') + if l != -1: + var = var[:l] exists = var in GLOBAL_VARS if force and exists: GLOBAL_VARS.remove(var) @@ -1500,6 +1495,9 @@ def add_global_var(var, force=False): If variable name begins with this., remove it''' if var[:5] == 'this.': var = var[5:] + l = var.find('.') + if l != -1: + var = var[:l] exists = var in LOCAL_VARS if force and exists: LOCAL_VARS.remove(var) @@ -1509,7 +1507,9 @@ def add_global_var(var, force=False): def print_var(var): 'If a variable is global, prepend this. to the variable name' - if var in GLOBAL_VARS: + l = var.find('.') + basevar = var[:l] if l != -1 else var + if basevar in GLOBAL_VARS: ret = 'this.%s' % (var) else: ret = '%s' % (var) @@ -1520,6 +1520,11 @@ def add_var_vartype(var, vartype): var = var[5:] VAR_TYPES[var] = vartype +def get_var_vartype(var, vartype=None): + if var[:5] == 'this.': + var = var[5:] + return VAR_TYPES[var] if var in VAR_TYPES else vartype + def add_boolean_var(var): add_var_vartype(var, BOOLEAN_TYPE) |