Skip to content

Commit

Permalink
move out builtin truffle functions to separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
arvyy committed Jul 27, 2024
1 parent 4ce60d0 commit 576bb03
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
4 changes: 4 additions & 0 deletions docs/apireference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Where main.lisp starts with

The correct invocation is `islisp -sp root1:root2 main.lisp` (on linux); `islisp -sp root1;root2 main.lisp` (on windows).

Some modules are built-in, their name starts with "builtin/".

=== Debugger

`(debugger)` statement enables triggering debugger breakpoint from code. Works only when ran in debug mode. Returns nil.
Expand Down Expand Up @@ -95,6 +97,8 @@ interop language's values are mapped to most fit ISLISP type. For some values, s

=== Truffle object interop API

NOTE: Following functions are provided through `(requires "builtin/truffle.lisp")`.

External objects with fields are represented as instances of `<truffle-object>` class (which is subclass of `<object>`). You can get a vector of fields (as strings) in a given object using `(truffle-object-fields _truffle-obj_)`.

[source,lisp]
Expand Down
11 changes: 11 additions & 0 deletions docs/site/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
= Truffle islisp static site

This folder contains HUGO static site for truffle, consisting of landing page, benchmark graphs, and rendered docs.

Building:

. Install `hugo` and `asciidoctor` executables.
. (Optionally) from `/benchmarks` folder execute `run.sh` to create benchmark svg images
. Run `./copycontent.sh` to move benchmark images and adoc files to content
. Run `hugo server` to run locally, site will be available at http://localhost:1313/islisp-truffle/
. Run `hugo` to build for distribution; the result will be placed in `public` folder.
18 changes: 13 additions & 5 deletions language/src/main/java/com/github/arvyy/islisp/ISLISPContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public ISLISPContext(ISLISPTruffleLanguage language, Env env) {
this.env = env;
modules = new HashMap<>();
modules.put("ROOT", new ISLISPModule());
modules.put("builtin/truffle.lisp", new ISLISPModule());
symbolProperties = new HashMap<>();
symbols = new HashMap<>();
currentOutputStream = new ValueReference();
Expand Down Expand Up @@ -136,6 +137,10 @@ void initGlobalFunction(String name, Function<TruffleLanguage<?>, LispFunction>
modules.get("ROOT").registerFunction(namedSymbol(name).identityReference(), f.apply(language));
}

void initTruffleLibFunction(String name, Function<TruffleLanguage<?>, LispFunction> f) {
modules.get("builtin/truffle.lisp").registerFunction(namedSymbol(name).identityReference(), f.apply(language));
}

/**
* Initialize builtin functions into function namespace storage.
*/
Expand Down Expand Up @@ -226,13 +231,16 @@ void initGlobalFunctions() {
//extension
initGlobalFunction("current-stacktrace", ISLISPCurrentStacktrace::makeLispFunction);
initGlobalFunction("exit", ISLISPExit::makeLispFunction);
initGlobalFunction("truffle-object-fields", ISLISPTruffleObjectFields::makeLispFunction);
initGlobalFunction("truffle-object-field", ISLISPTruffleObjectField::makeLispFunction);
initGlobalFunction("set-truffle-object-field", ISLISPSetTruffleObjectField::makeLispFunction);
initGlobalFunction("load-native-library", ISLISPLoadNativeLibrary::makeLispFunction);
initGlobalFunction("native-library-symbol", ISLISPNativeLibrarySymbol::makeLispFunction);
initGlobalFunction("closed-p", ISLISPClosedp::makeLispFunction);
initGlobalFunction("delete-file", ISLISPDeleteFile::makeLispFunction);

// truffle lib
initTruffleLibFunction("truffle-object-fields", ISLISPTruffleObjectFields::makeLispFunction);
initTruffleLibFunction("truffle-object-field", ISLISPTruffleObjectField::makeLispFunction);
initTruffleLibFunction("set-truffle-object-field", ISLISPSetTruffleObjectField::makeLispFunction);
initTruffleLibFunction("load-native-library", ISLISPLoadNativeLibrary::makeLispFunction);
initTruffleLibFunction("native-library-symbol", ISLISPNativeLibrarySymbol::makeLispFunction);
modules.get("builtin/truffle.lisp").exportAll();
}

private void initInitializeObjectMethod() {
Expand Down
1 change: 1 addition & 0 deletions tests/nonportable/evalinterop.lisp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(requires "testing.lisp")
(requires "builtin/truffle.lisp")

(let ((fun (eval "js" "(function(arg) { return 1 + arg; })")))
(test-equal (funcall fun 2) 3))
Expand Down
30 changes: 15 additions & 15 deletions tests/nonportable/stacktrace.expect.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
Unbound variable: unbound-var
at stacktrace.lisp:11
at stacktrace.lisp:8
at stacktrace.lisp:18
at stacktrace.lisp:13
at stacktrace.lisp:10
at stacktrace.lisp:20

Division by zero
at stacktrace.lisp:28
at stacktrace.lisp:30

Index 4 out of bounds (must be between 0 and 3 exclusive)
at stacktrace.lisp:38
at stacktrace.lisp:40

No next method available
at stacktrace.lisp:44
at stacktrace.lisp:46
at stacktrace.lisp:47
at stacktrace.lisp:45
at stacktrace.lisp:43
at stacktrace.lisp:51
at stacktrace.lisp:53

Error during truffle interop call: Unknown identifier: b
at stacktrace.lisp:62
at stacktrace.lisp:64

Undefined entity <doesntexist> in namespace class
at stacktrace.lisp:72
at stacktrace.lisp:74

Cannot convert A to #<class <list>>
at stacktrace.lisp:82
at stacktrace.lisp:84

Expected 1 args; received 2
at stacktrace.lisp:92
at stacktrace.lisp:93
at stacktrace.lisp:94
at stacktrace.lisp:95

Attempted to change immutable binding shouldbeimmutable
at stacktrace.lisp:104
at stacktrace.lisp:106

Error with value: test
at islispprelude.lisp:71
at stacktrace.lisp:114
at stacktrace.lisp:116
2 changes: 2 additions & 0 deletions tests/nonportable/stacktrace.lisp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(requires "builtin/truffle.lisp")

(defun print (str)
(format-object (standard-output) str nil)
(format-char (standard-output) #\newline))
Expand Down

0 comments on commit 576bb03

Please sign in to comment.