From 0f2a89cfbd50e6fb4c3fa8728b79d5d14209d165 Mon Sep 17 00:00:00 2001 From: Phil Dawes Date: Mon, 17 Aug 2009 21:37:06 +0100 Subject: [PATCH] moved strings fns to vm --- vm/strings.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++-------- vm/vm.hpp | 16 +++++++++ 2 files changed, 100 insertions(+), 14 deletions(-) diff --git a/vm/strings.cpp b/vm/strings.cpp index c70d9dfb6d..7e0506a519 100644 --- a/vm/strings.cpp +++ b/vm/strings.cpp @@ -3,7 +3,7 @@ namespace factor { -cell string_nth(string* str, cell index) +cell factorvm::string_nth(string* str, cell index) { /* If high bit is set, the most significant 16 bits of the char come from the aux vector. The least significant bit of the @@ -22,12 +22,22 @@ cell string_nth(string* str, cell index) } } -void set_string_nth_fast(string *str, cell index, cell ch) +cell string_nth(string* str, cell index) +{ + return vm->string_nth(str,index); +} + +void factorvm::set_string_nth_fast(string *str, cell index, cell ch) { str->data()[index] = ch; } -void set_string_nth_slow(string *str_, cell index, cell ch) +void set_string_nth_fast(string *str, cell index, cell ch) +{ + return vm->set_string_nth_fast(str,index,ch); +} + +void factorvm::set_string_nth_slow(string *str_, cell index, cell ch) { gc_root str(str_); @@ -54,8 +64,13 @@ void set_string_nth_slow(string *str_, cell index, cell ch) aux->data()[index] = ((ch >> 7) ^ 1); } +void set_string_nth_slow(string *str_, cell index, cell ch) +{ + return vm->set_string_nth_slow(str_,index,ch); +} + /* allocates memory */ -void set_string_nth(string *str, cell index, cell ch) +void factorvm::set_string_nth(string *str, cell index, cell ch) { if(ch <= 0x7f) set_string_nth_fast(str,index,ch); @@ -63,8 +78,13 @@ void set_string_nth(string *str, cell index, cell ch) set_string_nth_slow(str,index,ch); } +void set_string_nth(string *str, cell index, cell ch) +{ + return vm->set_string_nth(str,index,ch); +} + /* Allocates memory */ -string *allot_string_internal(cell capacity) +string *factorvm::allot_string_internal(cell capacity) { string *str = allot(string_size(capacity)); @@ -75,8 +95,13 @@ string *allot_string_internal(cell capacity) return str; } +string *allot_string_internal(cell capacity) +{ + return vm->allot_string_internal(capacity); +} + /* Allocates memory */ -void fill_string(string *str_, cell start, cell capacity, cell fill) +void factorvm::fill_string(string *str_, cell start, cell capacity, cell fill) { gc_root str(str_); @@ -91,29 +116,49 @@ void fill_string(string *str_, cell start, cell capacity, cell fill) } } +void fill_string(string *str_, cell start, cell capacity, cell fill) +{ + return vm->fill_string(str_,start,capacity,fill); +} + /* Allocates memory */ -string *allot_string(cell capacity, cell fill) +string *factorvm::allot_string(cell capacity, cell fill) { gc_root str(allot_string_internal(capacity)); fill_string(str.untagged(),0,capacity,fill); return str.untagged(); } -PRIMITIVE(string) +string *allot_string(cell capacity, cell fill) +{ + return vm->allot_string(capacity,fill); +} + +inline void factorvm::vmprim_string() { cell initial = to_cell(dpop()); cell length = unbox_array_size(); dpush(tag(allot_string(length,initial))); } -static bool reallot_string_in_place_p(string *str, cell capacity) +PRIMITIVE(string) +{ + PRIMITIVE_GETVM()->vmprim_string(); +} + +bool factorvm::reallot_string_in_place_p(string *str, cell capacity) { return in_zone(&nursery,str) && (str->aux == F || in_zone(&nursery,untag(str->aux))) && capacity <= string_capacity(str); } -string* reallot_string(string *str_, cell capacity) +bool reallot_string_in_place_p(string *str, cell capacity) +{ + return vm->reallot_string_in_place_p(str,capacity); +} + +string* factorvm::reallot_string(string *str_, cell capacity) { gc_root str(str_); @@ -155,21 +200,36 @@ string* reallot_string(string *str_, cell capacity) } } -PRIMITIVE(resize_string) +string* reallot_string(string *str_, cell capacity) +{ + return vm->reallot_string(str_,capacity); +} + +inline void factorvm::vmprim_resize_string() { string* str = untag_check(dpop()); cell capacity = unbox_array_size(); dpush(tag(reallot_string(str,capacity))); } -PRIMITIVE(string_nth) +PRIMITIVE(resize_string) +{ + PRIMITIVE_GETVM()->vmprim_resize_string(); +} + +inline void factorvm::vmprim_string_nth() { string *str = untag(dpop()); cell index = untag_fixnum(dpop()); dpush(tag_fixnum(string_nth(str,index))); } -PRIMITIVE(set_string_nth_fast) +PRIMITIVE(string_nth) +{ + PRIMITIVE_GETVM()->vmprim_string_nth(); +} + +inline void factorvm::vmprim_set_string_nth_fast() { string *str = untag(dpop()); cell index = untag_fixnum(dpop()); @@ -177,7 +237,12 @@ PRIMITIVE(set_string_nth_fast) set_string_nth_fast(str,index,value); } -PRIMITIVE(set_string_nth_slow) +PRIMITIVE(set_string_nth_fast) +{ + PRIMITIVE_GETVM()->vmprim_set_string_nth_fast(); +} + +inline void factorvm::vmprim_set_string_nth_slow() { string *str = untag(dpop()); cell index = untag_fixnum(dpop()); @@ -185,4 +250,9 @@ PRIMITIVE(set_string_nth_slow) set_string_nth_slow(str,index,value); } +PRIMITIVE(set_string_nth_slow) +{ + PRIMITIVE_GETVM()->vmprim_set_string_nth_slow(); +} + } diff --git a/vm/vm.hpp b/vm/vm.hpp index 65fea6f9f2..087e1ebe95 100644 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -205,6 +205,22 @@ struct factorvm { cell allot_array_2(cell v1_, cell v2_); cell allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_); inline void vmprim_resize_array(); + + //strings + cell string_nth(string* str, cell index); + void set_string_nth_fast(string *str, cell index, cell ch); + void set_string_nth_slow(string *str_, cell index, cell ch); + void set_string_nth(string *str, cell index, cell ch); + string *allot_string_internal(cell capacity); + void fill_string(string *str_, cell start, cell capacity, cell fill); + string *allot_string(cell capacity, cell fill); + inline void vmprim_string(); + bool reallot_string_in_place_p(string *str, cell capacity); + string* reallot_string(string *str_, cell capacity); + inline void vmprim_resize_string(); + inline void vmprim_string_nth(); + inline void vmprim_set_string_nth_fast(); + inline void vmprim_set_string_nth_slow(); // next method here: