Anyone here made their own programming language?

Off-topic talk on music, art, literature, games and forum games.
teo123
Master of the Forum
Posts: 1452
Joined: Tue Oct 27, 2015 3:46 pm
Diet: Vegan

Re: Anyone here made their own programming language?

Post by teo123 »

I barely managed to get the NodeJS version check to work on Git Bash on Windows. Before NodeJS outputted the error message "stdout is not a tty". Here is what the shell script to use the AEC-to-WebAssembly compiler looks like now:

Code: Select all

if [ $(command -v git > /dev/null 2>&1 ; echo $?) -eq 0 ]
then
  git clone https://github.com/FlatAssembler/AECforWebAssembly.git
  cd AECforWebAssembly
elif [ $(command -v wget > /dev/null 2>&1 ; echo $?) -eq 0 ]
then
  mkdir AECforWebAssembly
  cd AECforWebAssembly
  wget https://github.com/FlatAssembler/AECforWebAssembly/archive/refs/heads/master.zip
  unzip master.zip
  cd AECforWebAssembly-master
else
  mkdir AECforWebAssembly
  cd AECforWebAssembly
  curl -o AECforWebAssembly.zip -L https://github.com/FlatAssembler/AECforWebAssembly/archive/refs/heads/master.zip # Without the "-L", "curl" will store HTTP Response headers of redirects to the ZIP file instead of the actual ZIP file.
  unzip AECforWebAssembly.zip
  cd AECforWebAssembly-master
fi
if [ $(command -v g++ > /dev/null 2>&1 ; echo $?) -eq 0 ]
then
  g++ -std=c++11 -o aec AECforWebAssembly.cpp # "-std=c++11" should not be necessary for newer versions of "g++". Let me know if it is, as that probably means I disobeyed some new C++ standard (say, C++23).
else
  clang++ -o aec AECforWebAssembly.cpp
fi
cd analogClock
../aec analogClock.aec
npx -p wabt wat2wasm analogClock.wat
if [ "$OS" = "Windows_NT" ] # https://stackoverflow.com/a/75125384/8902065
                            # https://www.reddit.com/r/bash/comments/10cip05/comment/j4h9f0x/?utm_source=share&utm_medium=web2x&context=3
then
  node_version=$(node.exe -v)
else # We are presumably running on an UNIX-like system, where storing output of some program into a variable works as expected.
  node_version=$(node -v)
fi
# "node -v" outputs version in the format "v18.12.1"
node_version=${node_version:1} # Remove 'v' at the beginning
node_version=${node_version%\.*} # Remove trailing ".*".
node_version=${node_version%\.*} # Remove trailing ".*".
node_version=$(($node_version)) # Convert the NodeJS version number from a string to an integer.
if [ $node_version -lt 11 ]
then
  echo "NodeJS version is lower than 11 (it is $node_version), you will probably run into trouble!"
fi
node analogClock
        
You can see the latest version on my blog.
teo123
Master of the Forum
Posts: 1452
Joined: Tue Oct 27, 2015 3:46 pm
Diet: Vegan

Re: Anyone here made their own programming language?

Post by teo123 »

Can't edit. In case I wasn't clear, unless you do some weird hacks, NodeJS in Git Bash on Windows outputs "stdout is not a tty" error instead of outputting the version number.
TelepathyConspiracy
Junior Member
Posts: 82
Joined: Thu Dec 22, 2022 3:50 pm
Diet: Vegan

Re: Anyone here made their own programming language?

Post by TelepathyConspiracy »

I've never worked with the OS beyond basic terminal commands when I had a Mac and now that I'm primarily focused on mobile I doubt I'll ever get to it (would be nice) but the idea I mentioned was from this video

https://m.youtube.com/watch?v=f7aRZN5wiHk

