-- Copyright 1993-1998, by the Cecil Project -- Department of Computer Science and Engineering, University of Washington -- See the LICENSE file for license information. -- float_vector is a fixed-sized vector of floats, stored in unboxed form abstract object float_vector isa indexed[float]; method as_float_vector(v@:float_vector):float_vector { v } method length(v@:float_vector):int { prim rtl: "decl int len := num_elems_int v; decl OOP lenOop := box_int len; return lenOop;" } method fetch(v@:float_vector, index:int, if_absent:&():float):float { prim rtl: "if is_int_log index goto index_OK; fatal \"can only index into float_vectors with ints\"; label index_OK; decl int i := unbox_int index; decl int len := num_elems_int v; if i <_unsigned_log len goto bounds_OK; decl OOP t5 := send eval(if_absent); return t5; label bounds_OK; decl wordFloat t6 := v[i] wordFloat; decl OOP t7 := box_float t6; return t7; " } -- i_float_vector is a predefined immutable float_vector extend i_float_vector isa float_vector, i_indexed[float]; method new_i_float_vector(size@:int, filler_oop@:float):i_float_vector { prim rtl: " decl int len := unbox_int size; if len >=_int_log 0 goto OK; len := 0; label OK; decl OOP v := new_i_float_vector len; if len =_int_log 0 goto exit; decl wordFloat filler := unbox_float filler_oop; decl int i := 0; label l; v[i] wordFloat := filler; i := i +_int 1; if i <_int_log len goto l; label exit; return v; " } method new_i_float_vector_init(size@:int, cl:&(int):float):i_float_vector { prim rtl: " decl int len := unbox_int size; if len >=_int_log 0 goto OK; len := 0; label OK; decl OOP v := new_i_float_vector len; if len =_int_log 0 goto exit; decl int i := 0; label l; decl OOP tagged_i := box_int i; decl OOP elem_oop := send eval(cl, tagged_i); if is_float_log elem_oop goto elem_OK; fatal \"can only store floats in float_vectors\"; label elem_OK; decl wordFloat elem := unbox_float elem_oop; v[i] wordFloat := elem; i := i +_int 1; if i <_int_log len goto l; label exit; return v; " } method new_i_float_vector_init_from(c@:indexed[`T], cl:&(T):float):i_float_vector (** inline **) { new_i_float_vector_init(c.length, &(i:int){ eval(cl, c!i) }) } method new_i_float_vector_init_from(c@:ordered_collection[`T], cl:&(T):float):i_float_vector { let s:stream[T] := view_stream(c); new_i_float_vector_init(c.length, &(i:int){ eval(cl, s.next) }) } method as_i_float_vector(v@:i_float_vector):i_float_vector { v } -- copying behavior method copy(v@:i_float_vector):i_float_vector { new_i_float_vector_init_from(v, &(x:float){ x }) } -- printing behavior method collection_name(@:i_float_vector):string { "i_float_vector" } -- m_float_vector is a predefined mutable float_vector extend m_float_vector isa float_vector, m_indexed[float]; -- indexing behavior method store(v@:m_float_vector, index:int, x:float, if_absent:&():void):void { prim rtl: "if is_int_log index goto index_OK; fatal \"can only index into float_vectors with ints\"; label index_OK; if is_float_log x goto x_OK; fatal \"can only store floats in float_vectors\"; label x_OK; decl int i := unbox_int index; decl int len := num_elems_int v; if i <_unsigned_log len goto bounds_OK; decl OOP t5 := send eval(if_absent); return void; label bounds_OK; decl wordFloat x_f := unbox_float x; v[i] wordFloat := x_f; return void; " } -- m_float_vector creation behavior method new_m_float_vector(size@:int):m_float_vector { new_m_float_vector(size, 0.0) } method new_m_float_vector(size@:int, filler_oop@:float):m_float_vector { prim rtl: " decl int len := unbox_int size; if len >=_int_log 0 goto OK; len := 0; label OK; decl OOP v := new_m_float_vector len; if len =_int_log 0 goto exit; decl wordFloat filler := unbox_float filler_oop; decl int i := 0; label l; v[i] wordFloat := filler; i := i +_int 1; if i <_int_log len goto l; label exit; return v; " } method new_m_float_vector_init(size@:int, cl:&(int):float):m_float_vector { prim rtl: " decl int len := unbox_int size; if len >=_int_log 0 goto OK; len := 0; label OK; decl OOP v := new_m_float_vector len; if len =_int_log 0 goto exit; decl int i := 0; label l; decl OOP tagged_i := box_int i; decl OOP elem_oop := send eval(cl, tagged_i); if is_float_log elem_oop goto elem_OK; fatal \"can only store floats in float_vectors\"; label elem_OK; decl wordFloat elem := unbox_float elem_oop; v[i] wordFloat := elem; i := i +_int 1; if i <_int_log len goto l; label exit; return v; " } method new_m_float_vector_init_from(c@:indexed[`T], cl:&(T):float ):m_float_vector (** inline **) { new_m_float_vector_init(c.length, &(i:int){ eval(cl, c!i) }) } method new_m_float_vector_init_from(c@:ordered_collection[`T], cl:&(T):float):m_float_vector { let s:stream[T] := view_stream(c); new_m_float_vector_init(c.length, &(i:int){ eval(cl, s.next) }) } method as_m_float_vector(v@:m_float_vector):m_float_vector { v } -- copying behavior method copy(v@:m_float_vector):m_float_vector { new_m_float_vector_init_from(v, &(x:float){ x }) } -- printing behavior method collection_name(@:m_float_vector):string { "m_float_vector" }