introduce bespoke Heap type for in-heap partial strings

This commit is contained in:
Mark Thom
2024-05-13 18:00:56 -06:00
committed by Mark Thom
parent f7bbdfe73a
commit c0f72704ec
54 changed files with 7836 additions and 7167 deletions

View File

@@ -5,22 +5,24 @@ use crate::forms::*;
use crate::instructions::*;
use crate::types::*;
use std::rc::Rc;
pub(crate) struct FactInstruction;
pub(crate) struct QueryInstruction;
pub(crate) trait CompilationTarget<'a> {
fn to_constant(lvl: Level, literal: Literal, r: RegType) -> Instruction;
fn to_constant(lvl: Level, cell: HeapCellValue, r: RegType) -> Instruction;
fn to_list(lvl: Level, r: RegType) -> Instruction;
fn to_structure(lvl: Level, name: Atom, arity: usize, r: RegType) -> Instruction;
fn to_void(num_subterms: usize) -> Instruction;
fn is_void_instr(instr: &Instruction) -> bool;
fn to_pstr(lvl: Level, string: Atom, r: RegType, has_tail: bool) -> Instruction;
fn to_pstr(lvl: Level, string: Rc<String>, r: RegType) -> Instruction;
fn incr_void_instr(instr: &mut Instruction);
fn constant_subterm(literal: Literal) -> Instruction;
fn constant_subterm(literal: HeapCellValue) -> Instruction;
fn argument_to_variable(r: RegType, r: usize) -> Instruction;
fn argument_to_value(r: RegType, val: usize) -> Instruction;
@@ -36,8 +38,8 @@ pub(crate) trait CompilationTarget<'a> {
}
impl<'a> CompilationTarget<'a> for FactInstruction {
fn to_constant(lvl: Level, constant: Literal, reg: RegType) -> Instruction {
Instruction::GetConstant(lvl, HeapCellValue::from(constant), reg)
fn to_constant(lvl: Level, cell: HeapCellValue, reg: RegType) -> Instruction {
Instruction::GetConstant(lvl, cell, reg)
}
fn to_structure(lvl: Level, name: Atom, arity: usize, reg: RegType) -> Instruction {
@@ -56,8 +58,8 @@ impl<'a> CompilationTarget<'a> for FactInstruction {
matches!(instr, &Instruction::UnifyVoid(_))
}
fn to_pstr(lvl: Level, string: Atom, r: RegType, has_tail: bool) -> Instruction {
Instruction::GetPartialString(lvl, string, r, has_tail)
fn to_pstr(lvl: Level, string: Rc<String>, r: RegType) -> Instruction {
Instruction::GetPartialString(lvl, string, r)
}
fn incr_void_instr(instr: &mut Instruction) {
@@ -66,8 +68,8 @@ impl<'a> CompilationTarget<'a> for FactInstruction {
}
}
fn constant_subterm(constant: Literal) -> Instruction {
Instruction::UnifyConstant(HeapCellValue::from(constant))
fn constant_subterm(constant: HeapCellValue) -> Instruction {
Instruction::UnifyConstant(constant)
}
fn argument_to_variable(arg: RegType, val: usize) -> Instruction {
@@ -104,20 +106,20 @@ impl<'a> CompilationTarget<'a> for FactInstruction {
}
impl<'a> CompilationTarget<'a> for QueryInstruction {
fn to_structure(_lvl: Level, name: Atom, arity: usize, r: RegType) -> Instruction {
Instruction::PutStructure(name, arity, r)
fn to_constant(lvl: Level, constant: HeapCellValue, reg: RegType) -> Instruction {
Instruction::PutConstant(lvl, constant, reg)
}
fn to_constant(lvl: Level, constant: Literal, reg: RegType) -> Instruction {
Instruction::PutConstant(lvl, HeapCellValue::from(constant), reg)
fn to_structure(_lvl: Level, name: Atom, arity: usize, r: RegType) -> Instruction {
Instruction::PutStructure(name, arity, r)
}
fn to_list(lvl: Level, reg: RegType) -> Instruction {
Instruction::PutList(lvl, reg)
}
fn to_pstr(lvl: Level, string: Atom, r: RegType, has_tail: bool) -> Instruction {
Instruction::PutPartialString(lvl, string, r, has_tail)
fn to_pstr(lvl: Level, string: Rc<String>, r: RegType) -> Instruction {
Instruction::PutPartialString(lvl, string, r)
}
fn to_void(subterms: usize) -> Instruction {
@@ -134,8 +136,8 @@ impl<'a> CompilationTarget<'a> for QueryInstruction {
}
}
fn constant_subterm(constant: Literal) -> Instruction {
Instruction::SetConstant(HeapCellValue::from(constant))
fn constant_subterm(constant: HeapCellValue) -> Instruction {
Instruction::SetConstant(constant)
}
fn argument_to_variable(arg: RegType, val: usize) -> Instruction {