Giter VIP home page Giter VIP logo

bah's Introduction

Bah-lang

Installation

Note that Windows and MacOS (darwin) releases may be delayed compared to Linux releases.

To install bah on your machine, get the terminal warmed up 🔥 , stretch your fingers up 🏋‍♂ and paste this 😎:

Linux

Note that if you have pacman/apt installed on your system, gcc and such will be automatically installed.

git clone https://github.com/ithirzty/bah
cd ./bah
sudo ./linux_install.sh

If the installation fails for whatever reason, you will need to recompile the Bah compiler before installing it. Dont worry this is simple, simply run:

sudo ./linux_compile_install.sh

Windows

Please make sure that you have mingw gcc installed.

For the newbies, READ CAREFULLY. More help HERE

  1. Install MinGW.
  2. In the MinGW installation manager, select:
    • MinGW Base System: MinGW base,
    • MinGW libraries: mingw32-pthreads-w32 (or pthread equivalent).
  3. Click on the 'installation' menu and selct 'apply changes'.
  4. Clone this repository (download it).
  5. Open an administrator shell (cmd.exe).
  6. Execute windows_install.bah as administrator.
git clone https://github.com/ithirzty/bah
cd ./bah
.\windows_install.bat

If the installation fails for whatever reason, you will need to recompile the Bah compiler before installing it. Dont worry this is simple, simply run:

.\windows_compile_install.bat

MacOS (darwin)

git clone https://github.com/ithirzty/bah
cd ./bah
.\darwin_install.bat

If the installation fails for whatever reason, you will need to recompile the Bah compiler before installing it. Dont worry this is simple, simply run:

.\darwin_compile_install.bat

Note: yoy may need to run the following command after install if the version is Bah compiler is out of date clang -I "/opt/bah/libs/darwin/include/" -L "/opt/bah/libs/darwin/" ./installer/darwin.c -O1 -w -lgc -lpthread -lm -o /opt/bah/bah

More?

Yeah, there is more. You can also install the Bah extension for VS Code:

Updating

To update, execute the following:

./linux_update.sh

If the repository is updated, this script will pull the main branch and install everything.

Usage

Files containing bah code have the .bah extenstion.

  • To compile your program, use bah <file> <flags> (example: bah main.bah).
Usage of bah:
    -o (string)
        Name of the file to output.
    -c (bool)
        Translate bah file to C instead of compiling it.
    -v (bool)
        Show version of the compiler.
    -l (bool)
        Compile as a library.
    -object (bool)
        Compile as an object.
    -n (bool)
        Disables notices while keeping warnings enabled.
    -d (bool)
        Compile as a dynamic executable. (useful if you are using a library that is only available shared but might reduce portability).
    -target (string)
        Select the target OS for cross compilling (linux, windows, darwin), default: linux.
    -bahDir (string)
        If your Bah directory is not the default one (/opt/bah/).
    -CC (string)
        To change the C compiler used, default: gcc.
    -unsafe (bool)
        Compile without safety checking. This will make for faster executable but if your program crashes, it will show less informations.
    -nobuiltin (bool)
        Does not include the builtin library (be really carefull, your program WILL break).
    -optimize (bool)
        Includes optimized functions
    -rcp (bool)
        Enables RCP (reference counter) instead of the garbage collector. Warning: if you are using self-reference, this will lead to memory leaks!
    -fastrcp (bool)
        Enables RCP without leak detection. It is recommended to test you programs with the -rcp flag to test for leak detection before using this flag.
    -lightGC (bool)
        Enables the really light weight with no dependecy garbage collector. This one is not as complex as the default one, it is though not as robust.
    -nativeMem (bool)
        Disable any memory management. WARNING: this will cause insane memory leaks.
    -fixMe (bool)
        Enables runtime debugging engine, useful for segfaults... Note that your program will be slower and use more memory, this is only a debug option.
    -debug (bool)
        Enables verbose json output.
    -verboseRuntime (bool)
        Enables verbose runtime, a debug mode of the compiled program. (obsolete)
    -verboseCC (bool)
        Enables verbose C compiler output, USE IN LAST RESORT.

Learning

Hello world:

hello world


Bah REPL, a simple way of learning Bah lang.


Why?

Bah is a really fast language with as little bloat as possible. Its simplicity lets you choose your level of abstraction (C like low level <-> Go like high level).

It has been used to create:

You did something awesome in bah? Add it to the list!

Awesome features

Bah also supports awesome features like:

  • reflection (approach similar to Go, enabling one line (to and from) JSON conversion),
  • reference counting (-rcp flag),
  • async calls (execute function call in a new thread),
  • channels, maps, arrays (useful builtin data structures),
  • runtime evaluation (for 'evaluating' function calls at runtime eval.bah),
  • embedded debugger (for setting breakpoints... ...GDB also works),
  • compile-time safety features (null value checker, static loop iterator...),
  • fixMe (cry for help when a segfault occurs),
  • let (let var = 'maybe values' else handle exception),
  • tuple (light-weight wrapper for multiple values with different types, useful for returning multiple values).

This enables you to do things that would be impossible in C such as scanning JSON content to a variable (event structs and arrays), and marshalling vars to JSON. All of that with a single function call!

Bah also has a garbage collector AND a reference counter. You can choose the one that fits your needs at compile time!

Imports and includes

When to use #import and #include?

#import isolates the specified file where #include will simply include it.
If the file to import needs the file that imports it, then importing it will fail.
For example, a.bah imports b.bah but b.bah needs a global variable defined in a.bah. Then, using #import instead of #include will fail.
On the other hand, a.bah needs iostream.bah. Iostream does not depend on a.bah. You can then import it.

More generally, if #import fail, use #include that cannot fail.
Note that using import reduce compilation time because of its use of the cache.

How does it work?

Information on how a Bah compiler should operate can be found here (outdated).

bah's People

Contributors

ithirzty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

123ahaha

bah's Issues

could not compile

does bah support musl libc? I get this build error:

CC tcc
C compiler: tcc
Parsed. (2138 lines, total time: 16ms, lexer time: 4ms)
[CC-ERROR]
Could not compile.

while compiling this bah code:

#import "iostream.bah"

main(args []cpstring) int {

    println("merhaba dünya")
    return 0
}

Edit: translated to c and gcc seem to have error compiling it:

/opt/bah/builtin.bah: In function 'print':
/opt/bah/builtin.bah:93:7: warning: passing argument 1 of 'write' makes integer from pointer without a cast [-Wint-conversion]
93 | write(1, s, len(s))
| ^~~~~~~~~
| |
| void *
In file included from /opt/bah/builtin.bah:80:
/usr/include/unistd.h:51:15: note: expected 'int' but argument is of type 'void *'
51 | ssize_t write(int, const void *, size_t);
| ^~~
/opt/bah/gc.bah: In function 'cleanShutDown':
/opt/bah/gc.bah:53:1: warning: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
53 | exit(1)
| ^
/opt/bah/gc.bah:30:1: note: include '<stdlib.h>' or provide a declaration of 'exit'
29 | //The allocated memory cannot be shared by multiple processes. Use the sharedMemory() function instead.
+++ |+#include <stdlib.h>
30 | memoryAlloc(s int) ptr {
/opt/bah/gc.bah:53:1: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
53 | exit(1)
| ^
/opt/bah/gc.bah:53:1: note: include '<stdlib.h>' or provide a declaration of 'exit'
/opt/bah/gc.bah: In function 'memoryAllocSTR':
/opt/bah/gc.bah:85:20: warning: initialization of 'unsigned int *' from incompatible pointer type 'char ' [-Wincompatible-pointer-types]
85 | ln uint32
= r
| ^
/opt/bah/memory.bah: At top level:
/opt/bah/memory.bah:108: warning: "MAP_SHARED" redefined
108 | const MAP_SHARED = 1
|
In file included from /opt/bah/builtin.bah:99:
/usr/include/sys/mman.h:21: note: this is the location of the previous definition
21 | #define MAP_SHARED 0x01
|
/opt/bah/memory.bah:109: warning: "MAP_ANONYMOUS" redefined
109 | const MAP_ANONYMOUS = 32
|
/usr/include/sys/mman.h:27: note: this is the location of the previous definition
27 | #define MAP_ANONYMOUS MAP_ANON
|
/opt/bah/memory.bah: In function 'delete':
/opt/bah/memory.bah:191:21: warning: initialization of 'void *' from 'long long int' makes pointer from integer without a cast [-Wint-conversion]
191 | destOffset ptr = elemSize * i
| ^~~~~~~~
/opt/bah/memory.bah:193:17: warning: initialization of 'void *' from 'long long int' makes pointer from integer without a cast [-Wint-conversion]
193 | offset ptr = elemSize * i
| ^~~~~~~~
/opt/bah/memory.bah:194:13: warning: initialization of 'char ' from 'long long int' makes pointer from integer without a cast [-Wint-conversion]
194 | src char
= data + offset
| ^
/opt/bah/memory.bah:195:14: warning: initialization of 'char ' from 'long long int' makes pointer from integer without a cast [-Wint-conversion]
195 | dest char
= data + destOffset
| ^
/opt/bah/memory.bah: In function 'deleteRange':
/opt/bah/memory.bah:214:15: warning: initialization of 'void *' from 'long long int' makes pointer from integer without a cast [-Wint-conversion]
214 | dest ptr = data + elemSize * from
| ^
/opt/bah/memory.bah:215:14: warning: initialization of 'void *' from 'long long int' makes pointer from integer without a cast [-Wint-conversion]
215 | src ptr = dest + size + elemSize
| ^
/opt/bah/memory.bah: In function 'arrToStr':
/opt/bah/memory.bah:225:50: warning: comparison between pointer and integer
225 | if len(arr) > 0 && arr[len(arr)-1] == null {
| ^
/opt/bah/memory.bah:231:20: warning: initialization of 'unsigned int *' from incompatible pointer type 'char ' [-Wincompatible-pointer-types]
231 | ln uint32
= str
| ^
/opt/bah/builtin.bah: In function 'buffToStr':
/opt/bah/builtin.bah:111:27: warning: initialization of 'unsigned int ' from incompatible pointer type 'char ' [-Wincompatible-pointer-types]
111 | ln uint32
= s
| ^
/opt/bah/builtin.bah: In function 'cStrToBah':
/opt/bah/builtin.bah:133:27: warning: initialization of 'unsigned int ' from incompatible pointer type 'char ' [-Wincompatible-pointer-types]
133 | ln uint32
= nstr
| ^
/opt/bah/builtin.bah: In function '__Bah_multiple_concat':
/opt/bah/builtin.bah:141:22: warning: implicit declaration of function 'alloca' [-Wimplicit-function-declaration]
141 | lens uint32
= alloca(l * sizeof(uint32)) //stack list of lengths
| ^~~~~~
/opt/bah/builtin.bah:141:22: warning: incompatible implicit declaration of built-in function 'alloca' [-Wbuiltin-declaration-mismatch]
/opt/bah/builtin.bah:161:27: warning: initialization of 'unsigned int ' from incompatible pointer type 'char ' [-Wincompatible-pointer-types]
161 | ln uint32
= r
| ^
/opt/bah/builtin.bah: In function '__STR':
/opt/bah/builtin.bah:192:27: warning: initialization of 'unsigned int ' from incompatible pointer type 'char ' [-Wincompatible-pointer-types]
192 | ln uint32
= r
| ^
/opt/bah/builtin.bah: In function '__checkString':
/opt/bah/builtin.bah:208:68: warning: incompatible implicit declaration of built-in function 'alloca' [-Wbuiltin-declaration-mismatch]
208 | print("cpstring ("+l+") is null \n")
| ^
/opt/bah/builtin.bah:209:8: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
209 | exit(1)
| ^ ~~
/opt/bah/builtin.bah:100:1: note: include '<stdlib.h>' or provide a declaration of 'exit'
99 | }
+++ |+#include <stdlib.h>
100 |
/opt/bah/thread.bah: In function 'thread__create':
/opt/bah/thread.bah:13:25: warning: implicit declaration of function 'GC_pthread_create'; did you mean 'pthread_create'? [-Wimplicit-function-declaration]
13 | const __thread_create = GC_pthread_create
| ^~~~~~~~~~~~~~~~~
/opt/bah/thread.bah:133:1: note: in expansion of macro '__thread_create'
133 | __thread_create(&this.id, null, this.handle, null)
| ^ ~~~~~~~
/opt/bah/thread.bah: In function 'thread__wait':
/opt/bah/thread.bah:14:23: warning: implicit declaration of function 'GC_pthread_join'; did you mean 'pthread_join'? [-Wimplicit-function-declaration]
14 | const __thread_join = GC_pthread_join
| ^~~~~~~~~~~~~~~
/opt/bah/thread.bah:144:1: note: in expansion of macro '__thread_join'
144 | __thread_join(this.id, null)
| ^ ~~~~~
/opt/bah/builtin.bah: In function 'fastExec':
/opt/bah/builtin.bah:264:34: warning: initialization of 'unsigned int ' from incompatible pointer type 'char ' [-Wincompatible-pointer-types]
264 | ln uint32
= response
| ^~~~
/opt/bah/builtin.bah: In function '__BAH_panic':
/opt/bah/builtin.bah:280:62: warning: incompatible implicit declaration of built-in function 'alloca' [-Wbuiltin-declaration-mismatch]
280 | print("panic ("+line+"): "+e+"\n")
| ^
/opt/bah/builtin.bah:297:40: warning: initialization of 'long long int' from 'void ' makes integer from pointer without a cast [-Wint-conversion]
297 | p int = arr[i]
| ^
/opt/bah/builtin.bah: In function '__Bah_segfault_handle':
/opt/bah/builtin.bah:340:62: warning: incompatible implicit declaration of built-in function 'alloca' [-Wbuiltin-declaration-mismatch]
340 | __BAH_panic("Memory error (segfault).\n"+res, "???")
| ^
/opt/bah/builtin.bah: In function '__Bah_init_segfaultHandle':
/opt/bah/builtin.bah:345:24: warning: passing argument 2 of 'signal' from incompatible pointer type [-Wincompatible-pointer-types]
345 | signal(noCheck(SIGSEGV), __Bah_segfault_handle)
| ^~~~~~~~~~~~~~~~~~~~~
| |
| void (
)(long long int)
In file included from merhaba.c:23:
/usr/include/signal.h:289:20: note: expected 'void (
)(int)' but argument is of type 'void (
)(long long int)'
289 | void (signal(int, void ()(int)))(int);
| ^~~~~~~~~~~~~
/opt/bah/builtin.bah: In function '__Bah_safe_string':
/opt/bah/builtin.bah:378:62: warning: incompatible implicit declaration of built-in function 'alloca' [-Wbuiltin-declaration-mismatch]
378 | return """+s+"""
| ^
/opt/bah/builtin.bah: In function '__Bah_realocate_arr':
/opt/bah/builtin.bah:400:69: warning: incompatible implicit declaration of built-in function 'alloca' [-Wbuiltin-declaration-mismatch]
400 | n: array append out of bounds violation, index = "+cStrToBah(<char
>indexStr)+" and len = "+cStrToBah(<char
>lengthStr)+". Can only append index=length.")
| ^~~~~~

