Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cfe1eb0
base/builtin/*.c/h adapted to unboxing
sydow May 25, 2026
03978f1
findAttrSchemas added to Env.hs thanks to Johan N
sydow May 25, 2026
b1f3608
Added constructor Unboxed to Syntax.Type
sydow May 25, 2026
f90d2d9
added types tI8, tU8 and tU1, and names serializeKW and deserializeKW…
sydow May 25, 2026
e51c89b
added field gtypes to Env.EnvF for use in Boxing pass
sydow May 25, 2026
313bf6f
Major changes in Boxing.hs and Boxing.hs towards total unboxing
sydow May 25, 2026
4ccec33
significant simplification of standard lib module math
sydow May 25, 2026
966263c
changes for unboxing to __builtin__.ext.c and standard library files
sydow May 27, 2026
1b64f80
changes for unbox to list.c and rts.c
sydow May 27, 2026
15e0856
Changes to actonc for unbox. Actonc can compile __builtin__.act and a…
sydow May 27, 2026
8c702be
minor change in an example
sydow May 27, 2026
e412f94
fixed one-off errors in byte_length2
sydow May 28, 2026
dad68a5
fixed range tests for unsigned integer constructors
sydow May 28, 2026
7be5ddc
reinstated function name ord
sydow May 28, 2026
e2e5938
reinstated from_real_imag
sydow May 28, 2026
7a489e0
minor changes to fix bugs in test suite
sydow May 28, 2026
e512a15
reinstated some outcommented cases after bug fixing
sydow May 29, 2026
70916bf
reinstated raiseValueError which had disappeared
sydow May 29, 2026
1c82c05
small bug fixes in unsigned integer types
sydow May 29, 2026
f40f596
fixed bug in printing list element None
sydow May 29, 2026
c9b7451
vfixed bug in.ext.c file in regression test
sydow May 29, 2026
946ed7a
updated golden files on compiler/acton/test/parse
sydow May 29, 2026
d2b05b7
temporarily removed test_complex.act waaiting changes in __builtin__.act
sydow May 29, 2026
8389b6e
Small bugfixes; make test now passes except for golden tests and one …
sydow May 29, 2026
c10da05
adapted builtin C code to latest unboxing
sydow May 29, 2026
5f77f80
added gc info printout to examples/sumto.act
sydow May 29, 2026
222bdf1
further unbox optimization in __next__ for ranges and list indexing
sydow May 29, 2026
c507457
some names defined in Builtin.hs
sydow May 29, 2026
0a0bb7e
adapted some stdlib files to total unboxing
sydow May 29, 2026
af09b93
minor fir in CodeGen.hs when rebasing
sydow May 29, 2026
155636a
updated names in some stdlib files to branch new-unbox
sydow May 29, 2026
58819bf
Fix UnitTest snapshot output capture
May 29, 2026
b569ce2
Update golden files for total unboxing
May 29, 2026
523c11a
Keep abstract protocol returns boxed in codegen
May 30, 2026
d21aa73
Fixed minor bug in CodeGen.hs
sydow May 30, 2026
48960d2
Fix deserialize of unboxed struct fields
May 30, 2026
7cee4db
Regenerate codegen goldens for methodCast
May 30, 2026
7b8ad18
fixed bugs related to printing unsigned types
sydow May 30, 2026
c0c3b73
fixed minor Bug in Boxing.hs
sydow May 30, 2026
33e43a8
added changes in CodeGen.hs and Main.hs of undertain origin
sydow May 31, 2026
7f32310
First version with some generic closures
sydow Jun 1, 2026
1414eb2
Added clusures.c and .h to builtin.c and .h.
sydow Jun 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions base/builtin/bigint.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void zz_malloc_fit(zz_ptr res, len_t m) {
res->alloc = m;
}

B_bigint B_IntegralD_bigintD___lshift__(B_IntegralD_bigint wit, B_bigint a, B_int b);
B_bigint B_IntegralD_bigintD___lshift__(B_IntegralD_bigint wit, B_bigint a, int64_t b);

B_bigint B_bigintG_new(B_atom a, B_int base) {
if (base) {
Expand Down Expand Up @@ -123,7 +123,7 @@ B_bigint B_bigintG_new(B_atom a, B_int base) {
double m = frexp(aval,&e);
if (e>52) {
B_bigint c = toB_bigint((long)(m*4503599627370496.0)); // (1<< 52);
B_int d = toB_int(e-52);
int64_t d = e-52;
return B_IntegralD_bigintD___lshift__(NULL,c,d);
} else {
long al = (long)aval;
Expand Down Expand Up @@ -282,7 +282,7 @@ B_bigint B_IntegralD_bigintD_conjugate(B_IntegralD_bigint wit, B_bigint a) {
return a;
}

B_float B_IntegralD_bigintD___float__ (B_IntegralD_bigint wit, B_bigint n) {
double B_IntegralD_bigintD___float__ (B_IntegralD_bigint wit, B_bigint n) {
return B_floatG_new((B_atom)n);
}

Expand Down Expand Up @@ -327,26 +327,26 @@ B_bigint B_IntegralD_bigintD___round__ (B_IntegralD_bigint wit, B_bigint n, B_in
return wit2->$class->__fromatom__(wit2,(B_atom)res);
}

B_int B_IntegralD_bigintD___int__ (B_IntegralD_bigint wit, B_bigint n) {
int64_t B_IntegralD_bigintD___int__ (B_IntegralD_bigint wit, B_bigint n) {
unsigned long k = n->val.n[0];
long sz = n->val.size;
if (labs(sz) > 1 || (sz==1 && k > 0x7ffffffffffffffful) || sz == -1 && k > 0x8000000000000000ul) {
char errmsg[1024];
snprintf(errmsg, sizeof(errmsg), "bigint.__int__: value %s out of range for type int",get_str(&n->val));
$RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg)));
}
return toB_int(k*sz);
return k*sz;
}

B_int B_IntegralD_bigintD___index__ (B_IntegralD_bigint wit, B_bigint n) {
int64_t B_IntegralD_bigintD___index__ (B_IntegralD_bigint wit, B_bigint n) {
unsigned long k = n->val.n[0];
long sz = n->val.size;
if (labs(sz) > 1 || (sz==1 && k > 0x7ffffffffffffffful) || sz == -1 && k > 0x8000000000000000ul) {
char errmsg[1024];
snprintf(errmsg, sizeof(errmsg), "bigint.__index__: value %s out of range for type int",get_str(&n->val));
$RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg)));
}
return toB_int(k*sz);
return k*sz;
}

B_tuple B_IntegralD_bigintD___divmod__(B_IntegralD_bigint wit, B_bigint a, B_bigint b) {
Expand Down Expand Up @@ -377,10 +377,10 @@ B_bigint B_IntegralD_bigintD___mod__(B_IntegralD_bigint wit, B_bigint a, B_bigin
return t->components[1];
}

B_bigint B_IntegralD_bigintD___lshift__(B_IntegralD_bigint wit, B_bigint a, B_int b) {
B_bigint B_IntegralD_bigintD___lshift__(B_IntegralD_bigint wit, B_bigint a, int64_t b) {
zz_struct aval = a->val;
long ma = aval.size;
long bval = fromB_int(b);
long bval = b;
if (ma==0 || bval==0)
return a;
if (bval<0) {
Expand Down Expand Up @@ -408,10 +408,10 @@ B_bigint B_IntegralD_bigintD___lshift__(B_IntegralD_bigint wit, B_bigint a, B_i
return res;
}

B_bigint B_IntegralD_bigintD___rshift__(B_IntegralD_bigint wit, B_bigint a, B_int b) {
B_bigint B_IntegralD_bigintD___rshift__(B_IntegralD_bigint wit, B_bigint a, int64_t b) {
zz_struct aval = a->val;
long ma = aval.size;
long bval = fromB_int(b);
long bval = b;
if (ma==0 || bval==0)
return a;
if (bval<0) {
Expand Down Expand Up @@ -628,7 +628,7 @@ B_float B_DivD_bigintD___truediv__ (B_DivD_bigint wit, B_bigint a, B_bigint b) {
zz_div(&ared->val,aval,&g->val);
zz_div(&bred->val,bval,&g->val);
zz_divrem(&q->val,&r->val,&ared->val,&bred->val);
return to$float(B_floatG_new((B_atom)q)->val + B_floatG_new((B_atom)r)->val/ B_floatG_new((B_atom)bred)->val);
return toB_float((B_floatG_new((B_atom)q) + B_floatG_new((B_atom)r)/ B_floatG_new((B_atom)bred)));
}

// B_OrdD_bigint ////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions base/builtin/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@
#include "staticWitnesses.c"
#include "utils.c"
#include "hasher.c"
#include "closures.c"
2 changes: 1 addition & 1 deletion base/builtin/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct $Catcher *$Catcher;

///////////////////////////////////////////////////////////

#include "closures.h"
#include "../out/types/__builtin__.h"
#include "class_hierarchy.h"
#include "serialize.h"
Expand Down Expand Up @@ -115,4 +116,3 @@ typedef struct $Catcher *$Catcher;
#include "staticWitnesses.h"
#include "utils.h"
#include "hasher.h"

4 changes: 2 additions & 2 deletions base/builtin/builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ struct $IdentityActorG_class $IdentityActorG_methods = {"$IdentityActor", UNASSI

// Various small functions //////////////////////////////////////////////////////////////

// Code generated by acton
// Code generated by actonc
/*
$WORD B_abs (B_Number W_149, B_Real W_148, $WORD x) {
return W_149->$class->__abs__(W_149, x, W_148);
Expand Down Expand Up @@ -540,7 +540,7 @@ B_tuple B_divmod (B_Integral W_225, $WORD a, $WORD b) {
B_Iterator B_iter (B_Iterable W_278, $WORD x) {
return W_278->$class->__iter__(W_278, x);
}
B_int B_len (B_Collection W_301, $WORD x) {
int64_t B_len (B_Collection W_301, $WORD x) {
return W_301->$class->__len__(W_301, x);
}
Expand Down
4 changes: 2 additions & 2 deletions base/builtin/builtin_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct $IdentityActor {
$WORD B_min_def(B_Ord wit, B_Iterable wit2, $WORD iter, $WORD deflt);
$WORD B_max_def(B_Ord wit, B_Iterable wit2, $WORD iter, $WORD deflt);

// Signatures generated by acton
// Signatures generated by actonc

/*
$WORD B_abs (B_Real, B_Number, $WORD);
Expand All @@ -187,7 +187,7 @@ B_bool B_any (B_Iterable, $WORD);
B_tuple B_divmod (B_Integral, $WORD, $WORD);
B_u64 B_hash (B_Hashable, $WORD);
B_Iterator B_iter (B_Iterable, $WORD);
B_int B_len (B_Collection, $WORD);
int64_t B_len (B_Collection, $WORD);
$WORD $next (B_Iterator);
$WORD B_pow (B_Number, $WORD, $WORD);
B_str B_repr(B_value);
Expand Down
199 changes: 199 additions & 0 deletions base/builtin/closures.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/* Shared runtime classes for common lambda-lifted closure shapes.
*
* CodeGen aliases selected generated closure classes to these structs and emits
* only a small typed trampoline plus a constructor wrapper. Serialization is
* deliberately unsupported here until generic closures can record enough
* generated-code identity to deserialize safely.
*/

