Omnimaga

Calculator Community => HP Calculators => Topic started by: iconmaster on June 25, 2014, 05:49:17 pm

Title: Source: It's a programming language. Now with HPPL support!
Post by: iconmaster on June 25, 2014, 05:49:17 pm
Once upon a time, I was writing programs for the HP Prime in HPPL. The more I worked in HPPL, the more I became dissatisfied with the language. I mean, it was usable, but I wanted better.

So I decided to make something better. I started work on Source. It's a programming language.

Source is a procedural, statically-typed bytecode-compiled language that can either compile to whatever platform you need or interpret directly on your computer. Currently, it compiles to HPPL.

Source gives you control. It's statically typed, so you can read your code more easily. It can assume types, so it's not needlessly verbose. You can control how it compiles through directives.

Source is flexible. It provides data structures and user types. You can define methods for data types anywhere. You can organise your code into packages. Source even can handle cyclic dependencies!

Source has tools. Compile it into HPPL from the command line, or use SourceBench to write and compile code on the fly. Use SourceBox to run your code on your PC. Run SourceLine to interactively execute Source code.

Source isn't done yet. The core libraries still need implemented, not to mention a bunch of features such as custom structs and classes. In the future, it will be able to compile to a bunch of places, not just HPPL. I wouldn't describe it as 'usable' yet. But stay tuned!

Anyways, the important bit: The link. Check out the source code at:

https://github.com/iconmaster5326/Source (https://github.com/iconmaster5326/Source)

Want to download Source? Want to learn more? Check out the wiki at:

https://github.com/iconmaster5326/Source/wiki (https://github.com/iconmaster5326/Source/wiki)

The wiki has downloads, documentation, and tutorials.
Title: Re: HPP+ : A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on June 25, 2014, 07:18:14 pm
Seems interesting. Since HP PPL is fast I think an alternate language that compiles to it could be very feasible, although an interpreted language would probably run as slow as 83+ BASIC or so. Just make sure, however, that the compiled code doesn't end up totally bloated or unoptimized, though.

One thing I would suggest is offering certain pre-made routines for sprites or maps, for example, with a decompressor, so that people could use different image formats that are smaller than the built-in ones. The resulting code would simply decompress the images into a GROB upon runtime.
Title: Re: HPP+ : A WIP alternate programming language for the Prime
Post by: iconmaster on June 26, 2014, 08:43:22 am
Seems interesting. Since HP PPL is fast I think an alternate language that compiles to it could be very feasible, although an interpreted language would probably run as slow as 83+ BASIC or so. Just make sure, however, that the compiled code doesn't end up totally bloated or unoptimized, though.
Yeah, an interpreted language isn't a good idea for speed here. Even if I made, like, a bytecode language, it wouldn't be fast.

And yes, optimization will be important. I'll have to do lots of testing to see what code patterns run the most efficiently.

One thing I would suggest is offering certain pre-made routines for sprites or maps, for example, with a decompressor, so that people could use different image formats that are smaller than the built-in ones. The resulting code would simply decompress the images into a GROB upon runtime.

I do plan on having all-new custom functions in the mix as well, yes. Graphics-wise, I'll see if there's a format that's smaller than ICON (Uncompressed PNG file? There has to be a better way). The compiler will be smart enough to only put HPP+ custom functions into the code if you call them.

For example, there's no simple function to get only a part of a list, or to insert a list item in the middle of one. HPP+ will add these functions, which will decompile into an HPPL function that gets called when needed.


In the future, I'll probably be collaborating with other interested people to figure out A. how to organise functions into packages and B. what custom function we need and how they should be called.
Title: Re: HPP+ : A WIP alternate programming language for the Prime
Post by: bb010g on June 26, 2014, 04:27:25 pm
I like the idea, but I think this will become less useful over time. The most important thing the Prime needs is some way of passing around functions (either anonymously or by pointers) and values (pointers most likely) without strings. I used expr in a paint program I had and it dropped performance a bunch. Every time an expr is hit, a bit of compilation has to be done. In a tight loop (like in a game), this gets bad fast. I like the constants, but it's more space in the editor on-calc. I wouldn't mind so much if it was just in the compiled file. These problems can only be fixed by changing PPL itself. I think adding pointers, even without pointer arithmetic, development would be a whole lot nicer. (I would also feel better about using large data structures. :)) I'm using struct-esque lists in my in-progress Tetris clone, and all you really need are program-local vars that act like enums and a function to take key-value pairs and give a list with the proper indices. That function could even just be shared in a lib.

Anyhow, I'm looking forward to see how this goes. :)
Title: Re: HPP+ : A WIP alternate programming language for the Prime
Post by: cyrille on June 27, 2014, 01:26:46 am
Hello,

>smaller than ICON (Uncompressed PNG file? There has to be a better way).
ICON is a compressed PNG... problem is that since it is in hex, it takes 2 bytes per nibble :-(


>For example, there's no simple function to get only a part of a list
yes there is! L1({5,8}) will get you elements 5 to 8 of L1 in a list..

>or to insert a list item in the middle of one.
concat(L1({1,n}), { 1, 2, 3}, L1({n,1000}))

You can also pass around functions, but they need to be properly QUOTEd to make sure that they are not evaluated at the wrong time...

Cyrille
Title: Re: HPP+ : A WIP alternate programming language for the Prime
Post by: iconmaster on June 27, 2014, 08:08:42 am

Hey Cyrille!

Hello,

>smaller than ICON (Uncompressed PNG file? There has to be a better way).
ICON is a compressed PNG... problem is that since it is in hex, it takes 2 bytes per nibble :-(
I can see what you had to do it that way, though. Translating bytes directly into unicode would mean there would be characters like ; or control chars in the ICON. Perhaps if you encode it into base64?

>For example, there's no simple function to get only a part of a list
yes there is! L1({5,8}) will get you elements 5 to 8 of L1 in a list..

>or to insert a list item in the middle of one.
concat(L1({1,n}), { 1, 2, 3}, L1({n,1000}))
What.

You can also pass around functions, but they need to be properly QUOTEd to make sure that they are not evaluated at the wrong time...

Cyrille
WHAT.

Well, knowing this, back to messing around with quotes...


EDIT: Today, I learned that a list can have a maximum of 2^31 entries! You learn something new every day.
Title: Re: HPP+ : A WIP alternate programming language for the Prime
Post by: bb010g on July 03, 2014, 01:51:22 am
You can also pass around functions, but they need to be properly QUOTEd to make sure that they are not evaluated at the wrong time...
Could you give an example?
Title: Re: HPP+ : A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on July 03, 2014, 01:58:51 am
EDIT: Today, I learned that a list can have a maximum of 2^31 entries! You learn something new every day.
YEah I think the limit was increased in the 2nd firmware. Beforehand I think the limits from the HP 39gII were all accidentally left in, including DIMGROB size limits and stuff. IIRC the max amount of elements in lists was 999 like on the TI-83 Plus.
Title: Re: HPP+ : A WIP alternate programming language for the Prime
Post by: iconmaster on October 06, 2014, 04:23:56 pm
So you guys may be surprised to learn that this project isn't dead. Actually, I've restarted from scratch.

Today, I'm introducing Source.

Source is the new name for HPP+. I made the change because I might (might!) make this language compilable to other places eventually.

There is currently the Source compiler, which parses Source programs but doesn't compile it yet, and a Source plugin for the IDE Netbeans. The plugin has syntax highlighting and error displaying already built in.


Take a look at https://github.com/iconmaster5326/Source .

Soon, I plan on giving you guys a WIP document on the exact syntax of Source. Also, I really need to update the OP.

One las thing, concerning pointers: I've worked with QUOTE a little (I need to show you guys how it works), but it acts quite... Uniquely. I may or may not be able to figure out how to use this to make pointers fast.
Title: Re: HPP+ : A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 06, 2014, 07:50:36 pm
Hi and nice to see you again. :D

As for the new name, just keep in mind it might confuse people if they post actual source code literally :P, but I like the idea. Btw do you plan to write a tutorial on how to code in Source when finished? It might be good to post about it here if that's the case, so more people see it.

btw is this still a language written in HP PPL or does it now use ASM/C through any HP Prime exploit?
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 06, 2014, 07:55:02 pm
Hi and nice to see you again. :D

Hey! I just updated the OP, funny thing.

As for the new name, just keep in mind it might confuse people if they post actual source code literally :P , but I like the idea. Btw do you plan to write a tutorial on how to code in Source when finished? It might be good to post about it here if that's the case, so more people see it.

Source is a good name. I don't see how it could be confusing. :P


Anyways, I plan on writing Source tutorials soonish. Probably before the whole project is done, actually! Sooner than later, though, will be coming a description of the syntax. Syntax is important! How else can I get feedback on this thing?

btw is this still a language written in HP PPL or does it now use ASM/C through any HP Prime exploit?

Sadly, I have not found any good haxx. :P It will be initially entirely compiled to HPPL. However, as we learn more about the OS, I am willing to add in features in ASM/C.

Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 06, 2014, 07:59:39 pm
Indeed. I am really curious about how this language will look like. Just make sure it's not overly cryptic like Antidisassemblage on the 84+. Ironically, that language was meant to bridge the gap between TI-BASIC and Z80 ASM, yet it required learning ASM in order to even understand why Squirrelbox works in certain ways, which defeated the entire point.
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: JWinslow23 on October 06, 2014, 08:26:18 pm
Indeed. I am really curious about how this language will look like. Just make sure it's not overly cryptic like Antidisassemblage on the 84+. Ironically, that language was meant to bridge the gap between TI-BASIC and Z80 ASM, yet it required learning ASM in order to even understand why Squirrelbox works in certain ways, which defeated the entire point.
The only invented languages I know of that were successful are Axe and Nspire C++. I hope this will add another one to the list. :)
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 06, 2014, 08:55:49 pm
Indeed. I am really curious about how this language will look like. Just make sure it's not overly cryptic like Antidisassemblage on the 84+. Ironically, that language was meant to bridge the gap between TI-BASIC and Z80 ASM, yet it required learning ASM in order to even understand why Squirrelbox works in certain ways, which defeated the entire point.

Well, guess what? I quickly wrote up some syntax. It's at https://github.com/iconmaster5326/Source/blob/master/SyntaxGuide.src (https://github.com/iconmaster5326/Source/blob/master/SyntaxGuide.src) ! Try downloading the NetBeans plugin to read it in full color.

No, I'm not done with said syntax sheet yet. It's very bare-bones ATM.

The only invented languages I know of that were successful are Axe and Nspire C++. I hope this will add another one to the list. :)

Well, thank you. I'll do my best.


EDIT: Well, it seems pointers are on the table.


Code: [Select]
FUNC(a)
BEGIN
 MSGBOX("call "+a);
END;


FUNC2()
BEGIN
 LOCAL AA=1;
 LOCAL BB='FUNC(AA)';
 EVAL(BB);
 AA:=2;
 EVAL(BB);
 AA:=3;
 RETURN BB;
END;


EXPORT TST2()
BEGIN
 LOCAL XX=FUNC2();
 LOCAL AA=4;
 EVAL(XX);
END;

Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 06, 2014, 10:47:03 pm
Ok thanks I'll check that out when I have a minute. :)
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 07, 2014, 09:39:09 pm
I found this in an old changelog:


Quote
"1234"[n] now works to access a specific character in a string with no memory copy.


Note to self: Accessing from strings are now probably faster than accessing from a list.


EDIT: Did some speed testing. No, it's not faster.
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 09, 2014, 01:30:12 pm
Another interesting dynamic of HPPL is how global variables work. The following program show you a message when the program is compiled:

Code: [Select]
FF()
BEGIN
 MSGBOX("OH MY");
END;

GLOBALVAR=FF();

I have a few ideas about how this might come in handy. ;)
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: timwessman on October 09, 2014, 04:38:21 pm
I have a few ideas about how this might come in handy. ;)

Crap!

That might be quite problematic since the code gets compiled when you send it across... I'll have to check that.

Also, I think storing a char directly also does not require any memory allocations since the size isn't changing.
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 09, 2014, 08:42:31 pm
Crap!

That might be quite problematic since the code gets compiled when you send it across... I'll have to check that.

Also, I think storing a char directly also does not require any memory allocations since the size isn't changing.

Hmm? You can STORE characters using that notation too? Didn't know that.

It's a good thing you hang around here, Tim. We'd never have any documentation otherwise!


EDIT: Speaking of documentation, I was looking at #pragma. Can it accept any other arguments tham mode? In mode, can it only take separator and integer modes?
Title: Re: &lt;UPDATED&gt; Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 10, 2014, 07:22:25 am
I thought that code got compiled when exiting the editor? Or am I missing something here?
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 10, 2014, 06:35:38 pm
Guys, I have an announcement. Source is working.

I'm faaaaar from done, but we can now compile this:

Code: [Select]
field x as real = 3

function test() {
   x = 1 + 1
}

into this:

Code: [Select]

#pragma mode( separator(.,;) integer(h32) )


test();
x:=3;




test()
BEGIN
 LOCAL TMP_1:=1;
 LOCAL TMP_2:=1;
 LOCAL TMP_0:=TMP_1+TMP_2;
 x:=TMP_0;
END;

This is a huge step for the Source compiler. Right now, there is a huge lack of minification, as you can see. This will be fixed once the full syntax of Source gets added to the compiler.
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 11, 2014, 01:11:21 pm
Ooh that is awesome :D. It seems the code gets smaller, right? How well does it get optimized for particularly complex programs?
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 11, 2014, 03:15:05 pm
Ooh that is awesome :D . It seems the code gets smaller, right? How well does it get optimized for particularly complex programs?

Thanks!

Well, the Source program is a lot smaller, but that's just because the compiler doesn't inline simple statements yet. The equivalent HPPL program would be a bit smaller if a human did it right now. Eventually, I'll make it replace the TMPs with the statements that the TMPs equal; right now, these temporary variables are created by the Source compiler to allow for statements that can't be inlined in HPPL to be inlined in Source. Also, there isn't optimization yet. But trust me, I have a few ideas.

Also, more progress. Here's a Hello Source program:

Code: [Select]
@export
function hello() {
   print("Hello, Source!")
}

