Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfriend99 committed Oct 28, 2024
2 parents df5f591 + 7ba4f97 commit e8835ba
Show file tree
Hide file tree
Showing 25 changed files with 156 additions and 125 deletions.
57 changes: 57 additions & 0 deletions examples/arm_jit.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* ARM64 JIT compilation example.
*/


# -------------- STANDARD IMPLEMENTATION BEGINS ----------------------------

def square2(x) {
var y = 0
for i in 0..1000000 {
y += x
}
return y
}

var start = microtime()
echo square2(9)
echo 'Default: ${(microtime() - start)} microseconds'

# -------------- STANDARD IMPLEMENTATION ENDS ------------------------------

# ------------------- JIT IMPLEMENTATION BEGINS ----------------------------

import process
import clib
import convert

var code_address = process.PagedValue(true, true)

# long square(long num) {
# long y = 0;
# for(int i = 0; i < 1000000; i++) {
# y += num;
# }
# return y;
# }
# gcc -g -O3 arm64
# square:
# mov x1, #0x4240
# movk x1, #0xf, lsl #16
# mul x0, x0, x1
# ret
var data = convert.hex_to_bytes(hex(0xd2884801))
data.extend(convert.hex_to_bytes(hex(0xf2a001e1)))
data.extend(convert.hex_to_bytes(hex(0x9b017c00)))
data.extend(convert.hex_to_bytes(hex(0xd65f03c0)))

code_address.set(data)

var square3 = clib.function_handle(code_address.raw_pointer(), clib.long, clib.long)

start = microtime()
echo square3(9)
echo 'JITed: ${(microtime() - start)} microseconds'

# ------------------- JIT IMPLEMENTATION ENDS ------------------------------

29 changes: 29 additions & 0 deletions examples/smtp_mail.b
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* This example sends an email with itself as a file attachment.
*/

# Change the MY_* to their correct values.

import mail

var smtp = mail.smtp({
host: 'MY_SMTP_HOST', # e.g. smtp.gmail.com
username: 'MY_SMTP_USERNAME', # usually your email address
password: 'MY_SMTP_PASSWORD',
})

echo smtp.add_message(mail.message().
to('MY_MAIL_RECIPIENT'). # change to the correct value
subject('Testing a very new transmission').
html(
'Hi,'+
'<br><br>'+
'If you are receiving this mail, know that it was sent '+
'with the <strong>mailer</strong> library for '+
'<a href="https://bladelang.org">Blade programming language</a>.' +
'<br><br>' +
'Sincerely,<br>' +
'The Blade Community'
).
attachment(__file__, 'smtp_mail.b')
).send()
61 changes: 0 additions & 61 deletions examples/socket.b

This file was deleted.

8 changes: 6 additions & 2 deletions examples/vim.b
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* This example shows the implementation of a simple rudimentary vim
* like editor for Blade with syntax highlighting.
*/
import io

# simple test
Expand Down Expand Up @@ -114,6 +118,6 @@ while s = io.stdin.read() {
}

# Clear the terminal (classic Nano and Vim style)
io.stdout.write("\x1b[2J");
io.stdout.write("\x1b[H");
io.stdout.write("\x1b[2J")
io.stdout.write("\x1b[H")
io.stdout.flush()
14 changes: 8 additions & 6 deletions libs/args.b
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ def _get_real_value(item, value) {
else if item.type == STRING return to_string(value)
else if item.type == LIST return is_list(value) ? value : [value]
else if item.type == CHOICE {
if is_list(item.choices)
return item.choices.contains(value) ? value : value
else return item.choices.contains(value) ? item.choices[value] : value
if is_list(item.choices) {
return item.choices.contains(value) ? value : value
} else {
return item.choices.contains(value) ? item.choices[value] : value
}
}
return value
}
Expand Down Expand Up @@ -513,7 +515,7 @@ class Parser < _Optionable {

line += self._opt_line(opt)

# We want to separate the longtest option names at least 12
# We want to separate the longest option names at least 12
# characters away from the help texts.
line = line.rpad(width + 5)

Expand All @@ -528,7 +530,7 @@ class Parser < _Optionable {

line += self._opt_line(cmd)

# We want to separate the longtest option names at least 12
# We want to separate the longest option names at least 12
# characters away from the help texts.
line = line.rpad(width + 20)

Expand Down Expand Up @@ -663,7 +665,7 @@ class Parser < _Optionable {
* blade test.b install 5 --verbose
* ```
*
* may yeild such a result as similar to the one below.
* may yield such a result as similar to the one below.
*
* ```
* {options: {verbose: true}, command: {name: install, value: 5}}
Expand Down
2 changes: 1 addition & 1 deletion libs/array.b
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @module array
*
* This moddule provides multiple classes for working with arrays of twos-complement
* This module provides multiple classes for working with arrays of twos-complement
* integers in the platform byte order. The classes provided in this module complement
* the _bytes()_ object and allow higher other binary data manipulation.
*
Expand Down
2 changes: 1 addition & 1 deletion libs/colors.b
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def rgb_to_xyz(r, g, b) {
y = (r * 0.2126729) + (g * 0.7151522) + (b * 0.072175),
z = (r * 0.0193339) + (g * 0.119192) + (b * 0.9503041)

return [x * 100, y * 100, z * 100];
return [x * 100, y * 100, z * 100]
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libs/date.b
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class Date {
}

/**
* Returns the number of days in the year preceeding the first
* Returns the number of days in the year preceding the first
* day of the month.
*
* Example,
Expand Down
32 changes: 16 additions & 16 deletions libs/hash.b
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def whirlpool(str) {
}

/**
* Returns the snefru cyrptographic hash of the given string or bytes.
* Returns the Snefru cryptographic hash of the given string or bytes.
*
* @param string|bytes str
* @returns string
Expand All @@ -223,7 +223,7 @@ def snefru(str) {
}

/**
* Returns the siphash cyrptographic hash of the given string or bytes.
* Returns the SipHash cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -236,9 +236,9 @@ def siphash(key, str) {
raise Exception('str must be string or bytes')
}

if key.length() > 16
if key.length() > 16 {
raise Exception('key must be maximum of 16 characters/bytes long')
else if key.length() < 16 {
} else if key.length() < 16 {
if is_bytes(key) key = key.to_string()
key = key.rpad(16, '\0')
}
Expand All @@ -250,7 +250,7 @@ def siphash(key, str) {
}

/**
* Returns the gost cyrptographic hash of the given string or bytes.
* Returns the Gost cryptographic hash of the given string or bytes.
*
* @param string|bytes str
* @returns string
Expand Down Expand Up @@ -311,7 +311,7 @@ def hmac(method, key, str) {
}

/**
* Returns the HMAC-MD2 cyrptographic hash of the given string or bytes.
* Returns the HMAC-MD2 cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -322,7 +322,7 @@ def hmac_md2(key, str) {
}

/**
* Returns the HMAC-MD4 cyrptographic hash of the given string or bytes.
* Returns the HMAC-MD4 cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -333,7 +333,7 @@ def hmac_md4(key, str) {
}

/**
* Returns the HMAC-MD5 cyrptographic hash of the given string or bytes.
* Returns the HMAC-MD5 cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -344,7 +344,7 @@ def hmac_md5(key, str) {
}

/**
* Returns the HMAC-SHA1 cyrptographic hash of the given string or bytes.
* Returns the HMAC-SHA1 cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -355,7 +355,7 @@ def hmac_sha1(key, str) {
}

/**
* Returns the HMAC-SHA224 cyrptographic hash of the given string or bytes.
* Returns the HMAC-SHA224 cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -366,7 +366,7 @@ def hmac_sha224(key, str) {
}

/**
* Returns the HMAC-SHA256 cyrptographic hash of the given string or bytes.
* Returns the HMAC-SHA256 cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -377,7 +377,7 @@ def hmac_sha256(key, str) {
}

/**
* Returns the HMAC-SHA384 cyrptographic hash of the given string or bytes.
* Returns the HMAC-SHA384 cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -388,7 +388,7 @@ def hmac_sha384(key, str) {
}

/**
* Returns the HMAC-SHA512 cyrptographic hash of the given string or bytes.
* Returns the HMAC-SHA512 cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -399,7 +399,7 @@ def hmac_sha512(key, str) {
}

/**
* Returns the HMAC-WHIRLPOOL cyrptographic hash of the given string or bytes.
* Returns the HMAC-WHIRLPOOL cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -410,7 +410,7 @@ def hmac_whirlpool(key, str) {
}

/**
* Returns the HMAC-SNEFRU cyrptographic hash of the given string or bytes.
* Returns the HMAC-SNEFRU cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand All @@ -421,7 +421,7 @@ def hmac_snefru(key, str) {
}

/**
* Returns the HMAC-GOST cyrptographic hash of the given string or bytes.
* Returns the HMAC-GOST cryptographic hash of the given string or bytes.
*
* @param string|bytes key
* @param string|bytes str
Expand Down
2 changes: 1 addition & 1 deletion libs/io.b
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class TTY {
* Flushes the standard output and standard error interface
*/
flush() {
_io.TTY.flush(self.std);
_io.TTY.flush(self.std)
}
}

Expand Down
Loading

0 comments on commit e8835ba

Please sign in to comment.