B_bool $procD___bool__($proc self);
B_str $procD___str__($proc self);
B_bool $mutD___bool__($mut self);
B_str $mutD___str__($mut self);

#define B_CLOSURE_ARGS_0
#define B_CLOSURE_ARGS_1 , $WORD p0
#define B_CLOSURE_ARGS_2 , $WORD p0, $WORD p1
#define B_CLOSURE_ARGS_3 , $WORD p0, $WORD p1, $WORD p2
#define B_CLOSURE_ARGS_4 , $WORD p0, $WORD p1, $WORD p2, $WORD p3

#define B_CLOSURE_CALL_ARGS_0
#define B_CLOSURE_CALL_ARGS_1 , p0
#define B_CLOSURE_CALL_ARGS_2 , p0, p1
#define B_CLOSURE_CALL_ARGS_3 , p0, p1, p2
#define B_CLOSURE_CALL_ARGS_4 , p0, p1, p2, p3

#define B_CLOSURE_INIT_FIELDS_0
#define B_CLOSURE_INIT_FIELDS_1 self->p0 = p0;
#define B_CLOSURE_INIT_FIELDS_2 self->p0 = p0; self->p1 = p1;
#define B_CLOSURE_INIT_FIELDS_3 self->p0 = p0; self->p1 = p1; self->p2 = p2;
#define B_CLOSURE_INIT_FIELDS_4 self->p0 = p0; self->p1 = p1; self->p2 = p2; self->p3 = p3;

static void B_Closure_serialization_unsupported(char *name) {
fprintf(stderr, "Serialization of generic closure %s is not implemented\n", name);
abort();
}

#define B_DEFINE_CLOSURE_CONT(N) \
struct B_ClosureCont##N##G_class B_ClosureCont##N##G_methods; \
B_NoneType B_ClosureCont##N##D___init__(B_ClosureCont##N self, B_ClosureCont##N##Fn f B_CLOSURE_ARGS_##N) { \
self->f = f; \
B_CLOSURE_INIT_FIELDS_##N \
return B_None; \
} \
$R B_ClosureCont##N##D___call__(B_ClosureCont##N self, $WORD arg) { \
return self->f(self, arg); \
} \
void B_ClosureCont##N##D___serialize__(B_ClosureCont##N self, $Serial$state state) { \
B_Closure_serialization_unsupported("B_ClosureCont" #N); \
} \
B_ClosureCont##N B_ClosureCont##N##D___deserialize__(B_ClosureCont##N self, $Serial$state state) { \
B_Closure_serialization_unsupported("B_ClosureCont" #N); \
return NULL; \
} \
B_ClosureCont##N B_ClosureCont##N##G_new(B_ClosureCont##N##Fn f B_CLOSURE_ARGS_##N) { \
B_ClosureCont##N tmp = acton_malloc(sizeof(struct B_ClosureCont##N)); \
tmp->$class = &B_ClosureCont##N##G_methods; \
B_ClosureCont##N##G_methods.__init__(tmp, f B_CLOSURE_CALL_ARGS_##N); \
return tmp; \
}

