Created
March 30, 2011 16:41
-
-
Save erickt/894765 to your computer and use it in GitHub Desktop.
bug that exhibits code generation bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Warning: typeclass IByteStream entry read_line is not virtual | |
| bar/webserver.cpp: In member function ‘void* flxusr::webserver::aux::apply()’: | |
| bar/webserver.cpp:107: error: ‘pc’ was not declared in this scope | |
| compilation terminated due to -Wfatal-errors. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ----------------------------------------------------------------------------- | |
| union error[E,A] = | |
| | Error of E | |
| | Ok of A | |
| ; | |
| // ----------------------------------------------------------------------------- | |
| include "std/io/faio"; | |
| include "std/io/demux"; | |
| open Demux; | |
| open Faio; | |
| type socket_t = "int"; | |
| type socketio_request = "flx::faio::socketio_request"; | |
| gen mk_socketio_request: demuxer * socket_t * address * int * bool -> socketio_request | |
| = 'flx::faio::socketio_request($1, $2, (char*)$3, $4, $5)'; | |
| fun get_pb: socketio_request -> sel_param_ptr = '&$1.sv.pb'; | |
| // read & write differ only by a flag | |
| gen async_rw(fd: socket_t, buf: address, var len: int, read_flag: bool) = { | |
| var eof: bool; | |
| var asyncb = mk_socketio_request(sys_demux,fd, buf, len, read_flag); | |
| faio_req$ &asyncb; | |
| calc_eof(asyncb.pb, &len, &eof); | |
| return Ok[int,int] len; | |
| } | |
| gen async_read(fd: socket_t, buf: address, len: int) = { | |
| return async_rw(fd, buf, len, true); // read | |
| } | |
| // ----------------------------------------------------------------------------- | |
| typeclass IByteStream[T] { | |
| virtual gen read: T * address * int -> error[int,int]; | |
| gen read_line (istream: T) = { | |
| var c: char; | |
| val ac = address (&c); | |
| var st = ""; | |
| gen aux () => | |
| match read(istream, ac, 1) with | |
| | Error ?e => { return Error[int,string] e; } | |
| | Ok ?len => { | |
| if len == 0 do | |
| return Ok[int,string] st; | |
| else | |
| return aux (); | |
| done | |
| } | |
| endmatch () | |
| ; | |
| return aux (); | |
| } | |
| } | |
| // ----------------------------------------------------------------------------- | |
| instance IByteStream[socket_t] | |
| { | |
| gen read(s: socket_t, buf: address, len: int) = { | |
| return async_read(s, buf, len); | |
| } | |
| } | |
| open IByteStream[socket_t]; | |
| // ----------------------------------------------------------------------------- | |
| proc handler (k:socket_t) () { | |
| match read_line k with | |
| | Error ?e => { } | |
| | Ok ?line => { } | |
| endmatch; | |
| }; | |
| var s: socket_t; | |
| spawn_fthread$ handler s; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment