Author Topic: Creating a customised (front-end) compiler for Oxygen  (Read 6570 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Creating a customised (front-end) compiler for Oxygen
« on: June 27, 2012, 12:16:28 AM »
This was a task which required the compile-time to be measured. But it also demonstrates how simple it is to create a compiler out of Oxygen. This gives you the opportunity to preprocess the source code, add your own libraries etc.

http://rosettacode.org/wiki/Compile-time_calculation#OxygenBasic

Code: OxygenBasic
  1.  
  2.  
  3. 'LIBRARY CALLS
  4. '=============
  5.  
  6. extern lib "../../oxygen.dll"
  7.  
  8. declare o2_basic (string src)
  9. declare o2_exec  (optional sys p) as sys
  10. declare o2_errno () as sys
  11. declare o2_error () as string
  12.  
  13. extern lib "kernel32.dll"
  14.  
  15. declare QueryPerformanceFrequency(quad*freq)
  16. declare QueryPerformanceCounter(quad*count)
  17.  
  18. end extern
  19.  
  20. 'EMBEDDED SOURCE CODE
  21. '====================
  22.  
  23. src=quote
  24.  
  25. ===Source===
  26.  
  27. def  Pling10 2*3*4*5*6*7*8*9*10
  28.  
  29. byte a[pling10] 'Pling10 is resolved to a number here at compile time
  30.  
  31. print pling10
  32.  
  33. ===Source===
  34.  
  35.  
  36. 'TIMER
  37. '=====
  38.  
  39. quad ts,tc,freq
  40. QueryPerformanceFrequency freq
  41. QueryPerformanceCounter ts
  42.  
  43. 'COMPILE/EXECUTE
  44. '===============
  45.  
  46. o2_basic src
  47.  
  48. if o2_errno then
  49.   print o2_error
  50. else
  51.   QueryPerformanceCounter tc
  52.   print "Compile time: " str((tc-ts)*1000/freq, 1) " MilliSeconds"
  53.   o2_exec 'Run the program
  54. end if
  55.  


Charles

Aurel

  • Guest
Re: Creating a customised (front-end) compiler for Oxygen
« Reply #1 on: June 27, 2012, 07:39:11 AM »
Hi... this is interesting.
Charles
In this program oxygen.dll is a sort of runtime,right?
Is there a way to create a oxgen.dll as exe - some sort of virtual machine?

Charles Pegge

  • Guest
Re: Creating a customised (front-end) compiler for Oxygen
« Reply #2 on: June 27, 2012, 09:16:32 AM »

Hi Aurel,

You need Oxygen.dll if you want to compile and/or run the program directly in memory.

If you compile this program to a standalone  EXE then it will be an Oxygen compiler, though it will still require Oxygen.dll as the back-end.

I am thinking of replacing the freebasic-compiled gxo2 and exo2 with this sort of program.

The last time I produced compilers in this way, we had trouble from various paranoid antivirus software. But I hope they have improved their behaviour since then :)

Charles

efgee

  • Guest
Re: Creating a customised (front-end) compiler for Oxygen
« Reply #3 on: June 27, 2012, 12:09:24 PM »
IMHO also important are creating different executables for Windows/Linux/OSX.
Maybe export to asm this way nasm or yasm or other assemblers can be used...

I'm spending more time on a MacBook Pro nowadays... and loving it.

 Sorry Windows  ;D

P.S. Dislike what MS did with Windows 8... Leaving the Windows ship in the long run...  OSX  and Linux are my favorites now...
« Last Edit: June 27, 2012, 12:34:40 PM by efgee »

Charles Pegge

  • Guest
Re: Creating a customised (front-end) compiler for Oxygen
« Reply #4 on: June 27, 2012, 05:26:25 PM »
Hi Frank,

What restrictions do Apple place on developers these days. Do you have to use their compilers?

Charles

efgee

  • Guest
