https://github.com/riicchhaarrd/ocean Skip to content Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Issues - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] # * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} riicchhaarrd / ocean * Notifications * Star 73 * Fork 0 Programming language that compiles into a x86 ELF executable. BSD-3-Clause License 73 stars 0 forks Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 1 branch 0 tags Code Clone HTTPS GitHub CLI [https://github.com/r] Use Git or checkout with SVN using the web URL. [gh repo clone riicch] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @riicchhaarrd riicchhaarrd Merge branch 'main' of github.com:riicchhaarrd/ocean ... 6c5c96e Aug 3, 2021 Merge branch 'main' of github.com:riicchhaarrd/ocean 6c5c96e Git stats * 78 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time examples change builtin write to syscall, implement write in language self and Aug 3, 2021 rhd @ ad4e625 submodule & fixes Jun 29, 2021 .gitignore order fix Jul 29, 2021 .gitmodules submodule & fixes Jun 29, 2021 LICENSE Create LICENSE Jul 8, 2021 README.md Update README.md Aug 3, 2021 ast.c change builtin write to syscall, implement write in language self and Aug 3, 2021 ast.h change builtin write to syscall, implement write in language self and Aug 3, 2021 ast_node_type.h fixed bug with eax, needed to push and restore, added while test, Aug 2, 2021 build Generate x86 ELF image Jul 2, 2021 compile.h fixed bug with eax, needed to push and restore, added while test, Aug 2, 2021 compile_flags.txt Function call exit Jul 3, 2021 data_type.h restructuring / more nodes and new example Aug 1, 2021 dbg wip Jul 18, 2021 elf.c Fix relocating when not using any .data segment Jul 6, 2021 lex.c change builtin write to syscall, implement write in language self and Aug 3, 2021 main.c opts Jul 11, 2021 res wip Jul 18, 2021 std.h order fix Jul 29, 2021 token.h change builtin write to syscall, implement write in language self and Aug 3, 2021 types.h working calculator (expressions) to x86 Jun 29, 2021 x86.c change builtin write to syscall, implement write in language self and Aug 3, 2021 View code ocean TODO Example README.md ocean Programming language that compiles into a x86 ELF executable. TODO * [*] basic features of a programming language, conditionals/loops/ variables/types/order of precedence e.g (1 + 2) * 3 - 4 / 5 + (6 * 8) * [ ] a compiler somewhat resembling C * [ ] standard library * [ ] other compile targets e.g https://docs.microsoft.com/en-us/ windows/win32/debug/pe-format * [ ] self-hosting * [ ] Add new or borrow from other language(s) features ontop of C, deviate away from just C + [ ] defer + [ ] operator overloading + [ ] constexpr/consteval from c++ or some #run directive ( https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md) + [ ] learn from other similar projects (e.g https:// news.ycombinator.com/item?id=27890888) * [ ] target other ISA (instruction set architectures) e.g ARM/ x86_64 * [ ] better error handling / memory cleanup * [ ] LLVM or other IR backend (atm just targeting x86 and it's a great learning exercise) Example Example of code (may be subject to change) int strlen(const char *s) { int i = 0; while(s[i]) { i+=1; } return i; } void print(const char *s) { write(1, s, strlen(s) + 1); } int main() { print("hello, world!\n"); char msg[32]; msg[0] = 'h'; msg[1] = 'e'; msg[2] = 'l'; msg[3] = 'l'; msg[4] = 'o'; msg[5] = ','; msg[6] = ' '; msg[7] = 'w'; msg[8] = 'o'; msg[9] = 'r'; msg[10] = 'l'; msg[11] = 'd'; msg[12] = '!'; msg[13] = 10; msg[14] = 0; int i; for(i = 0; i < 10; i += 1) { if(i % 2 ==0) { print(msg); } } } Which compiles into (no relocations, when compiling to ELF strings will be relocated and 0xcccccccc would be replaced by the actual location) mov eax, 0 call eax xor ebx, ebx xor eax, eax inc eax int 0x80 push ebp mov ebp, esp sub esp, 4 mov eax, 0 push eax lea ebx, [ebp - 4] pop eax mov dword [ebx], eax mov ebx, dword [ebp + 8] mov eax, dword [ebp - 4] add ebx, eax movzx eax, byte [ebx] test eax, eax je 0x47 mov eax, 1 push eax lea ebx, [ebp - 4] pop eax add dword [ebx], eax jmp 0x23 mov eax, dword [ebp - 4] mov esp, ebp pop ebp ret mov esp, ebp pop ebp ret push ebp mov ebp, esp sub esp, 0 mov eax, 1 push eax mov eax, dword [ebp + 8] push eax mov eax, dword [ebp + 8] push eax call 0xe add esp, 4 push eax mov eax, 1 mov ecx, eax pop eax xor edx, edx add eax, ecx mov edx, eax pop ecx pop ebx mov eax, 4 int 0x80 mov esp, ebp pop ebp ret push ebp mov ebp, esp sub esp, 0x24 mov eax, 0xcccccccc push eax call 0x52 add esp, 4 mov eax, 0x68 push eax push eax lea ebx, [ebp - 0x20] mov eax, 0 add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x65 push eax push eax lea ebx, [ebp - 0x20] mov eax, 1 add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x6c push eax push eax lea ebx, [ebp - 0x20] mov eax, 2 add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x6c push eax push eax lea ebx, [ebp - 0x20] mov eax, 3 add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x6f push eax push eax lea ebx, [ebp - 0x20] mov eax, 4 add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x2c push eax push eax lea ebx, [ebp - 0x20] mov eax, 5 add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x20 push eax push eax lea ebx, [ebp - 0x20] mov eax, 6 add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x77 push eax push eax lea ebx, [ebp - 0x20] mov eax, 7 add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x6f push eax push eax lea ebx, [ebp - 0x20] mov eax, 8 add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x72 push eax push eax lea ebx, [ebp - 0x20] mov eax, 9 add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x6c push eax push eax lea ebx, [ebp - 0x20] mov eax, 0xa add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x64 push eax push eax lea ebx, [ebp - 0x20] mov eax, 0xb add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0x21 push eax push eax lea ebx, [ebp - 0x20] mov eax, 0xc add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0xa push eax push eax lea ebx, [ebp - 0x20] mov eax, 0xd add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0 push eax push eax lea ebx, [ebp - 0x20] mov eax, 0xe add ebx, eax pop eax pop eax mov byte [ebx], al mov eax, 0 push eax lea ebx, [ebp - 0x24] pop eax mov dword [ebx], eax mov eax, dword [ebp - 0x24] push eax mov eax, 0xa mov ecx, eax pop eax xor edx, edx cmp eax, ecx jge 0x202 xor eax, eax inc eax jmp 0x204 xor eax, eax test eax, eax je 0x256 mov eax, dword [ebp - 0x24] push eax mov eax, 2 mov ecx, eax pop eax xor edx, edx idiv ecx mov eax, edx push eax mov eax, 0 mov ecx, eax pop eax xor edx, edx cmp eax, ecx jne 0x232 xor eax, eax inc eax jmp 0x234 xor eax, eax cmp eax, 0 je 0x245 lea eax, [ebp - 0x20] push eax call 0x52 add esp, 4 mov eax, 1 push eax lea ebx, [ebp - 0x24] pop eax add dword [ebx], eax jmp 0x1eb mov esp, ebp pop ebp ret About Programming language that compiles into a x86 ELF executable. Topics programming-language Resources Readme License BSD-3-Clause License Releases No releases published Packages 0 No packages published Languages * C 99.9% * Shell 0.1% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.