Extra Features - BBpezsgo/BBLang GitHub Wiki

Extra Features

temp modifier

You can use the temp modifier if you don't want to mess with the delete keyword. The temp modifier can be applied to variables and parameters.

temp modifier on variables

If you define a variable with the temp modifier, it will be automatically deallocated when goes out of scope.


void main()
{
  // Allocate an integer on the heap
  temp i32* value = new i32*;
  // Random calculations
  *value = 64;
  *value -= 3;

  // The value will be deallocated here
}

temp modifier on parameters

If you define a parameter with the temp keyword, sometimes it can be used to automatically deallocate the value.

void print(temp u16[]* text)
{
  // Stuff ...
}

Pr

External Functions

External functions are functions that only have the function signature defined and the body written somewhere in C#. They often used to implement APIs.

To import an external function, use the External attribute with the external function's name as a parameter:

[External("stdout")]
void print(u16 data);

If the return type or parameter types don't match, a compiler error will be made.

Predefined External Functions

[!NOTE] These external functions are only available in default mode.

  • "stdin"

    Reads a key from the console. This blocks the code execution until a key is pressed.

    • Parameters: none
    • Return type: u16

    Corresponding .NET function:

    return (char)System.Console.In.Read();
    
  • "stdout"

    Writes a character to the standard output stream.

    • Parameters: u16 character
    • Return value: void

    Corresponding .NET function:

    System.Console.Out.Write(character);
    
  • "utc-time"

    Returns the elapsed milliseconds since midnight in UTC time.

    • Parameters: none
    • Return value: i32

    Corresponding .NET function:

    return (int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds;
    
  • "local-time"

    Returns the elapsed milliseconds since midnight in local time

    • Parameters: none
    • Return value: i32

    Corresponding .NET function:

    return (int)DateTime.Now.TimeOfDay.TotalMilliseconds;
    
  • "utc-date-day"

    Returns the current day of year in UTC time

    • Parameters: none
    • Return value: i32

    Corresponding .NET function:

    return (int)DateTime.UtcNow.DayOfYear;
    
  • "local-date-day"

    Returns the current day of year in local time

    • Parameters: none
    • Return value: i32

    Corresponding .NET function:

    return (int)DateTime.Now.DayOfYear;
    
  • "utc-date-year"

    Returns the current year in UTC time

    • Parameters: none
    • Return value: i32

    Corresponding .NET function:

    return (int)DateTime.UtcNow.Year;
    
  • "local-date-year"

    Returns the current year in local time

    • Parameters: none
    • Return value: i32

    Corresponding .NET function:

    return (int)DateTime.Now.Year;