OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 4:59 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: New esoteric programming language
PostPosted: Wed Sep 19, 2007 7:11 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2293
Location: USA (and Australia)
I'm writing my own esteric programming language. It's extended upon Brainf*ck but with a few of my own ideas.
- There is a stack that you can push to/pop from (using ^ and v).
- There are If and While equivilents now (depends if you close the code block with ] (loop code block) or } (end of code block)).
- You can declare functions.
- You can include other files (like libraries).

If you read over the specification, you might wonder what the c instruction is for. That's compiler specific and it's really up to compiler as to how it works. Once I make the H Standard Library that defines how things like file I/O should work, the library will be written in H as a wrapper around the c instruction (the standard library will be called by including "LIBRARY.H", pushing the paremeters onto the stack in reverse order, pushing 1 on to the stack, then calling the x instruction).

The language (excluding the library) should be fairly complete - I'm working on an interpreter now.

Code:
The H Programming Language
---------------------------------
           19 September 2007 0.02
http://messiahandrw.netfast.org

Execution Environment
---------------------------------
The environment consists of at
least 5000 units of memory
storage and at least 512 units of
stack storage. The environment
begins with the all memory set to
0 and nothing on the stack. The
pointer position begins pointing
to the first unit in memory. A
unit is at least 8 bits in
length. The program begins
executing from the first
instruction and continues until
there are no more instructions to
execute.

H Standard Library
---------------------------------
To be implemented.

---------------------------------
Execution Notes

- Brainf*ck code should execute
   correctly without requiring
   modification.
- If the pointer position is
   moved past beyond the bounds
   of the memory, then the
   pointer is wrapped around to
   the other side of the memory.
- If a value has been decreased
   below 0 or increase above the
   maximum value stored in a
   memory unit, then the value is
   wrapped around.
- If a closing nest is reached
   with no opening nest, then
   the debugger will be alerted
   in debug mode or the command
   will be ignored in release
   mode.
- If a value is pushed on to the
   stack and there is no stack
   space remaining, then the
   value is ignored.
- If a value is popped from the
   stack and the stack is empty,
   then the stack will return
   the value 0.
- If a ( is executed, then the
   program will to the
   instruction after the next
   ). Code between ( and ) is
   not executed unless the
   function is registered and
   executed.
- If a ) is executed outside of
   a loop, then the program will
   exit.
- If a function is associated to
   a value already associated to
   another function, then the new
   value will be associated to
   the new function.
- If a function is called with
   a value that is not associated
   with a function, the debugger
   will pause execution in debug
   mode, or the program will
   go to the next instruction in
   retail mode.
- If unrecognised text is
   executed in debug mode, then
   the debugger will pause the
   code, or the program will go
   to the next instruction in
   retail mode.
- The debugging command ! is
   ignored in retail mode.
- The c command varies between
   implementations and therefore
   should not be used directly.
   The c command should only be
   used for testing and for
   writing implementation-
   specific function wrappers
   inside of libraries.
- The ) and ] are identical, but
   should be used according to
   their context.
- A function may also be ended
   with ].

Commands
---------------------------------
-- Numeric Manipulation --
+  Increase value pointed to
    by the pointer.
-  Decrease value pointed to
    by the pointer.
>  Increment the pointer
    position.
<  Decrement the pointer
    position.
   
-- Program Control --
[  Opening nest. If value
   pointed to by the pointer is
   equal to 0 then jump to
   closing next.
]  Closing nest. Jump back to
   opening nest.

-- Stack --
^  Push value pointed to by the
    pointer on to the stack.
v  Pop value from the stack in
    to the position the pointer
    is pointing to.
   
-- Compatibility --
,  Read byte from keyboard and
    place in to the position the
    pointer is pointing to.
.  Write the ASCII character of
    the value the pointer is
    pointing to on the screen.

