fix builds without ffi feature
This commit is contained in:
@@ -4302,62 +4302,50 @@ impl Machine {
|
|||||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||||
}
|
}
|
||||||
&Instruction::CallLoadForeignLib => {
|
&Instruction::CallLoadForeignLib => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.load_foreign_lib());
|
try_or_throw!(self.machine_st, self.load_foreign_lib());
|
||||||
step_or_fail!(self, self.machine_st.p += 1);
|
step_or_fail!(self, self.machine_st.p += 1);
|
||||||
}
|
}
|
||||||
&Instruction::ExecuteLoadForeignLib => {
|
&Instruction::ExecuteLoadForeignLib => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.load_foreign_lib());
|
try_or_throw!(self.machine_st, self.load_foreign_lib());
|
||||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||||
}
|
}
|
||||||
&Instruction::CallForeignCall => {
|
&Instruction::CallForeignCall => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.foreign_call());
|
try_or_throw!(self.machine_st, self.foreign_call());
|
||||||
step_or_fail!(self, self.machine_st.p += 1);
|
step_or_fail!(self, self.machine_st.p += 1);
|
||||||
}
|
}
|
||||||
&Instruction::ExecuteForeignCall => {
|
&Instruction::ExecuteForeignCall => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.foreign_call());
|
try_or_throw!(self.machine_st, self.foreign_call());
|
||||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||||
}
|
}
|
||||||
&Instruction::CallDefineForeignStruct => {
|
&Instruction::CallDefineForeignStruct => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.define_foreign_struct());
|
try_or_throw!(self.machine_st, self.define_foreign_struct());
|
||||||
step_or_fail!(self, self.machine_st.p += 1);
|
step_or_fail!(self, self.machine_st.p += 1);
|
||||||
}
|
}
|
||||||
&Instruction::ExecuteDefineForeignStruct => {
|
&Instruction::ExecuteDefineForeignStruct => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.define_foreign_struct());
|
try_or_throw!(self.machine_st, self.define_foreign_struct());
|
||||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||||
}
|
}
|
||||||
&Instruction::CallFfiAllocate => {
|
&Instruction::CallFfiAllocate => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.ffi_allocate());
|
try_or_throw!(self.machine_st, self.ffi_allocate());
|
||||||
step_or_fail!(self, self.machine_st.p += 1);
|
step_or_fail!(self, self.machine_st.p += 1);
|
||||||
}
|
}
|
||||||
&Instruction::ExecuteFfiAllocate => {
|
&Instruction::ExecuteFfiAllocate => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.ffi_allocate());
|
try_or_throw!(self.machine_st, self.ffi_allocate());
|
||||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||||
}
|
}
|
||||||
&Instruction::CallFfiReadPtr => {
|
&Instruction::CallFfiReadPtr => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.ffi_read_ptr());
|
try_or_throw!(self.machine_st, self.ffi_read_ptr());
|
||||||
step_or_fail!(self, self.machine_st.p += 1);
|
step_or_fail!(self, self.machine_st.p += 1);
|
||||||
}
|
}
|
||||||
&Instruction::ExecuteFfiReadPtr => {
|
&Instruction::ExecuteFfiReadPtr => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.ffi_read_ptr());
|
try_or_throw!(self.machine_st, self.ffi_read_ptr());
|
||||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||||
}
|
}
|
||||||
&Instruction::CallFfiDeallocate => {
|
&Instruction::CallFfiDeallocate => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.ffi_deallocate());
|
try_or_throw!(self.machine_st, self.ffi_deallocate());
|
||||||
step_or_fail!(self, self.machine_st.p += 1);
|
step_or_fail!(self, self.machine_st.p += 1);
|
||||||
}
|
}
|
||||||
&Instruction::ExecuteFfiDeallocate => {
|
&Instruction::ExecuteFfiDeallocate => {
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
try_or_throw!(self.machine_st, self.ffi_deallocate());
|
try_or_throw!(self.machine_st, self.ffi_deallocate());
|
||||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -603,6 +603,20 @@ impl MachineState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn missing_feature_error(&self, feature: Atom) -> MachineError {
|
||||||
|
let stub = functor!(
|
||||||
|
atom!("resource_error"),
|
||||||
|
[functor(
|
||||||
|
(functor!(atom!("feature"), [atom_as_cell((feature))]))
|
||||||
|
)]
|
||||||
|
);
|
||||||
|
|
||||||
|
MachineError {
|
||||||
|
stub,
|
||||||
|
location: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn unreachable_error(&self) -> MachineError {
|
pub(super) fn unreachable_error(&self) -> MachineError {
|
||||||
let stub = functor!(atom!("system_error"));
|
let stub = functor!(atom!("system_error"));
|
||||||
|
|
||||||
|
|||||||
@@ -4952,13 +4952,17 @@ impl Machine {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn load_foreign_lib(&mut self) -> CallResult {
|
pub(crate) fn load_foreign_lib(&mut self) -> CallResult {
|
||||||
|
fn stub_gen() -> MachineStub {
|
||||||
|
functor_stub(atom!("$load_foreign_lib"), 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ffi")]
|
||||||
|
{
|
||||||
let library_name = self.deref_register(1);
|
let library_name = self.deref_register(1);
|
||||||
let args_reg = self.deref_register(2);
|
let args_reg = self.deref_register(2);
|
||||||
if let Some(library_name) = self.machine_st.value_to_str_like(library_name) {
|
if let Some(library_name) = self.machine_st.value_to_str_like(library_name) {
|
||||||
let stub_gen = || functor_stub(atom!("use_foreign_module"), 2);
|
|
||||||
match self.machine_st.try_from_list(args_reg, stub_gen) {
|
match self.machine_st.try_from_list(args_reg, stub_gen) {
|
||||||
Ok(addrs) => {
|
Ok(addrs) => {
|
||||||
let mut functions = Vec::new();
|
let mut functions = Vec::new();
|
||||||
@@ -5003,6 +5007,14 @@ impl Machine {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "ffi"))]
|
||||||
|
{
|
||||||
|
let err = self.machine_st.missing_feature_error(atom!("ffi"));
|
||||||
|
Err(self.machine_st.error_form(err, stub_gen()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ffi")]
|
||||||
fn map_ffi_arg(
|
fn map_ffi_arg(
|
||||||
&mut self,
|
&mut self,
|
||||||
source: HeapCellValue,
|
source: HeapCellValue,
|
||||||
@@ -5070,13 +5082,14 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn foreign_call(&mut self) -> CallResult {
|
pub(crate) fn foreign_call(&mut self) -> CallResult {
|
||||||
fn stub_gen() -> Vec<FunctorElement> {
|
fn stub_gen() -> Vec<FunctorElement> {
|
||||||
functor_stub(atom!("foreign_call"), 3)
|
functor_stub(atom!("$foreign_call"), 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ffi")]
|
||||||
|
{
|
||||||
let function_name_arg = self.deref_register(1);
|
let function_name_arg = self.deref_register(1);
|
||||||
let args_reg = self.deref_register(2);
|
let args_reg = self.deref_register(2);
|
||||||
let return_value = self.deref_register(3);
|
let return_value = self.deref_register(3);
|
||||||
@@ -5110,6 +5123,14 @@ impl Machine {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "ffi"))]
|
||||||
|
{
|
||||||
|
let err = self.machine_st.missing_feature_error(atom!("ffi"));
|
||||||
|
Err(self.machine_st.error_form(err, stub_gen()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ffi")]
|
||||||
fn unify_ffi_result(&mut self, return_value: HeapCellValue, result: Value) -> CallResult {
|
fn unify_ffi_result(&mut self, return_value: HeapCellValue, result: Value) -> CallResult {
|
||||||
match result {
|
match result {
|
||||||
Value::Number(n) => match n {
|
Value::Number(n) => match n {
|
||||||
@@ -5170,13 +5191,14 @@ impl Machine {
|
|||||||
sized_iter_to_heap_list(&mut self.machine_st.heap, cells.len(), cells.into_iter())
|
sized_iter_to_heap_list(&mut self.machine_st.heap, cells.len(), cells.into_iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ffi")]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn define_foreign_struct(&mut self) -> CallResult {
|
pub(crate) fn define_foreign_struct(&mut self) -> CallResult {
|
||||||
fn stub_gen() -> MachineStub {
|
fn stub_gen() -> MachineStub {
|
||||||
functor_stub(atom!("$define_foreign_struct"), 2)
|
functor_stub(atom!("$define_foreign_struct"), 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ffi")]
|
||||||
|
{
|
||||||
let struct_name_arg = self.deref_register(1);
|
let struct_name_arg = self.deref_register(1);
|
||||||
let fields_reg = self.deref_register(2);
|
let fields_reg = self.deref_register(2);
|
||||||
if let Some(struct_name) = self.machine_st.value_to_str_like(struct_name_arg) {
|
if let Some(struct_name) = self.machine_st.value_to_str_like(struct_name_arg) {
|
||||||
@@ -5213,9 +5235,20 @@ impl Machine {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn ffi_allocate(&mut self) -> CallResult {
|
#[cfg(not(feature = "ffi"))]
|
||||||
let stub_gen = || functor_stub(atom!("$ffi_allocate"), 4);
|
{
|
||||||
|
let err = self.machine_st.missing_feature_error(atom!("ffi"));
|
||||||
|
Err(self.machine_st.error_form(err, stub_gen()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn ffi_allocate(&mut self) -> CallResult {
|
||||||
|
fn stub_gen() -> MachineStub {
|
||||||
|
functor_stub(atom!("$ffi_allocate"), 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ffi")]
|
||||||
|
{
|
||||||
let allocator = self.deref_register(1);
|
let allocator = self.deref_register(1);
|
||||||
let ffi_type_arg = self.deref_register(2);
|
let ffi_type_arg = self.deref_register(2);
|
||||||
let ffi_type = ffi_type_arg.to_atom().unwrap();
|
let ffi_type = ffi_type_arg.to_atom().unwrap();
|
||||||
@@ -5247,9 +5280,20 @@ impl Machine {
|
|||||||
self.unify_ffi_result(return_value, value)
|
self.unify_ffi_result(return_value, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn ffi_read_ptr(&mut self) -> CallResult {
|
#[cfg(not(feature = "ffi"))]
|
||||||
let stub_gen = || functor_stub(atom!("$ffi_read_ptr"), 3);
|
{
|
||||||
|
let err = self.machine_st.missing_feature_error(atom!("ffi"));
|
||||||
|
Err(self.machine_st.error_form(err, stub_gen()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn ffi_read_ptr(&mut self) -> CallResult {
|
||||||
|
fn stub_gen() -> MachineStub {
|
||||||
|
functor_stub(atom!("$ffi_read_ptr"), 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ffi")]
|
||||||
|
{
|
||||||
let ffi_type_arg = self.deref_register(1);
|
let ffi_type_arg = self.deref_register(1);
|
||||||
let ffi_type = ffi_type_arg.to_atom().unwrap();
|
let ffi_type = ffi_type_arg.to_atom().unwrap();
|
||||||
let ptr = self.deref_register(2);
|
let ptr = self.deref_register(2);
|
||||||
@@ -5268,9 +5312,20 @@ impl Machine {
|
|||||||
self.unify_ffi_result(return_value, value)
|
self.unify_ffi_result(return_value, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn ffi_deallocate(&mut self) -> CallResult {
|
#[cfg(not(feature = "ffi"))]
|
||||||
let stub_gen = || functor_stub(atom!("$ffi_deallocate"), 3);
|
{
|
||||||
|
let err = self.machine_st.missing_feature_error(atom!("ffi"));
|
||||||
|
Err(self.machine_st.error_form(err, stub_gen()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn ffi_deallocate(&mut self) -> CallResult {
|
||||||
|
fn stub_gen() -> MachineStub {
|
||||||
|
functor_stub(atom!("$ffi_deallocate"), 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ffi")]
|
||||||
|
{
|
||||||
let allocator = self.deref_register(1);
|
let allocator = self.deref_register(1);
|
||||||
let ffi_type_arg = self.deref_register(2);
|
let ffi_type_arg = self.deref_register(2);
|
||||||
let ffi_type = ffi_type_arg.to_atom().unwrap();
|
let ffi_type = ffi_type_arg.to_atom().unwrap();
|
||||||
@@ -5295,10 +5350,16 @@ impl Machine {
|
|||||||
return Err(self.machine_st.error_form(machine_error, stub_gen()));
|
return Err(self.machine_st.error_form(machine_error, stub_gen()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "ffi"))]
|
||||||
|
{
|
||||||
|
let err = self.machine_st.missing_feature_error(atom!("ffi"));
|
||||||
|
Err(self.machine_st.error_form(err, stub_gen()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn js_eval(&mut self) -> CallResult {
|
pub(crate) fn js_eval(&mut self) -> CallResult {
|
||||||
|
|||||||
Reference in New Issue
Block a user