<oprypin>
codic12, almost nothing can be done without the stdlib
<oprypin>
thats --prelude=empty
<FromGitter>
<codic12> as long as you can do simple math, that's all I need for a kernel (though I'll implement a basic stdlib later); thanks!
<oprypin>
well im not even sure that you can do simple math - thats the thing
<oprypin>
yea your 1+2 program doesnt work already
<oprypin>
though nothing that a little `fun __crystal_raise_overflow; end` cant fix
<oprypin>
@codic12, take note of `1 &+ 2` & operations dont check for overflow
<oprypin>
a program `1 &+ 2` does indeed build with `crystal build --prelude=empty hw.cr`
<FromGitter>
<codic12> I see, thanks
<FromGitter>
<codic12> `crystal build kernel.cr --cross-compile --target i386-elf --prelude=empty` produces both a binary and an .o file; I only need the latter. Can I tell it to only produce an object file?
<FromGitter>
<Blacksmoke16> try `--no-codegren`
<FromGitter>
<Blacksmoke16> nvm, that wouldnt produce anything
<oprypin>
codic12, i think it's not true that it produces a binary.
<FromGitter>
<codic12> I have both `kernel` and `kernel.o` in my current directory
<oprypin>
codic12, well delete `kernel` and then you won't
<FromGitter>
<codic12> That's true haha
<oprypin>
no but crystlal also won't produce it
<FromGitter>
<codic12> It does produce it
<oprypin>
🤔
<oprypin>
not for me
<FromGitter>
<codic12> Even prints out `cc hw.o -o hw -rdynamic ` when I compile
renich has quit [Remote host closed the connection]
zorp has quit [Ping timeout: 256 seconds]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 240 seconds]
<FromGitter>
<codic12> I have this fairly simple C code for a basic kernel: https://hatebin.com/hbizmnwhik. I tried porting it to Crystal here: https://hatebin.com/bfvmmbfzca; this compiles, but just gives me a blinking cursor. Something's probably wrong with my logic
<FromGitter>
<Blacksmoke16> You never call your main method?
<FromGitter>
<Blacksmoke16> Don't actually need it either
<FromGitter>
<codic12> No, the main method is called from some assembly code (unless Crystal mangles the names up, which could cause it)
<FromGitter>
<codic12> Eg in rust I had to #[no_mangle]
<FromGitter>
<codic12> if I `nm -gc` my .o file I do see a `main` symbol, along with a `__crystal_main`
<FromGitter>
<codic12> Feel free to mention
<z64>
@codic12 the "equivalent" to #[no_mangle] is `fun method(..)` instead of `def method(..)`
renich has joined #crystal-lang
renich has quit [Ping timeout: 256 seconds]
renich has joined #crystal-lang
sagax has quit [Remote host closed the connection]
<jhass>
you would do us a great favor by trying to reduce your code to an as minimal example as possible
<jhass>
(that still triggers this)
<FromGitter>
<Dan-Do> let me try :)
<jhass>
I usually start by trying to remove require's from the entry point, then inline them, then remove all dead (not called) code, and then it usually starts to get a bit more apparent where the issue is already
<jhass>
for now you should be able to workaround this by just making this a struct and doing somehting like struct Foo; INSTANCE = Foo.new; and using Foo::INSTANCE instead
<yxhuvud>
I'm fairly certain it shouldn't compile too (as @-variables is not allowed in class methods). But the compiler should of course not crash.
<jhass>
yeah, if you minimize it the wrong way it turns into a compilation error :)
<FromGitter>
<Dan-Do> > *<jhass>* for now you should be able to workaround this by just making this a struct and doing somehting like struct Foo; INSTANCE = Foo.new; and using Foo::INSTANCE instead ⏎ ⏎ Actually it's the shard https://github.com/fukaoi/crystal-nodejs ⏎ I tried to add some methods and class variables ⏎ This module spans on many files. Do I need to change all? [https://git
<FromGitter>
<Dan-Do> Sorry I am not an expert in crystal :(
<jhass>
ah well, it's probably not meant to hold state :/
<jhass>
you could try to see if using @@class_vars works for you
<jhass>
or better yet if you can't find a way to not hold global state
<FromGitter>
<Dan-Do> > *<jhass>* or better yet if you can't find a way to not hold global state ⏎ ⏎ Sadly, that's what I want :(
<jhass>
another approach could be to extract all the functionality in the class and keep the old API intact by just delegating to an instance of it assigned to a constant
<jhass>
with that last approach, the "global state" would just be the convenient API and users could even manually have multiple instances by using the class
<FromGitter>
<Dan-Do> Can you give me a reduced code?
<jhass>
this should roughly sketch what I'm thinking about
<FromGitter>
<Dan-Do> That looks great! ⏎ BTW, what do you think the best structure that shard should be? I want to learn and understand more :)
<jhass>
I don't know, I haven't really spent time looking at what it wants to do and thinking about it :)
<FromGitter>
<Dan-Do> Okay, thanks.
<jhass>
but yeah, probably go away from the very procedural code it is right now and think about an OO design, Crystal is an OO language after all :)
<FromGitter>
<Dan-Do> Yeah, I will re-write the shard completely :) ⏎ not much files and codes
zorp has joined #crystal-lang
<riffraff169>
more like a singleton?
<riffraff169>
im having to rethink some of what im doing too...i mostly work in imperative languages, with some functional constructs thrown in...even the oo languages i use, i dont use many oo constructs as such....different way of thinking
<riffraff169>
writing a sort of compiler, and when i would create a global struct to hold state, now i create an object...
<jhass>
the big selling point of OO is that it allows you to group your state and the functionality that's depending on it close together, then compose the bigger task solution together from those units. Each composition should know less about how some unit even achieves what it does and what state it needs for that. If you're having some global state object passed around everywhere, you're pretty
<jhass>
much defeating the point, yeah :)
<FromGitter>
<Blacksmoke16> DI ftw 😉
<riffraff169>
unfortunately, ive never written a compiler in an oo language, so my work has kind of stalled until i figure out some code architecture (in between life)
<riffraff169>
im having to pass state around to, as mentioned...lexer passing lexemes to parser, which tokenizes and creates the list of tokens, which is then....more stuff...anyway
<FromGitter>
<Dan-Do> :D
<riffraff169>
its also been 15 years since i did any compiler design, so im rusty
<FromGitter>
<Dan-Do> What is the proper way to interactive with cli process (created in crystal)?
<FromGitter>
<Dan-Do> For example, when I run "node" in the terminal
<FromGitter>
<Blacksmoke16> its already empty because it was consumed entirely in the last line
<jhass>
well, #wait waits for the process to quit, do you expect that to happen actually?
<FromGitter>
<j8r> p `@output_io.gets_to_end`
<jhass>
also maybe it just dies with an error, don't forget to check the error output too
<FromGitter>
<Dan-Do> > *<jhass>* well, #wait waits for the process to quit, do you expect that to happen actually? ⏎ ⏎ Nope, I will change the code
<FromGitter>
<Dan-Do> > *<jhass>* well, #wait waits for the process to quit, do you expect that to happen actually? ⏎ ⏎ I think it will not quit because it's cli. Only with if I press CTRL+C
<jhass>
Dan-Do: using this https://p.jhass.eu/8v.txt I don't get any output until the input pipe is closed. I think node does some kind of pty detection and in fact not enter the REPL loop mode when spawned like this
<FromGitter>
<Dan-Do> wow, it works!
<FromGitter>
<Dan-Do> Does it mean that I cannot start node process like this?
<jhass>
In my example, you need to notice two things: First of all the output is not interleaved, first crystal, then node. Second, there's a three second delay between the crystal and the node output
<jhass>
you can make that a 6 second delay by adding another sleep 3 right before the close
<jhass>
these observations are what should generate the learnings from this example, namely that node does not seem to enter REPL mode unless it detects the other end to be a tty/pty
<FromGitter>
<Dan-Do> Oh no, it's a web app. It cannot sleep any seconds
<jhass>
you still didn't get it
<jhass>
meanwhile I looked at node -h and noticed the -i flag. Modifying the example (https://p.jhass.eu/8w.txt) we get the behavior we expect from running in REPL mode
<FromGitter>
<Dan-Do> I changed your code at this point:
<FromGitter>
<Dan-Do> There are differences between Process.new and Process.run
<jhass>
.run is largely just new; yield; wait
<FromGitter>
<Dan-Do> BTW, it's really magic about sleep. It does not sleep at all :)
<jhass>
the sleep is there for demonstrative purposes, not functional ones
<jhass>
the whole example was trying to demonstrate you something, not solve what you want to do any way
<jhass>
and I have no clue what you're talking about, the sleep makes it indeed sleep for three seconds where you would expect
<FromGitter>
<codic12> well if I do use `fun` instead of `def`, I can't use `String`; in C, since I had `char*`, I assume the equivalent would be `LibC::Char*`, but this is undefined (note that I'm building this with no prelude)
<jhass>
UInt8* :)
<FromGitter>
<codic12> For some reason that message doubled, thanks!