<div dir="ltr"><div dir="ltr">While you're poking at the Go code generation, some small tweaks:</div><div dir="ltr"><br></div><div dir="ltr">1) The type of the static arrays will be inferred from the type on the right-hand side of the equals sign; it doesn't need to be explicit in the variable declaration.</div><div dir="ltr"><br></div><div dir="ltr">2) Go doesn't fall-through case statements by default; the `break` lines are not necessary.<br><div><br></div><div><div>diff --git a/src/host-go/rlhc-go.lm b/src/host-go/rlhc-go.lm</div><div>index 7ca37b88..41fc2560 100644</div><div>--- a/src/host-go/rlhc-go.lm</div><div>+++ b/src/host-go/rlhc-go.lm</div><div>@@ -288,7 +288,7 @@ namespace go_gen</div><div> [embedded_host(EH)]</div><div> }</div><div> case [A: static_array] {</div><div>- "var [A.ident] \[\] [type(A.type)] = \[\] "</div><div>+ "var [A.ident] = \[\] "</div><div> "[type(A.type)] { [num_list(A.num_list)] }</div><div> "var _ = [A.ident]</div><div> }</div><div>@@ -379,13 +379,11 @@ namespace go_gen</div><div> {</div><div> "case [expr( CB.expr )]:</div><div> "[stmt_list( CB._repeat_stmt )]</div><div>- "break;</div><div> }</div><div> case [DB: default_block]</div><div> {</div><div> "default:</div><div> "[stmt_list( DB._repeat_stmt )]</div><div>- "break;</div><div> }</div><div> case [CL: case_label]</div><div> {</div></div><div><br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 5, 2018 at 9:11 AM Damian Gryski <<a href="mailto:dgryski@gmail.com">dgryski@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">You can prefix the underscore assignments with var also. That will work both at the function and global scopes.<div><span style="font-size:12.8px;font-family:sans-serif"><br></span></div><div><span style="font-size:12.8px;font-family:sans-serif">var _scanner_trans_cond_spaces [] int8 = [] int8 { ... }</span><div><div>var _ = <span style="font-size:12.8px;font-family:sans-serif"> _scanner_trans_cond_space</span></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 5, 2018 at 6:31 AM Adrian Thurston <<a href="mailto:thurston@colm.net" target="_blank">thurston@colm.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div style="font-size:14pt;font-family:Verdana,Geneva,sans-serif">
<p>Hi Damian,</p>
<p>I just altered the codegen so that unused arrays are not generated. This eliminates the need to assign to _ for the static arrays. The need is still there for static variables, for example:</p>
<p> _ = scanner_first_final<br> _ = scanner_error<br> _ = scanner_en_main<br><br></p>
<p>I've noticed though that the _ assignment trick isn't valid for arrays that are not in a function scope, which means we can't use it right after declaration. It could go into the write exec block or the write init block though. To do that I'll have to create a dedicated reference statement for the intermediate language since the go code generator does not understand the state machine. It's just a language translation. The reference statement can have no effect in other languages.</p>
<p>For the time being I'll need to revert the _ assignment since it breaks ragel programs where the data is not function scoped.</p>
<p>Adrian</p>
<p>On 2018-11-01 09:12, Damian Gryski wrote:</p>
<blockquote type="cite" style="padding-left:5px;border-left:#1010ff 2px solid;margin-left:5px">
<div dir="auto">
<div style="font-family:sans-serif;font-size:12.8px" dir="auto">
<div style="margin:16px 0px">
<div>
<div dir="auto">
<div style="font-size:12.8px" dir="auto">
<div style="margin:16px 0px">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div>This is with ragel 7.0.0.11 and colm 0.13.0.6. I was unable to get ragel to build from git.</div>
<div dir="ltr"> </div>
<div dir="ltr">With the example grammar at <a style="text-decoration-line:none;color:#4285f4" href="http://github.com/dgryski/ragel-examples/regexp1" target="_blank">github.com/dgryski/ragel-examples/regexp1</a>, I get the following error:</div>
<div dir="ltr"> </div>
<div dir="ltr">
<div dir="ltr">$ ragel-go sshd.rl</div>
<div dir="ltr">$ go build</div>
<div dir="ltr"># <a style="text-decoration-line:none;color:#4285f4" href="http://github.com/dgryski/ragel-examples/regexp1" target="_blank">github.com/dgryski/ragel-examples/regexp1</a></div>
<div dir="ltr">./sshd.go:11:6: _scanner_trans_cond_spaces declared and not used</div>
<div dir="ltr">./sshd.go:12:6: _scanner_trans_offsets declared and not used</div>
<div dir="ltr">./sshd.go:13:6: _scanner_trans_lengths declared and not used</div>
<div dir="ltr">./sshd.go:14:6: _scanner_cond_keys declared and not used</div>
<div dir="ltr">./sshd.go:17:6: _scanner_eof_cond_spaces declared and not used</div>
<div dir="ltr">./sshd.go:18:6: _scanner_eof_cond_key_offs declared and not used</div>
<div dir="ltr">./sshd.go:19:6: _scanner_eof_cond_key_lens declared and not used</div>
<div dir="ltr">./sshd.go:20:6: _scanner_eof_cond_keys declared and not used</div>
<div dir="ltr">./sshd.go:21:6: _scanner_nfa_targs declared and not used</div>
<div dir="ltr">./sshd.go:22:6: _scanner_nfa_offsets declared and not used</div>
<div dir="ltr">./sshd.go:22:6: too many errors</div>
<div dir="ltr"> </div>
<div dir="ltr">The usual solution to this in autogenerated code is to assign them to `_`, the underscore "blank variable". This satisfies the compiler and the entire array will be eliminated as a dead-store if it ends up not being used.</div>
<div> </div>
<div>Thus, each declaration for variables which may or may not be used will look like:</div>
<div>var _scanner_trans_cond_spaces [] int8 = [] int8 { ... }</div>
<div>_ = _scanner_trans_cond_space</div>
<div> </div>
<div>Note also the first `[] int8` is redundant -- the compiler will infer the type from the type of the array on the right hand side of the `=`.</div>
<div dir="auto"> </div>
<div dir="auto">Fixing these issues in the Go template in the src/host-go directory and rebuilding fixed these errors (although I had to copy files from the git checkout for the template changes to recompile successfully).</div>
<div style="color:#888888">
<div dir="auto"> </div>
<div dir="auto">Damian</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<pre>_______________________________________________
ragel-users mailing list
<a href="mailto:ragel-users@colm.net" target="_blank">ragel-users@colm.net</a>
<a href="http://www.colm.net/cgi-bin/mailman/listinfo/ragel-users" target="_blank">http://www.colm.net/cgi-bin/mailman/listinfo/ragel-users</a>
</pre>
</blockquote>
</div>
_______________________________________________<br>
ragel-users mailing list<br>
<a href="mailto:ragel-users@colm.net" target="_blank">ragel-users@colm.net</a><br>
<a href="http://www.colm.net/cgi-bin/mailman/listinfo/ragel-users" rel="noreferrer" target="_blank">http://www.colm.net/cgi-bin/mailman/listinfo/ragel-users</a></blockquote></div>
</blockquote></div>