that translates to:

Code: [Select]
#pragma mode( separator(.,;) integer(h32) )

hello();


EXPORT hello()
BEGIN
 LOCAL TMP_1:="Hello, Source!";
 LOCAL TMP_0:=print(TMP_1);
END;



As a bonus, some inner workings- here's the Source Intermediary Language (SIL) output for the Source program that compiles into HPPL:


Code: [Select]
FUNC hello [] []:
MOVS   TMP_1   Hello, Source!
CALL   TMP_0   print   TMP_1
END
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 14, 2014, 02:28:37 am
I see, thanks for the example :D
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 15, 2014, 06:39:00 pm
Some more progress. This time, we have inlining!


Code: [Select]

@inline
function test() {
   local a = 1
   return a + 1
}


@export
function hello() {
   print(test()+1)
}


In Source, the @inline directive tells the compiler to directly insert the code of the function test() into hello().


Here's what it compiles to:


Code: [Select]

#pragma mode( separator(.,;) integer(h32) )


hello();


EXPORT hello()
BEGIN
 LOCAL %TMP0:=1;
 LOCAL a:=%TMP0;
 LOCAL %TMP2:=a;
 LOCAL %TMP3:=1;
 LOCAL %TMP1:=%TMP2+%TMP3;
 LOCAL %TMP6:=%TMP1;
 LOCAL %TMP7:=1;
 LOCAL %TMP5:=%TMP6+%TMP7;
 LOCAL %TMP4:=print(%TMP5);
END;


Notice the non-existence of test(). It was inlined!

EDIT: Also, some work on simplifying compiled code is being done. However, it doesn't work perfectly yet:

Code: [Select]
@export
function hello() {
local a,b = 1,2
b,a = a,b
print(a+" "+b)
}
Code: [Select]
#pragma mode( separator(.,;) integer(h32) )

hello();
EXPORT hello()
BEGIN
 LOCAL a:=1;
 LOCAL b:=2;
 b:=a;
 a:=b;
 print(a+" "+b);
END;
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 17, 2014, 12:42:42 am
Nice so far. By the way at one point you should try to make an example program, such as a port of the "famed" Wacky Fun Random Numbar Generator v1.000069. Perhaps a graphical demo too to showcase the speed and size.
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: bb010g on October 17, 2014, 01:18:56 am
Nice. Would you mind pull requests in the future? :)
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 17, 2014, 06:49:12 am
Nice so far. By the way at one point you should try to make an example program, such as a port of the "famed" Wacky Fun Random Numbar Generator v1.000069. Perhaps a graphical demo too to showcase the speed and size.

That's a good idea. Right now, the language is about 90% stable; some things might change before final release, but not many. The big thing that's in the air right now is the functions I'll be providing. Even if these two things are true, I probably should work on making actual programs in Source.

Nice. Would you mind pull requests in the future? :)

I would love some collaboration!
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: chickendude on October 19, 2014, 08:34:54 am
I just saw this, nice work so far!
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: timwessman on October 20, 2014, 09:01:53 am
So how do you plan to distinguish lists from block braces? The primary reason we decided to go with the begin/end instead of { } was due to confusion and potential conflicts.
Title: Re: <UPDATED> Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 20, 2014, 03:28:45 pm
So how do you plan to distinguish lists from block braces? The primary reason we decided to go with the begin/end instead of { } was due to confusion and potential conflicts.

In Source, lists use [] instead. A deviance from the HPPL, sure, but one that works.

Even if I make {} the list delimiters, I believe my parsing system could handle it given some slight changes.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 21, 2014, 05:45:26 pm
Good news! I fixed the optimization routines.


Now, this:


Code: [Select]

@export
function hello() {
local a,b = 1,2
a,b = b,a
print(a+" "+b)
}


compiles into this:


Code: [Select]

#pragma mode( separator(.,;) integer(h32) )


hello();


EXPORT hello()
BEGIN
 LOCAL a:=1;
 LOCAL b:=2;
 LOCAL %TMP2:=b;
 LOCAL %TMP3:=a;
 a:=%TMP2;
 b:=%TMP3;
 print(a+" "+b);
END;


Which is both optimized and correctly prints out 2,1. However, it still could be more efficient.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: bb010g on October 22, 2014, 01:12:50 am
So how do you plan to distinguish lists from block braces? The primary reason we decided to go with the begin/end instead of { } was due to confusion and potential conflicts.

In Source, lists use [] instead. A deviance from the HPPL, sure, but one that works.

Even if I make {} the list delimiters, I believe my parsing system could handle it given some slight changes.
Vectors?
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 22, 2014, 11:50:40 am
Vectors?

Matrices (and thus, vectors) will have thier own instantiation syntax.

