-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Glowman554
committed
Jan 21, 2024
1 parent
ec1d417
commit 263798f
Showing
10 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ src/explorer/res | |
upload.sh | ||
/flvm | ||
modules | ||
src/backend/config | ||
src/backend/config | ||
*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
$include <std.fl> | ||
$include <vm.fl> | ||
|
||
function spark(int argc, str[] argv) -> int { | ||
int vm = vm_load("../../tests/args.fl.flbb"); | ||
|
||
str arg0 = "args"; | ||
str arg1 = "hello"; | ||
str arg2 = "world"; | ||
|
||
str[] args = allocate(8 * 4); | ||
args[0] = arg0; | ||
args[1] = arg1; | ||
args[2] = arg2; | ||
args[3] = 0; | ||
|
||
stack_push(vm, 3); | ||
stack_push(vm, args); | ||
|
||
int spark = memory_read_64(vm + vm_instance_offset_spark); | ||
invoke(vm, spark); | ||
|
||
vm_destroy(vm); | ||
deallocate(args); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "vm_test", | ||
"version": "1.0.0", | ||
"main": "main.fl", | ||
"type": "executable", | ||
"compiler": { | ||
"target": "bytecode", | ||
"mode": "flbb" | ||
}, | ||
"dependencies": [ | ||
"vm@1.0.0-x64" | ||
] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gcc native.c -o native.so -fpic --shared |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "../../src/flvm/vm.h" | ||
|
||
void native_stack_push(struct vm_instance* vm) { | ||
int64_t value = (int64_t) stack_pop(vm); | ||
struct vm_instance* vm2 = (struct vm_instance*) stack_pop(vm); | ||
stack_push(vm2, value); | ||
stack_push(vm, 0); | ||
} | ||
|
||
void native_stack_pop(struct vm_instance* vm) { | ||
struct vm_instance* vm2 = (struct vm_instance*) stack_pop(vm); | ||
stack_push(vm, stack_pop(vm2)); | ||
} | ||
|
||
void native_invoke(struct vm_instance* vm) { | ||
uint64_t location = (uint64_t) stack_pop(vm); | ||
struct vm_instance* vm2 = (struct vm_instance*) stack_pop(vm); | ||
invoke(vm2, location); | ||
stack_push(vm, 0); | ||
} | ||
|
||
void native_vm_load(struct vm_instance* vm) { | ||
const char* file = (const char*) stack_pop(vm); | ||
stack_push(vm, vm_load(file)); | ||
} | ||
|
||
void native_vm_destroy(struct vm_instance* vm) { | ||
struct vm_instance* vm2 = (struct vm_instance*) stack_pop(vm); | ||
vm_destroy(vm2); | ||
stack_push(vm, 0); | ||
} | ||
|
||
|
||
void init() { | ||
vm_native_register(48327, native_stack_push); | ||
vm_native_register(48328, native_stack_pop); | ||
vm_native_register(48329, native_invoke); | ||
vm_native_register(48330, native_vm_load); | ||
vm_native_register(48331, native_vm_destroy); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "vm", | ||
"version": "1.0.0-x64", | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
$define struct vm_instance_offset_code 0 | ||
$define struct vm_instance_offset_stack 8 | ||
$define struct vm_instance_offset_stack_ptr 16 | ||
$define struct vm_instance_offset_max_stack 20 | ||
$define struct vm_instance_offset_global_variables 24 | ||
$define struct vm_instance_offset_global_variable_types 32 | ||
$define struct vm_instance_offset_global_variable_size 40 | ||
$define struct vm_instance_offset_spark 48 | ||
$define struct vm_instance_size 56 | ||
|
||
function(assembly) stack_push(int vm, int value) -> void { | ||
"48327" | ||
} | ||
|
||
function(assembly) stack_pop(int vm) -> int { | ||
"48328" | ||
} | ||
|
||
function(assembly) invoke(int vm, int location) -> void { | ||
"48329" | ||
} | ||
|
||
function(assembly) vm_load(str file) -> int { | ||
"48330" | ||
} | ||
|
||
function(assembly) vm_destroy(int vm) -> void { | ||
"48331" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters