/dpt/ - Daily Programming Thread

youtube.com/watch?v=j2vTStG6Yys

There is nothing wrong with frogposting edition

Previous thread: What are you working on, Sup Forums?

Other urls found in this thread:

llvm.org/docs/WritingAnLLVMBackend.html
llvm.org/docs/LangRef.html
llvm.org/docs/CodeGenerator.html
llvm.org/docs/TableGen/index.html
llvm.org/docs/WritingAnLLVMPass.html
compilers.iecc.com/crenshaw/
haskellbook.com
github.com/bitemyapp/learnhaskell
wiki.c2.com//?FirstClass
c9x.me/compile/
twitter.com/SFWRedditVideos

How do i make a makefile that compiles sources from src dir to objs dir and links those to a file in $(TARGET) dir?

First for shotas

C++ is for substandard programmers (aka C rejects)

LLVM backend has FAR too much required reading.
I don't want to write a C or C++ compiler.
What is the easiest way to get C and C++ code compiled to a custom architecture?

GCC is worse, writing your own is worse.
Just git gud.

>Just git gud.
At what?
Using LLVM? Writing my own compiler?

At RTFM

Way too long.

use something like cmake if you can

Working on parsing using boost::spirit.

Then just give up now, if you're that lazy you're going to give up eventually.

>POOst

Where can I learn C++? I know all the basics and principles of C and know Java and C# along with some obscure languages.

Which resource should I use to learn c++? Any meme website or do I have to read a 500 page book?

No, that much required reading just to make a backend is very unreasonable.
The interface really should not be that complicated.

>LLVM backend has FAR too much required reading
I'm afraid programming isn't the right thing for you.

>Compilers should not be complicated
Well sweetie, feel free to fork TCC and see how many thousand times slower it is.

cancer

>custom architecture
>expecting to get spoonfed
just read the things you fag

>The interface really should not be that complicated.
It really isn't, I'm afraid you have some misconception about what's happening in a compiler's middle and back-ends.

Well written C++ is merely C with RAII and maybe templates or move semantics.

The compilation is much faster.

Make is cancer, cmake is chemo. It hurts and the syntax is literally poison, but it'll save you in the long run.

if gnu make is any less of a cancer then do you know the answer to

>Where can I learn C++?
In garbage containers

That's just stating the obvious.

I struggled with this question for a long time.

Honestly, I think reading 500 pages out of Stroustrup's 1300 page book and keeping it around for reference is really the best option.

user stop twisting her words. Clearly she's saying the interface to llvm shouldn't be that complicated and I agree.
I think the problem is that the person who wrote the required reading list is expecting a dedicated person to get into it. While user is expecting a tutorial of sorts because she's doing it for fun.

>the interface to llvm shouldn't be that complicated
Yeah I agree! You should just be able to type
llvm::MakeCompiler(this->magic);

Yeah that's the common use.
It's a garbage environment to be in. But it's the realistic use.

llvm.org/docs/WritingAnLLVMBackend.html
llvm.org/docs/LangRef.html
llvm.org/docs/CodeGenerator.html
llvm.org/docs/TableGen/index.html
llvm.org/docs/WritingAnLLVMPass.html

And take note of the size of each page.
Sorry, but that's way too unreasonable. LLVM is a bloated piece of shit, I don't have time to waste on this. I want to work on my VM and write an operating system for it.

At this point I will be spending waaaaay more time writing a fucking backend than actually implementing the VM and OS.

>reading 500 pages out of Stroustrup's 1300 page book
Typical C++ "programmers"

>a tutorial of sorts because she's doing it for fun
There literally is a tutorial about using LLVM. The guy is just illiterate. Which only furthers my opinion that programming isn't made for him.

Maybe this'll give you some inspiration compilers.iecc.com/crenshaw/

Did you just assume my fucking gender?

>I want to work on my VM and write an operating system for it
>At this point I will be spending waaaaay more time writing a fucking backend than actually implementing the VM and OS
Well you just have no clue.

Then you clearly don't agree with me user. That's ludicrous. How can you even imagine an interface like that? Where did you even convert your AST to their expected format?
Stop being such a useless programmer. Go play with Javascript, Scratch or something.

News flash dipshit, you need a C compiler for your incredibly awfully designed CPU architecture and buggy as shit operating system to be anything more than a waste of time.

>I don't have time to waste on this
then why are you using a custom architecture and making a VM and an OS this is like the biggest time sink you could possibly have

