Fork me on GitHub
#babashka
<
2019-11-15
>
sogaiu01:11:50

wow, are there any downsides?

borkdude07:11:14

Well it does reflection, so it might be somewhat slower? I don’t expect this to be a problem for scripting though

borkdude07:11:30

I’d say try out the branch and see if you notice any difference

borkdude07:11:24

The one thing that I want to add is support for Constructors. And unit tests.

borkdude07:11:17

And import

dominicm09:11:46

Is it runtime reflection or compile time reflection? (I'd assume the latter, if it works with graal)

jeroenvandijk11:11:01

Does it matter in binary size?

borkdude12:11:36

It is runtime reflection using Graal

borkdude12:11:09

Binary size: not really

Jakub Holý (HolyJak)15:11:29

@borkdude Regarding https://github.com/borkdude/babashka/pull/108 (`.write`), maybe it is better to just close the PR and do it via the new approach once ready? I can use my locally built bb in the meantime...

borkdude15:11:17

I hope to finish this soon

🤞 4
borkdude15:11:02

if I will give users access to for example all method of String will they be able to indirectly call (System/exit 1) even when I haven't given them explicitly a reference to the System class?

borkdude15:11:16

e.g. via getClassLoader, and what have you?

borkdude15:11:45

I think an extra check is in order here

borkdude16:11:09

@holyjak sci is kind of a replacement for clojail already. clojail doesn't work on JS

borkdude16:11:37

it uses eval which doesn't work on native, which is more or less the entire point of sci

borkdude16:11:19

Do you think a method filter is needed? Right now I give users access to classes with {:classes {'String String 'java.lang.String String}}. This will let them do everything with strings

borkdude16:11:40

But there might be classes where you want to say which methods are only allowed or which methods are not allowed?

borkdude16:11:01

something like this:

{:classes {'java.lang.String {:class String
                              :deny-methods '[getClass]}}
 :imports {'String 'java.lang.String}}

Jakub Holý (HolyJak)16:11:44

Possibly. But do you need to decide it now? Cant you wait to add black/whitelist when you actually need it?

borkdude16:11:02

I can, but if I start with:

{:classes {'java.lang.String String}}

borkdude16:11:24

I don't have much room left there

borkdude16:11:44

so one level of indirection is probably better

Jakub Holý (HolyJak)16:11:05

Good point. U guess you cant use metadata here?

borkdude16:11:38

that gets awkward. metadata on symbols only works when you use with-meta

borkdude16:11:33

it's bit weird really:

user=> (meta (edn/read-string "^:foo dude"))
{:foo true}
user=> (meta ^:foo 'dude)
nil

Jakub Holý (HolyJak)16:11:48

Could you follow the example of require? Accept either a symbol or vector of symbol + options?

borkdude16:11:41

I'll go with the extra level of indirection for now, the convenience option can always be added later

👍 4
borkdude19:11:42

This reflection stuff is starting to pay off:

$ ./sci '(def x "foo") (-> x (.replace \o \i) (.replace "f" "h"))'
"hii"
Note that I'm using two different overloads of .replace here

sogaiu19:11:43

./sci '((juxt #(.indexOf % "o") #(.indexOf % "o" 2) #(.indexOf % (int \o))) "foo")'
[1 2 1]

borkdude19:11:43

yeah that works, doesn't it

👍 4
borkdude19:11:12

I finished the unit tests in the sci / interop branch. Next: add import and then merge to babashka, add some classes and hopefully profit

sogaiu20:11:47

tests passed here on linux -- takes a bit now to run them 🙂

sogaiu20:11:14

good thing it's getting cooler here as the room feels warmer

borkdude20:11:50

are you implying some regression?

sogaiu20:11:02

no, i think things are fine -- afaiu, there is testing with 1.9.0, 1.10.1, cljs w/ node optimizations none and advanced, as well as native -- each time some tests are added, the effect is a bit amplified, right?

borkdude20:11:46

true, I thought you were referring to reflection vs function wrappers

sogaiu20:11:25

ah, i haven't been paying close enough attention -- i could go back to an earlier commit to compare, but i'm guessing it's not that important

borkdude20:11:57

import now works in sci / interop:

$ ./sci "(import clojure.lang.ExceptionInfo) (type ExceptionInfo)"
java.lang.Class

sogaiu21:11:25

tests passed and:

$ ./sci "(import java.lang.ArithmeticException) (type ArithmeticException)"
java.lang.Class

borkdude23:11:02

New version of babashka with refactored Java class support using reflection config: https://1743-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.28-SNAPSHOT-linux-amd64.zip https://1741-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.28-SNAPSHOT-macos-amd64.zip Commit: https://github.com/borkdude/babashka/commit/a0fa854969a4024b126c43b6fd2339b626a543f9 Classes supported:

ArithmeticException
AssertionError
Boolean
Class
Double
Exception
clojure.lang.ExceptionInfo
java.io.File
Integer
java.io.File
java.util.regex.Pattern
String
System
Thread
Please check if nothing broke 🙂

borkdude23:11:52

I'll see if I can add the Writer stuff tomorrow