-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VM: initial support for calling native functions
- Loading branch information
Showing
12 changed files
with
172 additions
and
21 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
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,23 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
#include <cstdint> | ||
#else | ||
#include <stdint.h> | ||
#endif | ||
|
||
typedef struct { | ||
uint64_t argc; | ||
uint64_t *argv; | ||
} ExternArgs; | ||
|
||
typedef struct { | ||
uint64_t value; | ||
enum { | ||
SPL_VOID = 0, | ||
SPL_VALUE, | ||
SPL_OBJECT, | ||
} type; | ||
} ExternReturn; | ||
|
||
typedef ExternReturn (*NativeFunction)(ExternArgs); |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/testlib.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,10 @@ | ||
CXX = c++ | ||
CXXFLAGS = -fPIC -shared -I ../include | ||
TARGET = testlib.so | ||
SRCS = testlib.cpp | ||
|
||
$(TARGET): $(SRCS) | ||
$(CXX) $(SRCS) $(CXXFLAGS) -o $(TARGET) | ||
|
||
clean: | ||
rm -f $(TARGET) |
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,9 @@ | ||
#include "testlib.h" | ||
#include <cassert> | ||
#include <cstdio> | ||
|
||
ExternReturn hello_world(ExternArgs args) { | ||
assert(args.argc == 0); | ||
printf("Hello world from C!\n"); | ||
return (ExternReturn){0, ExternReturn::SPL_VOID}; | ||
} |
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,7 @@ | ||
#pragma once | ||
|
||
#include "spl.h" | ||
|
||
extern "C" { | ||
ExternReturn hello_world(ExternArgs args); | ||
} |
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,4 @@ | ||
export define lib = native("./testlib.so"); | ||
export define nativeHelloWorld : function() -> void = { | ||
lib("hello_world", []); | ||
} |