Fix std Strings
This commit is contained in:
parent
3d73c52cb4
commit
bbdfae081d
@ -36,15 +36,27 @@ pub fn new_string() -> String {
|
|||||||
|
|
||||||
pub fn add_char(string: &mut String, c: char) {
|
pub fn add_char(string: &mut String, c: char) {
|
||||||
if ((*string).length + 1) >= (*string).max_length {
|
if ((*string).length + 1) >= (*string).max_length {
|
||||||
|
let new = allocate((*string).max_length + 4) as *char;
|
||||||
|
copy_bits((*string).inner, new, 0, (*string).max_length);
|
||||||
|
|
||||||
free((*string).inner as *u8);
|
free((*string).inner as *u8);
|
||||||
(*string).max_length = (*string).max_length + 4;
|
(*string).max_length = (*string).max_length + 4;
|
||||||
(*string).inner = allocate((*string).max_length) as *char;
|
(*string).inner = new;
|
||||||
|
|
||||||
}
|
}
|
||||||
(*string).inner[(*string).length] = c;
|
(*string).inner[(*string).length] = c;
|
||||||
(((*string).inner) as *u8)[((*string).length + 1)] = 0;
|
(((*string).inner) as *u8)[((*string).length + 1)] = 0;
|
||||||
(*string).length = (*string).length + 1;
|
(*string).length = (*string).length + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn copy_bits(from: *char, to: *char, pos: u64, max: u64) -> u8 {
|
||||||
|
if (pos >= max) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
to[pos] = from[pos];
|
||||||
|
return copy_bits(from, to, pos + 1, max);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn free_string(string: &mut String) {
|
pub fn free_string(string: &mut String) {
|
||||||
free((*string).inner as *u8);
|
free((*string).inner as *u8);
|
||||||
}
|
}
|
@ -150,7 +150,7 @@ pub fn perform_all_passes<'map>(
|
|||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
println!("{:-^100}", "TYPE INFERRER OUTPUT");
|
println!("{:-^100}", "TYPE INFERRER OUTPUT");
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
dbg!(&refs);
|
println!("{}", &refs);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
println!("{}", &context);
|
println!("{}", &context);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
@ -2,7 +2,27 @@ use std::fmt::{Debug, Display, Write};
|
|||||||
|
|
||||||
use crate::pad_adapter::PadAdapter;
|
use crate::pad_adapter::PadAdapter;
|
||||||
|
|
||||||
use super::*;
|
use super::{
|
||||||
|
typerefs::{TypeRef, TypeRefs},
|
||||||
|
*,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl Display for TypeRefs {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
for (i, typeref) in self.type_refs.borrow().iter().enumerate() {
|
||||||
|
let idx = *typeref.borrow();
|
||||||
|
writeln!(
|
||||||
|
f,
|
||||||
|
"{:<3} = {:<3} = {:?} = {}",
|
||||||
|
i,
|
||||||
|
unsafe { *self.recurse_type_ref(idx).borrow() },
|
||||||
|
self.retrieve_type(idx),
|
||||||
|
TypeKind::Vague(VagueType::TypeRef(idx)).resolve_ref(self)
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for Context {
|
impl Display for Context {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
@ -13,8 +13,8 @@ use super::{
|
|||||||
pass::{Pass, PassResult, PassState},
|
pass::{Pass, PassResult, PassState},
|
||||||
typecheck::ErrorKind,
|
typecheck::ErrorKind,
|
||||||
typerefs::{ScopeTypeRefs, TypeRef, TypeRefs},
|
typerefs::{ScopeTypeRefs, TypeRef, TypeRefs},
|
||||||
Block, ExprKind, Expression, FunctionDefinition, FunctionDefinitionKind, IfExpression, Module,
|
Block, CustomTypeKey, ExprKind, Expression, FunctionDefinition, FunctionDefinitionKind,
|
||||||
ReturnKind, StmtKind, CustomTypeKey,
|
IfExpression, Module, ReturnKind, StmtKind,
|
||||||
TypeKind::*,
|
TypeKind::*,
|
||||||
VagueType::*,
|
VagueType::*,
|
||||||
};
|
};
|
||||||
@ -183,8 +183,8 @@ impl Expression {
|
|||||||
type_refs
|
type_refs
|
||||||
.binop(op, &mut lhs_ref, &mut rhs_ref)
|
.binop(op, &mut lhs_ref, &mut rhs_ref)
|
||||||
.ok_or(ErrorKind::TypesIncompatible(
|
.ok_or(ErrorKind::TypesIncompatible(
|
||||||
lhs_ref.as_type(),
|
lhs_ref.resolve_deep().unwrap(),
|
||||||
rhs_ref.as_type(),
|
rhs_ref.resolve_deep().unwrap(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
ExprKind::FunctionCall(function_call) => {
|
ExprKind::FunctionCall(function_call) => {
|
||||||
|
@ -9,7 +9,10 @@ use crate::mir::VagueType;
|
|||||||
use super::{typecheck::ErrorKind, BinaryOperator, TypeKind};
|
use super::{typecheck::ErrorKind, BinaryOperator, TypeKind};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TypeRef<'scope>(TypeIdRef, &'scope ScopeTypeRefs<'scope>);
|
pub struct TypeRef<'scope>(
|
||||||
|
pub(super) TypeIdRef,
|
||||||
|
pub(super) &'scope ScopeTypeRefs<'scope>,
|
||||||
|
);
|
||||||
|
|
||||||
impl<'scope> TypeRef<'scope> {
|
impl<'scope> TypeRef<'scope> {
|
||||||
/// Resolve current type in a weak manner, not resolving any Arrays or
|
/// Resolve current type in a weak manner, not resolving any Arrays or
|
||||||
@ -54,9 +57,9 @@ type TypeIdRef = Rc<RefCell<usize>>;
|
|||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct TypeRefs {
|
pub struct TypeRefs {
|
||||||
/// Simple list of types that variables can refrence
|
/// Simple list of types that variables can refrence
|
||||||
hints: RefCell<Vec<TypeKind>>,
|
pub(super) hints: RefCell<Vec<TypeKind>>,
|
||||||
/// Indirect ID-references, referring to hints-vec
|
/// Indirect ID-references, referring to hints-vec
|
||||||
type_refs: RefCell<Vec<TypeIdRef>>,
|
pub(super) type_refs: RefCell<Vec<TypeIdRef>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypeRefs {
|
impl TypeRefs {
|
||||||
@ -89,7 +92,7 @@ impl TypeRefs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn recurse_type_ref(&self, mut idx: usize) -> TypeIdRef {
|
pub(super) unsafe fn recurse_type_ref(&self, mut idx: usize) -> TypeIdRef {
|
||||||
let refs = self.type_refs.borrow();
|
let refs = self.type_refs.borrow();
|
||||||
let mut inner_idx = refs.get_unchecked(idx);
|
let mut inner_idx = refs.get_unchecked(idx);
|
||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user