Skip to content

Commit

Permalink
Merge pull request #82 from Sparrow-lang/bitcopiable
Browse files Browse the repository at this point in the history
Bitcopiable
  • Loading branch information
lucteo authored Apr 26, 2019
2 parents 5f4134b + 4696c19 commit c97d621
Show file tree
Hide file tree
Showing 23 changed files with 732 additions and 79 deletions.
38 changes: 20 additions & 18 deletions SparrowImplicitLib/sprCore/basicDecls.spr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// Most basic types

[ct]
[native("Type"), noDefault]
[bitcopiable, native("Type"), noDefault]
datatype Type {}

[ct, protected]
Expand All @@ -14,22 +14,22 @@
[noDefault]
datatype Uninitialized {}

[native("Null")] datatype Null {}

[native("i1")] datatype Bool {}
[native("i8")] datatype Byte {}
[convert, native("u8")] datatype UByte {}
[convert, native("i16")] datatype Short {}
[convert, native("u16")] datatype UShort {}
[convert, native("i32")] datatype Int {}
[convert, native("u32")] datatype UInt {}
[convert, native("i64")] datatype Long {}
[convert, native("u64")] datatype ULong {}
[convert, native("u64")] datatype SizeType {}
[convert, native("i64")] datatype DiffType {}
[convert, native("float")] datatype Float {}
[convert, native("double")] datatype Double {}
[native("i8")] datatype Char {}
[bitcopiable, native("Null")] datatype Null {}

[bitcopiable, native("i1")] datatype Bool {}
[bitcopiable, native("i8")] datatype Byte {}
[bitcopiable, convert, native("u8")] datatype UByte {}
[bitcopiable, convert, native("i16")] datatype Short {}
[bitcopiable, convert, native("u16")] datatype UShort {}
[bitcopiable, convert, native("i32")] datatype Int {}
[bitcopiable, convert, native("u32")] datatype UInt {}
[bitcopiable, convert, native("i64")] datatype Long {}
[bitcopiable, convert, native("u64")] datatype ULong {}
[bitcopiable, convert, native("u64")] datatype SizeType {}
[bitcopiable, convert, native("i64")] datatype DiffType {}
[bitcopiable, convert, native("float")] datatype Float {}
[bitcopiable, convert, native("double")] datatype Double {}
[bitcopiable, native("i8")] datatype Char {}

[protected]
fun ctor(this: Uninitialized) {}
Expand Down Expand Up @@ -625,7 +625,7 @@ using oper_assoc_:= = -1
///

/// String class that DOES NOT have ownership of the characters; it simply refers to another string
[native("StringRef")]
[bitcopiable, native("StringRef")]
datatype StringRef
using RetType = @Char

Expand Down Expand Up @@ -740,6 +740,7 @@ fun construct()


/// Type used to represent an untyped pointer
[bitcopiable]
datatype UntypedPtr = @Byte

[autoCt]
Expand Down Expand Up @@ -767,6 +768,7 @@ package TypeOp
[native("$typeNumRef")] fun numRef(t: Type): Int
[native("$typeChangeMode")] fun changeMode(t: Type, mode: Int): Type
[native("$typeChangeRefCount")] fun changeRefCount(t: Type, numRef: Int): Type
[native("$typeIsBitcopiable")] fun isBitcopiable(t: Type): Bool

[ctGeneric]
fun isRef(t: Type) = 0<numRef(t)
Expand Down
2 changes: 1 addition & 1 deletion SparrowImplicitLib/std/ptr.spr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module std.ptr

import newDelete(delete)

[initCtor]
[initCtor, bitcopiable]
datatype Ptr(type: Type)
using ValueType = type

Expand Down
18 changes: 9 additions & 9 deletions SparrowImplicitLib/std/tuple.spr
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ concept TupleType(x) if (

using oper_precedence_~ = oper_precedence_*

[initCtor] datatype Tuple(t1, t2: Type)
[initCtor, autoBitcopiable] datatype Tuple(t1, t2: Type)
using arity = 2
v1: t1
v2: t2

[initCtor] datatype Tuple(t1, t2, t3: Type)
[initCtor, autoBitcopiable] datatype Tuple(t1, t2, t3: Type)
using arity = 3
v1: t1
v2: t2
v3: t3

[initCtor] datatype Tuple(t1, t2, t3, t4: Type)
[initCtor, autoBitcopiable] datatype Tuple(t1, t2, t3, t4: Type)
using arity = 4
v1: t1
v2: t2
v3: t3
v4: t4

[initCtor] datatype Tuple(t1, t2, t3, t4, t5: Type)
[initCtor, autoBitcopiable] datatype Tuple(t1, t2, t3, t4, t5: Type)
using arity = 5
v1: t1
v2: t2
v3: t3
v4: t4
v5: t5

[initCtor] datatype Tuple(t1, t2, t3, t4, t5, t6: Type)
[initCtor, autoBitcopiable] datatype Tuple(t1, t2, t3, t4, t5, t6: Type)
using arity = 6
v1: t1
v2: t2
Expand All @@ -43,7 +43,7 @@ using oper_precedence_~ = oper_precedence_*
v5: t5
v6: t6

[initCtor] datatype Tuple(t1, t2, t3, t4, t5, t6, t7: Type)
[initCtor, autoBitcopiable] datatype Tuple(t1, t2, t3, t4, t5, t6, t7: Type)
using arity = 7
v1: t1
v2: t2
Expand All @@ -53,7 +53,7 @@ using oper_precedence_~ = oper_precedence_*
v6: t6
v7: t7

[initCtor] datatype Tuple(t1, t2, t3, t4, t5, t6, t7, t8: Type)
[initCtor, autoBitcopiable] datatype Tuple(t1, t2, t3, t4, t5, t6, t7, t8: Type)
using arity = 8
v1: t1
v2: t2
Expand All @@ -64,7 +64,7 @@ using oper_precedence_~ = oper_precedence_*
v7: t7
v8: t8

[initCtor] datatype Tuple(t1, t2, t3, t4, t5, t6, t7, t8, t9: Type)
[initCtor, autoBitcopiable] datatype Tuple(t1, t2, t3, t4, t5, t6, t7, t8, t9: Type)
using arity = 9
v1: t1
v2: t2
Expand All @@ -76,7 +76,7 @@ using oper_precedence_~ = oper_precedence_*
v8: t8
v9: t9

[initCtor] datatype Tuple(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10: Type)
[initCtor, autoBitcopiable] datatype Tuple(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10: Type)
using arity = 10
v1: t1
v2: t2
Expand Down
11 changes: 7 additions & 4 deletions SparrowImplicitLib/std/vector.spr
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ datatype Vector(valueType: Type)
var dst = _begin
var src = other._begin

while dst != _end
dst.value().ctor(src.value())
dst = dst.advance()
src = src.advance()
[ct] if TypeOp.isBitcopiable(ValueType)
memcpy(dst.bytePtr, src.bytePtr, size*sizeOf(ValueType))
else
while dst != _end
dst.value().ctor(src.value())
dst = dst.advance()
src = src.advance()

fun ctor(this: @Vector, size: SizeType)
// Allocate the buffer
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.pngmath'
'sphinx.ext.imgmath',
'sphinx.ext.autosectionlabel'
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down
Loading

0 comments on commit c97d621

Please sign in to comment.