documentation for Blend, a programming language

id: 749669

category: Show and Tell

posts: 4

morveman morveman loading
(If you see english mistakes please don't correct me: I have no respect for that language (just kidding please tell me, thanks))

If you have any question I can try to help you… but I'm not sure to be able to answer…

Hi, yes I made another (bad) programming language (10,000 ops/s on scratch and 500,000 on Turbowarp), this one fixes the bugs from Mount Down (memory allocations errors mainly) and allow for a smoother use of imports

To start of, Bend is really close to Mount Down (since it's purpuse was to fixing it) and C so you'll have to type your variables…

This language is case sensitive so Hello != hEllO

You should use ‘;’ at the end of each lines since it allow to reset registers and so go way faster (if you don't their is nothing that will stop you)

/!\ Strings are stored as numbers (for exemple “a” is 098) so by doing (int)“a” you get 98 and by doing (string)98 you get “a” !!
main function
> Your program must contains the main function which will tell the code output (for exemple code=0 means everythings ok)

Comments:
> you can use comments using the /* and */

Types:
> there is 4 built-in types: int, float, string and void
- int like 3, 8, -78
- float like 5.9, -2.1, 9.
- string like “Hello”, “math” (note that strings are stored as numbers in ASCII (“a” become 098)) you can use “\<ASCII code>” to access a specific character (like the non-printable (“\0” is the EOF for exemple))
- void : can be replaced by anything in functions arguments (you should probably not use it)

> pointers:
- you can make pointers of any types using the ‘_’ delimiter: <type>_<pointer depth> <name> (for exemple: int_2 is a pointer to a pointer to an int)

> you can create your own using the deftype keyword:
struct <name> {
attribute {
<type> <attr name>;

}
}

Binary Operations:
> +, -, *, /, % on int and float
> * on strings (string concatenation)
> &&, || the and and or operation
> ==, != on int, float, strings and pointers
> <=, >=, >, < on int, float and pointers
> . to access attributes of a structure

Unary Operations:
> * on pointers to access the value pointed
> & to access the memory address of a variable
> +, - on int and float to change the sign
> ++, – on int to increment or decrement

Strings and Array manipulations
to create an array see in the memory allocation
> to access an element or a letter in a string you can use square brackets

Functions and variables
> create a variable using: <type> <name> (= <value>)
> re-assign them using: <name> = <value> and access the value with the name

> create a function using: <return type> <name>(<arg type> <arg name>, …) { … }
> you can return a value using the return keyword: return <value>;
> recursion is possible (but slower than loops)

Loops and conditions
> use the if statement exactly like in C same for the while: while (<cond>) { … } and if (<cond>) { … } (else { … })

Trans-Typing
> when using a variable you might want it to become another type, the use the (<type>) feature:
> for exemple if you want the ‘a’ variable to become an int you do: (int)a or a pointer to a string: (string_1)a
> this can be used with functions (<type>)<func name>(<args>) (ex: (int_1)malloc(1, 8)

Modules
> to import a module you must use the #include <name> (as <name2>) (note that the ‘<’, ‘>’ are actually needed here)
> you can use functions and variables defined inside the module using: <module name>.<function>(<args>) or <module name>.<variable>
> note that if module a import module b then you can use the features inside module b with <module a>.<module b>.<feature>
> built-in modules are listed furter

Memory management
> this programming language is made to be able to manipulate memory
> to use memory you should import the std module: #include <std> which is composed of:
- void_1 std.malloc(int <item size>, int <number>) (you should use the sizeof function to get the size) which return an array of <number> items of type <item>
. this function must (?) be used with the trans-type feature (ex: int_1 tab = (int_1)std.malloc(sizeof(int), 21); )

- void std.free(void_1 <pointer>) this free the memory adress pointed by the pointer (if it is an array then the entier array is free)

- int sizeof(<type>) return the size of a type

Modules list
> math
- functions: exp, ln, cos, sin, tan, acos, asin, atan, sqrt, abs, floor, ceil, round, pow

> std
- functions: malloc, free
- variables: NULL

> graphics
- functions: erase(), setColor(int r, int g, int b), text(string, float x, float y, float size, string center),
line(float x1, float y1, float x2, float y2), filleTri(x1, y1, x2, y2, x3, y3, float res), update()

> input
- functions: mouseDown, mousex, mousey, keyPressed

> time
- functions: daysince2000, resetTimer, timer
- variables: TIMER

> random
- functions: float random, int randint(int, int), int randrange(int, int)

> exception
- functions: raise
- variables: (all strings) NameError, TypeError, SignError , DivisionByZeroError, IndexError, FileError,
SyntaxError, CharError, OrderError, ImplementationError, UnknownError, ScopeError, MemoryError

> basics
- functions printf, newline, toUnicode, ask, toInt, length

Built-in functions
> all the built-in functions can be imported from a module (modules are mainly built-in functions)
> however you can get them directly using: #using { <name>, … } and if you are making a module and don't want people to use them outside you can use the local or global attribute: #using { local <name, global <name2> }

Creating your own module
> first if you want to be able to import the module you must add it to the FILE list with: // name for the first item and then your code
> else you can use the advantage of a module using: module <name> { … } which will create a local script where you can
call functions or variables outside using <module name>.<feature>

Errors
> There is nothing to say about that except that they are basicly useless and the line provided is never the right one you should still use it as an help even if it's not really one…


Here are exemples of code (save code at the end):
/* Here's a complex implementation: */

struct Complex {
attribute {
float reel;
float im;
}
}

Complex add(Complex a, Complex b) {
Complex c;
c.reel = a.reel + b.reel;
c.im = a.im + b.im;
return c;
}

Complex neg(Complex a) {
a.reel = -a.reel;
a.im = -a.im;
return a;
}

Complex sub(Complex a, Complex b) {
return add(a, neg(b));
}

Complex mult(Complex a, Complex b) {
Complex c;
c.reel = a.reel * b.reel - a.im * b.im;
c.im = a.reel * b.im + a.im * b.im;
return c;
}

Complex inv(Complex a) {
float m = a.reel * a.reel + a.im * a.im;
a.reel = a.reel / m;
a.im = -a.im / m;
return a;
}

Complex divide(Complex a, Complex b) {
return mult(a, inv(b));
}

Complex modulus(Complex a) {
return math.sqrt(a.reel * a.reel + a.im * a.im);
}

int main() { return 0; }
The save code:
/* Here's a complex implementation: */§§deftype Complex {§    attribute {§        float reel;§        float im;§    }§}§§Complex add(Complex a, Complex b) {§    §Complex c;§    c.reel = a.reel + b.reel;§    c.im = a.im + b.im;§    return c;§}§§Complex neg(Complex a)  {§    a.reel = -a.reel;§    a.im = -a.im;§    return a;§}§§Complex sub(Complex a, Complex b) {§    return add(a, neg(b));§}§§Complex mult(Complex a, Complex b) {§    Complex c;§    c.reel = a.reel * b.reel - a.im * b.im;§    c.im = a.reel * b.im + a.im * b.im;§    return c;§}§§Complex inv(Complex a) {§    float m = a.reel * a.reel + a.im * a.im;§    a.reel = a.reel / m;§    a.im = -a.im / m;§    return a;§}§§Complex divide(Complex a, Complex b) {§    return mult(a, inv(b));§}§§Complex modulus(Complex a) {§    return math.sqrt(a.reel * a.reel + a.im * a.im);§}§§int main() { return 0; }§
pitmiwi pitmiwi loading
Got this Vector library, for some reason it doesn't compile:

§/*§ Vector library§*/§#include <math>§§struct Vector2{§ attribute{§ float x;§ float y;§ }§}§§/*§ operators§*/§Vector2 Add(Vector2 a, Vector2 b){§ Vector2 result;§ result.x = a.x + b.x;§ result.y = a.y + b.y;§ return result;§}§Vector2 Sub(Vector2 a, Vector2 b){§ Vector2 result;§ result.x = a.x - b.x;§ result.y = a.y - b.y;§ return result;§}§Vector2 Mul(Vector2 a, Vector2 b){§ Vector2 result;§ result.x = a.x * b.x;§ result.y = a.y * b.y;§ return result;§}§Vector2 Div(Vector2 a, Vector2 b){§ Vector2 result;§ result.x = a.x / b.x;§ result.y = a.y / b.y;§ return result;§}§float Dot(Vector2 a, Vector2 b){§ float dot = a.x * b.x + a.y * b.y;§ return dot;§}§float Magnitude(Vector2 a){§ float result = math.sqrt(a.x * a.x + a.y * a.y);§ return result;§}§§/*§ Multiple vector operations§*/§float GetDistance2(Vector2 a, Vector2 b){§ Vector2 reference = Sub(b,a);§ float result = Magnitude(reference);§ return result;§}§§int main {return 0;}§
morveman morveman loading

pitmiwi wrote:

Got this Vector library, for some reason it doesn't compile:

I got it : you forgot the ‘()’ for the main function (I don't know why you did not get an error…) but here it is :
§§/*§    Vector library§*/§#include <math>§§struct Vector2{§    attribute{§        float x;§        float y;§    }§}§§/*§    operators§*/§Vector2 Add(Vector2 a, Vector2 b){§    Vector2 result;§    result.x = a.x + b.x;§    result.y = a.y + b.y;§    return result;§}§Vector2 Sub(Vector2 a, Vector2 b){§    Vector2 result;§    result.x = a.x - b.x;§    result.y = a.y - b.y;§    return result;§}§Vector2 Mul(Vector2 a, Vector2 b){§    Vector2 result;§    result.x = a.x * b.x;§    result.y = a.y * b.y;§    return result;§}§Vector2 Div(Vector2 a, Vector2 b){§    Vector2 result;§    result.x = a.x / b.x;§    result.y = a.y / b.y;§    return result;§}§float Dot(Vector2 a, Vector2 b){§    float dot = a.x * b.x + a.y * b.y;§    return dot;§}§float Magnitude(Vector2 a){§    float result = math.sqrt(a.x * a.x + a.y * a.y);§    return result;§}§§/*§    Multiple vector operations§*/§float GetDistance2(Vector2 a, Vector2 b){§    Vector2 reference = Sub(b,a);§    float result = Magnitude(reference);§    return result;§}§§int main() {return 0;}§
pitmiwi pitmiwi loading

morveman wrote:

I got it : you forgot the ‘()’ for the main function (I don't know why you did not get an error…) but here it is :

Oh thanks!
Not having errors show up in vs code makes it quite difficult to catch these