mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
rm TotallyNotJson
TotallyNotJson.roc now lives on the farm in virtual-dom-wip as Json.roc. Any reference in stdlib or builtins has been removed, as well as the last places it was used (in python/ruby-interop examples).
This commit is contained in:
parent
67f555feea
commit
d90da3af52
37 changed files with 114 additions and 144 deletions
3
examples/python-interop/.gitignore
vendored
Normal file
3
examples/python-interop/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.interop_env
|
||||
demo.egg-info
|
||||
dist
|
|
@ -5,12 +5,7 @@ set -euxo pipefail
|
|||
|
||||
# Could assume roc binary on path but this may be preferable
|
||||
cargo build --release
|
||||
../../target/release/roc build --lib
|
||||
|
||||
# Neither the application nor python needs a .0, so we can just rename it
|
||||
mv libhello.so.1.0 libhello.so.1
|
||||
# but one of which does expect plain libhello.so, so we symlink it
|
||||
ln -sf libhello.so.1 libhello.so
|
||||
../../target/release/roc build --lib libhello.roc
|
||||
|
||||
# For Python to find libhello, it needs it to be in a known library path, so we export
|
||||
export LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
|
||||
|
@ -24,6 +19,7 @@ export cc=clang
|
|||
python -m venv .interop_env
|
||||
source .interop_env/bin/activate
|
||||
python setup.py install
|
||||
set +x
|
||||
echo "You may now enter your virtual environment.
|
||||
In bash/zsh, run: source .interop_env/bin/activate
|
||||
In fish, run: source .interop_env/bin/activate.fish
|
||||
|
|
|
@ -227,15 +227,7 @@ PyObject * call_roc(PyObject *self, PyObject *args)
|
|||
roc__mainForHost_1_exposed_generic(&ret, &arg);
|
||||
|
||||
// Create a Python string from the heap-allocated JSON bytes the Roc function returned.
|
||||
PyObject* json_bytes = PyUnicode_FromStringAndSize((char*)ret.bytes, ret.len);
|
||||
PyObject* json_module = PyImport_ImportModule("json");
|
||||
PyObject* loads_func = PyObject_GetAttrString(json_module, "loads");
|
||||
PyObject *loads_args = PyTuple_Pack(1, json_bytes);
|
||||
PyObject* py_obj = PyObject_CallObject(loads_func, loads_args);
|
||||
Py_XDECREF(loads_args);
|
||||
Py_XDECREF(loads_func);
|
||||
Py_XDECREF(json_module);
|
||||
Py_XDECREF(json_bytes);
|
||||
PyObject* py_obj = PyUnicode_FromStringAndSize((char*)ret.bytes, ret.len);
|
||||
|
||||
// Now that we've created py_str, we're no longer referencing the RocBytes.
|
||||
decref((void *)&ret, alignof(uint8_t *));
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
platform "python-interop"
|
||||
requires {} { main : arg -> ret where arg implements Decoding, ret implements Encoding }
|
||||
requires {} { main : U64 -> Str }
|
||||
exposes []
|
||||
packages {}
|
||||
imports [TotallyNotJson]
|
||||
imports []
|
||||
provides [mainForHost]
|
||||
|
||||
mainForHost : List U8 -> List U8
|
||||
mainForHost = \json ->
|
||||
when Decode.fromBytes json TotallyNotJson.json is
|
||||
Ok arg -> Encode.toBytes (main arg) TotallyNotJson.json
|
||||
mainForHost = \input ->
|
||||
when Str.fromUtf8 input is
|
||||
Ok arg ->
|
||||
when Str.toU64 arg is
|
||||
Ok num -> main num |> Str.toUtf8
|
||||
Err _ -> []
|
||||
|
||||
Err _ -> []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue