Closed nwhetsell closed 6 years ago
if ... is syntatic sugar. It gets compiled to the lower level ops. I'd say that it is not selecting the correct op (cigoto ?). If you use -v, it would show what it's compiling to.
After running csound --nosound --orc test.orc --verbose
I get
virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
--Csound version 6.09.1 (double samples) Jul 10 2017
[commit: 0815e64648cdd7497c97d6a82eeffbcc774596a8]
libsndfile-1.0.25
WARNING: could not open library '/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/libjacko.dylib' (-1)
WARNING: could not open library '/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/libjackTransport.dylib' (-1)
WARNING: could not open library '/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/librtjack.dylib' (-1)
decode_long nosound
decode_long orc
decode_long verbose
scoreless operation
Environment variable 'SADIR' has been set to '…'
Environment variable 'SSDIR' has been set to '…'
Environment variable 'MFDIR' has been set to '…'
orchname: test.orc
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
signalflowgraph: csoundModuleInit(0x7fe497802600)
rtaudio: PortAudio module enabled ...
using callback interface
rtmidi: PortMIDI module enabled
Calling preprocess on >>iTest = 1
if iTest == 1 then
prints "\n==> test\n\n"
endif
scoreline_i "e"
#exit
<<
yielding >>#source 1
#line 1
iTest = 1
if iTest == 1 then
prints "\n==> test\n\n"
endif
scoreline_i "e"
<<
Starting parse
Entering state 0
Reading a token: Next token is token T_IDENT ()
Shifting token T_IDENT ()
Entering state 18
Reading a token: Next token is token '=' ()
Reducing stack by rule 171 (line 829):
$1 = token T_IDENT ()
csound_orc_semantics(1994) line = 1
-> $$ = nterm ident ()
Stack now 0
Entering state 33
Next token is token '=' ()
Shifting token '=' ()
Entering state 105
Reading a token: Next token is token INTEGER_TOKEN ()
Shifting token INTEGER_TOKEN ()
Entering state 50
Reducing stack by rule 173 (line 832):
$1 = token INTEGER_TOKEN ()
csound_orc_semantics(1994) line = 1
-> $$ = nterm constant ()
Stack now 0 33 105
Entering state 65
Reducing stack by rule 140 (line 748):
$1 = nterm constant ()
-> $$ = nterm ifac ()
Stack now 0 33 105
Entering state 62
Reducing stack by rule 138 (line 744):
$1 = nterm ifac ()
-> $$ = nterm iterm ()
Stack now 0 33 105
Entering state 61
Reducing stack by rule 129 (line 733):
$1 = nterm iterm ()
-> $$ = nterm iexp ()
Stack now 0 33 105
Entering state 60
Reading a token: Next token is token NEWLINE ()
Reducing stack by rule 120 (line 716):
$1 = nterm iexp ()
-> $$ = nterm expr ()
Stack now 0 33 105
Entering state 185
Next token is token NEWLINE ()
Shifting token NEWLINE ()
Entering state 258
Reducing stack by rule 31 (line 322):
$1 = nterm ident ()
$2 = token '=' ()
$3 = nterm expr ()
$4 = token NEWLINE ()
csound_orc_semantics(1994) line = 2
-> $$ = nterm statement ()
Stack now 0
Entering state 26
Reducing stack by rule 30 (line 318):
$1 = nterm statement ()
-> $$ = nterm topstatement ()
Stack now 0
Entering state 25
Reducing stack by rule 5 (line 199):
$1 = nterm topstatement ()
-> $$ = nterm rootstatement ()
Stack now 0
Entering state 22
Reading a token: Next token is token IF_TOKEN ()
Shifting token IF_TOKEN ()
Entering state 3
Reading a token: Next token is token T_IDENT ()
Shifting token T_IDENT ()
Entering state 48
Reducing stack by rule 171 (line 829):
$1 = token T_IDENT ()
csound_orc_semantics(1994) line = 2
-> $$ = nterm ident ()
Stack now 0 22 3
Entering state 63
Reading a token: Next token is token S_EQ ()
Reducing stack by rule 139 (line 747):
$1 = nterm ident ()
-> $$ = nterm ifac ()
Stack now 0 22 3
Entering state 62
Reducing stack by rule 138 (line 744):
$1 = nterm ifac ()
-> $$ = nterm iterm ()
Stack now 0 22 3
Entering state 61
Reducing stack by rule 129 (line 733):
$1 = nterm iterm ()
-> $$ = nterm iexp ()
Stack now 0 22 3
Entering state 60
Next token is token S_EQ ()
Reducing stack by rule 120 (line 716):
$1 = nterm iexp ()
-> $$ = nterm expr ()
Stack now 0 22 3
Entering state 59
Next token is token S_EQ ()
Shifting token S_EQ ()
Entering state 137
Reading a token: Next token is token INTEGER_TOKEN ()
Shifting token INTEGER_TOKEN ()
Entering state 50
Reducing stack by rule 173 (line 832):
$1 = token INTEGER_TOKEN ()
csound_orc_semantics(1994) line = 2
-> $$ = nterm constant ()
Stack now 0 22 3 59 137
Entering state 65
Reducing stack by rule 140 (line 748):
$1 = nterm constant ()
-> $$ = nterm ifac ()
Stack now 0 22 3 59 137
Entering state 62
Reducing stack by rule 138 (line 744):
$1 = nterm ifac ()
-> $$ = nterm iterm ()
Stack now 0 22 3 59 137
Entering state 61
Reducing stack by rule 129 (line 733):
$1 = nterm iterm ()
-> $$ = nterm iexp ()
Stack now 0 22 3 59 137
Entering state 60
Reading a token: Next token is token THEN_TOKEN ()
Reducing stack by rule 120 (line 716):
$1 = nterm iexp ()
-> $$ = nterm expr ()
Stack now 0 22 3 59 137
Entering state 209
Next token is token THEN_TOKEN ()
Reducing stack by rule 102 (line 693):
$1 = nterm expr ()
$2 = token S_EQ ()
$3 = nterm expr ()
-> $$ = nterm bexpr ()
Stack now 0 22 3
Entering state 58
Next token is token THEN_TOKEN ()
Shifting token THEN_TOKEN ()
Entering state 128
Reducing stack by rule 65 (line 625):
$1 = token THEN_TOKEN ()
csound_orc_semantics(1994) line = 2
-> $$ = nterm then ()
Stack now 0 22 3 58
Entering state 132
Reading a token: Next token is token NEWLINE ()
Shifting token NEWLINE ()
Entering state 200
Reducing stack by rule 28 (line 307):
-> $$ = nterm statementlist ()
Stack now 0 22 3 58 132 200
Entering state 270
Reading a token: Next token is token T_OPCODE0 ()
Shifting token T_OPCODE0 ()
Entering state 4
Reducing stack by rule 183 (line 854):
$1 = token T_OPCODE0 ()
csound_orc_semantics(1994) line = 3
-> $$ = nterm opcode0 ()
Stack now 0 22 3 58 132 200 270
Entering state 34
Reading a token: Next token is token STRING_TOKEN ()
Shifting token STRING_TOKEN ()
Entering state 47
Reducing stack by rule 175 (line 836):
$1 = token STRING_TOKEN ()
csound_orc_semantics(1994) line = 3
-> $$ = nterm constant ()
Stack now 0 22 3 58 132 200 270 34
Entering state 65
Reducing stack by rule 140 (line 748):
$1 = nterm constant ()
-> $$ = nterm ifac ()
Stack now 0 22 3 58 132 200 270 34
Entering state 62
Reducing stack by rule 138 (line 744):
$1 = nterm ifac ()
-> $$ = nterm iterm ()
Stack now 0 22 3 58 132 200 270 34
Entering state 61
Reducing stack by rule 129 (line 733):
$1 = nterm iterm ()
-> $$ = nterm iexp ()
Stack now 0 22 3 58 132 200 270 34
Entering state 60
Reading a token: Next token is token NEWLINE ()
Reducing stack by rule 120 (line 716):
$1 = nterm iexp ()
-> $$ = nterm expr ()
Stack now 0 22 3 58 132 200 270 34
Entering state 112
Next token is token NEWLINE ()
Reducing stack by rule 89 (line 674):
$1 = nterm expr ()
-> $$ = nterm exprlist ()
Stack now 0 22 3 58 132 200 270 34
Entering state 110
Next token is token NEWLINE ()
Shifting token NEWLINE ()
Entering state 188
Reducing stack by rule 39 (line 436):
$1 = nterm opcode0 ()
$2 = nterm exprlist ()
$3 = token NEWLINE ()
-> $$ = nterm statement ()
Stack now 0 22 3 58 132 200 270
Entering state 279
Reducing stack by rule 27 (line 303):
$1 = nterm statementlist ()
$2 = nterm statement ()
-> $$ = nterm statementlist ()
Stack now 0 22 3 58 132 200
Entering state 270
Reading a token: Next token is token ENDIF_TOKEN ()
Shifting token ENDIF_TOKEN ()
Entering state 285
Reading a token: Next token is token NEWLINE ()
Shifting token NEWLINE ()
Entering state 294
Reducing stack by rule 58 (line 544):
$1 = token IF_TOKEN ()
$2 = nterm bexpr ()
$3 = nterm then ()
$4 = token NEWLINE ()
$5 = nterm statementlist ()
$6 = token ENDIF_TOKEN ()
$7 = token NEWLINE ()
-> $$ = nterm ifthen ()
Stack now 0 22
Entering state 29
Reducing stack by rule 44 (line 486):
$1 = nterm ifthen ()
-> $$ = nterm statement ()
Stack now 0 22
Entering state 26
Reducing stack by rule 30 (line 318):
$1 = nterm statement ()
-> $$ = nterm topstatement ()
Stack now 0 22
Entering state 77
Reducing stack by rule 2 (line 187):
$1 = nterm rootstatement ()
$2 = nterm topstatement ()
-> $$ = nterm rootstatement ()
Stack now 0
Entering state 22
Reading a token: Next token is token T_OPCODE0 ()
Shifting token T_OPCODE0 ()
Entering state 4
Reducing stack by rule 183 (line 854):
$1 = token T_OPCODE0 ()
csound_orc_semantics(1994) line = 5
-> $$ = nterm opcode0 ()
Stack now 0 22
Entering state 34
Reading a token: Next token is token STRING_TOKEN ()
Shifting token STRING_TOKEN ()
Entering state 47
Reducing stack by rule 175 (line 836):
$1 = token STRING_TOKEN ()
csound_orc_semantics(1994) line = 5
-> $$ = nterm constant ()
Stack now 0 22 34
Entering state 65
Reducing stack by rule 140 (line 748):
$1 = nterm constant ()
-> $$ = nterm ifac ()
Stack now 0 22 34
Entering state 62
Reducing stack by rule 138 (line 744):
$1 = nterm ifac ()
-> $$ = nterm iterm ()
Stack now 0 22 34
Entering state 61
Reducing stack by rule 129 (line 733):
$1 = nterm iterm ()
-> $$ = nterm iexp ()
Stack now 0 22 34
Entering state 60
Reading a token: Next token is token NEWLINE ()
Reducing stack by rule 120 (line 716):
$1 = nterm iexp ()
-> $$ = nterm expr ()
Stack now 0 22 34
Entering state 112
Next token is token NEWLINE ()
Reducing stack by rule 89 (line 674):
$1 = nterm expr ()
-> $$ = nterm exprlist ()
Stack now 0 22 34
Entering state 110
Next token is token NEWLINE ()
Shifting token NEWLINE ()
Entering state 188
Reducing stack by rule 39 (line 436):
$1 = nterm opcode0 ()
$2 = nterm exprlist ()
$3 = token NEWLINE ()
-> $$ = nterm statement ()
Stack now 0 22
Entering state 26
Reducing stack by rule 30 (line 318):
$1 = nterm statement ()
-> $$ = nterm topstatement ()
Stack now 0 22
Entering state 77
Reducing stack by rule 2 (line 187):
$1 = nterm rootstatement ()
$2 = nterm topstatement ()
-> $$ = nterm rootstatement ()
Stack now 0
Entering state 22
Reading a token: Next token is token NEWLINE ()
Shifting token NEWLINE ()
Entering state 1
Reducing stack by rule 47 (line 507):
$1 = token NEWLINE ()
-> $$ = nterm statement ()
Stack now 0 22
Entering state 26
Reducing stack by rule 30 (line 318):
$1 = nterm statement ()
-> $$ = nterm topstatement ()
Stack now 0 22
Entering state 77
Reducing stack by rule 2 (line 187):
$1 = nterm rootstatement ()
$2 = nterm topstatement ()
-> $$ = nterm rootstatement ()
Stack now 0
Entering state 22
Reading a token: Now at end of input.
Reducing stack by rule 1 (line 177):
$1 = nterm rootstatement ()
ALL<ast>
<tree (0x7fe4980643f0 : 0x7fe498064270) type="61" name="=" loc="2:test.orc">
<treeleft (0x7fe4980642d0 : 0x7fe498064230) type="300" name="T_IDENT" varname="iTest" loc="1:test.orc">
</treeleft>
<treeright (0x7fe498064390 : 0x7fe498064330) type="302" name="INTEGER_TOKEN" value="1" loc="1:test.orc">
</treeright>
</tree>
<treenext (0x7fe498064990 : 0x0) type="274" name="IF_TOKEN" loc="2:test.orc">
<treeleft (0x7fe498064690 : 0x0) type="264" name="S_EQ" loc="2:test.orc">
<treeleft (0x7fe498064510 : 0x7fe4980644b0) type="300" name="T_IDENT" varname="iTest" loc="2:test.orc">
</treeleft>
<treeright (0x7fe4980645d0 : 0x7fe498064570) type="302" name="INTEGER_TOKEN" value="1" loc="2:test.orc">
</treeright>
</treeleft>
<treeright (0x7fe4980646f0 : 0x7fe498064630) type="304" name="THEN_TOKEN" loc="2:test.orc">
<treeright (0x7fe4980647b0 : 0x7fe498064750) type="275" name="T_OPCODE0" opname0="prints" loc="3:test.orc">
<treeright (0x7fe4980648d0 : 0x7fe498064860) type="299" name="T_STRCONST" str=""\n==> test\n\n"" loc="3:test.orc">
</treeright>
</treeright>
</treeright>
</treenext>
<treenext (0x7fe498064a50 : 0x7fe4980649f0) type="275" name="T_OPCODE0" opname0="scoreline_i" loc="5:test.orc">
<treeright (0x7fe498064b10 : 0x7fe498064ab0) type="299" name="T_STRCONST" str=""e"" loc="5:test.orc">
</treeright>
</treenext>
</ast>
-> $$ = nterm orcfile ()
Stack now 0
Entering state 21
Now at end of input.
Stack now 0 21
Cleanup: popping nterm orcfile ()
Semantic Analysis
Semantic Analysis Ends
Parsing successful!
csound_orc_semantics(1994) line = -1
csound_orc_semantics(1994) line = -1
csound_orc_semantics(1994) line = 0
Arg: iTest
Arg: #b0
esr = 44100.0, ekr = 4410.0, ksmps = 10, nchnls = 1 0dbfs = 32768.0
***opcode=cngoto thread=3 pftype=b
error: perf-pass statements illegal in header blk (cngoto)
=.i args: iTest 1
== args: #b0 iTest 1
cngoto args: #b0 __synthetic_300:
prints args: "\n==> test\n\n"
scoreline_i args: "e"
Compile State:
String Pool:
0) =.i
1) instr
2) iTest
3) cngoto
4) "\n==> test\n\n"
5)
==> test
6) #b0
7) "e"
8) ==
9) prints
10) __synthetic_300
11) scoreline_i
12) ""
13) e
14) endin
15) 1
16) 0
Constants Pool:
0) 0.000000
1) 1.000000
Global Variables:
0) sr:r
1) kr:r
2) ksmps:r
3) nchnls:r
4) nchnls_i:r
5) 0dbfs:r
6) A4:r
7) $sr:r
8) $kr:r
9) $ksmps:r
Instrument 0 0x7fe498065ae0 0x0
Variables
0) iTest:i
1) #b0:b
Elapsed time at end of orchestra compile: real: 0.003s, CPU: 0.003s
sorting score ...
yielding >>
<<
... done
Elapsed time at end of score sort: real: 0.003s, CPU: 0.003s
Creating search path cache for 'SNAPDIR':
Creating search path cache for 'SFDIR;SSDIR;INCDIR':
1: "…"
Creating search path cache for 'SFDIR':
Creating search path cache for 'SADIR':
1: "…"
Creating search path cache for 'SFDIR;SSDIR':
1: "…"
graphics suppressed, ascii substituted
0dBFS level = 32768.0
instance(): tp->act_instance = 0x7fe497877610
instr 0 allocated at 0x7fe497877610
lclbas 0x7fe4978777a8, opds 0x7fe4978777c8
op (=.i) allocated at 0x7fe4978777c8
op (==) allocated at 0x7fe497877978
op (cngoto) allocated at 0x7fe4978779c0
opadr = 0x1021f8310
op (prints) allocated at 0x7fe497877a00
op ($label) allocated at 0x7fe49787b8b0
op (scoreline_i) allocated at 0x7fe49787b8f0
==> test
orch now loaded
audio buffered in 1024 sample-frame blocks
not writing to sound disk
SECTION 1:
Score finished in csoundPerform().
removed instance of instr 0
inactive allocs returned to freespace
end of score. overall amps: 0.0
overall samples out of range: 0
0 errors in performance
Elapsed time at end of performance: real: 0.003s, CPU: 0.003s
no sound written to disk
signalflowgraph: csoundModuleDestroy(0x7fe497802600)
I have a version that fixes it but not sure if it will break other stuff
It is in git but NEEDS TESTING for use of "then"
csound_orc_compile_test.c might be a good spot for these sorts of tests.
My problem is knowing what the test should say, even if I understood ctest
(Reopening) From the mailing list, I corrected the change. However, looking at the fix, I'm wondering if this is the way to go to have if-then use different semantics different in instr 0. I'd like to propose that this should fail in instr 0, and that users should use if-ithen in instr 0. @nwhetsell and @jpffitch : thoughts on this?
I don’t see the harm in having
if 1 == 1 then
endif
be the same as
if 1 == 1 ithen
endif
in instrument 0, especially if if
is just syntactic sugar.
@nwhetsell I don't know of any language that changes the meaning of syntax depending on context such as what is being proposed here (i.e., would we really want to have to explain "if-then is a k-rate check everywhere except in instr 0, when it's an i-rate check", which is very odd to me).
BTW: if-then is syntax sugar for if-goto and labels.
I'd rather have if-then be consistent across the language, considering if-ithen exists as an existing solution for instr 0 conditional checks.
Well…
C uses static
for variables that retain their values in between invocations of functions, and for functions that are available only in a particular file.
C# uses using
as a namespace directive, and to simplify using IDisposable
objects.
Python uses in
in for loops, to check for substrings, and to check for membership in collections (like lists and sets).
In Csound itself, =
means assignment everywhere except if
conditions (where it’s the same as ==
); and #
usually means bitwise XOR, but it can also be a macro body delimiter and a macro argument separator.
If the only correct interpretation in instrument 0 of
if 1 == 1 then
endif
is
if 1 == 1 ithen
endif
I think the best thing to do is assume that was the user’s intention.
Of these examples, the C and C# ones have shared keywords but distinct (unambiguous) syntaxes. Python uses in
as an overloaded operator (IMO). Csound's =
and #
are relevant but I think of them as problematic too.
IMO, the introduction of special cases, such as "if-then means this except here it means that", adds cruft to the compiler and understanding of the language. One already has to know and understand the difference between then
and ithen
when programming within instruments and UDO's, so I don't see why this would merit a special case for instrument 0.
What about if the compiler instead printed a more detailed warning? Something like:
error: perf-pass statements illegal in header blk (cngoto)
This usually is a result of using if-then in instr 0 code which runs at k-rate. Did you mean to use if-ithen?
@kunstmusik I would agree that whether the syntax in the examples is ambiguous or unambiguous, or involves an operator or not, is a matter of opinion.
I can’t say I agree that having if
-then
in instrument 0 behave the only possible correct way (the same as if
-ithen
) complicates understanding of Csound. Having Csound interpret if
-then
as something surely incorrect, though, strikes me as odd.
If then
can only mean ithen
in instrument 0, then I don’t see ambiguity, a need for an error message, or a need for a warning. I truly appreciate your attention to this issue, and I don’t have more to add to the discussion, I’m afraid. I leave the ultimate resolution to Csound’s maintainers.
I have a number of comments so I will probably forget something.
First there is not a syntax problem but a semantic one, which I did not want the syntactic construct as I thought it would give rise to problems like this.
We have not solved the problem as using a UDO in instr0 could have the problem. Victor's change is probably the best we can do.
At present in clear cases the semantics are right, and in the problematic cases there is a soft warning. I would like to leave it as it is.
Can we have a status update on this? My suggestion before we close this is: 1) revert the code completely. 2) modify the error message for instr0 perf-pass into a warning (it's benign).
The message is now a warning. My change means it will only be seen in odd cases. I am for leaving it as it is now.
I just pulled the latest from Git and I'm still see the inZero value, the automatic conversion of then to ithen, and no warning messages. (The latest commit number in my history is f7029ee42fc971d311e1ea17d646f3bf2da391a7).
That is what I expect/want.
Sent from TypeApp
On Sep 22, 2017, 14:40, at 14:40, Steven Yi notifications@github.com wrote:
I just pulled the latest from Git and I'm still see the inZero value, the automatic conversion of then to ithen, and no warning messages. (The latest commit number in my history is f7029ee42fc971d311e1ea17d646f3bf2da391a7).
-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/csound/csound/issues/826#issuecomment-331449232
I'm confused, I thought the last we left it we agreed to revert and put in a warning message?
I never agreed to that and previously stated my preference
Sent from TypeApp
On Sep 22, 2017, 19:51, at 19:51, Steven Yi notifications@github.com wrote:
I'm confused, I thought the last we left it we agreed to revert and put in a warning message?
-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/csound/csound/issues/826#issuecomment-331531077
Well, I guess there was some miscommunication then on the last IRC chat as I think Victor had the same understanding from his last comment in this thread. I've voiced my opinions about this issue and am for reverting.
On Fri, Sep 22, 2017 at 3:22 PM, John ffitch notifications@github.com wrote:
I never agreed to that and previously stated my preference
Sent from TypeApp
On Sep 22, 2017, 19:51, at 19:51, Steven Yi notifications@github.com wrote:
I'm confused, I thought the last we left it we agreed to revert and put in a warning message?
-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/csound/csound/issues/826#issuecomment-331531077
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/csound/csound/issues/826#issuecomment-331537950, or mute the thread https://github.com/notifications/unsubscribe-auth/ABjAe6XXKrwtq1dbJVwwiy-7N25bxjxVks5slAjegaJpZM4OZ9mj .
yes, what we decided was that we would not change the parsing/compilation but just remove the perfError, so not to break UDOs
No, you decided, while I did not.
Sent from TypeApp
On Sep 22, 2017, 21:37, at 21:37, vlazzarini notifications@github.com wrote:
yes, what we decided was that we would not change the parsing/compilation but just remove the perfError, so not to break UDOs
-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/csound/csound/issues/826#issuecomment-331554411
So what's the proposed solution for UDOs?
Running
using
csound --nosound --orc test.orc
results inThis strikes me as unexpected because
cngoto
doesn’t appear in the orchestra,iTest
is an i‑time variable, and the orchestra appears to run.