Introducing... Z™

Ok. Time to present a true, non-shitty language. I've called it Z, because it's literally the last language you will ever need.
Syntax
Because novel syntaxes lead to meme write-only languages such as Rust or Haskell, Z is 99% C-like syntax, meaning you can understand and even modify programs written in it without having learned it.
Readability is a must, so special characters are kept to a minimum.
The aim of the language is to truly replace C while at the same time extending its scope and adapting it to $CURRENT_YEAR computing.
function main(int argc, string[] argv) => (int){ /* This is a comment! */ int age; string name; io.write(stdout, "Hello, world!\n"); io.write(stdout, "What is your name?\n"); name = io.read_line(stdin); io.write(stdout, "How old are you?\n"); age = io.read_integer(stdin); io.write(stdout, format("Okay, %s, ", name)); if (age < 18) { io.write(stdout, "you are underage b&\n"); } else { io.write(stdout, "you are a mature adult!\n"); } return 0;}
Easy to understand, right?

string name;
io.write(stdout, "Hello, world!\n");
io.write(stdout, "What is your name?\n");
name = io.read_line(stdin);
io.write(stdout, "How old are you?\n");
age = io.read_integer(stdin);
io.write(stdout, format("Okay, %s, ", name));
if (age < 18) {
io.write(stdout, "you are underage b&\n");
} else {
io.write(stdout, "you are a mature adult!\n");
}
return 0;
}
[/code]
Easy to understand, right?

Other urls found in this thread:

llvm.org/docs/tutorial/
gitbook.com/book/landersbenjamin/llvm-implementing-a-language/details
twitter.com/SFWRedditGifs

Type system
Strongly typed, all conversions have to be explicit, otherwise it's a compiler error. Basic portable types are:
* byte -- Defined as an integer which is equal to the byte size of the target machine and at least 8 bits.
* char -- Defined as an 8-bits integer. It is the only type to which you can assign characters, and the only one to accept them.
* int -- 32 bits minimum signed integer
* long -- 64 bits minimum signed integer
* float -- IEEE 754 single precision floating point number
* double -- IEEE 754 double precision floating point number
* errno_t -- Holds a POSIX error value
For situations where a bit width has to be defined, basic fixed types are available, based largely on C99 types:
* int8, int16, int32, in64, int128, uint8, uint16, uint32, uint64, uint128
* float32, float64
* hword, word, dword -- integers which depend on the word length of the targeted architecture
* size_t, off_t, ssize_t, clock_t -- equivalent to their C counterparts
Because we can't reinvent the wheel every time, the following compound types (built-in structs) are available:
* string -- consists of a char array and a size_t length. No more
* time_t -- equivalent to its C and Python counterparts, used to work with calendars and such
* socket_t -- time to have proper network support
* file -- does it need an explanation?
* error_t -- we will see more on this later

To work with the size of each variable, the C operator sizeof() is made available.

Up until here, everything is pretty standard, it's pretty much just C. The fun comes next.

is it memory safe?
does it have generics?
is the compiler free software?
is it a meme lang? (rhetorical question)

Functions
Function-level polymorphism is available, and name mangling is defined by the standard (unlike with C++). This means no shit _Generic
as introduced by C11.
The following functions are different:
function foo(int a) => (void);function foo(float a) => (void);function foo(string a, int b) => (void);
Nothing spectacular, is there? HOL' UP. Return type is also taken into account for polymorphism. The following is perfectly legal:
function parse(string s) => (float);function parse(string s) => (int);function parse(string s) => (time_t);
How do we know when to call one or the other function? This can be inferred at compile-time, of course, and it comes at no
cost since the language is strongly typed.
Pretty cool, isn't it? But HOL' UP. HOL'. UP. There's more! Functions can also return several values.
function convert_coords(int x, int y) => (float, float){ return (float)x * 5., (float)y / 5.;}
Okay, so this gives us a pretty flexible function system. But, does this mean we will end up with a code full of shit like this?
x, error = foo();if (error) { return 0, ERROR;}y, error = bar();if (error) { return -1, ERROR;}
No! In Z, there is a difference between a function that returns a valid result, and one that fails. How so?

No! In Z, there is a difference between a function that returns a valid result, and one that fails. How so?
Introducing... the keyword "fail", and the global variable "err".
function my_sqrt(float x) => (float){ if (x < 0) { fail; } else { return sqrt(x); }}function connect_to_server(void) => (socket_t){ socket_t buttnut = io.socket("google.com", 443); if (err) { log(ERROR, "Could not open connection to server."); fail; } else { return buttnut; }}
The fail; statement is equivalent to a standard return, except it has some more features: it sets the global 'err' value to a valid error value,
and all return values are set to 0/NULL.
At the beginning of every function, 'err' is set to a value meaning "No error has happened."
Okay, okay, okay. Stop right here. A global variable? And what is its type? Won't it also cause a large overhead?
Worry not! It is a global variable, but a per-thread one. This means no concurrency problems! As for the type, it is an error_t variable.
It contains the following fields: errno_t errno, and string errmsg. The errno field hold a value as defined by errno (3),
while the errmsg is a user defined string. By default, with a standard fail instruction, errno is set to EGENERIC, an extension to the
POSIX errors which Z defines as meaning any error. The following syntaxes for the fail; statement are also available:

LOL

fail EIO, "Error writing to file."; fail "Received a negative value"; fail format("Person '%s' is not in database", person_name);
While, on failure, errno is always guaranteed to have a non-0 value, errmsg is optional and its value by default is an empty string.
If you do not want the overhead of setting the global 'err' value and need maximum speed, it is possible to define your functions as
"nofail". Inside these functions, it is not possible to access err, and as such the fail; statement is forbidden:
nofail function swap(int a, int b) => (int, int);

Pointers
Pointers are a mix between C pointers and C++ references. They can be NULL, but you do not use the ampersand operator to get their value.
The conversion between a type and its pointer is one of the only implicit ones found in Z:
int a = 5;int* b = a;
Here, b is equal to the address of a. Implicit conversion between an integer and a pointer is forbidden anyway, so there is no ambiguity there.
Of course, as with C pointers, their usecase lies mostly with passing structures to functions.
In the example above, the value of b is accessed, as in C, with the unary operator *, and with structures, as with C, the operator -> is
used to access subfields.
Explicit conversion between pointers and integers can be achieved with the use of operators addr_of() and as_addr(). The compiler
will issue a warning if the integer type is too small to contain a pointer for the targeted architecture.
Because the implicit conversion between integers and pointers is forbidden, it is not possible to set a pointer to "0". Instead,
it must be set to the keyword value null. It is not possible either to give it a constant value. This must be done via as_addr().

Memory allocation
The new() and delete() operators are made available. Logic-wise, they act as functions. new() can accept one or two arguments. The
first one is a data type, and the second one is the amount of elements to be allocated. Memory is unitialized.
delete() accepts a single argument, a pointer to any data structure. The pointer given is also set to 'null'.
Note that trying to delete() stack-allocated data will result in a program crash, as it is basically an equivalent to C's free().

More features which I will post later:
* inline asm using built-in asm() function
* GUI and 2D graphics as part of the standard library (as C++20 might get)
* structures and packed structures
* modules
* functions as data types, function pointers
* regex, socket modules as part of the standard library
* complete and sane string handling module (split(), search(), concat(), etc.)
* generic containers as part of the standard library
- Maps, queues, stacks, etc.
* Database registries and persistence as built-in features (probably with compiler switches)
* Built-in thread management and parallelism (akin to openmp)
* Cryptographic and hash functions as part of the standard library
* Because of all the previous features to be included in the standard library, a division of it into two parts: a "core" part, to
be used in systems programming, and an "extended" part, to use in more general programs.

No.
Yes.
Yes, under GPLv4, which will be written specifically for Z
Where do you think you are?


Keep reading, kid.

funtion overloading was a mistake

consider this example:
you have funtion foo which returns an int.
you write foo(); somewhere, you dont care about the return value. later you declare another foo function that returns a void. now you have to change every instance where you call foo and specify that you want the function that returns an int and not void.

But that is forbidden, user!
Either the function returns a status code, in which case you just use the 'err' global variable, or the function returns a result which you have to care about or else you wouldn't call it in the first place.

so even if you dont care about the return value you _have_ to write int kys = foo();
LOL

What is that function with a result you should not care about, again?

a map that returns the old value on insertion if a value for the specified key already exists

Assuming you're referring to C++'s map::insert(), f you use such a function instead of the [] operator, then you do care about the return value.

Where is the compiler?

im not referring to anything. i was just giving you an example. anyway your meme language is shit that no one wants nor needs. what you are proposing is basically a slightly less shit c.
there already exists a better c and it is called d

LARP alert

LARP alert

are you retarded???????????

I know this isn't an education thread for plebs like me, but I wonder: how do you create a compiler for a language you invent?

I went as far as reading that you need to modify LLVM/Clang but didn't dare go deeper.

Can be disabled with compiler switch --bare-metal

Not him, and im only learning C so maybe theres something wrong, but Ive had functions with returns I sometimes care about and sometimes might not in the K&R exercises.
say, a function to read a line(I know getline, its an exercise) that returns the length of the line read(even if larger than the buffer) and assigns only as much of it as it can into the buffer
what if I really dont give half a shit about how long the line is though?
What if I Just want to get one line and then print it, and then not do anything with its length?

have you tried using a search engine?
llvm.org/docs/tutorial/
gitbook.com/book/landersbenjamin/llvm-implementing-a-language/details
btw you forgot to sage


dont start with c. it is an awfully designed language. also avoid any languages inspired by c. learn a functional language first.
btw you forgot to sage

First step is to define a grammar, then you create a parser for your language, which will create an AST (abstract syntax tree), from which you can then generate machine code (or, more easily, code in another language, which you will then feed to an existing compiler).
Flex and Bison are the two GNU tools usually used for this task.


The thing is, these functions are interesting in C, because C strings do not contain their own size, so you end up with functions that return two values: a string (passed as an argument), and an integer value. The key here, is that such a function returns the most important value via an argument rather than via the return keyword.
In the particular case of getline() or sprintf(), in Z, the string contains its own size, so it is a single return value, and not via an input argument.
string user_input = io.read_line(my_file);
Ignoring the return value in such a case would make no sense at all.
If, for some reason, you would like to ignore the next available file, it is more reasonable to do the following:
pass_line(my_file);
If you do not get a line, then calling a function called get_line makes little sense, and adds a small but noticeable difficulty to fluently read the code.
Of course, Z would also allow you to declare the following function anyway:
function get_line(file_t f) => (void);

TL;DR, the problem of functions with unused return values arises mostly because of status codes, single return values and null-terminated strings, all of which are non-problems in Z.


Sage isn't a downvote, reddit.

you forgot to suck my dick

what are side effects???

saged XDDD


you forgot to sage

Is all I can read in your post. Side effects have little to do with return values in this particular context, so I guess it's just that you can't program for shit, hence your recommendation to learn a functional language.

where is the compiler???????????
prove me wrong faggot. protip: kys *

Looks like I've struck a nerve here, kid.

epic
still no compiler though. LARP alert

Very great language for systems computing. Even though computers are meant for maths, as

is meant for.

#define fail \ errno = 1; \ return NULL;#define fail_void \ errno = 1; \ return;
memelang defeated

Is there a way to pack structures for systems programming? They really help for defining descriptor tables.

Yes, I'll write about packed structures later. I had thought about them for easy implementation of binary communication protocols as well, or anything related to information exchange between two potentially different architectures for that matter.

Why is this relevant? Is the image trying to convey some message about the impact of tall buildings on the economy?

...

Probably to show that tall buildings are usually built in periods of economic growth, rather.

I wait with bated breath.

This language is pointless. It's basically C with a few very minor differences.
I bet your compiler just changes everything to the C equivalent (easy to do) and then uses gcc.

there is none

Besides, virtually every imperative language is "C with minor differences" if you go by that

except all the imperative languages that arent trying to be c.
btw where is the compiler?????

It's WIP!

If you introduce strong typedefs and explicitly reject CoC in a premptive manner Im in.

Compiler will require you to take a picture of yourself to prove your hair isn't dyed. This should keep the community healthy.

You seem smarter than the people who made C and it is a better language, but it's still too much like C for me to want to use it.

Are there classes, or do I have to use function pointers in structs?

Why do you want OOP?

I just prefer thing.do() over thing->do()

It's not Simon Peyton Jones' fault that you're too retarded to read Haskell.
So you're appealing to people who use C, C++ and Java by keeping the ugly syntax

FPIDF get out, Haskell is objectively unreadable

Also thinking on supporting anonymous functions and structures, because these are really missing in C.

can you also add support for memory safety????????
also a compiler would be nice, i gues....

thread hidden

No.
I'm actually fighting with LLVM's lack of documentation for its C++ API (which has been broken in several versions), and it seems I will have to use the Ocaml API.
Of course, I don't know Ocaml, but heh.

