I3oris / ic

REPL Interface wrapping Crystal Interpreter (crystal-i).
MIT License
48 stars 2 forks source link

Error loading library (I think) #5

Closed Vici37 closed 2 years ago

Vici37 commented 2 years ago

Not sure if the error is part of crystal's interpreter itself, or ic's own changes in crystal-ic (are there any differences in there?). Anywho, when trying ic against my largest non-trivial project, I get this error:

Invalid option: -v (OptionParser::InvalidOption)
  from lib/ic/share/crystal-ic/src/option_parser.cr:128:45 in '->'
  from lib/ic/share/crystal-ic/src/option_parser.cr:494:27 in 'parse'
  from lib/ic/share/crystal-ic/src/option_parser.cr:116:5 in 'parse'
  from lib/ic/share/crystal-ic/src/compiler/crystal/interpreter/context.cr:369:1 in 'loader'
  from lib/ic/share/crystal-ic/src/compiler/crystal/interpreter/context.cr:382:5 in 'c_function'
  from lib/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1883:17 in 'compile_lib_call'
  from lib/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1764:7 in 'visit'
  from lib/ic/share/crystal-ic/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from lib/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:3000:5 in 'accept_with_wants_value'
[snipped]

The stacktrace is considerably larger, but the above bit should contain the relevant parts. Putting in some custom puts statements help show what it's tripping up on. The name param passed to c_function is getcwd, and the args that are being parsed and failing utterly are:

name # => "getcwd"                                                                                                                                                                                                                            
args # => ["-lyaml",                                                                                                                                                                                                                          
 "-lgmp",                                                                                                                                                                                                                                     
 "-lz",                                                                                                                                                                                                                                       
 "`command",                                                                                                                                                                                                                                  
 "-v",                                                                                                                                                                                                                                        
 "pkg-config",                                                                                                                                                                                                                                
 ">",                                                                                                                                                                                                                                         
 "/dev/null",                                                                                                                                                                                                                                 
 "&&",                                                                                                                                                                                                                                        
 "pkg-config",                                                                                                                                                                                                                                
 "--libs",                                                                                                                                                                                                                                    
 "--silence-errors",                                                                                                                                                                                                                          
 "libssl",                                                                                                                                                                                                                                    
 "||",                                                                                                                                                                                                                                        
 "printf",                                                                                                                                                                                                                                    
 "%s",                                                                                                                                                                                                                                        
 "-lssl -lcrypto`",                                                                                                                                                                                                                           
 "`command",                                                                                                                                                                                                                                  
 "-v",                                                                                                                                                                                                                                        
 "pkg-config",                                                                                                                                                                                                                                
 ">",                                                                                                                                                                                                                                         
 "/dev/null",                                                                                                                                                                                                                                 
 "&&",                                                                                                                                                                                                                                        
 "pkg-config",                                                                                                                                                                                                                                
 "--libs",                                                                                                                                                                                                                                    
 "--silence-errors",
 "libcrypto",
 "||",
 "printf",
 "%s",
 "-lcrypto`",
 "-lpcre",
 "-levent"]

Not entirely sure where to go from here from a debugging perspective. Let me know if you have any ideas of where I can search next, I'm not afraid to get my hands dirty when I have time :)

I3oris commented 2 years ago

Hello, Unfortunately, running a large project is a bit tricky for the interpreter now. I get the same error running IC on itself. When I try running IC with crystal-i directly, I get also the same error. It seem so be related to the interpreter (crystal-ic is the direct copy of https://github.com/crystal-lang/crystal/archive/refs/tags/1.4.1.zip unless I merged the fix for #4).

If fact, I found this issue, merging it would work I think! However I don't guarantee you it will works after that. (some language feature aren't yet implemented Crystal::Splat (when not inline by the parser), etc.)

What I could recommend you is to extract some small algorithm you what to debug (when possible) and to run it with IC on a separate file.

I3oris commented 2 years ago

I merged the fix here!

Vici37 commented 2 years ago

Wahoo! Verified that error has gone away!

I'm now running into a new one, but it looks related to one of my shards that I might be able to verify outside of my large project. I'll create a new issue if I can't track it down (or just try it with crystal i and create an issue on the compiler itself instead).