<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body 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"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<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">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">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">ragel-users@colm.net</a>
<a href="http://www.colm.net/cgi-bin/mailman/listinfo/ragel-users">http://www.colm.net/cgi-bin/mailman/listinfo/ragel-users</a>
</pre>
</blockquote>
</body></html>