#define B_DEFINE_CLOSURE_PROC(N) \
struct B_ClosureProc##N##G_class B_ClosureProc##N##G_methods; \
B_NoneType B_ClosureProc##N##D___init__(B_ClosureProc##N self, B_ClosureProc##N##Fn f B_CLOSURE_ARGS_##N) { \
self->f = f; \
B_CLOSURE_INIT_FIELDS_##N \
return B_None; \
} \
$R B_ClosureProc##N##D___call__(B_ClosureProc##N self, $Cont cont) { \
return self->f(self, cont); \
} \
$R B_ClosureProc##N##D___exec__(B_ClosureProc##N self, $Cont cont) { \
return self->f(self, cont); \
} \
void B_ClosureProc##N##D___serialize__(B_ClosureProc##N self, $Serial$state state) { \
B_Closure_serialization_unsupported("B_ClosureProc" #N); \
} \
B_ClosureProc##N B_ClosureProc##N##D___deserialize__(B_ClosureProc##N self, $Serial$state state) { \
B_Closure_serialization_unsupported("B_ClosureProc" #N); \
return NULL; \
} \
B_ClosureProc##N B_ClosureProc##N##G_new(B_ClosureProc##N##Fn f B_CLOSURE_ARGS_##N) { \
B_ClosureProc##N tmp = acton_malloc(sizeof(struct B_ClosureProc##N)); \
tmp->$class = &B_ClosureProc##N##G_methods; \
B_ClosureProc##N##G_methods.__init__(tmp, f B_CLOSURE_CALL_ARGS_##N); \
return tmp; \
}

B_DEFINE_CLOSURE_CONT(0)
B_DEFINE_CLOSURE_CONT(1)
B_DEFINE_CLOSURE_CONT(2)
B_DEFINE_CLOSURE_CONT(3)
B_DEFINE_CLOSURE_CONT(4)

B_DEFINE_CLOSURE_PROC(0)
B_DEFINE_CLOSURE_PROC(1)
B_DEFINE_CLOSURE_PROC(2)
B_DEFINE_CLOSURE_PROC(3)
B_DEFINE_CLOSURE_PROC(4)

struct B_ClosureMut0G_class B_ClosureMut0G_methods;

B_NoneType B_ClosureMut0D___init__(B_ClosureMut0 self, B_ClosureMut0Fn f) {
self->f = f;
return B_None;
}
$WORD B_ClosureMut0D___eval__(B_ClosureMut0 self) {
return self->f(self);
}
$R B_ClosureMut0D___call__(B_ClosureMut0 self, $Cont cont) {
return $R_CONT(cont, self->f(self));
}
$R B_ClosureMut0D___exec__(B_ClosureMut0 self, $Cont cont) {
return $R_CONT(cont, self->f(self));
}
void B_ClosureMut0D___serialize__(B_ClosureMut0 self, $Serial$state state) {
B_Closure_serialization_unsupported("B_ClosureMut0");
}
B_ClosureMut0 B_ClosureMut0D___deserialize__(B_ClosureMut0 self, $Serial$state state) {
B_Closure_serialization_unsupported("B_ClosureMut0");
return NULL;
}
B_ClosureMut0 B_ClosureMut0G_new(B_ClosureMut0Fn f) {
B_ClosureMut0 tmp = acton_malloc(sizeof(struct B_ClosureMut0));
tmp->$class = &B_ClosureMut0G_methods;
B_ClosureMut0G_methods.__init__(tmp, f);
return tmp;
}

