Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 'entrypoint' directive tells the compiler which function or static method will be starting point of the program
- #entrypoint SomeNamespace.class ^ main
- // or probably in some next version you could just call given function or method directly like that?:
- // SomeNamespace.class ^ main
- // namespace keeps any identifiers bound to given scope
- &SomeNamespace
- // declare some variable
- $a:int
- // you can also define initial value of given variable during it's declaring
- $b:int = 0
- // at this point arrays can be only used with fixed items count
- // (in next version there will be a special 'string' class for strings implemented on standard library side)
- $c:byte[3] = "hi"
- // copying value to another variable is done by using '\' symbol
- // (by default when you assign one object to another it's done just by copying references)
- a = \b
- // function that just returns some integer value
- // '<-' symbol is used to return values (functions and methods of type 'void' does not use this symbol)
- @doNothing:int ->
- <- 10
- // define class
- %class
- // class fields (for now everything is public, but i need to design proper way of fields and methods accessibility)
- $a:int = 1
- $b:float = 0.5
- $c:byte[13]
- // constructor method - we provide arguments layout after '->' symbol in the way just like variables
- // ('.c' means that we are using 'c' field of calling object)
- * -> $text:byte[10]
- .c = text
- // destructor method
- ~ ->
- .a = 0
- .b = 0.0
- .c = ""
- // typical method with arguments provided at calling point
- @add:float -> $a:int, $b:float
- <- a + b
- // method with arguments bound to given context
- // ('a' and 'b' fields of calling object are used as 'a' and 'b' arguments)
- @sub:float -> a, b
- <- a - b
- // typical method without arguments
- @mul:float ->
- <- .a * .b
- // methods and functions of type 'void' (without type) does not use ':type' suffix
- // use '|' prefix to mark field or method as static
- // (in this case entry point can be only a global function or static method)
- |@main ->
- // create new object of type 'class'
- $someObj:class = *class -> "hello world!"
- // make a copy of 'someObj' object reference
- $obj:class = someObj
- // dereference 'someObj' object - mark as ready to be deleted
- // (in this case it will be dereferenced because 'obj' object is still holding reference to this object)
- ~someObj
- // call method 'add' of object 'obj' with it's 'a' and 'b' fields as arguments
- $r0:float = obj ^ add -> obj.a, obj.b
- // now call method 'sub' but without arguments
- // (we declared context-bound arguments for this method so they will be passed automatically)
- $r1:float = obj ^ sub
- // and here we call method without arguments because we are using fields of calling object directly in this method
- $r2:float = obj ^ mul
- // and now we dereference 'obj' object and mark it's data to be deleted
- // (because now no one object has reference to it's data so it will be immediatelly deleted - magic of smart pointers)
- ~obj
- // 'debug' directive means that we wants to show something in debug console
- #debug "add: " + $r0
- #debug "sub: " + $r1
- #debug "mul: " + $r2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement