Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfriend99 committed Oct 28, 2024
1 parent f119757 commit 099d3d8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 63 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 ------------------------------

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()

0 comments on commit 099d3d8

Please sign in to comment.