-
-
Notifications
You must be signed in to change notification settings - Fork 0
Docs
_ __ __
| | / /_ _______/ /_
| | /| / / / / / ___/ __ \
| |/ |/ / /_/ (__ ) /_/ /
|__/|__/\__, /____/_.___/
/____/
Wysb is a statically typed programming language designed to offer a range of powerful features for both simple and complex applications. It combines the flexibility of Python with optimizations and additional functionalities for performance and safety. This documentation provides a comprehensive guide to the syntax, features, and usage of Wysb, as well as the tools provided by its compiler.
Wysb is designed to be both robust and user-friendly. It includes a set of built-in functionalities for mathematical operations, type checking, file handling, and more. The compiler translates Wysb code into Python, leveraging the power of Python's ecosystem while providing additional optimizations through Numba.
Wysb supports the following types:
-
int32
: 32-bit integer -
int64
: 64-bit integer -
float32
: 32-bit floating-point number -
float64
: 64-bit floating-point number -
bool
: Boolean value (True or False) -
string
: String of characters -
uint
: Unsigned integer (non-negative integer) -
char
: Single character
Creating Variables:
myVar: int32 = 10
myConst: float32 = 3.14
Assigning Values:
myVar = 20
Functions are defined using the !func
keyword.
Syntax:
!func myFunction(param1 : int32, param2 : float64) -> float64:
# Function body
Example:
!func addNumbers(a : int32, b : int32) -> int32:
return a + b
Resource filtering is used to make smarter and faster use of the device's memory, CPU and GPU. It can use more processing, and works more efficiently in calculation-intensive functions. It makes your function up to 50x faster, using the full power of the language.
Example:
@wysb.resfilt
!func addNumbers(a : int32, b : int32) -> int32:
return a + b
Conditional Statements:
if condition:
# code to execute
else:
# code to execute if condition is false
Loops:
for i = 0 to 10:
# code to execute
Classes are created using the !class
keyword.
Syntax:
class MyClass
!func __init__(self, value : int32)
self.value = value
!func getValue() : int32
return self.value
Exceptions are handled using !try
and !catch
blocks.
Syntax:
try
# code that may throw an exception
catch (e)
# code to handle the exception
Wysb performs type checking to ensure that values conform to their expected types. It supports several types including integers, floats, booleans, strings, unsigned integers, and characters.
Memory can be allocated using the allocate_memory(size)
method, which returns a bytearray
of the specified size.
The compiler provides methods for creating, reading, updating, and deleting files.
Syntax:
file_crud('create', 'file.txt', 'Hello, World!')
file_crud('read', 'file.txt')
Modules can be imported using the import_module
method or custom Wysb modules using import_wysb_module
.
Wysb code can be executed directly or converted into an executable file using PyInstaller.
Convert to Executable:
compiler.convert_to_executable('myfile.wysb', 'myfile')
The Wysb compiler provides a command-line interface for running or converting Wysb files.
Usage:
python wysb_compiler.py run <file>
python wysb_compiler.py convert <file> --output <output_file>
-
run
: Executes the Wysb file. -
convert
: Converts the Wysb file into an executable.
Example 1: Basic Wysb Program
x: int32 = 10
y: int32 = 20
!func add(a : int32, b : int32) : int32
return a + b
print(add(x, y))
Example 2: Class Definition and Usage
class Person
!func __init__(self, name : string, age : int32)
self.name = name
self.age = age
!func get_name() : string
return self.name
p = Person('Alice', 30)
print(p.get_name())
-
Compiler Class:
WysbCompiler
provides methods for various operations such as type checking, memory allocation, file handling, and more. -
Optimization: The
@njit
decorator from Numba is used to optimize function execution and loops.