use super::super::context::JITContext;
use super::jit_kinds::*;
use super::value_ffi::*;
pub extern "C" fn jit_get_field(ctx: *mut JITContext, row_offset: i32, column_index: u32) -> u64 {
unsafe {
if ctx.is_null() {
return TAG_NULL;
}
let ctx_ref = &*ctx;
let row_signed = ctx_ref.current_row as i32 + row_offset;
if row_signed < 0 || row_signed as usize >= ctx_ref.row_count {
return TAG_NULL;
}
let row_idx = row_signed as usize;
if column_index as usize >= ctx_ref.column_count {
return TAG_NULL;
}
if ctx_ref.column_ptrs.is_null() {
return TAG_NULL;
}
let col_ptr = *ctx_ref.column_ptrs.add(column_index as usize);
if col_ptr.is_null() {
return TAG_NULL;
}
let value = *col_ptr.add(row_idx);
box_number(value)
}
}
pub extern "C" fn jit_get_row_ref(ctx: *mut JITContext, row_offset: i32) -> u64 {
unsafe {
if ctx.is_null() {
return TAG_NULL;
}
let ctx_ref = &*ctx;
let row_signed = ctx_ref.current_row as i32 + row_offset;
if row_signed < 0 || row_signed as usize >= ctx_ref.row_count {
return TAG_NULL;
}
let row_idx = row_signed as usize;
box_data_row(row_idx)
}
}
pub extern "C" fn jit_row_get_field(ctx: *mut JITContext, row_ref: u64, column_index: u32) -> u64 {
unsafe {
if ctx.is_null() {
return TAG_NULL;
}
let ctx_ref = &*ctx;
if !is_data_row(row_ref) {
return TAG_NULL;
}
let row_idx = unbox_data_row(row_ref);
if row_idx >= ctx_ref.row_count {
return TAG_NULL;
}
if column_index as usize >= ctx_ref.column_count {
return TAG_NULL;
}
if ctx_ref.column_ptrs.is_null() {
return TAG_NULL;
}
let col_ptr = *ctx_ref.column_ptrs.add(column_index as usize);
if col_ptr.is_null() {
return TAG_NULL;
}
let value = *col_ptr.add(row_idx);
box_number(value)
}
}
pub extern "C" fn jit_get_row_timestamp(ctx: *mut JITContext, row_offset: i32) -> u64 {
unsafe {
if ctx.is_null() {
return TAG_NULL;
}
let ctx_ref = &*ctx;
let row_signed = ctx_ref.current_row as i32 + row_offset;
if row_signed < 0 || row_signed as usize >= ctx_ref.row_count {
return TAG_NULL;
}
let row_idx = row_signed as usize;
if ctx_ref.timestamps_ptr.is_null() {
return TAG_NULL;
}
let timestamp = *ctx_ref.timestamps_ptr.add(row_idx);
unified_box(HK_TIME, timestamp)
}
}
pub extern "C" fn jit_get_row_count(ctx: *mut JITContext) -> u64 {
unsafe {
if ctx.is_null() {
return box_number(0.0);
}
let ctx_ref = &*ctx;
box_number(ctx_ref.row_count as f64)
}
}
pub extern "C" fn jit_get_current_row(ctx: *mut JITContext) -> u64 {
unsafe {
if ctx.is_null() {
return box_number(0.0);
}
let ctx_ref = &*ctx;
box_number(ctx_ref.current_row as f64)
}
}
pub extern "C" fn jit_load_col_f64(ctx: *mut JITContext, col_id: u32, row_ref: u64) -> u64 {
unsafe {
if ctx.is_null() {
return TAG_NULL;
}
let ctx_ref = &*ctx;
let row_idx = if is_data_row(row_ref) {
unbox_data_row(row_ref)
} else {
ctx_ref.current_row
};
if row_idx >= ctx_ref.row_count || col_id as usize >= ctx_ref.column_count {
return TAG_NULL;
}
if ctx_ref.column_ptrs.is_null() {
return TAG_NULL;
}
let col_ptr = *ctx_ref.column_ptrs.add(col_id as usize);
if col_ptr.is_null() {
return TAG_NULL;
}
let value = *col_ptr.add(row_idx);
box_number(value)
}
}
pub extern "C" fn jit_load_col_i64(ctx: *mut JITContext, col_id: u32, row_ref: u64) -> u64 {
unsafe {
if ctx.is_null() {
return TAG_NULL;
}
let ctx_ref = &*ctx;
let row_idx = if is_data_row(row_ref) {
unbox_data_row(row_ref)
} else {
ctx_ref.current_row
};
if row_idx >= ctx_ref.row_count || col_id as usize >= ctx_ref.column_count {
return TAG_NULL;
}
if ctx_ref.column_ptrs.is_null() {
return TAG_NULL;
}
let col_ptr = *ctx_ref.column_ptrs.add(col_id as usize);
if col_ptr.is_null() {
return TAG_NULL;
}
let value = *col_ptr.add(row_idx);
box_number(value.trunc())
}
}
pub extern "C" fn jit_load_col_bool(ctx: *mut JITContext, col_id: u32, row_ref: u64) -> u64 {
unsafe {
if ctx.is_null() {
return TAG_NULL;
}
let ctx_ref = &*ctx;
let row_idx = if is_data_row(row_ref) {
unbox_data_row(row_ref)
} else {
ctx_ref.current_row
};
if row_idx >= ctx_ref.row_count || col_id as usize >= ctx_ref.column_count {
return TAG_NULL;
}
if ctx_ref.column_ptrs.is_null() {
return TAG_NULL;
}
let col_ptr = *ctx_ref.column_ptrs.add(col_id as usize);
if col_ptr.is_null() {
return TAG_NULL;
}
let value = *col_ptr.add(row_idx);
if value != 0.0 {
TAG_BOOL_TRUE
} else {
TAG_BOOL_FALSE
}
}
}
pub extern "C" fn jit_load_col_str(_ctx: *mut JITContext, _col_id: u32, _row_ref: u64) -> u64 {
TAG_NULL
}
pub extern "C" fn jit_eval_data_datetime_ref(_ctx: *mut JITContext, _expr: u64) -> u64 {
TAG_NULL
}
pub extern "C" fn jit_eval_data_relative(_ctx: *mut JITContext, _expr: u64, _offset: i32) -> u64 {
TAG_NULL
}
pub extern "C" fn jit_get_field_typed(obj: u64, type_id: u64, field_idx: u64, offset: u64) -> u64 {
#[allow(unused_imports)]
use crate::ffi::object::conversion::{jit_bits_to_nanboxed, nanboxed_to_jit_bits};
if is_typed_object(obj) {
let ptr = unbox_typed_object(obj) as *const super::typed_object::TypedObject;
if !ptr.is_null() {
return unsafe {
if type_id != 0 && (*ptr).schema_id != type_id as u32 {
TAG_NULL
} else {
(*ptr).get_field(offset as usize)
}
};
}
}
let _ = field_idx;
TAG_NULL
}
pub extern "C" fn jit_set_field_typed(
obj: u64,
value: u64,
type_id: u64,
_field_idx: u64,
offset: u64,
) -> u64 {
if is_typed_object(obj) {
let ptr = unbox_typed_object(obj) as *mut super::typed_object::TypedObject;
if !ptr.is_null() {
return unsafe {
if type_id != 0 && (*ptr).schema_id != type_id as u32 {
obj } else {
let old_bits = (*ptr).get_field(offset as usize);
super::gc::jit_write_barrier(old_bits, value);
(*ptr).set_field(offset as usize, value);
obj
}
};
}
}
obj
}