Essentially rewriting the OS to be as much JavaScript as possible sounds like max ROI... What is the incentive to advertising a different language? It makes sense if it were something secret so others won't corrupt your code but otherwise if it's about collaboration you should be trying to do what this guy did... Obviously I don't need to tell you but for the audience, JavaScript is the most known language in the world and is already in all environments apart from this core OS level
teo123
Master of the Forum
Posts: 1452
Joined: Tue Oct 27, 2015 3:46 pm
Diet: Vegan

Re: Anyone here made their own programming language?

Post by teo123 »

I have modified the shell script to compile Analog Clock for x86, so that it might be able to run on Windows. Here is what it looks like now:

Code: Select all

mkdir ArithmeticExpressionCompiler
cd ArithmeticExpressionCompiler
if [ $(command -v wget > /dev/null 2>&1 ; echo $?) -eq 0 ] # Check if "wget" exists, see those StackOverflow answers for more details:
                                                                                         # https://stackoverflow.com/a/75103891/8902065
                                                                                         # https://stackoverflow.com/a/75103209/8902065
then
  wget https://flatassembler.github.io/Duktape.zip
else
  curl -o Duktape.zip https://flatassembler.github.io/Duktape.zip
fi
unzip Duktape.zip
if [ $(command -v clang > /dev/null 2>&1 ; echo $?) -eq 0 ] # We prefer "clang" to "gcc" because... what if somebody tries to run this in CygWin terminal? GCC will not work then, CLANG might.
then
  c_compiler="clang"
else
  c_compiler="gcc"
fi
$c_compiler -o aec aec.c duktape.c -lm # The linker that comes with recent versions of Debian Linux insists that "-lm" is put AFTER the source files, or else it outputs some confusing error message.
if [ "$OS" = "Windows_NT" ]
then
  ./aec analogClockForWindows.aec
  $c_compiler -o analogClockForWindows analogClockForWindows.s -m32
  ./analogClockForWindows
else
  ./aec analogClock.aec
  $c_compiler -o analogClock analogClock.s -m32
  ./analogClock
fi
       
teo123
Master of the Forum
Posts: 1452
Joined: Tue Oct 27, 2015 3:46 pm
Diet: Vegan

Re: Anyone here made their own programming language?

Post by teo123 »

TelepathyConspiracy wrote:What is the incentive to advertising a different language?
Well, the languages I use have obvious flaws which have caused bugs in my programs. JavaScript is well-known for being a language full of such quirks, but C++ also isn't perfect, and C++ has also caused bugs in programs I have written in it, such as this one. I have some ideas about what a good programming language would look like and work internally, so I implemented some of them in my programming language.
Like I've said, I have no idea what a good operating system would look or work internally like, so I haven't made my operating system, and I likely never will.
teo123
Master of the Forum
Posts: 1452
Joined: Tue Oct 27, 2015 3:46 pm
Diet: Vegan

Re: Anyone here made their own programming language?

Post by teo123 »

Well, I guess the shell scripts are good enough to be added to READMEs (https://github.com/FlatAssembler/Arithm ... ler#readme https://github.com/FlatAssembler/AECfor ... ell-script), Arithmetic Expression Compiler web-page (https://flatassembler.github.io/compiler.html) and the Analog Clock example on the web (https://flatassembler.github.io/analogClock). Now they are difficult to change.
teo123
Master of the Forum
Posts: 1452
Joined: Tue Oct 27, 2015 3:46 pm
Diet: Vegan

Re: Anyone here made their own programming language?

Post by teo123 »

Writing shell scripts has left a very bad impression on me. I have written two short scripts, and I have had to ask no less than three StackOverflow questions (Fortunately, none of them reduced my reputation, and one of them received two upvotes.). One would think that checking whether a program with some name is available is one of the most common things one would like to do in a shell script. Nonetheless, doing that is very complicated. And two times in two short scripts, I had to rely on truly mysterious fixes. I've written a rant about it on my blog:
https://flatassembler.github.io/informatics wrote:Oh, and understand that you will sometimes have to apply fixes which you have no idea how they work. You will get a lot further by being empirical than by being a rationalist and only relying on things you understand. This is especially true when writing shell scripts, although it's also somewhat true in other types of programming. When writing a shell script to download, compile and run Analog Clock in AEC for x86, I ran into a problem that, on recent versions of Debian Linux, the linker insists that "-lm", the option for linking in the math library, is put after the source files, and it outputs some confusing error message if it's put before the source files. A rationalist solution would be to try to implement the math functions that Duktape invokes yourself, like I've implemented them in my programming language when writing Analog Clock for WebAssembly. Instead, I did a bit of Googling, and found a way nicer solution: put "-lm" after the source files, and not before them. I do not understand how it works, but I can empirically say it does work. You can read the zero9178's explanation for that if you are interested, I do not fully understand it either, and I probably know more about compiler theory than most programmers. And when writing a shell script to download, compile and run Analog Clock in AEC for WebAssembly, I realized that the code my AEC-to-WebAssembly compiler outputs works only on NodeJS 11 and newer, because it relies on WebAssembly global variables. So, I decided to warn the user if they have installed NodeJS that's older than NodeJS 11. So, I wrote "node_version=$(node -v)" to store the NodeJS version string into a variable called "node_version", so that I can extract the first number from it and act accordingly. That worked on Linux, but on Windows NodeJS outputted the error message "stdout is not a tty" instead of outputting the version string. I can't think of a rationalist work-around. But I was empirical, so I posted a question on StackOverflow, and I got the answer: on Windows, do "node_version=$(node.exe -v)". I almost did not try it, as it seemed so ridiculous. However, I was empirical enough that I tried it, and it somehow magically worked. I still have no idea how it works. It has something to do with the difference between how terminals work on Linux and how they work on Windows, but I don't understand the details. And like I've said, the fact that you sometimes stumble upon problems with truly mysterious fixes is true not only in shell scripting, but also in other types of programming, such as CSS. Look up the Internet Explorer 6 double-margin bug. Or how, when programming my PicoBlaze Simulator, I ran into a problem that the tooltips I made worked in Firefox but not in Chrome. In both cases, the fix seems so ridiculous that it's not even worth trying. For the Internet Explorer 6 double-margin bug, it was a mysterious bug in Internet Explorer 6. For the Chrome issue I've run into, the people on StackOverflow insist that Chrome is actually obeying the standard, while Firefox isn't. If so, the standard goes wildly against common sense here. Programming is an empirical thing, but universities pretend it's a rationalist thing.
teo123
Master of the Forum
Posts: 1452
Joined: Tue Oct 27, 2015 3:46 pm
Diet: Vegan

Re: Anyone here made their own programming language?

Post by teo123 »

After 55 new commits and one potentially breaking change (now you need to type `%%` in inline assembly to insert a single `%`, because `%` is now used to refer to variables inside inline assembly), I've decided to make a new release of the AEC-to-WebAssembly compiler, `v2.5.0`: https://github.com/FlatAssembler/AECfor ... tag/v2.5.0
teo123
Master of the Forum
Posts: 1452
Joined: Tue Oct 27, 2015 3:46 pm
Diet: Vegan

Re: Anyone here made their own programming language?

Post by teo123 »

I already have 20 GitHub Stars on the AEC-to-WebAssembly compiler. Damn, those stars fall like rain now.
https://github.com/FlatAssembler/AECforWebAssembly
teo123
Master of the Forum
Posts: 1452
Joined: Tue Oct 27, 2015 3:46 pm
Diet: Vegan

Re: Anyone here made their own programming language?

Post by teo123 »

A few days ago, I managed to modify the part of the compiler that deals with inline assembly so that the assembly code it emits for `%variable` in inline assembly is now properly indented.

Today, I released the AECforWebAsembly v2.5.1, which contains the mentioned bugfix.
https://github.com/FlatAssembler/AECfor ... tag/v2.5.1
Post Reply