While vectors are used in math a lot, [] are list deliminators in some programming languages; this is a more programmer-oriented language rather than HPPL, which is more math-oriented. Don't wory, though, in due time there will be an interface for all of HPPL's math functions.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 22, 2014, 11:53:58 am
Glad to see more optimizing being done :). Now if only ASM/C was possible on the Prime so that such program could be compiled directly on-calc or even in actual ASM code. In its current form it's still promising, though, especially considering how fast HP PPL is.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 22, 2014, 01:09:15 pm
Glad to see more optimizing being done :) . Now if only ASM/C was possible on the Prime so that such program could be compiled directly on-calc or even in actual ASM code. In its current form it's still promising, though, especially considering how fast HP PPL is.
Well, do DO have a way to run native code, it's just that we would have to write a LOT to get a basic framework for anything going. Actually getting reliable ASM execution is far beyond my ability, I believe.


About on-calc execution: In retrospect, perhaps I should have made the Source compiler in C and not Java. :P

But trust me, the minute we have a framework for native code, Source will be able to compile to it. Source is designed so it can compile to multiple platforms.

In other Source news, Source now has ifs and while loops. They're kind of important, I've heard.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 22, 2014, 04:30:01 pm
Oh yeah I meant if somebody made the stuff required to run native code. It's possible but the question is if anybody will ever bother, considering how powerful HP PPL already is. You can already have SNES-like graphics without much slowdowns and even 3D polygons now, so if somebody decides to make a game in native code then it will most likely be a port of Doom or emulators.


And yeah glad you added If/while lol, but again I once made a game on a calculator that lacks While/For/Repeat so I guess they're not that essential, after all. :P (I had to use Lbl, Goto, IS>() and DS<())
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 22, 2014, 05:44:43 pm
Oh yeah I meant if somebody made the stuff required to run native code. It's possible but the question is if anybody will ever bother, considering how powerful HP PPL already is. You can already have SNES-like graphics without much slowdowns and even 3D polygons now, so if somebody decides to make a game in native code then it will most likely be a port of Doom or emulators.


And yeah glad you added If/while lol, but again I once made a game on a calculator that lacks While/For/Repeat so I guess they're not that essential, after all. :P (I had to use Lbl, Goto, IS>() and DS<())

Yeah, I don't suppose native execution will come soon; I mean, there's like 3 or 4 willing Prime fans total :P

Well, if only we had GOTOs. I would actually like a GOTO; Source could really take advantage of GOTO-based optimizations.

I'm trying to make for loops now. Speaking of that, Source probably won't optimize FORs to MAKELISTs right off the bat; I'm still implementing anonymous functions, which that would depend on internally.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 22, 2014, 05:47:37 pm
Indeed. After the small craze last Fall and Winter I think only 1 game came out. Of course tho it doesn't help that calculator programmers is an endangered species and that the few dedicated ones that remains are too busy with school and work. HP marketing the calc more outside USA and fixing the bugs would help, though.


As for Gotos I'm not a big fan of them anymore since they often cause memory leaks in certain languages or are slower, but they can be handy in some cases if you use and name them properly.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 22, 2014, 08:11:03 pm
As for Gotos I'm not a big fan of them anymore since they often cause memory leaks in certain languages or are slower, but they can be handy in some cases if you use and name them properly.

I'm not usually the best fan of them, myself; however, I would believe using nothing but GOTOs would be faster than most loop constructs currently available. If I was programming directly in HPPL, that would be a pain. However, I'm writing in Source. :)

Anyways, I whipped up a little interactive Source application to let you guys see how Source is coming along. You'll need the following 2 files:

https://drone.io/github.com/iconmaster5326/Source/files (https://drone.io/github.com/iconmaster5326/Source/files)
https://drone.io/github.com/iconmaster5326/SourceBench/files (https://drone.io/github.com/iconmaster5326/SourceBench/files)

Put them both in the same directory, and then run SourceBench.

Here's what SourceBench looks like:
Spoiler For Spoiler:
(http://i.imgur.com/l6sCHND.png)

You put Source code in the input box, hit compile, and see your HPPL output. I suggest trying examples from earlier in the thread!
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 22, 2014, 08:14:46 pm
A Java exception has occured D:
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 22, 2014, 08:18:23 pm
A Java exception has occured D:
It was compiled in Java 8. Do you have Java 8 installed?
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on October 22, 2014, 09:17:18 pm
Ok I just realized that my version (7) was 2 months old. I updated and it starts fine now (although with a Windows 7-like theme rather than the Windows 95-like theme in your screenshot :P)
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 23, 2014, 04:29:20 pm
Now you can inline variables, too!

Code: [Select]
@export
function hello() {
   @inline
   local x="Source"
   print("Hello, "+x)
}

Compiles to:

Code: [Select]
#pragma mode( separator(.,;) integer(h32) )
hello();

EXPORT hello()
BEGIN
 print("Hello, "+"Source");
END;

You can make inlined stuff equal to non-constant pieces of code, so they're a little like a macro. You can even redefine constants!

Here's a program showing off everything I've implemented recently:

Code: [Select]
@export
function test() {
 @inline
 local end=10
 local a,i=range(1,end),1
 while i<=end {
  print(a[i])
  a[i]*=2
  i+=1
 }
 print(a)
}
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 27, 2014, 09:06:37 pm
Data types are (mostly) working. I'll talk more about how they work in Source, but for now, have an example of how data type methods work:


Code: [Select]

function list.test(a as list) {
local i = a.size()
print("The list is "~i~" elements long.")
while i>0 {
print("Element "~i~" contains "~a[i]~".")
i-=1
}
print("Interesting!")
}


@export
function main() {
local l as list = range(1,10)
l.test()
}
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on October 31, 2014, 03:17:24 pm

Some news!

First of all, I gave a presentation on my language to my peers this week! My presentation included all presently implemented features of Source. Get the slides here (https://docs.google.com/presentation/d/1-Dr09IFew0Zzv3misipsPmDKefITZLnPRUkycb_9FrU/edit?usp=sharing)!


Second of all, here's an example of how the type system works:


Code: [Select]

function types() {
local a as real //a is of type real
local b as string //b is of type string


//a = "" //real!=string, ERROR!
b = "" //string==string, fine

a = 1 //fine
//b = 1 //ERROR!


local c //c is ??, which is the base type (?) weakly typed


c = 1 //fine, c is now of type real?, again weakly typed
c = "" //fine, c is now type string?


local d = 44 //d is of type real?
a = d //real==real?, fine
//b = d //string!=real?, ERROR!
d = "" //real?==string?, fine


local e as ? //e is ?, the base type, but strongly typed


e = "" //you can set anything to e
//... But the reverse is not true.
//b = e //string!=?, ERROR!
d = e //??==?, fine
}
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: aeTIos on November 03, 2014, 02:39:21 am
I still plan on buying  a Prime one day. This will be one of the first programs to run on it.

Once I buy it. <_<
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on November 05, 2014, 02:56:59 am
I'll definitively have to try Source at one point too, although since I prefer to not learn multiple languages at once I'll most likely stick to PPL at first, but if I keep running into roadblocks or can't stand it, I might attempt a switch to Source.

Anyway keep the good work on this. If this do come to fruition this is definitively front page material I'll be suggesting to staff.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 06, 2014, 06:38:48 pm
I still plan on buying  a Prime one day. This will be one of the first programs to run on it.

Once I buy it. <_<

I'll definitively have to try Source at one point too, although since I prefer to not learn multiple languages at once I'll most likely stick to PPL at first, but if I keep running into roadblocks or can't stand it, I might attempt a switch to Source.

Anyway keep the good work on this. If this do come to fruition this is definitively front page material I'll be suggesting to staff.

I'm flattered. Thanks for all your support!

Speaking of support, Source now allows you to write your own custom compiling targets! Source can compile into any language you write a Java plugin for. To show off this system, I made SourceBox, a Source interpreter. Get all 3 needed jars at:

https://drone.io/github.com/iconmaster5326/Source/files
https://drone.io/github.com/iconmaster5326/SourceBench/files
https://drone.io/github.com/iconmaster5326/SourceBox/files

Put Source and SourceBench in the same directory, as usual. Run Bench once, and close it. There is now a folder called BenchData, and a subfolder called libs. Put SourceBox in there, and restart Bench.

Now, try to use that 'Platform' drop-down box.

With SourceBox, you should be able to run this directly on your computer:

Code: [Select]
@export
function powers() {
@inline
local end = 10
print("The first "~end~" powers of 2 are:")
local i,a,b = 0,0,1
while i<end {
a = a + b
b = a
print(b)
i+=1
}
print("Done!")
}
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on November 06, 2014, 06:41:49 pm
Wait, so basically if I want to make a game for both the HP Prime and the computer at once then I now can if the computer language is available for Source? O.O
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 06, 2014, 07:25:58 pm
Wait, so basically if I want to make a game for both the HP Prime and the computer at once then I now can if the computer language is available for Source? O.O

Yes.

Of course, Source still needs a library for drawing...
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: aeTIos on November 06, 2014, 07:28:09 pm
That's amazing. O.O

Someone, create this for Axe please!
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on November 06, 2014, 07:29:54 pm
Wait, so basically if I want to make a game for both the HP Prime and the computer at once then I now can if the computer language is available for Source? O.O

Yes.

Of course, Source still needs a library for drawing...
That's amazing. I wonder if PC programs will run as they do on the Prime, especially for compiled languages? It would definitively make things even easier (although you would need of course good support for the TICKS and WAIT commands so we can make our games run at constant speed.


And yeah drawing will definitively be a must, especially with how much freedom HP PPL offers already.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 06, 2014, 07:40:22 pm
That's amazing. I wonder if PC programs will run as they do on the Prime, especially for compiled languages? It would definitively make things even easier (although you would need of course good support for the TICKS and WAIT commands so we can make our games run at constant speed.

And yeah drawing will definitively be a must, especially with how much freedom HP PPL offers already.

Well, right now, SourceBox is a rather... Naive implementation. For one, in SourceBox, lists start at 0 and are passed by reference...

For one, I plan on having other compiling platforms; platforms where things are passed by reference and where arrays are indexed by different things.
I have plans to alleviate this divide; for example, I plan on making Source a language where the first list index is irrelevant. Wait and see to find out how!

In other news, you can insert HPPL code directly into Source programs:

Code: [Select]
@export
@!optimize
function hax() {
   local a="HAX"
   @lang=hppl "msgbox(a)"
}

Also, you can use custom HPPL functions as Source functions:

Code: [Select]
@native=MAX
function wow(a,b) {
   
}

@export
function getmax() {
   return wow(1,2)
}

Code: [Select]
@native
function MAX(a,b) {
   
}

@export
function getmax() {
   return MAX(1,2)
}


You can also use @lang to comment your compiled output:


Code: [Select]

@export
function stuff() {
@lang=comment "This function does stuff."
print("Stuff done!")
}
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: bb010g on November 06, 2014, 11:54:53 pm
I'm guessing the FFI is not going to be platform independent. Am I sensing compile-time code selection?
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 07, 2014, 03:50:51 pm
I'm guessing the FFI is not going to be platform independent. Am I sensing compile-time code selection?

Yes, the @lang strings are platform-dependant, as well as @native. However, I plan on making a few @langs that are independent, such as ones for Source internal bytecode.

Basically, there is a bytecode operation called NATIVE which contains the @lang string. The platform assembles this operation however it wishes; in this case, the HPPL platform takes @lang=hppl blocks and inserts the contents directly into the HPPL output.


Moving on...


Today, I have for you more progress! We now have function overloading. Now you can have two functions with the same name and different arguments, like so:


Code: [Select]

@export
function overloadTest() {
print(func())
print(func("an argument"));
}


function func() {
return "Got no arguments!"
}


function func(a) {
return "Got "~a
}


Overloading via data type will be supported soon. Right now, however, I have made directive-based overloading, too.


So, in SourceBox, you have an output panel where calling print is like the standard println. Well, what if you want a newline-less print? Well, in SourceBox, there are two versions of print. They both take 1 argument, but one of them is tagged with the @append directive. Because of this fact, you can target the print-like one instead of the println-like one as so:


Code: [Select]

@main
function printTest() {
print("This ends with a newline.")
@append print("This one ")
@append print("does not.")
}


If you tag your function call with a directive, it will try to match the directives up between functions. This way, you can have a very fine way to control function call overloading.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 07, 2014, 08:00:20 pm
I implemented the libraries for drawing in HPPL.

Code: [Select]

import prime.draw
import prime.io


@export
function main() {
local a = [rgb(255,0,0),rgb(0,255,0),rgb(0,0,255),rgb(255,0,255),rgb(0,255,255),rgb(255,255,0)]
screen.clear()
screen.drawString("Press any key to begin.",20,10)
waitForInput()
local i = 1
while not isKeyDown(4) {
screen.fill(a[i] as real)
screen.drawString("Source",125,40,7)
wait(.5)


i+=1
if i>a.size() {
i = 1
}
}
msgbox("Source. It's a programming language.")
}
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: bb010g on November 08, 2014, 02:15:50 am
Multiple dispatch?
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 08, 2014, 07:16:44 pm
Multiple dispatch?

Source uses static dispatch, but yes, it does dispatch now.

Anyways, I've been working for HPPL drawing emulation in SourceBox. It's limited, but for now you can run this program in both the Prime and on your PC:

Code: [Select]
import prime.draw
import prime.io

@export
function main() {
   local a = [rgb(255,0,0),rgb(0,255,0),rgb(0,0,255),rgb(255,0,255),rgb(0,255,255),rgb(255,255,0)]
   screen.clear()
   screen.drawString("Press any key to begin.",20,10)
   waitForInput()
   local i = list.start
   while not isKeyDown(key.esc) {
      screen.fill(a[i] as int)
      screen.drawString("Source",125,40,7)
      wait(.5)

      if a[i]==a.last() {
         i = list.start
      } else {
         i+=1
      }
   }
   msgbox("Source. It's a programming language.")
}
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on November 08, 2014, 07:37:32 pm
inline HP PPL support is definitively a good idea. Also if the calc ever supports ASM maybe Source could allow inline ASM opcodes?
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 08, 2014, 08:53:33 pm
inline HP PPL support is definitively a good idea. Also if the calc ever supports ASM maybe Source could allow inline ASM opcodes?

My thoughts exactly.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 11, 2014, 06:46:35 pm
I did a little work on parameterized types today. You use square brackets.


Code: [Select]

function test[K](a as list[K]) as K {
   return a[1]
}


@export
function main(a as list[int]) as int {
   return test(a)
}


Here, you can see two things: First, the list data type can have a type parameter; this indicates the type that can go into it or come out of it. Second, your own functions can specify type parameters, which are respected by the compiler.


EDIT: here's another example of parameters:


Code: [Select]

function do[A as int,B as int](a as A,b as B) as A {
return a+b
}


@export
function main[E as int](c as E,d as E) as E {
return do(c,d)
}
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 12, 2014, 09:44:17 pm
I am proud to present to you for loops! They're very powerful in Source.

All fors in Source are for-each loops. The kind of for you're used to looks like this:

Code: [Select]
@export
function test1() {
   for i in range(1,10) {
      print(i)
   }
}

A backwards for loop needs some special stuff done to it as of now; expect this to change:

Code: [Select]
@export
function test2() {
   @downloop
   for i in range(10,1,-1) {
      print(i)
   }
}

A traditional for-each loop is as so:

Code: [Select]
@export
function test3() {
   local a = [5,8,7,3]
   for v in a {
      print(v)
   }
}

Each loop, v becomes the next element of a.

You can get both the index and the element it references with the pairs() function of a list:

Code: [Select]
@export
function test4() {
   local a = [5,8,7,3]
   for i,v in a.pairs() {
      print(i~" "~v)
   }
}

Finally, you can simply have your own iterator functions. Just use the iterator keyword:

Code: [Select]
@export
function test5() {
   local a = [5,8,7,3]
   for newv in myOwnIter(a) {
      print(newv)
   }
}

iterator myOwnIter(a as list) as int {
   for v in a {
      return (v as int) + 1
   }
}

Note that the above code can also be written as:

Code: [Select]
@export
function test5() {
local a as list = [5,8,7,3]
for newv in a.myOwnIter() {
print(newv)
}
}

iterator list.myOwnIter(a as list) as int {
for v in a {
return (v as int) + 1
}
}
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 16, 2014, 06:31:37 pm
Right now, I'm working on developing a standard set of functions that all Source platforms get. HPPL specific ones are next.

To see how Source stuff is being divided up into packages, just go on over to https://docs.google.com/document/d/1Pe0HS0z0SAxyUH6f4UgXTKe88uxG5tcs7CyMtHha1ho/edit?usp=sharing !

I've also been working on Source bytecode optimization. It's going well.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: bb010g on November 16, 2014, 09:09:57 pm
Can you have type parameters of a rank higher than 1? That always bugged me in Java.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on November 18, 2014, 06:26:34 pm
Can you have type parameters of a rank higher than 1? That always bugged me in Java.

I'm not sure. I'll have to get back to you on that one.

Anyways, My GitHub now has a wiki. There's already a getting started guide there, and soon I will be adding Source programming tutorials, specifications, and examples there. Check it out (https://github.com/iconmaster5326/Source/wiki)!
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: DJ Omnimaga on November 22, 2014, 10:52:33 am
Awesome, hopefully there is enough documentation for people to use the language in the future. :)

Also I was always worried about For loops, because I know some languages seem to try very hard at making them weird. Even HP PPL is borderline with its FROM TO STEP DO syntax. Casio BASIC is the worst, I think, because it even inverts stuff. Instead of For(A,1,7,2) you have to write For 1->A To 7 Step 2 which is really weird.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: bb010g on November 22, 2014, 05:53:24 pm
Also I was always worried about For loops, because I know some languages seem to try very hard at making them weird. Even HP PPL is borderline with its FROM TO STEP DO syntax. Casio BASIC is the worst, I think, because it even inverts stuff. Instead of For(A,1,7,2) you have to write For 1->A To 7 Step 2 which is really weird.
Casio Isn't that weird. They just wanted to keep the standard assignment operator for the initial part of the for loop, like in other languages where you would say something like for (int i = 0; i < n; i++). It also doesn't require another token.
Title: Re: Source: A WIP alternate programming language for the Prime
Post by: iconmaster on March 28, 2015, 03:11:41 pm
Hello everyone! It's been a while.

First of all, I updated the original post. It's a lot better now.

Second of all, I'm currently at work rewriting Source from scratch. I'm also contemplating renaming Source (I've got a lot of people saying the name is bad; it kind of is). What do you think?

The drone.io will still have Source version 1 builds if you want them.
Title: Re: Source: It's a programming language. Now with HPPL support!
Post by: chickendude on March 29, 2015, 11:57:36 am
I kinda like the name. If you want to change it go for it, but i think Source is nice.