Merge branch 'master' into library-use-case

# Conflicts:
#	Cargo.toml
#	src/machine/mock_wam.rs
#	src/machine/mod.rs
This commit is contained in:
Nicolas Luck
2023-08-30 18:12:26 +02:00
27 changed files with 927 additions and 594 deletions

View File

@@ -187,8 +187,8 @@ impl<T: CopierTarget> CopyTermState<T> {
fn copy_attr_var_list(&mut self, mut list_addr: HeapCellValue) {
while let HeapCellValueTag::Lis = list_addr.get_tag() {
let threshold = self.target.threshold();
let heap_loc = list_addr.get_value();
let str_loc = self.target[heap_loc].get_value();
let heap_loc = list_addr.get_value() as usize;
let str_loc = self.target[heap_loc].get_value() as usize;
self.target.push(heap_loc_as_cell!(threshold+2));
self.target.push(heap_loc_as_cell!(threshold+1));

View File

@@ -27,7 +27,7 @@ pub struct BranchNumber {
impl Default for BranchNumber {
fn default() -> Self {
Self {
branch_num: Rational::from(1usize << 63),
branch_num: Rational::from(1u64 << 63),
delta: Rational::from(1),
}
}

View File

@@ -1497,6 +1497,14 @@ impl Machine {
try_or_throw!(self.machine_st, self.machine_st.is(r, at));
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
Instruction::DefaultCallGetNumber(at) => {
try_or_throw!(self.machine_st, self.machine_st.get_number(at));
step_or_fail!(self, self.machine_st.p += 1);
}
Instruction::DefaultExecuteGetNumber(at) => {
try_or_throw!(self.machine_st, self.machine_st.get_number(at));
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallAcyclicTerm => {
let addr = self.machine_st.registers[1];
@@ -1965,6 +1973,34 @@ impl Machine {
self.machine_st.p = self.machine_st.cp;
}
}
Instruction::CallGetNumber(at) => {
try_or_throw!(self.machine_st, self.machine_st.get_number(at));
if self.machine_st.fail {
self.machine_st.backtrack();
} else {
try_or_throw!(
self.machine_st,
(self.machine_st.increment_call_count_fn)(&mut self.machine_st)
);
self.machine_st.p += 1;
}
}
Instruction::ExecuteGetNumber(at) => {
try_or_throw!(self.machine_st, self.machine_st.get_number(at));
if self.machine_st.fail {
self.machine_st.backtrack();
} else {
try_or_throw!(
self.machine_st,
(self.machine_st.increment_call_count_fn)(&mut self.machine_st)
);
self.machine_st.p = self.machine_st.cp;
}
}
&Instruction::CallN(arity) => {
let pred = self.machine_st.registers[1];
@@ -4242,58 +4278,72 @@ impl Machine {
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallHttpOpen => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_open());
step_or_fail!(self, self.machine_st.p += 1);
}
&Instruction::ExecuteHttpOpen => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_open());
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallHttpListen => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_listen());
step_or_fail!(self, self.machine_st.p += 1);
}
&Instruction::ExecuteHttpListen => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_listen());
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallHttpAccept => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_accept());
step_or_fail!(self, self.machine_st.p += 1);
}
&Instruction::ExecuteHttpAccept => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_accept());
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallHttpAnswer => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_answer());
step_or_fail!(self, self.machine_st.p += 1);
}
&Instruction::ExecuteHttpAnswer => {
#[cfg(feature = "http")]
try_or_throw!(self.machine_st, self.http_answer());
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallLoadForeignLib => {
#[cfg(feature = "ffi")]
try_or_throw!(self.machine_st, self.load_foreign_lib());
step_or_fail!(self, self.machine_st.p += 1);
}
&Instruction::ExecuteLoadForeignLib => {
#[cfg(feature = "ffi")]
try_or_throw!(self.machine_st, self.load_foreign_lib());
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallForeignCall => {
#[cfg(feature = "ffi")]
try_or_throw!(self.machine_st, self.foreign_call());
step_or_fail!(self, self.machine_st.p += 1);
}
&Instruction::ExecuteForeignCall => {
#[cfg(feature = "ffi")]
try_or_throw!(self.machine_st, self.foreign_call());
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallDefineForeignStruct => {
#[cfg(feature = "ffi")]
try_or_throw!(self.machine_st, self.define_foreign_struct());
step_or_fail!(self, self.machine_st.p += 1);
}
&Instruction::ExecuteDefineForeignStruct => {
#[cfg(feature = "ffi")]
try_or_throw!(self.machine_st, self.define_foreign_struct());
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
@@ -4462,18 +4512,22 @@ impl Machine {
self.machine_st.p = self.machine_st.cp;
}
&Instruction::CallTLSAcceptClient => {
#[cfg(feature = "tls")]
try_or_throw!(self.machine_st, self.tls_accept_client());
step_or_fail!(self, self.machine_st.p += 1);
}
&Instruction::ExecuteTLSAcceptClient => {
#[cfg(feature = "tls")]
try_or_throw!(self.machine_st, self.tls_accept_client());
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
&Instruction::CallTLSClientConnect => {
#[cfg(feature = "tls")]
try_or_throw!(self.machine_st, self.tls_client_connect());
step_or_fail!(self, self.machine_st.p += 1);
}
&Instruction::ExecuteTLSClientConnect => {
#[cfg(feature = "tls")]
try_or_throw!(self.machine_st, self.tls_client_connect());
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}

View File

@@ -68,7 +68,7 @@ pub(crate) struct StacklessPreOrderHeapIter<'a, UMP: UnmarkPolicy> {
orig_heap_len: usize,
start: usize,
current: usize,
next: usize,
next: u64,
_marker: PhantomData<UMP>,
}
@@ -153,14 +153,14 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
}
fn forward_var(&mut self) -> Option<HeapCellValue> {
if self.heap[self.next].get_forwarding_bit() {
if self.heap[self.next as usize].get_forwarding_bit() {
return self.backward_and_return();
}
let temp = self.heap[self.next].get_value();
let temp = self.heap[self.next as usize].get_value();
self.heap[self.next].set_value(self.current);
self.current = self.next;
self.heap[self.next as usize].set_value(self.current as u64);
self.current = self.next as usize;
self.next = temp;
None
@@ -175,23 +175,23 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
HeapCellValueTag::AttrVar => {
if let Some(cell) = UMP::forward_attr_var(self) { return Some(cell); }
if self.heap[self.next].get_mark_bit() {
if self.heap[self.next as usize].get_mark_bit() {
return Some(attr_var_as_cell!(self.current));
}
}
HeapCellValueTag::Var => {
if let Some(cell) = self.forward_var() { return Some(cell); }
if self.heap[self.next].get_mark_bit() {
if self.heap[self.next as usize].get_mark_bit() {
return Some(heap_loc_as_cell!(self.current));
}
}
HeapCellValueTag::Str => {
if self.heap[self.next + 1].get_forwarding_bit() {
if self.heap[self.next as usize + 1].get_forwarding_bit() {
return self.backward_and_return();
}
let h = self.next;
let h = self.next as usize;
let cell = self.heap[h];
let arity = cell_as_atom_cell!(self.heap[h]).get_arity();
@@ -203,13 +203,13 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
let last_cell_loc = h + arity;
self.next = self.heap[last_cell_loc].get_value();
self.heap[last_cell_loc].set_value(self.current);
self.heap[last_cell_loc].set_value(self.current as u64);
self.current = last_cell_loc;
return Some(cell);
}
HeapCellValueTag::Lis => {
let last_cell_loc = self.next + 1;
let last_cell_loc = self.next as usize + 1;
if self.heap[last_cell_loc].get_forwarding_bit() {
return self.backward_and_return();
@@ -218,13 +218,13 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
self.heap[last_cell_loc].set_forwarding_bit(true);
self.next = self.heap[last_cell_loc].get_value();
self.heap[last_cell_loc].set_value(self.current);
self.heap[last_cell_loc].set_value(self.current as u64);
self.current = last_cell_loc;
return Some(list_loc_as_cell!(last_cell_loc - 1));
}
HeapCellValueTag::PStrLoc => {
let h = self.next;
let h = self.next as usize;
let cell = self.heap[h];
if self.heap[h+1].get_forwarding_bit() {
@@ -236,13 +236,13 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
self.heap[last_cell_loc].set_forwarding_bit(true);
self.next = self.heap[last_cell_loc].get_value();
self.heap[last_cell_loc].set_value(self.current);
self.heap[last_cell_loc].set_value(self.current as u64);
self.current = last_cell_loc;
} else {
debug_assert!(self.heap[h].get_tag() == HeapCellValueTag::PStrOffset);
self.next = self.heap[h].get_value();
self.heap[h].set_value(self.current);
self.heap[h].set_value(self.current as u64);
self.current = h;
if self.heap[h].get_mark_bit() {
@@ -253,7 +253,7 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
return Some(cell);
}
HeapCellValueTag::PStrOffset => {
let h = self.next;
let h = self.next as usize;
let cell = self.heap[h];
// mark the Fixnum offset.
@@ -269,20 +269,20 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
self.heap[last_cell_loc].set_forwarding_bit(true);
self.next = self.heap[last_cell_loc].get_value();
self.heap[last_cell_loc].set_value(self.current);
self.heap[last_cell_loc].set_value(self.current as u64);
self.current = last_cell_loc;
} else {
debug_assert!(self.heap[h].get_tag() == HeapCellValueTag::CStr);
self.next = self.heap[h].get_value();
self.heap[h].set_value(self.current);
self.heap[h].set_value(self.current as u64);
self.current = h;
}
return Some(cell);
}
tag @ HeapCellValueTag::Atom => {
let cell = HeapCellValue::build_with(tag, self.next as u64);
let cell = HeapCellValue::build_with(tag, self.next);
let arity = AtomCell::from_bytes(cell.into_bytes()).get_arity();
if arity == 0 {
@@ -315,8 +315,8 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> {
UMP::unmark(self.heap, self.current);
self.heap[self.current].set_value(self.next);
self.next = self.current;
self.current = temp;
self.next = self.current as u64;
self.current = temp as usize;
}
self.heap[self.current].set_forwarding_bit(false);

View File

@@ -2,6 +2,7 @@ use crate::arena::*;
use crate::atom_table::*;
use crate::parser::ast::*;
#[cfg(feature = "ffi")]
use crate::ffi::FFIError;
use crate::forms::*;
use crate::machine::heap::*;
@@ -538,6 +539,7 @@ impl MachineState {
}
}
#[cfg(feature = "ffi")]
pub(super) fn ffi_error(&mut self, err: FFIError) -> MachineError {
let error_atom = match err {
FFIError::ValueCast => atom!("value_cast"),

View File

@@ -143,6 +143,10 @@ impl IndexPtr {
#[derive(Debug, Clone, Copy, Ord, Hash, PartialOrd, Eq, PartialEq)]
pub struct CodeIndex(TypedArenaPtr<IndexPtr>);
#[cfg(target_pointer_width="32")]
const_assert!(std::mem::align_of::<CodeIndex>() == 4);
#[cfg(target_pointer_width="64")]
const_assert!(std::mem::align_of::<CodeIndex>() == 8);
impl Deref for CodeIndex {
@@ -164,7 +168,7 @@ impl DerefMut for CodeIndex {
impl From<CodeIndex> for UntypedArenaPtr {
#[inline(always)]
fn from(ptr: CodeIndex) -> UntypedArenaPtr {
unsafe { std::mem::transmute(ptr.0.as_ptr()) }
UntypedArenaPtr::build_with(ptr.0.as_ptr() as usize)
}
}

View File

@@ -31,6 +31,7 @@ use crate::arena::*;
use crate::arithmetic::*;
use crate::atom_table::*;
use crate::forms::*;
#[cfg(feature = "ffi")]
use crate::ffi::ForeignFunctionTable;
use crate::instructions::*;
use crate::machine::args::*;
@@ -73,6 +74,7 @@ pub struct Machine {
pub(super) user_output: Stream,
pub(super) user_error: Stream,
pub(super) load_contexts: Vec<LoadContext>,
#[cfg(feature = "ffi")]
pub(super) foreign_function_table: ForeignFunctionTable,
}
@@ -452,6 +454,7 @@ impl Machine {
user_output,
user_error,
load_contexts: vec![],
#[cfg(feature = "ffi")]
foreign_function_table: Default::default(),
};
@@ -1253,7 +1256,7 @@ impl Machine {
}
}
TrailEntryTag::TrailedBlackboardEntry => {
let key = Atom::from(h);
let key = Atom::from(h as u64);
match self.indices.global_variables.get_mut(&key) {
Some((_, ref mut loc)) => *loc = None,
@@ -1261,7 +1264,7 @@ impl Machine {
}
}
TrailEntryTag::TrailedBlackboardOffset => {
let key = Atom::from(h);
let key = Atom::from(h as u64);
let value_cell = HeapCellValue::from(u64::from(self.machine_st.trail[i + 1]));
match self.indices.global_variables.get_mut(&key) {

View File

@@ -9,6 +9,7 @@ use crate::machine::machine_errors::*;
use crate::machine::machine_indices::*;
use crate::machine::machine_state::*;
use crate::types::*;
#[cfg(feature = "http")]
use crate::http::HttpResponse;
pub use modular_bitfield::prelude::*;
@@ -26,6 +27,7 @@ use std::net::{TcpStream, Shutdown};
use std::ops::{Deref, DerefMut};
use std::ptr;
#[cfg(feature = "tls")]
use native_tls::TlsStream;
#[derive(Debug, BitfieldSpecifier, Clone, Copy, PartialEq, Eq, Hash)]
@@ -232,12 +234,14 @@ impl Write for NamedTcpStream {
}
}
#[cfg(feature = "tls")]
#[derive(Debug)]
pub struct NamedTlsStream {
address: Atom,
tls_stream: TlsStream<Stream>,
}
#[cfg(feature = "tls")]
impl Read for NamedTlsStream {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
@@ -245,6 +249,7 @@ impl Read for NamedTlsStream {
}
}
#[cfg(feature = "tls")]
impl Write for NamedTlsStream {
#[inline]
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
@@ -257,17 +262,20 @@ impl Write for NamedTlsStream {
}
}
#[cfg(feature = "http")]
pub struct HttpReadStream {
url: Atom,
body_reader: Box<dyn BufRead>,
}
#[cfg(feature = "http")]
impl Debug for HttpReadStream {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Http Read Stream [{}]", self.url.as_str())
}
}
#[cfg(feature = "http")]
impl Read for HttpReadStream {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
@@ -275,6 +283,7 @@ impl Read for HttpReadStream {
}
}
#[cfg(feature = "http")]
pub struct HttpWriteStream {
status_code: u16,
headers: hyper::HeaderMap,
@@ -282,12 +291,14 @@ pub struct HttpWriteStream {
buffer: Vec<u8>,
}
#[cfg(feature = "http")]
impl Debug for HttpWriteStream {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Http Write Stream")
}
}
#[cfg(feature = "http")]
impl Write for HttpWriteStream {
#[inline]
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
@@ -361,7 +372,7 @@ impl StreamOptions {
#[inline]
pub fn get_alias(self) -> Option<Atom> {
if self.has_alias() {
Some(Atom::from((self.alias() << 3) as usize))
Some(Atom::from((self.alias() as u64) << 3))
} else {
None
}
@@ -453,8 +464,11 @@ arena_allocated_impl_for_stream!(CharReader<ByteStream>, ByteStream);
arena_allocated_impl_for_stream!(CharReader<InputFileStream>, InputFileStream);
arena_allocated_impl_for_stream!(OutputFileStream, OutputFileStream);
arena_allocated_impl_for_stream!(CharReader<NamedTcpStream>, NamedTcpStream);
#[cfg(feature = "tls")]
arena_allocated_impl_for_stream!(CharReader<NamedTlsStream>, NamedTlsStream);
#[cfg(feature = "http")]
arena_allocated_impl_for_stream!(CharReader<HttpReadStream>, HttpReadStream);
#[cfg(feature = "http")]
arena_allocated_impl_for_stream!(CharReader<HttpWriteStream>, HttpWriteStream);
arena_allocated_impl_for_stream!(ReadlineStream, ReadlineStream);
arena_allocated_impl_for_stream!(StaticStringStream, StaticStringStream);
@@ -468,8 +482,11 @@ pub enum Stream {
OutputFile(TypedArenaPtr<StreamLayout<OutputFileStream>>),
StaticString(TypedArenaPtr<StreamLayout<StaticStringStream>>),
NamedTcp(TypedArenaPtr<StreamLayout<CharReader<NamedTcpStream>>>),
#[cfg(feature = "tls")]
NamedTls(TypedArenaPtr<StreamLayout<CharReader<NamedTlsStream>>>),
#[cfg(feature = "http")]
HttpRead(TypedArenaPtr<StreamLayout<CharReader<HttpReadStream>>>),
#[cfg(feature = "http")]
HttpWrite(TypedArenaPtr<StreamLayout<CharReader<HttpWriteStream>>>),
Null(StreamOptions),
Readline(TypedArenaPtr<StreamLayout<ReadlineStream>>),
@@ -524,8 +541,11 @@ impl Stream {
Stream::OutputFile(TypedArenaPtr::new(ptr as *mut _))
}
ArenaHeaderTag::NamedTcpStream => Stream::NamedTcp(TypedArenaPtr::new(ptr as *mut _)),
#[cfg(feature = "tls")]
ArenaHeaderTag::NamedTlsStream => Stream::NamedTls(TypedArenaPtr::new(ptr as *mut _)),
#[cfg(feature = "http")]
ArenaHeaderTag::HttpReadStream => Stream::HttpRead(TypedArenaPtr::new(ptr as *mut _)),
#[cfg(feature = "http")]
ArenaHeaderTag::HttpWriteStream => Stream::HttpWrite(TypedArenaPtr::new(ptr as *mut _)),
ArenaHeaderTag::ReadlineStream => Stream::Readline(TypedArenaPtr::new(ptr as *mut _)),
ArenaHeaderTag::StaticStringStream => {
@@ -578,8 +598,11 @@ impl Stream {
Stream::OutputFile(ptr) => ptr.header_ptr(),
Stream::StaticString(ptr) => ptr.header_ptr(),
Stream::NamedTcp(ptr) => ptr.header_ptr(),
#[cfg(feature = "tls")]
Stream::NamedTls(ptr) => ptr.header_ptr(),
#[cfg(feature = "http")]
Stream::HttpRead(ptr) => ptr.header_ptr(),
#[cfg(feature = "http")]
Stream::HttpWrite(ptr) => ptr.header_ptr(),
Stream::Null(_) => ptr::null(),
Stream::Readline(ptr) => ptr.header_ptr(),
@@ -595,9 +618,12 @@ impl Stream {
Stream::OutputFile(ref ptr) => &ptr.options,
Stream::StaticString(ref ptr) => &ptr.options,
Stream::NamedTcp(ref ptr) => &ptr.options,
#[cfg(feature = "tls")]
Stream::NamedTls(ref ptr) => &ptr.options,
#[cfg(feature = "http")]
Stream::HttpRead(ref ptr) => &ptr.options,
Stream::HttpWrite(ref ptr) => &ptr.options,
#[cfg(feature = "http")]
Stream::HttpWrite(ref ptr) => &ptr.options,
Stream::Null(ref options) => options,
Stream::Readline(ref ptr) => &ptr.options,
Stream::StandardOutput(ref ptr) => &ptr.options,
@@ -612,8 +638,11 @@ impl Stream {
Stream::OutputFile(ref mut ptr) => &mut ptr.options,
Stream::StaticString(ref mut ptr) => &mut ptr.options,
Stream::NamedTcp(ref mut ptr) => &mut ptr.options,
#[cfg(feature = "tls")]
Stream::NamedTls(ref mut ptr) => &mut ptr.options,
#[cfg(feature = "http")]
Stream::HttpRead(ref mut ptr) => &mut ptr.options,
#[cfg(feature = "http")]
Stream::HttpWrite(ref mut ptr) => &mut ptr.options,
Stream::Null(ref mut options) => options,
Stream::Readline(ref mut ptr) => &mut ptr.options,
@@ -630,8 +659,11 @@ impl Stream {
Stream::OutputFile(ptr) => ptr.lines_read += incr_num_lines_read,
Stream::StaticString(ptr) => ptr.lines_read += incr_num_lines_read,
Stream::NamedTcp(ptr) => ptr.lines_read += incr_num_lines_read,
#[cfg(feature = "tls")]
Stream::NamedTls(ptr) => ptr.lines_read += incr_num_lines_read,
#[cfg(feature = "http")]
Stream::HttpRead(ptr) => ptr.lines_read += incr_num_lines_read,
#[cfg(feature = "http")]
Stream::HttpWrite(_) => {}
Stream::Null(_) => {}
Stream::Readline(ptr) => ptr.lines_read += incr_num_lines_read,
@@ -648,8 +680,11 @@ impl Stream {
Stream::OutputFile(ptr) => ptr.lines_read = value,
Stream::StaticString(ptr) => ptr.lines_read = value,
Stream::NamedTcp(ptr) => ptr.lines_read = value,
#[cfg(feature = "tls")]
Stream::NamedTls(ptr) => ptr.lines_read = value,
#[cfg(feature = "http")]
Stream::HttpRead(ptr) => ptr.lines_read = value,
#[cfg(feature = "http")]
Stream::HttpWrite(_) => {}
Stream::Null(_) => {}
Stream::Readline(ptr) => ptr.lines_read = value,
@@ -666,8 +701,11 @@ impl Stream {
Stream::OutputFile(ptr) => ptr.lines_read,
Stream::StaticString(ptr) => ptr.lines_read,
Stream::NamedTcp(ptr) => ptr.lines_read,
#[cfg(feature = "tls")]
Stream::NamedTls(ptr) => ptr.lines_read,
#[cfg(feature = "http")]
Stream::HttpRead(ptr) => ptr.lines_read,
#[cfg(feature = "http")]
Stream::HttpWrite(_) => 0,
Stream::Null(_) => 0,
Stream::Readline(ptr) => ptr.lines_read,
@@ -682,15 +720,21 @@ impl CharRead for Stream {
match self {
Stream::InputFile(file) => (*file).peek_char(),
Stream::NamedTcp(tcp_stream) => (*tcp_stream).peek_char(),
#[cfg(feature = "tls")]
Stream::NamedTls(tls_stream) => (*tls_stream).peek_char(),
#[cfg(feature = "http")]
Stream::HttpRead(http_stream) => (*http_stream).peek_char(),
Stream::Readline(rl_stream) => (*rl_stream).peek_char(),
Stream::StaticString(src) => (*src).peek_char(),
Stream::Byte(cursor) => (*cursor).peek_char(),
#[cfg(feature = "http")]
Stream::HttpWrite(_) => Some(Err(std::io::Error::new(
ErrorKind::PermissionDenied,
StreamError::ReadFromOutputStream,
))),
Stream::OutputFile(_) |
Stream::StandardError(_) |
Stream::StandardOutput(_) |
Stream::HttpWrite(_) |
Stream::Null(_) => Some(Err(std::io::Error::new(
ErrorKind::PermissionDenied,
StreamError::ReadFromOutputStream,
@@ -702,15 +746,21 @@ impl CharRead for Stream {
match self {
Stream::InputFile(file) => (*file).read_char(),
Stream::NamedTcp(tcp_stream) => (*tcp_stream).read_char(),
#[cfg(feature = "tls")]
Stream::NamedTls(tls_stream) => (*tls_stream).read_char(),
#[cfg(feature = "http")]
Stream::HttpRead(http_stream) => (*http_stream).read_char(),
Stream::Readline(rl_stream) => (*rl_stream).read_char(),
Stream::StaticString(src) => (*src).read_char(),
Stream::Byte(cursor) => (*cursor).read_char(),
#[cfg(feature = "http")]
Stream::HttpWrite(_) => Some(Err(std::io::Error::new(
ErrorKind::PermissionDenied,
StreamError::ReadFromOutputStream,
))),
Stream::OutputFile(_) |
Stream::StandardError(_) |
Stream::StandardOutput(_) |
Stream::HttpWrite(_) |
Stream::Null(_) => Some(Err(std::io::Error::new(
ErrorKind::PermissionDenied,
StreamError::ReadFromOutputStream,
@@ -722,15 +772,18 @@ impl CharRead for Stream {
match self {
Stream::InputFile(file) => file.put_back_char(c),
Stream::NamedTcp(tcp_stream) => tcp_stream.put_back_char(c),
#[cfg(feature = "tls")]
Stream::NamedTls(tls_stream) => tls_stream.put_back_char(c),
#[cfg(feature = "http")]
Stream::HttpRead(http_stream) => http_stream.put_back_char(c),
Stream::Readline(rl_stream) => rl_stream.put_back_char(c),
Stream::StaticString(src) => src.put_back_char(c),
Stream::Byte(cursor) => cursor.put_back_char(c),
#[cfg(feature = "http")]
Stream::HttpWrite(_) => {}
Stream::OutputFile(_) |
Stream::StandardError(_) |
Stream::StandardOutput(_) |
Stream::HttpWrite(_) |
Stream::Null(_) => {}
}
}
@@ -739,15 +792,18 @@ impl CharRead for Stream {
match self {
Stream::InputFile(ref mut file) => file.consume(nread),
Stream::NamedTcp(ref mut tcp_stream) => tcp_stream.consume(nread),
#[cfg(feature = "tls")]
Stream::NamedTls(ref mut tls_stream) => tls_stream.consume(nread),
#[cfg(feature = "http")]
Stream::HttpRead(ref mut http_stream) => http_stream.consume(nread),
Stream::Readline(ref mut rl_stream) => rl_stream.consume(nread),
Stream::StaticString(ref mut src) => src.consume(nread),
Stream::Byte(ref mut cursor) => cursor.consume(nread),
#[cfg(feature = "http")]
Stream::HttpWrite(_) => {}
Stream::OutputFile(_) |
Stream::StandardError(_) |
Stream::StandardOutput(_) |
Stream::HttpWrite(_) |
Stream::Null(_) => {}
}
}
@@ -759,15 +815,21 @@ impl Read for Stream {
let bytes_read = match self {
Stream::InputFile(file) => (*file).read(buf),
Stream::NamedTcp(tcp_stream) => (*tcp_stream).read(buf),
#[cfg(feature = "tls")]
Stream::NamedTls(tls_stream) => (*tls_stream).read(buf),
#[cfg(feature = "http")]
Stream::HttpRead(http_stream) => (*http_stream).read(buf),
Stream::Readline(rl_stream) => (*rl_stream).read(buf),
Stream::StaticString(src) => (*src).read(buf),
Stream::Byte(cursor) => (*cursor).read(buf),
#[cfg(feature = "http")]
Stream::HttpWrite(_) => Err(std::io::Error::new(
ErrorKind::PermissionDenied,
StreamError::ReadFromOutputStream,
)),
Stream::OutputFile(_)
| Stream::StandardError(_)
| Stream::StandardOutput(_)
| Stream::HttpWrite(_)
| Stream::Null(_) => Err(std::io::Error::new(
ErrorKind::PermissionDenied,
StreamError::ReadFromOutputStream,
@@ -783,12 +845,18 @@ impl Write for Stream {
match self {
Stream::OutputFile(ref mut file) => file.write(buf),
Stream::NamedTcp(ref mut tcp_stream) => tcp_stream.get_mut().write(buf),
#[cfg(feature = "tls")]
Stream::NamedTls(ref mut tls_stream) => tls_stream.get_mut().write(buf),
Stream::Byte(ref mut cursor) => cursor.get_mut().write(buf),
Stream::StandardOutput(stream) => stream.write(buf),
Stream::StandardError(stream) => stream.write(buf),
#[cfg(feature = "http")]
Stream::HttpWrite(ref mut stream) => stream.get_mut().write(buf),
Stream::HttpRead(_) |
#[cfg(feature = "http")]
Stream::HttpRead(_) => Err(std::io::Error::new(
ErrorKind::PermissionDenied,
StreamError::WriteToInputStream,
)),
Stream::StaticString(_) |
Stream::Readline(_) |
Stream::InputFile(..) |
@@ -803,12 +871,18 @@ impl Write for Stream {
match self {
Stream::OutputFile(ref mut file) => file.stream.flush(),
Stream::NamedTcp(ref mut tcp_stream) => tcp_stream.stream.get_mut().flush(),
#[cfg(feature = "tls")]
Stream::NamedTls(ref mut tls_stream) => tls_stream.stream.get_mut().flush(),
Stream::Byte(ref mut cursor) => cursor.stream.get_mut().flush(),
Stream::StandardError(stream) => stream.stream.flush(),
Stream::StandardOutput(stream) => stream.stream.flush(),
#[cfg(feature = "http")]
Stream::HttpWrite(ref mut stream) => stream.stream.get_mut().flush(),
Stream::HttpRead(_) |
#[cfg(feature = "http")]
Stream::HttpRead(_) => Err(std::io::Error::new(
ErrorKind::PermissionDenied,
StreamError::FlushToInputStream,
)),
Stream::StaticString(_) |
Stream::Readline(_) |
Stream::InputFile(_) |
@@ -913,7 +987,12 @@ impl Stream {
Stream::InputFile(file_stream) => {
file_stream.position()
}
Stream::NamedTcp(..) | Stream::NamedTls(..) | Stream::Readline(..) => {
#[cfg(feature = "tls")]
Stream::NamedTls(..) => {
Some(0)
}
Stream::NamedTcp(..)
| Stream::Readline(..) => {
Some(0)
}
_ => None,
@@ -951,8 +1030,11 @@ impl Stream {
Stream::OutputFile(stream) => stream.past_end_of_stream,
Stream::StaticString(stream) => stream.past_end_of_stream,
Stream::NamedTcp(stream) => stream.past_end_of_stream,
#[cfg(feature = "tls")]
Stream::NamedTls(stream) => stream.past_end_of_stream,
#[cfg(feature = "http")]
Stream::HttpRead(stream) => stream.past_end_of_stream,
#[cfg(feature = "http")]
Stream::HttpWrite(stream) => stream.past_end_of_stream,
Stream::Null(_) => false,
Stream::Readline(stream) => stream.past_end_of_stream,
@@ -974,8 +1056,11 @@ impl Stream {
Stream::OutputFile(stream) => stream.past_end_of_stream = value,
Stream::StaticString(stream) => stream.past_end_of_stream = value,
Stream::NamedTcp(stream) => stream.past_end_of_stream = value,
#[cfg(feature = "tls")]
Stream::NamedTls(stream) => stream.past_end_of_stream = value,
#[cfg(feature = "http")]
Stream::HttpRead(stream) => stream.past_end_of_stream = value,
#[cfg(feature = "http")]
Stream::HttpWrite(stream) => stream.past_end_of_stream = value,
Stream::Null(_) => {}
Stream::Readline(stream) => stream.past_end_of_stream = value,
@@ -1054,6 +1139,7 @@ impl Stream {
Stream::InputFile(file) => Some(file.stream.get_ref().file_name),
Stream::OutputFile(file) => Some(file.stream.file_name),
Stream::NamedTcp(tcp) => Some(tcp.stream.get_ref().address),
#[cfg(feature = "tls")]
Stream::NamedTls(tls) => Some(tls.stream.get_ref().address),
_ => None,
}
@@ -1062,14 +1148,19 @@ impl Stream {
#[inline]
pub(crate) fn mode(&self) -> Atom {
match self {
#[cfg(feature = "http")]
Stream::HttpRead(_) => atom!("read"),
#[cfg(feature = "tls")]
Stream::NamedTls(..) => atom!("read_append"),
Stream::Byte(_)
| Stream::Readline(_)
| Stream::StaticString(_)
| Stream::HttpRead(_)
| Stream::InputFile(..) => atom!("read"),
Stream::NamedTcp(..) | Stream::NamedTls(..) => atom!("read_append"),
Stream::NamedTcp(..) => atom!("read_append"),
Stream::OutputFile(file) if file.is_append => atom!("append"),
Stream::OutputFile(_) | Stream::StandardError(_) | Stream::StandardOutput(_) | Stream::HttpWrite(_) => atom!("write"),
#[cfg(feature = "http")]
Stream::HttpWrite(_) => atom!("write"),
Stream::OutputFile(_) | Stream::StandardError(_) | Stream::StandardOutput(_) => atom!("write"),
Stream::Null(_) => atom!(""),
}
}
@@ -1108,6 +1199,7 @@ impl Stream {
))
}
#[cfg(feature = "tls")]
#[inline]
pub(crate) fn from_tls_stream(
address: Atom,
@@ -1123,6 +1215,7 @@ impl Stream {
))
}
#[cfg(feature = "http")]
#[inline]
pub(crate) fn from_http_stream(
url: Atom,
@@ -1138,6 +1231,7 @@ impl Stream {
))
}
#[cfg(feature = "http")]
#[inline]
pub(crate) fn from_http_sender(
response: TypedArenaPtr<HttpResponse>,
@@ -1189,9 +1283,11 @@ impl Stream {
Stream::NamedTcp(ref mut tcp_stream) => {
tcp_stream.inner_mut().tcp_stream.shutdown(Shutdown::Both)
},
#[cfg(feature = "tls")]
Stream::NamedTls(ref mut tls_stream) => {
tls_stream.inner_mut().tls_stream.shutdown()
}
#[cfg(feature = "http")]
Stream::HttpRead(ref mut http_stream) => {
unsafe {
http_stream.set_tag(ArenaHeaderTag::Dropped);
@@ -1200,7 +1296,8 @@ impl Stream {
Ok(())
}
Stream::HttpWrite(ref mut http_stream) => {
#[cfg(feature = "http")]
Stream::HttpWrite(ref mut http_stream) => {
unsafe {
http_stream.set_tag(ArenaHeaderTag::Dropped);
std::ptr::drop_in_place(&mut http_stream.inner_mut().buffer as *mut _);
@@ -1242,9 +1339,11 @@ impl Stream {
#[inline]
pub(crate) fn is_input_stream(&self) -> bool {
match self {
#[cfg(feature = "tls")]
Stream::NamedTls(..) => true,
#[cfg(feature = "http")]
Stream::HttpRead(..) => true,
Stream::NamedTcp(..)
| Stream::NamedTls(..)
| Stream::HttpRead(..)
| Stream::Byte(_)
| Stream::Readline(_)
| Stream::StaticString(_)
@@ -1256,11 +1355,13 @@ impl Stream {
#[inline]
pub(crate) fn is_output_stream(&self) -> bool {
match self {
#[cfg(feature = "tls")]
Stream::NamedTls(..) => true,
#[cfg(feature = "http")]
Stream::HttpWrite(..) => true,
Stream::StandardError(_)
| Stream::StandardOutput(_)
| Stream::NamedTcp(..)
| Stream::NamedTls(..)
| Stream::HttpWrite(..)
| Stream::Byte(_)
| Stream::OutputFile(..) => true,
_ => false,

View File

@@ -7,9 +7,11 @@ use lazy_static::lazy_static;
use crate::arena::*;
use crate::atom_table::*;
use crate::forms::*;
#[cfg(feature = "ffi")]
use crate::ffi::*;
use crate::heap_iter::*;
use crate::heap_print::*;
#[cfg(feature = "http")]
use crate::http::{HttpService, HttpListener, HttpResponse};
use crate::instructions::*;
use crate::machine;
@@ -44,6 +46,7 @@ use std::cmp::Ordering;
use std::collections::BTreeSet;
use std::convert::TryFrom;
use std::env;
#[cfg(feature = "ffi")]
use std::ffi::CString;
use std::fs;
use std::hash::{BuildHasher, BuildHasherDefault};
@@ -57,10 +60,13 @@ use std::process;
use std::str::FromStr;
use chrono::{offset::Local, DateTime};
#[cfg(not(target_os = "wasi"))]
use cpu_time::ProcessTime;
use std::time::{Duration, SystemTime};
#[cfg(feature = "repl")]
use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyModifiers};
#[cfg(feature = "repl")]
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
use blake2::{Blake2b, Blake2s};
@@ -72,24 +78,28 @@ use ring::{
use ripemd160::{Digest, Ripemd160};
use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512};
use crrl::secp256k1;
use sodiumoxide::crypto::scalarmult::curve25519::*;
use crrl::{secp256k1, x25519};
#[cfg(feature = "tls")]
use native_tls::{TlsConnector,TlsAcceptor,Identity};
use base64;
use roxmltree;
use select;
#[cfg(feature = "http")]
use hyper::server::conn::http1;
#[cfg(feature = "http")]
use hyper::header::{HeaderValue, HeaderName};
#[cfg(feature = "http")]
use hyper::{HeaderMap, Method};
use http_body_util::BodyExt;
use bytes::Buf;
#[cfg(feature = "http")]
use reqwest::Url;
use hyper_util::rt::TokioIo;
#[cfg(feature = "repl")]
pub(crate) fn get_key() -> KeyEvent {
let key;
enable_raw_mode().expect("failed to enable raw mode");
@@ -744,7 +754,7 @@ impl MachineState {
};
if let Some(max_steps) = max_steps_n {
if max_steps.abs() as usize <= 1 << 63 {
if max_steps.abs() as u64 <= 1 << 63 {
if max_steps >= 0 {
max_old = max_steps;
} else {
@@ -979,7 +989,7 @@ impl MachineState {
pub(crate) fn call_continuation_chunk(&mut self, chunk: HeapCellValue, return_p: usize) -> usize {
let chunk = self.store(self.deref(chunk));
let s = chunk.get_value();
let s = chunk.get_value() as usize;
let arity = cell_as_atom_cell!(self.heap[s]).get_arity();
let num_cells = arity - 1;
@@ -1160,7 +1170,7 @@ impl Machine {
let attr_var = self.deref_register(1);
if let HeapCellValueTag::AttrVar = attr_var.get_tag() {
let attr_var_loc = attr_var.get_value();
let attr_var_loc = attr_var.get_value() as usize;
self.machine_st.heap[attr_var_loc] = heap_loc_as_cell!(attr_var_loc);
self.machine_st.trail(TrailRef::Ref(Ref::attr_var(attr_var_loc)));
}
@@ -1346,7 +1356,7 @@ impl Machine {
} else {
if is_internal_call {
debug_assert_eq!(goal.get_tag(), HeapCellValueTag::Str);
goal = self.machine_st.heap[goal.get_value()+1];
goal = self.machine_st.heap[goal.get_value() as usize+1];
(module_name, goal) = self.machine_st.strip_module(goal, module_name);
if let Some((inner_name, inner_arity)) = self.machine_st.name_and_arity_from_heap(goal) {
@@ -1576,7 +1586,7 @@ impl Machine {
);
if HeapCellValueTag::Str == qualified_goal.get_tag() {
let s = qualified_goal.get_value();
let s = qualified_goal.get_value() as usize;
let (name, arity) = cell_as_atom_cell!(self.machine_st.heap[s])
.get_name_and_arity();
@@ -1767,6 +1777,7 @@ impl Machine {
#[inline(always)]
pub(crate) fn current_hostname(&mut self) {
#[cfg(feature = "hostname")]
match hostname::get().ok() {
Some(host) => match host.to_str() {
Some(host) => {
@@ -3682,6 +3693,7 @@ impl Machine {
Ok(())
}
#[cfg(feature = "repl")]
#[inline(always)]
pub(crate) fn get_single_char(&mut self) -> CallResult {
let ctrl_c = KeyEvent {
@@ -3705,7 +3717,28 @@ impl Machine {
KeyCode::Char(c) => c,
_ => unreachable!(),
};
let a1 = self.deref_register(1);
self.machine_st.unify_char(
c,
a1,
);
Ok(())
}
#[cfg(not(feature = "repl"))]
#[inline(always)]
pub(crate) fn get_single_char(&mut self) -> CallResult {
let mut buffer = [0; 1];
// is there a better way?
if std::io::stdin().read(&mut buffer).is_err() {
let stub = functor_stub(atom!("get_single_char"), 1);
let err = self.machine_st.interrupt_error();
let err = self.machine_st.error_form(err, stub);
return Err(err);
}
let c = buffer[0] as char;
let a1 = self.deref_register(1);
self.machine_st.unify_char(
c,
@@ -4161,6 +4194,7 @@ impl Machine {
self.machine_st.fail = result;
}
#[cfg(not(target_os = "wasi"))]
#[inline(always)]
pub(crate) fn cpu_now(&mut self) {
let secs = ProcessTime::now().as_duration().as_secs_f64();
@@ -4169,6 +4203,12 @@ impl Machine {
self.machine_st.unify_f64(secs, self.machine_st.registers[1]);
}
#[cfg(target_os = "wasi")]
#[inline(always)]
pub(crate) fn cpu_now(&mut self) {
// TODO
}
#[inline(always)]
pub(crate) fn det_length_rundown(&mut self) -> CallResult {
let stub_gen = || functor_stub(atom!("length"), 2);
@@ -4201,6 +4241,7 @@ impl Machine {
Ok(())
}
#[cfg(feature = "http")]
#[inline(always)]
pub(crate) fn http_open(&mut self) -> CallResult {
let address_sink = self.deref_register(1);
@@ -4319,6 +4360,7 @@ impl Machine {
Ok(())
}
#[cfg(feature = "http")]
#[inline(always)]
pub(crate) fn http_listen(&mut self) -> CallResult {
let address_sink = self.deref_register(1);
@@ -4371,6 +4413,7 @@ impl Machine {
Ok(())
}
#[cfg(feature = "http")]
#[inline(always)]
pub(crate) fn http_accept(&mut self) -> CallResult {
let culprit = self.deref_register(1);
@@ -4455,6 +4498,7 @@ impl Machine {
Ok(())
}
#[cfg(feature = "http")]
#[inline(always)]
pub(crate) fn http_answer(&mut self) -> CallResult {
let culprit = self.deref_register(1);
@@ -4521,6 +4565,7 @@ impl Machine {
Ok(())
}
#[cfg(feature = "ffi")]
#[inline(always)]
pub(crate) fn load_foreign_lib(&mut self) -> CallResult {
let library_name = self.deref_register(1);
@@ -4567,6 +4612,7 @@ impl Machine {
Ok(())
}
#[cfg(feature = "ffi")]
#[inline(always)]
pub(crate) fn foreign_call(&mut self) -> CallResult {
let function_name = self.deref_register(1);
@@ -4642,6 +4688,7 @@ impl Machine {
Ok(())
}
#[cfg(feature = "ffi")]
fn build_struct(&mut self, name: &str, mut args: Vec<Value>) -> HeapCellValue {
args.insert(0, Value::CString(CString::new(name).unwrap()));
let cells: Vec<_> = args.into_iter()
@@ -4662,6 +4709,7 @@ impl Machine {
)
}
#[cfg(feature = "ffi")]
#[inline(always)]
pub(crate) fn define_foreign_struct(&mut self) -> CallResult {
let struct_name = self.deref_register(1);
@@ -4854,7 +4902,7 @@ impl Machine {
Some(AttrListMatch { match_site: MatchSite::Match(match_site), .. }) => {
let list_head = self.machine_st.heap[match_site];
if list_head.get_value() == match_site {
if list_head.get_value() as usize == match_site {
// at the end of the list, no match found in this case.
self.machine_st.fail = true;
} else {
@@ -4927,7 +4975,7 @@ impl Machine {
prev_tail
} else {
if self.machine_st.heap[match_site + 1].is_var() {
let h = attr_var.get_value();
let h = attr_var.get_value() as usize;
self.machine_st.heap[h] = heap_loc_as_cell!(h);
self.machine_st.trail(TrailRef::Ref(Ref::attr_var(h)));
@@ -5002,13 +5050,13 @@ impl Machine {
}
MatchSite::Match(match_site) => {
let l = self.machine_st.heap[match_site].get_value();
self.machine_st.heap[match_site].set_value(h);
self.machine_st.heap[match_site].set_value(h as u64);
(match_site, l)
}
};
self.machine_st.trail(TrailRef::AttrVarListLink(match_site, l));
self.machine_st.trail(TrailRef::AttrVarListLink(match_site, l as usize));
}
None => {
// the list is empty.
@@ -5038,7 +5086,7 @@ impl Machine {
let mut prev_tail = None;
while let HeapCellValueTag::Lis = attrs_list.get_tag() {
let mut list_head = self.machine_st.heap[attrs_list.get_value()];
let mut list_head = self.machine_st.heap[attrs_list.get_value() as usize];
loop {
read_heap_cell!(list_head,
@@ -5058,7 +5106,7 @@ impl Machine {
if module == module_loc && name == t_name && arity == t_arity {
return Some(AttrListMatch {
match_site: MatchSite::Match(attrs_list.get_value()),
match_site: MatchSite::Match(attrs_list.get_value() as usize),
prev_tail,
});
}
@@ -5071,7 +5119,7 @@ impl Machine {
);
}
let tail_loc = attrs_list.get_value() + 1;
let tail_loc = attrs_list.get_value() as usize + 1;
prev_tail = Some(tail_loc);
// do the work of self.store(self.deref(...)) but inline it
@@ -5416,7 +5464,7 @@ impl Machine {
let value = self.deref_register(2);
debug_assert_eq!(HeapCellValueTag::AttrVar, var.get_tag());
self.machine_st.heap[var.get_value()] = value;
self.machine_st.heap[var.get_value() as usize] = value;
}
#[inline(always)]
@@ -6241,6 +6289,7 @@ impl Machine {
Ok(())
}
#[cfg(feature = "tls")]
#[inline(always)]
pub(crate) fn tls_client_connect(&mut self) -> CallResult {
if let Some(hostname) = self.machine_st.value_to_str_like(self.machine_st.registers[1]) {
@@ -6278,6 +6327,7 @@ impl Machine {
}
}
#[cfg(feature = "tls")]
#[inline(always)]
pub(crate) fn tls_accept_client(&mut self) -> CallResult {
let pkcs12 = self.string_encoding_bytes(self.machine_st.registers[1], atom!("octet"));
@@ -7304,13 +7354,11 @@ impl Machine {
pub(crate) fn curve25519_scalar_mult(&mut self) {
let stub1_gen = || functor_stub(atom!("curve25519_scalar_mult"), 3);
let scalar_bytes = self.machine_st.integers_to_bytevec(self.machine_st.registers[1], stub1_gen);
let scalar = Scalar(<[u8; 32]>::try_from(&scalar_bytes[..]).unwrap());
let stub2_gen = || functor_stub(atom!("curve25519_scalar_mult"), 3);
let point_bytes = self.machine_st.integers_to_bytevec(self.machine_st.registers[2], stub2_gen);
let point = GroupElement(<[u8; 32]>::try_from(&point_bytes[..]).unwrap());
let result = scalarmult(&scalar, &point).unwrap();
let result = x25519::x25519(&<[u8; 32]>::try_from(&point_bytes[..]).unwrap(),
&<[u8; 32]>::try_from(&scalar_bytes[..]).unwrap());
let string = self.u8s_to_string(&result[..]);