Author Topic: The Imperium programming language - IPL  (Read 86895 times)

0 Members and 7 Guests are viewing this topic.

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 20768
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: A microcontroller programming language
« Reply #650 on: January 01, 2023, 05:19:06 pm »
C++ is great, because C++ connects people: basically all experienced or knowledgeable people (people with a clue, or those who grok, so to speak) agree on if not hating, but at least not loving C++, no matter how much they disagree otherwise. It's truly a horrible and messy language.

That is a superb example of "making a silk purse out of a sow's ear" (which has been done!). I'm far too old and grouchy to be able to be so imaginatively positive :(
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15439
  • Country: fr
Re: A microcontroller programming language
« Reply #651 on: January 01, 2023, 07:49:37 pm »
C++ is great, because C++ connects people: basically all experienced or knowledgeable people (people with a clue, or those who grok, so to speak) agree on if not hating, but at least not loving C++, no matter how much they disagree otherwise. It's truly a horrible and messy language.

As I mentioned in other threads, one particularly entertaining activity (up to a point, don't abuse it) is to watch talks from C++ conferences such as CppCon.
Almost endless hours of fun.

And to be fair, although for slightly different reasons, Rust talks are often pretty entertaining too. Don't take my word for it, go watch a few!

 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #652 on: January 01, 2023, 08:24:13 pm »
Yes, all args are passed by ref. To achieve pass by value (that is, pass a ref to a temp copy) one just surrounds the arg in parens:

omfg. I am without words.

You just threw away a huge chunk of performance, as well as compatibility with all existing libraries and OS interfaces.

Ha! but not without expletives!

OK since you do want to discuss this with me, let me respond.

I'm referring to the general policy for arg passing, ultimately an implementation could do this in various ways (pass in a register for example). I'm not really referring to the implementation but to the semantics, I don't think I made that clear.

So "pass by reference" here is meant to indicate that the callee can change something in the datum that's been passed. That's the default convention, and if the the caller want's to prevent a callee from changing the value of an arg, they'd simply make that arg an expression with ( and ).

This leads to increased performance because unless the developer wants to pass by value, they can write the code and just let args pass by ref, meaning passing a bunch of structures, strings, arrays or combinations of these will entail nothing more than pushing a pointer onto the stack!

Ugh.

Code: [Select]
procedure foo(i : integer)
  var i : integer = 1;
  procedure bar(j : integer)
    i := i + 1;
    j := j + 1
  end
  bar(i);
  print(i)
end

What is printed?

Run it and it and see, then tell us the answer and then explain what the relevance is of asking this question? is it an attempt to make some "point"? well then state your case, state your proposition whatever it is.
« Last Edit: January 01, 2023, 08:32:40 pm by Sherlock Holmes »
“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #653 on: January 01, 2023, 08:28:09 pm »
the author should really take a deep look into

Frankly, the author should really get a job. I mean programming real stuff, from home automation to avionics. Only then can he come back here and talk. Otherwise, sugar crap is and will be the only main core of everything.

Why do you want to discuss me rather than programming languages? I can talk here any time I choose, your approval is irrelevant, your criteria for my participation is irrelevant, please stick to the subject, be objective scientific, analytical rather than rude, insulting and emotional.

What has one's employment status got to do with the subject under discussion?
« Last Edit: January 01, 2023, 08:34:05 pm by Sherlock Holmes »
“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #654 on: January 01, 2023, 08:35:13 pm »
Why do you want to discuss me rather than programming languages?

Your idea have ZERO real life experience, too much arrogance.
Enjoy my ignore list.

More emotions, try answering my question before running away in future.

If you want to debate me on something then ask me, start a thread, state some position and if I disagree I'll respond and we can then debate it like adults, no emotions, just, logic, reason, ball's in your court.

This thread though is not about me, go and re-read the OP, see for yourself.


« Last Edit: January 01, 2023, 08:37:13 pm by Sherlock Holmes »
“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4247
  • Country: gb
Re: A microcontroller programming language
« Reply #655 on: January 01, 2023, 08:38:27 pm »
Why do you want to discuss me rather than programming languages?

Run it and it and see, then tell us the answer and then explain what the relevance is of asking this question? is it an attempt to make some "point"? well then state your case, state your proposition whatever it is.

The Dunning-Kruger effect occurs when a person's lack of knowledge and skills in a certain area
 (real life programming) cause them to overestimate their own competence.

Enjoy my ignore list.
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 
The following users thanked this post: MK14

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 20768
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: A microcontroller programming language
« Reply #656 on: January 01, 2023, 08:56:06 pm »
C++ is great, because C++ connects people: basically all experienced or knowledgeable people (people with a clue, or those who grok, so to speak) agree on if not hating, but at least not loving C++, no matter how much they disagree otherwise. It's truly a horrible and messy language.

As I mentioned in other threads, one particularly entertaining activity (up to a point, don't abuse it) is to watch talks from C++ conferences such as CppCon.
Almost endless hours of fun.

And to be fair, although for slightly different reasons, Rust talks are often pretty entertaining too. Don't take my word for it, go watch a few!

I don't like 99.7% of videos: too few words/minute, and there's no way of determining within 30s that it will be worth my time. (Won't be worth my time is a trivially easy decision) Hence I get my C++ jollies from the C++ Frequently Questioned Answers[1] at https://yosefk.com/c++fqa/ Don't forget to click on any of the "FAQ:" links, since they link to the relevant FAQ.

Zealots claim that the FQA is no longer valid in some respects. I have no reason to doubt that, but there are plenty of others left untouched. I'm particularly fond of the const correctness section. As a taster I'll repeat "The pointer aliasing issue is one reason that the compiler can't really optimize code because it sees a pointer declared as const. And when it can figure out there are no aliases, it doesn't need your const declarations to help it."

If that is too detailed, then there's always https://yosefk.com/c++fqa/class.html#fqa-7.5 "How does C++ help with the tradeoff of safety vs. usability? ... Anyway, here's the real answer to the original question: C++ helps with the tradeoff of safety vs. usability by eliminating both."

[1] accurate, and sets the tone nicely
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 
The following users thanked this post: Sherlock Holmes

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #657 on: January 01, 2023, 08:58:51 pm »
Why do you want to discuss me rather than programming languages?

Run it and it and see, then tell us the answer and then explain what the relevance is of asking this question? is it an attempt to make some "point"? well then state your case, state your proposition whatever it is.

The Dunning-Kruger effect occurs when a person's lack of knowledge and skills in a certain area
 (real life programming) cause them to overestimate their own competence.

Enjoy my ignore list.

This like many posts here, is fallacious, you cannot invalidate someone's argument on the basis of their job title, experience or educational qualifications, this is terrible reasoning, really poor reasoning.

"But Mr. Einstein, we can't accept this rather controversial pseudo scientific paper on clocks 'slowing down' and so on. I mean you're only a patent clerk as well for goodness sake, sorry we can't publish such ideas, not in our journal".

“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4538
  • Country: nz
Re: A microcontroller programming language
« Reply #658 on: January 02, 2023, 09:02:51 am »
Yes, all args are passed by ref. To achieve pass by value (that is, pass a ref to a temp copy) one just surrounds the arg in parens:

omfg. I am without words.

You just threw away a huge chunk of performance, as well as compatibility with all existing libraries and OS interfaces.

Ha! but not without expletives!

OK since you do want to discuss this with me, let me respond.

I'm referring to the general policy for arg passing, ultimately an implementation could do this in various ways (pass in a register for example). I'm not really referring to the implementation but to the semantics, I don't think I made that clear.

So "pass by reference" here is meant to indicate that the callee can change something in the datum that's been passed. That's the default convention, and if the the caller want's to prevent a callee from changing the value of an arg, they'd simply make that arg an expression with ( and ).

This leads to increased performance because unless the developer wants to pass by value, they can write the code and just let args pass by ref, meaning passing a bunch of structures, strings, arrays or combinations of these will entail nothing more than pushing a pointer onto the stack!

Ugh.

Code: [Select]
procedure foo(i : integer)
  var i : integer = 1;
  procedure bar(j : integer)
    i := i + 1;
    j := j + 1
  end
  bar(i);
  print(i)
end

What is printed?

Run it and it and see, then tell us the answer and then explain what the relevance is of asking this question? is it an attempt to make some "point"? well then state your case, state your proposition whatever it is.

I can not run it, sir.

This is my best guess of a possible syntax for YOUR proposed programming language, which you have not provided us with a compiler for.

My proposition is that your feature of everything is pass by reference not only sucks in general, but is especially nasty when combined with your feature of nested functions.
 
The following users thanked this post: newbrain

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3527
  • Country: it
Re: A microcontroller programming language
« Reply #659 on: January 02, 2023, 10:01:48 am »
Frankly, the point bruce wanted to make was pretty obvious: anyone can write terrible code in any language, no matter the features that should supposedly make it better than *insert language name*. That snippet really hurt my brains and made me wish for a committee to produce a coding standard.
« Last Edit: January 02, 2023, 10:03:20 am by JPortici »
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #660 on: January 02, 2023, 12:19:04 pm »
Yes, all args are passed by ref. To achieve pass by value (that is, pass a ref to a temp copy) one just surrounds the arg in parens:

omfg. I am without words.

You just threw away a huge chunk of performance, as well as compatibility with all existing libraries and OS interfaces.

Ha! but not without expletives!

OK since you do want to discuss this with me, let me respond.

I'm referring to the general policy for arg passing, ultimately an implementation could do this in various ways (pass in a register for example). I'm not really referring to the implementation but to the semantics, I don't think I made that clear.

So "pass by reference" here is meant to indicate that the callee can change something in the datum that's been passed. That's the default convention, and if the the caller want's to prevent a callee from changing the value of an arg, they'd simply make that arg an expression with ( and ).

This leads to increased performance because unless the developer wants to pass by value, they can write the code and just let args pass by ref, meaning passing a bunch of structures, strings, arrays or combinations of these will entail nothing more than pushing a pointer onto the stack!

Ugh.

Code: [Select]
procedure foo(i : integer)
  var i : integer = 1;
  procedure bar(j : integer)
    i := i + 1;
    j := j + 1
  end
  bar(i);
  print(i)
end

What is printed?

Run it and it and see, then tell us the answer and then explain what the relevance is of asking this question? is it an attempt to make some "point"? well then state your case, state your proposition whatever it is.

I can not run it, sir.

This is my best guess of a possible syntax for YOUR proposed programming language, which you have not provided us with a compiler for.

My proposition is that your feature of everything is pass by reference not only sucks in general, but is especially nasty when combined with your feature of nested functions.

I'm not familiar with the technical terms "sucks" or "nasty" when describing programming languages.

“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #661 on: January 02, 2023, 09:20:08 pm »
I have a feeling this language will suck more than what (C?) is going to replace  :o :o :o

If it's efficacy were dependent upon facile contributions like this post of yours, I dare say I'd agree with you.

“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #662 on: January 02, 2023, 09:28:31 pm »
Note that, as we often discuss, this certainly has an impact on the intrisic qualities of a language, but little on its popularity. A number of languages that have become very popular were just a bunch of ad-hoc stuff stitched together. Sad but just how it goes.
PHP is perhaps the best example of this.

Considering that, why would anyone start designing a language from the ground up, starting with syntax or grammar, instead of examining how expressions and algorithms would be best expressed in the new language?

How many time must I address this point?

First, language grammar's have properties, different grammars have different properties, a property I value greatly is an ability to easily extend the scope of the language by adding new keywords.

Second my posts have not been confined to matters of grammar, I've discussed a plethora of things so far, yet some here - like you - seem to want to do nothing but complain.

Third I will discuss what I want to discuss in any order I choose, if this is not to your liking then kindly leave the thread in peace.



“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #663 on: January 02, 2023, 09:44:31 pm »
Here's a condensed list of important goals for a new language suitable for writing code for MCUs:

1. Extensible grammar (new keywords easily added over time, 100% backward compatibility guaranteed)
2. Elimination of pointer arithmetic.
3. Multidimensional arrays with variable upper/lower bounds.
4. An advanced preprocessor.
5. Support true 'offsets' in addition to conventional 'pointers'.
6. Supported nested procedures.
7. Support exceptions/conditions
8. Support 'builtin' and 'intrinsic' as fundamental language concepts.
9. Abstraction of interop - use a declarative means of interfacing to code written by other languages.
10. Support 'bit' as a data type.
11. Support flexible alignment, padding and ordering of structure/array members.
12. Support endianness operations for converting a contiguous memory block from big/little to little/big endian.
13. Support multiple 'heaps' and facilitate the freeing of all allocations within a heap by simply resetting the heap.
14. Innate support for coroutines.
15. Support decimal, octal, binary and hex numeric literals.
16. Support fixed point arithmetic in decimal/binary base.
17. Remain vigilante, aware of other old and new languages like Ada, Rust, Zig, Hare, Odin etc, where are these weak? where are they strong?

Is there anything fundamental missing from this list ? (I recognize that some want to talk about threading, synchronization and multiple cores, these are important but perhaps best set aside for now, to be revisited later).

It would be interesting to also examine various examples of C based solutions to certain MCU problems to see how a new language could improve the implementation of that code.

I'd like to also remind some here that all/any of these topics are up for discussion, I am not only concerned with grammar, if anyone wants to discuss any of these aspects then please be my guest, lets explore and move forward...



« Last Edit: January 02, 2023, 09:54:16 pm by Sherlock Holmes »
“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 520
  • Country: au
Re: A microcontroller programming language
« Reply #664 on: January 02, 2023, 10:09:40 pm »

Code: [Select]
procedure foo(i : integer)
  var i : integer = 1;
  procedure bar(j : integer)
    i := i + 1;
    j := j + 1
  end
  bar(i);
  print(i)
end

What is printed?
I wondered if there was a sensible answer.

Hopefully the compiler would give a warning "Do you really want to create a local variable the same name as a passed parameter?" at line 2.

If that warning is ignored, then does procedure bar inherit the current instantiation of i from foo due to scoping?
if not, then compiler should warn "uninitiated variable i"
if so within bar, i := i + 1; will operate on the i declared in foo due to scoping: i then = 2
j := j + 1 will operate on the  i declared in foo as a passed variable by reference: i then = 3
Print 3

This seems logical to me. Makes what I regard as sensible interpretation of scoping. Is this a reasonable analysis? other interpretation?

Maybe a solution is to make the rules flexible [procedure bar(i) - don't say how i is passed and let the linker make that decision. Not the same as VB where the variable is mutable at run time, just flexible until link time]. If the procedure caller doesn't care what happens to the passed variables or requires their version to remain unchanged, can explicitly pass by value. If the procedure caller expects something to be modified and wants the result, explicitly pass by reference. Let the linker fix it up. This means the programmer has more flexibility, the procedure writer can determine if a particular method is required (causing a linker error if not adhered to) or let the linker fix it. And there is no ambiguity in the calling code.

 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4538
  • Country: nz
Re: A microcontroller programming language
« Reply #665 on: January 02, 2023, 10:57:50 pm »

Code: [Select]
procedure foo(i : integer)
  var i : integer = 1;
  procedure bar(j : integer)
    i := i + 1;
    j := j + 1
  end
  bar(i);
  print(i)
end

What is printed?
I wondered if there was a sensible answer.

Hopefully the compiler would give a warning "Do you really want to create a local variable the same name as a passed parameter?" at line 2.

If that warning is ignored, then does procedure bar inherit the current instantiation of i from foo due to scoping?
if not, then compiler should warn "uninitiated variable i"
if so within bar, i := i + 1; will operate on the i declared in foo due to scoping: i then = 2
j := j + 1 will operate on the  i declared in foo as a passed variable by reference: i then = 3
Print 3

This seems logical to me. Makes what I regard as sensible interpretation of scoping. Is this a reasonable analysis? other interpretation?

Maybe a solution is to make the rules flexible [procedure bar(i) - don't say how i is passed and let the linker make that decision. Not the same as VB where the variable is mutable at run time, just flexible until link time]. If the procedure caller doesn't care what happens to the passed variables or requires their version to remain unchanged, can explicitly pass by value. If the procedure caller expects something to be modified and wants the result, explicitly pass by reference. Let the linker fix it up. This means the programmer has more flexibility, the procedure writer can determine if a particular method is required (causing a linker error if not adhered to) or let the linker fix it. And there is no ambiguity in the calling code.

Very good except our friend stated "So 'pass by reference' here is meant to indicate that the callee can change something in the datum that's been passed", and in other places that it might not actually be by a pointer, but by being passed in a register and passed back. He's also indicated several times the he follows Ada in various things.

Ada has INOUT parameters, where it is *undefined* whether they are passed by copy/return or by pointer.

This makes a difference to code such as the above.
 
The following users thanked this post: MK14, DiTBho

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #666 on: January 02, 2023, 11:30:37 pm »

Code: [Select]
procedure foo(i : integer)
  var i : integer = 1;
  procedure bar(j : integer)
    i := i + 1;
    j := j + 1
  end
  bar(i);
  print(i)
end

What is printed?
I wondered if there was a sensible answer.

Hopefully the compiler would give a warning "Do you really want to create a local variable the same name as a passed parameter?" at line 2.

If that warning is ignored, then does procedure bar inherit the current instantiation of i from foo due to scoping?
if not, then compiler should warn "uninitiated variable i"
if so within bar, i := i + 1; will operate on the i declared in foo due to scoping: i then = 2
j := j + 1 will operate on the  i declared in foo as a passed variable by reference: i then = 3
Print 3

This seems logical to me. Makes what I regard as sensible interpretation of scoping. Is this a reasonable analysis? other interpretation?

Maybe a solution is to make the rules flexible [procedure bar(i) - don't say how i is passed and let the linker make that decision. Not the same as VB where the variable is mutable at run time, just flexible until link time]. If the procedure caller doesn't care what happens to the passed variables or requires their version to remain unchanged, can explicitly pass by value. If the procedure caller expects something to be modified and wants the result, explicitly pass by reference. Let the linker fix it up. This means the programmer has more flexibility, the procedure writer can determine if a particular method is required (causing a linker error if not adhered to) or let the linker fix it. And there is no ambiguity in the calling code.

Very good except our friend stated "So 'pass by reference' here is meant to indicate that the callee can change something in the datum that's been passed", and in other places that it might not actually be by a pointer, but by being passed in a register and passed back. He's also indicated several times the he follows Ada in various things.

Ada has INOUT parameters, where it is *undefined* whether they are passed by copy/return or by pointer.

This makes a difference to code such as the above.

A similar discussion arises when we discuss stuff like:

Code: [Select]

for (I = 0; I < Funct(I); I++)
     {
     ;
     }

Is Funct(I) evaluated once, at loop initialization and the value stored opaquely? or is Funct(I) evaluated at the start of each iteration?

There is no right answer, these are options that a language designer must weigh up and choose.

Given the prevalence of passing structures in C on MCUs as almost always by address, it makes sense to recognize that and why it happens and then say "OK, well since whenever we pass a structure into some function in C on say STM32 devices, we always pass its address for the performance gain and because the callee will likely update the structure, lets recognize that and relieve the developer from having to always pass a pointer or pass the address".

We could even declare the datum itself with a "pass as" attribute, is that a good or bad idea? That way we can declare some structure to some concept like an A/D Converter as inherently always passed by val or ref, then there is no pass by convention, instead the means of passing is part of the type...just sayin...I've not thought about this at all, just throwing it out there, suggest, propose ideas, first, evaluate their utility later...I love ideas, I do not defer to orthodoxy, instead I like to hear all ideas, whether they be good or bad doesn't matter at first, we can always decide that later, this is lateral thinking, think freely, worry not, just generate ideas, encourage the breaking of convention, suggest the absurd even, but do not filter human thought prematurely, this is the essence of western European rationalism, the scientific revolution, there's nothing to worry about, get hung up about, this is just a discussion on the interet.

That's all I'm saying, sure, one can write code that abuses that or does it in a way that seems to undermine the principle, but we can do that with any language, one can take any language and write appalling code and then say "Look, I told you, that's a crap language".



« Last Edit: January 02, 2023, 11:41:08 pm by Sherlock Holmes »
“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #667 on: January 03, 2023, 07:25:42 pm »
In a different discussion about another language the question of how best to exit or continue loops, particularly nested loops, came up for discussion.

What are people's thoughts about this kind of thing?

“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15439
  • Country: fr
Re: A microcontroller programming language
« Reply #668 on: January 03, 2023, 07:39:49 pm »
In a different discussion about another language the question of how best to exit or continue loops, particularly nested loops, came up for discussion.

What are people's thoughts about this kind of thing?

My take on this is named blocks, which generalizes loops.
Then to exit the block, 'exit xxx' or 'break xxx' or whatever syntax you like.

Example (again the syntax is just an example C-like, use whatever syntax you like - this is NOT C, so those tags would not be C goto labels, just block names):
Code: [Select]
Rows: for (i = 0; i < n; i++)
{
    Columns: for (j = 0; j < m; j++)
    {
        ...
        if (...)
            exit Rows;
    }
}

The block names or tags could be used for just any code block and not just loops. And again the syntax is just to show the idea, could be something else entirely. The idea is just to give code blocks a tag.
Simple and effective, and easy to read IMO. (Obviously you can do the same in C using goto and labels, but this isn't as readable IMO, and the above may allow better static analysis and better optimization.)
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #669 on: January 03, 2023, 07:48:19 pm »
In a different discussion about another language the question of how best to exit or continue loops, particularly nested loops, came up for discussion.

What are people's thoughts about this kind of thing?

My take on this is named blocks, which generalizes loops.
Then to exit the block, 'exit xxx' or 'break xxx' or whatever syntax you like.

Example (again the syntax is just an example C-like, use whatever syntax you like - this is NOT C, so those tags would not be C goto labels, just block names):
Code: [Select]
Rows: for (i = 0; i < n; i++)
{
    Columns: for (j = 0; j < m; j++)
    {
        ...
        if (...)
            exit Rows;
    }
}

The block names or tags could be used for just any code block and not just loops. And again the syntax is just to show the idea, could be something else entirely. The idea is just to give code blocks a tag.
Simple and effective, and easy to read IMO. (Obviously you can do the same in C using goto and labels, but this isn't as readable IMO, and the above may allow better static analysis and better optimization.)

Yes that seems reasonable, the syntax <identifier><colon> is used by PL/I and C, used in PL/I to name procedures and functions in fact.

Its a bit disjointed though, in both C and PL/I.

In PL/I a procedure is named using a label:

Code: [Select]

sort_data:
   procedure (arg);
   // stuff
   end;

Yet PL/I does not use that form for naming declared items, C too only uses <identifier><colon> for label and nowhere else.

Of course in the example above "goto sort_data" would not compile because it knows that name is not a simple label.

PL/I also lets you break out of nested loops by referring to a label that prefixes some outer loop, all in all the use of label notation seems a bit odd to me in C and PL/I.

Is there another way? a "better" notation for labels?

Any easy thing to do would be a "label" keyword:

Code: [Select]

label outer_loop;

loop while (a > b)
   // stuff

   if (X) then
      leave outer_loop; // break in C
end;


But a keyword followed by the name? seems long winded...

I discovered that historically the <identifier><colon> form dates back to at least Algol, PL/I got it from that language and C got it from PL/I.

Ada uses <<label_name>> as a label.

Perhaps (since braces are not used by this new language, the 'draft' grammar) one could use { and } ?

Code: [Select]

{main_loop}

   loop
      // stuff
      if (a > b) then
         leave main_loop;
   end;

In that example {main_loop} visually stands out well, it is easy to see it's not some keyword or part of some ordinary statement, a : looks a lot like a ; too when perusing code, it also seems slightly better than Ada's << and >> IMHO...
« Last Edit: January 04, 2023, 10:43:40 pm by Sherlock Holmes »
“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #670 on: January 05, 2023, 02:33:49 pm »
Yes, all args are passed by ref. To achieve pass by value (that is, pass a ref to a temp copy) one just surrounds the arg in parens:

omfg. I am without words.

You just threw away a huge chunk of performance, as well as compatibility with all existing libraries and OS interfaces.

Ha! but not without expletives!

OK since you do want to discuss this with me, let me respond.

I'm referring to the general policy for arg passing, ultimately an implementation could do this in various ways (pass in a register for example). I'm not really referring to the implementation but to the semantics, I don't think I made that clear.

So "pass by reference" here is meant to indicate that the callee can change something in the datum that's been passed. That's the default convention, and if the the caller want's to prevent a callee from changing the value of an arg, they'd simply make that arg an expression with ( and ).

This leads to increased performance because unless the developer wants to pass by value, they can write the code and just let args pass by ref, meaning passing a bunch of structures, strings, arrays or combinations of these will entail nothing more than pushing a pointer onto the stack!

Ugh.

Code: [Select]
procedure foo(i : integer)
  var i : integer = 1;
  procedure bar(j : integer)
    i := i + 1;
    j := j + 1
  end
  bar(i);
  print(i)
end

What is printed?

Run it and it and see, then tell us the answer and then explain what the relevance is of asking this question? is it an attempt to make some "point"? well then state your case, state your proposition whatever it is.

I can not run it, sir.

This is my best guess of a possible syntax for YOUR proposed programming language, which you have not provided us with a compiler for.

My proposition is that your feature of everything is pass by reference not only sucks in general, but is especially nasty when combined with your feature of nested functions.

I'd be willing to create a runnable parser for the language that you can feed source code into and explore. There is no compiler yet, just a grammar and parser that proves that the grammar recognizes valid source code. If anyone would like to see that and explore it I'd  be willing to set aside some time to create that for general use.

“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #671 on: January 05, 2023, 06:24:18 pm »
Evaluation order is a very important aspect of a programming language, C and C++ are very sloppy in this regard so I think this should be defined, not left to compiler writers to decide.

Java and C# are more formal, strict so I think a new language should follow their example which is left-to-right both within expressions and argument lists.

Short circuit evaluation too can be supported by dedicated operators, & and | for "evaluate" both sides and ?& and ?| for "evaluate the right only if the left has some value".

« Last Edit: January 05, 2023, 06:32:39 pm by Sherlock Holmes »
“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: A microcontroller programming language
« Reply #672 on: January 05, 2023, 07:00:50 pm »
FYI - The language has a name now, it has been named "Imperium" after the Latin term for "control", source files are suffixed .ipl - Imperium Programming Language.

“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1772
  • Country: se
Re: A microcontroller programming language
« Reply #673 on: January 05, 2023, 10:02:39 pm »
FYI - The language has a name now, it has been named "Imperium" after the Latin term for "control", source files are suffixed .ipl - Imperium Programming Language.
Be careful, this might cost you a life sentence in Azkaban.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 20768
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: A microcontroller programming language
« Reply #674 on: January 05, 2023, 10:20:52 pm »
FYI - The language has a name now, it has been named "Imperium" after the Latin term for "control", source files are suffixed .ipl - Imperium Programming Language.

Usually the name is chosen to reflect a language's principal characteristics and behaviour.

Congratulations on making this important advance which will, no doubt about it, speed up progress.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf