These are chat archives for learnclang/general

1st
Jan 2015
Marcus Ottosson
@mottosso
Jan 01 2015 13:54
I started looking through the Coursera course on writing your own compiler, and it's pretty interesting. Lots of work involved, but it clear up a few questions from above, like what Front-end versus Back-end means and what the Linker versus Compiler actually does.
It says to take 11 weeks to complete, but the videos so far seem to be around 100 @ 15mins each, which together with my calculator comes to a grand total of 25 hours. That, together with actually writing and figuring stuff out should take no more than a week to muscle through. :)
And should prove a good experience.
Anyone in?
Cesar Saez
@csaez
Jan 01 2015 14:13
I'll take the course! It seems way too interesting to pass up :)
Marcus Ottosson
@mottosso
Jan 01 2015 14:14
Sweeet!
Marcus Ottosson
@mottosso
Jan 01 2015 14:25
How about we set a date to start on Monday, and we'll work through one chapter at a time?
There's about 18 chapters
about 30-60 mins of video each
Marcus Ottosson
@mottosso
Jan 01 2015 18:49

Having gone through a few more videos, and reached the first assignment, it looks as though we'd have to implement the language in either C++ or Java, both of which are a little out of my depth at the moment, so I'm thinking we should wait with this until a little further ahead.

The assignment is here:
https://class.coursera.org/compilers-2012-002/assignment/view?assignment_id=2

David Martinez
@davidmartinezanim
Jan 01 2015 19:09
I'd be in once we are more comfortable with the language
Cool, let's wait a little till we're ready. :)
Hey @davidmartinezanim Were you adding a section about MinGW to the Wiki?
I think we're almost ready to declare the first project complete soon
David Martinez
@davidmartinezanim
Jan 01 2015 19:15
I will between today and tomorrow
Marcus Ottosson
@mottosso
Jan 01 2015 19:15
Brilliant!
Marcus Ottosson
@mottosso
Jan 01 2015 19:23

Also found this: http://llvm.org/docs/tutorial/OCamlLangImpl1.html

Looks like there's plenty of resources to get going with writing a new language!

Added to Resources

Marcus Ottosson
@mottosso
Jan 01 2015 19:58

Does anyone know how to do some sort of introspection with C?

>>> import os
>>> print os
<module 'os' from '/usr/lib/python2.7/os.pyc'>

This, for example, prints the location of where a particular module is located at, can I do the same with C?

>>> help(os.path)
Help on module posixpath:

NAME
    posixpath - Common operations on Posix pathnames.

FILE
    /usr/lib/python2.7/posixpath.py
...

This prints a comment out of the module, can C do that?


Primarily, I'm interested in figuring out where functions come from, as they all appear in the global namespace. Such as:

#include <ctype.h>
for (i=0; isspace(s[i]); i++);

Is isspace coming from ctype.h or is it part of the language?

David Martinez
@davidmartinezanim
Jan 01 2015 20:06
http://www.tutorialspoint.com/c_standard_library/ctype_h.htm <-- This indicates that this is the case. Having said that, I can understand what you mean and it would be great to be able to do some introspection there. I thought the same thing a few days ago.
Marcus Ottosson
@mottosso
Jan 01 2015 20:07
Yeah, it's a simple example, the trouble arises when you've got many libraries imported.
David Martinez
@davidmartinezanim
Jan 01 2015 20:08
specially when looking at someone else's code
Marcus Ottosson
@mottosso
Jan 01 2015 20:08
Yeah
Are you still going with the C book?
I'm at page 55
David Martinez
@davidmartinezanim
Jan 01 2015 20:10
I am indeed. slowly
Marcus Ottosson
@mottosso
Jan 01 2015 20:13
How's it going though?
David Martinez
@davidmartinezanim
Jan 01 2015 20:16
it's going well so far. I learned a few things that I did not know about the command line as well. When I created the application that copies the contents of the input into the output. Then I played at changing the int values to do some crappy file that was not in english anymore and bring it back to an understandable file. Kinda like what we used to do as kids.
Marcus Ottosson
@mottosso
Jan 01 2015 20:17
Changing int values of a file? How do you mean?
David Martinez
@davidmartinezanim
Jan 01 2015 20:18
u know how it reads the input using getchar() and then putchar(), the value is read into an integer so I was changing it's value by adding a given number before calling putchar()
Marcus Ottosson
@mottosso
Jan 01 2015 20:18
aah yes
But yeah, about the passing of streams to C programs, that's really interesting
What was the syntax again?
$ a.out | myfile.txt
Or something?
David Martinez
@davidmartinezanim
Jan 01 2015 20:19
well, I was using windows so it was something like:
my_program < input >> output
Marcus Ottosson
@mottosso
Jan 01 2015 20:20
Hmm
David Martinez
@davidmartinezanim
Jan 01 2015 20:21
if you only add the output, you end up saving into a file everything you type. (if I remember correctly)
Marcus Ottosson
@mottosso
Jan 01 2015 20:22
Ah yeah, tried it out, you're right
Forget so fast. What's the | operator then?
David Martinez
@davidmartinezanim
Jan 01 2015 20:23
no idea
:-P
Marcus Ottosson
@mottosso
Jan 01 2015 20:23
marcus@ubuntu:~/github/kandr/builds$ ./1-21 | ~/spaces.txt 
bash: /home/marcus/spaces.txt: Permission denied
That was what I found fascinating
Because it means you can communicate between two processes, without any fancy tricks, just by printing to stdout
I guess in that case, it's from one to the other, and not the other way around. But I'm sure there must be a way for both of them to be able to pass data to each other
David Martinez
@davidmartinezanim
Jan 01 2015 20:25
I guess in that case, it's from one to the other, and not the other way around.
What do you mean?
Marcus Ottosson
@mottosso
Jan 01 2015 20:26

I mean

$ program1 | program2

Here, program2 passes it's results into program1

But there's no way of getting program2 to receive data from program1, if I understand it correctly
Also, I'm not sure whether it outputs asynchronously, or whether program2 has to finish before program1 can get anything..
David Martinez
@davidmartinezanim
Jan 01 2015 20:27
ah! I see what you mean. Well, When I did that, it was between text files
that is the program, getting a text file as input and printing output
Marcus Ottosson
@mottosso
Jan 01 2015 20:28
Yeah, I think < is especially made for files.
David Martinez
@davidmartinezanim
Jan 01 2015 20:28
and I believe it only happened when execution was finished
Marcus Ottosson
@mottosso
Jan 01 2015 20:39
Here we go: http://www.tldp.org/LDP/abs/html/io-redirection.html
< FILENAME
      # Accept input from a file.

|
      # Pipe.
      # General purpose process and command chaining tool.
David Martinez
@davidmartinezanim
Jan 01 2015 21:32
Ok, I added some info to the wiki in the form of a tutorial. I reckon we need to clean that up as right know it feels like there is duplicate information here and there. Also some of the content is placeholder. I will finish it up either later or tomorrow morning
Marcus Ottosson
@mottosso
Jan 01 2015 22:56
Looks like a good start, and looks like the tutorial layout works well for each compiler. Any compiler we're missing that might be of interest?
I suppose Visual Studio would be good to include, especially now that the professional version is free.
David Martinez
@davidmartinezanim
Jan 01 2015 23:32
Is it worth adding LLVM? I don't think it would be any different than MinGW, right?