Challenge:

Implement the fibonacci sequence with the tree recursive solution but avoid exponential time and ensure it's total for all terms.

Haskell, Agda, and idris may NOT be used for this... bonus points if you can say why they are banned from this challenge.

Test cases:
fib(10);
fib(100);
fib(50);
fib(1);


Good luck

No, just your normal gender.

We don't accept male programmers here. So yes.

So you're the one who's too lazy to understand modern compilers and their requirements and I, as the one who can actually use LLVM, am useless.

Just do what I did: Don't use C, make a small lisp instead.

Do your own homework

>can use llvm
Clearly you can't if you think that's what the interface should be. It's just a terrible api with no flexibility. It's useless.

Any good books on functional programming? I'm learning Erlang/Elixir. Seems easy enough to work with, but I'm having trouble approaching problems from a functional perspective.

I know that, fucking idiot.
My original question was what is the easiest way to get a C compiler to target my architecture, because I'm not interested in the compiler side of things.

Because I want to design and implement my own architecture and platform, and write an OS for it. I like low level programming, It's fun, I've written a few VM's before.
I just hate compilers.

I am thinking about making my own C-like language designed for my architecture (don't want to read the C and especially not the C++ standard), since it would be easier to parse and generate code for.
Maybe I should, It would probably take less time than dealing with LLVM, and would teach me some new things.

>generate_single_cell_regression_training_input

haskellbook.com
github.com/bitemyapp/learnhaskell

>i don't want to write a compiler but i need a compiler guis
write a compiler you fucking mongoloid

>So you're the one who's too lazy to understand modern compilers and their requirements
The guy you are responding to is not me

Parsing and making a lisp in general is much easier and you will have a more standard (implementing the R7RS is piss-easy) and flexible language, this is why I suggest it.
While making a C is possible, and quite easy if you use something like bison, it will not be quite lacking while still more difficult to implement.

It's not homework, I teach programming so thought I would see how "good" Sup Forums actually can be as so far it's mostly fizzbuzz.

Post your sock to leg ratio

I've never used lisp and not interested in using it. I like C syntax, I like the imperative/procedural way of doing things.
No thanks.

"I want to do [x] big thing, but I don't want to put in the proportional work required to achieve [x]"
Maybe you should hire someone.

Homosex faggot

Look at the suckless c compiler it's under 10kloc C.
Or just steal someones hobby C compiler that's written in some nicer language and modify it for your platform. There's really no need to write the compiler in c.

teach me daddy

C isn't a shit language.
C programmers are shit, though.
Seriously, guys, brace abstractions. There's no fucking point to implement your own shit for the 1000th time. Well documented black boxes is the fucking point of programming.

Back to ribbit

>avoiding bad abstractions
Not the same thing as
>implementing your own shit over and over
You write it once. You control it. You can copy it all over.
Since you control it you can make changes to it. You make your own perfect api to the system. And you've actually abstracted constructively. Unlike people who #include

Thanks, I'm going to give this a go.

>suckless
Last time I looked at the source code of one of their programs (st I think), I nearly vomited, no thanks.

I don't really want to steal someone elses project either.
It's either a backend to an existing compiler framework, or just simply design my own simple language and write a compiler for that.
I think I'm going to go with the latter.

Most C libraries are way too opinionated, they are either not maintained or fucking huge.

Because you're such an amazing programmer that your implementation is proven to be more efficient, more bug free, and more generic than something that's tested against literally millions of codebases.

>than something that's tested against literally millions of codebases.
>thinking that most libraries are tested
Also when it comes to C most libraries are just for platforms that support POSIX. I try to write portable software

Poor library support for a particular platform is a legit reason to roll your own, and that goes for any language.
But that is not C-culture.

Found the guy who rolls his own linked list implementation

The Plan 9 C compilers are very easy to retarget. Until very recently, the Go project used and maintained them. Maybe they still do -- sniff around the source code.

Also, lcc (literally called "a retargetable C compiler") and tcc.

I'm not afraid to it's just that it's a big topic.
>Java is what most would call oop today.
I suggest reading this site a little
wiki.c2.com//?FirstClass

I don't know if Java has first class objects or not because I haven't used it. I know C++ doesn't though. It should give you a good idea of the situation though.

Stop using GLib.

>In ObjectOriented languages such as CeePlusPlus, objects are FirstClass
Your own sources seem to disagree with what you're saying.

>more generic
That's a problem though. Solutions that aren't specialized are potentially more inefficient, difficult to use or error prone than a specialized solution.
If you write code well you find a middle ground and then specialize a little for a specific use case.
I practically never use linked lists. They're almost useless. It's fairly impressive how rarely they fit a situation.

And to both of you. If you don't have any requirements on you don't bother replying. What's the point in arguing with you if you don't need anything and are free to write code that's as inefficient as you like? C programmers have requirements. Of course it's not the best language for programming on hypothetical machines running in the ether. Mathematics is the best language for those.

Getting really tired of the repetitive strain of pressing shift, especially when working with camel case.

Is there any ease of access feature that will, if you hold down a key for X milliseconds, replace the character you're typing with its shifted counterpart? Am I just going to have to resort to autohotkey?

A hashmap is always going to look the same no matter what types you put in it. The only differences are the hash and comparator functions.
sepples templates are perfectly suited for such data structures.

In fact I guess I'll try remapping the held-down-for-X-milliseconds space bar to shift.

Sepples templates aren't perfectly suited for anything.

Languages vary as to what isFirstClass. Some, such as theCeeLanguagehave only basic types (ints, pointers; in particular, arrays are not trulyFirstClassthough the array/pointer equivalence lets you fake it in most situations). InObjectOrientedlanguages such asCeePlusPlus, objects areFirstClassbut classes are not, while inSmalltalkLanguageorRubyLanguage, for example, all references including references to class objects areFirstClass. InFunctionalProgramming, functions areFirstClass.
--end quote
I can't be expected to argue with someone who can't even read.

> Solutions that aren't specialized are potentially more inefficient, difficult to use or error prone
Potentially inefficient, sure. Keyword here is potentially. Examine the performance characteristics and see if it's 1) sensible, and 2) meets your requirements.
But more difficult to use and error prone than rolling your own? Ehhhh.
>If you don't have any requirements on you don't bother replying. What's the point in arguing with you if you don't need anything and are free to write code that's as inefficient as you like? C programmers have requirements.
Sure, if you have requirements a library isn't meeting, go for it. But C culture seems to be roll their own regardless of requirements, eventually gathering up a huge personal library of buggy, largely untested, half-implemented algorithms and data structures.

>InObjectOrientedlanguages such asCeePlusPlus, objects areFirstClassbut classes are not

>They have the double indirection right there and they could give us first class objects. They explicitly went against that for some reason

C++ has first class objects. You said they didn't, your sources say they do.
I'll give you the benefit of the doubt and assume you meant to write first class classes the first time.

No. Obviously not. Sometimes you want to pair the keys and the values. Sometimes you want to store an array of the keys and separately allocate the values. Sometimes you want them to use reference counting on the values and have a way to invalidate the keys.
There's tons of variations.

Templates can do anything. They're not well suited for this case. Even if you just wanted to alter the types they're a very messy way to write that compared to writing functions where the syntax let's you specify compile time determined type with say a character.

I don't see who could think templates are perfect if they're not the most unimaginable programmer ever.

A lot of that could be achieved with wrapper functions/classes.

what joy

examples

I see the confusion. But first class objects is a general way of expressing first class-ness. You can say a function in functional programming is a first class function. Or you can say it's a first class object. It's not an object in the OOP sense though.
You'll find it all over. I suppose I should have said first class classes for greater clarity.

>let's hack our general implementation to work well for our use case
Do you not think there's perhaps a better way to do this?

When you need specialization, use specialization.

h = h*33 ^ c;

Which hash function is this?

Use qbe
c9x.me/compile/

>C++ has first class objects.
no

It doesn't? Really?

>steal
kys

I need specialization a lot. Most applications do.
It's just that this Kind of thinking obscures the fact. Tons of simple applications become complicated this way.

isn't that k&r

unsigned int fib(unsigned int n) {
return fib_(n, 0, 1);
}

unsigned int fib_(unsigned int n, unsigned int a, unsigned int b) {
if(n < 1) return a;
else return fib_(n - 1, a + b, a);
}

Because instead of writing only a few LOC to get the behavior I want on top of well-tested underlying implementations is inferior to writing multitudes more code when 80% of it ends up being doing the same exact thing.

And the stack blew up

Basically you're saying that when you write specialized code you do it unnecessarily.
That's not very smart user.

implementation defined.

At fib(100)?
Weak ass system.

wat

look what I found