sq / JSIL

CIL to Javascript Compiler
http://jsil.org/
Other
1.73k stars 241 forks source link

Error: The external method 'System.Int32 Peek()' of type 'System.IO.TextReader' has not been implemented. #593

Open DrMiaow opened 10 years ago

DrMiaow commented 10 years ago

Error while parsing the .twee file.

I'm assuming I need to implement this following the instructions here?

https://github.com/sq/JSIL/wiki/Troubleshooting-FAQ

Error: The external method 'System.Int32 Peek()' of type 'System.IO.TextReader' has not been implemented.
    at ExternalMemberStub.getError (http://localhost.thumbwhere.com/Libraries/JSIL.Core.js:1251:16)
    at Object.ExternalMemberStub (http://localhost.thumbwhere.com/Libraries/JSIL.Core.js:1257:19)
    at Object.ExternalMemberStub (http://localhost.thumbwhere.com/Libraries/JSIL.Core.js:1234:39)
    at Object.Parser_Peek (http://localhost.thumbwhere.com/game/My64k.Twine.Implementation,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:15053:19)
    at Object.Parser_Story (http://localhost.thumbwhere.com/game/My64k.Twine.Implementation,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:15071:17)
    at InterfaceMethod_CallInterface_I985$Story$961$eq986 [as Call] (jsil://closure/InterfaceMethod.CallInterface_I985$Story$961=986:5:47)
    at Object.Player_Load (http://localhost.thumbwhere.com/game/My64K.HexTheGame.Core,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:29416:28)
    at Object.CommandTutorialLoad_File_Execute (http://localhost.thumbwhere.com/game/My64K.HexTheGame.Core,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:47415:39)
    at InterfaceMethod_CallInterface_I378$Execute$393$cm14$lb13$rb$eq11 [as Call] (jsil://closure/InterfaceMethod.CallInterface_I378$Execute$393,14[13]=11:5:55)
    at Object.CommandScriptInterpreter_ExecuteScript (http://localhost.thumbwhere.com/game/My64K.HexTheGame.Core,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:42289:24)
    at ExternalMemberStub.getError (http://localhost.thumbwhere.com/Libraries/JSIL.Core.js:1251:16)
    at Object.ExternalMemberStub (http://localhost.thumbwhere.com/Libraries/JSIL.Core.js:1257:19)
    at Object.ExternalMemberStub (http://localhost.thumbwhere.com/Libraries/JSIL.Core.js:1234:39)
    at Object.Parser_Peek (http://localhost.thumbwhere.com/game/My64k.Twine.Implementation,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:15053:19)
    at Object.Parser_Story (http://localhost.thumbwhere.com/game/My64k.Twine.Implementation,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:15072:126)
    at InterfaceMethod_CallInterface_I985$Story$961$eq986 [as Call] (jsil://closure/InterfaceMethod.CallInterface_I985$Story$961=986:5:47)
    at Object.Player_Load (http://localhost.thumbwhere.com/game/My64K.HexTheGame.Core,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:29416:28)
    at Object.CommandTutorialLoad_File_Execute (http://localhost.thumbwhere.com/game/My64K.HexTheGame.Core,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:47415:39)
    at InterfaceMethod_CallInterface_I378$Execute$393$cm14$lb13$rb$eq11 [as Call] (jsil://closure/InterfaceMethod.CallInterface_I378$Execute$393,14[13]=11:5:55)
    at Object.CommandScriptInterpreter_ExecuteScript (http://localhost.thumbwhere.com/game/My64K.HexTheGame.Core,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:42289:24) JSIL.Browser.js:199
Uncaught System.Exception: Don't know what to do with line starting with '' My64k.Twine.Implementation,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null.js:15072
kg commented 10 years ago

Yeah, looks like Peek isn't implemented on Stream or any of the related classes in the bootstrap library.

kg commented 10 years ago

(IMO, for text parsing, just load the whole file as a string unless it's enormous. Peek/short reads are pretty expensive/slow)

DrMiaow commented 10 years ago

Some of the stories are heading towards several megabytes of text (Liz is prolific) and the core parser uses SteamReader for design reasons.

I could swap for StringReader to change the granularity of the IO but it sounds like that won't have Peek either?

I'll build a StringStreamReader based on StreamReader which will have the minimal impact.

kg commented 10 years ago

Actually, checking again ReadLine just reads one character a time since that's how StreamReader works, so I guess it doesn't matter. :-)

FYI, Streams appear to already have a '$PeekByte' method, they just don't have Peek. I think I did that because Peek's semantics are incredibly gross and I didn't feel like implementing them. You can probably implement Peek on top of $PeekByte.

On Fri, Aug 1, 2014 at 6:53 PM, DrMiaow notifications@github.com wrote:

Some of the stories are heading towards several megabytes of text (Liz is prolific) and the core parser uses SteamReader for design reasons.

I could swap for StringReader to change the granularity of the IO but it sounds like that won't have Peek either?

I'll build a StringStreamReader based on StreamReader which will have the minimal impact.

— Reply to this email directly or view it on GitHub https://github.com/sq/JSIL/issues/593#issuecomment-50950901.

DrMiaow commented 10 years ago

Another Saturday morning, another hacking session :)

Managed to progress parsing (still testing) by adding these two to System.IO.StreamReader in JSIL.IO.js

  $.Method({Static:false, Public:true }, "Peek", 
    (new JSIL.MethodSignature($.Int32, [], [])), 
    function Peek () {
      var peeked = this.stream.$PeekByte();
      if (peeked === -1)
        return peeked;

      var position = this.stream.Position;
      var ch = $jsilio.ReadCharFromStream(this.stream, this.encoding);
      this.stream.Position = position;

      if (ch)
        return ch.charCodeAt(0);
      else
        return -1;
    }
  );

  $.Method({Static:false, Public:true }, "Read", 
    (new JSIL.MethodSignature($.Int32, [], [])), 
    function Read () {
      var ch = $jsilio.ReadCharFromStream(this.stream, this.encoding);  
      if (ch)
        return ch.charCodeAt(0);
      else
        return -1;
    }
  );
DrMiaow commented 10 years ago

Looks good. Looking at the logs I have managed to parse the entire file, it's the interpreter now that seems to be falling over somewhere with a weird error.

This one at least seems to be resolved :)

kg commented 10 years ago

Cool, if you don't mind, submit a PR for Peek and Read and I'll merge them. An automated test wouldn't hurt but I can probably write that myself.

DrMiaow commented 10 years ago

Will do.

JamesMcParlane commented 10 years ago

I'm in the middle of moving house. Got as far as making a branch but then everything went into a truck. Should have my lab back up and running in a few days.