lol. nice meme m8

Ok kid

i mean llvm. use gcc or kys niggerfaggot

No.

...

simple lack > total lack

dude all you have to do is convert your shitty c wannabe memelang to c and then invoke gcc.

That involves writing a lexer and a parser at a minimum, kiddo

yes???????

ok well it isnt a trivial task kiddo im trying to get flex and bison to work nicely

LOOOOOOOOL

sadly you didn't reply to the other issue. I'm being quite serious, I'll EVEN HELP or INVEST if this thing has those two things, because so far this sounds like something I have wanted for a long time.

1) Will you have strict Typedefs?
2) Would you be willing to compromise to simply publicly disavow CoC's at the first time someone requests you to add a CoC?

also, please, don't add oop. Let people build their own oop schemes.

Yes, I would publicly refuse to adopt any CoC. As for your question on strict typedef, I'm not quite sure what you mean.

Typedefs are not checked at compile time, they-re actually treated as aliases.

If you write:

Typedef int pepe;
Typedef int oscar;

pepe a=1;
oscar b=a;

Will not even do a warning. The crime here is that the compiler has this features for its own types, but doesn't allow the user to have it.

The dark council of C++ assumes this is fixed just because Classes, which are unfairly favored already have this behaviour.

So, you mean treating typedefs as new types of their own, instead of merely aliases?
Yes, I agree.

Good, I'll be following this thread in case you start a repository or open some irc channel or something.

You can catch me in #Holla Forums on Rizon (there's a reason I tripfag in the first place) at roughly 11am-11pm GMT+1 every day, as for setting up a repo, I'll first get a parser running with Bison+Flex.

I thought it was because you were an attention whore. Still, I like this idea, sadly, I see no channel like that on rizon.

lel, derp, riot irc client can't enter channels with slashes on its name, or something like that, Will try tomorrow on other client.

It can be and is both.

hello were is de compiler :D :DD

i dont know XDDD where is it?????? :^)

fagmo is still working on the lexer.

You are already making the big mistake of having retarded defaults like C++. This is how I know you are larping "If you don't care about this super duper cool feature I'll add a keyword for you to remove it", it should be opt-in, you write more text to do more things not the opposite.
Also making it not possible to access err means any leaf err function would virally force everything else to be fail.
I hope you realize how stupid this is. I don't see what's stopping me from using err functions in nofail functions, as long as I can handle the error.

Also all that pointer shit is a non issue in C++, it's just that C allows implicit casts so shit like "unsigned a = &4;" compiles, just force people to make casts like in C++ and there would be no problem, at least not a single problem that does not exist in your convoluted system. You're making it different for the sake of making it different, you solved absolutely nothing.

Dropped. Another shit-turd like Rust.

That's how I know you've never developed anything besides single file fizzbuzzs.
You should see C++ code that's in production sometimes to understand how fucked up pointers can be.
This isn't a situation because you only "nofail" performance-critical functions where you need to get rid of the call overhead, which only makes sense when that function doesn't call more than a couple functions itself, which in turn don't call any other functions, otherwise nofailing it makes no sense.

where is the compiler???????????

Working on the parser ATM

Show me

why did you make a thread about your memelang without a working compiler????????????????

Are you retarded? I can't post production code online, that goes against company policies and intellectual property laws. Not that you'd know that since you've likely never had a job anyway.

LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOL
seriously though, where is the compiler???????

Show me an example retard, show me a common mistake that your shitty system prevents.
Pointers still can be null, so they are not references. You can still take the address, you can still assign a pointer. The implicit conversion is already forbidden in C++ ("Because the implicit conversion between integers and pointers is forbidden", LARP INCORPORATED). What the fuck does your language do better in that regard?.

not adding oop retardation to the mix seems quite enough to me to be honest.

Most people that care about performance go for c++ with a c appearance, ignoring all the unpredictable, bloated and nonsensical features. For any of those people having a c++ that looks crippled for a modern c++ cultist would be a gem.

Nifty spec.


I'm betting 1 litecoin that this project will be abandoned within 6 months. My definition of abandoned is no commits within a 3 day timespan.

there is no source code

Found the LARPer

if you start a thread about your memelang and dont have a working compiler you are a LARPer

Nice sage-as-a-downvote btw

where is the concept compiler??????????????
sage

counter upboat