/opt/bah/map.bah: In function 'mapNode__calc':
/opt/bah/map.bah:41:12: warning: comparison between pointer and integer
41 | if s[i] == null || this.str[i] != s[i] {
| ^~
/opt/bah/map.bah:45:29: warning: comparison between pointer and integer
45 | if i == this.strL && s[i] == null {
| ^~
/opt/bah/builtin.bah: In function 'strBuilder__append':
/opt/bah/builtin.bah:480:20: warning: initialization of 'unsigned int *' from incompatible pointer type 'char ' [-Wincompatible-pointer-types]
480 | ln uint32
= this.buff
| ^~~~
/opt/bah/iostream.bah: In function 'stdinput':
/opt/bah/iostream.bah:21:20: warning: passing argument 1 of 'read' makes integer from pointer without a cast [-Wint-conversion]
21 | nDataLength = read(0,buff,1024)
| ^~~~~~~~~
| |
| void *
/usr/include/unistd.h:50:14: note: expected 'int' but argument is of type 'void *'
50 | ssize_t read(int, void *, size_t);
| ^~~
/opt/bah/iostream.bah:36:20: warning: passing argument 1 of 'read' makes integer from pointer without a cast [-Wint-conversion]
36 | nDataLength = read(0,buff,1024)
| ^~~~~~~~~
| |
| void *
/usr/include/unistd.h:50:14: note: expected 'int' but argument is of type 'void *'
50 | ssize_t read(int, void *, size_t);
| ^~~
/opt/bah/iostream.bah: In function 'println':
/opt/bah/iostream.bah:61:333: warning: passing argument 1 of 'write' makes integer from pointer without a cast [-Wint-conversion]
61 | write(1, s+"\n", len(s)+1)
| ^
| |
| void *
/usr/include/unistd.h:51:15: note: expected 'int' but argument is of type 'void *'
51 | ssize_t write(int, const void *, size_t);
| ^~~
/ev/çizeylemcil/bah/merhaba.bah: In function '__BAH_init':
/ev/çizeylemcil/bah/merhaba.bah:381:29: warning: assignment discards 'volatile' qualifier from pointer target type [-Wdiscarded-qualifiers]
/an/duyum/etki/ld: /tmp/ccEjklla.o: in function main': merhaba.c:(.text+0x10): undefined reference to GC_init'
/an/duyum/etki/ld: /tmp/ccEjklla.o: in function memoryAlloc': merhaba.c:(.text+0x181): undefined reference to GC_malloc'
/an/duyum/etki/ld: /tmp/ccEjklla.o: in function destroy': merhaba.c:(.text+0x19b): undefined reference to GC_free'
/an/duyum/etki/ld: /tmp/ccEjklla.o: in function memoryRealloc': merhaba.c:(.text+0x1e0): undefined reference to GC_realloc'
/an/duyum/etki/ld: /tmp/ccEjklla.o: in function memoryOnEnd': merhaba.c:(.text+0x220): undefined reference to GC_register_finalizer_ignore_self'
/an/duyum/etki/ld: /tmp/ccEjklla.o: in function memoryAllocSTR': merhaba.c:(.text+0x2f4): undefined reference to GC_malloc'
/an/duyum/etki/ld: /tmp/ccEjklla.o: in function thread__create': merhaba.c:(.text+0x10c3): undefined reference to GC_pthread_create'
/an/duyum/etki/ld: /tmp/ccEjklla.o: in function thread__createWithArg': merhaba.c:(.text+0x10f8): undefined reference to GC_pthread_create'
/an/duyum/etki/ld: /tmp/ccEjklla.o: in function thread__wait': merhaba.c:(.text+0x1120): undefined reference to GC_pthread_join'
/an/duyum/etki/ld: /tmp/ccEjklla.o: in function __BAH_panic': merhaba.c:(.text+0x1c08): undefined reference to backtrace'
collect2: error: ld returned 1 exit status

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.