Skip to content

Commit

Permalink
Use better naming convention for syscalls (such as .log becoming `.…
Browse files Browse the repository at this point in the history
…io_out`)

Also remove info from readme which is outdated.
  • Loading branch information
James-Livesey committed Jun 28, 2024
1 parent 0aafca3 commit dfe1099
Show file tree
Hide file tree
Showing 36 changed files with 776 additions and 756 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@ Voxel only generates the necessary bytecode to provide the supporting features n

```
56 78 43 01 22 48 65 6c 6c 6f 2c 20 77 6f 72 6c VxC."Hello, worl
64 21 0a 00 33 01 2e 6c 6f 67 00 70 00 d!..3..log.p.
64 21 0a 00 33 01 2e 69 6f 5f 6f 75 74 00 70 00 d!..3..io_out.p.
```

Since this program does not make use of Voxel's auxiliary features, all code from [`core.vxl`](tools/vxbuild-js/core.vxl) in this example has been excluded through static code analysis and is therefore never compiled into the bytecode.

The following Voxel code produced the above bytecode:

```voxel
syscall log("Hello, world!\n");
```

More examples of Voxel programs can be found in the [`examples`](examples) and [`test`](test) directories.
Examples of Voxel programs can be found in the [`examples`](examples) and [`test`](test) directories.

## Key features of the Voxel programming language
* **Functions** — named and anonymous
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ include src/builtins/core/strings.h
include src/builtins/core/objects.h
include src/builtins/core/lists.h
include src/builtins/core/core.h
include src/builtins/io/io.h
include src/builtins/threads/threads.h
include src/maths.h
include src/contexts.h
Expand Down
1 change: 1 addition & 0 deletions dist/libvoxel-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#endif

#define VOXEL_BUILTINS_CORE
#define VOXEL_BUILTINS_IO
#define VOXEL_BUILTINS_THREADS

// #define VOXEL_DEBUG
Expand Down
54 changes: 34 additions & 20 deletions dist/libvoxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1594,19 +1594,6 @@ void voxel_builtins_core_joinList(voxel_Executor* executor) {

#ifdef VOXEL_BUILTINS_CORE

void voxel_builtins_core_log(voxel_Executor* executor) {
voxel_Int argCount = voxel_popNumberInt(executor);
voxel_Thing* thing = voxel_pop(executor);

if (thing) {
voxel_logThing(executor->context, thing);

voxel_unreferenceThing(executor->context, thing);
}

voxel_pushNull(executor);
}

void voxel_builtins_core_params(voxel_Executor* executor) {
voxel_Int required = voxel_popNumberInt(executor);
voxel_Int actual = voxel_popNumberInt(executor);
Expand Down Expand Up @@ -1906,7 +1893,6 @@ void voxel_builtins_core_getEnumEntry(voxel_Executor* executor) {
}

void voxel_builtins_core(voxel_Context* context) {
voxel_defineBuiltin(context, ".log", &voxel_builtins_core_log);
voxel_defineBuiltin(context, ".P", &voxel_builtins_core_params);
voxel_defineBuiltin(context, ".T", &voxel_builtins_core_getType);
voxel_defineBuiltin(context, ".C", &voxel_builtins_core_toClosure);
Expand Down Expand Up @@ -1979,6 +1965,33 @@ void voxel_builtins_core(voxel_Context* context) {}

#endif

// src/builtins/io/io.h

#ifdef VOXEL_BUILTINS_IO

void voxel_builtins_io_out(voxel_Executor* executor) {
voxel_Int argCount = voxel_popNumberInt(executor);
voxel_Thing* thing = voxel_pop(executor);

if (thing) {
voxel_logThing(executor->context, thing);

voxel_unreferenceThing(executor->context, thing);
}

voxel_pushNull(executor);
}

void voxel_builtins_io(voxel_Context* context) {
voxel_defineBuiltin(context, ".io_out", &voxel_builtins_io_out);
}

#else

void voxel_builtins_io(voxel_Context* context) {}

#endif

// src/builtins/threads/threads.h

#ifdef VOXEL_BUILTINS_THREADS
Expand Down Expand Up @@ -2123,12 +2136,12 @@ void voxel_builtins_threads_preserveSymbols(voxel_Executor* executor) {
}

void voxel_builtins_threads(voxel_Context* context) {
voxel_defineBuiltin(context, ".Thn", &voxel_builtins_threads_newThread);
voxel_defineBuiltin(context, ".Thd", &voxel_builtins_threads_destroyThread);
voxel_defineBuiltin(context, ".Thoi", &voxel_builtins_threads_getOwnThreadId);
voxel_defineBuiltin(context, ".Thir", &voxel_builtins_threads_threadIsRunning);
voxel_defineBuiltin(context, ".Thsr", &voxel_builtins_threads_setThreadIsRunning);
voxel_defineBuiltin(context, ".Thps", &voxel_builtins_threads_preserveSymbols);
voxel_defineBuiltin(context, ".threads_new", &voxel_builtins_threads_newThread);
voxel_defineBuiltin(context, ".threads_destroy", &voxel_builtins_threads_destroyThread);
voxel_defineBuiltin(context, ".threads_getOwnId", &voxel_builtins_threads_getOwnThreadId);
voxel_defineBuiltin(context, ".threads_isRunning", &voxel_builtins_threads_threadIsRunning);
voxel_defineBuiltin(context, ".threads_setIsRunning", &voxel_builtins_threads_setThreadIsRunning);
voxel_defineBuiltin(context, ".threads_preserve", &voxel_builtins_threads_preserveSymbols);
}

#else
Expand Down Expand Up @@ -2213,6 +2226,7 @@ voxel_Context* voxel_newContext() {
voxel_newExecutor(context);

voxel_builtins_core(context);
voxel_builtins_io(context);
voxel_builtins_threads(context);

return context;
Expand Down
2 changes: 1 addition & 1 deletion examples/another.vxl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
syscall log("This was also imported!\n");
syscall io_out("This was also imported!\n");
6 changes: 3 additions & 3 deletions examples/hello.vxl
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ var thisIsAwesome = true;
// Functions (these ones are mainly for usage later on)

function print(value) {
syscall log(value);
syscall io_out(value);
}

function println(value) {
syscall log(value);
syscall log("\n");
syscall io_out(value);
syscall io_out("\n");
}

function newList() {
Expand Down
2 changes: 1 addition & 1 deletion examples/imported.vxl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "another.vxl" as another;
import "hello.vxl" as hello;

syscall log("This was imported!\n");
syscall io_out("This was imported!\n");

var valueFromImport = "this value has been exported";

Expand Down
2 changes: 1 addition & 1 deletion examples/smallest.vxl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
syscall log("Hello, world!\n");
syscall io_out("Hello, world!\n");
14 changes: 0 additions & 14 deletions src/builtins/core/core.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
#ifdef VOXEL_BUILTINS_CORE

void voxel_builtins_core_log(voxel_Executor* executor) {
voxel_Int argCount = voxel_popNumberInt(executor);
voxel_Thing* thing = voxel_pop(executor);

if (thing) {
voxel_logThing(executor->context, thing);

voxel_unreferenceThing(executor->context, thing);
}

voxel_pushNull(executor);
}

void voxel_builtins_core_params(voxel_Executor* executor) {
voxel_Int required = voxel_popNumberInt(executor);
voxel_Int actual = voxel_popNumberInt(executor);
Expand Down Expand Up @@ -312,7 +299,6 @@ void voxel_builtins_core_getEnumEntry(voxel_Executor* executor) {
}

void voxel_builtins_core(voxel_Context* context) {
voxel_defineBuiltin(context, ".log", &voxel_builtins_core_log);
voxel_defineBuiltin(context, ".P", &voxel_builtins_core_params);
voxel_defineBuiltin(context, ".T", &voxel_builtins_core_getType);
voxel_defineBuiltin(context, ".C", &voxel_builtins_core_toClosure);
Expand Down
24 changes: 24 additions & 0 deletions src/builtins/io/io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifdef VOXEL_BUILTINS_IO

void voxel_builtins_io_out(voxel_Executor* executor) {
voxel_Int argCount = voxel_popNumberInt(executor);
voxel_Thing* thing = voxel_pop(executor);

if (thing) {
voxel_logThing(executor->context, thing);

voxel_unreferenceThing(executor->context, thing);
}

voxel_pushNull(executor);
}

void voxel_builtins_io(voxel_Context* context) {
voxel_defineBuiltin(context, ".io_out", &voxel_builtins_io_out);
}

#else

void voxel_builtins_io(voxel_Context* context) {}

#endif
12 changes: 6 additions & 6 deletions src/builtins/threads/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ void voxel_builtins_threads_preserveSymbols(voxel_Executor* executor) {
}

void voxel_builtins_threads(voxel_Context* context) {
voxel_defineBuiltin(context, ".Thn", &voxel_builtins_threads_newThread);
voxel_defineBuiltin(context, ".Thd", &voxel_builtins_threads_destroyThread);
voxel_defineBuiltin(context, ".Thoi", &voxel_builtins_threads_getOwnThreadId);
voxel_defineBuiltin(context, ".Thir", &voxel_builtins_threads_threadIsRunning);
voxel_defineBuiltin(context, ".Thsr", &voxel_builtins_threads_setThreadIsRunning);
voxel_defineBuiltin(context, ".Thps", &voxel_builtins_threads_preserveSymbols);
voxel_defineBuiltin(context, ".threads_new", &voxel_builtins_threads_newThread);
voxel_defineBuiltin(context, ".threads_destroy", &voxel_builtins_threads_destroyThread);
voxel_defineBuiltin(context, ".threads_getOwnId", &voxel_builtins_threads_getOwnThreadId);
voxel_defineBuiltin(context, ".threads_isRunning", &voxel_builtins_threads_threadIsRunning);
voxel_defineBuiltin(context, ".threads_setIsRunning", &voxel_builtins_threads_setThreadIsRunning);
voxel_defineBuiltin(context, ".threads_preserve", &voxel_builtins_threads_preserveSymbols);
}

#else
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#endif

#define VOXEL_BUILTINS_CORE
#define VOXEL_BUILTINS_IO
#define VOXEL_BUILTINS_THREADS

// #define VOXEL_DEBUG
Expand Down
1 change: 1 addition & 0 deletions src/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ voxel_Context* voxel_newContext() {
voxel_newExecutor(context);

voxel_builtins_core(context);
voxel_builtins_io(context);
voxel_builtins_threads(context);

return context;
Expand Down
2 changes: 1 addition & 1 deletion stdlib/core.vxl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var thisStack = [];
var nextThis = null;
var superStack = [];

syscall Thps([
syscall threads_preserve([
#symbol(thisStack),
#symbol(nextThis),
#symbol(superStack)
Expand Down
6 changes: 3 additions & 3 deletions stdlib/io/io.vxl
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class StandardOutputStream extends Stream {
write(data) {
super.write(data);

syscall log(data);
syscall io_out(data);
}
}

function print(data) {
syscall log(data);
syscall io_out(data);
}

function println(data) {
syscall log(data + "\n");
syscall io_out(data + "\n");
}
12 changes: 6 additions & 6 deletions stdlib/threads/threads.vxl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Thread {
}

if (this._hasStarted) {
syscall Thd(this._id);
syscall threads_destroy(this._id);
}

this._hasBeenClosed = true;
Expand All @@ -51,7 +51,7 @@ class Thread {
this._checkThreadExists();

if (this._isPaused) {
syscall Thsr(true, this._id);
syscall threads_setIsRunning(true, this._id);

this._isPaused = false;

Expand All @@ -62,7 +62,7 @@ class Thread {
throw ThreadError.CANNOT_ENTER_STATE;
}

this._id = syscall Thn(this.callFunction, this.callArgs);
this._id = syscall threads_new(this.callFunction, this.callArgs);
this._hasStarted = true;
}

Expand All @@ -73,7 +73,7 @@ class Thread {
throw ThreadError.CANNOT_ENTER_STATE;
}

syscall Thsr(false, this._id);
syscall threads_setIsRunning(false, this._id);

this._isPaused = true;
}
Expand All @@ -87,7 +87,7 @@ class Thread {
return false;
}

return syscall Thir(this._id);
return syscall threads_isRunning(this._id);
}

isPaused() {
Expand Down Expand Up @@ -133,7 +133,7 @@ class MainThread extends Thread {
}

function getOwnThread() {
var id = syscall Thoi();
var id = syscall threads_getOwnId();

return _existingThreads.find(function(thread) {
return thread._id == id;
Expand Down
Loading

0 comments on commit dfe1099

Please sign in to comment.