diff options
author | Ori Bernstein <ori@eigenstate.org> | 2015-09-30 21:45:49 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-09-30 21:51:04 -0700 |
commit | 627ef0fa8e965ac37ba79db1eae7e7d6b78c53b7 (patch) | |
tree | 4dbab77cb83962b3414752dc6e3aae5e3da69720 | |
parent | bfb7664b7f66e0d9e406672fa92bdee35bced70b (diff) | |
download | mc-627ef0fa8e965ac37ba79db1eae7e7d6b78c53b7.tar.gz |
Add support for duplicating functions.
-rw-r--r-- | lib/std/bitset.myr | 21 | ||||
-rw-r--r-- | lib/std/bld.sub | 1 | ||||
-rw-r--r-- | lib/std/fndup.myr | 34 | ||||
-rw-r--r-- | mbld/deps.myr | 2 | ||||
-rw-r--r-- | parse/parse.h | 2 | ||||
-rw-r--r-- | parse/trait.def | 1 | ||||
-rw-r--r-- | parse/type.c | 3 |
7 files changed, 53 insertions, 11 deletions
diff --git a/lib/std/bitset.myr b/lib/std/bitset.myr index edf123e..3ce76ea 100644 --- a/lib/std/bitset.myr +++ b/lib/std/bitset.myr @@ -18,8 +18,8 @@ pkg std = const bsmax : (a : bitset# -> size) - generic bsput : (bs : bitset#, v : @a::(integral,numeric) -> void) - generic bsdel : (bs : bitset#, v : @a::(integral,numeric) -> void) + generic bsput : (bs : bitset#, v : @a::(integral,numeric) -> bool) + generic bsdel : (bs : bitset#, v : @a::(integral,numeric) -> bool) generic bshas : (bs : bitset#, v : @a::(integral,numeric) -> bool) const bsdiff : (a : bitset#, b : bitset# -> void) @@ -55,25 +55,28 @@ const bsmax = {bs } generic bsput = {bs, v - var idx - var off + var idx, off, has idx = (v castto(size)) / (8*sizeof(size)) off = (v castto(size)) % (8*sizeof(size)) ensurelen(bs, idx) + + has = (bs.bits[idx] & (1 << off)) != 0 bs.bits[idx] |= (1 << off) + -> has } generic bsdel = {bs, v - var idx - var off + var idx, off, had + had = false idx = (v castto(size)) / (8*sizeof(size)) off = (v castto(size)) % (8*sizeof(size)) - if idx >= bs.bits.len - -> + if idx < bs.bits.len + had = (bs.bits[idx] & (1 << off)) != 0 + bs.bits[idx] &= ~(1 << off) ;; - bs.bits[idx] &= ~(1 << off) + -> had } generic bshas = {bs, v diff --git a/lib/std/bld.sub b/lib/std/bld.sub index 1a2111c..9a97f5f 100644 --- a/lib/std/bld.sub +++ b/lib/std/bld.sub @@ -20,6 +20,7 @@ lib std {inc=.} = fltfmt.myr fmt.myr fmtfuncs.myr + fndup.myr getcwd.myr getint.myr hashfuncs.myr diff --git a/lib/std/fndup.myr b/lib/std/fndup.myr new file mode 100644 index 0000000..250d5d7 --- /dev/null +++ b/lib/std/fndup.myr @@ -0,0 +1,34 @@ +use "alloc.use" +use "die.use" +use "sldup.use" +use "types.use" + +pkg std = + generic fndup : (fn : @fn::function -> @fn::function) + generic fnfree : (fn : @fn::function -> void) +;; + +generic fndup = {fn + var repr : intptr[2] + + repr = (&fn castto(intptr[2]#))# + repr[0] = sldup(envslice(repr[0])) castto(intptr) + -> (&repr castto(@fn::function#))# +} + +generic fnfree = {fn + var repr : intptr[2] + + repr = (&fn castto(intptr[2]#))# + std.slfree(envslice(repr[0])) +} + +const envslice = {ep : intptr + var env : byte# + var szp : intptr# + + env = ep castto(byte#) + szp = env castto(intptr#) + -> env[:szp#] +} + diff --git a/mbld/deps.myr b/mbld/deps.myr index 17dfb79..f4a8efd 100644 --- a/mbld/deps.myr +++ b/mbld/deps.myr @@ -14,7 +14,7 @@ pkg bld = var usepat : regex.regex# ;; -const Abiversion = 7 +const Abiversion = 8 var usepat : regex.regex# diff --git a/parse/parse.h b/parse/parse.h index f57c730..2e04e15 100644 --- a/parse/parse.h +++ b/parse/parse.h @@ -4,7 +4,7 @@ # define FATAL #endif -#define Abiversion 7 +#define Abiversion 8 typedef uint8_t byte; typedef unsigned int uint; diff --git a/parse/trait.def b/parse/trait.def index bdc720e..627ca9c 100644 --- a/parse/trait.def +++ b/parse/trait.def @@ -4,3 +4,4 @@ Tc(Tcint, "integral") /* behaves like an int, defaults to int as fallb Tc(Tcfloat, "floating") /* behaves like a float, defaults to float as fallback */ Tc(Tcidx, "indexable") /* indexable */ Tc(Tcslice, "sliceable") /* sliceable */ +Tc(Tcfunc, "function") /* behaves like a function */ diff --git a/parse/type.c b/parse/type.c index e329f1c..fc0cebd 100644 --- a/parse/type.c +++ b/parse/type.c @@ -904,6 +904,9 @@ void tyinit(Stab *st) traits[Tyarray][0] = traittab[Tcidx]; traits[Tyarray][1] = traittab[Tcslice]; + /* @a::function */ + traits[Tyfunc][0] = traittab[Tcfunc]; + /* Definining and registering the types has to go after we define the * constraints, otherwise they will have no constraints set on them. */ #define Ty(t, n, stk) \ |