on master help sign in
Move buffer offset handling into idris code

This simplifies the native code significantly, including removing GETTYs at every Buffer-related function call, at the cost of: * Needing to store an offset of 0 in cases where the old code could just refer directly to the struct Buffer * Boxing of the offset * When an append to a buffer requires an allocation + copy, all of the data before the offset needs to be allocated and copied too (as there doesn't seem to be a good way for the append functions to tell the idris code when the offset needs to be changed and when not) I think the simplification outweighs the cost, but I don't have hard numbers so YMMV.

commit6efa70d417feffb3e8cb734bb284a2dab73592c9 authorShea Levy <shea@shealevy.com> dateSat 1 Feb 2014, 16:34 (13 years ago) parent55b241a
8 files changed+90−240
libs/base/Data/Buffer.idr+30−36 rts/idris_gc.c+1−8 rts/idris_heap.c−9 rts/idris_rts.c+54−165 rts/idris_rts.h+2−11 src/IRTS/CodegenC.hs+1−3 src/IRTS/Lang.hs−2 src/Idris/Primitives.hs+2−6
libs/base/Data/Buffer.idr+30−36
@@ -19,11 +19,14 @@ module Data.Buffer
1919-- 6. Conversion from Fin to Bits64 (which, re 2, should eventually
2020-- be a fixed-width implementation-dependent type) is likely
2121-- inefficient relative to conversion from Nat to Bits64
22+-- 7. We may want to have a separate type that is a product of Buffer
23+-- and offset rather than storing the offset in Buffer itself, which
24+-- would require exposing the offset argument of prim__appendBuffer
2225
2326-- A contiguous chunk of n bytes
2427abstract
2528record Buffer : Nat -> Type where
26− MkBuffer : ( realBuffer : prim__UnsafeBuffer ) -> Buffer n
29+ MkBuffer : ( offset : Nat ) -> ( realBuffer : prim__UnsafeBuffer ) -> Buffer n
2730
2831bitsFromNat : Nat -> Bits64
2932bitsFromNat Z = 0
@@ -38,28 +41,8 @@ bitsFromFin (fS k) = 1 + bitsFromFin k
3841-- approximate ultimate size of the Buffer is known. Users can assume
3942-- the new Buffer is word-aligned.
4043public
41−allocate : ( hint : Nat ) -> Buffer 0
42−allocate = MkBuffer . prim__allocate . bitsFromNat
43−
44−-- Copy a buffer. Since multiple buffers can reference the same
45−-- underlying chunk of memory, it may happen that a reference to
46−-- a relatively small bit of data might be preventing the runtime
47−-- from freeing a much larger chunk. copy allows giving up references
48−-- to the larger chunk without losing the smaller one.
49−%assert_total
50−public
51−copy : Buffer n -> Buffer n
52−copy { n } = MkBuffer . prim__copy ( bitsFromNat n ) . realBuffer
53−
54−-- Read a Buffer from another Buffer starting at offset
55−-- (i.e. create a view of a subset of the Buffer)
56−%assert_total
57−public
58−peekBuffer : Buffer ( m + n ) ->
59− ( offset : Fin ( S n ) ) ->
60− Buffer m
61−peekBuffer ( MkBuffer real ) =
62− MkBuffer . prim__peekBuffer real . bitsFromFin
44+allocate : ( hint : Nat ) -> Buffer Z
45+allocate = MkBuffer Z . prim__allocate . bitsFromNat
6346
6447-- Append count repetitions of a Buffer to another Buffer
6548%assert_total
@@ -67,24 +50,35 @@ public
6750appendBuffer : Buffer n ->
6851 ( count : Nat ) ->
6952 Buffer m ->
70− Buffer ( n + m * count )
71−appendBuffer { n } { m } ( MkBuffer input ) count =
72− MkBuffer . app . realBuffer
53+ Buffer ( n + count * m )
54+appendBuffer { n } { m } ( MkBuffer o1 r1 ) c ( MkBuffer o2 r2 ) =
55+ MkBuffer o1 $ prim__appendBuffer r1 size1 count size2 off r2
7356 where
74− nBits : Bits64
75− nBits = bitsFromNat n
76− mBits : Bits64
77− mBits = bitsFromNat m
78− cBits : Bits64
79− cBits = bitsFromNat count
80− app = prim__appendBuffer input nBits cBits mBits
57+ size1 : Bits64
58+ size1 = bitsFromNat ( n + o1 )
59+ size2 : Bits64
60+ size2 = bitsFromNat m
61+ count : Bits64
62+ count = bitsFromNat c
63+ off : Bits64
64+ off = bitsFromNat o2
65+
66+-- Copy a buffer, potentially allowing the (potentially large) space it
67+-- pointed to to be freed
68+public
69+copy : Buffer n -> Buffer n
70+copy { n } = replace ( plusZeroRightNeutral n ) . appendBuffer ( allocate n ) 1
8171
72+-- Create a view over a buffer
73+public
74+peekBuffer : { n : Nat } -> { offset : Nat } -> Buffer ( n + offset ) -> ( offset : Nat ) -> Buffer n
75+peekBuffer ( MkBuffer o r ) off = MkBuffer ( o + off ) r
8276
8377peekBits : ( prim__UnsafeBuffer -> Bits64 -> a ) ->
8478 Buffer ( m + n ) ->
8579 ( offset : Fin ( S n ) ) ->
8680 a
87−peekBits prim ( MkBuffer real ) = prim real . bitsFromFin
81+peekBits prim ( MkBuffer o r ) = prim r . bitsFromNat . plus o . finToNat
8882
8983appendBits : ( prim__UnsafeBuffer ->
9084 Bits64 ->
@@ -95,8 +89,8 @@ appendBits : ( prim__UnsafeBuffer ->
9589 ( count : Nat) ->
9690 a ->
9791 Buffer ( n + count * size )
98−appendBits { n } prim ( MkBuffer real ) count =
99− MkBuffer . prim real ( bitsFromNat n ) ( bitsFromNat count )
92+appendBits { n } prim ( MkBuffer o r ) count =
93+ MkBuffer o . prim r ( bitsFromNat $ n + o ) ( bitsFromNat count )
10094
10195
10296-- Read a Bits8 from a Buffer starting at offset
rts/idris_gc.c+1−8
@@ -30,9 +30,6 @@ VAL copy(VM* vm, VAL x) {
3030 case BUFFER:
3131 cl = MKBUFFERc(vm, x->info.buf);
3232 break;
33− case BUFOFFSET:
34− cl = MKBUFOFFSETc(vm, x->info.buf_offset);
35− break;
3633 case BIGINT:
3734 cl = MKBIGMc(vm, x->info.ptr);
3835 break;
@@ -69,7 +66,7 @@ void cheney(VM *vm) {
6966 while(scan < vm->heap.next) {
7067 size_t inc = *((size_t*)scan);
7168 VAL heap_item = (VAL)(scan+sizeof(size_t));
72− // If it's a CON, STROFFSET, or BUFOFFSET, copy its arguments
69+ // If it's a CON or STROFFSET, copy its arguments
7370 switch(GETTY(heap_item)) {
7471 case CON:
7572 ar = ARITY(heap_item);
@@ -84,10 +81,6 @@ void cheney(VM *vm) {
8481 heap_item->info.str_offset->str
8582 = copy(vm, heap_item->info.str_offset->str);
8683 break;
87− case BUFOFFSET:
88− heap_item->info.buf_offset->buf
89− = copy(vm, heap_item->info.buf_offset->buf);
90− break;
9184 default: // Nothing to copy
9285 break;
9386 }
rts/idris_heap.c−9
@@ -106,15 +106,6 @@ void heap_check_pointers(Heap * heap) {
106106 }
107107 break;
108108 }
109− case BUFOFFSET:
110− if (!ref_in_heap(heap, heap_item->info.buf_offset->buf)) {
111− fprintf(stderr,
112− "RTS ERROR: heap closure broken. "\
113− "<HEAP %p %p %p> <REF %p>\n",
114− heap->heap, heap->next, heap->end, heap_item->info.buf_offset->buf);
115− exit(EXIT_FAILURE);
116− }
117− break;
118109 case FWD:
119110 // Check for artifacts after cheney gc.
120111 fprintf(stderr, "RTS ERROR: FWD in working heap.\n");
rts/idris_rts.c+54−165
@@ -483,22 +483,6 @@ VAL MKBUFFERc(VM* vm, Buffer* buf) {
483483 return cl;
484484}
485485
486−static VAL make_buf_offset(VM* vm, BufOffset* off, int outerlock) {
487− Closure* cl = allocate(vm, sizeof(Closure) + sizeof *off, outerlock);
488− SETTY(cl, BUFOFFSET);
489− cl->info.buf_offset = (BufOffset*)((void*)cl + sizeof(Closure));
490− memmove(cl->info.buf_offset, off, sizeof *off);
491− return cl;
492−}
493−
494−static VAL MKBUFOFFSET(VM* vm, BufOffset* off) {
495− return make_buf_offset(vm, off, 0);
496−}
497−
498−VAL MKBUFOFFSETc(VM* vm, BufOffset* off) {
499− return make_buf_offset(vm, off, 1);
500−}
501−
502486static VAL internal_allocate(VM *vm, size_t hint) {
503487 size_t size = hint + sizeof(Closure) + sizeof(Buffer);
504488
@@ -523,17 +507,6 @@ VAL idris_allocate(VM* vm, VAL hint) {
523507 return cl;
524508}
525509
526−VAL idris_copy(VM* vm, VAL len, VAL src) {
527− size_t length = len->info.bits64;
528− Closure* cl = internal_allocate(vm, length);
529− memmove(cl->info.buf->store, (GETTY(src) == BUFOFFSET ?
530− src->info.buf_offset->buf->info.buf->store + src->info.buf_offset->offset :
531− src->info.buf->store
532− ), length);
533− cl->info.buf->fill = length;
534− return cl;
535−}
536−
537510static void internal_memset(void *dest, const void *src, size_t size, size_t num) {
538511 while (num--) {
539512 memmove(dest, src, size);
@@ -541,95 +514,49 @@ static void internal_memset(void *dest, const void *src, size_t size, size_t num
541514 }
542515}
543516
544−static void internal_prepare_append(VM* vm, VAL buf, size_t bufLen, size_t appLen, void** storePtr, Closure** valPtr) {
517+static VAL internal_prepare_append(VM* vm, VAL buf, size_t bufLen, size_t appLen) {
545518 size_t totalLen = bufLen + appLen;
546− // Might be able to get rid of some duplication here...
547− if (GETTY(buf) == BUFOFFSET) {
548− if (buf->info.buf_offset->offset + bufLen !=
549− buf->info.buf_offset->buf->info.buf->fill ||
550− buf->info.buf_offset->offset + totalLen >
551− buf->info.buf_offset->buf->info.buf->cap) {
552− // We're not at the fill or are over cap, so need a new buffer
553− *valPtr = internal_allocate(vm, totalLen);
554− memmove((*valPtr)->info.buf->store,
555− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset,
556− bufLen);
557− (*valPtr)->info.buf->fill = totalLen;
558− *storePtr = (*valPtr)->info.buf->store + bufLen;
559− } else {
560− // Hooray, can just bump the fill
561− *valPtr = buf;
562− buf->info.buf_offset->buf->info.buf->fill += appLen;
563− *storePtr = buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + bufLen;
564− }
519+ Closure* cl;
520+ if (bufLen != buf->info.buf->fill ||
521+ totalLen > buf->info.buf->cap) {
522+ // We're not at the fill or are over cap, so need a new buffer
523+ cl = internal_allocate(vm, totalLen);
524+ memmove(cl->info.buf->store,
525+ buf->info.buf->store,
526+ bufLen);
527+ cl->info.buf->fill = totalLen;
565528 } else {
566− Buffer* newBuf;
567− if (bufLen != buf->info.buf->fill ||
568− totalLen > buf->info.buf->cap) {
569− // We're not at the fill or are over cap, so need a new buffer
570− *valPtr = internal_allocate(vm, totalLen);
571− newBuf = (*valPtr)->info.buf;
572− memmove(newBuf->store,
573− buf->info.buf->store,
574− bufLen);
575− newBuf->fill = totalLen;
576− } else {
577− // Hooray, can just bump the fill
578− *valPtr = buf;
579− newBuf = buf->info.buf;
580− newBuf->fill += appLen;
581− }
582− *storePtr = newBuf->store + bufLen;
529+ // Hooray, can just bump the fill
530+ cl = buf;
531+ cl->info.buf->fill += appLen;
583532 }
533+ return cl;
584534}
585535
586−VAL idris_appendBuffer(VM* vm, VAL fst, VAL fstLen, VAL cnt, VAL sndLen, VAL snd) {
536+VAL idris_appendBuffer(VM* vm, VAL fst, VAL fstLen, VAL cnt, VAL sndLen, VAL sndOff, VAL snd) {
587537 size_t firstLength = fstLen->info.bits64;
588538 size_t secondLength = sndLen->info.bits64;
589539 size_t count = cnt->info.bits64;
590− void* store;
591− Closure *cl;
592− internal_prepare_append(vm, fst, firstLength, count * secondLength, &store, &cl);
593− internal_memset(store, GETTY(snd) == BUFOFFSET ?
594− snd->info.buf_offset->buf->info.buf->store + snd->info.buf_offset->offset :
595− snd->info.buf->store
596− , secondLength, count);
540+ size_t offset = sndOff->info.bits64;
541+ Closure* cl = internal_prepare_append(vm, fst, firstLength, count * secondLength);
542+ internal_memset(cl->info.buf->store + firstLength, snd->info.buf->store + offset, secondLength, count);
597543 return cl;
598544}
599545
600−VAL idris_peekBuffer(VM* vm, VAL src, VAL off) {
601− size_t offset = off->info.bits64;
602− if (offset == 0)
603− return src;
604− BufOffset b;
605− if (GETTY(src) == BUFOFFSET) {
606− b.buf = src->info.buf_offset->buf;
607− b.offset = src->info.buf_offset->offset + offset;
608− } else {
609− b.buf = src;
610− b.offset = offset;
611− }
612− return MKBUFOFFSET(vm, &b);
613−}
614−
615546// Special cased because we can use memset
616547VAL idris_appendB8Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
617548 size_t bufLen = len->info.bits64;
618549 size_t count = cnt->info.bits64;
619− void* store;
620− Closure* cl;
621− internal_prepare_append(vm, buf, bufLen, count, &store, &cl);
622− memset(store, val->info.bits8, count);
550+ Closure* cl = internal_prepare_append(vm, buf, bufLen, count);
551+ memset(cl->info.buf->store + bufLen, val->info.bits8, count);
623552 return cl;
624553}
625554
626555static VAL internal_append_bits(VM* vm, VAL buf, VAL bufLen, VAL cnt, const void* val, size_t val_len) {
627556 size_t len = bufLen->info.bits64;
628557 size_t count = cnt->info.bits64;
629− void* store;
630− Closure* cl;
631− internal_prepare_append(vm, buf, len, count * val_len, &store, &cl);
632− internal_memset(store, val, val_len, count);
558+ Closure* cl = internal_prepare_append(vm, buf, len, count * val_len);
559+ internal_memset(cl->info.buf->store + len, val, val_len, count);
633560 return cl;
634561}
635562
@@ -708,104 +635,78 @@ VAL idris_appendB64BE(VM* vm, VAL buf, VAL len, VAL cnt, VAL val) {
708635
709636VAL idris_peekB8Native(VM* vm, VAL buf, VAL off) {
710637 size_t offset = off->info.bits64;
711− uint8_t* val = GETTY(buf) == BUFOFFSET ?
712− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + offset :
713− buf->info.buf->store + offset;
638+ uint8_t *val = buf->info.buf->store + offset;
714639 return MKB8(vm, *val);
715640}
716641
717642VAL idris_peekB16Native(VM* vm, VAL buf, VAL off) {
718643 size_t offset = off->info.bits64;
719− uint16_t* val = (uint16_t *) ((GETTY(buf) == BUFOFFSET) ?
720− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + offset :
721− buf->info.buf->store + offset);
644+ uint16_t *val = (uint16_t *) (buf->info.buf->store + offset);
722645 return MKB16(vm, *val);
723646}
724647
725648VAL idris_peekB16LE(VM* vm, VAL buf, VAL off) {
726649 size_t offset = off->info.bits64;
727− unsigned char* val = (GETTY(buf) == BUFOFFSET) ?
728− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + offset :
729− buf->info.buf->store + offset;
730− return MKB16(vm, ((uint16_t) val[0]) +
731− (((uint16_t) val[1]) << 8));
650+ return MKB16(vm, ((uint16_t) buf->info.buf->store[offset]) +
651+ (((uint16_t) buf->info.buf->store[offset + 1]) << 8));
732652}
733653
734654VAL idris_peekB16BE(VM* vm, VAL buf, VAL off) {
735655 size_t offset = off->info.bits64;
736− unsigned char* val = (GETTY(buf) == BUFOFFSET) ?
737− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + offset :
738− buf->info.buf->store + offset;
739− return MKB16(vm, ((uint16_t) val[1]) +
740− (((uint16_t) val[0]) << 8));
656+ return MKB16(vm, ((uint16_t) buf->info.buf->store[offset + 1]) +
657+ (((uint16_t) buf->info.buf->store[offset]) << 8));
741658}
742659
743660VAL idris_peekB32Native(VM* vm, VAL buf, VAL off) {
744661 size_t offset = off->info.bits64;
745− uint32_t* val = (uint32_t *) ((GETTY(buf) == BUFOFFSET) ?
746− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + offset :
747− buf->info.buf->store + offset);
662+ uint32_t *val = (uint32_t *) (buf->info.buf->store + offset);
748663 return MKB32(vm, *val);
749664}
750665
751666VAL idris_peekB32LE(VM* vm, VAL buf, VAL off) {
752667 size_t offset = off->info.bits64;
753− unsigned char* val = (GETTY(buf) == BUFOFFSET) ?
754− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + offset :
755− buf->info.buf->store + offset;
756− return MKB32(vm, ((uint32_t) val[0]) +
757− (((uint32_t) val[1]) << 8) +
758− (((uint32_t) val[2]) << 16) +
759− (((uint32_t) val[3]) << 24));
668+ return MKB32(vm, ((uint32_t) buf->info.buf->store[offset]) +
669+ (((uint32_t) buf->info.buf->store[offset + 1]) << 8) +
670+ (((uint32_t) buf->info.buf->store[offset + 2]) << 16) +
671+ (((uint32_t) buf->info.buf->store[offset + 3]) << 24));
760672}
761673
762674VAL idris_peekB32BE(VM* vm, VAL buf, VAL off) {
763675 size_t offset = off->info.bits64;
764− unsigned char* val = (GETTY(buf) == BUFOFFSET) ?
765− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + offset :
766− buf->info.buf->store + offset;
767− return MKB32(vm, ((uint32_t) val[3]) +
768− (((uint32_t) val[2]) << 8) +
769− (((uint32_t) val[1]) << 16) +
770− (((uint32_t) val[0]) << 24));
676+ return MKB32(vm, ((uint32_t) buf->info.buf->store[offset + 3]) +
677+ (((uint32_t) buf->info.buf->store[offset + 2]) << 8) +
678+ (((uint32_t) buf->info.buf->store[offset + 1]) << 16) +
679+ (((uint32_t) buf->info.buf->store[offset]) << 24));
771680}
772681
773682VAL idris_peekB64Native(VM* vm, VAL buf, VAL off) {
774683 size_t offset = off->info.bits64;
775− uint64_t* val = (uint64_t *) ((GETTY(buf) == BUFOFFSET) ?
776− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + offset :
777− buf->info.buf->store + offset);
684+ uint64_t *val = (uint64_t *) (buf->info.buf->store + offset);
778685 return MKB64(vm, *val);
779686}
780687
781688VAL idris_peekB64LE(VM* vm, VAL buf, VAL off) {
782689 size_t offset = off->info.bits64;
783− unsigned char* val = (GETTY(buf) == BUFOFFSET) ?
784− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + offset :
785− buf->info.buf->store + offset;
786− return MKB64(vm, ((uint64_t) val[0]) +
787− (((uint64_t) val[1]) << 8) +
788− (((uint64_t) val[2]) << 16) +
789− (((uint64_t) val[3]) << 24) +
790− (((uint64_t) val[4]) << 32) +
791− (((uint64_t) val[5]) << 40) +
792− (((uint64_t) val[6]) << 48) +
793− (((uint64_t) val[7]) << 56));
690+ return MKB64(vm, ((uint64_t) buf->info.buf->store[offset]) +
691+ (((uint64_t) buf->info.buf->store[offset + 1]) << 8) +
692+ (((uint64_t) buf->info.buf->store[offset + 2]) << 16) +
693+ (((uint64_t) buf->info.buf->store[offset + 3]) << 24) +
694+ (((uint64_t) buf->info.buf->store[offset + 4]) << 32) +
695+ (((uint64_t) buf->info.buf->store[offset + 5]) << 40) +
696+ (((uint64_t) buf->info.buf->store[offset + 6]) << 48) +
697+ (((uint64_t) buf->info.buf->store[offset + 7]) << 56));
794698}
795699
796700VAL idris_peekB64BE(VM* vm, VAL buf, VAL off) {
797701 size_t offset = off->info.bits64;
798− unsigned char* val = (GETTY(buf) == BUFOFFSET) ?
799− buf->info.buf_offset->buf->info.buf->store + buf->info.buf_offset->offset + offset :
800− buf->info.buf->store + offset;
801− return MKB64(vm, ((uint64_t) val[7]) +
802− (((uint64_t) val[6]) << 8) +
803− (((uint64_t) val[5]) << 16) +
804− (((uint64_t) val[4]) << 24) +
805− (((uint64_t) val[3]) << 32) +
806− (((uint64_t) val[2]) << 40) +
807− (((uint64_t) val[1]) << 48) +
808− (((uint64_t) val[0]) << 56));
702+ return MKB64(vm, ((uint64_t) buf->info.buf->store[offset + 7]) +
703+ (((uint64_t) buf->info.buf->store[offset + 6]) << 8) +
704+ (((uint64_t) buf->info.buf->store[offset + 5]) << 16) +
705+ (((uint64_t) buf->info.buf->store[offset + 4]) << 24) +
706+ (((uint64_t) buf->info.buf->store[offset + 3]) << 32) +
707+ (((uint64_t) buf->info.buf->store[offset + 2]) << 40) +
708+ (((uint64_t) buf->info.buf->store[offset + 1]) << 48) +
709+ (((uint64_t) buf->info.buf->store[offset]) << 56));
809710}
810711
811712typedef struct {
@@ -888,18 +789,6 @@ VAL copyTo(VM* vm, VAL x) {
888789 case BUFFER:
889790 cl = MKBUFFERc(vm, x->info.buf);
890791 break;
891− case BUFOFFSET:
892− // The underlying Buffer might already exist in the new heap
893− // but we can't do anything reasonable about it
894− if (x->info.buf_offset->offset == 0)
895− cl = MKBUFFERc(vm, x->info.buf_offset->buf->info.buf);
896− else {
897− // Could theoretically make this a bit more efficient
898− // by allocating the BufOffset and Buffer together
899− cl = MKBUFOFFSETc(vm, x->info.buf_offset);
900− cl->info.buf_offset->buf = MKBUFFERc(vm, x->info.buf_offset->buf->info.buf);
901− }
902− break;
903792 case BIGINT:
904793 cl = MKBIGMc(vm, x->info.ptr);
905794 break;
rts/idris_rts.h+2−11
@@ -17,7 +17,7 @@
1717typedef enum {
1818 CON, INT, BIGINT, FLOAT, STRING, STROFFSET,
1919 BITS8, BITS16, BITS32, BITS64, UNIT, PTR, FWD,
20− BUFFER, BUFOFFSET
20+ BUFFER
2121} ClosureType;
2222
2323typedef struct Closure *VAL;
@@ -40,11 +40,6 @@ typedef struct {
4040 unsigned char store[];
4141} Buffer;
4242
43−typedef struct {
44− VAL buf;
45− size_t offset;
46−} BufOffset;
47−
4843
4944typedef struct Closure {
5045// Use top 16 bits of ty for saying which heap value is in
@@ -62,7 +57,6 @@ typedef struct Closure {
6257 uint32_t bits32;
6358 uint64_t bits64;
6459 Buffer* buf;
65− BufOffset* buf_offset;
6660 } info;
6761} Closure;
6862
@@ -180,7 +174,6 @@ VAL MKSTROFFc(VM* vm, StrOffset* off);
180174VAL MKSTRc(VM* vm, char* str);
181175VAL MKPTRc(VM* vm, void* ptr);
182176VAL MKBUFFERc(VM* vm, Buffer* buf);
183−VAL MKBUFOFFSETc(VM* vm, BufOffset* off);
184177
185178char* GETSTROFF(VAL stroff);
186179
@@ -255,9 +248,7 @@ VAL idris_strRev(VM* vm, VAL str);
255248
256249// Buffer primitives
257250VAL idris_allocate(VM* vm, VAL hint);
258−VAL idris_copy(VM* vm, VAL len, VAL src);
259−VAL idris_appendBuffer(VM* vm, VAL fst, VAL fstLen, VAL count, VAL sndLen, VAL snd);
260−VAL idris_peekBuffer(VM* vm, VAL src, VAL off);
251+VAL idris_appendBuffer(VM* vm, VAL fst, VAL fstLen, VAL cnt, VAL sndLen, VAL sndOff, VAL snd);
261252VAL idris_appendB8Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val);
262253VAL idris_appendB16Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val);
263254VAL idris_appendB16LE(VM* vm, VAL buf, VAL len, VAL cnt, VAL val);
src/IRTS/CodegenC.hs+1−3
@@ -458,9 +458,7 @@ doOp v LStrIndex [x, y] = v ++ "idris_strIndex(vm, " ++ creg x ++ "," ++ creg y
458458doOp v LStrRev [x] = v ++ "idris_strRev(vm, " ++ creg x ++ ")"
459459
460460doOp v LAllocate [x] = v ++ "idris_allocate(vm, " ++ creg x ++ ")"
461−doOp v LCopy [x, y] = v ++ "idris_copy(vm, " ++ creg x ++ "," ++ creg y ++ ")"
462−doOp v LAppendBuffer [a, b, c, d, e] = v ++ "idris_appendBuffer(vm, " ++ creg a ++ "," ++ creg b ++ "," ++ creg c ++ "," ++ creg d ++ "," ++ creg e ++ ")"
463−doOp v LPeekBuffer [x, y] = v ++ "idris_peekBuffer(vm, " ++ creg x ++ "," ++ creg y ++ ")"
461+doOp v LAppendBuffer [a, b, c, d, e, f] = v ++ "idris_appendBuffer(vm, " ++ creg a ++ "," ++ creg b ++ "," ++ creg c ++ "," ++ creg d ++ "," ++ creg e ++ "," ++ creg f ++ ")"
464462doOp v (LAppend ity en) [a, b, c, d] = v ++ "idris_append" ++ intTyName ity ++ show en ++ "(vm, " ++ creg a ++ "," ++ creg b ++ "," ++ creg c ++ "," ++ creg d ++ ")"
465463doOp v (LPeek ity en) [x, y] = v ++ "idris_peek" ++ intTyName ity ++ show en ++ "(vm, " ++ creg x ++ "," ++ creg y ++ ")"
466464
src/IRTS/Lang.hs−2
@@ -54,9 +54,7 @@ data PrimFn = LPlus ArithTy | LMinus ArithTy | LTimes ArithTy
5454
5555 -- Buffers
5656 | LAllocate
57− | LCopy
5857 | LAppendBuffer
59− | LPeekBuffer
6058 -- Note that for Bits8 only Native endianness is actually used
6159 -- and the user-exposed interface for Bits8 doesn't mention
6260 -- endianness
src/Idris/Primitives.hs+2−6
@@ -176,12 +176,8 @@ primitives =
176176 -- Buffers
177177 Prim (sUN "prim__allocate") (ty [AType (ATInt (ITFixed IT64))] BufferType) 1 (p_cantreduce)
178178 (1, LAllocate) total,
179− Prim (sUN "prim__copy") (ty [AType (ATInt (ITFixed IT64)), BufferType] BufferType) 2 (p_cantreduce)
180− (2, LCopy) partial,
181− Prim (sUN "prim__peekBuffer") (ty [BufferType, AType (ATInt (ITFixed IT64))] BufferType) 2 (p_cantreduce)
182− (2, LPeekBuffer) partial,
183− Prim (sUN "prim__appendBuffer") (ty [BufferType, AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), BufferType] BufferType) 5 (p_cantreduce)
184− (5, LAppendBuffer) partial
179+ Prim (sUN "prim__appendBuffer") (ty [BufferType, AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), AType (ATInt (ITFixed IT64)), BufferType] BufferType) 6 (p_cantreduce)
180+ (6, LAppendBuffer) partial
185181 ] ++ concatMap intOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64, ITBig, ITNative, ITChar]
186182 ++ concatMap vecOps vecTypes
187183 ++ concatMap fixedOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64] -- ITNative, ITChar, ATFloat ] ++ vecTypes