-- Functions --
(  Declare the beginning of a
    function.
)  Return from a function.
:  Register the function of the
   last ( executed and   associate
   it with the next number
   popped from the stack.
x  Execute the function
    associated with the next
    number popped from the stack.
z  Unassociate function
    associated with the next
    number popped from the stack.
   
-- Preprocessor --
"  Include the contents of the
    file named between two " over
    the position of the file name
    and the two "'s.
#  Ignore all text from and
    including the # to the end of
    the line.

-- Debugger --
!  Pause execution until the
    debugger allows the program
    to resume execution.
   
-- Compiler/Interpreter --
c  Compiler/interpreter specific
   command.

Change Log
---------------------------------
version 0.02:
- Removed { (do if 0) and } (end
  without loop)
version 0.01:
- Initial design documentation.

_________________
My OS is Perception.


Last edited by AndrewAPrice on Thu Sep 27, 2007 12:47 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 1:52 pm 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2006 12:00 am
Posts: 1444
Sounds interesting, theres a Brainf*ck interpreter for DexOS, let me know when its done, if i like it i may port it too, if thats OK.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 4:00 pm 
Offline
Member
Member

Joined: Sun Apr 29, 2007 1:13 am
Posts: 234
who hasn't created their own esoteric programming language?
Code:
+a1?a50!a


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 4:05 pm 
Offline
Member
Member
User avatar

Joined: Thu Jan 04, 2007 3:29 pm
Posts: 1466
Location: Noricum and Pannonia
I think system calls would be cool:
Code:
21 ^ #

Push 21(the system interrupt.) and have # call it.

:)

_________________
C8H10N4O2 | #446691 | Trust the nodes.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 27, 2007 12:46 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2293
Location: USA (and Australia)
I've removed the { and } instructions since they are unnecessary. I'm trying to keep the language as 'minimal' as possible while being as flexible as possible.

_________________
My OS is Perception.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 27, 2007 4:25 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2293
Location: USA (and Australia)
I've been working the compiler. Since bf code is valid H code, I've finished implementing all brainf*ck instructions into my compiler.

Code:
H Programming Language Compiler
http://messiahandrw.netfast.org

Usage: h [options] source

Options:
        -b <bits>       Specify the size of the memory cells in bits.
        -cs             Output to C# source code rather than a binary image.
        -d, --debug     Generate debugging information.
        -h, --help      Show this text.
        -l <language>   Language to compile.
        -m <size>       Number of cells in memory.
        -o <file>       Specify output file.
        -O              Disable optimisation.
        -u, --unsafe    Generate unsafe code. Unsafe code is faster but does
                        not provide memory protection.

Supported languages:
        bf              Brainf*ck (default)
        h0.02           H (0.02)(comming soon)

Supported memory cell sizes:
        8               8-bits
        16              16-bits
        32              32-bits (default)
        64              64-bits


My compiler can generate either Windows binaries or C# source (not fully supported yet because a 2MB bf program expands to around 90MB of C#!). I've also got basic optimisation, like merging multiple -,+,<,> into a single instruction at compile time. "--debug" does nothing for now. The number of memory cells can range from 1 all the way up to 2^64 (that means it can access from 8-bits up to a theoritcal 137,438,953,472 gigabytes of memory ((2^64) * 8 bytes))!

I'm considering more optimisation tricks, such as merging + with -, and < with >, and replacing [-] with a set-to-0 instruction which should speed nearly every brainf*ck program up significantly!

_________________
My OS is Perception.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 27, 2007 5:05 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
Looks good. If you can make a linux ELF-producing port I might port it to jimix as my first 'compiler'... ;)

I've now got bash history pretty much working and working on JTED - the jimix test execution daemon - will perform automated builds for different architectures then automated tests (forks, boots bochs/qemu quietly in the background, feeds input into the serial port and records output). This should tell me if I've buggered anything up when making code changes (it checks out my svn source automatically). Also putting in 'analysis' tests, that'll return CSV tables which get rendered by R scripts. So I'll be able to tell if I'm getting exponential performance (degradation) when forking processes or not... :S

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 3:04 pm 
Offline
Member
Member

Joined: Thu Oct 21, 2004 11:00 pm
Posts: 248
Why do you want a personal dialect of Brainfuck?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 3:57 pm 
Offline
Member
Member
User avatar

Joined: Thu Mar 08, 2007 11:08 am
Posts: 670
Isn't one of the major selling points of Brainfuck the ability to pack code really densely: since there are only eight instructions, every instruction will take only 3bits to store.

_________________
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 1:48 pm 
Offline
Member
Member

Joined: Thu Oct 21, 2004 11:00 pm
Posts: 248
Well sure, but the actual code necessary to really accomplish anything will take *more* space than normal.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 56 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group