#define B_INIT_CLOSURE_CONT(N) \
B_ClosureCont##N##G_methods.$GCINFO = "B_ClosureCont" #N; \
B_ClosureCont##N##G_methods.$superclass = ($SuperG_class)&$ContG_methods; \
B_ClosureCont##N##G_methods.__init__ = B_ClosureCont##N##D___init__; \
B_ClosureCont##N##G_methods.__serialize__ = B_ClosureCont##N##D___serialize__; \
B_ClosureCont##N##G_methods.__deserialize__ = B_ClosureCont##N##D___deserialize__; \
B_ClosureCont##N##G_methods.__bool__ = (B_bool (*)(B_ClosureCont##N))$ContD___bool__; \
B_ClosureCont##N##G_methods.__str__ = (B_str (*)(B_ClosureCont##N))$ContD___str__; \
B_ClosureCont##N##G_methods.__repr__ = (B_str (*)(B_ClosureCont##N))$ContD___str__; \
B_ClosureCont##N##G_methods.__call__ = B_ClosureCont##N##D___call__; \
$register(&B_ClosureCont##N##G_methods);

#define B_INIT_CLOSURE_PROC(N) \
B_ClosureProc##N##G_methods.$GCINFO = "B_ClosureProc" #N; \
B_ClosureProc##N##G_methods.$superclass = ($SuperG_class)&$procG_methods; \
B_ClosureProc##N##G_methods.__init__ = B_ClosureProc##N##D___init__; \
B_ClosureProc##N##G_methods.__serialize__ = B_ClosureProc##N##D___serialize__; \
B_ClosureProc##N##G_methods.__deserialize__ = B_ClosureProc##N##D___deserialize__; \
B_ClosureProc##N##G_methods.__bool__ = (B_bool (*)(B_ClosureProc##N))$procD___bool__; \
B_ClosureProc##N##G_methods.__str__ = (B_str (*)(B_ClosureProc##N))$procD___str__; \
B_ClosureProc##N##G_methods.__repr__ = (B_str (*)(B_ClosureProc##N))$procD___str__; \
B_ClosureProc##N##G_methods.__call__ = B_ClosureProc##N##D___call__; \
B_ClosureProc##N##G_methods.__exec__ = B_ClosureProc##N##D___exec__; \
$register(&B_ClosureProc##N##G_methods);

void B_ClosureQ___init__() {
B_INIT_CLOSURE_CONT(0)
B_INIT_CLOSURE_CONT(1)
B_INIT_CLOSURE_CONT(2)
B_INIT_CLOSURE_CONT(3)
B_INIT_CLOSURE_CONT(4)

B_INIT_CLOSURE_PROC(0)
B_INIT_CLOSURE_PROC(1)
B_INIT_CLOSURE_PROC(2)
B_INIT_CLOSURE_PROC(3)
B_INIT_CLOSURE_PROC(4)

B_ClosureMut0G_methods.$GCINFO = "B_ClosureMut0";
B_ClosureMut0G_methods.$superclass = ($SuperG_class)&$mutG_methods;
B_ClosureMut0G_methods.__init__ = B_ClosureMut0D___init__;
B_ClosureMut0G_methods.__serialize__ = B_ClosureMut0D___serialize__;
B_ClosureMut0G_methods.__deserialize__ = B_ClosureMut0D___deserialize__;
B_ClosureMut0G_methods.__bool__ = (B_bool (*)(B_ClosureMut0))$mutD___bool__;
B_ClosureMut0G_methods.__str__ = (B_str (*)(B_ClosureMut0))$mutD___str__;
B_ClosureMut0G_methods.__repr__ = (B_str (*)(B_ClosureMut0))$mutD___str__;
B_ClosureMut0G_methods.__call__ = B_ClosureMut0D___call__;
B_ClosureMut0G_methods.__exec__ = B_ClosureMut0D___exec__;
B_ClosureMut0G_methods.__eval__ = B_ClosureMut0D___eval__;
$register(&B_ClosureMut0G_methods);
}

#undef B_INIT_CLOSURE_CONT
#undef B_INIT_CLOSURE_PROC
#undef B_DEFINE_CLOSURE_CONT
#undef B_DEFINE_CLOSURE_PROC
#undef B_CLOSURE_ARGS_0
#undef B_CLOSURE_ARGS_1
#undef B_CLOSURE_ARGS_2
#undef B_CLOSURE_ARGS_3
#undef B_CLOSURE_ARGS_4
#undef B_CLOSURE_CALL_ARGS_0
#undef B_CLOSURE_CALL_ARGS_1
#undef B_CLOSURE_CALL_ARGS_2
#undef B_CLOSURE_CALL_ARGS_3
#undef B_CLOSURE_CALL_ARGS_4
#undef B_CLOSURE_INIT_FIELDS_0
#undef B_CLOSURE_INIT_FIELDS_1
#undef B_CLOSURE_INIT_FIELDS_2
#undef B_CLOSURE_INIT_FIELDS_3
#undef B_CLOSURE_INIT_FIELDS_4
Loading
Loading