Re: Creating a customised (front-end) compiler for Oxygen
« Reply #5 on: June 29, 2012, 10:59:08 AM »
Charles,
What I heard so far is that with the upcoming version of OSX (this summer) it will be harder (or even impossible) to install non-signed apps from the Apple Store.

What the implication will be in regards to Indie Programming Languages I don't know.

I can imagine that you still can download and run executable files (from other sources) but the user has to click several OK buttons to make it happen.
(if it's only once at install it's not a big deal)

BTW: The compilers I know that are available for OSX are:

Apple XCode (Objective C)
GCC (never tested it)
Go (will test it soon)
JavaScript (well...)
Java (no VM installed by default anymore - will be more restricted in the future for security reasons)
PureBasic (uses XCode - or part of it - to generate executable files)
RealBasic (it's actually a big slow VM)
Objective Basic (generates Objective C files -> uses XCode - will test it soon)
TCC (never tested it)

The nice thing is that with the right tools you can create an APP package that entails all needed files in order to run the application.
(it's actually a zip file that's renamed to app, but certain static files, like icons, need to be in a specific location; inside the zip file)
With that, if you delete the app file everything goes with it (exception: files that are created at runtime because they are outside of this app file).
No dependency hell... if done right!

Just to make it clear:
I'm not talking about iOS for iPhone and iTab - I'm talking about OSX for Apple desktops and laptops.

Sometimes I fall into a trap because I'm used to Windows/Linux and expect stuff to be difficult.

 :D

Charles Pegge

  • Guest
Re: Creating a customised (front-end) compiler for Oxygen
« Reply #6 on: June 29, 2012, 11:39:12 AM »

Hi Frank,

I like the idea of the App-pack.

The best option as far as Oxygen is concerned, is to produce C code for GCC or objective-C. It will have to be low level stuff, using C as a form of Assembly code, which I believe is the approach taken by the Freebasic developers. Some of the constructs like inner functions do not exist in C or C++. So these have to be turned into lower level constructs. ( C-- :) ) But that should give us access to many different platforms.

..The Raspberry Pie

http://www.raspberrypi.org/

Charles



efgee

  • Guest
Re: Creating a customised (front-end) compiler for Oxygen
« Reply #7 on: June 29, 2012, 02:34:36 PM »
This would be so awesome  8)
(the Objective C part... XCode is free!)

Are you working on a C emitter?

Best Regards


BTW:
A colleague of mine bought the Raspberry Pie and he has Linux running on it  ;)

Now he ordered this:
http://www.amazon.com/AT-Laptop-Dock-Motorola-ATRIX/dp/B004M17D62/ref=sr_1_7?ie=UTF8&qid=1340915669&sr=8-7&keywords=motorola+docking+station+keyboard

So he can have a dedicated keyboard and screen (only usb + hdmi inputs needed).
Not bad for $65  ;D

izzy77

  • Guest
Re: Creating a customised (front-end) compiler for Oxygen
« Reply #8 on: June 29, 2012, 03:30:23 PM »
Thanks for that info efgee. I have just purchased an iMac desktop and about to try my hand at programing on it.

The info you gave on Java is of value to me. Thansk.

Charles Pegge

  • Guest
Re: Creating a customised (front-end) compiler for Oxygen
« Reply #9 on: June 29, 2012, 10:09:06 PM »
Frank, I have a much clearer concept of the C emitter now, so I anticipate putting fingers to keyboard soon. Meanwhile, going through the Rosetta code tasks is very useful for testing the capabilities of Oxygen and flushing out a few more bugs.

With the diversity of devices and operating systems, I think C becomes the de facto universal assembler.

Charles.

JRS

  • Guest
Re: Creating a customised (front-end) compiler for Oxygen
« Reply #10 on: June 30, 2012, 12:56:46 AM »
Quote
With the diversity of devices and operating systems, I think C becomes the de facto universal assembler.

I couldn't agree with you more.

Want to add a pre-tested library to your project, all it takes is an include of a .h file. It's hard to match the flexibility of using C [cross] compilers.