diff --git a/base/builtin/bigint.c b/base/builtin/bigint.c index b4ea17a24..378e334dd 100644 --- a/base/builtin/bigint.c +++ b/base/builtin/bigint.c @@ -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) { @@ -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; @@ -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); } @@ -327,7 +327,7 @@ 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) { @@ -335,10 +335,10 @@ B_int B_IntegralD_bigintD___int__ (B_IntegralD_bigint wit, B_bigint n) { 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) { @@ -346,7 +346,7 @@ B_int B_IntegralD_bigintD___index__ (B_IntegralD_bigint wit, B_bigint n) { 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) { @@ -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) { @@ -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) { @@ -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 //////////////////////////////////////////////////////////////////////////////////////// diff --git a/base/builtin/builtin.c b/base/builtin/builtin.c index 249acd04f..001bc65dc 100644 --- a/base/builtin/builtin.c +++ b/base/builtin/builtin.c @@ -57,3 +57,4 @@ #include "staticWitnesses.c" #include "utils.c" #include "hasher.c" +#include "closures.c" diff --git a/base/builtin/builtin.h b/base/builtin/builtin.h index c0202c71f..6be0c5d46 100644 --- a/base/builtin/builtin.h +++ b/base/builtin/builtin.h @@ -80,6 +80,7 @@ typedef struct $Catcher *$Catcher; /////////////////////////////////////////////////////////// +#include "closures.h" #include "../out/types/__builtin__.h" #include "class_hierarchy.h" #include "serialize.h" @@ -115,4 +116,3 @@ typedef struct $Catcher *$Catcher; #include "staticWitnesses.h" #include "utils.h" #include "hasher.h" - diff --git a/base/builtin/builtin_functions.c b/base/builtin/builtin_functions.c index d4e49488e..633341d8a 100644 --- a/base/builtin/builtin_functions.c +++ b/base/builtin/builtin_functions.c @@ -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); @@ -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); } diff --git a/base/builtin/builtin_functions.h b/base/builtin/builtin_functions.h index 8ac647e8d..d02f503b9 100644 --- a/base/builtin/builtin_functions.h +++ b/base/builtin/builtin_functions.h @@ -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); @@ -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); diff --git a/base/builtin/closures.c b/base/builtin/closures.c new file mode 100644 index 000000000..c76ebe630 --- /dev/null +++ b/base/builtin/closures.c @@ -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 diff --git a/base/builtin/closures.h b/base/builtin/closures.h new file mode 100644 index 000000000..f7c733ded --- /dev/null +++ b/base/builtin/closures.h @@ -0,0 +1,119 @@ +#pragma once + +struct B_bool; +typedef struct B_bool *B_bool; + +struct B_str; +typedef struct B_str *B_str; + +#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_FIELDS_0 +#define B_CLOSURE_FIELDS_1 $WORD p0; +#define B_CLOSURE_FIELDS_2 $WORD p0; $WORD p1; +#define B_CLOSURE_FIELDS_3 $WORD p0; $WORD p1; $WORD p2; +#define B_CLOSURE_FIELDS_4 $WORD p0; $WORD p1; $WORD p2; $WORD p3; + +#define B_DECLARE_CLOSURE_CONT(N) \ +struct B_ClosureCont##N; \ +typedef struct B_ClosureCont##N *B_ClosureCont##N; \ +typedef $R (*B_ClosureCont##N##Fn)(B_ClosureCont##N, $WORD); \ +struct B_ClosureCont##N##G_class { \ + char *$GCINFO; \ + int $class_id; \ + $SuperG_class $superclass; \ + B_NoneType (*__init__)(B_ClosureCont##N, B_ClosureCont##N##Fn B_CLOSURE_ARGS_##N); \ + void (*__serialize__)(B_ClosureCont##N, $Serial$state); \ + B_ClosureCont##N (*__deserialize__)(B_ClosureCont##N, $Serial$state); \ + B_bool (*__bool__)(B_ClosureCont##N); \ + B_str (*__str__)(B_ClosureCont##N); \ + B_str (*__repr__)(B_ClosureCont##N); \ + $R (*__call__)(B_ClosureCont##N, $WORD); \ +}; \ +struct B_ClosureCont##N { \ + struct B_ClosureCont##N##G_class *$class; \ + B_ClosureCont##N##Fn f; \ + B_CLOSURE_FIELDS_##N \ +}; \ +extern struct B_ClosureCont##N##G_class B_ClosureCont##N##G_methods; \ +B_ClosureCont##N B_ClosureCont##N##G_new(B_ClosureCont##N##Fn f B_CLOSURE_ARGS_##N) + +#define B_DECLARE_CLOSURE_PROC(N) \ +struct B_ClosureProc##N; \ +typedef struct B_ClosureProc##N *B_ClosureProc##N; \ +typedef $R (*B_ClosureProc##N##Fn)(B_ClosureProc##N, $Cont); \ +struct B_ClosureProc##N##G_class { \ + char *$GCINFO; \ + int $class_id; \ + $SuperG_class $superclass; \ + B_NoneType (*__init__)(B_ClosureProc##N, B_ClosureProc##N##Fn B_CLOSURE_ARGS_##N); \ + void (*__serialize__)(B_ClosureProc##N, $Serial$state); \ + B_ClosureProc##N (*__deserialize__)(B_ClosureProc##N, $Serial$state); \ + B_bool (*__bool__)(B_ClosureProc##N); \ + B_str (*__str__)(B_ClosureProc##N); \ + B_str (*__repr__)(B_ClosureProc##N); \ + $R (*__call__)(B_ClosureProc##N, $Cont); \ + $R (*__exec__)(B_ClosureProc##N, $Cont); \ +}; \ +struct B_ClosureProc##N { \ + struct B_ClosureProc##N##G_class *$class; \ + B_ClosureProc##N##Fn f; \ + B_CLOSURE_FIELDS_##N \ +}; \ +extern struct B_ClosureProc##N##G_class B_ClosureProc##N##G_methods; \ +B_ClosureProc##N B_ClosureProc##N##G_new(B_ClosureProc##N##Fn f B_CLOSURE_ARGS_##N) + +B_DECLARE_CLOSURE_CONT(0); +B_DECLARE_CLOSURE_CONT(1); +B_DECLARE_CLOSURE_CONT(2); +B_DECLARE_CLOSURE_CONT(3); +B_DECLARE_CLOSURE_CONT(4); + +B_DECLARE_CLOSURE_PROC(0); +B_DECLARE_CLOSURE_PROC(1); +B_DECLARE_CLOSURE_PROC(2); +B_DECLARE_CLOSURE_PROC(3); +B_DECLARE_CLOSURE_PROC(4); + +struct B_ClosureMut0; +typedef struct B_ClosureMut0 *B_ClosureMut0; +typedef $WORD (*B_ClosureMut0Fn)(B_ClosureMut0); +struct B_ClosureMut0G_class { + char *$GCINFO; + int $class_id; + $SuperG_class $superclass; + B_NoneType (*__init__)(B_ClosureMut0, B_ClosureMut0Fn); + void (*__serialize__)(B_ClosureMut0, $Serial$state); + B_ClosureMut0 (*__deserialize__)(B_ClosureMut0, $Serial$state); + B_bool (*__bool__)(B_ClosureMut0); + B_str (*__str__)(B_ClosureMut0); + B_str (*__repr__)(B_ClosureMut0); + $R (*__call__)(B_ClosureMut0, $Cont); + $R (*__exec__)(B_ClosureMut0, $Cont); + $WORD (*__eval__)(B_ClosureMut0); +}; +struct B_ClosureMut0 { + struct B_ClosureMut0G_class *$class; + B_ClosureMut0Fn f; +}; +extern struct B_ClosureMut0G_class B_ClosureMut0G_methods; +B_ClosureMut0 B_ClosureMut0G_new(B_ClosureMut0Fn f); + +void B_ClosureQ___init__(); + +#undef B_DECLARE_CLOSURE_CONT +#undef B_DECLARE_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_FIELDS_0 +#undef B_CLOSURE_FIELDS_1 +#undef B_CLOSURE_FIELDS_2 +#undef B_CLOSURE_FIELDS_3 +#undef B_CLOSURE_FIELDS_4 diff --git a/base/builtin/complex.c b/base/builtin/complex.c index 7e029a4c6..d031d748d 100644 --- a/base/builtin/complex.c +++ b/base/builtin/complex.c @@ -24,8 +24,8 @@ B_complex B_complexG_new(B_Number wit, $WORD c) { } B_complex B_complexD_from_real_imag (B_Real wit1, B_Real wit2, $WORD real, $WORD imag) { - double re = wit1->$class->__float__(wit1, real)->val; - double im = wit2->$class->__float__(wit2, imag)->val; + double re = wit1->$class->__float__(wit1, real); + double im = wit2->$class->__float__(wit2, imag); return toB_complex(re + im * _Complex_I); } diff --git a/base/builtin/dict.c b/base/builtin/dict.c index 437487f77..5628c3872 100644 --- a/base/builtin/dict.c +++ b/base/builtin/dict.c @@ -49,7 +49,7 @@ static void build_indices(B_Hashable hashwit, $table oldtable, $table newtable, if (oldtable->tb_size > INIT_SIZE) hash = ep->hash; else { - hash = fromB_u64(B_hash(hashwit, ep->key)); + hash = B_hash(hashwit, ep->key); ep->hash = hash; } unsigned long i = (unsigned long)hash & mask; @@ -201,7 +201,7 @@ static void insertdict(B_dict dict, B_Hashable hashwit, uint64_t hash, $WORD key if (!dict->table || dict->table->tb_usable <= 0) dictresize(hashwit,dict); if (dict->table->tb_size == 2*INIT_SIZE) - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); int ix = $lookdict(dict,hashwit,hash,key,&old_value); if (ix == DKIX_EMPTY) { table = dict->table; @@ -351,7 +351,7 @@ B_bool B_dictrel(bool directfalse,B_OrdD_dict w, B_dict a, B_dict b) { x = it->$class->__next__(it); long h = 0; if (a->table->tb_size > INIT_SIZE) - h = fromB_u64(B_hash(wH, x)); + h = B_hash(wH, x); int ixa = $lookdict(a, wH, h, x, &resa); int ixb = $lookdict(b, wH, h, x ,&resb); if (ixb<0 || wB->$class->__ne__(wB,resa,resb)->val) { @@ -469,8 +469,8 @@ B_dict B_MappingD_dictD___fromiter__ (B_MappingD_dict wit, B_Iterable wit2, $WOR */ } -B_int B_MappingD_dictD___len__ (B_MappingD_dict wit, B_dict dict) { - return toB_int(dict->numelements); +int64_t B_MappingD_dictD___len__ (B_MappingD_dict wit, B_dict dict) { + return dict->numelements; } B_bool B_MappingD_dictD___contains__ (B_MappingD_dict wit, B_dict dict, $WORD key) { @@ -480,7 +480,7 @@ B_bool B_MappingD_dictD___contains__ (B_MappingD_dict wit, B_dict dict, $WORD ke $WORD res; long h = 0; if (dict->table->tb_size > INIT_SIZE) - h = fromB_u64(B_hash(hashwit, key)); + h = B_hash(hashwit, key); return toB_bool($lookdict(dict,hashwit,h,key,&res) >= 0); } @@ -494,7 +494,7 @@ B_bool B_MappingD_dictD___containsnot__ (B_MappingD_dict wit, B_dict dict, $WORD uint64_t hash = 0; B_Hashable hashwit = wit->W_HashableD_AD_MappingD_dict; if (dict->table->tb_size > INIT_SIZE) - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); $WORD res; int ix = $lookdict(dict,hashwit,hash,key,&res); if (ix < 0) @@ -509,7 +509,7 @@ B_bool B_MappingD_dictD___containsnot__ (B_MappingD_dict wit, B_dict dict, $WORD uint64_t hash = 0; B_Hashable hashwit = wit->W_HashableD_AD_MappingD_dict; if (dict->table->tb_size > INIT_SIZE) - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); $WORD res; int ix = $lookdict(dict,hashwit,hash,key,&res); if (ix < 0) @@ -525,7 +525,7 @@ B_bool B_MappingD_dictD___containsnot__ (B_MappingD_dict wit, B_dict dict, $WORD uint64_t hash = 0; B_Hashable hashwit = wit->W_HashableD_AD_MappingD_dict; if (table->tb_size > INIT_SIZE) { - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); } $WORD res; int ix = $lookdict(dict,hashwit,hash,key,&res); @@ -551,7 +551,7 @@ B_bool B_MappingD_dictD___containsnot__ (B_MappingD_dict wit, B_dict dict, $WORD uint64_t hash = 0; B_Hashable hashwit = wit->W_HashableD_AD_MappingD_dict; if (table->tb_size > INIT_SIZE) { - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); } $WORD res; int ix = $lookdict(dict,hashwit,hash,key,&res); @@ -726,7 +726,7 @@ B_tuple B_MappingD_dictD_popitem (B_MappingD_dict wit, B_dict dict) { $entry_t entry = &TB_ENTRIES(table)[ix]; if (entry->value != DELETED) { if (table->tb_size > INIT_SIZE) { - uint64_t hash = fromB_u64(B_hash(hashwit, entry->key)); + uint64_t hash = B_hash(hashwit, entry->key); int i = $lookdict_index(table,hash,ix); table->tb_indices[i] = DKIX_DUMMY; } @@ -742,7 +742,7 @@ B_tuple B_MappingD_dictD_popitem (B_MappingD_dict wit, B_dict dict) { $WORD B_MappingD_dictD_setdefault (B_MappingD_dict wit, B_dict dict, $WORD key, $WORD deflt) { if (!deflt) deflt = B_None; B_Hashable hashwit = wit->W_HashableD_AD_MappingD_dict; - uint64_t hash = fromB_u64(B_hash(hashwit, key)); + uint64_t hash = B_hash(hashwit, key); $WORD value; int ix = $lookdict(dict,hashwit,hash,key,&value); if (ix >= 0) @@ -760,7 +760,7 @@ B_tuple B_MappingD_dictD_popitem (B_MappingD_dict wit, B_dict dict) { B_Hashable hashwit = ((B_MappingD_dict)wit->W_Mapping)->W_HashableD_AD_MappingD_dict; uint64_t hash = 0; if (dict->table->tb_size > INIT_SIZE) { - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); } $WORD res; int ix = $lookdict(dict,hashwit,hash,key,&res); @@ -774,7 +774,7 @@ B_NoneType B_IndexedD_MappingD_dictD___setitem__ (B_IndexedD_MappingD_dict wit, B_Hashable hashwit = ((B_MappingD_dict)wit->W_Mapping)->W_HashableD_AD_MappingD_dict; uint64_t hash = 0; if (dict->table && dict->table->tb_size > INIT_SIZE) { - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); } insertdict(dict, hashwit, hash, key, value); return B_None; @@ -788,7 +788,7 @@ B_NoneType B_IndexedD_MappingD_dictD___delitem__ (B_IndexedD_MappingD_dict wit, uint64_t hash = 0; B_Hashable hashwit = ((B_MappingD_dict)wit->W_Mapping)->W_HashableD_AD_MappingD_dict; if (dict->table->tb_size > INIT_SIZE) { - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); } $WORD res; int ix = $lookdict(dict,hashwit,hash,key,&res); @@ -813,7 +813,7 @@ B_NoneType B_IndexedD_MappingD_dictD___delitem__ (B_IndexedD_MappingD_dict wit, void B_dictD_setitem(B_dict dict, B_Hashable hashwit, $WORD key, $WORD value) { uint64_t hash = 0; if (dict->table && dict->table->tb_size > INIT_SIZE) { - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); } insertdict(dict, hashwit, hash, key, value); } @@ -823,7 +823,7 @@ void B_dictD_setitem(B_dict dict, B_Hashable hashwit, $WORD key, $WORD value) { return deflt; uint64_t hash = 0; if (dict->table->tb_size > INIT_SIZE) { - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); } $WORD res; int ix = $lookdict(dict,hashwit,hash,key,&res); @@ -839,7 +839,7 @@ void B_dictD_setitem(B_dict dict, B_Hashable hashwit, $WORD key, $WORD value) { $table table = dict->table; uint64_t hash = 0; if (table->tb_size > INIT_SIZE) { - hash = fromB_u64(B_hash(hashwit, key)); + hash = B_hash(hashwit, key); } $WORD res; int ix = $lookdict(dict,hashwit,hash,key,&res); diff --git a/base/builtin/env.c b/base/builtin/env.c index f0fa24485..913ec18a5 100644 --- a/base/builtin/env.c +++ b/base/builtin/env.c @@ -95,8 +95,8 @@ void read_stdin(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { return $R_CONT(c$cont, B_None); } -$R B_EnvD_exitG_local (B_Env self, $Cont c$cont, B_int n) { - return_val = fromB_int(n); +$R B_EnvD_exitG_local (B_Env self, $Cont c$cont, int64_t n) { + return_val = n; rts_shutdown(); return $R_CONT(c$cont, B_None); } diff --git a/base/builtin/exceptions.h b/base/builtin/exceptions.h index 4f568ad22..910b581b2 100644 --- a/base/builtin/exceptions.h +++ b/base/builtin/exceptions.h @@ -177,4 +177,4 @@ extern struct $RETG_class $RETG_methods; $RET $RETG_new(B_value); $WORD $raiseValueError(B_str str); - + diff --git a/base/builtin/float.c b/base/builtin/float.c index e2dce808a..8a39b16cd 100644 --- a/base/builtin/float.c +++ b/base/builtin/float.c @@ -16,17 +16,20 @@ // General methods /////////////////////////////////////////////////////////////////////// -B_float B_floatG_new(B_atom a) { - if ($ISINSTANCE0(a,B_int)) return to$float((double)((B_int)a)->val); - if ($ISINSTANCE0(a,B_i32)) return to$float((double)((B_i32)a)->val); - if ($ISINSTANCE0(a,B_i16)) return to$float((double)((B_i16)a)->val); - if ($ISINSTANCE0(a,B_u64)) return to$float((double)((B_u64)a)->val); - if ($ISINSTANCE0(a,B_u32)) return to$float((double)((B_u32)a)->val); - if ($ISINSTANCE0(a,B_u16)) return to$float((double)((B_u16)a)->val); +double B_floatG_new(B_atom a) { + if ($ISINSTANCE0(a,B_int)) return (double)((B_int)a)->val; + if ($ISINSTANCE0(a,B_i32)) return (double)((B_i32)a)->val; + if ($ISINSTANCE0(a,B_i16)) return (double)((B_i8)a)->val; + if ($ISINSTANCE0(a,B_i8)) return (double)((B_i16)a)->val; + if ($ISINSTANCE0(a,B_u64)) return (double)((B_u64)a)->val; + if ($ISINSTANCE0(a,B_u32)) return (double)((B_u32)a)->val; + if ($ISINSTANCE0(a,B_u16)) return (double)((B_u16)a)->val; + if ($ISINSTANCE0(a,B_u8)) return (double)((B_u8)a)->val; + if ($ISINSTANCE0(a,B_u1)) return (double)((B_u1)a)->val; if ($ISINSTANCE0(a,B_bigint)) { zz_struct aval = ((B_bigint)a)->val; - if (aval.size == 0) - return to$float(0.0); + if (aval.size == 0) + return 0.0; if (labs(aval.size) > 16) $RAISE((B_BaseException)$NEW(B_ValueError,to$str("float(): int value too big for type float"))); double pow = 1.0; @@ -35,16 +38,16 @@ B_float B_floatG_new(B_atom a) { res += aval.n[i] * pow; pow *= 18446744073709551616.0; // literal is 2^64 } - return to$float(aval.size<0 ? -res : res); + return aval.size<0 ? -res : res; } - if ($ISINSTANCE0(a,B_float)) return (B_float)a; - if ($ISINSTANCE0(a,B_bool)) return to$float((double)((B_bool)a)->val); + if ($ISINSTANCE0(a,B_float)) return ((B_float)a)->val; + if ($ISINSTANCE0(a,B_bool)) return (double)((B_bool)a)->val; if ($ISINSTANCE0(a,B_str)) { double x; int c; sscanf((char *)((B_str)a)->str,"%lf%n",&x,&c); if (c==((B_str)a)->nbytes) - return to$float(x); + return x; else $RAISE((B_BaseException)$NEW(B_ValueError,to$str("float_fromatom(): invalid str literal for type float"))); } @@ -54,7 +57,7 @@ B_float B_floatG_new(B_atom a) { } B_NoneType B_floatD___init__(B_float self, B_atom a){ - self->val = B_floatG_new(a)->val; + self->val = B_floatG_new(a); return B_None; } @@ -103,15 +106,15 @@ double fromB_float(B_float x) { // B_RealFloatD_float ///////////////////////////////////////////////////////////////////////// B_float B_RealFloatD_floatD___add__(B_RealFloatD_float wit, B_float a, B_float b) { - return to$float(fromB_float(a) + fromB_float(b)); + return toB_float(a->val + b->val); } B_float B_RealFloatD_floatD___zero__(B_RealFloatD_float wit) { - return to$float(0.0); + return toB_float(0.0); } B_float B_RealFloatD_floatD___fromatom__(B_RealFloatD_float wit, B_atom a) { - return B_floatG_new(a); + return toB_float(B_floatG_new(a)); } B_complex B_RealFloatD_floatD___complex__(B_RealFloatD_float wit, B_float a) { @@ -119,15 +122,20 @@ B_complex B_RealFloatD_floatD___complex__(B_RealFloatD_float wit, B_float a) { } B_float B_RealFloatD_floatD___mul__(B_RealFloatD_float wit, B_float a, B_float b) { - return to$float(fromB_float(a) * fromB_float(b)); + return toB_float(a->val * b->val); } B_float B_RealFloatD_floatD___pow__(B_RealFloatD_float wit, B_float a, B_float b) { - return to$float(exp(fromB_float(b) * log(fromB_float(a)))); + if ( b->val < 0) { + char errmsg[1024]; + snprintf(errmsg, sizeof(errmsg), "int.__pow__: negative exponent %f ",b->val); + $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); + } + return toB_float(exp(b->val * log(a->val))); } B_float B_RealFloatD_floatD___neg__(B_RealFloatD_float wit, B_float a) { - return to$float(-fromB_float(a)); + return toB_float(-a->val); } B_float B_RealFloatD_floatD___pos__(B_RealFloatD_float wit, B_float a) { @@ -139,49 +147,49 @@ B_float B_RealFloatD_floatD___pos__(B_RealFloatD_float wit, B_float a) { } $WORD B_RealFloatD_floatD_imag(B_RealFloatD_float wit, B_float a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)to$float(0.0)); + return B_RealFloatD_floatD___zero__(wit); } $WORD B_RealFloatD_floatD___abs__(B_RealFloatD_float wit, B_float a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)to$float(fabs(fromB_float(a)))); + return wit2->$class->__fromatom__(wit2,(B_atom)to$float(fabs(a->val))); } B_float B_RealFloatD_floatD_conjugate(B_RealFloatD_float wit, B_float a) { return a; } -B_float B_RealFloatD_floatD___float__ (B_RealFloatD_float wit, B_float x) { - return x; +double B_RealFloatD_floatD___float__ (B_RealFloatD_float wit, B_float x) { + return x->val; } $WORD B_RealFloatD_floatD___trunc__ (B_RealFloatD_float wit, B_float x, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_int((long)trunc(fromB_float(x)))); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_int((long)trunc(x->val))); } $WORD B_RealFloatD_floatD___floor__ (B_RealFloatD_float wit, B_float x, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_int((long)floor(fromB_float(x)))); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_int((long)floor(x->val))); } $WORD B_RealFloatD_floatD___ceil__ (B_RealFloatD_float wit, B_float x, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_int((long)ceil(fromB_float(x)))); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_int((long)ceil(x->val))); } B_float B_RealFloatD_floatD___round__ (B_RealFloatD_float wit, B_float x, B_int p) { - double pval = p==NULL ? 0.0 : (double)fromB_int(p); + double pval = p==NULL ? 0.0 : (double)p->val; double p10 = pow(10.0,pval); - return to$float(round(x->val * p10)/p10); + return toB_float(round(x->val * p10)/p10); } // B_MinusD_RealFloatD_float //////////////////////////////////////////////////////////////////////////////////////// B_float B_MinusD_RealFloatD_floatD___sub__(B_MinusD_RealFloatD_float wit, B_float a, B_float b) { - return to$float(fromB_float(a) - fromB_float(b)); + return toB_float(a->val - b->val); } // B_DivD_float //////////////////////////////////////////////////////////////////////////////////////// B_float B_DivD_floatD___truediv__(B_DivD_float wit, B_float a, B_float b) { - return to$float(fromB_float(a) / fromB_float(b)); + return toB_float(a->val / b->val); } // B_OrdD_float //////////////////////////////////////////////////////////////////////////////////////// @@ -222,6 +230,6 @@ B_bool B_HashableD_floatD___neq__(B_HashableD_float wit, B_float a, B_float b) { } B_NoneType B_HashableD_floatD_hash(B_HashableD_float wit, B_float a, B_hasher h) { - zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a->val), 8)); + zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&a, 8)); return B_None; } diff --git a/base/builtin/float.h b/base/builtin/float.h index 562d7c0d0..3b1a8c3c1 100644 --- a/base/builtin/float.h +++ b/base/builtin/float.h @@ -12,7 +12,7 @@ B_float to$float(double x); // Dare not remove this; possibly used in compiler.. B_float toB_float(double x); double fromB_float(B_float x); -B_float B_floatG_new(B_atom a); +double B_floatG_new(B_atom a); #define float_DIV(x,y) (x/y) #define float_pow(x,y) (pow(x,y)) diff --git a/base/builtin/hasher.c b/base/builtin/hasher.c index b9c54b304..14b0f8ef5 100644 --- a/base/builtin/hasher.c +++ b/base/builtin/hasher.c @@ -1,4 +1,4 @@ -B_NoneType B_hasherD___init__ (B_hasher self, B_u64 seed) { +B_NoneType B_hasherD___init__ (B_hasher self, B_u64 seed) { // seed is optional self->_hasher = zig_hash_wyhash_init(seed ? fromB_u64(seed) : 0); return B_None; } @@ -8,10 +8,9 @@ B_NoneType B_hasherD_update (B_hasher self, B_bytes data) { return B_None; } -B_u64 B_hasherD_finalize (B_hasher self) { +uint64_t B_hasherD_finalize (B_hasher self) { uint64_t h = zig_hash_wyhash_final(self->_hasher); - B_u64 result = toB_u64(h); - return result; + return h; } B_bool B_hasherD___bool__(B_hasher h) { diff --git a/base/builtin/i16.c b/base/builtin/i16.c index 619f69371..de7a2d0b3 100644 --- a/base/builtin/i16.c +++ b/base/builtin/i16.c @@ -15,7 +15,7 @@ // Auxiliary ////////////////////////////////////////////////////////////////////////////// // only called with e>=0. -short i16_pow(short a, short e) { +int16_t i16_pow(int16_t a, int16_t e) { if (e == 0) return 1; if (e == 1) return a; if (e%2 == 0) return i16_pow(a*a,e/2); @@ -24,20 +24,21 @@ short i16_pow(short a, short e) { // General methods /////////////////////////////////////////////////////////////////////// -B_i16 B_i16G_new(B_atom a, B_int base) { +int16_t B_i16G_new(B_atom a, B_int base) { B_bigint b = B_bigintG_new(a, base); unsigned long n = b->val.n[0]; long sz = b->val.size; - if (labs(sz) > 1 || (sz==1 && n > 0x7ffful) || sz == -1 && n > 0x8000ul) { + if (labs(sz) > 1 || (sz==1 && n > 0x7ffffffful) || sz == -1 && n > 0x80000000ul) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), "i16(): value %s out of range for type i16",get_str(&b->val)); $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_i16((short)(n*sz)); + return (int16_t)(n*sz); } + B_NoneType B_i16D___init__(B_i16 self, B_atom a, B_int base){ - self->val = B_i16G_new(a,base)->val; + self->val = B_i16G_new(a,base); return B_None; } @@ -46,7 +47,7 @@ void B_i16D___serialize__(B_i16 n, $Serial$state state) { } B_i16 B_i16D___deserialize__(B_i16 n, $Serial$state state) { - return toB_i16((short)(uintptr_t)$val_deserialize(state)); + return toB_i16((int16_t)(uintptr_t)$val_deserialize(state)); } B_bool B_i16D___bool__(B_i16 n) { @@ -54,21 +55,21 @@ B_bool B_i16D___bool__(B_i16 n) { } B_str B_i16D___str__(B_i16 n) { - return $FORMAT("%hd", n->val); + return $FORMAT("%d", n->val); } B_str B_i16D___repr__(B_i16 n) { - return $FORMAT("%hd", n->val); + return $FORMAT("%d", n->val); } -B_i16 toB_i16(short i) { +B_i16 toB_i16(int16_t i) { B_i16 res = acton_malloc(sizeof(struct B_i16)); res->$class = &B_i16G_methods; res->val = i; return res; } -short fromB_i16(B_i16 w) { +int16_t fromB_i16(B_i16 w) { return w->val; } @@ -78,7 +79,7 @@ short fromB_i16(B_i16 w) { B_i16 B_IntegralD_i16D___add__(B_IntegralD_i16 wit, B_i16 a, B_i16 b) { - return toB_i16(a->val + b->val); + return toB_i16(a->val+b->val); } B_i16 B_IntegralD_i16D___zero__(B_IntegralD_i16 wit) { @@ -86,11 +87,11 @@ B_i16 B_IntegralD_i16D___zero__(B_IntegralD_i16 wit) { } B_complex B_IntegralD_i16D___complex__(B_IntegralD_i16 wit, B_i16 a) { - return toB_complex((double)a->val); + return toB_complex((double)(a->val)); } B_i16 B_IntegralD_i16D___fromatom__(B_IntegralD_i16 wit, B_atom a) { - return B_i16G_new(a,NULL); + return toB_i16(B_i16G_new(a,NULL)); } B_i16 B_IntegralD_i16D___mul__(B_IntegralD_i16 wit, B_i16 a, B_i16 b) { @@ -98,11 +99,14 @@ B_i16 B_IntegralD_i16D___mul__(B_IntegralD_i16 wit, B_i16 a, B_i16 b) { } B_i16 B_IntegralD_i16D___pow__(B_IntegralD_i16 wit, B_i16 a, B_i16 b) { - if ( b->val < 0) { - // raise VALUEERROR; - return NULL; + int16_t aval = a->val; + int16_t bval = b->val; + if ( bval < 0) { + char errmsg[1024]; + snprintf(errmsg, sizeof(errmsg), "int.__pow__: negative exponent %d ",bval); + $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_i16(i16_pow(a->val,b->val)); + return toB_i16(i16_pow(aval,bval)); } B_i16 B_IntegralD_i16D___neg__(B_IntegralD_i16 wit, B_i16 a) { @@ -114,23 +118,23 @@ B_i16 B_IntegralD_i16D___pos__(B_IntegralD_i16 wit, B_i16 a) { } $WORD B_IntegralD_i16D_real(B_IntegralD_i16 wit, B_i16 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)(a)); } $WORD B_IntegralD_i16D_imag(B_IntegralD_i16 wit, B_i16 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_i16(0L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_i16(0)); } $WORD B_IntegralD_i16D___abs__(B_IntegralD_i16 wit, B_i16 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_i16(labs(a->val))); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_i16(abs(a->val))); } B_i16 B_IntegralD_i16D_conjugate(B_IntegralD_i16 wit, B_i16 a) { return a; } -B_float B_IntegralD_i16D___float__ (B_IntegralD_i16 wit, B_i16 n) { - return to$float((double)n->val); +double B_IntegralD_i16D___float__ (B_IntegralD_i16 wit, B_i16 n) { + return (double)n->val; } $WORD B_IntegralD_i16D___trunc__ (B_IntegralD_i16 wit, B_i16 n, B_Integral wit2) { @@ -146,17 +150,17 @@ B_float B_IntegralD_i16D___float__ (B_IntegralD_i16 wit, B_i16 n) { } B_i16 B_IntegralD_i16D___round__ (B_IntegralD_i16 wit, B_i16 n, B_int p) { - short nval = n->val; + int16_t nval = n->val; if (nval<0) return toB_i16(-B_IntegralD_i16D___round__(wit,toB_i16(-nval),p)->val); - short pval = p==NULL ? 0 : fromB_int(p); + int pval = p==NULL ? 0 : fromB_int(p); if (pval>=0) return n; - short p10 = i16_pow(10,-pval); - short res = nval/p10; + int p10 = i16_pow(10,-pval); + int res = nval/p10; if (nval%p10 * 2 > p10) res++; - return toB_i16 (res * p10); + return toB_i16(res * p10); } $WORD B_IntegralD_i16D_numerator (B_IntegralD_i16 wit, B_i16 n, B_Integral wit2) { @@ -164,22 +168,20 @@ B_i16 B_IntegralD_i16D___round__ (B_IntegralD_i16 wit, B_i16 n, B_int p) { } $WORD B_IntegralD_i16D_denominator (B_IntegralD_i16 wit, B_i16 n, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_i16(1L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_i16(1)); } -B_int B_IntegralD_i16D___int__ (B_IntegralD_i16 wit, B_i16 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_i16D___int__ (B_IntegralD_i16 wit, B_i16 n) { + return (int64_t)n->val; } -B_int B_IntegralD_i16D___index__(B_IntegralD_i16 wit, B_i16 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_i16D___index__(B_IntegralD_i16 wit, B_i16 n) { + return (int64_t)n->val; } B_tuple B_IntegralD_i16D___divmod__(B_IntegralD_i16 wit, B_i16 a, B_i16 b) { - if (b->val == 0) - $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - short n = a->val; - short d = b->val; + int16_t n = a->val; + int16_t d = b->val; return $NEWTUPLE(2, toB_i16(n/d), toB_i16(n%d)); } @@ -193,16 +195,16 @@ B_i16 B_IntegralD_i16D___mod__(B_IntegralD_i16 wit, B_i16 a, B_i16 b) { return toB_i16(a->val % b->val); } -B_i16 B_IntegralD_i16D___lshift__(B_IntegralD_i16 wit, B_i16 a, B_int b) { - return toB_i16(a->val << fromB_int(b)); +B_i16 B_IntegralD_i16D___lshift__(B_IntegralD_i16 wit, B_i16 a, int64_t b) { + return toB_i16(a->val << b); } -B_i16 B_IntegralD_i16D___rshift__(B_IntegralD_i16 wit, B_i16 a, B_int b) { - return toB_i16(a->val >> fromB_int(b)); +B_i16 B_IntegralD_i16D___rshift__(B_IntegralD_i16 wit, B_i16 a, int64_t b) { + return toB_i16(a->val >> b); } B_i16 B_IntegralD_i16D___invert__(B_IntegralD_i16 wit, B_i16 a) { - return toB_i16(~a->val); + return toB_i16( ~a->val); } @@ -233,7 +235,7 @@ B_i16 B_MinusD_IntegralD_i16D___sub__(B_MinusD_IntegralD_i16 wit, B_i16 a, B_i1 B_float B_DivD_i16D___truediv__ (B_DivD_i16 wit, B_i16 a, B_i16 b) { if (b->val == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - return to$float((double)a->val/(double)b->val); + return toB_float((double)a->val/(double)b->val); } // B_OrdD_i16 //////////////////////////////////////////////////////////////////////////////////////// @@ -273,6 +275,6 @@ B_bool B_HashableD_i16D___ne__(B_HashableD_i16 wit, B_i16 a, B_i16 b) { } B_NoneType B_HashableD_i16D_hash(B_HashableD_i16 wit, B_i16 a, B_hasher h) { - zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a->val), 2)); + zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a), 4)); return B_None; } diff --git a/base/builtin/i16.h b/base/builtin/i16.h index cee1807b5..e0bf74d90 100644 --- a/base/builtin/i16.h +++ b/base/builtin/i16.h @@ -7,10 +7,10 @@ struct B_i16 { B_i16 toB_i16(short n); short fromB_i16(B_i16 n); -B_i16 B_i16G_new(B_atom a, B_int base); +int16_t B_i16G_new(B_atom a, B_int base); #define i16_DIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("i16 truediv: division by zero"))); (double)a/(double)b;} ) #define i16_FLOORDIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("i16 floordiv: division by zero"))); a/b;} ) #define i16_MOD(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("i16 mod: division by zero"))); a%b;} ) -short i16_pow(short a, short b); +int16_t i16_pow(int16_t a, int16_t b); diff --git a/base/builtin/i32.c b/base/builtin/i32.c index 147b6b646..80fb68f5e 100644 --- a/base/builtin/i32.c +++ b/base/builtin/i32.c @@ -24,7 +24,7 @@ int i32_pow(int a, int e) { // General methods /////////////////////////////////////////////////////////////////////// -B_i32 B_i32G_new(B_atom a, B_int base) { +int32_t B_i32G_new(B_atom a, B_int base) { B_bigint b = B_bigintG_new(a, base); unsigned long n = b->val.n[0]; long sz = b->val.size; @@ -33,12 +33,12 @@ B_i32 B_i32G_new(B_atom a, B_int base) { snprintf(errmsg, sizeof(errmsg), "i32(): value %s out of range for type i32",get_str(&b->val)); $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_i32((int)(n*sz)); + return (int32_t)(n*sz); } B_NoneType B_i32D___init__(B_i32 self, B_atom a, B_int base){ - self->val = B_i32G_new(a,base)->val; + self->val = B_i32G_new(a,base); return B_None; } @@ -47,7 +47,7 @@ void B_i32D___serialize__(B_i32 n, $Serial$state state) { } B_i32 B_i32D___deserialize__(B_i32 n, $Serial$state state) { - return toB_i32((int)(uintptr_t)$val_deserialize(state)); + return toB_i32((int32_t)(uintptr_t)$val_deserialize(state)); } B_bool B_i32D___bool__(B_i32 n) { @@ -62,14 +62,14 @@ B_str B_i32D___repr__(B_i32 n) { return $FORMAT("%d", n->val); } -B_i32 toB_i32(int i) { +B_i32 toB_i32(int32_t i) { B_i32 res = acton_malloc(sizeof(struct B_i32)); res->$class = &B_i32G_methods; res->val = i; return res; } -int fromB_i32(B_i32 w) { +int32_t fromB_i32(B_i32 w) { return w->val; } @@ -79,7 +79,7 @@ int fromB_i32(B_i32 w) { B_i32 B_IntegralD_i32D___add__(B_IntegralD_i32 wit, B_i32 a, B_i32 b) { - return toB_i32(a->val + b->val); + return toB_i32(a->val+b->val); } B_i32 B_IntegralD_i32D___zero__(B_IntegralD_i32 wit) { @@ -87,11 +87,11 @@ B_i32 B_IntegralD_i32D___zero__(B_IntegralD_i32 wit) { } B_complex B_IntegralD_i32D___complex__(B_IntegralD_i32 wit, B_i32 a) { - return toB_complex((double)a->val); + return toB_complex((double)(a->val)); } B_i32 B_IntegralD_i32D___fromatom__(B_IntegralD_i32 wit, B_atom a) { - return B_i32G_new(a,NULL); + return toB_i32(B_i32G_new(a,NULL)); } B_i32 B_IntegralD_i32D___mul__(B_IntegralD_i32 wit, B_i32 a, B_i32 b) { @@ -99,11 +99,14 @@ B_i32 B_IntegralD_i32D___mul__(B_IntegralD_i32 wit, B_i32 a, B_i32 b) { } B_i32 B_IntegralD_i32D___pow__(B_IntegralD_i32 wit, B_i32 a, B_i32 b) { - if ( b->val < 0) { - // raise VALUEERROR; - return NULL; + int32_t aval = a->val; + int32_t bval = b->val; + if ( bval < 0) { + char errmsg[1024]; + snprintf(errmsg, sizeof(errmsg), "int.__pow__: negative exponent %d ",bval); + $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_i32(i32_pow(a->val,b->val)); + return toB_i32(i32_pow(aval,bval)); } B_i32 B_IntegralD_i32D___neg__(B_IntegralD_i32 wit, B_i32 a) { @@ -115,23 +118,23 @@ B_i32 B_IntegralD_i32D___pos__(B_IntegralD_i32 wit, B_i32 a) { } $WORD B_IntegralD_i32D_real(B_IntegralD_i32 wit, B_i32 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)(a)); } $WORD B_IntegralD_i32D_imag(B_IntegralD_i32 wit, B_i32 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_i32(0L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_i32(0)); } $WORD B_IntegralD_i32D___abs__(B_IntegralD_i32 wit, B_i32 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_i32(labs(a->val))); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_i32(abs(a->val))); } B_i32 B_IntegralD_i32D_conjugate(B_IntegralD_i32 wit, B_i32 a) { return a; } -B_float B_IntegralD_i32D___float__ (B_IntegralD_i32 wit, B_i32 n) { - return to$float((double)n->val); +double B_IntegralD_i32D___float__ (B_IntegralD_i32 wit, B_i32 n) { + return (double)n->val; } $WORD B_IntegralD_i32D___trunc__ (B_IntegralD_i32 wit, B_i32 n, B_Integral wit2) { @@ -147,7 +150,7 @@ B_float B_IntegralD_i32D___float__ (B_IntegralD_i32 wit, B_i32 n) { } B_i32 B_IntegralD_i32D___round__ (B_IntegralD_i32 wit, B_i32 n, B_int p) { - int nval = n->val; + int32_t nval = n->val; if (nval<0) return toB_i32(-B_IntegralD_i32D___round__(wit,toB_i32(-nval),p)->val); int pval = p==NULL ? 0 : fromB_int(p); @@ -157,7 +160,7 @@ B_i32 B_IntegralD_i32D___round__ (B_IntegralD_i32 wit, B_i32 n, B_int p) { int res = nval/p10; if (nval%p10 * 2 > p10) res++; - return toB_i32 (res * p10); + return toB_i32(res * p10); } $WORD B_IntegralD_i32D_numerator (B_IntegralD_i32 wit, B_i32 n, B_Integral wit2) { @@ -165,20 +168,20 @@ B_i32 B_IntegralD_i32D___round__ (B_IntegralD_i32 wit, B_i32 n, B_int p) { } $WORD B_IntegralD_i32D_denominator (B_IntegralD_i32 wit, B_i32 n, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_i32(1L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_i32(1)); } -B_int B_IntegralD_i32D___int__ (B_IntegralD_i32 wit, B_i32 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_i32D___int__ (B_IntegralD_i32 wit, B_i32 n) { + return (int64_t)n->val; } -B_int B_IntegralD_i32D___index__(B_IntegralD_i32 wit, B_i32 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_i32D___index__(B_IntegralD_i32 wit, B_i32 n) { + return (int64_t)n->val; } B_tuple B_IntegralD_i32D___divmod__(B_IntegralD_i32 wit, B_i32 a, B_i32 b) { - int n = a->val; - int d = b->val; + int32_t n = a->val; + int32_t d = b->val; return $NEWTUPLE(2, toB_i32(n/d), toB_i32(n%d)); } @@ -192,16 +195,16 @@ B_i32 B_IntegralD_i32D___mod__(B_IntegralD_i32 wit, B_i32 a, B_i32 b) { return toB_i32(a->val % b->val); } -B_i32 B_IntegralD_i32D___lshift__(B_IntegralD_i32 wit, B_i32 a, B_int b) { - return toB_i32(a->val << fromB_int(b)); +B_i32 B_IntegralD_i32D___lshift__(B_IntegralD_i32 wit, B_i32 a, int64_t b) { + return toB_i32(a->val << b); } -B_i32 B_IntegralD_i32D___rshift__(B_IntegralD_i32 wit, B_i32 a, B_int b) { - return toB_i32(a->val >> fromB_int(b)); +B_i32 B_IntegralD_i32D___rshift__(B_IntegralD_i32 wit, B_i32 a, int64_t b) { + return toB_i32(a->val >> b); } B_i32 B_IntegralD_i32D___invert__(B_IntegralD_i32 wit, B_i32 a) { - return toB_i32(~a->val); + return toB_i32( ~a->val); } @@ -232,7 +235,7 @@ B_i32 B_MinusD_IntegralD_i32D___sub__(B_MinusD_IntegralD_i32 wit, B_i32 a, B_i3 B_float B_DivD_i32D___truediv__ (B_DivD_i32 wit, B_i32 a, B_i32 b) { if (b->val == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - return to$float((double)a->val/(double)b->val); + return toB_float((double)a->val/(double)b->val); } // B_OrdD_i32 //////////////////////////////////////////////////////////////////////////////////////// @@ -272,6 +275,6 @@ B_bool B_HashableD_i32D___ne__(B_HashableD_i32 wit, B_i32 a, B_i32 b) { } B_NoneType B_HashableD_i32D_hash(B_HashableD_i32 wit, B_i32 a, B_hasher h) { - zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a->val), 4)); + zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a), 4)); return B_None; } diff --git a/base/builtin/i32.h b/base/builtin/i32.h index d7eae1f15..fdb87874e 100644 --- a/base/builtin/i32.h +++ b/base/builtin/i32.h @@ -4,13 +4,13 @@ struct B_i32 { }; -B_i32 toB_i32(int n); -int fromB_i32(B_i32 n); +B_i32 toB_i32(int32_t n); +int32_t fromB_i32(B_i32 n); -B_i32 B_i32G_new(B_atom a, B_int base); +int32_t B_i32G_new(B_atom a, B_int base); #define i32_DIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("i32 truediv: division by zero"))); (double)a/(double)b;} ) #define i32_FLOORDIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("i32 floordiv: division by zero"))); a/b;} ) #define i32_MOD(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("i32 mod: division by zero"))); a%b;} ) -int i32_pow(int a, int b); +int32_t i32_pow(int32_t a, int32_t b); diff --git a/base/builtin/i8.c b/base/builtin/i8.c index 908fa964f..691f7d453 100644 --- a/base/builtin/i8.c +++ b/base/builtin/i8.c @@ -24,20 +24,21 @@ int8_t i8_pow(int8_t a, int8_t e) { // General methods /////////////////////////////////////////////////////////////////////// -B_i8 B_i8G_new(B_atom a, B_int base) { +int8_t B_i8G_new(B_atom a, B_int base) { B_bigint b = B_bigintG_new(a, base); unsigned long n = b->val.n[0]; long sz = b->val.size; - if (labs(sz) > 1 || (sz==1 && n > SCHAR_MAX) || sz == -1 && n > labs(SCHAR_MIN)) { + if (labs(sz) > 1 || (sz==1 && n > 0x7ffffffful) || sz == -1 && n > 0x80000000ul) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), "i8(): value %s out of range for type i8",get_str(&b->val)); $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_i8(n); + return (int8_t)(n*sz); } + B_NoneType B_i8D___init__(B_i8 self, B_atom a, B_int base){ - self->val = B_i8G_new(a,base)->val; + self->val = B_i8G_new(a,base); return B_None; } @@ -46,7 +47,7 @@ void B_i8D___serialize__(B_i8 n, $Serial$state state) { } B_i8 B_i8D___deserialize__(B_i8 n, $Serial$state state) { - return toB_i8((int8_t)$val_deserialize(state)); + return toB_i8((int8_t)(uintptr_t)$val_deserialize(state)); } B_bool B_i8D___bool__(B_i8 n) { @@ -78,7 +79,7 @@ int8_t fromB_i8(B_i8 w) { B_i8 B_IntegralD_i8D___add__(B_IntegralD_i8 wit, B_i8 a, B_i8 b) { - return toB_i8(a->val + b->val); + return toB_i8(a->val+b->val); } B_i8 B_IntegralD_i8D___zero__(B_IntegralD_i8 wit) { @@ -86,11 +87,11 @@ B_i8 B_IntegralD_i8D___zero__(B_IntegralD_i8 wit) { } B_complex B_IntegralD_i8D___complex__(B_IntegralD_i8 wit, B_i8 a) { - return toB_complex((double)a->val); + return toB_complex((double)(a->val)); } B_i8 B_IntegralD_i8D___fromatom__(B_IntegralD_i8 wit, B_atom a) { - return B_i8G_new(a,NULL); + return toB_i8(B_i8G_new(a,NULL)); } B_i8 B_IntegralD_i8D___mul__(B_IntegralD_i8 wit, B_i8 a, B_i8 b) { @@ -98,11 +99,14 @@ B_i8 B_IntegralD_i8D___mul__(B_IntegralD_i8 wit, B_i8 a, B_i8 b) { } B_i8 B_IntegralD_i8D___pow__(B_IntegralD_i8 wit, B_i8 a, B_i8 b) { - if ( b->val < 0) { - // raise VALUEERROR; - return NULL; + int8_t aval = a->val; + int8_t bval = b->val; + if ( bval < 0) { + char errmsg[1024]; + snprintf(errmsg, sizeof(errmsg), "int.__pow__: negative exponent %d ",bval); + $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_i8(i8_pow(a->val,b->val)); + return toB_i8(i8_pow(aval,bval)); } B_i8 B_IntegralD_i8D___neg__(B_IntegralD_i8 wit, B_i8 a) { @@ -114,23 +118,23 @@ B_i8 B_IntegralD_i8D___pos__(B_IntegralD_i8 wit, B_i8 a) { } $WORD B_IntegralD_i8D_real(B_IntegralD_i8 wit, B_i8 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)(a)); } $WORD B_IntegralD_i8D_imag(B_IntegralD_i8 wit, B_i8 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_i8(0L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_i8(0)); } $WORD B_IntegralD_i8D___abs__(B_IntegralD_i8 wit, B_i8 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_i8(labs(a->val))); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_i8(abs(a->val))); } B_i8 B_IntegralD_i8D_conjugate(B_IntegralD_i8 wit, B_i8 a) { return a; } -B_float B_IntegralD_i8D___float__ (B_IntegralD_i8 wit, B_i8 n) { - return to$float((double)n->val); +double B_IntegralD_i8D___float__ (B_IntegralD_i8 wit, B_i8 n) { + return (double)n->val; } $WORD B_IntegralD_i8D___trunc__ (B_IntegralD_i8 wit, B_i8 n, B_Integral wit2) { @@ -149,14 +153,14 @@ B_i8 B_IntegralD_i8D___round__ (B_IntegralD_i8 wit, B_i8 n, B_int p) { int8_t nval = n->val; if (nval<0) return toB_i8(-B_IntegralD_i8D___round__(wit,toB_i8(-nval),p)->val); - long pval = p==NULL ? 0 : fromB_int(p); + int pval = p==NULL ? 0 : fromB_int(p); if (pval>=0) return n; - int8_t p10 = i8_pow(10,-pval); - int8_t res = nval/p10; + int p10 = i8_pow(10,-pval); + int res = nval/p10; if (nval%p10 * 2 > p10) res++; - return toB_i8 (res * p10); + return toB_i8(res * p10); } $WORD B_IntegralD_i8D_numerator (B_IntegralD_i8 wit, B_i8 n, B_Integral wit2) { @@ -164,20 +168,18 @@ B_i8 B_IntegralD_i8D___round__ (B_IntegralD_i8 wit, B_i8 n, B_int p) { } $WORD B_IntegralD_i8D_denominator (B_IntegralD_i8 wit, B_i8 n, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_i8(1L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_i8(1)); } -B_int B_IntegralD_i8D___int__ (B_IntegralD_i8 wit, B_i8 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_i8D___int__ (B_IntegralD_i8 wit, B_i8 n) { + return (int64_t)n->val; } -B_int B_IntegralD_i8D___index__(B_IntegralD_i8 wit, B_i8 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_i8D___index__(B_IntegralD_i8 wit, B_i8 n) { + return (int64_t)n->val; } B_tuple B_IntegralD_i8D___divmod__(B_IntegralD_i8 wit, B_i8 a, B_i8 b) { - if (b->val == 0) - $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); int8_t n = a->val; int8_t d = b->val; return $NEWTUPLE(2, toB_i8(n/d), toB_i8(n%d)); @@ -193,16 +195,16 @@ B_i8 B_IntegralD_i8D___mod__(B_IntegralD_i8 wit, B_i8 a, B_i8 b) { return toB_i8(a->val % b->val); } -B_i8 B_IntegralD_i8D___lshift__(B_IntegralD_i8 wit, B_i8 a, B_int b) { - return toB_i8(a->val << fromB_int(b)); +B_i8 B_IntegralD_i8D___lshift__(B_IntegralD_i8 wit, B_i8 a, int64_t b) { + return toB_i8(a->val << b); } -B_i8 B_IntegralD_i8D___rshift__(B_IntegralD_i8 wit, B_i8 a, B_int b) { - return toB_i8(a->val >> fromB_int(b)); +B_i8 B_IntegralD_i8D___rshift__(B_IntegralD_i8 wit, B_i8 a, int64_t b) { + return toB_i8(a->val >> b); } B_i8 B_IntegralD_i8D___invert__(B_IntegralD_i8 wit, B_i8 a) { - return toB_i8(~a->val); + return toB_i8( ~a->val); } @@ -233,7 +235,7 @@ B_i8 B_MinusD_IntegralD_i8D___sub__(B_MinusD_IntegralD_i8 wit, B_i8 a, B_i8 b) B_float B_DivD_i8D___truediv__ (B_DivD_i8 wit, B_i8 a, B_i8 b) { if (b->val == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - return to$float((double)a->val/(double)b->val); + return toB_float((double)a->val/(double)b->val); } // B_OrdD_i8 //////////////////////////////////////////////////////////////////////////////////////// @@ -273,6 +275,6 @@ B_bool B_HashableD_i8D___ne__(B_HashableD_i8 wit, B_i8 a, B_i8 b) { } B_NoneType B_HashableD_i8D_hash(B_HashableD_i8 wit, B_i8 a, B_hasher h) { - zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a->val),1)); + zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a), 4)); return B_None; } diff --git a/base/builtin/i8.h b/base/builtin/i8.h index eabc5c43d..8b5272cc2 100644 --- a/base/builtin/i8.h +++ b/base/builtin/i8.h @@ -7,7 +7,7 @@ struct B_i8 { B_i8 toB_i8(int8_t n); int8_t fromB_i8(B_i8 n); -B_i8 B_i8G_new(B_atom a, B_int base); +int8_t B_i8G_new(B_atom a, B_int base); #define i8_DIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("i8 truediv: division by zero"))); (double)a/(double)b;} ) #define i8_FLOORDIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("i8 floordiv: division by zero"))); a/b;} ) diff --git a/base/builtin/int.c b/base/builtin/int.c index 200def9fb..47a7d31b5 100644 --- a/base/builtin/int.c +++ b/base/builtin/int.c @@ -24,20 +24,20 @@ long int_pow(long a, long e) { // General methods /////////////////////////////////////////////////////////////////////// -B_int B_intG_new(B_atom a, B_int base) { +int64_t B_intG_new(B_atom a, B_int base) { // base is optional B_bigint b = B_bigintG_new(a, base); unsigned long n = b->val.n[0]; - long sz = b->val.size; + int sz = b->val.size; if (labs(sz) > 1 || (sz==1 && n > 0x7ffffffffffffffful) || sz == -1 && n > 0x8000000000000000ul) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), "int(): value %s out of range for type int",get_str(&b->val)); $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_int(n*sz); + return n*sz; } B_NoneType B_intD___init__(B_int self, B_atom a, B_int base){ - self->val = B_intG_new(a,base)->val; + self->val = B_intG_new(a,base); return B_None; } @@ -76,13 +76,13 @@ int64_t fromB_int(B_int w) { return w->val; } - + // B_IntegralD_int ///////////////////////////////////////////////////////////////////////// - + B_int B_IntegralD_intD___add__(B_IntegralD_int wit, B_int a, B_int b) { - return toB_int(a->val + b->val); + return toB_int(a->val + b->val); } B_int B_IntegralD_intD___zero__(B_IntegralD_int wit) { @@ -90,11 +90,11 @@ B_int B_IntegralD_intD___zero__(B_IntegralD_int wit) { } B_complex B_IntegralD_intD___complex__(B_IntegralD_int wit, B_int a) { - return toB_complex((double)a->val); + return toB_complex((double)(a->val)); } B_int B_IntegralD_intD___fromatom__(B_IntegralD_int wit, B_atom a) { - return B_intG_new(a,NULL); + return toB_int(B_intG_new(a,NULL)); } B_int B_IntegralD_intD___mul__(B_IntegralD_int wit, B_int a, B_int b) { @@ -102,11 +102,14 @@ B_int B_IntegralD_intD___mul__(B_IntegralD_int wit, B_int a, B_int b) { } B_int B_IntegralD_intD___pow__(B_IntegralD_int wit, B_int a, B_int b) { - if ( b->val < 0) { - // raise VALUEERROR; - return NULL; + int64_t aval = a->val; + int64_t bval = b->val; + if ( bval < 0) { + char errmsg[1024]; + snprintf(errmsg, sizeof(errmsg), "int.__pow__: negative exponent %ld ",(long)bval); + $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_int(int_pow(a->val,b->val)); + return toB_int(int_pow(aval,bval)); } B_int B_IntegralD_intD___neg__(B_IntegralD_int wit, B_int a) { @@ -118,11 +121,11 @@ B_int B_IntegralD_intD___pos__(B_IntegralD_int wit, B_int a) { } $WORD B_IntegralD_intD_real(B_IntegralD_int wit, B_int a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)(a)); } $WORD B_IntegralD_intD_imag(B_IntegralD_int wit, B_int a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_int(0L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_int(0LL)); } $WORD B_IntegralD_intD___abs__(B_IntegralD_int wit, B_int a, B_Real wit2) { @@ -133,8 +136,8 @@ B_int B_IntegralD_intD_conjugate(B_IntegralD_int wit, B_int a) { return a; } -B_float B_IntegralD_intD___float__ (B_IntegralD_int wit, B_int n) { - return to$float((double)n->val); +double B_IntegralD_intD___float__ (B_IntegralD_int wit, B_int n) { + return (double)n->val; } $WORD B_IntegralD_intD___trunc__ (B_IntegralD_int wit, B_int n, B_Integral wit2) { @@ -150,17 +153,17 @@ B_float B_IntegralD_intD___float__ (B_IntegralD_int wit, B_int n) { } B_int B_IntegralD_intD___round__ (B_IntegralD_int wit, B_int n, B_int p) { - long nval = n->val; + int64_t nval = n->val; if (nval<0) - return toB_int(-B_IntegralD_intD___round__(wit,toB_int(-nval),p)->val); - long pval = p==NULL ? 0 : fromB_int(p); + return toB_int(-B_IntegralD_intD___round__(wit,toB_int(-nval),p)->val); + int64_t pval = p==NULL ? 0 : fromB_int(p); if (pval>=0) return n; - long p10 = int_pow(10,-pval); - long res = nval/p10; + int64_t p10 = int_pow(10,-pval); + int64_t res = nval/p10; if (nval%p10 * 2 > p10) res++; - return toB_int (res * p10); + return toB_int(res * p10); } $WORD B_IntegralD_intD_numerator (B_IntegralD_int wit, B_int n, B_Integral wit2) { @@ -168,20 +171,20 @@ B_int B_IntegralD_intD___round__ (B_IntegralD_int wit, B_int n, B_int p) { } $WORD B_IntegralD_intD_denominator (B_IntegralD_int wit, B_int n, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_int(1L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_int(1LL)); } -B_int B_IntegralD_intD___int__ (B_IntegralD_int wit, B_int n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_intD___int__ (B_IntegralD_int wit, B_int n) { + return n->val; } -B_int B_IntegralD_intD___index__(B_IntegralD_int wit, B_int n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_intD___index__(B_IntegralD_int wit, B_int n) { + return n->val; } B_tuple B_IntegralD_intD___divmod__(B_IntegralD_int wit, B_int a, B_int b) { - long n = a->val; - long d = b->val; + int64_t n = a->val; + int64_t d = b->val; return $NEWTUPLE(2, toB_int(n/d), toB_int(n%d)); } @@ -195,12 +198,12 @@ B_int B_IntegralD_intD___mod__(B_IntegralD_int wit, B_int a, B_int b) { return toB_int(a->val % b->val); } -B_int B_IntegralD_intD___lshift__(B_IntegralD_int wit, B_int a, B_int b) { - return toB_int(a->val << fromB_int(b)); +B_int B_IntegralD_intD___lshift__(B_IntegralD_int wit, B_int a, int64_t b) { + return toB_int(a->val << b); } -B_int B_IntegralD_intD___rshift__(B_IntegralD_int wit, B_int a, B_int b) { - return toB_int(a->val >> fromB_int(b)); +B_int B_IntegralD_intD___rshift__(B_IntegralD_int wit, B_int a, int64_t b) { + return toB_int(a->val >> b); } B_int B_IntegralD_intD___invert__(B_IntegralD_int wit, B_int a) { @@ -235,7 +238,7 @@ B_int B_MinusD_IntegralD_intD___sub__(B_MinusD_IntegralD_int wit, B_int a, B_in B_float B_DivD_intD___truediv__ (B_DivD_int wit, B_int a, B_int b) { if (b->val == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - return to$float((double)a->val/(double)b->val); + return toB_float((double)a->val/(double)b->val); } // B_OrdD_int //////////////////////////////////////////////////////////////////////////////////////// diff --git a/base/builtin/int.h b/base/builtin/int.h index 6d91a7d9a..244730b56 100644 --- a/base/builtin/int.h +++ b/base/builtin/int.h @@ -8,7 +8,7 @@ B_int toB_int(int64_t n); B_int to$int(int64_t n); int64_t fromB_int(B_int n); -B_int B_intG_new(B_atom a, B_int base); +int64_t B_intG_new(B_atom a, B_int base); // only called with e>=0. long int_pow(long a, long e); // used also for ndarrays diff --git a/base/builtin/list.c b/base/builtin/list.c index 8bfb643e4..f4f242a0c 100644 --- a/base/builtin/list.c +++ b/base/builtin/list.c @@ -186,7 +186,7 @@ B_NoneType B_listD_extend(B_list lst, B_list other) { ix = fromB_int(i); long ix0 = ix < 0 ? len + ix : ix; if (ix0 < 0 || ix0 >= len) { - $RAISE((B_BaseException)$NEW(B_IndexError, toB_int(ix0), to$str("pop: index outside list"))); + $RAISE((B_BaseException)$NEW(B_IndexError, ix0, to$str("pop: index outside list"))); } $WORD res = lst->data[ix0]; memmove(lst->data + ix0, @@ -198,7 +198,7 @@ B_NoneType B_listD_extend(B_list lst, B_list other) { return res; } -B_int B_listD_index(B_list self, B_Eq W_EqD_B, $WORD val, B_int start, B_int stop) { +int64_t B_listD_index(B_list self, B_Eq W_EqD_B, $WORD val, B_int start, B_int stop) { int strt = 0; if (start) strt = fromB_int(start); @@ -218,21 +218,21 @@ B_int B_listD_index(B_list self, B_Eq W_EqD_B, $WORD val, B_int start, B_int sto B_value elem = (B_value)self->data[i]; B_bool eq = W_EqD_B->$class->__eq__(W_EqD_B, val, elem); if (eq->val) - return toB_int(i); + return i; } $RAISE((B_BaseException)$NEW(B_KeyError, val, to$str("element is not in list"))); - return NULL; //to prevent compiler warning + return 0; //to prevent compiler warning } -B_int B_listD_count(B_list self, B_Eq W_EqD_B, $WORD val) { - int count = 0; +int64_t B_listD_count(B_list self, B_Eq W_EqD_B, $WORD val) { + int64_t count = 0; for (int i = 0; i < self->length; i++) { B_value elem = (B_value)self->data[i]; B_bool eq = W_EqD_B->$class->__eq__(W_EqD_B, val, elem); if (eq->val) count++; } - return to$int(count); + return count; } @@ -307,7 +307,7 @@ B_list B_TimesD_SequenceD_listD___zero__ (B_TimesD_SequenceD_list wit) { B_list B_TimesD_SequenceD_listD___mul__ (B_TimesD_SequenceD_list wit, B_list lst, B_int n) { int lstlen = lst->length; - long n64 = fromB_int(n); + long n64 = n->val; if (lstlen == 0 || n64 <= 0) return B_listD_new(0); else { @@ -383,42 +383,40 @@ B_list B_CollectionD_SequenceD_listD___fromiter__ (B_CollectionD_SequenceD_list */ } -B_int B_CollectionD_SequenceD_listD___len__(B_CollectionD_SequenceD_list wit, B_list self) { - return toB_int(self->length); +int64_t B_CollectionD_SequenceD_listD___len__(B_CollectionD_SequenceD_list wit, B_list self) { + return (int64_t) self->length; } // B_SequenceD_list ////////////////////////////////////////////////////////////////// $WORD $listD_U__getitem__(B_list lst, int64_t n) { int len = lst->length; - int ix0 = n < 0 ? len + n : n; + int ix = n; + int ix0 = ix < 0 ? len + ix : ix; if (ix0 < 0 || ix0 >= len) { - $RAISE((B_BaseException)$NEW(B_IndexError, toB_int(ix0), to$str("getitem: index outside list"))); + $RAISE((B_BaseException)$NEW(B_IndexError, ix0, to$str("getitem: index outside list"))); } return lst->data[ix0]; } $WORD B_SequenceD_listD___getitem__(B_SequenceD_list wit, B_list lst, B_int n) { - return $listD_U__getitem__(lst, fromB_int(n)); + return $listD_U__getitem__(lst, n->val); } -B_NoneType listD_U__setitem__(B_list lst, int64_t n, $WORD val) { +B_NoneType B_SequenceD_listD___setitem__(B_SequenceD_list wit, B_list lst, B_int n, $WORD val) { int len = lst->length; - int ix0 = n < 0 ? len + n : n; + int ix = n->val; + int ix0 = ix < 0 ? len + ix : ix; if (ix0 < 0 || ix0 >= len) { - $RAISE((B_BaseException)$NEW(B_IndexError, toB_int(ix0), to$str("setitem: index outside list"))); + $RAISE((B_BaseException)$NEW(B_IndexError, ix0, to$str("setitem: index outside list"))); } lst->data[ix0] = val; return B_None; } -B_NoneType B_SequenceD_listD___setitem__(B_SequenceD_list wit, B_list lst, B_int n, $WORD val) { - return listD_U__setitem__(lst, fromB_int(n), val); -} - B_NoneType B_SequenceD_listD___delitem__(B_SequenceD_list wit, B_list lst, B_int n) { int len = lst->length; - int64_t ix = fromB_int(n); + int ix = n->val; int ix0 = ix < 0 ? len + ix : ix; if(ix0 < 0 || ix0 >= len) { return B_None; @@ -534,11 +532,10 @@ B_Iterator B_SequenceD_listD___reversed__(B_SequenceD_list wit, B_list lst) { return B_CollectionD_SequenceD_listD___iter__((B_CollectionD_SequenceD_list)wit->W_Collection, copy); } -B_NoneType B_SequenceD_listD_insert(B_SequenceD_list wit, B_list lst, B_int n, $WORD elem) { +B_NoneType B_SequenceD_listD_insert(B_SequenceD_list wit, B_list lst, int64_t n, $WORD elem) { int len = lst->length; - long ix = fromB_int(n); expand(lst,1); - long ix0 = ix < 0 ? (len+ix < 0 ? 0 : len+ix) : (ix < len ? ix : len); + long ix0 = n < 0 ? (len+n < 0 ? 0 : len+n) : (n < len ? n : len); memmove(lst->data + (ix0 + 1), lst->data + ix0 , (len - ix0) * sizeof($WORD)); diff --git a/base/builtin/range.c b/base/builtin/range.c index ffe3dc3e4..6febc704f 100644 --- a/base/builtin/range.c +++ b/base/builtin/range.c @@ -12,19 +12,19 @@ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -B_range B_rangeG_new(B_int start, B_int stop, B_int step) { +B_range B_rangeG_new(int64_t start, B_int stop, B_int step) { return $NEW(B_range, start, stop, step); } -B_NoneType B_rangeD___init__(B_range self, B_int start, B_int stop, B_int step) { +B_NoneType B_rangeD___init__(B_range self, int64_t start, B_int stop, B_int step) { int64_t ustart, ustop, ustep, stp; if (stop) { - ustart = start->val; + ustart = start; ustop = stop->val; } else { ustart = 0; - ustop = start->val; + ustop = start; } if (step) { stp = step->val; @@ -76,15 +76,16 @@ B_range B_rangeD___deserialize__(B_range self, $Serial$state state) { return res; } */ -int64_t rangeD_U__next__(B_range self) { +int64_t $rangeD_U__next__(B_range self) { if (self->remaining-- <= 0) $RAISE ((B_BaseException)$NEW(B_StopIteration, to$str("range iterator terminated"))); return self->nxt += self->step; } B_int B_rangeD___next__(B_range self) { - return toB_int(rangeD_U__next__(self)); + return toB_int($rangeD_U__next__(self)); } + /* void B_IteratorD_rangeD_init(B_IteratorD_range self, B_range rng) { int64_t stp = self->step = rng->step; diff --git a/base/builtin/range.h b/base/builtin/range.h index 273e486fb..5cb10a4fb 100644 --- a/base/builtin/range.h +++ b/base/builtin/range.h @@ -6,4 +6,4 @@ struct B_range { int64_t remaining; }; -int64_t $rangeD_U__next__(B_range); +int64_t $rangeD_U__next__(B_range self); diff --git a/base/builtin/registration.c b/base/builtin/registration.c index 55a7e0ed0..a46b7db62 100644 --- a/base/builtin/registration.c +++ b/base/builtin/registration.c @@ -95,6 +95,7 @@ void $register_builtin() { $register_force(U16_ID,&B_u16G_methods); $register_force(U32_ID,&B_u32G_methods); $register_force(U64_ID,&B_u64G_methods); + B_ClosureQ___init__(); } diff --git a/base/builtin/set.c b/base/builtin/set.c index eef8e340a..244f3379f 100644 --- a/base/builtin/set.c +++ b/base/builtin/set.c @@ -215,7 +215,7 @@ B_NoneType B_setD___init__(B_set set, B_Hashable hashwit, B_Iterable wit, $WORD while(1) { if ($PUSH()) { $WORD nxt = it->$class->__next__(it); - B_set_add_entry(set,hashwit,nxt,fromB_u64(B_hash(hashwit, nxt))); + B_set_add_entry(set,hashwit,nxt,B_hash(hashwit, nxt)); $DROP(); } else { B_BaseException ex = $POP(); @@ -376,7 +376,7 @@ B_Iterator B_SetD_setD___iter__ (B_SetD_set wit, B_set set) { B_NoneType B_SetD_setD_add (B_SetD_set wit, B_set set, $WORD elem) { B_Hashable hashwit = wit->W_HashableD_AD_SetD_set; - B_set_add_entry(set,hashwit,elem,fromB_u64(B_hash(hashwit, elem))); + B_set_add_entry(set,hashwit,elem,B_hash(hashwit, elem)); return B_None; } @@ -399,13 +399,13 @@ B_set B_SetD_setD___fromiter__(B_SetD_set wit, B_Iterable wit2, $WORD iter) { */ } -B_int B_SetD_setD___len__ (B_SetD_set wit, B_set set) { - return toB_int(set->numelements); +int64_t B_SetD_setD___len__ (B_SetD_set wit, B_set set) { + return set->numelements; } B_bool B_SetD_setD___contains__ (B_SetD_set wit, B_set set, $WORD val) { B_Hashable hashwit = wit->W_HashableD_AD_SetD_set; - return toB_bool(B_set_contains_entry(set,hashwit,val,fromB_u64(B_hash(hashwit, val)))); + return toB_bool(B_set_contains_entry(set,hashwit,val,B_hash(hashwit, val))); } B_bool B_SetD_setD___containsnot__ (B_SetD_set wit, B_set set, $WORD v) { @@ -440,7 +440,7 @@ B_NoneType B_SetD_setD_update (B_SetD_set wit, B_set set, B_Iterable otherwit, $ while(1) { if ($PUSH()) { $WORD e = it->$class->__next__(it); - B_set_add_entry(set, hashwit, e, fromB_u64(B_hash(hashwit, e))); + B_set_add_entry(set, hashwit, e, B_hash(hashwit, e)); $DROP(); } else { B_BaseException ex = $POP(); @@ -455,7 +455,7 @@ B_NoneType B_SetD_setD_update (B_SetD_set wit, B_set set, B_Iterable otherwit, $ B_NoneType B_SetD_setD_discard (B_SetD_set wit, B_set set, $WORD elem) { B_Hashable hashwit = wit->W_HashableD_AD_SetD_set; - B_set_discard_entry(set,hashwit,elem,fromB_u64(B_hash(hashwit, elem))); + B_set_discard_entry(set,hashwit,elem,B_hash(hashwit, elem)); return B_None; } diff --git a/base/builtin/str.c b/base/builtin/str.c index d87194bec..e8e63761f 100644 --- a/base/builtin/str.c +++ b/base/builtin/str.c @@ -32,7 +32,6 @@ static unsigned char nul = 0; static struct B_str null_struct = {&B_strG_methods,0,0,&nul}; static B_str null_str = &null_struct; - // Prebuilt immutable one-byte ASCII strings used by indexing and iteration. #define ASCII_CHAR_TABLE_SIZE 128 static unsigned char ascii_char_data[ASCII_CHAR_TABLE_SIZE][2] = { @@ -293,6 +292,7 @@ static struct B_str ascii_char_strs[ASCII_CHAR_TABLE_SIZE] = { [126] = {&B_strG_methods, 1, 1, ascii_char_data[126]}, [127] = {&B_strG_methods, 1, 1, ascii_char_data[127]} }; + static B_str space_str = &ascii_char_strs[(unsigned char)' ']; static struct B_str whitespace_struct = {&B_strG_methods,6,6,(unsigned char *)" \t\n\r\x0b\x0c"}; @@ -517,11 +517,8 @@ static unsigned char *skip_chars(unsigned char* start, int n, int isascii) { static int byte_no(B_str text, int i) { int res = 0; unsigned char *t = text->str; - for (int k=0; k= -nchars) return nchars+i; } - $RAISE((B_BaseException)$NEW(B_IndexError, toB_int(i), to$str("index outside str"))); + $RAISE((B_BaseException)$NEW(B_IndexError, i, to$str("index outside str"))); return 0; } @@ -895,8 +892,8 @@ B_str B_strD_capitalize(B_str s) { return res; } -B_str B_strD_center(B_str s, B_int width, B_str fill) { - int wval = fromB_int(width); +B_str B_strD_center(B_str s, int64_t width, B_str fill) { + int wval = width; if (!fill) fill = space_str; if (fill->nchars != 1) { @@ -928,21 +925,21 @@ B_str B_strD_center(B_str s, B_int width, B_str fill) { } -B_int B_strD_count(B_str s, B_str sub, B_int start, B_int end) { +int64_t B_strD_count(B_str s, B_str sub, B_int start, B_int end) { int isascii = s->nchars == s->nbytes; B_int st = start; B_int en = end; - if (fix_start_end(s->nchars,&st,&en) < 0) return toB_int(0); + if (fix_start_end(s->nchars,&st,&en) < 0) return 0; unsigned char *p = skip_chars(s->str,fromB_int(st),isascii); unsigned char *q = skip_chars(p,fromB_int(en)-fromB_int(st),isascii); - int res = 0; + int64_t res = 0; int n = bmh(p,sub->str,q-p,sub->nbytes); while (n>=0) { res++; p += n + (sub->nbytes>0 ? sub->nbytes : 1); n = bmh(p,sub->str,q-p,sub->nbytes); } - return toB_int(res); + return res; } B_bytes B_strD_encode(B_str s) { @@ -1004,21 +1001,21 @@ B_str B_strD_expandtabs(B_str s, B_int tabsize){ return res; } -B_int B_strD_find(B_str s, B_str sub, B_int start, B_int end) { +int64_t B_strD_find(B_str s, B_str sub, B_int start, B_int end) { int isascii = s->nchars == s->nbytes; B_int st = start; B_int en = end; - if (fix_start_end(s->nchars,&st,&en) < 0) return toB_int(-1); + if (fix_start_end(s->nchars,&st,&en) < 0) return -1; unsigned char *p = skip_chars(s->str,fromB_int(st),isascii); unsigned char *q = skip_chars(p,fromB_int(en)-fromB_int(st),isascii); int n = bmh(p,sub->str,q-p,sub->nbytes); - if (n<0) return toB_int(-1); - return toB_int(char_no(s,n+p-s->str)); + if (n<0) return -1; + return char_no(s,n+p-s->str); } -B_int B_strD_index(B_str s, B_str sub, B_int start, B_int end) { - B_int n = B_strD_find(s,sub,start,end); - if (fromB_int(n)<0) { +int64_t B_strD_index(B_str s, B_str sub, B_int start, B_int end) { + int64_t n = B_strD_find(s,sub,start,end); + if (n<0) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("index: substring not found"))); } return n; @@ -1212,12 +1209,12 @@ B_str B_strD_join(B_str s, B_Iterable wit, $WORD iter) { return res; } -B_str B_strD_ljust(B_str s, B_int width, B_str fill) { +B_str B_strD_ljust(B_str s, int64_t width, B_str fill) { if (!fill) fill = space_str; if (fill->nchars != 1) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("ljust: fill str not single char"))); } - int wval = fromB_int(width); + int wval = width; if (wval <= s->nchars) { return s; } @@ -1262,12 +1259,11 @@ B_str B_strD_lstrip(B_str s, B_str cs) { } B_tuple B_strD_partition(B_str s, B_str sep) { - int n = fromB_int(B_strD_find(s,sep,NULL,NULL)); + int64_t n = B_strD_find(s,sep,NULL,NULL); if (n<0) { return $NEWTUPLE(3,s,null_str,null_str); } else { - int isascii = s->nchars == s->nbytes; - int nb = (int)(skip_chars(s->str,n,isascii)-s->str); + int nb = bmh(s->str,sep->str,s->nbytes,sep->nbytes); B_str ls; NEW_UNFILLED_STR(ls,n,nb); memcpy(ls->str,s->str,nb); @@ -1282,7 +1278,7 @@ B_tuple B_strD_partition(B_str s, B_str sep) { B_str B_strD_replace(B_str s, B_str old, B_str new, B_int count) { if (count==NULL) count = toB_int(INT_MAX); - int c = fromB_int(B_strD_count(s,old,NULL,NULL)); + int c = B_strD_count(s,old,NULL,NULL); int c0 = fromB_int(count) < c ? fromB_int(count) : c; if (c0==0){ return s; @@ -1314,33 +1310,33 @@ B_str B_strD_replace(B_str s, B_str old, B_str new, B_int count) { } -B_int B_strD_rfind(B_str s, B_str sub, B_int start, B_int end) { +int64_t B_strD_rfind(B_str s, B_str sub, B_int start, B_int end) { int isascii = s->nchars == s->nbytes; B_int st = start; B_int en = end; - if (fix_start_end(s->nchars,&st,&en) < 0) return toB_int(-1); + if (fix_start_end(s->nchars,&st,&en) < 0) return -1; unsigned char *p = skip_chars(s->str,fromB_int(st),isascii); unsigned char *q = skip_chars(p,fromB_int(en)-fromB_int(st),isascii); int n = rbmh(p,sub->str,q-p,sub->nbytes); - if (n<0) return toB_int(-1); - return toB_int(char_no(s,n+p-s->str)); + if (n<0) return -1; + return char_no(s,n+p-s->str); } -B_int B_strD_rindex(B_str s, B_str sub, B_int start, B_int end) { - B_int n = B_strD_rfind(s,sub,start,end); - if (fromB_int(n)<0) { +int64_t B_strD_rindex(B_str s, B_str sub, B_int start, B_int end) { + int64_t n = B_strD_rfind(s,sub,start,end); + if (n<0) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("rindex: substring not found"))); }; return n; } -B_str B_strD_rjust(B_str s, B_int width, B_str fill) { +B_str B_strD_rjust(B_str s, int64_t width, B_str fill) { if (!fill) fill = space_str; if (fill->nchars != 1) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("rjust: fill string not single char"))); } - int wval = fromB_int(width); + int wval = width; if (wval <= s->nchars) { return s; } @@ -1358,12 +1354,11 @@ B_str B_strD_rjust(B_str s, B_int width, B_str fill) { } B_tuple B_strD_rpartition(B_str s, B_str sep) { - int n = fromB_int(B_strD_rfind(s,sep,NULL,NULL)); + int64_t n = B_strD_rfind(s,sep,NULL,NULL); if (n<0) { return $NEWTUPLE(3,null_str,null_str,s); } else { - int isascii = s->nchars == s->nbytes; - int nb = (int)(skip_chars(s->str,n,isascii)-s->str); + int nb = rbmh(s->str,sep->str,s->nbytes,sep->nbytes); B_str ls; NEW_UNFILLED_STR(ls,n,nb); memcpy(ls->str,s->str,nb); @@ -1541,8 +1536,8 @@ B_str B_strD_upper(B_str s) { return str_transform(s,utf8proc_toupper); } -B_str B_strD_zfill(B_str s, B_int width) { - int wval = fromB_int(width); +B_str B_strD_zfill(B_str s, int64_t width) { + int wval = width; int fill = wval - s->nchars; if (fill < 0) return s; @@ -1631,7 +1626,7 @@ B_str B_TimesD_strD___zero__ (B_TimesD_str wit) { } B_str B_TimesD_strD___mul__ (B_TimesD_str wit, B_str a, B_int n) { - int nval = fromB_int(n); + int64_t nval = n->val; if (nval <= 0) return null_str; else { @@ -1650,8 +1645,8 @@ B_str B_ContainerD_strD___fromiter__ (B_ContainerD_str wit, B_Iterable wit2, $WO return B_strD_join(null_str,wit2,iter); } -B_int B_ContainerD_strD___len__ (B_ContainerD_str wit, B_str s){ - return toB_int(s->nchars); +int64_t B_ContainerD_strD___len__ (B_ContainerD_str wit, B_str s){ + return (int64_t)s->nchars; } // B_Container /////////////////////////////////////////////////////////////////////////// @@ -1728,7 +1723,7 @@ B_Iterator B_ContainerD_strD___iter__ (B_ContainerD_str wit, B_str s) { B_str B_SliceableD_strD___getitem__ (B_SliceableD_str wit, B_str s, B_int i) { unsigned char *p = s->str; - int ix = get_index(fromB_int(i),s->nchars); + int ix = get_index(i->val,s->nchars); p = skip_chars(p,ix,s->nchars == s->nbytes); return mk_char(p); } @@ -1754,16 +1749,13 @@ B_str B_SliceableD_strD___getslice__ (B_SliceableD_str wit, B_str s, B_slice slc if (slen == 0) { return null_str; } - if (slen == 1) { - return mk_char(skip_chars(s->str, start, isascii)); - } //slice notation have been eliminated and default values applied. unsigned char buffer[4*slen]; // very conservative buffer size. unsigned char *p = buffer; - unsigned char *t = skip_chars(s->str, start, isascii); + unsigned char *t = skip_chars(s->str,start,isascii); for (int i=0; inbytes != 1) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("center: fill bytearray not single char"))); } - int wval = fromB_int(width); + int wval = width; if (wval <= s->nbytes) { return B_bytearrayD_copy(s); } @@ -1978,22 +1970,22 @@ B_bytearray B_bytearrayD_center(B_bytearray s, B_int width, B_bytearray fill) { return res; } -B_int B_bytearrayD_count(B_bytearray s, B_bytearray sub, B_int start, B_int end) { +int64_t B_bytearrayD_count(B_bytearray s, B_bytearray sub, B_int start, B_int end) { B_int st = start; B_int en = end; - if (fix_start_end(s->nbytes,&st,&en) < 0) return toB_int(0); + if (fix_start_end(s->nbytes,&st,&en) < 0) return 0; int stval = fromB_int(st); int enval = fromB_int(en); unsigned char *p = &s->str[stval]; unsigned char *q = &p[enval-stval]; - int res = 0; + int64_t res = 0; int n = bmh(p,sub->str,q-p,sub->nbytes); while (n>=0) { res++; p += n + (sub->nbytes>0 ? sub->nbytes : 1); n = bmh(p,sub->str,q-p,sub->nbytes); } - return toB_int(res); + return res; } B_str B_bytearrayD_decode(B_bytearray s) { @@ -2051,15 +2043,15 @@ B_bytearray B_bytearrayD_expandtabs(B_bytearray s, B_int tabsz){ return res; } -B_int B_bytearrayD_find(B_bytearray s, B_bytearray sub, B_int start, B_int end) { +int64_t B_bytearrayD_find(B_bytearray s, B_bytearray sub, B_int start, B_int end) { B_int st = start; B_int en = end; - if (fix_start_end(s->nbytes,&st,&en) < 0) return toB_int(-1); + if (fix_start_end(s->nbytes,&st,&en) < 0) return -1; unsigned char *p = &s->str[fromB_int(st)]; unsigned char *q = &s->str[fromB_int(en)]; int n = bmh(p,sub->str,q-p,sub->nbytes); - if (n<0) return toB_int(-1); - return toB_int(n+p-s->str); + if (n<0) return -1; + return n+p-s->str; } B_bytearray B_bytearrayD_from_hex(B_str s) { @@ -2128,9 +2120,9 @@ B_str B_bytearrayD_hex(B_bytearray s) { } -B_int B_bytearrayD_index(B_bytearray s, B_bytearray sub, B_int start, B_int end) { - B_int n = B_bytearrayD_find(s,sub,start,end); - if (fromB_int(n)<0) { +int64_t B_bytearrayD_index(B_bytearray s, B_bytearray sub, B_int start, B_int end) { + int64_t n = B_bytearrayD_find(s,sub,start,end); + if (n<0) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("index: substring not found"))); } return n; @@ -2264,10 +2256,10 @@ B_bytearray B_bytearrayD_join(B_bytearray s, B_Iterable wit, $WORD iter) { return res; } -B_bytearray B_bytearrayD_ljust(B_bytearray s, B_int width, B_bytearray fill) { +B_bytearray B_bytearrayD_ljust(B_bytearray s, int64_t width, B_bytearray fill) { if (!fill) fill = space_bytearray; - int wval = fromB_int(width); + int wval = width; if (fill->nbytes != 1) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("bytearray ljust: fill array not single char"))); } @@ -2316,7 +2308,7 @@ B_bytearray B_bytearrayD_lstrip(B_bytearray s, B_bytearray cs) { B_tuple B_bytearrayD_partition(B_bytearray s, B_bytearray sep) { - int n = fromB_int(B_bytearrayD_find(s,sep,NULL,NULL)); + int64_t n = B_bytearrayD_find(s,sep,NULL,NULL); if (n<0) { return $NEWTUPLE(3,s,toB_bytearray(""),toB_bytearray("")); } else { @@ -2336,7 +2328,7 @@ B_tuple B_bytearrayD_partition(B_bytearray s, B_bytearray sep) { B_bytearray B_bytearrayD_replace(B_bytearray s, B_bytearray old, B_bytearray new, B_int count) { if (count==NULL) count = toB_int(INT_MAX); - int c = fromB_int(B_bytearrayD_count(s,old,NULL,NULL)); + int64_t c = B_bytearrayD_count(s,old,NULL,NULL); int c0 = fromB_int(count) < c ? fromB_int(count) : c; if (c0==0){ return B_bytearrayD_copy(s); @@ -2367,30 +2359,30 @@ B_bytearray B_bytearrayD_replace(B_bytearray s, B_bytearray old, B_bytearray new } -B_int B_bytearrayD_rfind(B_bytearray s, B_bytearray sub, B_int start, B_int end) { +int64_t B_bytearrayD_rfind(B_bytearray s, B_bytearray sub, B_int start, B_int end) { B_int st = start; B_int en = end; - if (fix_start_end(s->nbytes,&st,&en) < 0) return toB_int(-1); + if (fix_start_end(s->nbytes,&st,&en) < 0) return -1; unsigned char *p = &s->str[fromB_int(st)]; unsigned char *q = &s->str[fromB_int(en)]; int n = rbmh(p,sub->str,q-p,sub->nbytes); - if (n<0) return toB_int(-1); - return toB_int(n+p-s->str); + if (n<0) return -1; + return n+p-s->str; } -B_int B_bytearrayD_rindex(B_bytearray s, B_bytearray sub, B_int start, B_int end) { - B_int n = B_bytearrayD_rfind(s,sub,start,end); - if (fromB_int(n)<0) { +int64_t B_bytearrayD_rindex(B_bytearray s, B_bytearray sub, B_int start, B_int end) { + int64_t n = B_bytearrayD_rfind(s,sub,start,end); + if (n<0) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("rindex for bytearray: substring not found"))); }; return n; } -B_bytearray B_bytearrayD_rjust(B_bytearray s, B_int width, B_bytearray fill) { +B_bytearray B_bytearrayD_rjust(B_bytearray s, int64_t width, B_bytearray fill) { if (!fill) fill = space_bytearray; - int wval = fromB_int(width); + int wval = width; if (fill->nbytes != 1) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("rjust: fill string not single char"))); } @@ -2409,7 +2401,7 @@ B_bytearray B_bytearrayD_rjust(B_bytearray s, B_int width, B_bytearray fill) { } B_tuple B_bytearrayD_rpartition(B_bytearray s, B_bytearray sep) { - int n = fromB_int(B_bytearrayD_rfind(s,sep,NULL,NULL)); + int64_t n = B_bytearrayD_rfind(s,sep,NULL,NULL); if (n<0) { return $NEWTUPLE(3,toB_bytearray(""),toB_bytearray(""),s); } else { @@ -2578,8 +2570,8 @@ B_bytearray B_bytearrayD_upper(B_bytearray s) { return res; } -B_bytearray B_bytearrayD_zfill(B_bytearray s, B_int width) { - int wval = fromB_int(width); +B_bytearray B_bytearrayD_zfill(B_bytearray s, int64_t width) { + int wval = width; int fill = wval - s->nbytes; if (fill < 0) return B_bytearrayD_copy(s); @@ -2684,14 +2676,14 @@ B_bytearray B_ContainerD_bytearrayD___fromiter__ (B_ContainerD_bytearray wit, B_ return B_bytearrayD_join(toB_bytearray(""),wit2,iter); } -B_int B_ContainerD_bytearrayD___len__ (B_ContainerD_bytearray wit, B_bytearray str) { - return toB_int(str->nbytes); +int64_t B_ContainerD_bytearrayD___len__ (B_ContainerD_bytearray wit, B_bytearray str) { + return (int64_t)str->nbytes; } B_bool B_ContainerD_bytearrayD___contains__(B_ContainerD_bytearray wit, B_bytearray self, B_int n) { long res = 0; for (int i=0; i < self->nbytes; i++) { - if (self->str[i] == (unsigned char)fromB_int(n)) { + if (self->str[i] == (unsigned char)n->val) { res = 1; break; } @@ -2706,19 +2698,19 @@ B_bool B_ContainerD_bytearrayD___containsnot__(B_ContainerD_bytearray wit, B_byt // Sequence B_int B_SequenceD_bytearrayD___getitem__ (B_SequenceD_bytearray wit, B_bytearray self, B_int n) { - int64_t ix = fromB_int(n); + int64_t ix = n->val; int64_t ix0 = ix < 0 ? self->nbytes + ix : ix; if (ix0<0 || ix0 >= self->nbytes) - $RAISE((B_BaseException)$NEW(B_IndexError, toB_int(ix0), to$str("getitem: index outside bytearray"))); - return toB_int((long)self->str[ix0]); + $RAISE((B_BaseException)$NEW(B_IndexError, ix0, to$str("getitem: index outside bytearray"))); + return toB_int((int64_t)self->str[ix0]); } B_NoneType B_SequenceD_bytearrayD___setitem__ (B_SequenceD_bytearray wit, B_bytearray self, B_int n, B_int v) { - int64_t ix = fromB_int(n); + int64_t ix = n->val; int64_t ix0 = ix < 0 ? self->nbytes + ix : ix; - long val = fromB_int(v); + long val = v->val; if (ix0<0 || ix0 >= self->nbytes) - $RAISE((B_BaseException)$NEW(B_IndexError, toB_int(ix0), to$str("setitem: index outside bytearray"))); + $RAISE((B_BaseException)$NEW(B_IndexError, ix0, to$str("setitem: index outside bytearray"))); if (val<0 || val>255) $RAISE((B_BaseException)$NEW(B_ValueError,to$str("setitem for bytearray: value outside [0..255]"))); self->str[ix0] = (unsigned char)val; @@ -2726,32 +2718,32 @@ B_NoneType B_SequenceD_bytearrayD___setitem__ (B_SequenceD_bytearray wit, B_byte } B_NoneType B_SequenceD_bytearrayD___delitem__ (B_SequenceD_bytearray wit, B_bytearray self, B_int n) { - int64_t ix = fromB_int(n); + int64_t ix = n->val; int64_t ix0 = ix < 0 ? self->nbytes + ix : ix; int len = self->nbytes; if (ix0 < 0 || ix0 >= len) - $RAISE((B_BaseException)$NEW(B_IndexError, toB_int(ix0), to$str("delitem: index outside bytearray"))); + $RAISE((B_BaseException)$NEW(B_IndexError, ix0, to$str("delitem: index outside bytearray"))); memmove(self->str + ix0,self->str + (ix0 + 1),len-(ix0+1)); self->nbytes--; return B_None; } -B_NoneType B_SequenceD_bytearrayD_insert(B_SequenceD_bytearray wit, B_bytearray self, B_int n, B_int elem) { - long ix = fromB_int(n); +B_NoneType B_SequenceD_bytearrayD_insert(B_SequenceD_bytearray wit, B_bytearray self, int64_t n, B_int elem) { + long ix = n; int len = self->nbytes; expand_bytearray(self,1); int ix0 = ix < 0 ? (len+ix < 0 ? 0 : len+ix) : (ix < len ? ix : len); memmove(self->str + (ix0 + 1), self->str + ix0 , len - ix0 + 1); // +1 to move also terminating '\0' - self->str[ix0] = (unsigned char)fromB_int(elem) & 0xff; + self->str[ix0] = (unsigned char)(elem->val & 0xff); self->nbytes++; return B_None; } B_NoneType B_SequenceD_bytearrayD_append(B_SequenceD_bytearray wit, B_bytearray self, B_int elem) { expand_bytearray(self,1); - self->str[self->nbytes++] = (unsigned char)fromB_int(elem) & 0xff; + self->str[self->nbytes++] = (unsigned char)(elem->val & 0xff); self->str[self->nbytes] = '\0'; return B_None; } @@ -2794,7 +2786,7 @@ B_NoneType B_SequenceD_bytearrayD___setslice__ (B_SequenceD_bytearray wit, B_by NEW_UNFILLED_BYTEARRAY(other,0); $WORD w; while ((w=it->$class->__next__(it))) - B_SequenceD_bytearrayD_append(wit, other,(B_int)w); + B_SequenceD_bytearrayD_append(wit, other,w); int olen = other->nbytes; int64_t start, stop, step, slen; normalize_slice(slc, len, &slen, &start, &stop, &step); @@ -2857,8 +2849,8 @@ B_bytearray B_CollectionD_SequenceD_bytearrayD___fromiter__ (B_CollectionD_Seque return B_bytearrayD_join(toB_bytearray(""),wit2,iter); } -B_int B_CollectionD_SequenceD_bytearrayD___len__ (B_CollectionD_SequenceD_bytearray wit, B_bytearray str) { - return toB_int(str->nbytes); +int64_t B_CollectionD_SequenceD_bytearrayD___len__ (B_CollectionD_SequenceD_bytearray wit, B_bytearray str) { + return (int64_t)str->nbytes; } // Times @@ -2876,7 +2868,7 @@ B_bytearray B_TimesD_SequenceD_bytearrayD___zero__ (B_TimesD_SequenceD_bytearray } B_bytearray B_TimesD_SequenceD_bytearrayD___mul__ (B_TimesD_SequenceD_bytearray wit, B_bytearray a, B_int n) { - int nval = fromB_int(n); + int nval = n->val; if (nval <= 0) return toB_bytearray(""); else { @@ -2943,8 +2935,8 @@ B_bytes actBytesFromCStringLengthNoCopy(char *str, int length) { return res; } -unsigned char *fromB_bytes(B_bytes b) { - return b->str; +char *fromB_bytes(B_bytes b) { + return (char *)b->str; } // Auxiliaries @@ -3046,8 +3038,8 @@ B_bytes B_bytesD_capitalize(B_bytes s) { return res; } -B_bytes B_bytesD_center(B_bytes s, B_int width, B_bytes fill) { - int wval = fromB_int(width); +B_bytes B_bytesD_center(B_bytes s, int64_t width, B_bytes fill) { + int wval = width; if (!fill) fill = to$bytes(" "); if (fill->nbytes != 1) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("center: fill bytes not single char"))); @@ -3073,21 +3065,21 @@ B_bytes B_bytesD_center(B_bytes s, B_int width, B_bytes fill) { return res; } -B_int B_bytesD_count(B_bytes s, B_bytes sub, B_int start, B_int end) { +int64_t B_bytesD_count(B_bytes s, B_bytes sub, B_int start, B_int end) { B_int st = start; B_int en = end; - if (fix_start_end(s->nbytes,&st,&en) < 0) return toB_int(0); + if (fix_start_end(s->nbytes,&st,&en) < 0) return 0; int stval = fromB_int(st); unsigned char *p = &s->str[stval]; unsigned char *q = &p[fromB_int(en)-stval]; - int res = 0; + int64_t res = 0; int n = bmh(p,sub->str,q-p,sub->nbytes); while (n>=0) { res++; p += n + (sub->nbytes>0 ? sub->nbytes : 1); n = bmh(p,sub->str,q-p,sub->nbytes); } - return toB_int(res); + return res; } B_str B_bytesD_decode(B_bytes s) { @@ -3144,15 +3136,15 @@ B_bytes B_bytesD_expandtabs(B_bytes s, B_int tabsz){ return res; } -B_int B_bytesD_find(B_bytes s, B_bytes sub, B_int start, B_int end) { +int64_t B_bytesD_find(B_bytes s, B_bytes sub, B_int start, B_int end) { B_int st = start; B_int en = end; - if (fix_start_end(s->nbytes,&st,&en) < 0) return toB_int(-1); + if (fix_start_end(s->nbytes,&st,&en) < 0) return -1; unsigned char *p = &s->str[fromB_int(st)]; unsigned char *q = &s->str[fromB_int(en)]; int n = bmh(p,sub->str,q-p,sub->nbytes); - if (n<0) return toB_int(-1); - return toB_int(n+p-s->str); + if (n<0) return -1; + return n+p-s->str; } B_bytes B_bytesD_from_hex(B_str s) { @@ -3160,7 +3152,7 @@ B_bytes B_bytesD_from_hex(B_str s) { return null_bytes; // Each byte is represented by 2 hex chars int strlen = s->nbytes; // Changed from len to nbytes - if (strlen % 2 != 0) { + if (strlen % 2 != 0) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("from_hex: hex string must have even length"))); } @@ -3224,9 +3216,9 @@ B_str B_bytesD_hex(B_bytes s) { return to_str_noc(result); } -B_int B_bytesD_index(B_bytes s, B_bytes sub, B_int start, B_int end) { - B_int n = B_bytesD_find(s,sub,start,end); - if (fromB_int(n)<0) { +int64_t B_bytesD_index(B_bytes s, B_bytes sub, B_int start, B_int end) { + int64_t n = B_bytesD_find(s,sub,start,end); + if (n<0) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("index: substring not found"))); } return n; @@ -3360,10 +3352,10 @@ B_bytes B_bytesD_join(B_bytes s, B_Iterable wit, $WORD iter) { return res; } -B_bytes B_bytesD_ljust(B_bytes s, B_int width, B_bytes fill) { +B_bytes B_bytesD_ljust(B_bytes s, int64_t width, B_bytes fill) { if (!fill) fill = space_bytes; - int wval = fromB_int(width); + int wval = width; if (fill->nbytes != 1) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("bytes ljust: fill array not single char"))); } @@ -3412,7 +3404,7 @@ B_bytes B_bytesD_lstrip(B_bytes s, B_bytes cs) { B_tuple B_bytesD_partition(B_bytes s, B_bytes sep) { - int n = fromB_int(B_bytesD_find(s,sep,NULL,NULL)); + int64_t n = B_bytesD_find(s,sep,NULL,NULL); if (n<0) { return $NEWTUPLE(3,s,to$bytes(""),to$bytes("")); } else { @@ -3457,7 +3449,7 @@ B_bytes B_bytesD_removesuffix(B_bytes s, B_bytes suffix) { B_bytes B_bytesD_replace(B_bytes s, B_bytes old, B_bytes new, B_int count) { if (count==NULL) count = toB_int(INT_MAX); - int c = fromB_int(B_bytesD_count(s,old,NULL,NULL)); + int64_t c = B_bytesD_count(s,old,NULL,NULL); int c0 = fromB_int(count) < c ? fromB_int(count) : c; if (c0==0){ return B_bytesD_copy(s); @@ -3488,33 +3480,33 @@ B_bytes B_bytesD_replace(B_bytes s, B_bytes old, B_bytes new, B_int count) { } -B_int B_bytesD_rfind(B_bytes s, B_bytes sub, B_int start, B_int end) { +int64_t B_bytesD_rfind(B_bytes s, B_bytes sub, B_int start, B_int end) { B_int st = start; B_int en = end; - if (fix_start_end(s->nbytes,&st,&en) < 0) return toB_int(-1); + if (fix_start_end(s->nbytes,&st,&en) < 0) return -1; unsigned char *p = &s->str[fromB_int(st)]; unsigned char *q = &s->str[fromB_int(en)]; int n = rbmh(p,sub->str,q-p,sub->nbytes); - if (n<0) return toB_int(-1); - return toB_int(n+p-s->str); + if (n<0) return -1; + return n+p-s->str; } -B_int B_bytesD_rindex(B_bytes s, B_bytes sub, B_int start, B_int end) { - B_int n = B_bytesD_rfind(s,sub,start,end); - if (fromB_int(n)<0) { +int64_t B_bytesD_rindex(B_bytes s, B_bytes sub, B_int start, B_int end) { + int64_t n = B_bytesD_rfind(s,sub,start,end); + if (n<0) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("rindex for bytes: substring not found"))); }; return n; } -B_bytes B_bytesD_rjust(B_bytes s, B_int width, B_bytes fill) { +B_bytes B_bytesD_rjust(B_bytes s, int64_t width, B_bytes fill) { if (!fill) fill = space_bytes; if (fill->nbytes != 1) { $RAISE((B_BaseException)$NEW(B_ValueError,to$str("rjust: fill string not single char"))); } - int wval = fromB_int(width); + int wval = width; if (wval <= s->nbytes) { return B_bytesD_copy(s); } @@ -3530,7 +3522,7 @@ B_bytes B_bytesD_rjust(B_bytes s, B_int width, B_bytes fill) { } B_tuple B_bytesD_rpartition(B_bytes s, B_bytes sep) { - int n = fromB_int(B_bytesD_rfind(s,sep,NULL,NULL)); + int64_t n = B_bytesD_rfind(s,sep,NULL,NULL); if (n<0) { return $NEWTUPLE(3,to$bytes(""),to$bytes(""),s); } else { @@ -3700,8 +3692,8 @@ B_bytes B_bytesD_upper(B_bytes s) { return res; } -B_bytes B_bytesD_zfill(B_bytes s, B_int width) { - int wval = fromB_int(width); +B_bytes B_bytesD_zfill(B_bytes s, int64_t width) { + int wval = width; int fill = wval - s->nbytes; if (fill < 0) return B_bytesD_copy(s); @@ -3816,14 +3808,14 @@ B_bytes B_ContainerD_bytesD___fromiter__ (B_ContainerD_bytes wit, B_Iterable wit return B_bytesD_join(to$bytes(""),wit2,iter); } -B_int B_ContainerD_bytesD___len__ (B_ContainerD_bytes wit, B_bytes str) { - return toB_int(str->nbytes); +int64_t B_ContainerD_bytesD___len__ (B_ContainerD_bytes wit, B_bytes str) { + return (int64_t)str->nbytes; } B_bool B_ContainerD_bytesD___contains__ (B_ContainerD_bytes wit, B_bytes str, B_int n) { long res = 0; for (int i=0; i < str->nbytes; i++) { - if (str->str[i] == (unsigned char)fromB_int(n)) { + if (str->str[i] == (unsigned char)n->val) { res = 1; break; } @@ -3838,10 +3830,10 @@ B_bool B_ContainerD_bytesD___containsnot__ (B_ContainerD_bytes wit, B_bytes str, // Sliceable B_int B_SliceableD_bytesD___getitem__ (B_SliceableD_bytes wit, B_bytes str, B_int n) { - long ix = fromB_int(n); + long ix = n->val; long ix0 = ix < 0 ? str->nbytes + ix : ix; if (ix0<0 || ix0 >= str->nbytes) - $RAISE((B_BaseException)$NEW(B_IndexError, toB_int(ix0), to$str("getitem: index outside bytesarray"))); + $RAISE((B_BaseException)$NEW(B_IndexError, ix0, to$str("getitem: index outside bytesarray"))); return toB_int((long)str->str[ix0]); } @@ -3895,7 +3887,7 @@ B_bytes B_TimesD_bytesD___zero__ (B_TimesD_bytes wit) { } B_bytes B_TimesD_bytesD___mul__ (B_TimesD_bytes wit, B_bytes a, B_int n) { - int nval = fromB_int(n); + int64_t nval = n->val; if (nval <= 0) return to$bytes(""); else { @@ -3951,7 +3943,7 @@ B_str B_ascii(B_value v) { } B_str B_bin(B_Integral wit, $WORD n) { - long v = fromB_int(wit->$class->__int__(wit,n)); + long v = wit->$class->__int__(wit,n); int sign = v<0; int nbits = 1; unsigned long u = labs(v); @@ -3990,7 +3982,7 @@ B_str B_bin(B_Integral wit, $WORD n) { } B_str B_chr(B_Integral wit, $WORD n) { - long v = fromB_int(wit->$class->__int__(wit,n)); + int64_t v = wit->$class->__int__(wit,n); if (v >= 0x110000) $RAISE((B_BaseException)$NEW(B_ValueError,to$str("chr: argument is not a valid Unicode code point"))); if (v > 0 && v < ASCII_CHAR_TABLE_SIZE) @@ -4008,7 +4000,7 @@ B_str B_chr(B_Integral wit, $WORD n) { B_str B_hex(B_Integral wit, $WORD n) { unsigned char *hexdigits = (unsigned char *)"0123456789abcdef"; - long v = fromB_int(wit->$class->__int__(wit,n)); + long v = wit->$class->__int__(wit,n); int sign = v<0; int nhexs = 1; unsigned long u = labs(v); @@ -4040,7 +4032,7 @@ B_str B_hex(B_Integral wit, $WORD n) { return res; } -int64_t B_U_6ord(B_str c) { +int64_t B_ord(B_str c) { if(c->nchars != 1) $RAISE((B_BaseException)$NEW(B_ValueError,to$str("ord: argument is not a single Unicode char"))); int cp; diff --git a/base/builtin/str.h b/base/builtin/str.h index 62970cb18..164d4132c 100644 --- a/base/builtin/str.h +++ b/base/builtin/str.h @@ -102,7 +102,7 @@ B_bytes actBytesFromCString(char *str); B_bytes actBytesFromCStringNoCopy(char *str); B_bytes actBytesFromCStringLength(char *str, int len); B_bytes actBytesFromCStringLengthNoCopy(char *str, int length); -unsigned char *fromB_bytes(B_bytes b); +char *fromB_bytes(B_bytes b); // Iterators over bytes /////////////////////////////////////////////////////// diff --git a/base/builtin/tuple.c b/base/builtin/tuple.c index 898793c91..f10bd822d 100644 --- a/base/builtin/tuple.c +++ b/base/builtin/tuple.c @@ -175,7 +175,7 @@ B_NoneType B_SliceableD_tupleD___init__ (B_SliceableD_tuple wit) { int ix = fromB_int(n); int ix0 = ix < 0 ? size + ix : ix; if (ix0 < 0 || ix0 >= size) { - $RAISE((B_BaseException)$NEW(B_IndexError, toB_int(ix0), to$str("tuple.getitem: index outside tuple"))); + $RAISE((B_BaseException)$NEW(B_IndexError, ix0, to$str("tuple.getitem: index outside tuple"))); } return self->components[ix0]; } diff --git a/base/builtin/u1.c b/base/builtin/u1.c index 0d8cf9374..d3e79b8c3 100644 --- a/base/builtin/u1.c +++ b/base/builtin/u1.c @@ -14,29 +14,46 @@ // Auxiliary ////////////////////////////////////////////////////////////////////////////// +#define U1_NORM(a) ((uint8_t)((a) & 1)) +#define U1_ADD(a,b) U1_NORM((a) + (b)) +#define U1_SUB(a,b) U1_NORM((a) - (b)) +#define U1_MUL(a,b) U1_NORM((a) * (b)) +#define U1_NEG(a) U1_NORM(-(a)) +#define U1_INVERT(a) U1_NORM(~(a)) +#define U1_AND(a,b) U1_NORM((a) & (b)) +#define U1_OR(a,b) U1_NORM((a) | (b)) +#define U1_XOR(a,b) U1_NORM((a) ^ (b)) +#define U1_LSHIFT(a,b) U1_NORM((a) << (b)) +#define U1_RSHIFT(a,b) U1_NORM((a) >> (b)) +#define U1_DIV(a,b) ({ uint8_t _u1_b = (b); if (_u1_b == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); (double)(a)/(double)_u1_b; }) +#define U1_FLOORDIV(a,b) ({ uint8_t _u1_b = (b); if (_u1_b == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); U1_NORM((a) / _u1_b); }) +#define U1_MOD(a,b) ({ uint8_t _u1_b = (b); if (_u1_b == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); U1_NORM((a) % _u1_b); }) + // only called with e>=0. uint8_t u1_pow(uint8_t a, uint8_t e) { if (e == 0) return 1; - return a; + if (e == 1) return a; + if (e%2 == 0) return U1_NORM(int_pow(a*a,e/2)); + return U1_NORM(a * int_pow(a*a,e/2)); } -// General methods /////////////////////////////////////////////////////////////////////// +// General methods +/////////////////////////////////////////////////////////////////////// -B_u1 B_u1G_new(B_atom a, B_int base) { +uint8_t B_u1G_new(B_atom a, B_int base) { // base is optional B_bigint b = B_bigintG_new(a, base); - long sz = b->val.size; - if (sz == 0) return toB_u1(0); unsigned long n = b->val.n[0]; - if (sz != 1 || n > 1) { + int sz = b->val.size; + if (sz > 1 || sz < 0 || (sz==1 && n > 1)) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), "u1(): value %s out of range for type u1",get_str(&b->val)); $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_u1(n); + return (uint8_t)(n*sz); } - + B_NoneType B_u1D___init__(B_u1 self, B_atom a, B_int base){ - self->val = B_u1G_new(a,base)->val; + self->val = B_u1G_new(a,base); return B_None; } @@ -49,21 +66,21 @@ B_u1 B_u1D___deserialize__(B_u1 n, $Serial$state state) { } B_bool B_u1D___bool__(B_u1 n) { - return toB_bool(n->val); + return toB_bool(n->val != 0); } B_str B_u1D___str__(B_u1 n) { - return $FORMAT("%d", n->val); + return $FORMAT("%c", (unsigned char)n->val); } B_str B_u1D___repr__(B_u1 n) { - return $FORMAT("%d", n->val); + return $FORMAT("%c", (unsigned char)n->val); } B_u1 toB_u1(uint8_t i) { B_u1 res = acton_malloc(sizeof(struct B_u1)); res->$class = &B_u1G_methods; - res->val = i; + res->val = U1_NORM(i); return res; } @@ -71,39 +88,39 @@ uint8_t fromB_u1(B_u1 w) { return w->val; } - + // B_IntegralD_u1 ///////////////////////////////////////////////////////////////////////// - + B_u1 B_IntegralD_u1D___add__(B_IntegralD_u1 wit, B_u1 a, B_u1 b) { - return toB_u1((a->val + b->val)%2); -} + return toB_u1(U1_ADD(a->val, b->val)); +} B_u1 B_IntegralD_u1D___zero__(B_IntegralD_u1 wit) { return toB_u1(0); } B_complex B_IntegralD_u1D___complex__(B_IntegralD_u1 wit, B_u1 a) { - return toB_complex((double)a->val); + return toB_complex((double)(a->val)); } B_u1 B_IntegralD_u1D___fromatom__(B_IntegralD_u1 wit, B_atom a) { - return B_u1G_new(a,NULL); + return toB_u1(B_u1G_new(a,NULL)); } B_u1 B_IntegralD_u1D___mul__(B_IntegralD_u1 wit, B_u1 a, B_u1 b) { - return toB_u1((a->val * b->val)); + return toB_u1(U1_MUL(a->val, b->val)); } B_u1 B_IntegralD_u1D___pow__(B_IntegralD_u1 wit, B_u1 a, B_u1 b) { - return toB_u1(u1_pow(a->val,b->val)); + uint8_t aval = a->val; + uint8_t bval = b->val; + return toB_u1(int_pow(aval,bval)); } B_u1 B_IntegralD_u1D___neg__(B_IntegralD_u1 wit, B_u1 a) { - if (a->val > 0L) - $RAISE((B_BaseException)$NEW(B_ValueError,to$str("u1.neg: cannot negate non-zero value in u1"))); - return a; + return toB_u1(U1_NEG(a->val)); } B_u1 B_IntegralD_u1D___pos__(B_IntegralD_u1 wit, B_u1 a) { @@ -111,23 +128,23 @@ B_u1 B_IntegralD_u1D___pos__(B_IntegralD_u1 wit, B_u1 a) { } $WORD B_IntegralD_u1D_real(B_IntegralD_u1 wit, B_u1 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)(a)); } $WORD B_IntegralD_u1D_imag(B_IntegralD_u1 wit, B_u1 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_u1(0)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u1(0LL)); } $WORD B_IntegralD_u1D___abs__(B_IntegralD_u1 wit, B_u1 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u1(a->val)); } B_u1 B_IntegralD_u1D_conjugate(B_IntegralD_u1 wit, B_u1 a) { return a; } -B_float B_IntegralD_u1D___float__ (B_IntegralD_u1 wit, B_u1 n) { - return to$float((double)n->val); +double B_IntegralD_u1D___float__ (B_IntegralD_u1 wit, B_u1 n) { + return (double)n->val; } $WORD B_IntegralD_u1D___trunc__ (B_IntegralD_u1 wit, B_u1 n, B_Integral wit2) { @@ -144,14 +161,14 @@ B_float B_IntegralD_u1D___float__ (B_IntegralD_u1 wit, B_u1 n) { B_u1 B_IntegralD_u1D___round__ (B_IntegralD_u1 wit, B_u1 n, B_int p) { uint8_t nval = n->val; - long pval = p==NULL ? 0 : fromB_int(p); + uint8_t pval = p==NULL ? 0 : fromB_int(p); if (pval>=0) return n; - uint8_t p10 = u1_pow(10,-pval); + uint8_t p10 = int_pow(10,-pval); uint8_t res = nval/p10; if (nval%p10 * 2 > p10) res++; - return toB_u1 (res * p10); // is this what we want? + return toB_u1(res * p10); } $WORD B_IntegralD_u1D_numerator (B_IntegralD_u1 wit, B_u1 n, B_Integral wit2) { @@ -159,74 +176,70 @@ B_u1 B_IntegralD_u1D___round__ (B_IntegralD_u1 wit, B_u1 n, B_int p) { } $WORD B_IntegralD_u1D_denominator (B_IntegralD_u1 wit, B_u1 n, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_u1(1L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u1(1LL)); } -B_int B_IntegralD_u1D___int__ (B_IntegralD_u1 wit, B_u1 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_u1D___int__ (B_IntegralD_u1 wit, B_u1 n) { + return n->val; } -B_int B_IntegralD_u1D___index__(B_IntegralD_u1 wit, B_u1 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_u1D___index__(B_IntegralD_u1 wit, B_u1 n) { + return n->val; } B_tuple B_IntegralD_u1D___divmod__(B_IntegralD_u1 wit, B_u1 a, B_u1 b) { - int n = a->val; - int d = b->val; - return $NEWTUPLE(2, toB_u1(n/d), toB_u1(n%d)); + uint8_t n = a->val; + uint8_t d = b->val; + return $NEWTUPLE(2, toB_u1(U1_FLOORDIV(n, d)), toB_u1(U1_MOD(n, d))); } B_u1 B_IntegralD_u1D___floordiv__(B_IntegralD_u1 wit, B_u1 a, B_u1 b) { - if (b->val == 0) - $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - return toB_u1(a->val / b->val); + return toB_u1(U1_FLOORDIV(a->val, b->val)); } B_u1 B_IntegralD_u1D___mod__(B_IntegralD_u1 wit, B_u1 a, B_u1 b) { - return toB_u1(a->val % b->val); + return toB_u1(U1_MOD(a->val, b->val)); } -B_u1 B_IntegralD_u1D___lshift__(B_IntegralD_u1 wit, B_u1 a, B_int b) { - return toB_u1(a->val << fromB_int(b)); +B_u1 B_IntegralD_u1D___lshift__(B_IntegralD_u1 wit, B_u1 a, int64_t b) { + return toB_u1(U1_LSHIFT(a->val, b)); } -B_u1 B_IntegralD_u1D___rshift__(B_IntegralD_u1 wit, B_u1 a, B_int b) { - return toB_u1(a->val >> fromB_int(b)); +B_u1 B_IntegralD_u1D___rshift__(B_IntegralD_u1 wit, B_u1 a, int64_t b) { + return toB_u1(U1_RSHIFT(a->val, b)); } B_u1 B_IntegralD_u1D___invert__(B_IntegralD_u1 wit, B_u1 a) { - return toB_u1(~a->val); + return toB_u1(U1_INVERT(a->val)); } // B_LogicalD_IntegralD_u1 //////////////////////////////////////////////////////////////////////////////////////// B_u1 B_LogicalD_IntegralD_u1D___and__(B_LogicalD_IntegralD_u1 wit, B_u1 a, B_u1 b) { - return toB_u1(a->val & b->val); + return toB_u1(U1_AND(a->val, b->val)); } B_u1 B_LogicalD_IntegralD_u1D___or__(B_LogicalD_IntegralD_u1 wit, B_u1 a, B_u1 b) { - return toB_u1(a->val | b->val); + return toB_u1(U1_OR(a->val, b->val)); } B_u1 B_LogicalD_IntegralD_u1D___xor__(B_LogicalD_IntegralD_u1 wit, B_u1 a, B_u1 b) { - return toB_u1(a->val ^ b->val); + return toB_u1(U1_XOR(a->val, b->val)); } // B_MinusD_IntegralD_u1 //////////////////////////////////////////////////////////////////////////////////////// B_u1 B_MinusD_IntegralD_u1D___sub__(B_MinusD_IntegralD_u1 wit, B_u1 a, B_u1 b) { - return toB_u1(a->val - b->val); + return toB_u1(U1_SUB(a->val, b->val)); } // B_DivD_u1 //////////////////////////////////////////////////////////////////////////////////////// B_float B_DivD_u1D___truediv__ (B_DivD_u1 wit, B_u1 a, B_u1 b) { - if (b->val == 0) - $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - return to$float((double)a->val/(double)b->val); + return toB_float(U1_DIV(a->val, b->val)); } // B_OrdD_u1 //////////////////////////////////////////////////////////////////////////////////////// @@ -266,6 +279,6 @@ B_bool B_HashableD_u1D___ne__(B_HashableD_u1 wit, B_u1 a, B_u1 b) { } B_NoneType B_HashableD_u1D_hash(B_HashableD_u1 wit, B_u1 a, B_hasher h) { - zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a->val),1)); + zig_hash_wyhash_update(h->_hasher,to$bytesD_len((char *)&(a->val),8)); return B_None; } diff --git a/base/builtin/u1.h b/base/builtin/u1.h index 1892c5deb..3f6fa8137 100644 --- a/base/builtin/u1.h +++ b/base/builtin/u1.h @@ -6,10 +6,10 @@ struct B_u1 { B_u1 toB_u1(uint8_t n); uint8_t fromB_u1(B_u1 n); -B_u1 B_u1G_new(B_atom a, B_int base); +uint8_t B_u1G_new(B_atom a, B_int base); #define u1_DIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u1 truediv: division by zero"))); (double)a;} ) #define u1_FLOORDIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u1 floordiv: division by zero"))); a;} ) -#define u1_MOD(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u1 mod: division by zero"))); a;} ) +#define u1_MOD(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u1 mod: division by zero"))); (a%b)&1;} ) uint8_t u1_pow(uint8_t a, uint8_t b); diff --git a/base/builtin/u16.c b/base/builtin/u16.c index 0b9bc1eae..240d969d4 100644 --- a/base/builtin/u16.c +++ b/base/builtin/u16.c @@ -15,30 +15,30 @@ // Auxiliary ////////////////////////////////////////////////////////////////////////////// // only called with e>=0. -unsigned short u16_pow(unsigned short a, unsigned short e) { +uint16_t u16_pow(uint16_t a, uint16_t e) { if (e == 0) return 1; if (e == 1) return a; - if (e%2 == 0) return u16_pow(a*a,e/2); - return a * u16_pow(a*a,e/2); + if (e%2 == 0) return int_pow(a*a,e/2); + return a * int_pow(a*a,e/2); } -// General methods /////////////////////////////////////////////////////////////////////// +// General methods +/////////////////////////////////////////////////////////////////////// -B_u16 B_u16G_new(B_atom a, B_int base) { +uint16_t B_u16G_new(B_atom a, B_int base) { // base is optional B_bigint b = B_bigintG_new(a, base); - long sz = b->val.size; - if (sz==0) return toB_u16(0); unsigned long n = b->val.n[0]; - if (sz != 1 || n > 0xfffful) { + int sz = b->val.size; + if (sz > 1 || sz < 0 || (sz==1 && n > 0xffff)) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), "u16(): value %s out of range for type u16",get_str(&b->val)); $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } -return toB_u16((unsigned short)n); + return n*sz; } - + B_NoneType B_u16D___init__(B_u16 self, B_atom a, B_int base){ - self->val = B_u16G_new(a,base)->val; + self->val = B_u16G_new(a,base); return B_None; } @@ -55,43 +55,43 @@ B_bool B_u16D___bool__(B_u16 n) { } B_str B_u16D___str__(B_u16 n) { - return $FORMAT("%hu", n->val); + return $FORMAT("%u", (unsigned)n->val); } B_str B_u16D___repr__(B_u16 n) { - return $FORMAT("%hu", n->val); + return $FORMAT("%u", (unsigned)n->val); } -B_u16 toB_u16(unsigned short i) { +B_u16 toB_u16(uint16_t i) { B_u16 res = acton_malloc(sizeof(struct B_u16)); res->$class = &B_u16G_methods; res->val = i; return res; } -unsigned short fromB_u16(B_u16 w) { +uint16_t fromB_u16(B_u16 w) { return w->val; } - + // B_IntegralD_u16 ///////////////////////////////////////////////////////////////////////// - + B_u16 B_IntegralD_u16D___add__(B_IntegralD_u16 wit, B_u16 a, B_u16 b) { - return toB_u16(a->val + b->val); -} + return toB_u16(a->val + b->val); +} B_u16 B_IntegralD_u16D___zero__(B_IntegralD_u16 wit) { return toB_u16(0); } B_complex B_IntegralD_u16D___complex__(B_IntegralD_u16 wit, B_u16 a) { - return toB_complex((double)a->val); + return toB_complex((double)(a->val)); } B_u16 B_IntegralD_u16D___fromatom__(B_IntegralD_u16 wit, B_atom a) { - return B_u16G_new(a,NULL); + return toB_u16(B_u16G_new(a,NULL)); } B_u16 B_IntegralD_u16D___mul__(B_IntegralD_u16 wit, B_u16 a, B_u16 b) { @@ -99,13 +99,13 @@ B_u16 B_IntegralD_u16D___mul__(B_IntegralD_u16 wit, B_u16 a, B_u16 b) { } B_u16 B_IntegralD_u16D___pow__(B_IntegralD_u16 wit, B_u16 a, B_u16 b) { - return toB_u16(u16_pow(a->val,b->val)); + uint16_t aval = a->val; + uint16_t bval = b->val; + return toB_u16(int_pow(aval,bval)); } B_u16 B_IntegralD_u16D___neg__(B_IntegralD_u16 wit, B_u16 a) { - if (a->val > 0L) - $RAISE((B_BaseException)$NEW(B_ValueError,to$str("u16.neg: cannot negate non-zero value in u16"))); - return a; + return toB_u16(-a->val); } B_u16 B_IntegralD_u16D___pos__(B_IntegralD_u16 wit, B_u16 a) { @@ -113,23 +113,23 @@ B_u16 B_IntegralD_u16D___pos__(B_IntegralD_u16 wit, B_u16 a) { } $WORD B_IntegralD_u16D_real(B_IntegralD_u16 wit, B_u16 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)(a)); } $WORD B_IntegralD_u16D_imag(B_IntegralD_u16 wit, B_u16 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_u16(0L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u16(0LL)); } $WORD B_IntegralD_u16D___abs__(B_IntegralD_u16 wit, B_u16 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u16(a->val)); } B_u16 B_IntegralD_u16D_conjugate(B_IntegralD_u16 wit, B_u16 a) { return a; } -B_float B_IntegralD_u16D___float__ (B_IntegralD_u16 wit, B_u16 n) { - return to$float((double)n->val); +double B_IntegralD_u16D___float__ (B_IntegralD_u16 wit, B_u16 n) { + return (double)n->val; } $WORD B_IntegralD_u16D___trunc__ (B_IntegralD_u16 wit, B_u16 n, B_Integral wit2) { @@ -145,15 +145,15 @@ B_float B_IntegralD_u16D___float__ (B_IntegralD_u16 wit, B_u16 n) { } B_u16 B_IntegralD_u16D___round__ (B_IntegralD_u16 wit, B_u16 n, B_int p) { - unsigned short nval = n->val; - short pval = p==NULL ? 0 : fromB_int(p); + uint16_t nval = n->val; + int16_t pval = p==NULL ? 0 : fromB_int(p); if (pval>=0) return n; - unsigned short p10 = u16_pow(10,-pval); - unsigned short res = nval/p10; + uint16_t p10 = int_pow(10,-pval); + uint16_t res = nval/p10; if (nval%p10 * 2 > p10) res++; - return toB_u16 (res * p10); + return toB_u16(res * p10); } $WORD B_IntegralD_u16D_numerator (B_IntegralD_u16 wit, B_u16 n, B_Integral wit2) { @@ -161,20 +161,20 @@ B_u16 B_IntegralD_u16D___round__ (B_IntegralD_u16 wit, B_u16 n, B_int p) { } $WORD B_IntegralD_u16D_denominator (B_IntegralD_u16 wit, B_u16 n, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_u16(1L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u16(1LL)); } -B_int B_IntegralD_u16D___int__ (B_IntegralD_u16 wit, B_u16 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_u16D___int__ (B_IntegralD_u16 wit, B_u16 n) { + return n->val; } -B_int B_IntegralD_u16D___index__(B_IntegralD_u16 wit, B_u16 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_u16D___index__(B_IntegralD_u16 wit, B_u16 n) { + return n->val; } B_tuple B_IntegralD_u16D___divmod__(B_IntegralD_u16 wit, B_u16 a, B_u16 b) { - int n = a->val; - int d = b->val; + uint16_t n = a->val; + uint16_t d = b->val; return $NEWTUPLE(2, toB_u16(n/d), toB_u16(n%d)); } @@ -188,12 +188,12 @@ B_u16 B_IntegralD_u16D___mod__(B_IntegralD_u16 wit, B_u16 a, B_u16 b) { return toB_u16(a->val % b->val); } -B_u16 B_IntegralD_u16D___lshift__(B_IntegralD_u16 wit, B_u16 a, B_int b) { - return toB_u16(a->val << fromB_int(b)); +B_u16 B_IntegralD_u16D___lshift__(B_IntegralD_u16 wit, B_u16 a, int64_t b) { + return toB_u16(a->val << b); } -B_u16 B_IntegralD_u16D___rshift__(B_IntegralD_u16 wit, B_u16 a, B_int b) { - return toB_u16(a->val >> fromB_int(b)); +B_u16 B_IntegralD_u16D___rshift__(B_IntegralD_u16 wit, B_u16 a, int64_t b) { + return toB_u16(a->val >> b); } B_u16 B_IntegralD_u16D___invert__(B_IntegralD_u16 wit, B_u16 a) { @@ -228,7 +228,7 @@ B_u16 B_MinusD_IntegralD_u16D___sub__(B_MinusD_IntegralD_u16 wit, B_u16 a, B_u1 B_float B_DivD_u16D___truediv__ (B_DivD_u16 wit, B_u16 a, B_u16 b) { if (b->val == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - return to$float((double)a->val/(double)b->val); + return toB_float((double)a->val/(double)b->val); } // B_OrdD_u16 //////////////////////////////////////////////////////////////////////////////////////// @@ -268,6 +268,6 @@ B_bool B_HashableD_u16D___ne__(B_HashableD_u16 wit, B_u16 a, B_u16 b) { } B_NoneType B_HashableD_u16D_hash(B_HashableD_u16 wit, B_u16 a, B_hasher h) { - zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a->val),2)); + zig_hash_wyhash_update(h->_hasher,to$bytesD_len((char *)&(a->val),8)); return B_None; } diff --git a/base/builtin/u16.h b/base/builtin/u16.h index 19a3f18fc..1487f2b4c 100644 --- a/base/builtin/u16.h +++ b/base/builtin/u16.h @@ -6,10 +6,10 @@ struct B_u16 { B_u16 toB_u16(unsigned short n); unsigned short fromB_u16(B_u16 n); -B_u16 B_u16G_new(B_atom a, B_int base); +uint16_t B_u16G_new(B_atom a, B_int base); #define u16_DIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u16 truediv: division by zero"))); (double)a/(double)b;} ) #define u16_FLOORDIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u16 floordiv: division by zero"))); a/b;} ) #define u16_MOD(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u16 mod: division by zero"))); a%b;} ) -unsigned short u16_pow(unsigned short a, unsigned short b); +uint16_t u16_pow(uint16_t a, uint16_t b); diff --git a/base/builtin/u32.c b/base/builtin/u32.c index dfc267a98..f3f44998c 100644 --- a/base/builtin/u32.c +++ b/base/builtin/u32.c @@ -15,30 +15,30 @@ // Auxiliary ////////////////////////////////////////////////////////////////////////////// // only called with e>=0. -unsigned int u32_pow(unsigned int a, unsigned int e) { +uint32_t u32_pow(uint32_t a, uint32_t e) { if (e == 0) return 1; if (e == 1) return a; - if (e%2 == 0) return u32_pow(a*a,e/2); - return a * u32_pow(a*a,e/2); + if (e%2 == 0) return int_pow(a*a,e/2); + return a * int_pow(a*a,e/2); } -// General methods /////////////////////////////////////////////////////////////////////// +// General methods +/////////////////////////////////////////////////////////////////////// -B_u32 B_u32G_new(B_atom a, B_int base) { +uint32_t B_u32G_new(B_atom a, B_int base) { // base is optional B_bigint b = B_bigintG_new(a, base); - long sz = b->val.size; - if (sz==0) return toB_u32(0); unsigned long n = b->val.n[0]; - if ((sz != 1 || n > 0xfffffffful)) { + int sz = b->val.size; + if (sz > 1 || sz < 0 || (sz==1 && n > 0xffffffff)) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), "u32(): value %s out of range for type u32",get_str(&b->val)); $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); - } - return toB_u32((unsigned int)n); + } + return n*sz; } - + B_NoneType B_u32D___init__(B_u32 self, B_atom a, B_int base){ - self->val = B_u32G_new(a,base)->val; + self->val = B_u32G_new(a,base); return B_None; } @@ -47,7 +47,7 @@ void B_u32D___serialize__(B_u32 n, $Serial$state state) { } B_u32 B_u32D___deserialize__(B_u32 n, $Serial$state state) { - return toB_u32((int)(uintptr_t)$val_deserialize(state)); + return toB_u32((uint32_t)$val_deserialize(state)); } B_bool B_u32D___bool__(B_u32 n) { @@ -55,43 +55,43 @@ B_bool B_u32D___bool__(B_u32 n) { } B_str B_u32D___str__(B_u32 n) { - return $FORMAT("%u", n->val); + return $FORMAT("%lu", n->val); } B_str B_u32D___repr__(B_u32 n) { - return $FORMAT("%u", n->val); + return $FORMAT("%lu", n->val); } -B_u32 toB_u32(unsigned int i) { +B_u32 toB_u32(uint32_t i) { B_u32 res = acton_malloc(sizeof(struct B_u32)); res->$class = &B_u32G_methods; res->val = i; return res; } -unsigned int fromB_u32(B_u32 w) { +uint32_t fromB_u32(B_u32 w) { return w->val; } - + // B_IntegralD_u32 ///////////////////////////////////////////////////////////////////////// - + B_u32 B_IntegralD_u32D___add__(B_IntegralD_u32 wit, B_u32 a, B_u32 b) { - return toB_u32(a->val + b->val); -} + return toB_u32(a->val + b->val); +} B_u32 B_IntegralD_u32D___zero__(B_IntegralD_u32 wit) { return toB_u32(0); } B_complex B_IntegralD_u32D___complex__(B_IntegralD_u32 wit, B_u32 a) { - return toB_complex((double)a->val); + return toB_complex((double)(a->val)); } B_u32 B_IntegralD_u32D___fromatom__(B_IntegralD_u32 wit, B_atom a) { - return B_u32G_new(a,NULL); + return toB_u32(B_u32G_new(a,NULL)); } B_u32 B_IntegralD_u32D___mul__(B_IntegralD_u32 wit, B_u32 a, B_u32 b) { @@ -99,13 +99,13 @@ B_u32 B_IntegralD_u32D___mul__(B_IntegralD_u32 wit, B_u32 a, B_u32 b) { } B_u32 B_IntegralD_u32D___pow__(B_IntegralD_u32 wit, B_u32 a, B_u32 b) { - return toB_u32(u32_pow(a->val,b->val)); + uint32_t aval = a->val; + uint32_t bval = b->val; + return toB_u32(int_pow(aval,bval)); } B_u32 B_IntegralD_u32D___neg__(B_IntegralD_u32 wit, B_u32 a) { - if (a->val > 0L) - $RAISE((B_BaseException)$NEW(B_ValueError,to$str("u32.neg: cannot negate non-zero value in u32"))); - return a; + return toB_u32(-a->val); } B_u32 B_IntegralD_u32D___pos__(B_IntegralD_u32 wit, B_u32 a) { @@ -113,23 +113,23 @@ B_u32 B_IntegralD_u32D___pos__(B_IntegralD_u32 wit, B_u32 a) { } $WORD B_IntegralD_u32D_real(B_IntegralD_u32 wit, B_u32 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)(a)); } $WORD B_IntegralD_u32D_imag(B_IntegralD_u32 wit, B_u32 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_u32(0L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u32(0LL)); } $WORD B_IntegralD_u32D___abs__(B_IntegralD_u32 wit, B_u32 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u32(a->val)); } B_u32 B_IntegralD_u32D_conjugate(B_IntegralD_u32 wit, B_u32 a) { return a; } -B_float B_IntegralD_u32D___float__ (B_IntegralD_u32 wit, B_u32 n) { - return to$float((double)n->val); +double B_IntegralD_u32D___float__ (B_IntegralD_u32 wit, B_u32 n) { + return (double)n->val; } $WORD B_IntegralD_u32D___trunc__ (B_IntegralD_u32 wit, B_u32 n, B_Integral wit2) { @@ -145,15 +145,15 @@ B_float B_IntegralD_u32D___float__ (B_IntegralD_u32 wit, B_u32 n) { } B_u32 B_IntegralD_u32D___round__ (B_IntegralD_u32 wit, B_u32 n, B_int p) { - unsigned int nval = n->val; - int pval = p==NULL ? 0 : fromB_int(p); + uint32_t nval = n->val; + int32_t pval = p==NULL ? 0 : fromB_int(p); if (pval>=0) return n; - unsigned int p10 = u32_pow(10,-pval); - unsigned int res = nval/p10; + uint32_t p10 = int_pow(10,-pval); + uint32_t res = nval/p10; if (nval%p10 * 2 > p10) res++; - return toB_u32 (res * p10); + return toB_u32(res * p10); } $WORD B_IntegralD_u32D_numerator (B_IntegralD_u32 wit, B_u32 n, B_Integral wit2) { @@ -161,20 +161,20 @@ B_u32 B_IntegralD_u32D___round__ (B_IntegralD_u32 wit, B_u32 n, B_int p) { } $WORD B_IntegralD_u32D_denominator (B_IntegralD_u32 wit, B_u32 n, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_u32(1L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u32(1LL)); } -B_int B_IntegralD_u32D___int__ (B_IntegralD_u32 wit, B_u32 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_u32D___int__ (B_IntegralD_u32 wit, B_u32 n) { + return n->val; } -B_int B_IntegralD_u32D___index__(B_IntegralD_u32 wit, B_u32 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_u32D___index__(B_IntegralD_u32 wit, B_u32 n) { + return n->val; } B_tuple B_IntegralD_u32D___divmod__(B_IntegralD_u32 wit, B_u32 a, B_u32 b) { - int n = a->val; - int d = b->val; + uint32_t n = a->val; + uint32_t d = b->val; return $NEWTUPLE(2, toB_u32(n/d), toB_u32(n%d)); } @@ -188,12 +188,12 @@ B_u32 B_IntegralD_u32D___mod__(B_IntegralD_u32 wit, B_u32 a, B_u32 b) { return toB_u32(a->val % b->val); } -B_u32 B_IntegralD_u32D___lshift__(B_IntegralD_u32 wit, B_u32 a, B_int b) { - return toB_u32(a->val << fromB_int(b)); +B_u32 B_IntegralD_u32D___lshift__(B_IntegralD_u32 wit, B_u32 a, int64_t b) { + return toB_u32(a->val << b); } -B_u32 B_IntegralD_u32D___rshift__(B_IntegralD_u32 wit, B_u32 a, B_int b) { - return toB_u32(a->val >> fromB_int(b)); +B_u32 B_IntegralD_u32D___rshift__(B_IntegralD_u32 wit, B_u32 a, int64_t b) { + return toB_u32(a->val >> b); } B_u32 B_IntegralD_u32D___invert__(B_IntegralD_u32 wit, B_u32 a) { @@ -228,7 +228,7 @@ B_u32 B_MinusD_IntegralD_u32D___sub__(B_MinusD_IntegralD_u32 wit, B_u32 a, B_u3 B_float B_DivD_u32D___truediv__ (B_DivD_u32 wit, B_u32 a, B_u32 b) { if (b->val == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - return to$float((double)a->val/(double)b->val); + return toB_float((double)a->val/(double)b->val); } // B_OrdD_u32 //////////////////////////////////////////////////////////////////////////////////////// @@ -268,6 +268,6 @@ B_bool B_HashableD_u32D___ne__(B_HashableD_u32 wit, B_u32 a, B_u32 b) { } B_NoneType B_HashableD_u32D_hash(B_HashableD_u32 wit, B_u32 a, B_hasher h) { - zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a->val), 4)); + zig_hash_wyhash_update(h->_hasher,to$bytesD_len((char *)&(a->val),8)); return B_None; } diff --git a/base/builtin/u32.h b/base/builtin/u32.h index 5700f6c63..3184f14ba 100644 --- a/base/builtin/u32.h +++ b/base/builtin/u32.h @@ -6,10 +6,10 @@ struct B_u32 { B_u32 toB_u32(unsigned int n); unsigned int fromB_u32(B_u32 n); -B_u32 B_u32G_new(B_atom a, B_int base); +uint32_t B_u32G_new(B_atom a, B_int base); #define u32_DIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u32 truediv: division by zero"))); (double)a/(double)b;} ) #define u32_FLOORDIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u32 floordiv: division by zero"))); a/b;} ) #define u32_MOD(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u32 mod: division by zero"))); a%b;} ) -unsigned int u32_pow(unsigned int a, unsigned int b); +uint32_t u32_pow(uint32_t a, uint32_t b); diff --git a/base/builtin/u64.c b/base/builtin/u64.c index 95118f26c..5aa63ea92 100644 --- a/base/builtin/u64.c +++ b/base/builtin/u64.c @@ -18,27 +18,27 @@ uint64_t u64_pow(uint64_t a, uint64_t e) { if (e == 0) return 1; if (e == 1) return a; - if (e%2 == 0) return u64_pow(a*a,e/2); - return a * u64_pow(a*a,e/2); + if (e%2 == 0) return int_pow(a*a,e/2); + return a * int_pow(a*a,e/2); } -// General methods /////////////////////////////////////////////////////////////////////// +// General methods +/////////////////////////////////////////////////////////////////////// -B_u64 B_u64G_new(B_atom a, B_int base) { +uint64_t B_u64G_new(B_atom a, B_int base) { // base is optional B_bigint b = B_bigintG_new(a, base); - long sz = b->val.size; - if (sz==0) return toB_u64(0); - uint64_t n = b->val.n[0]; - if (sz != 1) { + unsigned long n = b->val.n[0]; + int sz = b->val.size; + if (sz > 1 || sz < 0) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), "u64(): value %s out of range for type u64",get_str(&b->val)); $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_u64(n); + return n*sz; } B_NoneType B_u64D___init__(B_u64 self, B_atom a, B_int base){ - self->val = B_u64G_new(a,base)->val; + self->val = B_u64G_new(a,base); return B_None; } @@ -47,7 +47,7 @@ void B_u64D___serialize__(B_u64 n, $Serial$state state) { } B_u64 B_u64D___deserialize__(B_u64 n, $Serial$state state) { - return toB_u64((long)$val_deserialize(state)); + return toB_u64((uint64_t)(uintptr_t)$val_deserialize(state)); } B_bool B_u64D___bool__(B_u64 n) { @@ -55,11 +55,11 @@ B_bool B_u64D___bool__(B_u64 n) { } B_str B_u64D___str__(B_u64 n) { - return $FORMAT("%llu", n->val); + return $FORMAT("%llu", (unsigned long long)n->val); } B_str B_u64D___repr__(B_u64 n) { - return $FORMAT("%llu", n->val); + return $FORMAT("%llu", (unsigned long long)n->val); } B_u64 toB_u64(uint64_t i) { @@ -73,25 +73,25 @@ uint64_t fromB_u64(B_u64 w) { return w->val; } - + // B_IntegralD_u64 ///////////////////////////////////////////////////////////////////////// - + B_u64 B_IntegralD_u64D___add__(B_IntegralD_u64 wit, B_u64 a, B_u64 b) { - return toB_u64(a->val + b->val); -} + return toB_u64(a->val + b->val); +} B_u64 B_IntegralD_u64D___zero__(B_IntegralD_u64 wit) { return toB_u64(0); } B_complex B_IntegralD_u64D___complex__(B_IntegralD_u64 wit, B_u64 a) { - return toB_complex((double)a->val); + return toB_complex((double)(a->val)); } B_u64 B_IntegralD_u64D___fromatom__(B_IntegralD_u64 wit, B_atom a) { - return B_u64G_new(a,NULL); + return toB_u64(B_u64G_new(a,NULL)); } B_u64 B_IntegralD_u64D___mul__(B_IntegralD_u64 wit, B_u64 a, B_u64 b) { @@ -99,13 +99,13 @@ B_u64 B_IntegralD_u64D___mul__(B_IntegralD_u64 wit, B_u64 a, B_u64 b) { } B_u64 B_IntegralD_u64D___pow__(B_IntegralD_u64 wit, B_u64 a, B_u64 b) { - return toB_u64(u64_pow(a->val,b->val)); + uint64_t aval = a->val; + uint64_t bval = b->val; + return toB_u64(int_pow(aval,bval)); } B_u64 B_IntegralD_u64D___neg__(B_IntegralD_u64 wit, B_u64 a) { - if (a->val > 0L) - $RAISE((B_BaseException)$NEW(B_ValueError,to$str("u64.neg: cannot negate non-zero value in u64"))); - return a; + return toB_u64(-a->val); } B_u64 B_IntegralD_u64D___pos__(B_IntegralD_u64 wit, B_u64 a) { @@ -113,23 +113,23 @@ B_u64 B_IntegralD_u64D___pos__(B_IntegralD_u64 wit, B_u64 a) { } $WORD B_IntegralD_u64D_real(B_IntegralD_u64 wit, B_u64 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)(a)); } $WORD B_IntegralD_u64D_imag(B_IntegralD_u64 wit, B_u64 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_u64(0L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u64(0LL)); } $WORD B_IntegralD_u64D___abs__(B_IntegralD_u64 wit, B_u64 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u64(a->val)); } B_u64 B_IntegralD_u64D_conjugate(B_IntegralD_u64 wit, B_u64 a) { return a; } -B_float B_IntegralD_u64D___float__ (B_IntegralD_u64 wit, B_u64 n) { - return to$float((double)n->val); +double B_IntegralD_u64D___float__ (B_IntegralD_u64 wit, B_u64 n) { + return (double)n->val; } $WORD B_IntegralD_u64D___trunc__ (B_IntegralD_u64 wit, B_u64 n, B_Integral wit2) { @@ -146,14 +146,14 @@ B_float B_IntegralD_u64D___float__ (B_IntegralD_u64 wit, B_u64 n) { B_u64 B_IntegralD_u64D___round__ (B_IntegralD_u64 wit, B_u64 n, B_int p) { uint64_t nval = n->val; - long pval = p==NULL ? 0 : fromB_int(p); + int64_t pval = p==NULL ? 0 : fromB_int(p); if (pval>=0) return n; - uint64_t p10 = u64_pow(10,-pval); + uint64_t p10 = int_pow(10,-pval); uint64_t res = nval/p10; if (nval%p10 * 2 > p10) res++; - return toB_u64 (res * p10); + return toB_u64(res * p10); } $WORD B_IntegralD_u64D_numerator (B_IntegralD_u64 wit, B_u64 n, B_Integral wit2) { @@ -161,24 +161,20 @@ B_u64 B_IntegralD_u64D___round__ (B_IntegralD_u64 wit, B_u64 n, B_int p) { } $WORD B_IntegralD_u64D_denominator (B_IntegralD_u64 wit, B_u64 n, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_u64(1L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u64(1LL)); } -B_int B_IntegralD_u64D___int__ (B_IntegralD_u64 wit, B_u64 n) { - if (n->val > 0x7ffffffffffffffful) - $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("u64 value too large to be converted to int"))); - return toB_int(n->val); +int64_t B_IntegralD_u64D___int__ (B_IntegralD_u64 wit, B_u64 n) { + return n->val; } -B_int B_IntegralD_u64D___index__(B_IntegralD_u64 wit, B_u64 n) { - if (n->val > 0x7ffffffffffffffful) - $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("u64 value too large to be converted to int"))); - return toB_int(n->val); +int64_t B_IntegralD_u64D___index__(B_IntegralD_u64 wit, B_u64 n) { + return n->val; } B_tuple B_IntegralD_u64D___divmod__(B_IntegralD_u64 wit, B_u64 a, B_u64 b) { - int n = a->val; - int d = b->val; + uint64_t n = a->val; + uint64_t d = b->val; return $NEWTUPLE(2, toB_u64(n/d), toB_u64(n%d)); } @@ -192,12 +188,12 @@ B_u64 B_IntegralD_u64D___mod__(B_IntegralD_u64 wit, B_u64 a, B_u64 b) { return toB_u64(a->val % b->val); } -B_u64 B_IntegralD_u64D___lshift__(B_IntegralD_u64 wit, B_u64 a, B_int b) { - return toB_u64(a->val << fromB_int(b)); +B_u64 B_IntegralD_u64D___lshift__(B_IntegralD_u64 wit, B_u64 a, int64_t b) { + return toB_u64(a->val << b); } -B_u64 B_IntegralD_u64D___rshift__(B_IntegralD_u64 wit, B_u64 a, B_int b) { - return toB_u64(a->val >> fromB_int(b)); +B_u64 B_IntegralD_u64D___rshift__(B_IntegralD_u64 wit, B_u64 a, int64_t b) { + return toB_u64(a->val >> b); } B_u64 B_IntegralD_u64D___invert__(B_IntegralD_u64 wit, B_u64 a) { @@ -232,7 +228,7 @@ B_u64 B_MinusD_IntegralD_u64D___sub__(B_MinusD_IntegralD_u64 wit, B_u64 a, B_u6 B_float B_DivD_u64D___truediv__ (B_DivD_u64 wit, B_u64 a, B_u64 b) { if (b->val == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - return to$float((double)a->val/(double)b->val); + return toB_float((double)a->val/(double)b->val); } // B_OrdD_u64 //////////////////////////////////////////////////////////////////////////////////////// @@ -272,6 +268,6 @@ B_bool B_HashableD_u64D___ne__(B_HashableD_u64 wit, B_u64 a, B_u64 b) { } B_NoneType B_HashableD_u64D_hash(B_HashableD_u64 wit, B_u64 a, B_hasher h) { - zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a->val), 8)); + zig_hash_wyhash_update(h->_hasher,to$bytesD_len((char *)&(a->val),8)); return B_None; } diff --git a/base/builtin/u64.h b/base/builtin/u64.h index fd3a69905..2e51cd476 100644 --- a/base/builtin/u64.h +++ b/base/builtin/u64.h @@ -6,7 +6,7 @@ struct B_u64 { B_u64 toB_u64(uint64_t n); uint64_t fromB_u64(B_u64 n); -B_u64 B_u64G_new(B_atom a, B_int base); +uint64_t B_u64G_new(B_atom a, B_int base); #define u64_DIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u64 truediv: division by zero"))); (double)a/(double)b;} ) #define u64_FLOORDIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u64 floordiv: division by zero"))); a/b;} ) diff --git a/base/builtin/u8.c b/base/builtin/u8.c index 4ada8b6b5..dbf5cf43f 100644 --- a/base/builtin/u8.c +++ b/base/builtin/u8.c @@ -18,27 +18,27 @@ uint8_t u8_pow(uint8_t a, uint8_t e) { if (e == 0) return 1; if (e == 1) return a; - if (e%2 == 0) return u8_pow(a*a,e/2); - return a * u8_pow(a*a,e/2); + if (e%2 == 0) return int_pow(a*a,e/2); + return a * int_pow(a*a,e/2); } -// General methods /////////////////////////////////////////////////////////////////////// +// General methods +/////////////////////////////////////////////////////////////////////// -B_u8 B_u8G_new(B_atom a, B_int base) { +uint8_t B_u8G_new(B_atom a, B_int base) { // base is optional B_bigint b = B_bigintG_new(a, base); - long sz = b->val.size; - if (sz == 0) return toB_u8(0); unsigned long n = b->val.n[0]; - if (sz != 1 || n > UCHAR_MAX) { + int sz = b->val.size; + if (sz > 1 || sz < 0 || (sz==1 && n > 0xff)) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), "u8(): value %s out of range for type u8",get_str(&b->val)); $RAISE((B_BaseException)$NEW(B_ValueError,to$str(errmsg))); } - return toB_u8(n); + return n*sz; } - + B_NoneType B_u8D___init__(B_u8 self, B_atom a, B_int base){ - self->val = B_u8G_new(a,base)->val; + self->val = B_u8G_new(a,base); return B_None; } @@ -55,11 +55,11 @@ B_bool B_u8D___bool__(B_u8 n) { } B_str B_u8D___str__(B_u8 n) { - return $FORMAT("%u", n->val); + return $FORMAT("%c",(unsigned char) n->val); } B_str B_u8D___repr__(B_u8 n) { - return $FORMAT("%u", n->val); + return $FORMAT("%c", (unsigned char)n->val); } B_u8 toB_u8(uint8_t i) { @@ -73,25 +73,25 @@ uint8_t fromB_u8(B_u8 w) { return w->val; } - + // B_IntegralD_u8 ///////////////////////////////////////////////////////////////////////// - + B_u8 B_IntegralD_u8D___add__(B_IntegralD_u8 wit, B_u8 a, B_u8 b) { - return toB_u8(a->val + b->val); -} + return toB_u8(a->val + b->val); +} B_u8 B_IntegralD_u8D___zero__(B_IntegralD_u8 wit) { return toB_u8(0); } B_complex B_IntegralD_u8D___complex__(B_IntegralD_u8 wit, B_u8 a) { - return toB_complex((double)a->val); + return toB_complex((double)(a->val)); } B_u8 B_IntegralD_u8D___fromatom__(B_IntegralD_u8 wit, B_atom a) { - return B_u8G_new(a,NULL); + return toB_u8(B_u8G_new(a,NULL)); } B_u8 B_IntegralD_u8D___mul__(B_IntegralD_u8 wit, B_u8 a, B_u8 b) { @@ -99,13 +99,13 @@ B_u8 B_IntegralD_u8D___mul__(B_IntegralD_u8 wit, B_u8 a, B_u8 b) { } B_u8 B_IntegralD_u8D___pow__(B_IntegralD_u8 wit, B_u8 a, B_u8 b) { - return toB_u8(u8_pow(a->val,b->val)); + uint8_t aval = a->val; + uint8_t bval = b->val; + return toB_u8(int_pow(aval,bval)); } B_u8 B_IntegralD_u8D___neg__(B_IntegralD_u8 wit, B_u8 a) { - if (a->val > 0L) - $RAISE((B_BaseException)$NEW(B_ValueError,to$str("u8.neg: cannot negate non-zero value in u8"))); - return a; + return toB_u8(-a->val); } B_u8 B_IntegralD_u8D___pos__(B_IntegralD_u8 wit, B_u8 a) { @@ -113,23 +113,23 @@ B_u8 B_IntegralD_u8D___pos__(B_IntegralD_u8 wit, B_u8 a) { } $WORD B_IntegralD_u8D_real(B_IntegralD_u8 wit, B_u8 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)(a)); } $WORD B_IntegralD_u8D_imag(B_IntegralD_u8 wit, B_u8 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_u8(0L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u8(0LL)); } $WORD B_IntegralD_u8D___abs__(B_IntegralD_u8 wit, B_u8 a, B_Real wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)a); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u8(a->val)); } B_u8 B_IntegralD_u8D_conjugate(B_IntegralD_u8 wit, B_u8 a) { return a; } -B_float B_IntegralD_u8D___float__ (B_IntegralD_u8 wit, B_u8 n) { - return to$float((double)n->val); +double B_IntegralD_u8D___float__ (B_IntegralD_u8 wit, B_u8 n) { + return (double)n->val; } $WORD B_IntegralD_u8D___trunc__ (B_IntegralD_u8 wit, B_u8 n, B_Integral wit2) { @@ -146,14 +146,14 @@ B_float B_IntegralD_u8D___float__ (B_IntegralD_u8 wit, B_u8 n) { B_u8 B_IntegralD_u8D___round__ (B_IntegralD_u8 wit, B_u8 n, B_int p) { uint8_t nval = n->val; - long pval = p==NULL ? 0 : fromB_int(p); + int8_t pval = p==NULL ? 0 : fromB_int(p); if (pval>=0) return n; - uint8_t p10 = u8_pow(10,-pval); + uint8_t p10 = int_pow(10,-pval); uint8_t res = nval/p10; if (nval%p10 * 2 > p10) res++; - return toB_u8 (res * p10); + return toB_u8(res * p10); } $WORD B_IntegralD_u8D_numerator (B_IntegralD_u8 wit, B_u8 n, B_Integral wit2) { @@ -161,20 +161,20 @@ B_u8 B_IntegralD_u8D___round__ (B_IntegralD_u8 wit, B_u8 n, B_int p) { } $WORD B_IntegralD_u8D_denominator (B_IntegralD_u8 wit, B_u8 n, B_Integral wit2) { - return wit2->$class->__fromatom__(wit2,(B_atom)toB_u8(1L)); + return wit2->$class->__fromatom__(wit2,(B_atom)toB_u8(1LL)); } -B_int B_IntegralD_u8D___int__ (B_IntegralD_u8 wit, B_u8 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_u8D___int__ (B_IntegralD_u8 wit, B_u8 n) { + return n->val; } -B_int B_IntegralD_u8D___index__(B_IntegralD_u8 wit, B_u8 n) { - return B_intG_new((B_atom)n,NULL); +int64_t B_IntegralD_u8D___index__(B_IntegralD_u8 wit, B_u8 n) { + return n->val; } B_tuple B_IntegralD_u8D___divmod__(B_IntegralD_u8 wit, B_u8 a, B_u8 b) { - int n = a->val; - int d = b->val; + uint8_t n = a->val; + uint8_t d = b->val; return $NEWTUPLE(2, toB_u8(n/d), toB_u8(n%d)); } @@ -188,12 +188,12 @@ B_u8 B_IntegralD_u8D___mod__(B_IntegralD_u8 wit, B_u8 a, B_u8 b) { return toB_u8(a->val % b->val); } -B_u8 B_IntegralD_u8D___lshift__(B_IntegralD_u8 wit, B_u8 a, B_int b) { - return toB_u8(a->val << fromB_int(b)); +B_u8 B_IntegralD_u8D___lshift__(B_IntegralD_u8 wit, B_u8 a, int64_t b) { + return toB_u8(a->val << b); } -B_u8 B_IntegralD_u8D___rshift__(B_IntegralD_u8 wit, B_u8 a, B_int b) { - return toB_u8(a->val >> fromB_int(b)); +B_u8 B_IntegralD_u8D___rshift__(B_IntegralD_u8 wit, B_u8 a, int64_t b) { + return toB_u8(a->val >> b); } B_u8 B_IntegralD_u8D___invert__(B_IntegralD_u8 wit, B_u8 a) { @@ -228,7 +228,7 @@ B_u8 B_MinusD_IntegralD_u8D___sub__(B_MinusD_IntegralD_u8 wit, B_u8 a, B_u8 b) B_float B_DivD_u8D___truediv__ (B_DivD_u8 wit, B_u8 a, B_u8 b) { if (b->val == 0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError, to$str("division by zero"))); - return to$float((double)a->val/(double)b->val); + return toB_float((double)a->val/(double)b->val); } // B_OrdD_u8 //////////////////////////////////////////////////////////////////////////////////////// @@ -268,6 +268,6 @@ B_bool B_HashableD_u8D___ne__(B_HashableD_u8 wit, B_u8 a, B_u8 b) { } B_NoneType B_HashableD_u8D_hash(B_HashableD_u8 wit, B_u8 a, B_hasher h) { - zig_hash_wyhash_update(h->_hasher, to$bytesD_len((char *)&(a->val),1)); + zig_hash_wyhash_update(h->_hasher,to$bytesD_len((char *)&(a->val),8)); return B_None; } diff --git a/base/builtin/u8.h b/base/builtin/u8.h index 1867e28f7..1a3ce1c36 100644 --- a/base/builtin/u8.h +++ b/base/builtin/u8.h @@ -6,7 +6,7 @@ struct B_u8 { B_u8 toB_u8(uint8_t n); uint8_t fromB_u8(B_u8 n); -B_u8 B_u8G_new(B_atom a, B_int base); +uint8_t B_u8G_new(B_atom a, B_int base); #define u8_DIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u8 truediv: division by zero"))); (double)a/(double)b;} ) #define u8_FLOORDIV(a,b) ( {if (b==0) $RAISE((B_BaseException)$NEW(B_ZeroDivisionError,to$str("u8 floordiv: division by zero"))); a/b;} ) diff --git a/base/builtin/utils.c b/base/builtin/utils.c index 5a8e12505..7df93774d 100644 --- a/base/builtin/utils.c +++ b/base/builtin/utils.c @@ -14,7 +14,7 @@ B_set B_mk_set(int len, B_Hashable w,...) { va_start(args, w); for (int i=0; i < len; i++) { $WORD elem = va_arg(args, $WORD); - B_set_add_entry(res,w,elem,fromB_u64(B_hash(w, elem))); + B_set_add_entry(res,w,elem,B_hash(w, elem)); } return res; } diff --git a/base/rts/rts.c b/base/rts/rts.c index 1ac8d2d4f..899f7eb0d 100644 --- a/base/rts/rts.c +++ b/base/rts/rts.c @@ -1403,7 +1403,7 @@ void BOOTSTRAP(int argc, char *argv[]) { wit->$class->append(wit,args,to$str(argv[i])); env_actor = B_EnvG_newactor(B_WorldCapG_new(), B_SysCapG_new(), args); - env_actor->nr_wthreads = toB_int(num_wthreads); + env_actor->nr_wthreads = num_wthreads; root_actor = $ROOT(); // Assumed to return $NEWACTOR(X) for the selected root actor X time_t now = current_time(); diff --git a/base/src/__builtin__.ext.c b/base/src/__builtin__.ext.c index 353e44773..a3efe62b0 100644 --- a/base/src/__builtin__.ext.c +++ b/base/src/__builtin__.ext.c @@ -14,7 +14,7 @@ void B___ext_init__() { B_HashableD_bytesG_methods.__eq__ = (B_bool (*)(B_HashableD_bytes, B_bytes, B_bytes))B_OrdD_bytesD___eq__; B_HashableD_complexG_methods.__eq__ = (B_bool (*)(B_HashableD_complex, B_complex, B_complex))B_HashableD_complexD___eq__; - B_ContainerD_listG_methods.__len__ = (B_int (*)(B_ContainerD_list, B_list))B_CollectionD_SequenceD_listD___len__; + B_ContainerD_listG_methods.__len__ = (int64_t (*)(B_ContainerD_list, B_list))B_CollectionD_SequenceD_listD___len__; B_ContainerD_listG_methods.__fromiter__ = (B_list (*)(B_ContainerD_list, B_Iterable, $WORD))B_CollectionD_SequenceD_listD___fromiter__; B_ContainerD_listG_methods.__iter__ = (B_Iterator (*)(B_ContainerD_list, B_list))B_CollectionD_SequenceD_listD___iter__; } diff --git a/base/src/acton/rts.ext.c b/base/src/acton/rts.ext.c index 0c2329668..a0a0f57d8 100644 --- a/base/src/acton/rts.ext.c +++ b/base/src/acton/rts.ext.c @@ -50,34 +50,34 @@ B_u64 actonQ_rtsQ_get_heap_size (B_SysCap cap) { return toB_u64(GC_get_heap_size()); } -uint64_t actonQ_rtsQ_U_get_mem_usage (B_SysCap cap) { +uint64_t actonQ_rtsQ_get_mem_usage (B_SysCap cap) { return GC_get_heap_size() - GC_get_free_bytes(); } // def get_gc_total_bytes(cap: SysCap) -> u64: -uint64_t actonQ_rtsQ_U_1get_gc_total_bytes (B_SysCap cap) { +uint64_t actonQ_rtsQ_get_gc_total_bytes (B_SysCap cap) { return GC_get_total_bytes(); } //def get_gc_bytes_since_gc(cap: SysCap) -> u64: -uint64_t actonQ_rtsQ_U_2get_gc_bytes_since_gc (B_SysCap cap) { +uint64_t actonQ_rtsQ_get_gc_bytes_since_gc (B_SysCap cap) { return GC_get_bytes_since_gc(); } // def get_rss(cap: SysCap) -> u64: -uint64_t actonQ_rtsQ_U_3get_rss (B_SysCap cap) { - uint64_t rsm; +uint64_t actonQ_rtsQ_get_rss (B_SysCap cap) { + size_t rsm; int r = uv_resident_set_memory(&rsm); - return rsm; + return (uint64_t)rsm; } -int64_t actonQ_rtsQ_U_6rss (B_SysCap cap) { - int64_t rsm; +int64_t actonQ_rtsQ_rss (B_SysCap cap) { + size_t rsm; int r = uv_resident_set_memory(&rsm); - return rsm; + return (int64_t)rsm; } -B_NoneType actonQ_rtsQ_U_4sleep (B_SysCap cap, double sleep_time) { +B_NoneType actonQ_rtsQ_sleep (B_SysCap cap, double sleep_time) { double st = sleep_time; struct timespec ts; ts.tv_sec = (int)st; @@ -143,7 +143,7 @@ B_dict actonQ_rtsQ__io_handles (B_SysCap cap) { B_dict actonQ_rtsQ_rts_stats (B_SysCap cap) { B_Hashable wit = (B_Hashable)B_HashableD_u64G_witness; B_dict d = $NEW(B_dict, wit, NULL, NULL); - for (int i; i <= num_wthreads; i++) { + for (int i = 0; i <= num_wthreads; i++) { B_tuple stats = $NEWTUPLE(28, to$str("TODO"), // state toB_u64(wt_stats[i].sleeps), @@ -180,6 +180,6 @@ B_dict actonQ_rtsQ_rts_stats (B_SysCap cap) { } $R actonQ_rtsQ_WThreadMonitorD__initG_local (actonQ_rtsQ_WThreadMonitor self, $Cont C_cont) { - set_actor_affinity(fromB_int(self->wthread_id)); + set_actor_affinity((int)self->wthread_id); return $R_CONT(C_cont, B_None); } diff --git a/base/src/crypto/hash/md5.ext.c b/base/src/crypto/hash/md5.ext.c index 54170b870..4172bbf28 100644 --- a/base/src/crypto/hash/md5.ext.c +++ b/base/src/crypto/hash/md5.ext.c @@ -5,15 +5,15 @@ void *zig_crypto_hash_md5_update(void *hasher, B_bytes data); void *zig_crypto_hash_md5_finalize(void *hasher, B_bytes output); B_NoneType cryptoQ_hashQ_md5Q_HasherD__init (cryptoQ_hashQ_md5Q_Hasher self) { - self->_hasher = zig_crypto_hash_md5_init(); + self->_hasher = (uint64_t)(uintptr_t)zig_crypto_hash_md5_init(); return B_None; } B_NoneType cryptoQ_hashQ_md5Q_HasherD_update (cryptoQ_hashQ_md5Q_Hasher self, B_bytes data) { - zig_crypto_hash_md5_update(self->_hasher, data); + zig_crypto_hash_md5_update((void *)(uintptr_t)self->_hasher, data); return B_None; } B_bytes cryptoQ_hashQ_md5Q_HasherD_finalize (cryptoQ_hashQ_md5Q_Hasher self) { B_bytes output = to$bytes("1234567890abcdef"); - zig_crypto_hash_md5_finalize(self->_hasher, output); + zig_crypto_hash_md5_finalize((void *)(uintptr_t)self->_hasher, output); return output; } diff --git a/base/src/file.ext.c b/base/src/file.ext.c index f6de80271..43e16cd7a 100644 --- a/base/src/file.ext.c +++ b/base/src/file.ext.c @@ -22,12 +22,12 @@ void fileQ___ext_init__() { // def is_dir(self) -> bool: B_bool fileQ_FileStatD_is_dir (fileQ_FileStat self) { - return toB_bool(S_ISDIR(fromB_u64(self->mode))); + return toB_bool(S_ISDIR(self->mode)); } // def is_file(self) -> bool: B_bool fileQ_FileStatD_is_file (fileQ_FileStat self) { - return toB_bool(S_ISREG(fromB_u64(self->mode))); + return toB_bool(S_ISREG(self->mode)); } // def is_symlink(self) -> bool: @@ -36,18 +36,18 @@ B_bool fileQ_FileStatD_is_symlink (fileQ_FileStat self) { // TODO: do better return B_False; #else - return toB_bool(S_ISLNK(fromB_u64(self->mode))); + return toB_bool(S_ISLNK(self->mode)); #endif } // def is_block_device(self) -> bool: B_bool fileQ_FileStatD_is_block_device (fileQ_FileStat self) { - return toB_bool(S_ISBLK(fromB_u64(self->mode))); + return toB_bool(S_ISBLK(self->mode)); } // def is_char_device(self) -> bool: B_bool fileQ_FileStatD_is_char_device (fileQ_FileStat self) { - return toB_bool(S_ISCHR(fromB_u64(self->mode))); + return toB_bool(S_ISCHR(self->mode)); } // def is_fifo(self) -> bool: @@ -56,7 +56,7 @@ B_bool fileQ_FileStatD_is_fifo (fileQ_FileStat self) { // TODO: do better return B_False; #else - return toB_bool(S_ISFIFO(fromB_u64(self->mode))); + return toB_bool(S_ISFIFO(self->mode)); #endif } @@ -66,7 +66,7 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { // TODO: do better return B_False; #else - return toB_bool(S_ISSOCK(fromB_u64(self->mode))); + return toB_bool(S_ISSOCK(self->mode)); #endif } @@ -181,7 +181,7 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { } // libuv stores the resolved path in req->path, not in the template buffer. - B_str path = to$str(req->path); + B_str path = to$str((char *)req->path); uv_fs_req_cleanup(req); return $R_CONT(C_cont, path); } @@ -202,7 +202,7 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { } uv_dirent_t ent; while (uv_fs_scandir_next(req, &ent) != UV_EOF) { - wit->$class->append(wit, res, to$str(ent.name)); + wit->$class->append(wit, res, to$str((char *)ent.name)); } uv_fs_req_cleanup(req); return $R_CONT(C_cont, res); @@ -221,22 +221,22 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { } uv_stat_t *stat = (uv_stat_t *)req->ptr; fileQ_FileStat res = fileQ_FileStatG_new(filename, - toB_u64(stat->st_dev), - toB_u64(stat->st_mode), - toB_u64(stat->st_nlink), - toB_u64(stat->st_uid), - toB_u64(stat->st_gid), - toB_u64(stat->st_rdev), - toB_u64(stat->st_ino), - toB_u64(stat->st_size), - toB_u64(stat->st_blksize), - toB_u64(stat->st_blocks), - toB_u64(stat->st_flags), - toB_u64(stat->st_gen), - toB_float(stat->st_atim.tv_sec + stat->st_atim.tv_nsec / 1e9), - toB_float(stat->st_mtim.tv_sec + stat->st_mtim.tv_nsec / 1e9), - toB_float(stat->st_ctim.tv_sec + stat->st_ctim.tv_nsec / 1e9), - toB_float(stat->st_birthtim.tv_sec + stat->st_birthtim.tv_nsec / 1e9) + (uint64_t)stat->st_dev, + (uint64_t)stat->st_mode, + (uint64_t)stat->st_nlink, + (uint64_t)stat->st_uid, + (uint64_t)stat->st_gid, + (uint64_t)stat->st_rdev, + (uint64_t)stat->st_ino, + (uint64_t)stat->st_size, + (uint64_t)stat->st_blksize, + (uint64_t)stat->st_blocks, + (uint64_t)stat->st_flags, + (uint64_t)stat->st_gen, + stat->st_atim.tv_sec + stat->st_atim.tv_nsec / 1e9, + stat->st_mtim.tv_sec + stat->st_mtim.tv_nsec / 1e9, + stat->st_ctim.tv_sec + stat->st_ctim.tv_nsec / 1e9, + stat->st_birthtim.tv_sec + stat->st_birthtim.tv_nsec / 1e9 ); uv_fs_req_cleanup(req); return $R_CONT(C_cont, res); @@ -288,22 +288,22 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { } uv_stat_t *stat = (uv_stat_t *)req->ptr; fileQ_FileStat res = fileQ_FileStatG_new(filename, - toB_u64(stat->st_dev), - toB_u64(stat->st_mode), - toB_u64(stat->st_nlink), - toB_u64(stat->st_uid), - toB_u64(stat->st_gid), - toB_u64(stat->st_rdev), - toB_u64(stat->st_ino), - toB_u64(stat->st_size), - toB_u64(stat->st_blksize), - toB_u64(stat->st_blocks), - toB_u64(stat->st_flags), - toB_u64(stat->st_gen), - toB_float(stat->st_atim.tv_sec + stat->st_atim.tv_nsec / 1e9), - toB_float(stat->st_mtim.tv_sec + stat->st_mtim.tv_nsec / 1e9), - toB_float(stat->st_ctim.tv_sec + stat->st_ctim.tv_nsec / 1e9), - toB_float(stat->st_birthtim.tv_sec + stat->st_birthtim.tv_nsec / 1e9) + (uint64_t)stat->st_dev, + (uint64_t)stat->st_mode, + (uint64_t)stat->st_nlink, + (uint64_t)stat->st_uid, + (uint64_t)stat->st_gid, + (uint64_t)stat->st_rdev, + (uint64_t)stat->st_ino, + (uint64_t)stat->st_size, + (uint64_t)stat->st_blksize, + (uint64_t)stat->st_blocks, + (uint64_t)stat->st_flags, + (uint64_t)stat->st_gen, + stat->st_atim.tv_sec + stat->st_atim.tv_nsec / 1e9, + stat->st_mtim.tv_sec + stat->st_mtim.tv_nsec / 1e9, + stat->st_ctim.tv_sec + stat->st_ctim.tv_nsec / 1e9, + stat->st_birthtim.tv_sec + stat->st_birthtim.tv_nsec / 1e9 ); uv_fs_req_cleanup(req); return $R_CONT(C_cont, res); @@ -346,7 +346,7 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { $RAISE(((B_BaseException)B_OSErrorG_new(to$str(errmsg)))); } - self->_fd = toB_int(r); + self->_fd = r; uv_fs_req_cleanup(req); return $R_CONT(c$cont, B_None); } @@ -355,7 +355,7 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { #if defined(_WIN32) || defined(_WIN64) assert(0 && "fileQ_ReadFileD__lock_fileG_local not implemented on Windows"); #else - int r = flock(fromB_int(self->_fd), LOCK_EX + LOCK_NB); + int r = flock(self->_fd, LOCK_EX + LOCK_NB); if (r < 0) { char errmsg[1024] = "Error locking file: "; uv_strerror_r(r, errmsg + strlen(errmsg), sizeof(errmsg)-strlen(errmsg)); @@ -368,7 +368,7 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { $R fileQ_ReadFileD_closeG_local (fileQ_ReadFile self, $Cont c$cont) { uv_fs_t *req = (uv_fs_t *)acton_malloc(sizeof(uv_fs_t)); - int r = uv_fs_close(get_uv_loop(), req, (uv_file)fromB_int(self->_fd), NULL); + int r = uv_fs_close(get_uv_loop(), req, (uv_file)self->_fd, NULL); if (r < 0) { char errmsg[1024] = "Error closing file: "; uv_strerror_r(r, errmsg + strlen(errmsg), sizeof(errmsg)-strlen(errmsg)); @@ -385,14 +385,14 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { uv_fs_t *req = (uv_fs_t *)acton_malloc(sizeof(uv_fs_t)); char buf[1024] = {0}; uv_buf_t iovec = uv_buf_init(buf, sizeof(buf)); - int r = uv_fs_read(get_uv_loop(), req, (uv_file)fromB_int(self->_fd), &iovec, 1, -1, NULL); + int r = uv_fs_read(get_uv_loop(), req, (uv_file)self->_fd, &iovec, 1, -1, NULL); B_list res = B_listD_new(0); res->length = 0; while (r > 0) { wit->$class->append(wit, res, to$bytesD_len(buf,r)); uv_fs_req_cleanup(req); iovec = uv_buf_init(buf, sizeof(buf)); - r = uv_fs_read(get_uv_loop(), req, (uv_file)fromB_int(self->_fd), &iovec, 1, -1, NULL); + r = uv_fs_read(get_uv_loop(), req, (uv_file)self->_fd, &iovec, 1, -1, NULL); } if (r < 0) { char errmsg[1024] = "Error reading from file: "; @@ -420,7 +420,7 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { $RAISE(((B_BaseException)B_OSErrorG_new(to$str(errmsg)))); } - self->_fd = toB_int(r); + self->_fd = r; uv_fs_req_cleanup(req); return $R_CONT(c$cont, B_None); } @@ -429,7 +429,7 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { #if defined(_WIN32) || defined(_WIN64) assert(0 && "fileQ_ReadFileD__lock_fileG_local not implemented on Windows"); #else - int r = flock(fromB_int(self->_fd), LOCK_EX + LOCK_NB); + int r = flock(self->_fd, LOCK_EX + LOCK_NB); if (r < 0) { char errmsg[1024] = "Error locking file: "; uv_strerror_r(r, errmsg + strlen(errmsg), sizeof(errmsg)-strlen(errmsg)); @@ -443,7 +443,7 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { $R fileQ_WriteFileD_closeG_local (fileQ_WriteFile self, $Cont c$cont) { uv_fs_t *req = (uv_fs_t *)acton_malloc(sizeof(uv_fs_t)); - int r = uv_fs_close(get_uv_loop(), req, (uv_file)fromB_int(self->_fd), NULL); + int r = uv_fs_close(get_uv_loop(), req, (uv_file)self->_fd, NULL); if (r < 0) { char errmsg[1024] = "Error closing file: "; uv_strerror_r(r, errmsg + strlen(errmsg), sizeof(errmsg)-strlen(errmsg)); @@ -459,7 +459,7 @@ B_bool fileQ_FileStatD_is_socket (fileQ_FileStat self) { uv_fs_t *req = (uv_fs_t *)acton_malloc(sizeof(uv_fs_t)); uv_buf_t buf = uv_buf_init((char *)data->str, data->nbytes); - int r = uv_fs_write(get_uv_loop(), req, (uv_file)fromB_int(self->_fd), &buf, 1, 0, NULL); + int r = uv_fs_write(get_uv_loop(), req, (uv_file)self->_fd, &buf, 1, 0, NULL); if (r < 0) { char errmsg[1024] = "Error writing to file: "; uv_strerror_r(r, errmsg + strlen(errmsg), sizeof(errmsg)-strlen(errmsg)); diff --git a/base/src/hash/wyhash.ext.c b/base/src/hash/wyhash.ext.c index 102688333..1d293003f 100644 --- a/base/src/hash/wyhash.ext.c +++ b/base/src/hash/wyhash.ext.c @@ -5,23 +5,21 @@ void zig_hash_wyhash_update(void *hasher, B_bytes data); uint64_t zig_hash_wyhash_final(void *hasher); uint64_t zig_hash_wyhash_hash(uint64_t seed, B_bytes data); -B_NoneType hashQ_wyhashQ_HasherD__init (hashQ_wyhashQ_Hasher self, B_u64 seed) { - self->_hasher = zig_hash_wyhash_init(fromB_u64(seed)); +B_NoneType hashQ_wyhashQ_HasherD__init (hashQ_wyhashQ_Hasher self, uint64_t seed) { + self->_hasher = (uint64_t)(uintptr_t)zig_hash_wyhash_init(seed); return B_None; } B_NoneType hashQ_wyhashQ_HasherD_update (hashQ_wyhashQ_Hasher self, B_bytes data) { - zig_hash_wyhash_update(self->_hasher, data); + zig_hash_wyhash_update((void *)(uintptr_t)self->_hasher, data); return B_None; } -B_u64 hashQ_wyhashQ_HasherD_finalize (hashQ_wyhashQ_Hasher self) { - uint64_t h = zig_hash_wyhash_final(self->_hasher); - B_u64 result = toB_u64(h); - return result; +uint64_t hashQ_wyhashQ_HasherD_finalize (hashQ_wyhashQ_Hasher self) { + return zig_hash_wyhash_final((void *)(uintptr_t)self->_hasher); } -uint64_t hashQ_wyhashQ_U_1hash (uint64_t seed, B_bytes data) { +uint64_t hashQ_wyhashQ_hash (uint64_t seed, B_bytes data) { uint64_t result = zig_hash_wyhash_hash(seed, data); return result; } diff --git a/base/src/logging.ext.c b/base/src/logging.ext.c index 0a8fad75f..0c7f7d3fc 100644 --- a/base/src/logging.ext.c +++ b/base/src/logging.ext.c @@ -1,9 +1,9 @@ void loggingQ___ext_init__() {} -B_int loggingQ_MessageD__get_actor_id (loggingQ_Message self) { +int64_t loggingQ_MessageD__get_actor_id (loggingQ_Message self) { $Actor actor_self = GET_SELF(); - return toB_int(actor_self->$globkey); + return actor_self->$globkey; } B_str loggingQ_MessageD__get_actor_class (loggingQ_Message self) { diff --git a/base/src/math.act b/base/src/math.act index 76520dc84..1d3cf0cb1 100644 --- a/base/src/math.act +++ b/base/src/math.act @@ -11,70 +11,36 @@ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # -pi = 3.141592653589793 +pi: float = 3.141592653589793 -protocol RealFuns: - @staticmethod - sqrt : (Self) -> Self - @staticmethod - exp : (Self) -> Self - @staticmethod - log : (Self) -> Self - @staticmethod - sin : (Self) -> Self - @staticmethod - cos : (Self) -> Self - @staticmethod - tan : (Self) -> Self - @staticmethod - asin : (Self) -> Self - @staticmethod - acos : (Self) -> Self - @staticmethod - atan : (Self) -> Self - @staticmethod - sinh : (Self) -> Self - @staticmethod - cosh : (Self) -> Self - @staticmethod - tanh : (Self) -> Self - @staticmethod - asinh : (Self) -> Self - @staticmethod - acosh : (Self) -> Self - @staticmethod - atanh : (Self) -> Self -extension float (RealFuns): - NotImplemented - -def sqrt(x: float): - return RealFuns.sqrt(x) -def exp(x: float): - return RealFuns.exp(x) -def log(x: float): - return RealFuns.log(x) -def sin(x: float): - return RealFuns.sin(x) -def cos(x: float): - return RealFuns.cos(x) -def tan(x: float): - return RealFuns.tan(x) -def asin(x: float): - return RealFuns.asin(x) -def acos(x: float): - return RealFuns.acos(x) -def atan(x: float): - return RealFuns.atan(x) -def sinh(x: float): - return RealFuns.sinh(x) -def cosh(x: float): - return RealFuns.cosh(x) -def tanh(x: float): - return RealFuns.tanh(x) -def asinh(x: float): - return RealFuns.asinh(x) -def acosh(x: float): - return RealFuns.acosh(x) -def atanh(x: float): - return RealFuns.atanh(x) +def sqrt(x: float)->float: + NotImplemented +def exp(x: float)->float: + NotImplemented +def log(x: float)->float: + NotImplemented +def sin(x: float)->float: + NotImplemented +def cos(x: float)->float: + NotImplemented +def tan(x: float)->float: + NotImplemented +def asin(x: float)->float: + NotImplemented +def acos(x: float)->float: + NotImplemented +def atan(x: float)->float: + NotImplemented +def sinh(x: float)->float: + NotImplemented +def cosh(x: float)->float: + NotImplemented +def tanh(x: float)->float: + NotImplemented +def asinh(x: float)->float: + NotImplemented +def acosh(x: float)->float: + NotImplemented +def atanh(x: float)->float: + NotImplemented diff --git a/base/src/math.ext.c b/base/src/math.ext.c index 5dcf2faec..24bc51e8a 100644 --- a/base/src/math.ext.c +++ b/base/src/math.ext.c @@ -1,47 +1,47 @@ -B_float mathQ_RealFunsD_floatD_sqrt(mathQ_RealFunsD_float wit, B_float x) { - return to$float(sqrt(x->val)); +double mathQ_sqrt(double x) { + return sqrt(x); } -B_float mathQ_RealFunsD_floatD_exp(mathQ_RealFunsD_float wit, B_float x) { - return to$float(exp(x->val)); +double mathQ_exp(double x) { + return exp(x); } -B_float mathQ_RealFunsD_floatD_log(mathQ_RealFunsD_float wit, B_float x) { - return to$float(log(x->val)); +double mathQ_log(double x) { + return log(x); } -B_float mathQ_RealFunsD_floatD_sin(mathQ_RealFunsD_float wit, B_float x) { - return to$float(sin(x->val)); +double mathQ_sin(double x) { + return sin(x); } -B_float mathQ_RealFunsD_floatD_cos(mathQ_RealFunsD_float wit, B_float x) { - return to$float(cos(x->val)); +double mathQ_cos(double x) { + return cos(x); } -B_float mathQ_RealFunsD_floatD_tan(mathQ_RealFunsD_float wit, B_float x) { - return to$float(tan(x->val)); +double mathQ_tan(double x) { + return tan(x); } -B_float mathQ_RealFunsD_floatD_asin(mathQ_RealFunsD_float wit, B_float x) { - return to$float(asin(x->val)); +double mathQ_asin(double x) { + return asin(x); } -B_float mathQ_RealFunsD_floatD_acos(mathQ_RealFunsD_float wit, B_float x) { - return to$float(acos(x->val)); +double mathQ_acos(double x) { + return acos(x); } -B_float mathQ_RealFunsD_floatD_atan(mathQ_RealFunsD_float wit, B_float x) { - return to$float(atan(x->val)); +double mathQ_atan(double x) { + return atan(x); } -B_float mathQ_RealFunsD_floatD_sinh(mathQ_RealFunsD_float wit, B_float x) { - return to$float(sinh(x->val)); +double mathQ_sinh(double x) { + return sinh(x); } -B_float mathQ_RealFunsD_floatD_cosh(mathQ_RealFunsD_float wit, B_float x) { - return to$float(cosh(x->val)); +double mathQ_cosh(double x) { + return cosh(x); } -B_float mathQ_RealFunsD_floatD_tanh(mathQ_RealFunsD_float wit, B_float x) { - return to$float(tanh(x->val)); +double mathQ_tanh(double x) { + return tanh(x); } -B_float mathQ_RealFunsD_floatD_asinh(mathQ_RealFunsD_float wit, B_float x) { - return to$float(asinh(x->val)); +double mathQ_asinh(double x) { + return asinh(x); } -B_float mathQ_RealFunsD_floatD_acosh(mathQ_RealFunsD_float wit, B_float x) { - return to$float(acosh(x->val)); +double mathQ_acosh(double x) { + return acosh(x); } -B_float mathQ_RealFunsD_floatD_atanh(mathQ_RealFunsD_float wit, B_float x) { - return to$float(atanh(x->val)); +double mathQ_atanh(double x) { + return atanh(x); } void mathQ___ext_init__() { diff --git a/base/src/net.ext.c b/base/src/net.ext.c index 95146de67..3e0b793d7 100644 --- a/base/src/net.ext.c +++ b/base/src/net.ext.c @@ -182,9 +182,9 @@ void netQ_TCPConnection__on_receive(uv_stream_t *stream, ssize_t nread, const uv netQ_TCPConnection self = stream->data; if ((intptr_t)stream != -1) uv_close((uv_handle_t *)stream, NULL); - self->_sock = toB_int(-1); - self->_sock4 = toB_int(-1); - self->_sock6 = toB_int(-1); + self->_sock = -1LL; + self->_sock4 = -1LL; + self->_sock6 = -1LL; if (self->on_remote_close) { $action f = ($action)self->on_remote_close; f->$class->__asyn__(f, self); @@ -195,7 +195,7 @@ void netQ_TCPConnection__on_receive(uv_stream_t *stream, ssize_t nread, const uv netQ_TCPConnection self = stream->data; $action2 f = ($action2)self->on_receive; f->$class->__asyn__(f, self, to$bytesD_len(buf->base, nread)); - self->_bytes_in->val += nread; + self->_bytes_in += nread; } } } @@ -213,7 +213,7 @@ void on_connect4(uv_connect_t *connect_req, int status) { char errmsg[1024] = "Error in TCP connect over IPv4: "; uv_strerror_r(status, errmsg + strlen(errmsg), sizeof(errmsg)-strlen(errmsg)); log_warn(errmsg); - self->$class->_on_tcp_error(self, toB_int(4), toB_int(status), to$str(errmsg)); + self->$class->_on_tcp_error(self, 4LL, (int64_t)status, to$str(errmsg)); return; } self->$class->_on_connect4(self); @@ -226,7 +226,7 @@ void on_connect6(uv_connect_t *connect_req, int status) { char errmsg[1024] = "Error in TCP connect over IPv6: "; uv_strerror_r(status, errmsg + strlen(errmsg), sizeof(errmsg)-strlen(errmsg)); log_warn(errmsg); - self->$class->_on_tcp_error(self, toB_int(6), toB_int(status), to$str(errmsg)); + self->$class->_on_tcp_error(self, 6LL, (int64_t)status, to$str(errmsg)); return; } self->$class->_on_connect6(self); @@ -236,13 +236,13 @@ void on_connect6(uv_connect_t *connect_req, int status) { log_debug("TCP connecting over IPv4 to %s", fromB_str(ip_address)); uv_tcp_t* socket = (uv_tcp_t*)acton_malloc(sizeof(uv_tcp_t)); uv_tcp_init(get_uv_loop(), socket); - self->_sock4 = toB_int((int64_t)(intptr_t)socket); + self->_sock4 = (int64_t)(intptr_t)socket; uv_connect_t* connect_req = (uv_connect_t*)acton_malloc(sizeof(uv_connect_t)); connect_req->data = (void *)self; struct sockaddr_in dest; - uv_ip4_addr((const char *)fromB_str(ip_address), fromB_int(self->port), &dest); + uv_ip4_addr((const char *)fromB_str(ip_address), (int)self->port, &dest); uv_tcp_connect(connect_req, socket, (const struct sockaddr*)&dest, on_connect4); @@ -253,13 +253,13 @@ void on_connect6(uv_connect_t *connect_req, int status) { log_debug("TCP connecting over IPv6 to %s", fromB_str(ip_address)); uv_tcp_t* socket = (uv_tcp_t*)acton_malloc(sizeof(uv_tcp_t)); uv_tcp_init(get_uv_loop(), socket); - self->_sock6 = toB_int((int64_t)(intptr_t)socket); + self->_sock6 = (int64_t)(intptr_t)socket; uv_connect_t* connect_req = (uv_connect_t*)acton_malloc(sizeof(uv_connect_t)); connect_req->data = (void *)self; struct sockaddr_in6 dest; - uv_ip6_addr((const char *)fromB_str(ip_address), fromB_int(self->port), &dest); + uv_ip6_addr((const char *)fromB_str(ip_address), (int)self->port, &dest); uv_tcp_connect(connect_req, socket, (const struct sockaddr*)&dest, on_connect6); @@ -267,7 +267,7 @@ void on_connect6(uv_connect_t *connect_req, int status) { } $R netQ_TCPConnectionD__read_startG_local (netQ_TCPConnection self, $Cont c$cont) { - uv_tcp_t* socket = (uv_tcp_t *)fromB_int(self->_sock); + uv_tcp_t* socket = (uv_tcp_t *)(intptr_t)self->_sock; socket->data = self; int r = uv_read_start((uv_stream_t *)socket, alloc_buffer, netQ_TCPConnection__on_receive); if (r < 0) { @@ -283,7 +283,7 @@ void on_connect6(uv_connect_t *connect_req, int status) { } $R netQ_TCPConnectionD_writeG_local (netQ_TCPConnection self, $Cont c$cont, B_bytes data) { - uv_stream_t *stream = (uv_stream_t *)fromB_int(self->_sock); + uv_stream_t *stream = (uv_stream_t *)(intptr_t)self->_sock; // fd == -1 means invalid FD and can happen after __resume__ if ((intptr_t)stream == -1) return $R_CONT(c$cont, B_None); @@ -298,14 +298,14 @@ void on_connect6(uv_connect_t *connect_req, int status) { $action2 f = ($action2)self->on_error; f->$class->__asyn__(f, self, to$str(errmsg)); } - self->_bytes_out->val += data->nbytes; + self->_bytes_out += data->nbytes; return $R_CONT(c$cont, B_None); } B_NoneType netQ_TCPConnectionD___resume__ (netQ_TCPConnection self) { - self->_sock = toB_int(-1); - self->_sock4 = toB_int(-1); - self->_sock6 = toB_int(-1); + self->_sock = -1LL; + self->_sock4 = -1LL; + self->_sock6 = -1LL; $action2 f = ($action2)self->on_error; f->$class->__asyn__(f, self, to$str("resume")); return B_None; @@ -327,7 +327,7 @@ static void after_shutdown(uv_shutdown_t* req, int status) { } $R netQ_TCPConnectionD_closeG_local (netQ_TCPConnection self, $Cont c$cont, $action on_close) { - uv_stream_t *stream = (uv_stream_t *)fromB_int(self->_sock); + uv_stream_t *stream = (uv_stream_t *)(intptr_t)self->_sock; // fd == -1 means invalid FD and can happen after __resume__ if ((intptr_t)stream == -1) { on_close->$class->__asyn__(on_close, self); @@ -341,9 +341,9 @@ static void after_shutdown(uv_shutdown_t* req, int status) { uv_shutdown_t *req = (uv_shutdown_t *)acton_malloc(sizeof(uv_shutdown_t)); req->data = (void *)cb_data; int r = uv_shutdown(req, stream, after_shutdown); - self->_sock = toB_int(-1); - self->_sock4 = toB_int(-1); - self->_sock6 = toB_int(-1); + self->_sock = -1LL; + self->_sock4 = -1LL; + self->_sock6 = -1LL; if (r < 0) { // TODO: we could probably ignore most or all of these errors as the // purpose is to shutdown our side of the connection and many of these @@ -362,7 +362,7 @@ static void after_shutdown(uv_shutdown_t* req, int status) { $R netQ_TCPConnectionD_ip_versionG_local (netQ_TCPConnection self, $Cont c$cont) { struct sockaddr_storage peername; int namelen = sizeof(peername); - if (uv_tcp_getpeername((const uv_tcp_t *)fromB_int(self->_sock), (struct sockaddr*)&peername, &namelen) == 0) { + if (uv_tcp_getpeername((const uv_tcp_t *)(intptr_t)self->_sock, (struct sockaddr*)&peername, &namelen) == 0) { if (peername.ss_family == AF_INET) { return $R_CONT(c$cont, toB_int(4)); } else if (peername.ss_family == AF_INET6) { @@ -371,7 +371,7 @@ static void after_shutdown(uv_shutdown_t* req, int status) { log_error("Unhandled AFI"); } } else { - log_error("Failed to get peer name from handle %d", fromB_int(self->_sock)); + log_error("Failed to get peer name from handle %lld", (long long)self->_sock); } return $R_CONT(c$cont, B_None); } @@ -380,7 +380,7 @@ static void after_shutdown(uv_shutdown_t* req, int status) { struct sockaddr_storage sockname; int namelen = sizeof(sockname); char addr[INET6_ADDRSTRLEN] = { '\0' }; - if (uv_tcp_getsockname((const uv_tcp_t *)fromB_int(self->_sock), (struct sockaddr*)&sockname, &namelen) == 0) { + if (uv_tcp_getsockname((const uv_tcp_t *)(intptr_t)self->_sock, (struct sockaddr*)&sockname, &namelen) == 0) { if (sockname.ss_family == AF_INET) { uv_ip4_name((struct sockaddr_in*)&sockname, addr, sizeof(addr)); } else if (sockname.ss_family == AF_INET6) { @@ -389,7 +389,7 @@ static void after_shutdown(uv_shutdown_t* req, int status) { log_error("Unhandled AFI"); } } else { - log_error("Failed to get sock name from handle %d", fromB_int(self->_sock)); + log_error("Failed to get sock name from handle %lld", (long long)self->_sock); } return $R_CONT(c$cont, to$str(addr)); } @@ -398,7 +398,7 @@ static void after_shutdown(uv_shutdown_t* req, int status) { struct sockaddr_storage peername; int namelen = sizeof(peername); char addr[INET6_ADDRSTRLEN] = { '\0' }; - if (uv_tcp_getpeername((const uv_tcp_t *)fromB_int(self->_sock), (struct sockaddr*)&peername, &namelen) == 0) { + if (uv_tcp_getpeername((const uv_tcp_t *)(intptr_t)self->_sock, (struct sockaddr*)&peername, &namelen) == 0) { if (peername.ss_family == AF_INET) { uv_ip4_name((struct sockaddr_in*)&peername, addr, sizeof(addr)); } else if (peername.ss_family == AF_INET6) { @@ -407,7 +407,7 @@ static void after_shutdown(uv_shutdown_t* req, int status) { log_error("Unhandled AFI"); } } else { - log_error("Failed to get peer name from handle %d", fromB_int(self->_sock)); + log_error("Failed to get peer name from handle %lld", (long long)self->_sock); } return $R_CONT(c$cont, to$str(addr)); } @@ -439,7 +439,7 @@ void on_new_connection(uv_stream_t *server, int status) { return; } - self->$class->create_tcp_listen_connection(self, B_None, toB_int((int64_t)(intptr_t)client)); + self->$class->create_tcp_listen_connection(self, B_None, (int64_t)(intptr_t)client); // NOTE: free() here if do manual memory management in I/O one day } @@ -454,9 +454,9 @@ void on_new_connection(uv_stream_t *server, int status) { struct sockaddr_in addr4; struct sockaddr_in6 addr6; if (inet_pton(AF_INET, (const char *)fromB_str(self->address), &(addr4.sin_addr)) == 1) { - r = uv_ip4_addr((const char *)fromB_str(self->address), fromB_int(self->port), &addr4); + r = uv_ip4_addr((const char *)fromB_str(self->address), (int)self->port, &addr4); } else if (inet_pton(AF_INET6, (const char *)fromB_str(self->address), &(addr6.sin6_addr)) == 1) { - r = uv_ip6_addr((const char *)fromB_str(self->address), fromB_int(self->port), &addr6); + r = uv_ip6_addr((const char *)fromB_str(self->address), (int)self->port, &addr6); } else { B_str errmsg = $FORMAT("Address is not an IPv4 or IPv6 address: %s", fromB_str(self->address)); log_warn((const char *)fromB_str(errmsg)); @@ -507,7 +507,7 @@ void on_new_connection(uv_stream_t *server, int status) { } B_NoneType netQ_TCPListenerD___resume__ (netQ_TCPListener self) { - self->_stream = toB_int(-1); + self->_stream = -1LL; $action2 f = ($action2)self->on_listen; f->$class->__asyn__(f, self, to$str("resume")); return B_None; @@ -516,13 +516,13 @@ B_NoneType netQ_TCPListenerD___resume__ (netQ_TCPListener self) { $R netQ_TCPListenConnectionD__initG_local (netQ_TCPListenConnection self, $Cont c$cont) { pin_actor_affinity(); - uv_stream_t *client = (uv_stream_t *)fromB_int(self->server_client); + uv_stream_t *client = (uv_stream_t *)(intptr_t)self->server_client; uv_os_fd_t fd; uv_fileno((uv_handle_t *)client, &fd); uv_tcp_t* client_handle = (uv_tcp_t*)acton_malloc(sizeof(uv_tcp_t)); uv_tcp_init(get_uv_loop(), client_handle); uv_tcp_open(client_handle, (uv_os_sock_t)fd); - self->client = toB_int((int64_t)(intptr_t)client_handle); + self->client = (int64_t)(intptr_t)client_handle; return $R_CONT(c$cont, B_None); } @@ -533,7 +533,7 @@ void netQ_TCPListenConnection__on_receive(uv_stream_t *stream, ssize_t nread, co netQ_TCPListenConnection self = stream->data; if ((intptr_t)stream != -1) uv_close((uv_handle_t *)stream, NULL); - self->client = toB_int(-1); + self->client = -1LL; if (self->on_remote_close) { $action f = ($action)self->on_remote_close; f->$class->__asyn__(f, self); @@ -553,7 +553,7 @@ void netQ_TCPListenConnection__on_receive(uv_stream_t *stream, ssize_t nread, co } $R netQ_TCPListenConnectionD__read_startG_local (netQ_TCPListenConnection self, $Cont c$cont) { - uv_stream_t *client = (uv_stream_t *)fromB_int(self->client); + uv_stream_t *client = (uv_stream_t *)(intptr_t)self->client; client->data = self; int r = uv_read_start(client, alloc_buffer, netQ_TCPListenConnection__on_receive); if (r < 0) { @@ -569,7 +569,7 @@ void netQ_TCPListenConnection__on_receive(uv_stream_t *stream, ssize_t nread, co } $R netQ_TCPListenConnectionD_writeG_local (netQ_TCPListenConnection self, $Cont c$cont, B_bytes data) { - uv_stream_t *stream = (uv_stream_t *)fromB_int(self->client); + uv_stream_t *stream = (uv_stream_t *)(intptr_t)self->client; // fd == -1 means invalid FD and can happen after __resume__ if ((intptr_t)stream == -1) return $R_CONT(c$cont, B_None); @@ -589,7 +589,7 @@ void netQ_TCPListenConnection__on_receive(uv_stream_t *stream, ssize_t nread, co $R netQ_TCPListenConnectionD_closeG_local (netQ_TCPListenConnection self, $Cont c$cont) { log_debug("Closing TCP connection, affinity=%d", self->$affinity); - uv_stream_t *client = (uv_stream_t *)fromB_int(self->client); + uv_stream_t *client = (uv_stream_t *)(intptr_t)self->client; // fd == -1 means invalid FD and can happen after __resume__ or if the socket was closed if ((intptr_t)client == -1) return $R_CONT(c$cont, B_None); @@ -599,13 +599,13 @@ void netQ_TCPListenConnection__on_receive(uv_stream_t *stream, ssize_t nread, co if (uv_is_closing((uv_handle_t *)client) == 0) { uv_close((uv_handle_t *)client, NULL); } - self->client = toB_int(-1); + self->client = -1LL; return $R_CONT(c$cont, B_None); } B_NoneType netQ_TCPListenConnectionD___resume__ (netQ_TCPListenConnection self) { - self->server_client = toB_int(-1); - self->client = toB_int(-1); + self->server_client = -1LL; + self->client = -1LL; return B_None; } @@ -637,7 +637,7 @@ static void tls_listener_on_connect(uv_connect_t *creq, int status) { return; } - listener->$class->create_tls_listen_connection(listener, B_None, toB_int((int64_t)(intptr_t)stream)); + listener->$class->create_tls_listen_connection(listener, B_None, (int64_t)(intptr_t)stream); } static void tls_listener_on_receive(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { @@ -651,7 +651,7 @@ static void tls_listener_on_receive(uv_stream_t *stream, ssize_t nread, const uv } else if (nread == UV_EOF) { log_debug("TLS listen connection closed %p", stream); tls_listener_close_stream((tlsuv_stream_t *)stream); - self->_stream = toB_int(-1); + self->_stream = -1LL; if (self->on_remote_close) { $action f = ($action)self->on_remote_close; f->$class->__asyn__(f, self); @@ -660,7 +660,7 @@ static void tls_listener_on_receive(uv_stream_t *stream, ssize_t nread, const uv log_debug("TLS listen read error %ld: %s", nread, uv_strerror((int)nread)); tls_listener_close_stream((tlsuv_stream_t *)stream); if (stream->data) { - self->_stream = toB_int(-1); + self->_stream = -1LL; } } } @@ -751,7 +751,7 @@ static void on_new_tls_connection(uv_stream_t *server, int status) { uv_os_sock_t sock = (uv_os_sock_t)dup_fd; #endif - tls_context *tls = (tls_context *)fromB_int(self->_tls_ctx); + tls_context *tls = (tls_context *)(intptr_t)self->_tls_ctx; tlsuv_stream_t *stream = (tlsuv_stream_t *)acton_malloc(sizeof(tlsuv_stream_t)); tlsuv_stream_init(get_uv_loop(), stream, tls); tlsuv_stream_set_server(stream, 1); @@ -815,7 +815,7 @@ static void on_new_tls_connection(uv_stream_t *server, int status) { return $R_CONT(c$cont, B_None); } - self->_tls_ctx = toB_int((int64_t)(intptr_t)tls); + self->_tls_ctx = (int64_t)(intptr_t)tls; uv_tcp_t *server = (uv_tcp_t *)acton_malloc(sizeof(uv_tcp_t)); uv_tcp_init(get_uv_loop(), server); @@ -824,9 +824,9 @@ static void on_new_tls_connection(uv_stream_t *server, int status) { struct sockaddr_in addr4; struct sockaddr_in6 addr6; if (inet_pton(AF_INET, (const char *)fromB_str(self->address), &(addr4.sin_addr)) == 1) { - r = uv_ip4_addr((const char *)fromB_str(self->address), fromB_int(self->port), &addr4); + r = uv_ip4_addr((const char *)fromB_str(self->address), (int)self->port, &addr4); } else if (inet_pton(AF_INET6, (const char *)fromB_str(self->address), &(addr6.sin6_addr)) == 1) { - r = uv_ip6_addr((const char *)fromB_str(self->address), fromB_int(self->port), &addr6); + r = uv_ip6_addr((const char *)fromB_str(self->address), (int)self->port, &addr6); } else { B_str errmsg = $FORMAT("Address is not an IPv4 or IPv6 address: %s", fromB_str(self->address)); log_warn((const char *)fromB_str(errmsg)); @@ -867,15 +867,15 @@ static void on_new_tls_connection(uv_stream_t *server, int status) { return $R_CONT(c$cont, B_None); } - self->_stream = toB_int((int64_t)(intptr_t)server); + self->_stream = (int64_t)(intptr_t)server; $action2 f = ($action2)self->on_listen; f->$class->__asyn__(f, self, B_None); return $R_CONT(c$cont, B_None); } B_NoneType netQ_TLSListenerD___resume__ (netQ_TLSListener self) { - self->_stream = toB_int(-1); - self->_tls_ctx = toB_int(-1); + self->_stream = -1LL; + self->_tls_ctx = -1LL; $action2 f = ($action2)self->on_listen; f->$class->__asyn__(f, self, to$str("resume")); return B_None; @@ -884,15 +884,15 @@ B_NoneType netQ_TLSListenerD___resume__ (netQ_TLSListener self) { $R netQ_TLSListenConnectionD__initG_local (netQ_TLSListenConnection self, $Cont c$cont) { pin_actor_affinity(); - tlsuv_stream_t *stream = (tlsuv_stream_t *)fromB_int(self->server_stream); + tlsuv_stream_t *stream = (tlsuv_stream_t *)(intptr_t)self->server_stream; stream->data = self; - self->_stream = toB_int((int64_t)(intptr_t)stream); + self->_stream = (int64_t)(intptr_t)stream; return $R_CONT(c$cont, B_None); } $R netQ_TLSListenConnectionD__read_startG_local (netQ_TLSListenConnection self, $Cont c$cont) { - tlsuv_stream_t *stream = (tlsuv_stream_t *)fromB_int(self->_stream); + tlsuv_stream_t *stream = (tlsuv_stream_t *)(intptr_t)self->_stream; if ((intptr_t)stream == -1) return $R_CONT(c$cont, B_None); @@ -910,7 +910,7 @@ B_NoneType netQ_TLSListenerD___resume__ (netQ_TLSListener self) { } $R netQ_TLSListenConnectionD_writeG_local (netQ_TLSListenConnection self, $Cont c$cont, B_bytes data) { - tlsuv_stream_t *stream = (tlsuv_stream_t *)fromB_int(self->_stream); + tlsuv_stream_t *stream = (tlsuv_stream_t *)(intptr_t)self->_stream; if ((intptr_t)stream == -1) return $R_CONT(c$cont, B_None); @@ -929,18 +929,18 @@ B_NoneType netQ_TLSListenerD___resume__ (netQ_TLSListener self) { } $R netQ_TLSListenConnectionD_closeG_local (netQ_TLSListenConnection self, $Cont c$cont) { - tlsuv_stream_t *stream = (tlsuv_stream_t *)fromB_int(self->_stream); + tlsuv_stream_t *stream = (tlsuv_stream_t *)(intptr_t)self->_stream; if ((intptr_t)stream == -1) return $R_CONT(c$cont, B_None); tls_listener_close_stream(stream); - self->_stream = toB_int(-1); + self->_stream = -1LL; return $R_CONT(c$cont, B_None); } B_NoneType netQ_TLSListenConnectionD___resume__ (netQ_TLSListenConnection self) { - self->server_stream = toB_int(-1); - self->_stream = toB_int(-1); + self->server_stream = -1LL; + self->_stream = -1LL; return B_None; } @@ -960,7 +960,7 @@ static void tls_close(tlsuv_stream_t *stream) { if (on_close) on_close->$class->__asyn__(on_close, self); tlsuv_stream_close(stream, tls_on_close); - self->_stream = toB_int(-1); + self->_stream = -1LL; } void tls_on_receive(uv_stream_t *stream, ssize_t nread, const uv_buf_t* buf) { @@ -970,7 +970,7 @@ void tls_on_receive(uv_stream_t *stream, ssize_t nread, const uv_buf_t* buf) { $action2 f = ($action2)self->on_receive; B_bytes data = to$bytesD_len(buf->base, nread); f->$class->__asyn__(f, self, data); - self->_bytes_in->val += nread; + self->_bytes_in += nread; } } else if (nread == UV_EOF) { log_debug("TLS connection closed %p", stream); @@ -1000,7 +1000,7 @@ void tls_write_cb(uv_write_t *wreq, int status) { } $R netQ_TLSConnectionD_closeG_local (netQ_TLSConnection self, $Cont c$cont, $action on_close) { - uv_stream_t *stream = (uv_stream_t *)fromB_int(self->_stream); + uv_stream_t *stream = (uv_stream_t *)(intptr_t)self->_stream; // fd == -1 means invalid FD and can happen after __resume__ if ((intptr_t)stream == -1) return $R_CONT(c$cont, B_None); @@ -1016,7 +1016,7 @@ void tls_write_cb(uv_write_t *wreq, int status) { } $R netQ_TLSConnectionD_writeG_local (netQ_TLSConnection self, $Cont c$cont, B_bytes data) { - tlsuv_stream_t *stream = (tlsuv_stream_t *)fromB_int(self->_stream); + tlsuv_stream_t *stream = (tlsuv_stream_t *)(intptr_t)self->_stream; // fd == -1 means invalid FD and can happen after __resume__ if ((intptr_t)stream == -1) return $R_CONT(c$cont, B_None); @@ -1032,7 +1032,7 @@ void tls_write_cb(uv_write_t *wreq, int status) { $action2 f = ($action2)self->on_error; f->$class->__asyn__(f, self, to$str(errmsg)); } - self->_bytes_out->val += data->nbytes; + self->_bytes_out += data->nbytes; return $R_CONT(c$cont, B_None); } @@ -1044,7 +1044,7 @@ static void tls_on_connect(uv_connect_t *creq, int status) { uv_strerror_r(status, errmsg + strlen(errmsg), sizeof(errmsg)-strlen(errmsg)); log_debug(errmsg); tls_close((tlsuv_stream_t *)creq->handle); - self->$class->_on_tls_error(self, toB_int(-1), toB_int(status), to$str(errmsg)); + self->$class->_on_tls_error(self, -1LL, (int64_t)status, to$str(errmsg)); return; } @@ -1108,8 +1108,8 @@ void tlsuv_logger(int level, const char *file, unsigned int line, const char *ms // TODO: take SNI as input to TLSConnection actor stream->data = (void *)self; - tlsuv_stream_connect(connect_req, stream, (const char *)fromB_str(self->address), fromB_int(self->port), tls_on_connect); - self->_stream = toB_int((int64_t)(intptr_t)stream); + tlsuv_stream_connect(connect_req, stream, (const char *)fromB_str(self->address), (int)self->port, tls_on_connect); + self->_stream = (int64_t)(intptr_t)stream; return $R_CONT(c$cont, B_None); } diff --git a/base/src/process.ext.c b/base/src/process.ext.c index 386b2e104..c3d11839e 100644 --- a/base/src/process.ext.c +++ b/base/src/process.ext.c @@ -1,6 +1,7 @@ #include "rts/common.h" #include +#include #include "../rts/io.h" #include "../rts/log.h" @@ -29,7 +30,7 @@ void exit_handler(uv_process_t *req, int64_t exit_status, int term_signal) { // Close the process handle uv_close((uv_handle_t *)req, NULL); - process_data->process->_p = toB_int(0); + process_data->process->_p = 0; // Trigger the on_exit callback $action3 f = ($action3)process_data->on_exit; @@ -91,7 +92,7 @@ void read_stdout(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { uv_process_options_t *options = acton_calloc(1, sizeof(uv_process_options_t)); uv_process_t *req = acton_calloc(1, sizeof(uv_process_t)); - self->_p = toB_int((long)req); + self->_p = (int64_t)(intptr_t)req; req->data = process_data; @@ -103,7 +104,7 @@ void read_stdout(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { args[self->cmd->length] = NULL; if (self->workdir != B_None) { - options->cwd = fromB_str(self->workdir); + options->cwd = (const char *)fromB_str(self->workdir); } if (self->new_env == B_None) { @@ -115,8 +116,8 @@ void read_stdout(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { for (int i = 0; i < self->new_env->numelements; i++) { item = (B_tuple)iter->$class->__next__(iter); - char *key = fromB_str((B_str)item->components[0]); - char *value = fromB_str((B_str)item->components[1]); + char *key = (char *)fromB_str((B_str)item->components[0]); + char *value = (char *)fromB_str((B_str)item->components[1]); size_t env_size = strlen(key) + strlen(value) + 2; char *env_var = acton_malloc(env_size); snprintf(env_var, env_size, "%s=%s", key, value); @@ -173,7 +174,7 @@ void close_cb(uv_handle_t *handle) { } $R processQ_ProcessD_done_writingG_local(processQ_Process self, $Cont c$cont) { - uv_process_t *p = (uv_process_t *)fromB_int(self->_p); + uv_process_t *p = (uv_process_t *)(intptr_t)self->_p; struct process_data *process_data = (struct process_data *)p->data; uv_handle_t *stdin_handle = (uv_handle_t *)&process_data->stdin_pipe; // Ensure stdin is closed properly. stdin might be closed already from @@ -184,7 +185,7 @@ void close_cb(uv_handle_t *handle) { } $R processQ_ProcessD_pidG_local(processQ_Process self, $Cont c$cont) { - uv_process_t *p = (uv_process_t *)fromB_int(self->_p); + uv_process_t *p = (uv_process_t *)(intptr_t)self->_p; if (p == 0) { log_warn("Process has exited, ignoring PID request"); return $R_CONT(c$cont, B_None); @@ -192,25 +193,25 @@ void close_cb(uv_handle_t *handle) { return $R_CONT(c$cont, (B_atom)toB_int(p->pid)); } -$R processQ_ProcessD_signalG_local(processQ_Process self, $Cont c$cont, B_int signal) { - uv_process_t *p = (uv_process_t *)fromB_int(self->_p); +$R processQ_ProcessD_signalG_local(processQ_Process self, $Cont c$cont, int64_t signal) { + uv_process_t *p = (uv_process_t *)(intptr_t)self->_p; if (p == 0) { log_warn("Process has exited, ignoring signal request"); return $R_CONT(c$cont, B_None); } - uv_process_kill(p, fromB_int(signal)); + uv_process_kill(p, (int)signal); return $R_CONT(c$cont, B_None); } $R processQ_ProcessD_writeG_local(processQ_Process self, $Cont c$cont, B_bytes data) { - uv_process_t *p = (uv_process_t *)fromB_int(self->_p); + uv_process_t *p = (uv_process_t *)(intptr_t)self->_p; if (p == 0) { log_warn("Process has exited, ignoring write request"); return $R_CONT(c$cont, B_None); } uv_write_t *req = (uv_write_t *)acton_malloc(sizeof(uv_write_t)); - uv_buf_t buf = uv_buf_init(data->str, data->nbytes); + uv_buf_t buf = uv_buf_init((char *)data->str, (unsigned int)data->nbytes); struct process_data *process_data = (struct process_data *)p->data; uv_stream_t *stdin_handle = (uv_stream_t *)&process_data->stdin_pipe; diff --git a/base/src/random.ext.c b/base/src/random.ext.c index 3bdd7d9ad..ae77e559a 100644 --- a/base/src/random.ext.c +++ b/base/src/random.ext.c @@ -39,7 +39,6 @@ long randlong (long min, long max) { return min + r%range; } -int64_t randomQ_U_randint(int64_t min, int64_t max) { +int64_t randomQ_randint(int64_t min, int64_t max) { return randlong(min,max); } - diff --git a/base/src/re.ext.c b/base/src/re.ext.c index 5e829ae9f..ee3686ff6 100644 --- a/base/src/re.ext.c +++ b/base/src/re.ext.c @@ -23,7 +23,7 @@ void reQ___ext_init__() { // TODO: use u64 instead of int for arg_start_pos -reQ_Match reQ_U__match (B_str arg_pattern, B_str arg_text, int64_t arg_start_pos) { +reQ_Match reQ__match (B_str arg_pattern, B_str arg_text, int64_t arg_start_pos) { B_Hashable hwit = (B_Hashable)B_HashableD_strG_witness; B_SequenceD_list swit = B_SequenceD_listG_witness; B_list groups = B_listG_new(NULL, NULL); @@ -152,5 +152,5 @@ reQ_Match reQ_U__match (B_str arg_pattern, B_str arg_text, int64_t arg_start_pos pcre2_match_data_free(match_data); pcre2_code_free(re); - return reQ_MatchG_new(arg_pattern, arg_text, toB_int(match_start), toB_int(match_end), groups, named_groups); + return reQ_MatchG_new(arg_pattern, arg_text, match_start, match_end, groups, named_groups); } diff --git a/base/src/testing.act b/base/src/testing.act index e8bb2189a..5279eefb2 100644 --- a/base/src/testing.act +++ b/base/src/testing.act @@ -474,7 +474,7 @@ class UnitTest(Test): self.module = module def run_test(self, report_result: action(?bool, ?Exception, ?str) -> None, env: Env, log_handler: logging.Handler, tags: set[str]): - output = None + output: ?str = None success = None exception = None try: @@ -484,12 +484,12 @@ class UnitTest(Test): except SkipTest as e: success = True exception = e - except AssertionError as e: + except AssertionError as assertion_error: success = False - exception = e - except Exception as e: + exception = assertion_error + except Exception as exception_error: success = None - exception = e + exception = exception_error report_result(success, exception, output) class SimpleSyncTest(Test): @@ -510,12 +510,12 @@ class SimpleSyncTest(Test): except SkipTest as e: success = True exception = e - except AssertionError as e: + except AssertionError as assertion_error: success = False - exception = e - except Exception as e: + exception = assertion_error + except Exception as exception_error: success = None - exception = e + exception = exception_error report_result(success, exception, output) class SyncTest(Test): @@ -536,12 +536,12 @@ class SyncTest(Test): except SkipTest as e: success = True exception = e - except AssertionError as e: + except AssertionError as assertion_error: success = False - exception = e - except Exception as e: + exception = assertion_error + except Exception as exception_error: success = None - exception = e + exception = exception_error report_result(success, exception, output) class AsyncTest(Test): @@ -1968,6 +1968,6 @@ actor test_runner(env: Env, except argparse.PrintUsage as exc: print(exc.error_message) env.exit(0) - except argparse.ArgumentError as exc: - print(exc.error_message) + except argparse.ArgumentError as arg_error: + print(arg_error.error_message) env.exit(1) diff --git a/base/src/time.ext.c b/base/src/time.ext.c index 0a7447e80..648456248 100644 --- a/base/src/time.ext.c +++ b/base/src/time.ext.c @@ -102,7 +102,7 @@ void timeQ___ext_init__() { time__get_clock_data_cb(NULL); } -int64_t timeQ_U__get_incarnation () { +int64_t timeQ__get_incarnation () { return time__incarnation; } @@ -148,7 +148,7 @@ B_tuple timeQ_get_clock_data () { #endif } -B_tuple timeQ_U_1localtime (int64_t seconds) { +B_tuple timeQ_localtime (int64_t seconds) { time_t t = seconds; struct tm tm; #ifdef _WIN32 @@ -188,7 +188,7 @@ B_tuple timeQ_U_1localtime (int64_t seconds) { #endif } -B_tuple timeQ_U_3gmtime (int64_t seconds) { +B_tuple timeQ_gmtime (int64_t seconds) { time_t t = seconds; struct tm tm; #ifdef _WIN32 diff --git a/compiler/acton/Main.hs b/compiler/acton/Main.hs index cf7fcacbc..97dc631e9 100644 --- a/compiler/acton/Main.hs +++ b/compiler/acton/Main.hs @@ -2557,15 +2557,18 @@ genBuildZig template spec zigDeps depModuleOpts = where pkgDepDef (name, _) = let selectedCsv = M.findWithDefault "" name depModuleOpts - in unlines [ " const actdep_" ++ name ++ " = b.dependency(\"" ++ name ++ "\", .{" - , " .target = target," - , " .optimize = optimize," - , " .no_threads = no_threads," - , " .db = db," - , " .acton_modules = " ++ show selectedCsv ++ "," - , " .acton_root_stubs = \"\"," - , " });" - ] + moduleOpts + | name == "std" = [] + | otherwise = [ " .acton_modules = " ++ show selectedCsv ++ "," + , " .acton_root_stubs = \"\"," + ] + in unlines $ [ " const actdep_" ++ name ++ " = b.dependency(\"" ++ name ++ "\", .{" + , " .target = target," + , " .optimize = optimize," + , " .no_threads = no_threads," + , " .db = db," + ] ++ moduleOpts ++ + [ " });" ] pkgLibLink (name, _) = " libActonProject.root_module.linkLibrary(actdep_" ++ name ++ ".artifact(\"ActonProject\"));\n" ++ " for (explicit_static_libraries.items) |libActonExplicit| {\n" diff --git a/compiler/acton/test/parse/simple.all.golden b/compiler/acton/test/parse/simple.all.golden index a9149f3cc..cb58ea941 100644 --- a/compiler/acton/test/parse/simple.all.golden +++ b/compiler/acton/test/parse/simple.all.golden @@ -66,7 +66,7 @@ pure def main () -> None: return None =============================================== -/* Acton impl hash: 90d154672dec39acdfe73f54da1124538a944a4989833b41555c4693f4283455 */ +/* Acton impl hash: 0ca2a92cafc149a9706464cc8c1405785ee688eb49a8ebe57c2f63bc80d954c1 */ #pragma once #include "builtin/builtin.h" #include "rts/rts.h" diff --git a/compiler/acton/test/parse/simple.cgen.golden b/compiler/acton/test/parse/simple.cgen.golden index b9856bd94..64465cb7e 100644 --- a/compiler/acton/test/parse/simple.cgen.golden +++ b/compiler/acton/test/parse/simple.cgen.golden @@ -1,4 +1,4 @@ -/* Acton impl hash: 90d154672dec39acdfe73f54da1124538a944a4989833b41555c4693f4283455 */ +/* Acton impl hash: 0ca2a92cafc149a9706464cc8c1405785ee688eb49a8ebe57c2f63bc80d954c1 */ #include "rts/common.h" #include "out/types/simple.h" B_NoneType simpleQ_main () { diff --git a/compiler/acton/test/parse/simple.hgen.golden b/compiler/acton/test/parse/simple.hgen.golden index bc9721ea1..3bc12bb33 100644 --- a/compiler/acton/test/parse/simple.hgen.golden +++ b/compiler/acton/test/parse/simple.hgen.golden @@ -1,4 +1,4 @@ -/* Acton impl hash: 90d154672dec39acdfe73f54da1124538a944a4989833b41555c4693f4283455 */ +/* Acton impl hash: 0ca2a92cafc149a9706464cc8c1405785ee688eb49a8ebe57c2f63bc80d954c1 */ #pragma once #include "builtin/builtin.h" #include "rts/rts.h" diff --git a/compiler/lib/src/Acton/Boxing.hs b/compiler/lib/src/Acton/Boxing.hs index 127ed25d7..e0a1f65dd 100644 --- a/compiler/lib/src/Acton/Boxing.hs +++ b/compiler/lib/src/Acton/Boxing.hs @@ -17,32 +17,48 @@ import Control.Monad.Except import qualified Data.HashMap.Strict as M doBoxing :: Acton.Env.Env0 -> Module -> IO Module -doBoxing env m = do return m{mbody = ss} +doBoxing env m = return m{mbody = ss} where (_,ss) = runBoxM (boxing (boxEnv env) (mbody m)) -- Boxing monad --------------------------------------------------------------------------------------------------- type BoxM a = State Int a -newName :: String -> BoxM Name -newName s = do n <- get - put (n+1) - return $ Internal BoxPass s n - -newNames (n : ns) = do un <- newName (nstr n) - ps <- newNames ns - return ((n,un) : ps) -newNames [] = return [] +--newName :: String -> BoxM Name +--newName s = do n <- get +-- put (n+1) +-- return $ Internal BoxPass s n +-- +--newNames (n : ns) = do un <- newName (nstr n) +-- ps <- newNames ns +-- return ((n,un) : ps) +--newNames [] = return [] runBoxM ss = evalState ss 0 -data BoxX = BoxX { unboxedVarsX :: M.HashMap Name Name, isTopLevelX :: Bool, delayedUnboxX :: Bool, inClassX :: Bool } - type BoxEnv = EnvF BoxX + +data BoxX = BoxX {inClassX :: Maybe (TCon, TEnv), inActionX :: Bool, returnTypeX :: Maybe Type} + + boxEnv :: Env0 -> BoxEnv -boxEnv env0 = setX env0 (BoxX M.empty True False False) +boxEnv env0 = setX env0 BoxX{inClassX = Nothing, inActionX = False, returnTypeX = Nothing} + + +setInClass mtc env = modX env $ \x -> x{ inClassX = mtc } + +getInClass env = inClassX $ envX env +setInAction b env = modX env $ \x -> x{ inActionX = b } + +getInAction env = inActionX $ envX env + +setReturnType t env = modX env $ \x -> x{ returnTypeX = t } + +getReturnType env = returnTypeX $ envX env + +{- addUnboxedVars :: [(Name,Name)] -> BoxEnv -> BoxEnv addUnboxedVars ps env = modX env $ \x -> x{unboxedVarsX = foldr (uncurry M.insert) (unboxedVarsX x) ps} @@ -56,18 +72,178 @@ isTopLevel env = isTopLevelX $ envX env setDelayedUnbox b env = modX env $ \x -> x{delayedUnboxX = b} isDelayedUnbox env = delayedUnboxX $ envX env +-} +-- Unboxing helpers ------------------------------------- + +-- returns the uninstantiated type of method n in class c, i.e. the type of the corresponding method in oldest superclass. +-- n may be a method for which findAttrSchemas has no info, e.g. __init__, __str__, etc, in which case Nothing is returned. +generalTypeC :: EnvF x -> QName -> Name -> Maybe Type +generalTypeC env c n = case lookup n (findAttrSchemas env c) of + Just (NDef sc _ _) -> Just (sctype sc) + Just (NSig sc _ _) -> Just (sctype sc) + Just _ -> Nothing + Nothing -> Nothing + +-- generalType env n returns the same info as generalTypeC if n is a method of a class, but expects the TEnv of the class to be accessed via the env; +-- for use while traversing the class. +-- If n is a toplevel function it returns just the type in the NameInfo from the env. +-- n may be a method for which findAttrSchemas has no info, e.g. __init__, __str__, etc, in which case Nothing is returned. +generalType :: EnvF x -> Name -> Maybe Type +generalType env n = case getNI n of + Just (NDef sc _ _) -> Just $ sctype sc + Just (NSig sc _ _) -> Just $ sctype sc + ni -> Nothing + where getNI n = case contextIs env CtxClass of + True -> lookup n (gtypes env) + False -> Just (findQName (NoQ n) env) + +-- matchTypes expects to be called with both arguments a function type; the specific one returned by typeOf for a name f and +-- the general one returned by findAttrSchemas (if applicable) for the same name. +-- matchTypes t t' tags as TUnboxed those type components in t which can be unboxed taking the uninstantiated type t' +-- (type of the oldest corresponding method in a superclass) into account. +matchTypes t@TCon{} t'@TCon{} + | t == t' = if isUnboxable t then TUnboxed NoLoc t else t +matchTypes (TFun _ fx p _ r) (TFun _ fx' p' _ r') + = tFun fx (matchTypes p p') kwdNil (matchTypes r r') +matchTypes (TRow _ _ _ t r) (TRow _ _ _ t' r') + = posRow (matchTypes t t') (matchTypes r r') +matchTypes TNil{} TNil{} = posNil +matchTypes t _ = t -- ignore possibilities for unboxing + + +-- returns the representation type of method f selected from tc. +-- If generalTypeC cannot find an uninstantiated type to match against, the instantiated type is matched against itself (so, unboxable types will be annotated with TUnboxed). +rtypeOf :: EnvF x -> TCon -> Name -> Type +rtypeOf env tc f + | f == initKW = matchTypes (sctype sc) (sctype sc) + | otherwise = case generalTypeC env (tcname tc) f of + Just t -> matchTypes (sctype sc) t + Nothing -> matchTypes (sctype sc) (sctype sc) + where (sc,_) = findAttr' env tc f + +rtypeOf' env w f = rtypeOf env tc f + where NVar (TCon _ tc) = findQName w env -- Auxiliaries --------------------------------------------------------------------------------------------------- -- unboxing -integralTypes = [tBigint, tInt, tI32, tI16, tU64, tU32, tU16] +integralTypes = [tBigint, tInt, tI32, tI16, tI8, tU64, tU32, tU16, tU8, tU1] numericTypes = integralTypes ++ [tFloat] unboxableTypes = tail numericTypes isUnboxable t = t `elem` unboxableTypes +isUnboxedRep TUnboxed{} = True +isUnboxedRep t = isUnboxable t + +asUnboxedRep t + | isUnboxable t = TUnboxed NoLoc t + | otherwise = t + +boxedRepType (TUnboxed _ t) = t +boxedRepType t = t + +unboxedRepType (TUnboxed _ t) = Just t +unboxedRepType t + | isUnboxable t = Just t + | otherwise = Nothing + +rawRepType (TUnboxed _ t) = Just t +rawRepType _ = Nothing + +forceUnbox env t (Box _ e) + | boxedResultExpr env e = UnBox t e + | otherwise = e +forceUnbox env t e = UnBox t e + +boxedResultExpr env (Paren _ e) = boxedResultExpr env e +boxedResultExpr env DotI{} = True +boxedResultExpr env c@(Call _ f _ KwdNil) + | rawClassConstructor env c f = False + | callReturnsMsg env f = False + | otherwise = callReturnsBoxed env f +boxedResultExpr env _ = False + +rawClassConstructor env c f = callIsClass env f && isUnboxable (boxedRepType (typeOf env c)) + +exposeMsg fx t + | fx == fxAction = tMsg t + | otherwise = t + +callReturnsMsg env f = case rtypeOfFun env f of + TFun _ fx _ _ _ -> fx == fxAction + _ -> False + +callReturnsBoxed env f@(TApp _ f0 _) + | callIsClass env f0 = True + | otherwise = callableReturnsBoxed env f +callReturnsBoxed env f@(Var _ n) + | NClass{} <- findQName n env = True + | otherwise = callableReturnsBoxed env f +callReturnsBoxed env f = callableReturnsBoxed env f + +callIsClass env (TApp _ f _) = callIsClass env f +callIsClass env (Var _ n) = case findQName n env of + NClass{} -> True + _ -> False +callIsClass env _ = False + +callableReturnsBoxed env f = case rtypeOfFun env f of + TFun _ _ _ _ t -> isUnboxable t + _ -> False + +callableRawRep env f = case rtypeOfFun env f of + TFun _ _ _ _ (TUnboxed _ t) -> Just t + _ -> Nothing + +unboxedFieldType env e@(Var _ n) attr + | isTypeRef (findQName n env) = Nothing + | otherwise = unboxedFieldType' env e attr +unboxedFieldType env e n = unboxedFieldType' env e n + +unboxedFieldType' env e n = case typeOf env e of + TCon _ tc -> fieldType tc + TVar _ tv -> fieldType (findTVBound env tv) + _ -> Nothing + where fieldType tc = let (_, tc') = splitTC env tc + t = sctype $ fst $ findAttr' env tc' n + in if isUnboxedRep t then Just (boxedType t) else Nothing + boxedType (TUnboxed _ t) = t + boxedType t = t + +isTypeRef NAct{} = True +isTypeRef NClass{} = True +isTypeRef NProto{} = True +isTypeRef NExt{} = True +isTypeRef _ = False + +varType (NVar t) = Just t +varType (NSVar t) = Just t +varType _ = Nothing + +qvarType env n = tryQName n env >>= varType . convHNameInfo2NameInfo + +envVarType n te = case lookup n te of + Just (NVar t) -> Just t + Just (NSVar t) -> Just t + _ -> Nothing + +assignTargetType env s n e = maybe (maybe (typeOf env e) id (qvarType env (NoQ n))) id (envVarType n (envOf s)) + +targetType env (Dot _ e n) = sctype sc + where t0 = typeOf env e + (_,c0) = case t0 of + TCon _ tc -> splitTC env tc + TVar _ tv -> splitTC env (findTVBound env tv) + (sc, _) = findAttr' env c0 n +targetType env (Var _ n) + | Just t <- qvarType env n + = t +targetType env e = typeOf env e + + prims = [primISINSTANCE, primISNOTNONE, primISNONE] unboxedPrim p @@ -75,6 +251,7 @@ unboxedPrim p | p == primISNOTNONE = primISNOTNONE0 | p == primISNONE = primISNONE0 +{- qMath str = QName (ModName [name "math"]) (name str) mathfuns = map qMath ["sqrt", "exp", "log", "sin", "cos", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh"] @@ -85,58 +262,133 @@ class UnboxClass a where unbox :: Type -> a -> a instance UnboxClass Expr where - unbox _ (Box _ e) = e - unbox t e = UnBox t e - -instance UnboxClass PosArg where - unbox t (PosArg e p) = PosArg (unbox t e) (unbox t p) - unbox t (PosStar e) = PosStar (unbox t e) - unbox t PosNil = PosNil +-} +unbox _ (Box _ e) = e +unbox t e = UnBox t e + +tryUnbox, tryBox :: Type -> Expr -> Expr +tryUnbox (TUnboxed _ t) e = unbox t e +tryUnbox _ e = e +tryBox (TUnboxed _ _) (UnBox _ e)= e +tryBox (TUnboxed _ t) e = Box t e +tryBox _ e = e + +literalUnboxedRep (Int _ val _) + | val < (-9223372036854775808) = Nothing + | val > 18446744073709551615 = Nothing + | val > 9223372036854775807 = Just tU64 + | otherwise = Just tInt +literalUnboxedRep (Float _ _ _) = Just tFloat +literalUnboxedRep _ = Nothing + +exprUnboxedRep env e@Int{} = literalUnboxedRep e +exprUnboxedRep env e@Float{} = literalUnboxedRep e +exprUnboxedRep env e@DotI{} = Nothing +exprUnboxedRep env c@(Call _ f _ KwdNil) + | callReturnsMsg env f = Nothing + | rawClassConstructor env c f = unboxedRepType (typeOf env c) + | Just t <- callableRawRep env f = Just t +exprUnboxedRep env e = unboxedRepType (typeOf env e) + +fixreturn env rt e e1 + | getInAction env = e1 + | Just t <- rawRepType rt = forceUnbox env t e1 + | Box{} <- e1 = e1 + | Just t <- exprUnboxedRep env e = Box t e1 + | otherwise = e1 + +fixreturnUnknown env e e1 + | getInAction env = e1 + | Just t <- exprUnboxedRep env e = forceUnbox env t e1 + | otherwise = e1 + +fixassign env (TOpt _ t) e + | Box{} <- e = e + | isUnboxable t, + exprUnboxedRep env e == Just t = Box t e +fixassign env t e + | Just t' <- unboxedRepType t = forceUnbox env t' e + | otherwise = e + +fixarg env (TUnboxed _ t) e = forceUnbox env t e +fixarg env (TOpt _ t) e@Box{} = e +fixarg env (TOpt _ t) e + | isUnboxable t && exprUnboxedRep env e == Just t + = Box t e +fixarg env t e@Box{} = e +fixarg env t e + | isUnboxable t && isRawArg e = Box t e + where isRawArg UnBox{} = True + isRawArg e = case typeOf env e of + TUnboxed{} -> True + _ -> False +fixarg env t e + | Nothing <- unboxedRepType t, + Just rt <- exprUnboxedRep env e + = Box rt e +fixarg env _ e = e + +fixargs :: BoxEnv -> PosArg -> Type -> PosArg +fixargs env (PosArg e p) r = PosArg (fixarg env (rtype r) e) (fixargs env p (rtail r)) +-- fixargs(PosStar e) r = PosStar (tryUnbox t e) +-- where t = rtype r +fixargs env PosNil _ = PosNil + +fixpars (PosPar n (Just t) mbe p) r + = PosPar n (Just t') mbe (fixpars p (rtail r)) + where t' = rtype r +fixpars PosNIL _ = PosNIL + +rtypeOfFun env f@(TApp _ (Var _ n) _) + | boxedCPrim n = typeOf env f +rtypeOfFun env (TApp _ f0 []) = rtypeOfFun env f0 +rtypeOfFun env f@(TApp _ f0 ts) = matchTypes (typeOf env f) (typeInstOf env (map (const tWild) ts) f0) +rtypeOfFun env (Async _ f) = rtypeOfFun env f +rtypeOfFun env f@(Dot _ (Var _ x) _) + | NClass{} <- findQName x env + = typeOf env f +rtypeOfFun env f@(Dot _ e n) = case typeOf env e of + TCon _ tc -> rtypeOf env tc n + TVar _ tv -> rtypeOf env (findTVBound env tv) n + _ -> typeOf env f +rtypeOfFun env f@(Var _ n) + | boxedCPrim n = typeOf env f + | otherwise = case findQName n env of + NDef sc _ _ + | isInternalQName n -> matchTypes (typeOf env f) (typeOf env f) + | otherwise -> matchTypes (typeOf env f) (sctype sc) + NSig sc _ _ -> matchTypes (typeOf env f) (sctype sc) + NClass q _ _ _ + | null q -> matchTypes (typeOf env f) (typeOf env f) + _ -> typeOf env f +rtypeOfFun env f = typeOf env f + +boxedCPrim n = n `elem` [primAFTER, primAFTERc, primAFTERf] + +isInternalQName (NoQ n) = isInternal n +isInternalQName (GName _ n) = isInternal n +isInternalQName (QName _ n) = isInternal n -- Walking the syntax tree to place Box/UnBox annotations and sometimes restructure code to mimic C code on unboxed values --------------- +-- Return list of used witnesses and restructured code class Boxing a where boxing :: BoxEnv -> a -> BoxM ([Name],a) -instance {-# OVERLAPS #-} Boxing ([Stmt]) where - boxing env [] = return ([],[]) - boxing env (x@(Assign _ [PVar _ n _] _) : xs) - | isWitness n = do (ws1,x') <- boxing env x - (ws2,xs') <- boxing env1 xs - return $ if n `elem` ws2 then (ws1++ws2,x':xs') else (ws2,xs') - where te = envOf x - env1 = define te env - boxing env (x@(Assign l [p@(PVar _ n (Just t))] e) : xs) - | isUnboxable t = do case M.lookup n (unboxedVars env) of - Nothing -> do (ws1, e') <- boxing env e - un <- newName (nstr n) - let env1 = define (envOf x) (addUnboxedVars [(n,un)] env) - (ws2,p') <- boxing env1 p - (ws3,xs') <- boxing env1 xs - let ss = if isTopLevel env1 then [sAssign p (Box t (eVar un))] else [] - return (ws1++ws2++ws3, Assign l [p'] (if isUnboxed (pn p') then unbox t e' else e') : ss ++ xs') - Just un -> do (ws1,x') <- boxing env x - (ws2,xs') <- boxing (define (envOf x) env) xs - let ss = if isTopLevel env then [sAssign p (Box t (eVar un))] else [] - return (ws1++ws2, x' : ss ++ xs') - - boxing env (x@If{} : xs) = do ns <- newNames [ n | (n,NVar t) <- te, isUnboxable t ] - let env1 = addUnboxedVars ns env - (ws1,x') <- boxing env1 x - (ws2,xs') <- boxing (define te env1) xs - return (ws1++ws2, x' : xs') - where te = envOf x - - boxing env (x : xs) = do ps <- if (inClass env) then return [] else newNames [n | (n,NDef (TSchema _ [] (TFun _ _ p _ t)) _ _) <- te, isUnboxable t || hasUnboxableType p] - (ws1,x') <- boxing (addUnboxedVars ps env) x - (ws2,xs') <- boxing (addUnboxedVars ps env1) xs - return (ws1++ws2, x' : xs') - where te = envOf x - env1 = define te env - hasUnboxableType (TRow _ _ _ t r) - = isUnboxable t || hasUnboxableType r - hasUnboxableType _ = False +boxingTarget env (Dot l e n) = do (ws1,e1) <- boxing env e + return (ws1, Dot l e1 n) +boxingTarget env (DotI l e i) = do (ws1,e1) <- boxing env e + return (ws1, DotI l e1 i) +boxingTarget env (Rest l e n) = do (ws1,e1) <- boxing env e + return (ws1, Rest l e1 n) +boxingTarget env (RestI l e i) = do (ws1,e1) <- boxing env e + return (ws1, RestI l e1 i) +boxingTarget env e = return ([], e) +instance Boxing a => Boxing (Maybe a) where + boxing env (Just x) = do (ws1, x1) <- boxing env x + return (ws1, Just x1) + boxing env Nothing = return ([], Nothing) instance (Boxing a) => Boxing ([a]) where boxing env [] = return ([],[]) @@ -144,93 +396,102 @@ instance (Boxing a) => Boxing ([a]) where (ws2,xs2) <- boxing env xs return (ws1++ws2, x1:xs2) -instance Boxing a => Boxing (Maybe a) where - boxing env (Just x) = do (ws1, x1) <- boxing env x - return (ws1, Just x1) - boxing env Nothing = return ([], Nothing) +instance {-# OVERLAPS #-} Boxing ([Stmt]) where + boxing env [] = return ([],[]) + boxing env (x@(Assign _ [PVar _ w _] _) : xs) + -- if witness n is not used in xs, delete statement x defining n + | isWitness w = do (ws1,x') <- boxing env x + (ws2,xs') <- boxing env1 xs + return $ if w `elem` ws2 then (ws1++ws2,x':xs') else (ws2,xs') + where te = envOf x + env1 = define te env + boxing env (x : xs) = do (ws1,x') <- boxing env x + let env1 = define (envOf x') env + (ws2,xs') <- boxing env1 xs + return (ws1++ws2, x' : xs') + +-- After boxing, each Expr of unboxable type is boxed. Operands in BinOp/CompOp/UnOp expressions +-- are first boxed as part of their own boxing, then unboxed when used to form the BinOp/CompOp/UnOp term instance Boxing Expr where - boxing env e@(Var l (NoQ n)) + boxing env e@(Var _ (NoQ n)) | isWitness n = return ([n], e) - | otherwise = case M.lookup n ps of - Just un -> return ([], Box (typeOf env e) (eVar un)) - Nothing -> return ([], e) - where ps = unboxedVars env - boxing env v@Var{} = return ([], v) + | isUnboxable t = return ([], Box t e) + where t = typeOf env e + -- Qualified imported constants such as math.pi need the same boxed read + -- as local unboxable variables, but typeOf is not safe for all Vars here. + boxing env v@(Var _ n) + | Just t <- varType (findQName n env), isUnboxable t + = return ([], Box t v) boxing env (Call _ (Dot _ e@(Var _ w@(NoQ n)) attr) p KwdNil) | isWitness n = do (ws1,p1) <- boxing env p - (ws2,e1) <- boxingWitness env w attr ws1 p1 + (ws2,e1) <- boxingWitness env w attr ws1 p1 pr rest return (ws1++ws2,e1) - | attr == nextKW = return ([n], eCallP (eDot (eQVar w) attr) p) where - boxingWitness :: BoxEnv -> QName -> Name -> [Name] ->PosArg -> BoxM ([Name],Expr) - boxingWitness env w attr ws p = case findQName w env of + TFun _ _ pr _ rest = rtypeOf' env w attr + boxingWitness :: BoxEnv -> QName -> Name -> [Name] -> PosArg -> Type -> Type ->BoxM ([Name],Expr) + boxingWitness env w attr ws p pr rest = case findQName w env of NVar (TCon _ (TC _ ts)) - | any (not . vFree) ts -> return ([n], eCallP (eDot (eQVar w) attr) p) + -- | any (not . vFree) ts -> return ([n], eCallP (eDot (eQVar w) attr) p) | attr == fromatomKW -> boxingFromAtom w ts es - | attr == getitemKW -> boxingGetItem w ts es - | attr `elem` binopKWs -> boxingBinop w attr es ts - | attr `elem` eqordKWs -> boxingCompop w attr es ts - _ -> return ([n], eCallP (eDot (eQVar w) attr) p) + | attr `elem` binopKWs -> boxingBinop w attr es ts pr rest -- rest indicates "result type", not any form of remainder + | attr `elem` unopKWs -> boxingUnop w attr es ts pr rest + | attr `elem` eqordKWs -> boxingCompop w attr es ts pr rest + _ -> do let c = eCallP (eDot (eQVar w) attr) (fixargs env p pr) + return ([n], tryBox rest c) where es = posargs p - vFree (TCon _ (TC _ _))= True - vFree _ = False +-- vFree (TCon _ (TC _ _))= True +-- vFree _ = False boxingFromAtom w ts [i@Int{}] - | t == tBigint = return ([], i) + | t == tBigint = return ([n], eCall (eDot (eQVar w) fromatomKW) [i]) | t `elem` numericTypes = return ([], Box (last ts) (unbox t i)) where t = head ts boxingFromAtom w ts [x@Float{}] = return ([], Box (last ts) (unbox (head ts) x)) boxingFromAtom w ts es = return ([n], eCall (eDot (eQVar w) fromatomKW) es) - boxingGetItem w (t0:t:t1:_) es@[a, k] - | t == tInt && tn == qnList = return ([], eCall (tApp (eQVar primUGetItem) [t1]) [a, unbox t k]) -- only list indexing optimized. TODO: str indexing - where TCon _ (TC tn _) = t0 - boxingGetItem w ts es = return ([n], eCall (eDot (eQVar w) attr) es) - -- boxingNext w ts [] - boxingBinop w attr es@[x1, x2] ts + boxingBinop w attr es@[x1, x2] ts _ _ | isUnboxable t = return ([], Box (last ts) $ Paren NoLoc $ BinOp NoLoc (unbox t x1) op (unbox t x2)) where t = head ts op = bin2Binary attr - boxingBinop w attr es _ = return ([n], eCall (eDot (eQVar w) attr) es) - - boxingCompop w attr es@[x1, x2] ts + boxingBinop w attr es _ pr rest= return ([n], tryBox rest $ eCallP (eDot (eQVar w) attr) (fixargs env (posarg es) pr)) + boxingUnop w attr es@[x1] ts _ _ + | isUnboxable t = return ([], Box (last ts) $ Paren NoLoc $ UnOp NoLoc op (unbox t x1)) + where t = head ts + op = un2Unary attr + boxingUnop w attr es _ pr rest= return ([n], tryBox rest $ eCallP (eDot (eQVar w) attr) (fixargs env (posarg es) pr)) + boxingCompop w attr es@[x1, x2] ts _ _ | isUnboxable t = return ([], Box tBool $ Paren NoLoc $ CompOp NoLoc (unbox t x1) [OpArg op (unbox t x2)]) where t = head ts op = cmp2Comparison attr - boxingCompop w attr es _ = return ([n], eCall (eDot (eQVar w) attr) es) + boxingCompop w attr es _ pr rest= return ([n], tryBox rest $ eCallP (eDot (eQVar w) attr) (fixargs env (posarg es) pr)) boxing env (Call l e@(TApp _ (Var _ f) ts) p KwdNil) | f `elem` prims = do (ws1,p1) <- boxing env p - return (ws1,Box tBool $ eCallP e' p1) + return (ws1, Box tBool $ eCallP e' (fixargs env p1 r)) | otherwise = do (ws1,p1) <- boxing env p - return (ws1, eCallP e p1) + return (ws1, tryBox (exposeMsg fx t) $ eCallP e (fixargs env p1 r)) where e' = tApp (eQVar (unboxedPrim f)) ts - boxing env c@(Call l e@(Var _ (NoQ n)) p KwdNil) - | isUnboxable t = do (ws1,p1) <- boxing env p - case M.lookup n (unboxedVars env) of - Just un -> return (ws1, Box t (eCallP (eVar un) (ub env p1))) - Nothing -> return (ws1, eCallP e p1) - where t = typeOf env c - ub env (PosArg e p) - | isUnboxable t = PosArg (unbox t e) (ub env p) - | otherwise = PosArg e (ub env p) - where t = typeOf env e - ub env (PosStar e) - | isUnboxable t = PosStar (unbox t e) - | otherwise = PosStar e - where t = typeOf env e - ub env PosNil = PosNil - boxing env (Call l e@(Var _ f) p KwdNil) - | f `elem`prims = do (ws1,p1) <- boxing env p - return (ws1,Box tBool $ eCallP e' p1) - | f `elem` mathfuns = do (ws1,p1) <- boxing env p - return (ws1,Box tFloat $ eCallP e (unbox tFloat p1)) - | otherwise = do (ws1,p1) <- boxing env p - return (ws1, eCallP e p1) - where e' = eQVar (unboxedPrim f) + TFun _ fx r _ t = rtypeOfFun env e + boxing env (Call l f@Async{} p KwdNil) + = do (ws1,f1) <- boxing env f + (ws2,p1) <- boxing env p + return (ws1++ws2, eCallP f1 (fixargs env p1 r)) + where TFun _ _ r _ _ = rtypeOfFun env f + -- boxing env c@(Call l e@(Var _ (NoQ n)) p KwdNil) + -- = do (ws1,p1) <- boxing env p + -- return (ws1, tryBox t (eCallP e (fixargs env p1 r))) + -- where TFun _ _ r _ t = typeOf env c + -- boxing env (Call _ a@(TApp _ (Dot _ e n) ts) p KwdNil) + -- = do (ws1,p1) <- boxing env p + -- (ws2,e1) <- boxing env e + -- let res = eCallP (tApp (eDot e1 n) ts) (fixargs env p1 r) + -- return (ws1++ws2, tryBox t res) + -- where TFun _ _ r _ t = typeOf env a boxing env (Call l f p KwdNil) = do (ws1,f1) <- boxing env f (ws2,p1) <- boxing env p - return (ws1++ws2, eCallP f1 p1) + let c = eCallP f1 (fixargs env p1 r) + return (ws1++ws2, tryBox (exposeMsg fx t) c) + where TFun _ fx r _ t = rtypeOfFun env f boxing env (TApp l f ts) = do (ws1,f1) <- boxing env f return (ws1, TApp l f1 ts) boxing env (Let l ss e) = do (ws1, ss') <- boxing env ss @@ -240,37 +501,47 @@ instance Boxing Expr where return (ws1, Async l e1) boxing env (Await l e) = do (ws1,e1) <- boxing env e return (ws1, Await l e1) - boxing env (Index l e1 e2) = do (ws1,e1') <- boxing env e1 - (ws2,e2') <- boxing env e2 - return (ws1++ws2, Index l e1' e2') - boxing env (Cond l e1 e2 e3) = do (ws1,e1') <- boxing env e1 + boxing env e@(Cond l e1 e2 e3) = do (ws1,e1') <- boxing env e1 (ws2,e2') <- boxing env e2 (ws3,e3') <- boxing env e3 - return (ws1++ws2++ws3, Cond l e1' e2' e3') + case unboxedRepType (typeOf env e) of + Just t -> return (ws1++ws2++ws3, Box t $ Cond l (forceUnbox env t e1') e2' (forceUnbox env t e3')) + Nothing -> return (ws1++ws2++ws3, Cond l e1' e2' e3') boxing env (IsInstance l e qn) = do (ws1,e1) <- boxing env e return (ws1, IsInstance l e1 qn) - boxing env e@(BinOp l e1 op e2) = do (ws1,e1') <- boxing env e1 -- op is And or Or + boxing env e@(BinOp l e1 op e2) + | op `notElem` [And, Or], + Just rt <- unboxedRepType t + = do (ws1,e1') <- boxing env e1 + (ws2,e2') <- boxing env e2 + return (ws1++ws2, Box rt $ Paren NoLoc $ BinOp l (unboxArg e1 e1') op (unboxArg e2 e2')) + where t = typeOf env e + unboxArg e0 e' = maybe e' (\t -> forceUnbox env t e') (unboxedRepType (typeOf env e0)) + boxing env e@(BinOp l e1 op e2) = do (ws1,e1') <- boxing env e1 (ws2,e2') <- boxing env e2 return (ws1++ws2, BinOp l e1' op e2') - where t = typeOf env e boxing env (CompOp l e os) = do (ws1,e1) <- boxing env e (ws2,e2) <- boxing env os return (ws1++ws2, CompOp l e1 e2) - boxing env (UnOp l uop e) = do (ws1,e') <- boxing env e --uop is Not + boxing env (UnOp l uop e) + | uop /= Not, + Just rt <- unboxedRepType (typeOf env e) + = do (ws1,e') <- boxing env e + return (ws1, Box rt $ Paren NoLoc $ UnOp l uop (unbox rt e')) + boxing env (UnOp l uop e) = do (ws1,e') <- boxing env e return (ws1, UnOp l uop e') - where t = typeOf env e - boxing env (Dot l e n) = do (ws1,e1) <- boxing env e - return (ws1, Dot l e1 n) + boxing env d@(Dot _ (Var _ n) _) + | isTypeRef (findQName n env) = return ([], d) + boxing env d@(Dot l e n) = do (ws1,e1) <- boxing env e + let d' = Dot l e1 n + return (ws1, maybe d' (\t -> Box t d') (unboxedFieldType env e n)) boxing env (DotI l e i) = do (ws1,e1) <- boxing env e return (ws1, DotI l e1 i) boxing env (Rest l e n) = do (ws1,e1) <- boxing env e return (ws1, Rest l e1 n) boxing env (RestI l e i) = do (ws1,e1) <- boxing env e return (ws1, RestI l e1 i) --- boxing env (Lambda l p k f fx) = Lambda l <$> boxing env p <*> boxing env k <*> boxing env f <*> return fx --- boxing env (Yield l mbe) = Yield l <$> boxing env mbe --- boxing env (YieldFrom l e) = YieldFrom l <$> boxing env e - boxing env (Tuple l p k) = do (ws1,p1) <- boxing env p + boxing env (Tuple l p k) = do (ws1,p1) <- boxingTupleArgs env p return (ws1,Tuple l p1 k) boxing env (List l es) = do (ws1,es1) <- boxing env es return (ws1, List l es1) @@ -278,17 +549,31 @@ instance Boxing Expr where return (ws1, Set l es1) boxing env (Dict l es) = do (ws1,es1) <- boxing env es return (ws1, Dict l es1) - boxing env (Paren l e) = do (ws1,e1) <- boxing env e - return (ws1, Paren l e1) boxing env (Box t e) = do (ws1,e1) <- boxing env e case e1 of UnBox _ e' -> return (ws1,e') _ -> return (ws1,Box t e1) return (ws1, e1) --- boxing env (Box _ (UnBox _ e)) = do (ws1,e1) <- boxing env e --- return (ws1, e1) boxing env e = return ([],e) +boxingTupleArgs env (PosArg e p) = do (ws1,e1) <- boxing env e + (ws2,p1) <- boxingTupleArgs env p + return (ws1++ws2, PosArg (boxValueExpr env e e1) p1) +boxingTupleArgs env (PosStar e) = do (ws1,e1) <- boxing env e + return (ws1, PosStar e1) +boxingTupleArgs _ PosNil = return ([], PosNil) + +boxValueExpr env e e1 + | Box{} <- e1 = e1 + | boxedResultExpr env e = e1 +boxValueExpr env (Call _ f _ KwdNil) e1 + | callReturnsMsg env f = e1 +boxValueExpr env (Paren _ e) e1 = boxValueExpr env e e1 +boxValueExpr env e e1 + | Just rt <- exprUnboxedRep env e + = Box rt e1 + | otherwise = e1 + instance Boxing OpArg where boxing env (OpArg op e) = do (ws1,e1) <- boxing env e return (ws1, OpArg op e1) @@ -296,7 +581,8 @@ instance Boxing OpArg where instance Boxing Stmt where boxing env (Expr l e) = do (ws1,e1) <- boxing env e return (ws1, Expr l e1) - boxing env (Assign l [pt@(PVar _ x Nothing)] e@(Call _ (Dot _ (Var _ w@(NoQ n)) attr) p KwdNil)) +{- + boxing env (Assign l [(PVar _ x Nothing)] e@(Call _ (Dot _ (Var _ w@(NoQ n)) attr) p KwdNil)) | isWitness n = do (ws1,p1) <- boxing env p (ws2,pt2) <- boxing env pt @@ -305,8 +591,8 @@ instance Boxing Stmt where where boxingWitness env pt w attr p = case findQName w env of NVar (TCon _ (TC _ ts)) - | any (not . vFree) ts -> return ([n], Assign l [pt] (eCallP (eDot (eQVar w) attr) p)) - | attr `elem` incrBinopKWs -> boxingincrBinop pt w attr es ts + -- | any (not . vFree) ts -> return ([n], Assign l [pt] (eCallP (eDot (eQVar w) attr) p)) + | attr `elem` augopKWs -> boxingincrBinop pt w attr es ts _ -> do (ws,e') <- boxing env e return (ws, Assign l [pt] (if isUnboxed (pn pt) then unbox t e' else e')) where es = posargs p @@ -319,14 +605,28 @@ instance Boxing Stmt where op = bin2Aug attr boxingincrBinop pt w attr es _ = return ([n], Assign l [pt] (eCall (eDot (eQVar w) attr) es)) - boxing env (Assign l [pt@PVar{}] e) +-} + boxing env (Assign l [pt@(PVar _ _ Nothing)] e@(Call _ (Dot _ (Var _ (NoQ w)) attr) p KwdNil)) -- (re)introduce augmented arithmetic operator for unboxable types; Assign case + | isWitness w && attr `elem` augopKWs && isUnboxable t + = do (ws, p') <- boxing env p + let [x1,x2] = posargs p' + return (ws, AugAssign l (unbox t x1) op (unbox t x2)) + where t = typeOf env e + op = bin2Aug attr + + boxing env (Assign l [p@(PVar _ n (Just t))] e) + = do (ws1,p') <- boxing env p + (ws2, e') <- boxing env e + return (ws1++ws2, Assign l [pvar p'] (fixassign env (asUnboxedRep t) e')) + where pvar (PVar l n _) = PVar l n (Just (asUnboxedRep t)) + pvar p = p + boxing env s@(Assign l [pt@(PVar _ n Nothing)] e) = do (ws1,pt1) <- boxing env pt (ws2,e2) <- boxing env e - return (ws1++ws2, Assign l [pt1] (if isUnboxed (pn pt1) then unbox t e2 else e2)) - where t = typeOf env e - boxing env (Assign l ps e) = do (ws1,ps1) <- boxing env ps - (ws2,e2) <- boxing env e - return (ws1++ws2, Assign l ps1 e2) + return (ws1++ws2,Assign l [pt1] (fixassign env t e2)) + where t = assignTargetType env s n e + + {- This does not work. It may cause mutable updates to integer-typed varibles. boxing env (MutAssign l tg@Dot{} e@(Call _ (Dot _ (Var _ w@(NoQ n)) attr) p KwdNil)) @@ -353,115 +653,89 @@ instance Boxing Stmt where op = bin2Aug attr boxingincrBinop w attr es _ = return ([n], MutAssign l tg (eCall (eDot (eQVar w) attr) es)) -} - boxing env (MutAssign l t e) = do (ws0,t1) <- boxing env t + boxing env (MutAssign l _ e@(Call _ (Dot _ (Var _ (NoQ w)) attr) p KwdNil)) -- (re)introduce augmented arithmetic operator for unboxable types; MutAssign case + | isWitness w && attr `elem` augopKWs && isUnboxable t + = do let [x1,x2] = posargs p + (ws, x2') <- boxing env x2 + return (ws, AugAssign l x1 op (unbox t x2')) + where t = typeOf env e + op = bin2Aug attr + boxing env (MutAssign l tg e) = do (ws0,tg1) <- boxingTarget env tg (ws1,e1) <- boxing env e - return (ws0++ws1, MutAssign l t1 e1) - boxing env (AugAssign l t aop e)= do (ws0,t1) <- boxing env t - (ws1,e1) <- boxing env e - return (ws0++ws1, AugAssign l t aop e1) - boxing env (Assert l e mbe) = do (ws1,e1) <- boxing env e - (ws2,mbe1) <- boxing env mbe - return (ws1++ws2, Assert l e1 mbe1) + return (ws0++ws1, MutAssign l tg1 (fixassign env t e1)) + where t = targetType env tg boxing env (Pass l) = return ([], Pass l) boxing env (Delete l t) = return ([], Delete l t) boxing env (Return l (Just e)) = do (ws1,e1) <- boxing env e - if (isUnboxable t && isDelayedUnbox env) - then return (ws1, Return l (Just (unbox t e1))) - else return (ws1, Return l (Just e1)) - where t = typeOf env e + case getReturnType env of + Just rt -> return (ws1, Return l (Just (fixreturn env rt e e1))) + Nothing -> return (ws1, Return l (Just (fixreturnUnknown env e e1))) boxing env (Return l Nothing) = return ([], Return l Nothing) - boxing env (Raise l e) = do (ws1,e1) <- boxing env e - return (ws1, Raise l e1) boxing env (Break l) = return ([], Break l) boxing env (Continue l) = return ([], Continue l) - boxing env (If l bs ss) = do (ws1,bs1) <- boxing env1 bs - (ws2,ss1) <- boxing env1 ss + boxing env (If l bs ss) = do (ws1,bs1) <- boxing env bs + (ws2,ss1) <- boxing env ss return (ws1++ws2,If l bs1 ss1) - where env1 = setTopLevel False env boxing env (While l e ss els) = do (ws1,e1) <- boxing env e - (ws2,ss1) <- boxing env1 ss - (ws3,els1) <- boxing env1 els + (ws2,ss1) <- boxing env ss + (ws3,els1) <- boxing env els return (ws1++ws2++ws3, While l e1 ss1 els1) - where env1 = setTopLevel False env - boxing env (Try l ss hs els fs) = do (ws1,ss1) <- boxing env1 ss - (ws2,hs1) <- boxing env1 hs - (ws3,els1) <- boxing env1 els - (ws4,fs1) <- boxing env1 fs - return (ws1++ws2++ws3++ws4, Try l ss1 hs1 els1 fs1) - where env1 = setTopLevel False env - boxing env (With l ws ss) = do (ws1,ws') <- boxing env ws - (ws2,ss1) <- boxing (setTopLevel False env) ss - return (ws1++ws2, With l ws' ss1) - boxing env (VarAssign l ps e) = do (ws1,e1) <- boxing env e - return (ws1, VarAssign l ps e) - boxing env (After l e1 e2) = do (ws1,e1') <- boxing env e1 - (ws2,e2') <- boxing env e2 - return (ws1++ws2, After l e1' e2') boxing env s@(Signature l ns sc d) = return ([], s) boxing env g@(Decl l ds) = do (ws1, ds1) <- boxing env1 ds return (ws1, Decl l ds1) where te = envOf g - env1 = setTopLevel False $ define te env + env1 = define te env + boxing env s = error ("Unhandled boxing " ++show s) -instance {-# OVERLAPS #-} Boxing [Decl] where - boxing env (c@Class{} : ds) = do (ws1,c1) <- boxing (setInClass env) c - (ws2,ds2) <- boxing env ds - return (ws1++ws2,c1:ds2) - boxing env (d@Def{} : ds) +--instance {-# OVERLAPS #-} Boxing [Decl] where +-- boxing env (c@Class{} : ds) = do (ws1,c1) <- boxing (setInClass env) c +-- (ws2,ds2) <- boxing env ds +-- return (ws1++ws2,c1:ds2) +-- boxing env (d@Def{} : ds) -- | hasNotImpl (dbody d) = do (ws,ds1) <- boxing env ds -- return (ws, d : ds1) - -- | otherwise = case M.lookup (dname d) (unboxedVars env) of - = case M.lookup (dname d) (unboxedVars env) of - Just un -> do - (ws1,d1) <- boxing (setDelayedUnbox True env) d{dname = un} - let ds1 = [mkWrapper d un] - (ws2,ds2) <- boxing env ds - return (ws1++ws2,d1 : ds1 ++ ds2) - _ -> do - (ws1,d1) <- boxing env d - (ws2,ds2) <- boxing env ds - return (ws1++ws2,d1:ds2) - where mkWrapper (Def l n q p _ (Just t) ss dec fx ddoc) un - | isUnboxable t = Def l n q p KwdNIL (Just t) [Return NoLoc (Just (Box t (eCallP (eVar un) (ub p))))] dec fx ddoc - | otherwise = Def l n q p KwdNIL (Just t) [Return NoLoc (Just (eCallP (eVar un) (ub p)))] dec fx ddoc - ub (PosPar n (Just t) _ p) - | isUnboxable t = PosArg (unbox t (eVar n)) (ub p) - | otherwise = PosArg (eVar n) (ub p) - ub (PosSTAR n _) = PosStar (eVar n) - ub PosNIL = PosNil - boxing env [] = return ([],[]) + -- | otherwise = case lookup (dname d) (unboxedVars env) of +-- = do (ws1,d') <- boxing env d +-- (ws2,ds') <- boxing env ds +-- return (ws1++ws2,d':ds') +-- boxing env [] = return ([],[]) instance Boxing Decl where boxing env (Class l n q cs ss ddoc) - = do (ws1, ss1) <- boxing env1 ss' + = do (ws1, ss1) <- boxing env2 ss' return (ws1, Class l n q cs ss1 ddoc) where ss' = vsubst [(tvSelf, tCon c)] ss c = TC (NoQ n) (map tVar $ qbound q) env1 = defineTVars q env - boxing env (Def l n q p KwdNIL t ss dec fx ddoc) - = do ps <- if (inClass env || not (isUnboxed n)) then return [] else newNames [n | (n,NVar t) <- te, isUnboxable t] - let env2 = addUnboxedVars ps $ env1 - (ws1,p1) <- boxing env2 p - (ws2,ss1) <- boxing env2 ss - return (ws1++ws2,Def l n q p1 KwdNIL t ss1 dec fx ddoc) - where te = envOf p - env1 = define te env - + env2 = Acton.Boxing.setInClass (Just(c,findAttrSchemas env1 (NoQ n))) env1 + boxing env f@(Def l n q p KwdNIL t ss dec fx ddoc) + = do (ws2,ss') <- boxing env1 ss + return (ws2, Def l n q pFinal KwdNIL (Just t') ss' dec fx ddoc) + where ft = tFun fx (prowOf p) kwdNil (fromJust t) + (pFinal, t0@(TFun _ _ _ _ t')) + = case getInClass env of + Just(tc,_) + | dec == Static -> (fixpars p r, mt) + | otherwise -> (keepSelf p r, mt) + where mt@(TFun _ _ r _ _) = rtypeOf env tc n + Nothing -> (fixpars p r, mt) + where mt@(TFun _ _ r _ _) = maybe (matchTypes ft ft) (matchTypes ft) (generalType env n) + keepSelf (PosPar a b c p') r + = PosPar a b c (fixpars p' r) + keepSelf p r = fixpars p r + te = envOf pFinal + env1 = setReturnType (Just t') $ setInAction (fx == fxAction) $ define te env + instance Boxing Branch where - boxing env (Branch e ss) = do (ws1,e1) <- boxing env e - (ws2,ss1) <- boxing env ss - return (ws1++ws2, Branch e1 ss1) - -instance Boxing Handler where - boxing env (Handler ex b) = do (ws1, b1) <- boxing env b - return (ws1, Handler ex b1) + boxing env (Branch e ss) = do (ws1,e') <- boxing env e + (ws2,ss') <- boxing env ss + return (ws1++ws2, Branch e' ss') instance Boxing PosPar where - boxing env (PosPar n t e p) = do (ws1, e1) <- boxing env e + boxing env (PosPar n (Just t) e p) + = do (ws1, e1) <- boxing env e (ws2, p2) <- boxing env p - case M.lookup n (unboxedVars env) of - Just un -> return (ws1++ws2, PosPar un t e1 p2) - _ -> return (ws1++ws2, PosPar n t e1 p2) + return (ws1++ws2, PosPar n (Just t) e1 p2) -- keep boxed if has default value (if isUnboxable t then maybe Nothing (Just . unbox t) e1 else e1) p2) boxing env (PosSTAR n t) = return ([],PosSTAR n t) boxing env PosNIL = return ([],PosNIL) @@ -470,39 +744,27 @@ instance Boxing PosArg where boxing env (PosArg e p) = do (ws1,e1) <- boxing env e (ws2,p1) <- boxing env p return (ws1++ws2, PosArg e1 p1) + where t = typeOf env e boxing env (PosStar e) = do (ws1,e1) <- boxing env e return (ws1, PosStar e1) boxing env PosNil = return ([],PosNil) instance Boxing Elem where boxing env (Elem e) = do (ws1,e1) <- boxing env e - return (ws1, Elem e1) + return (ws1, Elem (boxValueExpr env e e1)) boxing env (Star e) = do (ws1,e1) <- boxing env e return (ws1, Star e1) instance Boxing Assoc where boxing env (Assoc k v) = do (ws1,k1) <- boxing env k (ws2,v1) <- boxing env v - return (ws1++ws2, Assoc k1 v1) + return (ws1++ws2, Assoc (boxValueExpr env k k1) (boxValueExpr env v v1)) boxing env (StarStar e) = do (ws1,e1) <- boxing env e return (ws1, StarStar e1) -instance Boxing WithItem where - boxing env (WithItem e mbp) = do (ws1,e1) <- boxing env e - return (ws1, WithItem e1 mbp) instance Boxing Pattern where - boxing env v@(PVar l n mbt) = case M.lookup n ps of - Just un -> return ([], PVar l un mbt) - Nothing -> return ([], v) - where ps = unboxedVars env - boxing env (PParen l p) = do (ws,p') <- boxing env p - return (ws, PParen l p') - boxing env (PList l ps mbp) = do (ws1, ps1) <- boxing env ps - (ws2, mbp2) <- boxing env mbp - return (ws1++ws2, PList l ps1 mbp2) - - - + boxing env v@(PVar l n mbt) = return ([],v) + bin2Binary kw | kw == addKW = Plus | kw == subKW = Minus @@ -517,6 +779,11 @@ bin2Binary kw | kw == xorKW = BXor | kw == andKW = BAnd +un2Unary kw + | kw == posKW = UPlus + | kw == negKW = UMinus + | kw == invertKW = BNot + cmp2Comparison kw | kw == eqKW = Eq | kw == neKW = NEq diff --git a/compiler/lib/src/Acton/Builtin.hs b/compiler/lib/src/Acton/Builtin.hs index 0ddad12b0..d5a52e057 100644 --- a/compiler/lib/src/Acton/Builtin.hs +++ b/compiler/lib/src/Acton/Builtin.hs @@ -38,10 +38,13 @@ appendKW = name "append" boolKW = name "__bool__" strKW = name "__str__" reprKW = name "__repr__" +serializeKW = name "__serialize__" +deserializeKW = name "__deserialize__" cleanupKW = name "__cleanup__" resumeKW = name "__resume__" valueKWs = [boolKW, strKW, reprKW] +indexedKWs = [getitemKW, setitemKW, delitemKW] iaddKW = name "__iadd__" isubKW = name "__isub__" @@ -60,12 +63,15 @@ imatmulKW = name "__imatmul__" incrBinopKWs = [iaddKW, isubKW, imulKW, ipowKW, itruedivKW, imodKW, ifloordivKW, ilshiftKW, irshiftKW, iorKW, ixorKW, iandKW, imatmulKW] +augopKWs = incrBinopKWs + addKW = name "__add__" subKW = name "__sub__" mulKW = name "__mul__" powKW = name "__pow__" truedivKW = name "__truediv__" modKW = name "__mod__" +divmodKW = name "__divmod__" floordivKW = name "__floordiv__" lshiftKW = name "__lshift__" rshiftKW = name "__rshift__" @@ -105,9 +111,12 @@ nObject = name "object" nInt = name "int" nI32 = name "i32" nI16 = name "i16" +nI8 = name "i8" nU64 = name "u64" nU32 = name "u32" nU16 = name "u16" +nU8 = name "u8" +nU1 = name "u1" nBigint = name "bigint" nFloat = name "float" nComplex = name "complex" @@ -170,9 +179,12 @@ qnObject = gBuiltin nObject qnInt = gBuiltin nInt qnI32 = gBuiltin nI32 qnI16 = gBuiltin nI16 +qnI8 = gBuiltin nI8 qnU64 = gBuiltin nU64 qnU32 = gBuiltin nU32 qnU16 = gBuiltin nU16 +qnU8 = gBuiltin nU8 +qnU1 = gBuiltin nU1 qnBigint = gBuiltin nBigint qnFloat = gBuiltin nFloat qnComplex = gBuiltin nComplex @@ -234,9 +246,12 @@ cObject = TC qnObject [] cInt = TC qnInt [] cI32 = TC qnI32 [] cI16 = TC qnI16 [] +cI8 = TC qnI8 [] cU64 = TC qnU64 [] cU32 = TC qnU32 [] cU16 = TC qnU16 [] +cU8 = TC qnU8 [] +cU1 = TC qnU1 [] cBigint = TC qnBigint [] cFloat = TC qnFloat [] cComplex = TC qnComplex [] @@ -250,6 +265,7 @@ cList a = TC qnList [a] cDict a b = TC qnDict [a,b] cSet a = TC qnSetT [a] cSlice = TC qnSlice [] +cRange = TC qnRange [] cIterator a = TC qnIterator [a] cBaseException = TC qnBaseException [] cException = TC qnException [] @@ -288,9 +304,12 @@ tObject = tCon cObject tInt = tCon cInt tI32 = tCon cI32 tI16 = tCon cI16 +tI8 = tCon cI8 tU64 = tCon cU64 tU32 = tCon cU32 tU16 = tCon cU16 +tU8 = tCon cU8 +tU1 = tCon cU1 tBigint = tCon cBigint tFloat = tCon cFloat tComplex = tCon cComplex @@ -303,6 +322,7 @@ tList a = tCon (cList a) tDict a b = tCon (cDict a b) tSet a = tCon (cSet a) tSlice = tCon cSlice +tRange = tCon cRange tIterator a = tCon (cIterator a) tBaseException = tCon cBaseException tException = tCon cException diff --git a/compiler/lib/src/Acton/CodeGen.hs b/compiler/lib/src/Acton/CodeGen.hs index 4e458726e..6102c9b6b 100644 --- a/compiler/lib/src/Acton/CodeGen.hs +++ b/compiler/lib/src/Acton/CodeGen.hs @@ -127,6 +127,8 @@ setVolVars as env = modX env $ \x -> x{ volVarsX = as } isVolVar a env = a `elem` volVarsX (envX env) +localDefined env = localX (envX env) + -- Line emission helpers setLineEmit :: (SrcLoc -> Doc) -> GenEnv -> GenEnv setLineEmit f env = modX env $ \x -> x{ lineEmitX = Just f } @@ -136,6 +138,7 @@ getLineEmit env = case lineEmitX (envX env) of Just f -> f Nothing -> const empty + -- Helpers ------------------------------------------------------------------------------------------ include :: GenEnv -> String -> ModName -> Doc @@ -148,6 +151,148 @@ modNames (FromImportAll _ (ModRef (0,Just m)) : is) = m : modNames is modNames [] = [] +tnm env (Derived _ (Derived _ n)) + | B.isUnboxable (tCon0 (gBuiltin n) []) = gen env (tCon0 (gBuiltin n) []) +tnm env (Derived _ n) + | B.isUnboxable (tCon0 (gBuiltin n) []) = gen env (tCon0 (gBuiltin n) []) +tnm _ _ = word + + +settype env True t + = rawType env t +settype env _ t = repType env t + +-- C ABI type renderers. +-- +-- repType/repParams render the representation already recorded in the Type: +-- only explicit TUnboxed markers become raw C types. rawType/rawParams are +-- for ABI boundaries that deliberately force builtin value classes to their raw +-- constructors/storage representation. +repType env t = gen env t + +repParams env (TNil _ _) = empty +repParams env (TRow _ _ _ t r@TRow{}) + = repType env t <> comma <+> repParams env r +repParams env (TRow _ _ _ t TNil{}) = repType env t +repParams env (TRow _ _ _ t TVar{}) = repType env t +repParams env t@TVar{} = gen env t +repParams env t = error ("codegen unexpected row: " ++ prstr t) + +rawType env t + | B.isUnboxable t' = text (unboxed_c_type t') + | otherwise = repType env t + where t' = boxedRepType t + +rawParams env (TNil _ _) = empty +rawParams env (TRow _ _ _ t r@TRow{}) + = rawType env t <> comma <+> rawParams env r +rawParams env (TRow _ _ _ t TNil{}) = rawType env t +rawParams env (TRow _ _ _ t TVar{}) = rawType env t +rawParams env t@TVar{} = gen env t +rawParams env t = error ("codegen unexpected row: " ++ prstr t) + +storageType env t = rawType env t + +-- Generic closure emission ------------------------------------------------------------------------- + +-- Lambda lifting represents each closure as a fresh class. For common closure +-- shapes we can keep the typed IR class, but emit it as a thin constructor +-- wrapper around a shared builtin C closure object plus the original lambda +-- body as a trampoline. +data GenericClosureKind = GCCont | GCProc | GCMut0 deriving (Eq,Show) + +data GenericClosure = GenericClosure { gcKind :: GenericClosureKind + , gcSlots :: [(Name,Type)] + } deriving (Eq,Show) + +genericClosureInfoByName :: GenEnv -> Name -> Maybe GenericClosure +genericClosureInfoByName env n = case findQName (NoQ n) env of + NClass q as te _ -> genericClosureInfo env (NoQ n) q (map snd as) te + _ -> Nothing + +genericClosureInfoByQName :: GenEnv -> QName -> Maybe GenericClosure +genericClosureInfoByQName env qn = case findQName qn env of + NClass q as te _ -> genericClosureInfo env qn q (map snd as) te + _ -> Nothing + +genericClosureInfo :: GenEnv -> QName -> QBinds -> [TCon] -> TEnv -> Maybe GenericClosure +genericClosureInfo env qn q as te + | hasBase primCont, + smallSlots, + Just [arg] <- callArgs, + not (rawCallArg arg) = Just $ GenericClosure GCCont slots + | hasBase primMut, + null slots, + Just [] <- evalArgs, + Just et <- evalRes, + not (rawCallResult et) = Just $ GenericClosure GCMut0 [] + | hasBase primProc, + not (any hasBase [primAction, primMut, primPure]), + smallSlots, + Just [arg] <- callArgs, + not (rawCallArg arg) = Just $ GenericClosure GCProc slots + | otherwise = Nothing + where tc = TC qn (map tVar $ qbound q) + hasBase p = any ((== p) . tcname) as + slots = [ (n,sctype sc) | (n, NSig sc Property _) <- te ] + smallSlots = length slots <= 4 && all pointerStored slots + pointerStored (_,t) = not (B.isUnboxable (boxedRepType t)) + callType = methodType attr_call_ + evalType = methodType attr_eval_ + callArgs = funArgs =<< callType + evalArgs = funArgs =<< evalType + evalRes = funRes =<< evalType + methodType n = case findAttr env tc n of + Just _ -> Just $ B.rtypeOf env tc n + _ -> Nothing + funArgs (TFun _ _ p _ _) = rowTypes p + funArgs _ = Nothing + funRes (TFun _ _ _ _ t) = Just t + funRes _ = Nothing + rowTypes (TNil _ _) = Just [] + rowTypes (TRow _ _ _ t r) = (t :) <$> rowTypes r + rowTypes _ = Nothing + rawCallArg TUnboxed{} = True + rawCallArg _ = False + rawCallResult TUnboxed{} = True + rawCallResult _ = False + +genericClosureCType :: GenericClosure -> Doc +genericClosureCType (GenericClosure GCCont slots) + = text "B_ClosureCont" <> pretty (length slots) +genericClosureCType (GenericClosure GCProc slots) + = text "B_ClosureProc" <> pretty (length slots) +genericClosureCType (GenericClosure GCMut0 _) + = text "B_ClosureMut0" + +genericClosureFnType :: GenericClosure -> Doc +genericClosureFnType gc = genericClosureCType gc <> text "Fn" + +genericClosureNew :: GenericClosure -> Doc +genericClosureNew gc = genericClosureCType gc <> text "G_new" + +genericClosureBodyMethod :: GenericClosure -> Name +genericClosureBodyMethod (GenericClosure GCMut0 _) = attr_eval_ +genericClosureBodyMethod _ = attr_call_ + +genericClosureMethods :: GenericClosure -> [Name] +genericClosureMethods gc = [genericClosureBodyMethod gc] + +genericClosureSlotAccess :: GenEnv -> Expr -> Name -> Maybe Doc +genericClosureSlotAccess env e n = do + TCon _ (TC qn _) <- Just $ boxedRepType (typeOf env e) + gc <- genericClosureInfoByQName env qn + (ix,t) <- lookupSlot 0 n (gcSlots gc) + return $ parens (parens (storageType env t) <> slot gc ix) + where lookupSlot _ _ [] = Nothing + lookupSlot i x ((n,t):nts) + | x == n = Just (i,t) + | otherwise = lookupSlot (i+1) x nts + slot gc i = parens (parens (genericClosureCType gc) <> gen env e) <> text "->" <> text ("p" ++ show i) + +posParNames :: PosPar -> [Name] +posParNames (PosPar n _ _ p) = n : posParNames p +posParNames _ = [] -- Header ------------------------------------------------------------------------------------------- @@ -177,15 +322,22 @@ hStmt _ env s = empty declstub env (Class _ n q a b ddoc) = text "struct" <+> genTopName env n <> semi declstub env Def{} = empty +typedef env (Class _ n q a b ddoc) + | Just gc <- genericClosureInfoByName env n + = text "typedef" <+> genericClosureCType gc <+> genTopName env n <> semi typedef env (Class _ n q a b ddoc) = text "typedef" <+> text "struct" <+> genTopName env n <+> char '*' <> genTopName env n <> semi typedef env Def{} = empty +decl env (Class _ n q a b ddoc) + | Just _ <- genericClosureInfoByName env n + = empty decl env (Class _ n q a b ddoc) = (text "struct" <+> classname env n <+> char '{') $+$ nest 4 (vcat $ stdprefix env ++ initdef : serialize env tc : deserialize env tc : meths) $+$ char '}' <> semi $+$ inst_struct where tc = TC (NoQ n) [ tVar v | QBind v _ <- q ] - initdef : meths = fields env tc + env1 = setGtypes env (findAttrSchemas env1 (NoQ n)) + initdef : meths = fields (setInClass env1) tc properties = [ varsig env n (sctype sc) <> semi | (n, NSig sc Property _) <- fullAttrEnv env tc ] inst_struct | initNotImpl = empty | otherwise = (text "struct" <+> genTopName env n <+> char '{') $+$ @@ -193,56 +345,59 @@ decl env (Class _ n q a b ddoc) = (text "struct" <+> classname env n <+> cha char '}' <> semi initNotImpl = any hasNotImpl [ b' | Decl _ ds <- b, Def{dname=n',dbody=b'} <- ds, n' == initKW ] decl env (Def _ n q p _ (Just t) _ _ fx ddoc) - = genTypeDecl env n (exposeMsg fx t) <+> genTopName env n <+> parens (par env $ prowOf p) <> semi - where par = if isUnboxed n then uparams else params + = repType env (exposeMsg fx t) <+> genTopName env n <+> parens (repParams env $ prowOf p) <> semi +methstub env (Class _ n q a b ddoc) + | Just _ <- genericClosureInfoByName env n + = constub env t n r b + where TFun _ _ r _ t = sctype $ fst $ schemaOf env (eVar n) methstub env (Class _ n q a b ddoc) = text "extern" <+> text "struct" <+> classname env n <+> methodtable env n <> semi $+$ constub env t n r b where TFun _ _ r _ t = sctype $ fst $ schemaOf env (eVar n) methstub env Def{} = empty constub env t n r b - | null ns || hasNotImpl b = gen env t <+> newcon env n <> parens (params env r) <> semi + | null ns || hasNotImpl b = rawType env t <+> newcon env n <> parens (rawParams env r) <> semi | otherwise = empty where ns = abstractAttrs env (NoQ n) fields env c = map field (vsubst [(tvSelf,tCon c)] te) where te = fullAttrEnv env c - field (n, NDef sc Static _) = funsig env n (sctype sc) <> semi - field (n, NDef sc NoDec _) = methsig env c n (sctype sc) <> semi + field (n, NDef sc Static _) = funsig2 env (Just n) (B.rtypeOf env c n) <> semi + field (n, NDef sc NoDec _) + = methsig2 env c (Just n) (B.rtypeOf env c n) <> semi field (n, NVar t) = varsig env n t <> semi - field (n, NSig sc Static _) = funsig env n (sctype sc) <> semi - field (n, NSig sc NoDec _) = methsig env c n (sctype sc) <> semi + field (n, NSig sc Static _) = funsig2 env (Just n) (B.rtypeOf env c n) <> semi + field (n, NSig sc NoDec _) = methsig2 env c (Just n) (B.rtypeOf env c n) <> semi field (n, NSig sc Property _) = empty -funsig env n (TFun _ _ r _ t) = gen env t <+> parens (char '*' <> gen env n) <+> parens (params env r) +funsig env n (TFun _ _ r _ t) = repType env t <+> parens (char '*' <> gen env n) <+> parens (repParams env r) funsig env n t = varsig env n t -methsig env c n (TFun _ fx r _ t) = gen env (exposeMsg fx t) <+> parens (char '*' <> gen env n) <+> parens (params env $ posRow (tCon c) r) +funsig2 :: GenEnv -> Maybe Name -> Type -> Doc +funsig2 env mbn (TFun _ fx p _ t) = repType env (exposeMsg fx t) <+> parens (char '*' <> maybe empty (gen env) mbn) <+> parens (repParams env p) + +methsig env c n (TFun _ fx r _ t) = repType env (exposeMsg fx t) <+> parens (char '*' <> gen env n) <+> parens (repParams env $ posRow (tCon c) r) methsig env c n t = varsig env n t +methsig2 :: GenEnv -> TCon -> Maybe Name -> Type -> Doc +methsig2 env c mbn (TFun _ fx p _ t) + = repType env (exposeMsg fx t) <+> parens (char '*' <> maybe empty (gen env) mbn) <+> parens (repParams env (posRow (tCon c) p)) + +{- params env (TNil _ _) = empty params env (TRow _ _ _ t r@TRow{}) = gen env t <> comma <+> params env r params env (TRow _ _ _ t TNil{}) = gen env t params env (TRow _ _ _ t TVar{}) = gen env t -- Ignore param tails for now... params env t = error ("codegen unexpected row: " ++ prstr t) - -uparams env (TNil _ _) = empty -uparams env (TRow _ _ _ t r@TRow{}) = utype env t <> comma <+> uparams env r -uparams env (TRow _ _ _ t TNil{}) = utype env t -uparams env (TRow _ _ _ t TVar{}) = utype env t -- Ignore param tails for now... -uparams env t = error ("codegen unexpected row: " ++ prstr t) - -utype env t - | B.isUnboxable t = text (unboxed_c_type t) - | otherwise = gen env t +-} exposeMsg fx t = if fx == fxAction then tMsg t else t exposeMsg' t@TFun{} = t{ restype = exposeMsg (effect t) (restype t) } exposeMsg' t = t -varsig env n t = gen env t <+> gen env n +varsig env n t = storageType env t <+> gen env n stdprefix env = [gcinfo env, classid env, superlink env] @@ -291,8 +446,6 @@ gcinfoKW = primKW "GCINFO" classidKW = primKW "class_id" superclassKW = primKW "superclass" componentsKW = name "components" -serializeKW = name "__serialize__" -deserializeKW = name "__deserialize__" primAND = gPrim "AND" primOR = gPrim "OR" @@ -315,6 +468,8 @@ tmpV = primKW "tmp" tSerialstate = tCon $ TC (GName mPrim (name "Serial$state")) [] primStepSerialize = gPrim "step_serialize" primStepDeserialize = gPrim "step_deserialize" +primValSerialize = gPrim "val_serialize" +primValDeserialize = gPrim "val_deserialize" primDNEW = gPrim "DNEW" primNEWTUPLE = gPrim "NEWTUPLE" primNEWTUPLE0 = gPrim "NEWTUPLE0" @@ -373,25 +528,61 @@ declModule env (s : ss) = vcat [ genTypeDecl env n t <+> genTopName env1 = gdefine te env +genPosPar env n d t p + | not (contextIs env CtxClass) || d == Static + = match p (posrow t) + | isInit n = gen env p + | p1 == PosNIL = genTypeDecl env x (fromJust y) <+> gen env x + | otherwise = genTypeDecl env x (fromJust y) <+> gen env x <> comma <+> match p1 (posrow t) + where PosPar x y z p1 = p + match (PosPar n (Just t) Nothing PosNIL) (TRow _ _ _ t' _) + = settype env (rawParam t' t) t <+> gen env n + match (PosPar n (Just t) Nothing r) (TRow _ _ _ t' tl) + = settype env (rawParam t' t) t <+> gen env n <> comma <+> match r tl + match PosNIL (TNil _ _) = empty + match p TVar{} = gen env p + match p t = error ("Internal error CodeGen.genPosPar: n = "++show n++", p = "++show p++", t ="++show t) + rawParam _ TUnboxed{} = True + rawParam _ _ = False + isInit (Derived _ n) = n == initKW + isInit n = n == initKW + declDecl env (Def dloc n q p KwdNIL (Just t) b d fx ddoc) - | hasNotImpl b = genTypeDecl env n t1 <+> genTopName env n <+> parens (gen env p) <> semi $+$ - text "/*" $+$ + | hasNotImpl b = t3 <+> genTopName env n <+> parens (genPosPar env n d t1 p) <> semi $+$ + text "/*" $+$ decl $+$ text "*/" | otherwise = decl - where (ss',vs) = genSuite env1 b + where methnm n@(Derived c n0) + |n0 == suffixNewact = n + |otherwise = n0 + methnm n0 = n0 + t1 = case methodType n of + Just t' -> t' + Nothing -> error "Internal error: CodeGen.declDecl" + methodType n@(Derived c n0) + | contextIs env CtxClass, + NClass q _ _ _ <- findQName (NoQ c) env + = Just $ B.rtypeOf env (TC (NoQ c) (map tVar $ qbound q)) n0 + methodType n = B.generalType env (methnm n) + (ss',vs) = genSuite env1 b decl = emit dloc $+$ - (genTypeDecl env n t1 <+> genTopName env n <+> parens (gen (setVolVars vs env) p) <+> char '{') $+$ - nest 4 ss' $+$ + t3 <+> genTopName env n <+> parens (genPosPar (setVolVars vs env) n d t1 p) <+> char '{' $+$ + nest 4 ss' $+$ char '}' - env1 = setRet t1 $ ldefine (envOf p) $ defineTVars q env - t1 = exposeMsg fx t + env1 = setRet t2 $ ldefine (envOf p) $ defineTVars q env + t2 = exposeMsg fx t + t3 = (if isVolVar n env then text "volatile" else empty) <+> settype env (rawReturn (restype t1)) t2 + rawReturn TUnboxed{} = True + rawReturn _ = False emit = getLineEmit env declDecl env (Class _ n q as b ddoc) - | cDefinedClass = vcat [ declDecl env1 d{ dname = methodname n (dname d) } | Decl _ ds <- b', d@Def{} <- ds ] $+$ + | Just gc <- genericClosureInfoByName env n + = declGenericClosure env n q b gc + | cDefinedClass = vcat [ declDecl env2 d{ dname = methodname n (dname d) } | Decl _ ds <- b', d@Def{} <- ds ] $+$ text "struct" <+> classname env n <+> methodtable env n <> semi - | otherwise = vcat [ declDecl env1 d{ dname = methodname n (dname d) } | Decl _ ds <- b', d@Def{} <- ds ] $+$ + | otherwise = vcat [ declDecl env2 d{ dname = methodname n (dname d) } | Decl _ ds <- b', d@Def{} <- ds ] $+$ declSerialize env1 n c props sup_c $+$ declDeserialize env1 n c props sup_c $+$ declCleanup env1 n sup_c $+$ @@ -399,12 +590,30 @@ declDecl env (Class _ n q as b ddoc) text "struct" <+> classname env n <+> methodtable env n <> semi where b' = vsubst [(tvSelf, tCon c)] b c = TC (NoQ n) (map tVar $ qbound q) - env1 = defineTVars q env - props = [ n | (n, NSig sc Property _) <- fullAttrEnv env c ] + env1 = setInClass (defineTVars q env) + env2 = setGtypes env1 (findAttrSchemas env1 (NoQ n)) + props = [ (n,sctype sc) | (n, NSig sc Property _) <- fullAttrEnv env c ] sup_c = filter ((`elem` special_repr) . tcname) as special_repr = [primActor] -- To be extended... cDefinedClass = inBuiltin env && any hasNotImpl [b' | Decl _ ds <- b, Def{dname=n',dbody=b'} <- ds, n' == initKW ] +declGenericClosure env n q b gc = vcat [ declDecl env2 d{ dname = methodname n (dname d) } + | Decl _ ds <- b', d@Def{} <- ds + , dname d `elem` genericClosureMethods gc ] $+$ + declGenericClosureCon env1 n gc + where b' = vsubst [(tvSelf, tCon c)] b + c = TC (NoQ n) (map tVar $ qbound q) + env1 = setInClass (defineTVars q env) + env2 = setGtypes env1 (findAttrSchemas env1 (NoQ n)) + +declGenericClosureCon env n gc = rawType env t <+> newcon env n <> parens (gen env pars) <+> char '{' $+$ + nest 4 (text "return" <+> parens (genTopName env n) <> genericClosureNew gc <> parens (hsep $ punctuate comma (fnArg : slotArgs)) <> semi) $+$ + char '}' + where TFun _ _ r _ t = sctype $ fst $ schemaOf env (eVar n) + pars = pPar paramNames r + fnArg = parens (genericClosureFnType gc) <> genTopName env (methodname n (genericClosureBodyMethod gc)) + slotArgs = [ parens word <> gen env p | p <- posParNames pars ] + declCleanup env n sup_c -- TODO: only match if this is an actor, or even better if this actor has a __cleanup__ method defined (not empty!?) | not (null sup_c) = -- Only for actors @@ -418,7 +627,7 @@ declCleanup env n sup_c where self = name "self" declSerialize env n c props sup_c = (text "void" <+> genTopName env (methodname n serializeKW) <+> parens (gen env pars) <+> char '{') $+$ - nest 4 (super_step $+$ vcat [ step i | i <- props \\ super_attrs ]) $+$ + nest 4 (super_step $+$ vcat [ step i | i <- props, fst i `notElem`super_attrs ]) $+$ char '}' where pars = PosPar self (Just $ tCon c) Nothing $ PosPar st (Just tSerialstate) Nothing PosNIL st = name "state" @@ -426,10 +635,12 @@ declSerialize env n c props sup_c = (text "void" <+> genTopName env (methodnam super_step | [c] <- sup_c = serializeSup env (tcname c) <> parens (parens (gen env $ tcname c) <> gen env self <> comma <+> gen env st) <> semi | otherwise = empty super_attrs = [ i | c <- sup_c, i <- conAttrs env (tcname c) ] - step i = gen env primStepSerialize <> parens (gen env self <> text "->" <> gen env i <> comma <+> gen env st) <> semi + step (i,t) + | B.isUnboxable t = gen env primValSerialize <> parens (text (class_id t) <> comma <+> text "&" <> gen env self <> text "->" <> gen env i <> comma <+> gen env st) <> semi + | otherwise = gen env primStepSerialize <> parens (gen env self <> text "->" <> gen env i <> comma <+> gen env st) <> semi declDeserialize env n c props sup_c = (gen env (tCon c) <+> genTopName env (methodname n deserializeKW) <+> parens (gen env pars) <+> char '{') $+$ - nest 4 (optcreate $+$ super_step $+$ vcat [ step i | i <- props \\ super_attrs ] $+$ ret) $+$ + nest 4 (word <+> gen env tmpV <> semi $+$ optcreate $+$ super_step $+$ vcat [ step i | i <- props, fst i `notElem` super_attrs ] $+$ ret) $+$ char '}' where pars = PosPar self (Just $ tCon c) Nothing $ PosPar st (Just tSerialstate) Nothing PosNIL st = name "state" @@ -447,12 +658,18 @@ declDeserialize env n c props sup_c = (gen env (tCon c) <+> genTopName env (meth super_step | [c] <- sup_c = deserializeSup env (tcname c) <> parens (parens (gen env $ tcname c) <> gen env self <> comma <+> gen env st) <> semi | otherwise = empty super_attrs = [ i | c <- sup_c, i <- conAttrs env (tcname c) ] - step i = gen env self <> text "->" <> gen env i <+> text "=" <+> gen env primStepDeserialize <> parens (gen env st) <> semi + step (i,t) + | B.isUnboxable t = gen env tmpV <+> text "=" <+> gen env primValDeserialize <> parens (gen env st) <> semi $+$ + text "memcpy" <> parens (text "&" <> gen env self <> text "->" <> gen env i <> comma <+> text "&" <> gen env tmpV <> comma <+> text "sizeof" <> parens (gen env self <> text "->" <> gen env i)) <> semi + | otherwise = gen env self <> text "->" <> gen env i <+> text "=" <+> gen env primStepDeserialize <> parens (gen env st) <> semi ret = text "return" <+> gen env self <> semi initTables env [] = empty -initTables env (Decl _ ds : ss) = vcat [ char '{' $+$ nest 4 (initClassBase env1 n q as hC $+$ initClass env1 n b hC) $+$ char '}' | Class _ n q as b ddoc <- ds, let hC = hasCDef b ] $+$ +initTables env (Decl _ ds : ss) = vcat [ char '{' $+$ nest 4 (initClassBase env1 n q as hC $+$ initClass env1 n q b hC) $+$ char '}' + | Class _ n q as b ddoc <- ds + , Nothing <- [genericClosureInfoByName env1 n] + , let hC = hasCDef b ] $+$ initTables env1 ss where env1 = gdefine (envOf ds) env hasCDef b = inBuiltin env && any hasNotImpl [b' | Decl _ ds <- b, Def{dname=n',dbody=b'} <- ds, n' == initKW ] @@ -473,30 +690,44 @@ initGlobals env (s : ss) = genStmt1 env s $+$ initClassBase env c q as hasCDef = methodtable env c <> dot <> gen env gcinfoKW <+> equals <+> doubleQuotes (genTopName env c) <> semi $+$ methodtable env c <> dot <> gen env superclassKW <+> equals <+> super <> semi $+$ vcat [ inherit c' n | (c',n) <- inheritedAttrs env (NoQ c) ] - where super = if null as then text "NULL" else parens (gen env qnSuperClass) <> text "&" <> methodtable' env (tcname $ head as) - selfsubst = selfSubst (NoQ c) q + where tc = TC (NoQ c) [ tVar v | QBind v _ <- q ] + super = if null as then text "NULL" else parens (gen env qnSuperClass) <> text "&" <> methodtable' env (tcname $ head as) inherit c' n | hasCDef = methodtable env c <> dot <> gen env n <+> equals <+> genTopName env (methodname c n) <> semi - | otherwise = methodtable env c <> dot <> gen env n <+> equals <+> cast (fromJust $ lookup n te) <> methodtable' env c' <> dot <> gen env n <> semi - cast (NSig sc dec _) = parens (gen env (selfsubst $ addSelf (sctype sc) (Just dec))) - cast (NDef sc dec _) = parens (gen env (selfsubst $ addSelf (sctype sc) (Just dec))) - cast (NVar t) = parens (gen env $ selfsubst t) - te = fullAttrEnv env $ TC (NoQ c) [ tVar v | QBind v _ <- q ] + | otherwise = methodtable env c <> dot <> gen env n <+> equals <+> inheritedCast n <> methodtable' env c' <> dot <> gen env n <> semi + inheritedCast n = case lookup n (fullAttrEnv env tc) of + Just (NVar t) -> parens (gen env (vsubst [(tvSelf,tCon tc)] t)) + _ -> methodCast env c q n -initClass env c [] hasCDef = vcat [ methodtable env c <> dot <> gen env n <+> equals <+> genTopName env (methodname c n) <> semi | n <- [serializeKW,deserializeKW] ] $+$ +initClass env c q [] hasCDef = vcat [ methodtable env c <> dot <> gen env n <+> equals <+> genTopName env (methodname c n) <> semi | n <- [serializeKW,deserializeKW] ] $+$ if hasCDef then empty else gen env primRegister <> parens (char '&' <> methodtable env c) <> semi -initClass env c (Decl _ ds : ss) b = vcat [ methodtable env c <> dot <> gen env n <+> equals <+> genTopName env (methodname c n) <> semi | Def{dname=n} <- ds ] $+$ - initClass env1 c ss b +initClass env c q (Decl _ ds : ss) b + = vcat [ methodAssign env c q n | Def{dname=n} <- ds ] $+$ + initClass env1 c q ss b where env1 = gdefine (envOf ds) env -initClass env c (Signature{} : ss) b = initClass env c ss b -initClass env c (s : ss) b - | isNotImpl s = initClass env c ss b +initClass env c q (Signature{} : ss) b = initClass env c q ss b +initClass env c q (s : ss) b + | isNotImpl s = initClass env c q ss b | otherwise = genStmt1 env s $+$ vcat [ genTopName env c <> dot <> gen env n <+> equals <+> gen env n <> semi | (n,_) <- te ] $+$ - initClass env1 c ss b + initClass env1 c q ss b where te = excludeDefined env (envOf s) env1 = ldefine te env +-- A direct method implementation can have a more specific C signature than the +-- class-table slot, for example when a method returns Self. The table slot is +-- the public ABI, so cast the generated function pointer to that shape. +methodAssign env c q n = methodtable env c <> dot <> gen env n <+> equals <+> methodCast env c q n <> genTopName env (methodname c n) <> semi + +methodCast env c q n = case lookup n (fullAttrEnv env tc) of + Just (NDef _ Static _) -> parens (funsig2 env Nothing rt) + Just (NSig _ Static _) -> parens (funsig2 env Nothing rt) + Just (NDef _ _ _) -> parens (methsig2 env tc Nothing rt) + Just (NSig _ _ _) -> parens (methsig2 env tc Nothing rt) + _ -> empty + where tc = TC (NoQ c) (map tVar $ qbound q) + rt = B.rtypeOf env tc n + initFlag = name "done$" @@ -523,7 +754,7 @@ instance Gen QName where | otherwise = gen env m <> text "Q_" <> text (mkCident $ nstr n) gen env (NoQ n) = gen env n gen env n@QName{} - | n `elem` B.mathfuns = text (nstr (noq n)) +-- | n `elem` B.mathfuns = text (nstr (noq n)) | otherwise = gen env (unalias env n) instance Gen Name where @@ -631,17 +862,16 @@ genSuite env (s:ss) = ((emit (sloc s) $+$ c) $+$ cs, vs' ++ filt (c,vs') = genStmt (setVolVars vs env) s emit = getLineEmit env -genTypeDecl env n t = (if isVolVar n env then text "volatile" else empty) <+> - if isUnboxed n && B.isUnboxable t then text (unboxed_c_type t) else gen env t - +genTypeDecl env n t = (if isVolVar n env then text "volatile" else empty) <+> storageType env t genStmt env (Decl _ ds) = (empty, []) genStmt env (Assign _ [PVar _ n (Just t)] e) - | not (isDefined env n) = (genTypeDecl env n t <+> gen env n <+> equals <+> rhs <> semi, []) + | not (n `HashSet.member` localDefined env) + = (genTypeDecl env n t <+> gen env n <+> equals <+> rhs <> semi, []) where rhs = if isWitness n then case staticWitnessName e of (Just nm,as) -> - foldr (\x y -> y <> text "->" <> myPretty x) (parens (myPretty (tcname (tcon t))) <> myPretty (witName nm)) as + foldr (\x y -> y <> text "->" <> myPretty x) (parens (myPretty ( tcname (tcon t))) <> myPretty (witName nm)) as _ -> genExp env t e else genExp env t e genStmt env s = (vcat [ genTypeDecl env n t <+> gen env n <> semi | (n,NVar t) <- te ] $+$ s', vs) @@ -654,12 +884,18 @@ genStmt1 env s = fst $ genStmt env s instance Gen Stmt where genV env s | isNotImpl s = (text "//" <+> text "NotImplemented", []) genV env (Expr _ Strings{}) = (semi, []) + genV env (Expr _ e) + | isRAISE e = (genExp' env e <> semi $+$ text "__builtin_unreachable();" , []) genV env (Expr _ e) = (genExp' env e <> semi, []) genV env (Assign _ [p] e) - | B.isUnboxable t = (gen env p <+> equals <+> gen env e <> semi, []) + | isUnboxedRep t = (gen env p <+> equals <+> gen env e <> semi, []) | otherwise = (gen env p <+> equals <+> genExp env t e <> semi, []) where t = typeOf env p + genV env (AugAssign _ tg op e) + | boxedRepType (targetType env tg) == tU1, + Just d <- genU1RawAugOp env op tg e + = (genTarget env tg <+> equals <+> d <> semi, []) genV env (AugAssign _ tg op e) = (genTarget env tg <+> augPretty op <+> genExp env t e <> semi, []) where t = targetType env tg genV env (MutAssign _ tg e) = (genTarget env tg <+> equals <+> genExp env t e <> semi, []) @@ -761,20 +997,168 @@ castLit env (Strings l ss) p = format (concat ss) p where expr = parens (parens (gen env tStr) <> gen env e) <> text "->str" conv ('%':s) p = format s p +-- Helpers for choosing the C representation at call boundaries. +-- +-- Boxing decides where Acton values are represented raw in the IR, but CodeGen +-- still has to match the C ABI of the callee. The predicates below describe +-- the representation generated by an expression, not just its Acton type. + +-- Render normal call arguments against the formal positional row. Only +-- parameters whose formal type is TUnboxed are forced to raw C values. +genCallPosArgs env (TRow _ _ _ t r) (PosArg e PosNil) + = genCallArg env t e +genCallPosArgs env (TRow _ _ _ t r) (PosArg e p) + = genCallArg env t e <> comma <+> genCallPosArgs env r p +genCallPosArgs env _ p = gen env p + +-- Render constructor arguments. Constructor C signatures use raw values for +-- unboxable Acton types even when the source-level parameter type is boxed. +genUCallPosArgs env (TRow _ _ _ t r) (PosArg e PosNil) + = genUCallArg env t e +genUCallPosArgs env (TRow _ _ _ t r) (PosArg e p) + = genUCallArg env t e <> comma <+> genUCallPosArgs env r p +genUCallPosArgs env _ p = gen env p + +-- Render one normal call argument. A TUnboxed formal parameter must receive a +-- raw C value; if the actual expression is not already raw, emit an UnBox. +genCallArg env TUnboxed{} e@UnBox{} = gen env e +genCallArg env (TUnboxed _ t) (Box _ e) + | boxedExpr env e = gen env (UnBox t e) + | otherwise = gen env e +genCallArg env (TUnboxed _ t) e + | rawExpr env e = gen env e + | otherwise = gen env (B.unbox t e) +genCallArg env _ e = gen env e + +-- Render one constructor argument in the representation used by generated +-- constructors: raw for unboxable values, normal boxed generation otherwise. +genUCallArg env t e + | B.isUnboxable t' = genRawExpr env e + | otherwise = gen env e + where t' = boxedRepType t + +-- Generate an expression as raw C when its boxed representation is unboxable. +-- Already-raw expressions are left alone; boxed values are unboxed here. +genRawExpr env e + | rawExpr env e = gen env e + | B.isUnboxable t = gen env (B.unbox t e) + | otherwise = gen env e + where t = boxedRepType (typeOf env e) + +-- Generate a raw C expression for a known target representation. This is +-- needed when the expression's own source type is boxed or optional, but the +-- surrounding context has established that the C value must be raw. +genRawExprAs env t e + | rawExpr env e = gen env e +genRawExprAs env t (Box _ e) + | boxedExpr env e = gen env (B.unbox t' e) + | otherwise = genRawExprAs env t' e + where t' = boxedRepType t +genRawExprAs env t e = gen env (B.unbox t' e) + where t' = boxedRepType t + +-- True when gen will already produce the raw C representation for this +-- expression. Operations are raw only when their operands/branches are raw. +rawExpr env UnBox{} = True +rawExpr env (Var _ n) = unboxedVar env n +rawExpr env (Dot _ e n) = unboxedField env e n +rawExpr env (Paren _ e) = rawExpr env e +rawExpr env c@(Call _ f _ KwdNil) + | rawClassConstructor env c f = True + | callableReturnsRaw env f = True +rawExpr env (Call _ (Var _ n) _ KwdNil) + | n == primUNext = True +rawExpr env (BinOp _ e1 op e2) + | op `notElem` [And, Or] = rawExpr env e1 && rawExpr env e2 +rawExpr env (UnOp _ op e) + | op /= Not = rawExpr env e +rawExpr env (Cond _ e1 _ e2) = rawExpr env e1 && rawExpr env e2 +rawExpr env _ = False + +-- True when gen is known to produce a boxed Acton value. This is used to +-- avoid double boxing and to decide whether an explicit UnBox is meaningful. +boxedExpr env (Var _ n) = not $ unboxedVar env n +boxedExpr env (Dot _ e n) = not $ unboxedField env e n +boxedExpr env DotI{} = True +boxedExpr env (Paren _ e) = boxedExpr env e +boxedExpr env Box{} = True +boxedExpr env (Call _ (TApp _ (Var _ n) _) _ KwdNil) + | n == primCAST = True + | n == primUGetItem = True +boxedExpr env (Call _ (Var _ n) _ KwdNil) + | n == primUNext = False + | n == primUGetItem = True +boxedExpr env c@(Call _ f _ KwdNil) + | rawClassConstructor env c f = False +boxedExpr env (Call _ f _ KwdNil) = callReturnsBoxed env f +boxedExpr env _ = False + +-- Some builtin class constructors, such as int/u64/i16, are written as class +-- calls in Acton but return the raw C value for their unboxable result type. +rawClassConstructor env c f = callIsClass env f && B.isUnboxable (boxedRepType (typeOf env c)) + +-- Class calls normally return boxed objects. Non-class calls are classified by +-- their callable return type. +callReturnsBoxed env f@(TApp _ f0 _) + | callIsClass env f0 = True + | otherwise = callableReturnsBoxed env f +callReturnsBoxed env f@(Var _ n) + | NClass{} <- findQName n env = True + | otherwise = callableReturnsBoxed env f +callReturnsBoxed env f = callableReturnsBoxed env f + +-- Identify class constructor calls, ignoring type application wrappers. +callIsClass env (TApp _ f _) = callIsClass env f +callIsClass env (Var _ n) = case findQName n env of + NClass{} -> True + _ -> False +callIsClass env _ = False + +-- A normal callable returning an unboxable Acton type returns the boxed object +-- unless its type has already been changed to TUnboxed. +callableReturnsBoxed env f = case B.rtypeOfFun env f of + TFun _ _ _ _ t -> B.isUnboxable t + _ -> False + +-- A callable whose return type is explicitly TUnboxed returns raw C. +callableReturnsRaw env f = case B.rtypeOfFun env f of + TFun _ _ _ _ TUnboxed{} -> True + _ -> False + +-- Compute the C-facing callable type used for argument rendering. Public +-- polymorphic callables are matched against a wildcard instantiation so +-- polymorphic positions keep their boxed ABI; internal/generated functions and +-- selected C primitives use the fully instantiated type directly. +genCallableType env ts e@(Var _ n) + | boxedCPrim n = typeInstOf env ts e + | isInternalQName n = B.matchTypes t t + | otherwise = B.matchTypes t t0 + where t = typeInstOf env ts e + t0 = typeInstOf env (map (const tWild) ts) e +genCallableType env ts e = typeInstOf env ts e + +boxedCPrim n = n `elem` [primAFTER, primAFTERc, primAFTERf] + +isInternalQName (NoQ n) = isInternal n +isInternalQName (GName _ n) = isInternal n +isInternalQName (QName _ n) = isInternal n + genCall env [] (TApp _ e ts) p = genCall env ts e p genCall env [_,t] (Var _ n) (PosArg e PosNil) - | n == primCAST = parens (parens (genTypeDecl env (noq n) t) <> gen env e) + | n == primCAST = parens (parens (gen env t) <> gen env e) genCall env [row] (Var _ n) (PosArg s@Strings{} (PosArg tup PosNil)) | n == primFORMAT = gen env n <> parens (genStr env (formatLit s) <> castLit env s (flatten tup)) - where unbox (TNil _ _) p = empty - unbox (TRow _ _ _ t r) (PosArg e p) - | t == tStr = comma <+> expr <> text "->str" <> unbox r p - | otherwise = comma <+> expr <> text "->val" <> unbox r p - where expr = parens (parens (gen env t) <> gen env e) + where -- unbox (TNil _ _) p = empty + -- unbox (TRow _ _ _ t r) (PosArg e p) + -- | t == tStr = comma <+> expr <> text "->str" <> unbox r p + -- | otherwise = comma <+> expr <> text "->val" <> unbox r p + -- where expr = parens (parens (gen env t) <> gen env e) flatten (Tuple _ p KwdNil) = p flatten e = foldr PosArg PosNil $ map (DotI l0 e) [0..] genCall env [t] (Var _ n) PosNil | n == primNEWACTOR = gen env n <> parens (gen env t) +genCall env ts (Var _ n) (PosArg e (PosArg ix PosNil)) + | n == primUGetItem = gen env n <> parens (gen env e <> comma <+> genRawExprAs env tInt ix) -- Only install GCfinalizer if one is defined, i.e. we don't have the default -- $ActorD___cleanup__ -- TODO: would be even better to determine this in the compiler and not emit @@ -783,21 +1167,18 @@ genCall env [TCon _ tc] (Var _ n) p | n == primInstallFinalizer = text "if" <+> parens (text "(void*)" <> gen env p <> text "->" <> gen env classKW <> text "->" <> gen env cleanupKW <+> text "!= (void*)$ActorD___cleanup__") <+> gen env n <> parens (gen env p <> comma <+> genTopName env (methodname (noq $ tcname tc) attr_finalizer)) genCall env ts e@(Var _ n) p | NClass{} <- info = genNew env n p - | NDef{} <- info = (instCast env ts e $ gen env e) <> parens (gen env p) + | NDef{} <- info = (instCast env ts e $ gen env e) <> parens (genCallPosArgs env r p) where info = findQName n env + TFun _ _ r _ _ = genCallableType env ts e genCall env ts (Async _ e) p = genCall env ts e p genCall env ts e0@(Dot _ e n) p = genDotCall env ts (snd $ schemaOf env e0) e n p genCall env ts e p = gen env e <> parens (gen env p) instCast env [] e = id instCast env ts e@(Var _ x) - | x == primUGetItem = case typeInstOf env ts e of - TFun _ fx (TRow _ _ _ t1 (TRow _ _ _ t2 _)) _ r -> - parens . (parens (gen env r <+> parens (char '*') <+> parens (gen env t1 <> comma <+> text (unboxed_c_type t2))) <>) - t -> error("Interal error: unexpected typecast for list indexing") | GName m _ <- x, m == mPrim = id instCast env ts e = parens . (parens (gen env t) <>) - where t = typeInstOf env ts e + where t = B.matchTypes (typeInstOf env ts e) (typeInstOf env (map (\_ -> tWild) ts) e) -- to cast to the general type targetType env (Dot _ e n) = sctype sc where t0 = typeOf env e @@ -807,23 +1188,71 @@ targetType env (Dot _ e n) = sctype sc (sc, dec) = findAttr' env c0 n targetType env e = typeOf env e -- Must be a Var with a monomorphic type since it is assignable +isUnboxedRep :: Type -> Bool +isUnboxedRep TUnboxed{} = True +isUnboxedRep t = B.isUnboxable t + +boxedRepType :: Type -> Type +boxedRepType (TUnboxed _ t) = t +boxedRepType t = t + +unboxedField :: GenEnv -> Expr -> Name -> Bool +unboxedField env e n = maybe False (isUnboxedRep . sctype . fst) (fieldAttr env e n) + +unboxedVar :: GenEnv -> QName -> Bool +unboxedVar env n = case findQName n env of + NVar t -> isRawVar t + NSVar t -> isRawVar t + _ -> False + where isRawVar TUnboxed{} = True + isRawVar t = isGlobalVar n && B.isUnboxable t + isGlobalVar (NoQ n) = isGlobal env n + isGlobalVar GName{} = True + isGlobalVar QName{} = True + +fieldAttr :: GenEnv -> Expr -> Name -> Maybe (TSchema, Maybe Deco) +fieldAttr env e n = case typeOf env e of + TCon _ tc -> Just $ findAttr' env (snd $ splitTC env tc) n + TVar _ tv -> Just $ findAttr' env (snd $ splitTC env (findTVBound env tv)) n + _ -> Nothing + dotCast env ent ts (Var _ x) n | GName m _ <- x, m == mPrim = id dotCast env ent ts e n - | t == t1 = id - | gen_t == gen env t1 = id + | gen_t == gen env t1, + not (needsPrimCallableCast t0 n) = id | otherwise = parens . (parens gen_t <>) where t0 = typeOf env e - (argsubst, c0) = case t0 of - TCon _ tc -> splitTC env tc - TVar _ tv -> splitTC env (findTVBound env tv) - TTuple{} -> ([], cValue) + (argsubst, c0, rtc) = case t0 of + TCon _ tc -> let (s,c) = splitTC env tc in (s, c, tc) + TVar _ tv -> let tc = findTVBound env tv + (s,c) = splitTC env tc + in (s, c, tc) + TTuple{} -> ([], cValue, cValue) (sc, dec) = findAttr' env c0 n t = vsubst fullsubst $ if ent then addSelf t1 dec else t1 t1 = exposeMsg' (sctype sc) + t' sc' = if ent then addSelf (t1' sc') dec else t1' sc' + t1' sc' = exposeMsg' (sctype sc') fullsubst = (tvSelf,t0) : (qbound (scbind sc) `zip` ts) ++ argsubst - gen_t = gen env t - + te = findAttrSchemas env (tcname c0) + gen_t + | null ts = gen env $ if ent then addSelf rt dec else rt + | otherwise = case lookup n te of + Just (NDef sc' _ _) -> gen env (B.matchTypes t (sctype sc')) + Just (NSig sc' _ _) -> gen env (B.matchTypes t (t' sc')) + Just (NVar t) -> gen env t + ni -> error ("Internal error in CodeGen.dotCast: looking for NameInfo for " ++ show n ++ ", found "++ show ni) + rt = exposeMsg' (B.rtypeOf env rtc n) + +needsPrimCallableCast (TCon _ (TC q _)) n + | q == primCont = n == attr_call_ + | q == primProc = n `elem` [attr_call_, attr_exec_] + | q == primAction = n `elem` [attr_call_, attr_exec_, attr_asyn_] + | q == primMut = n `elem` [attr_call_, attr_exec_, attr_eval_] + | q == primPure = n `elem` [attr_call_, attr_exec_, attr_eval_] +needsPrimCallableCast _ _ = False + classCast env ts x q n = parens . (parens (gen env t) <>) where (ts0,ts1) = splitAt (length q) ts tc = TC x ts0 @@ -831,7 +1260,8 @@ classCast env ts x q n = parens . (parens (gen env t) <>) t = vsubst fullsubst $ addSelf (sctype sc) dec fullsubst = (tvSelf,tCon tc) : (qbound (scbind sc) `zip` ts1) -genNew env n p = newcon' env n <> parens (gen env p) +genNew env n p = newcon' env n <> parens (genUCallPosArgs env r p) + where TFun _ _ r _ _ = sctype $ fst $ schemaOf env (Var NoLoc n) declCon env n q b | null abstr || hasNotImpl b = (gen env tRes <+> newcon env n <> parens (gen env pars) <+> char '{') $+$ @@ -871,15 +1301,24 @@ genDotCall env ts dec e@(Var _ x) n p where info = findQName x env genDotCall env ts dec e n p | Just NoDec <- dec = genEnter env ts e n p - | Just Static <- dec = dotCast env False ts e n (gen env e <> text "->" <> gen env classKW <> text "->" <> gen env n) <> parens (gen env p) + | Just Static <- dec = dotCast env False ts e n (genReceiver env e <> text "->" <> gen env classKW <> text "->" <> gen env n) <> parens (gen env p) genDot env ts e@(Var _ x) n | NClass q _ _ _ <- findQName x env = classCast env ts x q n $ methodtable' env x <> text "." <> gen env n -genDot env ts e n = dotCast env False ts e n $ gen env e <> text "->" <> gen env n +genDot env ts e n + | Just d <- genericClosureSlotAccess env e n + = d +genDot env ts e n = dotCast env False ts e n $ genReceiver env e <> text "->" <> gen env n -- NOTE: all method references are eta-expanded by the lambda-lifter at this point, so n cannot be a method (i.e., require methodtable lookup) here -genTarget env (Dot _ e n) = gen env e <> text "->" <> gen env n +genReceiver env e = parens (parens (gen env t) <> parens (gen env e)) + where t = boxedRepType (typeOf env e) + +genTarget env (Dot _ e n) + | Just d <- genericClosureSlotAccess env e n + = d +genTarget env (Dot _ e n) = genReceiver env e <> text "->" <> gen env n genTarget env e = gen env e @@ -892,13 +1331,19 @@ genEnter env ts e n p costly e = True t = typeOf env e env1 = ldefine [(tmpV,NVar t)] env -genEnter env ts e n p = dotCast env True ts e n (gen env e <> text "->" <> gen env classKW <> text "->" <> gen env n) <> parens (gen env e <> comma' (gen env p)) +genEnter env ts e n p = dotCast env True ts e n (genReceiver env e <> text "->" <> gen env classKW <> text "->" <> gen env n) <> parens (gen env e <> comma' (genCallPosArgs env r p)) + where TFun _ _ r _ _ = dotCallRType env ts e n + +dotCallRType env [] e n = B.rtypeOfFun env (Dot NoLoc e n) +dotCallRType env ts e n = B.rtypeOfFun env (TApp NoLoc (Dot NoLoc e n) ts) genInst env ts e@Var{} = instCast env ts e $ gen env e genInst env ts (Dot _ e n) = genDot env ts e n adjust t t' e | t == t' = e +adjust (TUnboxed _ t) t' e = adjust t t' e +adjust t (TUnboxed _ t') e = adjust t t' e adjust (TOpt _ t) t' e = adjust t t' e adjust t (TOpt _ t') e = adjust t t' e adjust TNone{} t' e = e @@ -915,6 +1360,8 @@ genExp env t' e = gen env (adjust t t' e') genExp' env e = gen env e' where (t, fx, e') = qType env adjust e +genBoxed env t e = text ("toB_"++render(pretty (noq (tcname(tcon (boxedRepType t)))))) <> parens e + instance Gen Expr where gen env (Var _ n) | NClass{} <- findQName n env = newcon' env n @@ -941,8 +1388,8 @@ instance Gen Expr where gen env (Let _ ss e) = text "({" <+> fst(genSuite env ss) $+$ gen (ldefine (envOf ss) env) e <> text ";})" gen env (IsInstance _ e c) = gen env primISINSTANCE <> parens (gen env e <> comma <+> genQName env c) gen env (Dot _ e n) = genDot env [] e n - gen env e0@(DotI _ e i) = parens $ parens (gen env t) <> gen env e <> text "->" <> gen env componentsKW <> brackets (pretty i) - where t = typeOf env e0 + gen env e0@(DotI _ e i) = parens $ parens (parens (gen env t) <> parens (gen env e)) <> text "->" <> gen env componentsKW <> brackets (pretty i) + where t = boxedRepType (typeOf env e) gen env (RestI _ e i) = gen env eNone <> semi <+> text "// CodeGen for tuple tail not implemented" gen env (Tuple _ p KwdNil) | n == 0 = gen env primNEWTUPLE0 @@ -954,12 +1401,17 @@ instance Gen Expr where gen env (BinOp _ e1 Or e2) = gen env primOR <> parens (gen env t <> comma <+> gen env e1 <> comma <+> gen env e2) where t = typeOf env e1 gen env (BinOp _ e1 op e2) + | boxedRepType t == tU1, + Just d <- genU1RawBinOp env op e1 e2 + = d | op == Div && t /= tFloat || op `elem` [Pow, Mod, EuDiv] -- Pow since there is no C operator, the others since they need to check for division by zero = gencFunCall env (tstr ++ '_' : opstr op) [e1, e2] + | B.isUnboxable (boxedRepType t) + = castRawResult t (genRawExpr env e1 <+> binPretty op <+> genRawExpr env e2) | otherwise = gen env e1 <+> binPretty op <+> gen env e2 where t = typeOf env e1 - tstr = nstr (noq (tcname (tcon t))) + tstr = nstr (noq (tcname (tcon (boxedRepType t)))) opstr Pow = "pow" opstr Div = "DIV" opstr Mod = "MOD" @@ -967,15 +1419,30 @@ instance Gen Expr where gen env (CompOp _ e [a]) = gen env e <+> gen env a gen env (UnOp _ Not e) = gen env primNOT <> parens (gen env t <> comma <+> gen env e) where t = typeOf env e + gen env (UnOp _ op e) + | t == tU1 + = genU1RawUnOp env op e + | B.isUnboxable t = castRawResult t (genRawUnOp env op e) + where t = boxedRepType (typeOf env e) + gen env (UnOp _ op e) = parens (pretty op <+> gen env e) gen env (Cond _ e1 e e2) = parens (parens (gen env (B.unbox tBool e)) <+> text "?" <+> gen env e1 <+> text ":" <+> gen env e2) gen env (Paren _ e) = parens (gen env e) - gen env (Box t e) = text ("toB_"++render(pretty (noq (tcname(tcon t))))) <> parens (gen env e) + gen env (Box t i@Int{}) + | B.isUnboxable t' = genBoxed env t' (gen env (UnBox t' i)) + where t' = boxedRepType t + gen env (Box t f@Float{}) + | B.isUnboxable t' = genBoxed env t' (gen env (UnBox t' f)) + where t' = boxedRepType t + gen env (Box t e) + | boxedExpr env e = gen env e + | otherwise = genBoxed env t (gen env e) gen env (UnBox _ e@(Call _ (Var _ f) p KwdNil)) | f == primISNOTNONE = genCall env [] (Var NoLoc primISNOTNONE0) p | f == primISNONE = genCall env [] (Var NoLoc primISNONE0) p + | f == primUNext = genCall env [] e p | f `elem` [primPUSH,primPUSHF] = gen env f <> parens(empty) - | f `elem` B.mathfuns = genCall env [] e p + -- | f `elem` B.mathfuns = genCall env [] e p | tCon (TC (gBuiltin (noq f)) []) `elem` B.integralTypes -- f is the constructor for an integer type, so check if argument e is a literal = genUnboxedInt env (posargs p) e gen env (UnBox t e@(Call _ (Dot _ (Var _ w) op) (PosArg x (PosArg y PosNil)) KwdNil)) -- use macro for int (in)equality tests @@ -988,22 +1455,68 @@ instance Gen Expr where gen env (UnBox _ (IsInstance _ e c)) = gen env primISINSTANCE0 <> parens(gen env e <> comma <+> genQName env c) - gen env (UnBox t (Int _ n s)) = text (s++ suffix t) - where suffix t - | t == tInt = "LL" - | t == tU64 = "UL" - | otherwise = "" + gen env (UnBox t (Int _ n s)) = genUnboxedIntLiteral t n s gen env (UnBox _ (Float _ x s)) = text s gen env (UnBox _ (Bool _ b)) = if b then text "true" else text "false" - gen env (UnBox _ v@(Var _ (NoQ n))) - | isUnboxed n = gen env v + gen env (UnBox t (Cond _ e1 e e2)) + = parens (parens (gen env (B.unbox tBool e)) <+> text "?" <+> genRawExprAs env t e1 <+> text ":" <+> genRawExprAs env t e2) + gen env (UnBox _ v@(Var _ n)) + | unboxedVar env n = gen env v + gen env (UnBox _ d@(Dot _ e n)) + | unboxedField env e n = gen env d gen env (UnBox t e) = parens (parens (gen env t) <> gen env e) <> text "->val" -- gen env (UnBox t e) = parens (gen env e) <> text "->val" gen env e = error ("CodeGen.gen for Expr: e = " ++ show e) +genUnboxedIntLiteral t n s + | t == tInt && n == -9223372036854775808 + = text "(-9223372036854775807LL - 1LL)" + | t == tInt = text (s++"LL") + | t == tU64 = text (s++"UL") + | otherwise = text s + gencFunCall env nm [] = text nm <> parens empty -gencFunCall env nm (x : xs) = text nm <> parens (gen env x <> hsep [ comma <+> gen env x | x <- xs ]) +gencFunCall env nm (x : xs) = text nm <> parens (genRawExpr env x <> hsep [ comma <+> genRawExpr env x | x <- xs ]) + +genU1RawBinOp env Plus e1 e2 = Just $ genU1Norm (genU1Raw2 env "+" e1 e2) +genU1RawBinOp env Minus e1 e2 = Just $ genU1Norm (genU1Raw2 env "-" e1 e2) +genU1RawBinOp env Mult e1 e2 = Just $ genU1Norm (genU1Raw2 env "*" e1 e2) +genU1RawBinOp env BOr e1 e2 = Just $ genU1Norm (genU1Raw2 env "|" e1 e2) +genU1RawBinOp env BXor e1 e2 = Just $ genU1Norm (genU1Raw2 env "^" e1 e2) +genU1RawBinOp env BAnd e1 e2 = Just $ genU1Norm (genU1Raw2 env "&" e1 e2) +genU1RawBinOp env ShiftL e1 e2 = Just $ genU1Norm (genU1Raw2 env "<<" e1 e2) +genU1RawBinOp env ShiftR e1 e2 = Just $ genU1Norm (genU1Raw2 env ">>" e1 e2) +genU1RawBinOp _ _ _ _ = Nothing + +genU1Raw2 env op e1 e2 = genRawExpr env e1 <+> text op <+> genRawExpr env e2 + +genRawUnOp env UPlus e = genRawExpr env e +genRawUnOp env op e = parens (pretty op <+> genRawExpr env e) + +genU1RawUnOp env UPlus e = genRawExpr env e +genU1RawUnOp env UMinus e = genU1Norm (text "-" <> parens (genRawExpr env e)) +genU1RawUnOp env BNot e = genU1Norm (text "~" <> parens (genRawExpr env e)) +genU1RawUnOp env op e = parens (pretty op <+> gen env e) + +genU1RawAugOp env PlusA tg e = Just $ genU1Norm (genU1RawAug2 env "+" tg e) +genU1RawAugOp env MinusA tg e = Just $ genU1Norm (genU1RawAug2 env "-" tg e) +genU1RawAugOp env MultA tg e = Just $ genU1Norm (genU1RawAug2 env "*" tg e) +genU1RawAugOp env PowA tg e = Just $ text "u1_pow" <> parens (genTarget env tg <> comma <+> genRawExpr env e) +genU1RawAugOp env ModA tg e = Just $ text "u1_MOD" <> parens (genTarget env tg <> comma <+> genRawExpr env e) +genU1RawAugOp env EuDivA tg e = Just $ text "u1_FLOORDIV" <> parens (genTarget env tg <> comma <+> genRawExpr env e) +genU1RawAugOp env BOrA tg e = Just $ genU1Norm (genU1RawAug2 env "|" tg e) +genU1RawAugOp env BXorA tg e = Just $ genU1Norm (genU1RawAug2 env "^" tg e) +genU1RawAugOp env BAndA tg e = Just $ genU1Norm (genU1RawAug2 env "&" tg e) +genU1RawAugOp env ShiftLA tg e = Just $ genU1Norm (genU1RawAug2 env "<<" tg e) +genU1RawAugOp env ShiftRA tg e = Just $ genU1Norm (genU1RawAug2 env ">>" tg e) +genU1RawAugOp _ _ _ _ = Nothing + +genU1RawAug2 env op tg e = genTarget env tg <+> text op <+> genRawExpr env e + +genU1Norm d = parens (parens d <+> text "& 1") + +castRawResult t d = parens (parens (text (unboxed_c_type (boxedRepType t))) <> parens d) genUnboxedInt env [Int _ n s, None _] _ = text s @@ -1026,6 +1539,7 @@ augPretty op = pretty op genStr env s = text $ head $ sval s +genBool env (Paren _ e) = genBool env e genBool env e = genExp env tBool e where t = typeOf env e @@ -1054,7 +1568,7 @@ instance Gen TCon where instance Gen Type where gen env (TVar _ v) = gen env v gen env (TCon _ c) = gen env c - gen env (TFun _ _ p _ t) = gen env t <+> parens (char '*') <+> parens (gen env p) + gen env (TFun _ _ p _ t) = gen env t <+> parens (text "*") <+> parens (gen env p) gen env (TTuple _ pos _) = gen env qnTuple gen env (TOpt _ t) = gen env t gen env (TNone _) = gen env qnNoneType @@ -1062,6 +1576,7 @@ instance Gen Type where gen env (TRow _ _ _ t TNil{}) = gen env t gen env (TRow _ _ _ t r) = gen env t <> comma <+> gen env r gen env (TNil _ _) = empty + gen env (TUnboxed _ t) = text (unboxed_c_type t) unboxed_c_type t | t == tInt = "int64_t" @@ -1070,5 +1585,22 @@ unboxed_c_type t | t == tU32 = "uint32_t" | t == tI16 = "int16_t" | t == tU16 = "uint16_t" + | t == tI8 = "int8_t" + | t == tU8 = "uint8_t" + | t == tU1 = "uint8_t" -- ???? | t == tFloat = "double" +-- | t == tBool = "bool" | otherwise = error ("Internal error: trying to find unboxed type for " ++ show t) + +class_id t + | t == tInt = "I64_ID" + | t == tU64 = "U64_ID" + | t == tI32 = "I32_ID" + | t == tU32 = "U32_ID" + | t == tI16 = "I16_ID" + | t == tU16 = "U16_ID" + | t == tI8 = "I8_ID" + | t == tU8 = "U8_ID" + | t == tU1 = "U1_ID" + | t == tFloat = "FLOAT_ID" + | otherwise = error ("Internal error: trying to find class id for " ++ show t) diff --git a/compiler/lib/src/Acton/Env.hs b/compiler/lib/src/Acton/Env.hs index cb815ab55..4d36dd911 100644 --- a/compiler/lib/src/Acton/Env.hs +++ b/compiler/lib/src/Acton/Env.hs @@ -60,6 +60,7 @@ data EnvF x = EnvF { thismod :: Maybe ModName, context :: [EnvCtx], qlevel :: Int, + gtypes :: TEnv, -- when traversing definition of a class c, gtypes contains result of findAttrSchemas c env envX :: x } deriving (Show) @@ -74,7 +75,7 @@ setX env x = EnvF { activeNames = activeNames env, closedNames hnames = hnames env, closedHNames = closedHNames env, imports = imports env, improots = improots env, modules = modules env, hmodules = hmodules env, thismod = thismod env, - context = context env, qlevel = qlevel env, envX = x } + context = context env, qlevel = qlevel env, gtypes = gtypes env, envX = x } modX :: EnvF x -> (x -> x) -> EnvF x modX env f = env{ envX = f (envX env) } @@ -104,6 +105,7 @@ inClass env = contextIs env CtxClass inLoop env = contextIs env CtxLoop +setGtypes env te = env{ gtypes = te } mapModules1 :: ((Name,NameInfo) -> (Name,NameInfo)) -> Env0 -> Env0 mapModules1 f env = mapModules (\_ _ ni -> [f ni]) env @@ -255,6 +257,7 @@ initEnv path True = return $ EnvF{ activeNames = [], thismod = Nothing, context = [], qlevel = 0, + gtypes = [], envX = () } initEnv path False = do (_,nmod,_,_,_,_,_,_,_,_,_,_) <- InterfaceFiles.readFile (joinPath [path,"__builtin__.ty"]) let NModule _ envBuiltin builtinDocstring = nmod @@ -271,6 +274,7 @@ initEnv path False = do (_,nmod,_,_,_,_,_,_,_,_,_,_) <- InterfaceFiles.r thismod = Nothing, context = [], qlevel = 0, + gtypes = [], envX = () } env = importAll mBuiltin envBuiltinPublic env0 return env @@ -655,13 +659,29 @@ findAttrInfoIn n = scan Nothing | x == n = scan (Just i) xs | otherwise = scan r xs +-- attributes' :: (WPath -> NameInfo -> Name -> Maybe a) -> EnvF x -> QName -> [a] +-- attributes' f env qn = catMaybes [ f wp i n | n <- ns, let Just (wp,i) = lookup n aenv ] +-- where ns = nub $ reverse $ dom aenv -- in offset order +-- aenv = [ (n,(wp,i)) | (wp,c) <- ([],tc) : us, let (_,_,te) = findConName (tcname c) env, (n,i) <- reverse te ] -- in override order +-- (q,us,_) = findConName qn env +-- tc = TC qn [ tVar v | QBind v _ <- q ] +-- The above function is replaced by the following version, as suggested in mail from Johan 260429. + attributes' :: (WPath -> NameInfo -> Name -> Maybe a) -> EnvF x -> QName -> [a] attributes' f env qn = catMaybes [ f wp i n | n <- ns, let Just (wp,i) = lookup n aenv ] where ns = nub $ reverse $ dom aenv -- in offset order - aenv = [ (n,(wp,i)) | (wp,c) <- ([],tc) : us, let (_,_,te) = findConName (tcname c) env, (n,i) <- reverse te ] -- in override order - (q,us,_) = findConName qn env + aenv = attrEnv env qn + +attrEnv :: EnvF x -> QName -> [(Name,(WPath,NameInfo))] +attrEnv env qn = [ (n,(wp,i)) | (wp,c) <- ([],tc) : us, let (_,_,te) = findConName (tcname c) env, (n,i) <- reverse te ] -- in override order + where (q,us,_) = findConName qn env tc = TC qn [ tVar v | QBind v _ <- q ] +findAttrSchemas :: EnvF x -> QName -> TEnv +findAttrSchemas env qn = [ (n,i) | n <- ns, let Just (_,i) = lookup n aenv ] + where ns = nub $ dom aenv + aenv = reverse $ attrEnv env qn + inheritedAttrs :: EnvF x -> QName -> [(QName,Name)] inheritedAttrs = attributes' f where f _ NSig{} _ = Nothing @@ -1027,10 +1047,12 @@ lub env (TRow _ k1 n1 t1 r1) (TRow _ k2 n2 t2 r2) | k1 == k2 && n1 == n2 = tRow k1 n1 <$> lub env t1 t2 <*> lub env r1 r2 lub env (TStar _ k1 r1) (TStar _ k2 r2) | k1 == k2 = tStar k1 <$> lub env r1 r2 - +lub env (TUnboxed _ t1) t2 = lub env t1 t2 +lub env t1 (TUnboxed _ t2) = lub env t1 t2 lub env t1 t2 = Nothing + lub2 env (TRow _ _ _ t1 p1) k1 (TRow _ _ _ t2 p2) k2 = do t <- lub env t1 t2 (p,k) <- lub2 env p1 k1 p2 k2 diff --git a/compiler/lib/src/Acton/Normalizer.hs b/compiler/lib/src/Acton/Normalizer.hs index 53d806376..ae0eceeb7 100644 --- a/compiler/lib/src/Acton/Normalizer.hs +++ b/compiler/lib/src/Acton/Normalizer.hs @@ -311,18 +311,34 @@ instance Norm Stmt where let p'@(PVar _ n _) : ps' = ps2 return $ Assign l [p'] e' : [ Assign l [p] (eVar n) | p <- ps' ] ++ concat stmts where t = typeOf env e - norm' env s@(For l p e b els) = do i <- newName "iter" + norm' env s@(For l p e b els) + | Just r <- rangeIteratorArg e = do i <- newName "range_iter" + v <- newName "val" + normSuite env [sAssign (pVar i tRange) r, + handleStop (While l (eBool True) (rangeBody v i) []) els] + | otherwise = do i <- newName "iter" v <- newName "val" normSuite env [sAssign (pVar i $ conv t) e, handleStop (While l (eBool True) (body v i) []) els] where t@(TCon _ (TC c [t'])) = typeOf env e next i = eCall (eDot (eVar i) nextKW) [] + rangeNext i = eCall (eQVar primUNext) [eVar i] handleStop loop els = Try l [loop] [Handler (Except l0 qnStopIteration) (mkBody els)] [] [] body v i | isPVar p = sAssign p (next i) : b | otherwise = sAssign (pVar v t') (next i) : sAssign p (eVar v) : b + rangeBody v i + | isPVar p = sAssign p (rangeNext i) : b + | otherwise = sAssign (pVar v t') (rangeNext i) : sAssign p (eVar v) : b isPVar PVar{} = True isPVar _ = False + rangeIteratorArg (Call _ f (PosArg r PosNil) KwdNil) + | isIterCall f && typeOf env r == tRange = Just r + rangeIteratorArg (Paren _ e) = rangeIteratorArg e + rangeIteratorArg _ = Nothing + isIterCall (Dot _ _ n) = n == iterKW + isIterCall (TApp _ f _) = isIterCall f + isIterCall _ = False {- with EXPRESSION as PATTERN: SUITE @@ -518,7 +534,10 @@ instance Norm Expr where norm env (Ellipsis l) = return $ Ellipsis l norm env (Strings l ss) = return $ Strings l (catStrings ss) norm env (BStrings l ss) = return $ BStrings l (catStrings ss) - norm env (Call l e p k) = Call l <$> norm env e <*> norm env (joinArg p k) <*> pure KwdNil + norm env (Call l e p k) + | Just (t, e1, e2) <- listGetItemCall env e (joinArg p k) + = eCall (tApp (eQVar primUGetItem) [conv t]) <$> mapM (norm env) [e1, e2] + | otherwise = Call l <$> norm env e <*> norm env (joinArg p k) <*> pure KwdNil norm env (TApp l e ts) = TApp l <$> normInst env ts e <*> pure (conv ts) norm env (Let l ss e) = Let l <$> norm env ss <*> norm env e norm env (Dot l (Var l' x) n) @@ -554,6 +573,18 @@ instance Norm Expr where norm env (Paren l e) = norm env e norm env e = error ("norm unexpected: " ++ prstr e) +listGetItemCall env (Dot _ _ n) (PosArg e (PosArg ix PosNil)) + | n == getitemKW, + typeOf env ix == tInt, + Just t <- listElementType (typeOf env e) + = Just (t, e, ix) +listGetItemCall env (TApp _ e _) p = listGetItemCall env e p +listGetItemCall env _ _ = Nothing + +listElementType (TCon _ (TC q [t])) + | q == qnList = Just t +listElementType _ = Nothing + deferComp env e = do f <- newName "compfun" let p = getLambdavars env addComp (f,p,e) diff --git a/compiler/lib/src/Acton/Prim.hs b/compiler/lib/src/Acton/Prim.hs index aa7658052..8c81d200b 100644 --- a/compiler/lib/src/Acton/Prim.hs +++ b/compiler/lib/src/Acton/Prim.hs @@ -567,9 +567,10 @@ scRaiseValueError = tSchema [qbind a] tRaiseValErr where tRaiseValErr= tFun fxPure (posRow tStr posNil) kwdNil (tVar a) a = TV KType (name "A") --- $rangeD_U__next__ : [A] => (Iterator[A]) -> A will only be used to replace B_IteratorD_range.__next__ +-- $rangeD_U__next__ : range -> int +-- Raw range iteration primitive used when normalizing for-loops over range. scUNext = tSchema [] tUNext - where tUNext = tFun fxMut (posRow (tIterator (tInt)) posNil) kwdNil tInt + where tUNext = tFun fxMut (posRow tRange posNil) kwdNil tInt -- $WRAP : [A,B,C] => ($Actor, proc(*A,**B)->C) -> action(*A,**B)->C scWRAP = tSchema [qbind a, qbind b, qbind c] tWRAP @@ -637,4 +638,3 @@ isPUSHF _ = False isRAISE (Call _ (Var _ x) _ _) = x == primRAISE isRAISE _ = False - diff --git a/compiler/lib/src/Acton/Printer.hs b/compiler/lib/src/Acton/Printer.hs index 6401a87a8..fba2610a4 100644 --- a/compiler/lib/src/Acton/Printer.hs +++ b/compiler/lib/src/Acton/Printer.hs @@ -507,6 +507,7 @@ instance Pretty Type where pretty r@TNil{rkind=PRow} = parens empty pretty r@TNil{rkind=KRow} = parens empty pretty (TFX _ fx) = pretty fx + pretty (TUnboxed _ t) = text "UNBOXED" <+> pretty t prettyFXnoPure (TFX _ FXPure) = empty prettyFXnoPure t = pretty t diff --git a/compiler/lib/src/Acton/QuickType.hs b/compiler/lib/src/Acton/QuickType.hs index 6f00c9f7a..4e0bf7e09 100644 --- a/compiler/lib/src/Acton/QuickType.hs +++ b/compiler/lib/src/Acton/QuickType.hs @@ -164,6 +164,8 @@ instance QType Expr where fx = upbound env [fx1,fx2] qType env f (UnOp l Not e) = (tBool, fx, UnOp l Not (qMatch f t tBool e')) where (t, fx, e') = qType env f e + qType env f (UnOp l op e) = (t, fx, UnOp l op e') + where (t, fx, e') = qType env f e qType env f (Cond l e1 e e2) = (t', fx', Cond l (qMatch f t1 t' e1') (qMatch f t tBool e') (qMatch f t2 t' e2')) where (t1, fx1, e1') = qType env f e1 (t, fx, e') = qType env f e diff --git a/compiler/lib/src/Acton/Subst.hs b/compiler/lib/src/Acton/Subst.hs index a45b8bc41..a984d2ee5 100644 --- a/compiler/lib/src/Acton/Subst.hs +++ b/compiler/lib/src/Acton/Subst.hs @@ -63,6 +63,7 @@ instance VFree Type where vfree (TOpt _ t) = vfree t vfree (TRow _ k n t r) = vfree t ++ vfree r vfree (TStar _ k r) = vfree r + vfree (TUnboxed _ t) = vfree t vfree _ = [] instance VFree TCon where @@ -228,7 +229,7 @@ instance VSubst Type where vsubst s (TWild l) = TWild l vsubst s (TNil l k) = TNil l k vsubst s (TFX l fx) = TFX l fx - + vsubst s (TUnboxed l t) = TUnboxed l (vsubst s t) instance VSubst TCon where vsubst s (TC n ts) = TC n (vsubst s ts) diff --git a/compiler/lib/src/Acton/Syntax.hs b/compiler/lib/src/Acton/Syntax.hs index 10a59dfcb..80f36c968 100644 --- a/compiler/lib/src/Acton/Syntax.hs +++ b/compiler/lib/src/Acton/Syntax.hs @@ -249,6 +249,7 @@ data Type = TUni { tloc::SrcLoc, uvar::TUni } | TRow { tloc::SrcLoc, rkind::Kind, label::Name, rtype::Type, rtail::TRow } | TStar { tloc::SrcLoc, rkind::Kind, rtail::TRow } | TFX { tloc::SrcLoc, tfx::FX } + | TUnboxed { tloc::SrcLoc, utp::Type } deriving (Show,Read,Generic,NFData) type TFX = Type @@ -309,6 +310,9 @@ eIsInstance x n = IsInstance NoLoc (eVar x) n pospar nts = foldr (\(n,t) p -> PosPar n (Just t) Nothing p) PosNIL nts pospar' ns = foldr (\n p -> PosPar n Nothing Nothing p) PosNIL ns +pospars (PosPar n (Just t) _ p) + = (n,t) : pospars p +pospars PosNIL = [] pospars' (PosPar n _ _ p) = n : pospars' p pospars' PosNIL = [] @@ -742,6 +746,7 @@ instance Eq Type where TRow _ k1 n1 t1 r1 == TRow _ k2 n2 t2 r2 = k1 == k2 && n1 == n2 && t1 == t2 && r1 == r2 TStar _ k1 r1 == TStar _ k2 r2 = k1 == k2 && r1 == r2 TFX _ fx1 == TFX _ fx2 = fx1 == fx2 + TUnboxed _ t1 == TUnboxed _ t2 = t1 == t2 _ == _ = False -- Show & Read ---------------- diff --git a/compiler/lib/src/Acton/Types.hs b/compiler/lib/src/Acton/Types.hs index fa62e86cc..290d5cefe 100644 --- a/compiler/lib/src/Acton/Types.hs +++ b/compiler/lib/src/Acton/Types.hs @@ -1813,27 +1813,31 @@ instance Check Branch where +defaultParamName n = Internal NormPass ("default_" ++ nstr n) 0 + defaultsP (PosPar n (Just t) (Just e) p) | e /= eNone = set : defaultsP p - where test = eCall (tApp (eQVar primISNONE) [t]) [eVar n] - set = sAssign (pVar n t) (eCond e test (eVar n)) + where n' = defaultParamName n + test = eCall (tApp (eQVar primISNONE) [t]) [eVar n'] + set = sAssign (pVar n t) (eCond e test (eVar n')) defaultsP (PosPar n _ _ p) = defaultsP p defaultsP _ = [] noDefaultsP (PosPar n (Just t) (Just e) p) - = PosPar n (Just $ tOpt t) Nothing (noDefaultsP p) + = PosPar (defaultParamName n) (Just $ tOpt t) Nothing (noDefaultsP p) noDefaultsP (PosPar n t e p) = PosPar n t e (noDefaultsP p) noDefaultsP k = k defaultsK (KwdPar n (Just t) (Just e) k) | e /= eNone = set : defaultsK k - where test = eCall (tApp (eQVar primISNONE) [t]) [eVar n] - set = sAssign (pVar n t) (eCond e test (eVar n)) + where n' = defaultParamName n + test = eCall (tApp (eQVar primISNONE) [t]) [eVar n'] + set = sAssign (pVar n t) (eCond e test (eVar n')) defaultsK (KwdPar n _ _ k) = defaultsK k defaultsK _ = [] noDefaultsK (KwdPar n (Just t) (Just e) k) - = KwdPar n (Just $ tOpt t) Nothing (noDefaultsK k) + = KwdPar (defaultParamName n) (Just $ tOpt t) Nothing (noDefaultsK k) noDefaultsK (KwdPar n t e k) = KwdPar n t e (noDefaultsK k) noDefaultsK k = k diff --git a/compiler/lib/test/8-boxing/deact.output b/compiler/lib/test/8-boxing/deact.output index fe20e4c27..db1230c9b 100644 --- a/compiler/lib/test/8-boxing/deact.output +++ b/compiler/lib/test/8-boxing/deact.output @@ -19,20 +19,18 @@ class L_4action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin_ return None # recursive group: proc def __call__ (L_self : L_4action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_4action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_4action, G_1 : __builtin__.int) -> __builtin__.int: L_3obj: Apa = L_self.L_3obj return L_3obj.notice(G_1) # (recursive group) -proc def U_L_5C_3cont (cb : $action[(__builtin__.int,), __builtin__.int], C_cont : $Cont[__builtin__.int], U_2C_4res : __builtin__.int) -> $R: - U_3v: __builtin__.int = U_2C_4res +proc def L_5C_3cont (cb : $action[(__builtin__.int,), __builtin__.int], C_cont : $Cont[__builtin__.int], C_4res : UNBOXED __builtin__.int) -> $R: + v: UNBOXED __builtin__.int = (UNBOX __builtin__.int C_4res) m: __builtin__.Msg[__builtin__.int] = cb.__asyn__((BOX __builtin__.int (UNBOX __builtin__.int 2))) - U_4N_tmp: __builtin__.int = (U_3v * (UNBOX __builtin__.int 10)) - return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int U_4N_tmp)) -proc def L_5C_3cont (cb : $action[(__builtin__.int,), __builtin__.int], C_cont : $Cont[__builtin__.int], C_4res : __builtin__.int) -> $R: - return U_L_5C_3cont(cb, C_cont, (UNBOX __builtin__.int C_4res)) + N_tmp: UNBOXED __builtin__.int = ((UNBOX __builtin__.int v) * (UNBOX __builtin__.int 10)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int N_tmp)) class L_6Cont ($Cont[__builtin__.int], __builtin__.value): @property cb : $action[(__builtin__.int,), __builtin__.int] @@ -85,15 +83,15 @@ class L_9proc ($proc[(), __builtin__.int], __builtin__.value): self : Apa @property i : __builtin__.int - pure def __init__ (L_self : L_9proc, self : Apa, i : __builtin__.int) -> None: + pure def __init__ (L_self : L_9proc, self : Apa, i : UNBOXED __builtin__.int) -> None: L_self.self = self - L_self.i = i + L_self.i = (UNBOX __builtin__.int i) return None # recursive group: proc def __call__ (L_self : L_9proc, C_cont : $Cont[__builtin__.int]) -> $R: self: Apa = L_self.self - U_5i: __builtin__.int = (UNBOX __builtin__.int L_self.i) - return self.noticeG_local(C_cont, (BOX __builtin__.int U_5i)) + i: UNBOXED __builtin__.int = L_self.i + return self.noticeG_local(C_cont, (UNBOX __builtin__.int i)) proc def __exec__ (L_self : L_9proc, C_cont : $Cont[__builtin__.int]) -> $R: return L_self.__call__(C_cont) # (recursive group) @@ -102,15 +100,15 @@ class L_10proc ($proc[(), __builtin__.int], __builtin__.value): self : Bepa @property i : __builtin__.int - pure def __init__ (L_self : L_10proc, self : Bepa, i : __builtin__.int) -> None: + pure def __init__ (L_self : L_10proc, self : Bepa, i : UNBOXED __builtin__.int) -> None: L_self.self = self - L_self.i = i + L_self.i = (UNBOX __builtin__.int i) return None # recursive group: proc def __call__ (L_self : L_10proc, C_cont : $Cont[__builtin__.int]) -> $R: self: Bepa = L_self.self - U_6i: __builtin__.int = (UNBOX __builtin__.int L_self.i) - return self.callbackG_local(C_cont, (BOX __builtin__.int U_6i)) + i: UNBOXED __builtin__.int = L_self.i + return self.callbackG_local(C_cont, (UNBOX __builtin__.int i)) proc def __exec__ (L_self : L_10proc, C_cont : $Cont[__builtin__.int]) -> $R: return L_self.__call__(C_cont) # (recursive group) @@ -122,9 +120,9 @@ class L_14action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin return None # recursive group: proc def __call__ (L_self : L_14action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_14action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_14action, G_1 : __builtin__.int) -> __builtin__.int: L_13obj: Apa = L_self.L_13obj return L_13obj.notice(G_1) @@ -137,9 +135,9 @@ class L_16action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin return None # recursive group: proc def __call__ (L_self : L_16action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_16action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_16action, G_1 : __builtin__.int) -> __builtin__.int: L_15obj: Bepa = L_self.L_15obj return L_15obj.callback(G_1) @@ -152,21 +150,19 @@ class L_19action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin return None # recursive group: proc def __call__ (L_self : L_19action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_19action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_19action, G_1 : __builtin__.int) -> __builtin__.int: L_18obj: main = L_self.L_18obj return L_18obj.myproc(G_1) # (recursive group) -proc def U_1L_17C_9cont (self : main, C_cont : $Cont[None], U_7C_10res : __builtin__.int) -> $R: - self.r = (BOX __builtin__.int U_7C_10res) - print@[(__builtin__.str, __builtin__.int)](("\"r =\"", self.r), None, None, None, None) +proc def L_17C_9cont (self : main, C_cont : $Cont[None], C_10res : UNBOXED __builtin__.int) -> $R: + self.r = (UNBOX __builtin__.int C_10res) + print@[(__builtin__.str, __builtin__.int)](("\"r =\"", (BOX __builtin__.int self.r)), None, None, None, None) (async self.a.compute)(L_19action(self)) print@[(__builtin__.str,)](("\"main\"",), None, None, None, None) return $R_CONT@[None](C_cont, None) -proc def L_17C_9cont (self : main, C_cont : $Cont[None], C_10res : __builtin__.int) -> $R: - return U_1L_17C_9cont(self, C_cont, (UNBOX __builtin__.int C_10res)) class L_20Cont ($Cont[__builtin__.int], __builtin__.value): @property self : main @@ -220,15 +216,15 @@ class L_23proc ($proc[(), __builtin__.int], __builtin__.value): self : main @property i : __builtin__.int - pure def __init__ (L_self : L_23proc, self : main, i : __builtin__.int) -> None: + pure def __init__ (L_self : L_23proc, self : main, i : UNBOXED __builtin__.int) -> None: L_self.self = self - L_self.i = i + L_self.i = (UNBOX __builtin__.int i) return None # recursive group: proc def __call__ (L_self : L_23proc, C_cont : $Cont[__builtin__.int]) -> $R: self: main = L_self.self - U_8i: __builtin__.int = (UNBOX __builtin__.int L_self.i) - return self.myprocG_local(C_cont, (BOX __builtin__.int U_8i)) + i: UNBOXED __builtin__.int = L_self.i + return self.myprocG_local(C_cont, (UNBOX __builtin__.int i)) proc def __exec__ (L_self : L_23proc, C_cont : $Cont[__builtin__.int]) -> $R: return L_self.__call__(C_cont) # (recursive group) @@ -330,26 +326,26 @@ class Apa ($Actor, __builtin__.value): proc def computeG_local (self : Apa, C_cont : $Cont[__builtin__.int], cb : $action[(__builtin__.int,), __builtin__.int]) -> $R: print@[(__builtin__.str,)](("\"compute\"",), None, None, None, None) return $AWAIT@[__builtin__.int](L_6Cont(cb, C_cont), cb.__asyn__((BOX __builtin__.int (UNBOX __builtin__.int 1)))) - proc def noticeG_local (self : Apa, C_cont : $Cont[__builtin__.int], i : __builtin__.int) -> $R: + proc def noticeG_local (self : Apa, C_cont : $Cont[__builtin__.int], i : UNBOXED __builtin__.int) -> $R: print@[(__builtin__.str,)](("\"notice\"",), None, None, None, None) - U_9N_1tmp: __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) - return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int U_9N_1tmp)) + N_1tmp: UNBOXED __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int N_1tmp)) action def setup (self : Apa, cb : $action[(__builtin__.int,), __builtin__.int]) -> None: return $ASYNC@[None](self, L_7proc(self, cb)) - action def compute (self : Apa, cb : $action[(__builtin__.int,), __builtin__.int]) -> __builtin__.int: + action def compute (self : Apa, cb : $action[(__builtin__.int,), __builtin__.int]) -> UNBOXED __builtin__.int: return $ASYNC@[__builtin__.int](self, L_8proc(self, cb)) - action def notice (self : Apa, i : __builtin__.int) -> __builtin__.int: - return $ASYNC@[__builtin__.int](self, L_9proc(self, i)) + action def notice (self : Apa, i : UNBOXED __builtin__.int) -> UNBOXED __builtin__.int: + return $ASYNC@[__builtin__.int](self, L_9proc(self, (UNBOX __builtin__.int i))) class Bepa ($Actor, __builtin__.value): proc def __init__ (self : Bepa, C_cont : $Cont[None]) -> $R: print@[(__builtin__.str,)](("\"Bepa\"",), None, None, None, None) return $R_CONT@[None](C_cont, None) - proc def callbackG_local (self : Bepa, C_cont : $Cont[__builtin__.int], i : __builtin__.int) -> $R: - print@[(__builtin__.str, __builtin__.int)](("\"callback\"", i), None, None, None, None) - U_10N_2tmp: __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) - return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int U_10N_2tmp)) - action def callback (self : Bepa, i : __builtin__.int) -> __builtin__.int: - return $ASYNC@[__builtin__.int](self, L_10proc(self, i)) + proc def callbackG_local (self : Bepa, C_cont : $Cont[__builtin__.int], i : UNBOXED __builtin__.int) -> $R: + print@[(__builtin__.str, __builtin__.int)](("\"callback\"", (BOX __builtin__.int i)), None, None, None, None) + N_2tmp: UNBOXED __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int N_2tmp)) + action def callback (self : Bepa, i : UNBOXED __builtin__.int) -> UNBOXED __builtin__.int: + return $ASYNC@[__builtin__.int](self, L_10proc(self, (UNBOX __builtin__.int i))) class main ($Actor, __builtin__.value): @property env : __builtin__.Env @@ -364,13 +360,13 @@ class main ($Actor, __builtin__.value): proc def __init__ (self : main, C_cont : $Cont[None], env : __builtin__.Env) -> $R: self.env = env return ApaG_newact(L_22Cont(self, C_cont)) - proc def myprocG_local (self : main, C_cont : $Cont[__builtin__.int], i : __builtin__.int) -> $R: - print@[(__builtin__.str, __builtin__.int)](("\"myproc\"", i), None, None, None, None) + proc def myprocG_local (self : main, C_cont : $Cont[__builtin__.int], i : UNBOXED __builtin__.int) -> $R: + print@[(__builtin__.str, __builtin__.int)](("\"myproc\"", (BOX __builtin__.int i)), None, None, None, None) if (BOX __builtin__.bool ((UNBOX __builtin__.int i) == (UNBOX __builtin__.int 2))): - (async self.env.exit)((BOX __builtin__.int (UNBOX __builtin__.int 0))) - return $R_CONT@[__builtin__.int](C_cont, i) - action def myproc (self : main, i : __builtin__.int) -> __builtin__.int: - return $ASYNC@[__builtin__.int](self, L_23proc(self, i)) + (async self.env.exit)((UNBOX __builtin__.int 0)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int i)) + action def myproc (self : main, i : UNBOXED __builtin__.int) -> UNBOXED __builtin__.int: + return $ASYNC@[__builtin__.int](self, L_23proc(self, (UNBOX __builtin__.int i))) proc def ApaG_newact (C_cont : $Cont[Apa]) -> $R: G_act: Apa = $NEWACTOR@[Apa]() $InstallFinalizer@[Apa](G_act) diff --git a/compiler/lib/test/9-codegen/deact.c b/compiler/lib/test/9-codegen/deact.c index 3a21e4252..83041f68c 100644 --- a/compiler/lib/test/9-codegen/deact.c +++ b/compiler/lib/test/9-codegen/deact.c @@ -7,17 +7,18 @@ return $R_CONT(C_cont, B_None); } B_NoneType deactQ_L_2ContD___init__ (deactQ_L_2Cont L_self, $Cont C_cont) { - L_self->C_cont = C_cont; + ((deactQ_L_2Cont)(L_self))->C_cont = C_cont; return B_None; } $R deactQ_L_2ContD___call__ (deactQ_L_2Cont L_self, B_NoneType G_1) { - $Cont C_cont = L_self->C_cont; + $Cont C_cont = ((deactQ_L_2Cont)(L_self))->C_cont; return deactQ_L_1C_1cont(C_cont, G_1); } void deactQ_L_2ContD___serialize__ (deactQ_L_2Cont self, $Serial$state state) { $step_serialize(self->C_cont, state); } deactQ_L_2Cont deactQ_L_2ContD___deserialize__ (deactQ_L_2Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_2Cont)); @@ -37,23 +38,24 @@ deactQ_L_2Cont deactQ_L_2ContG_new($Cont G_1) { } struct deactQ_L_2ContG_class deactQ_L_2ContG_methods; B_NoneType deactQ_L_4actionD___init__ (deactQ_L_4action L_self, deactQ_Apa L_3obj) { - L_self->L_3obj = L_3obj; + ((deactQ_L_4action)(L_self))->L_3obj = L_3obj; return B_None; } $R deactQ_L_4actionD___call__ (deactQ_L_4action L_self, $Cont L_cont, B_int G_1) { - return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) (deactQ_L_4action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } $R deactQ_L_4actionD___exec__ (deactQ_L_4action L_self, $Cont L_cont, B_int G_1) { - return $R_CONT(L_cont, ((B_value)((B_Msg (*) (deactQ_L_4action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $R_CONT(L_cont, ((B_value)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } B_Msg deactQ_L_4actionD___asyn__ (deactQ_L_4action L_self, B_int G_1) { - deactQ_Apa L_3obj = L_self->L_3obj; - return ((B_Msg)((B_Msg (*) (deactQ_Apa, B_int))L_3obj->$class->notice)(L_3obj, G_1)); + deactQ_Apa L_3obj = ((deactQ_L_4action)(L_self))->L_3obj; + return ((B_Msg)((B_Msg (*) ($WORD, int64_t))L_3obj->$class->notice)(L_3obj, ((B_int)G_1)->val)); } void deactQ_L_4actionD___serialize__ (deactQ_L_4action self, $Serial$state state) { $step_serialize(self->L_3obj, state); } deactQ_L_4action deactQ_L_4actionD___deserialize__ (deactQ_L_4action self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_4action)); @@ -72,32 +74,30 @@ deactQ_L_4action deactQ_L_4actionG_new(deactQ_Apa G_1) { return $tmp; } struct deactQ_L_4actionG_class deactQ_L_4actionG_methods; -$R deactQ_U_L_5C_3cont ($action cb, $Cont C_cont, int64_t U_2C_4res) { +$R deactQ_L_5C_3cont ($action cb, $Cont C_cont, int64_t C_4res) { #line 7 "test/src/deact.act" - int64_t U_3v = U_2C_4res; + int64_t v = C_4res; #line 8 "test/src/deact.act" - B_Msg m = ((B_Msg)((B_Msg (*) ($action, B_int))cb->$class->__asyn__)(cb, toB_int(2LL))); - int64_t U_4N_tmp = (U_3v * 10LL); - return $R_CONT(C_cont, toB_int(U_4N_tmp)); -} -$R deactQ_L_5C_3cont ($action cb, $Cont C_cont, B_int C_4res) { - return deactQ_U_L_5C_3cont(cb, C_cont, ((B_int)C_4res)->val); + B_Msg m = ((B_Msg)((B_Msg (*) ($WORD, B_int))cb->$class->__asyn__)(cb, toB_int(2LL))); + int64_t N_tmp = (((int64_t)(v * 10LL))); + return $R_CONT(C_cont, toB_int(N_tmp)); } B_NoneType deactQ_L_6ContD___init__ (deactQ_L_6Cont L_self, $action cb, $Cont C_cont) { - L_self->cb = cb; - L_self->C_cont = C_cont; + ((deactQ_L_6Cont)(L_self))->cb = cb; + ((deactQ_L_6Cont)(L_self))->C_cont = C_cont; return B_None; } $R deactQ_L_6ContD___call__ (deactQ_L_6Cont L_self, B_int G_1) { - $action cb = L_self->cb; - $Cont C_cont = L_self->C_cont; - return deactQ_L_5C_3cont(cb, C_cont, G_1); + $action cb = ((deactQ_L_6Cont)(L_self))->cb; + $Cont C_cont = ((deactQ_L_6Cont)(L_self))->C_cont; + return deactQ_L_5C_3cont(cb, C_cont, ((B_int)G_1)->val); } void deactQ_L_6ContD___serialize__ (deactQ_L_6Cont self, $Serial$state state) { $step_serialize(self->cb, state); $step_serialize(self->C_cont, state); } deactQ_L_6Cont deactQ_L_6ContD___deserialize__ (deactQ_L_6Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_6Cont)); @@ -118,23 +118,24 @@ deactQ_L_6Cont deactQ_L_6ContG_new($action G_1, $Cont G_2) { } struct deactQ_L_6ContG_class deactQ_L_6ContG_methods; B_NoneType deactQ_L_7procD___init__ (deactQ_L_7proc L_self, deactQ_Apa self, $action cb) { - L_self->self = self; - L_self->cb = cb; + ((deactQ_L_7proc)(L_self))->self = self; + ((deactQ_L_7proc)(L_self))->cb = cb; return B_None; } $R deactQ_L_7procD___call__ (deactQ_L_7proc L_self, $Cont C_cont) { - deactQ_Apa self = L_self->self; - $action cb = L_self->cb; - return (($R (*) (deactQ_Apa, $Cont, $action))self->$class->setupG_local)(self, C_cont, cb); + deactQ_Apa self = ((deactQ_L_7proc)(L_self))->self; + $action cb = ((deactQ_L_7proc)(L_self))->cb; + return (($R (*) ($WORD, $Cont, $action))self->$class->setupG_local)(self, C_cont, cb); } $R deactQ_L_7procD___exec__ (deactQ_L_7proc L_self, $Cont C_cont) { - return (($R (*) (deactQ_L_7proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void deactQ_L_7procD___serialize__ (deactQ_L_7proc self, $Serial$state state) { $step_serialize(self->self, state); $step_serialize(self->cb, state); } deactQ_L_7proc deactQ_L_7procD___deserialize__ (deactQ_L_7proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_7proc)); @@ -155,23 +156,24 @@ deactQ_L_7proc deactQ_L_7procG_new(deactQ_Apa G_1, $action G_2) { } struct deactQ_L_7procG_class deactQ_L_7procG_methods; B_NoneType deactQ_L_8procD___init__ (deactQ_L_8proc L_self, deactQ_Apa self, $action cb) { - L_self->self = self; - L_self->cb = cb; + ((deactQ_L_8proc)(L_self))->self = self; + ((deactQ_L_8proc)(L_self))->cb = cb; return B_None; } $R deactQ_L_8procD___call__ (deactQ_L_8proc L_self, $Cont C_cont) { - deactQ_Apa self = L_self->self; - $action cb = L_self->cb; - return (($R (*) (deactQ_Apa, $Cont, $action))self->$class->computeG_local)(self, C_cont, cb); + deactQ_Apa self = ((deactQ_L_8proc)(L_self))->self; + $action cb = ((deactQ_L_8proc)(L_self))->cb; + return (($R (*) ($WORD, $Cont, $action))self->$class->computeG_local)(self, C_cont, cb); } $R deactQ_L_8procD___exec__ (deactQ_L_8proc L_self, $Cont C_cont) { - return (($R (*) (deactQ_L_8proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void deactQ_L_8procD___serialize__ (deactQ_L_8proc self, $Serial$state state) { $step_serialize(self->self, state); $step_serialize(self->cb, state); } deactQ_L_8proc deactQ_L_8procD___deserialize__ (deactQ_L_8proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_8proc)); @@ -191,24 +193,25 @@ deactQ_L_8proc deactQ_L_8procG_new(deactQ_Apa G_1, $action G_2) { return $tmp; } struct deactQ_L_8procG_class deactQ_L_8procG_methods; -B_NoneType deactQ_L_9procD___init__ (deactQ_L_9proc L_self, deactQ_Apa self, B_int i) { - L_self->self = self; - L_self->i = i; +B_NoneType deactQ_L_9procD___init__ (deactQ_L_9proc L_self, deactQ_Apa self, int64_t i) { + ((deactQ_L_9proc)(L_self))->self = self; + ((deactQ_L_9proc)(L_self))->i = i; return B_None; } $R deactQ_L_9procD___call__ (deactQ_L_9proc L_self, $Cont C_cont) { - deactQ_Apa self = L_self->self; - int64_t U_5i = ((B_int)L_self->i)->val; - return (($R (*) (deactQ_Apa, $Cont, B_int))self->$class->noticeG_local)(self, C_cont, toB_int(U_5i)); + deactQ_Apa self = ((deactQ_L_9proc)(L_self))->self; + int64_t i = ((int64_t)((deactQ_L_9proc)(L_self))->i); + return (($R (*) ($WORD, $Cont, int64_t))self->$class->noticeG_local)(self, C_cont, i); } $R deactQ_L_9procD___exec__ (deactQ_L_9proc L_self, $Cont C_cont) { - return (($R (*) (deactQ_L_9proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void deactQ_L_9procD___serialize__ (deactQ_L_9proc self, $Serial$state state) { $step_serialize(self->self, state); - $step_serialize(self->i, state); + $val_serialize(I64_ID, &self->i, state); } deactQ_L_9proc deactQ_L_9procD___deserialize__ (deactQ_L_9proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_9proc)); @@ -218,34 +221,36 @@ deactQ_L_9proc deactQ_L_9procD___deserialize__ (deactQ_L_9proc self, $Serial$sta self = $DNEW(deactQ_L_9proc, state); } self->self = $step_deserialize(state); - self->i = $step_deserialize(state); + $tmp = $val_deserialize(state); + memcpy(&self->i, &$tmp, sizeof(self->i)); return self; } -deactQ_L_9proc deactQ_L_9procG_new(deactQ_Apa G_1, B_int G_2) { +deactQ_L_9proc deactQ_L_9procG_new(deactQ_Apa G_1, int64_t G_2) { deactQ_L_9proc $tmp = acton_malloc(sizeof(struct deactQ_L_9proc)); $tmp->$class = &deactQ_L_9procG_methods; deactQ_L_9procG_methods.__init__($tmp, G_1, G_2); return $tmp; } struct deactQ_L_9procG_class deactQ_L_9procG_methods; -B_NoneType deactQ_L_10procD___init__ (deactQ_L_10proc L_self, deactQ_Bepa self, B_int i) { - L_self->self = self; - L_self->i = i; +B_NoneType deactQ_L_10procD___init__ (deactQ_L_10proc L_self, deactQ_Bepa self, int64_t i) { + ((deactQ_L_10proc)(L_self))->self = self; + ((deactQ_L_10proc)(L_self))->i = i; return B_None; } $R deactQ_L_10procD___call__ (deactQ_L_10proc L_self, $Cont C_cont) { - deactQ_Bepa self = L_self->self; - int64_t U_6i = ((B_int)L_self->i)->val; - return (($R (*) (deactQ_Bepa, $Cont, B_int))self->$class->callbackG_local)(self, C_cont, toB_int(U_6i)); + deactQ_Bepa self = ((deactQ_L_10proc)(L_self))->self; + int64_t i = ((int64_t)((deactQ_L_10proc)(L_self))->i); + return (($R (*) ($WORD, $Cont, int64_t))self->$class->callbackG_local)(self, C_cont, i); } $R deactQ_L_10procD___exec__ (deactQ_L_10proc L_self, $Cont C_cont) { - return (($R (*) (deactQ_L_10proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void deactQ_L_10procD___serialize__ (deactQ_L_10proc self, $Serial$state state) { $step_serialize(self->self, state); - $step_serialize(self->i, state); + $val_serialize(I64_ID, &self->i, state); } deactQ_L_10proc deactQ_L_10procD___deserialize__ (deactQ_L_10proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_10proc)); @@ -255,10 +260,11 @@ deactQ_L_10proc deactQ_L_10procD___deserialize__ (deactQ_L_10proc self, $Serial$ self = $DNEW(deactQ_L_10proc, state); } self->self = $step_deserialize(state); - self->i = $step_deserialize(state); + $tmp = $val_deserialize(state); + memcpy(&self->i, &$tmp, sizeof(self->i)); return self; } -deactQ_L_10proc deactQ_L_10procG_new(deactQ_Bepa G_1, B_int G_2) { +deactQ_L_10proc deactQ_L_10procG_new(deactQ_Bepa G_1, int64_t G_2) { deactQ_L_10proc $tmp = acton_malloc(sizeof(struct deactQ_L_10proc)); $tmp->$class = &deactQ_L_10procG_methods; deactQ_L_10procG_methods.__init__($tmp, G_1, G_2); @@ -266,23 +272,24 @@ deactQ_L_10proc deactQ_L_10procG_new(deactQ_Bepa G_1, B_int G_2) { } struct deactQ_L_10procG_class deactQ_L_10procG_methods; B_NoneType deactQ_L_14actionD___init__ (deactQ_L_14action L_self, deactQ_Apa L_13obj) { - L_self->L_13obj = L_13obj; + ((deactQ_L_14action)(L_self))->L_13obj = L_13obj; return B_None; } $R deactQ_L_14actionD___call__ (deactQ_L_14action L_self, $Cont L_cont, B_int G_1) { - return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) (deactQ_L_14action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } $R deactQ_L_14actionD___exec__ (deactQ_L_14action L_self, $Cont L_cont, B_int G_1) { - return $R_CONT(L_cont, ((B_value)((B_Msg (*) (deactQ_L_14action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $R_CONT(L_cont, ((B_value)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } B_Msg deactQ_L_14actionD___asyn__ (deactQ_L_14action L_self, B_int G_1) { - deactQ_Apa L_13obj = L_self->L_13obj; - return ((B_Msg)((B_Msg (*) (deactQ_Apa, B_int))L_13obj->$class->notice)(L_13obj, G_1)); + deactQ_Apa L_13obj = ((deactQ_L_14action)(L_self))->L_13obj; + return ((B_Msg)((B_Msg (*) ($WORD, int64_t))L_13obj->$class->notice)(L_13obj, ((B_int)G_1)->val)); } void deactQ_L_14actionD___serialize__ (deactQ_L_14action self, $Serial$state state) { $step_serialize(self->L_13obj, state); } deactQ_L_14action deactQ_L_14actionD___deserialize__ (deactQ_L_14action self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_14action)); @@ -302,23 +309,24 @@ deactQ_L_14action deactQ_L_14actionG_new(deactQ_Apa G_1) { } struct deactQ_L_14actionG_class deactQ_L_14actionG_methods; B_NoneType deactQ_L_16actionD___init__ (deactQ_L_16action L_self, deactQ_Bepa L_15obj) { - L_self->L_15obj = L_15obj; + ((deactQ_L_16action)(L_self))->L_15obj = L_15obj; return B_None; } $R deactQ_L_16actionD___call__ (deactQ_L_16action L_self, $Cont L_cont, B_int G_1) { - return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) (deactQ_L_16action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } $R deactQ_L_16actionD___exec__ (deactQ_L_16action L_self, $Cont L_cont, B_int G_1) { - return $R_CONT(L_cont, ((B_value)((B_Msg (*) (deactQ_L_16action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $R_CONT(L_cont, ((B_value)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } B_Msg deactQ_L_16actionD___asyn__ (deactQ_L_16action L_self, B_int G_1) { - deactQ_Bepa L_15obj = L_self->L_15obj; - return ((B_Msg)((B_Msg (*) (deactQ_Bepa, B_int))L_15obj->$class->callback)(L_15obj, G_1)); + deactQ_Bepa L_15obj = ((deactQ_L_16action)(L_self))->L_15obj; + return ((B_Msg)((B_Msg (*) ($WORD, int64_t))L_15obj->$class->callback)(L_15obj, ((B_int)G_1)->val)); } void deactQ_L_16actionD___serialize__ (deactQ_L_16action self, $Serial$state state) { $step_serialize(self->L_15obj, state); } deactQ_L_16action deactQ_L_16actionD___deserialize__ (deactQ_L_16action self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_16action)); @@ -338,23 +346,24 @@ deactQ_L_16action deactQ_L_16actionG_new(deactQ_Bepa G_1) { } struct deactQ_L_16actionG_class deactQ_L_16actionG_methods; B_NoneType deactQ_L_19actionD___init__ (deactQ_L_19action L_self, deactQ_main L_18obj) { - L_self->L_18obj = L_18obj; + ((deactQ_L_19action)(L_self))->L_18obj = L_18obj; return B_None; } $R deactQ_L_19actionD___call__ (deactQ_L_19action L_self, $Cont L_cont, B_int G_1) { - return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) (deactQ_L_19action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } $R deactQ_L_19actionD___exec__ (deactQ_L_19action L_self, $Cont L_cont, B_int G_1) { - return $R_CONT(L_cont, ((B_value)((B_Msg (*) (deactQ_L_19action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $R_CONT(L_cont, ((B_value)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } B_Msg deactQ_L_19actionD___asyn__ (deactQ_L_19action L_self, B_int G_1) { - deactQ_main L_18obj = L_self->L_18obj; - return ((B_Msg)((B_Msg (*) (deactQ_main, B_int))L_18obj->$class->myproc)(L_18obj, G_1)); + deactQ_main L_18obj = ((deactQ_L_19action)(L_self))->L_18obj; + return ((B_Msg)((B_Msg (*) ($WORD, int64_t))L_18obj->$class->myproc)(L_18obj, ((B_int)G_1)->val)); } void deactQ_L_19actionD___serialize__ (deactQ_L_19action self, $Serial$state state) { $step_serialize(self->L_18obj, state); } deactQ_L_19action deactQ_L_19actionD___deserialize__ (deactQ_L_19action self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_19action)); @@ -373,35 +382,33 @@ deactQ_L_19action deactQ_L_19actionG_new(deactQ_main G_1) { return $tmp; } struct deactQ_L_19actionG_class deactQ_L_19actionG_methods; -$R deactQ_U_1L_17C_9cont (deactQ_main self, $Cont C_cont, int64_t U_7C_10res) { +$R deactQ_L_17C_9cont (deactQ_main self, $Cont C_cont, int64_t C_10res) { #line 34 "test/src/deact.act" - self->r = toB_int(U_7C_10res); + ((deactQ_main)(self))->r = C_10res; #line 35 "test/src/deact.act" - ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("r ="), self->r), B_None, B_None, B_None, B_None); + ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("r ="), toB_int(((int64_t)((deactQ_main)(self))->r))), B_None, B_None, B_None, B_None); #line 36 "test/src/deact.act" - ((B_Msg (*) (deactQ_Apa, $action))self->a->$class->compute)(self->a, (($action)deactQ_L_19actionG_new(self))); + ((B_Msg (*) ($WORD, $action))((deactQ_main)(self))->a->$class->compute)(((deactQ_main)(self))->a, (($action)deactQ_L_19actionG_new(self))); #line 37 "test/src/deact.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("main")), B_None, B_None, B_None, B_None); return $R_CONT(C_cont, B_None); } -$R deactQ_L_17C_9cont (deactQ_main self, $Cont C_cont, B_int C_10res) { - return deactQ_U_1L_17C_9cont(self, C_cont, ((B_int)C_10res)->val); -} B_NoneType deactQ_L_20ContD___init__ (deactQ_L_20Cont L_self, deactQ_main self, $Cont C_cont) { - L_self->self = self; - L_self->C_cont = C_cont; + ((deactQ_L_20Cont)(L_self))->self = self; + ((deactQ_L_20Cont)(L_self))->C_cont = C_cont; return B_None; } $R deactQ_L_20ContD___call__ (deactQ_L_20Cont L_self, B_int G_1) { - deactQ_main self = L_self->self; - $Cont C_cont = L_self->C_cont; - return deactQ_L_17C_9cont(self, C_cont, G_1); + deactQ_main self = ((deactQ_L_20Cont)(L_self))->self; + $Cont C_cont = ((deactQ_L_20Cont)(L_self))->C_cont; + return deactQ_L_17C_9cont(self, C_cont, ((B_int)G_1)->val); } void deactQ_L_20ContD___serialize__ (deactQ_L_20Cont self, $Serial$state state) { $step_serialize(self->self, state); $step_serialize(self->C_cont, state); } deactQ_L_20Cont deactQ_L_20ContD___deserialize__ (deactQ_L_20Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_20Cont)); @@ -423,23 +430,23 @@ deactQ_L_20Cont deactQ_L_20ContG_new(deactQ_main G_1, $Cont G_2) { struct deactQ_L_20ContG_class deactQ_L_20ContG_methods; $R deactQ_L_12C_7cont (deactQ_main self, $Cont C_cont, deactQ_Bepa C_8res) { #line 30 "test/src/deact.act" - self->b = C_8res; + ((deactQ_main)(self))->b = C_8res; #line 31 "test/src/deact.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("-----")), B_None, B_None, B_None, B_None); #line 32 "test/src/deact.act" - ((B_Msg (*) (deactQ_Apa, $action))self->a->$class->setup)(self->a, (($action)deactQ_L_14actionG_new(self->a))); + ((B_Msg (*) ($WORD, $action))((deactQ_main)(self))->a->$class->setup)(((deactQ_main)(self))->a, (($action)deactQ_L_14actionG_new(((deactQ_main)(self))->a))); #line 33 "test/src/deact.act" - self->x = ((B_Msg (*) (deactQ_Apa, $action))self->a->$class->compute)(self->a, (($action)deactQ_L_16actionG_new(self->b))); - return $AWAIT((($Cont)deactQ_L_20ContG_new(self, C_cont)), self->x); + ((deactQ_main)(self))->x = ((B_Msg (*) ($WORD, $action))((deactQ_main)(self))->a->$class->compute)(((deactQ_main)(self))->a, (($action)deactQ_L_16actionG_new(((deactQ_main)(self))->b))); + return $AWAIT((($Cont)deactQ_L_20ContG_new(self, C_cont)), ((deactQ_main)(self))->x); } B_NoneType deactQ_L_21ContD___init__ (deactQ_L_21Cont L_self, deactQ_main self, $Cont C_cont) { - L_self->self = self; - L_self->C_cont = C_cont; + ((deactQ_L_21Cont)(L_self))->self = self; + ((deactQ_L_21Cont)(L_self))->C_cont = C_cont; return B_None; } $R deactQ_L_21ContD___call__ (deactQ_L_21Cont L_self, deactQ_Bepa G_1) { - deactQ_main self = L_self->self; - $Cont C_cont = L_self->C_cont; + deactQ_main self = ((deactQ_L_21Cont)(L_self))->self; + $Cont C_cont = ((deactQ_L_21Cont)(L_self))->C_cont; return deactQ_L_12C_7cont(self, C_cont, G_1); } void deactQ_L_21ContD___serialize__ (deactQ_L_21Cont self, $Serial$state state) { @@ -447,6 +454,7 @@ void deactQ_L_21ContD___serialize__ (deactQ_L_21Cont self, $Serial$state state) $step_serialize(self->C_cont, state); } deactQ_L_21Cont deactQ_L_21ContD___deserialize__ (deactQ_L_21Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_21Cont)); @@ -468,17 +476,17 @@ deactQ_L_21Cont deactQ_L_21ContG_new(deactQ_main G_1, $Cont G_2) { struct deactQ_L_21ContG_class deactQ_L_21ContG_methods; $R deactQ_L_11C_5cont (deactQ_main self, $Cont C_cont, deactQ_Apa C_6res) { #line 29 "test/src/deact.act" - self->a = C_6res; + ((deactQ_main)(self))->a = C_6res; return deactQ_BepaG_newact((($Cont)deactQ_L_21ContG_new(self, C_cont))); } B_NoneType deactQ_L_22ContD___init__ (deactQ_L_22Cont L_self, deactQ_main self, $Cont C_cont) { - L_self->self = self; - L_self->C_cont = C_cont; + ((deactQ_L_22Cont)(L_self))->self = self; + ((deactQ_L_22Cont)(L_self))->C_cont = C_cont; return B_None; } $R deactQ_L_22ContD___call__ (deactQ_L_22Cont L_self, deactQ_Apa G_1) { - deactQ_main self = L_self->self; - $Cont C_cont = L_self->C_cont; + deactQ_main self = ((deactQ_L_22Cont)(L_self))->self; + $Cont C_cont = ((deactQ_L_22Cont)(L_self))->C_cont; return deactQ_L_11C_5cont(self, C_cont, G_1); } void deactQ_L_22ContD___serialize__ (deactQ_L_22Cont self, $Serial$state state) { @@ -486,6 +494,7 @@ void deactQ_L_22ContD___serialize__ (deactQ_L_22Cont self, $Serial$state state) $step_serialize(self->C_cont, state); } deactQ_L_22Cont deactQ_L_22ContD___deserialize__ (deactQ_L_22Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_22Cont)); @@ -505,24 +514,25 @@ deactQ_L_22Cont deactQ_L_22ContG_new(deactQ_main G_1, $Cont G_2) { return $tmp; } struct deactQ_L_22ContG_class deactQ_L_22ContG_methods; -B_NoneType deactQ_L_23procD___init__ (deactQ_L_23proc L_self, deactQ_main self, B_int i) { - L_self->self = self; - L_self->i = i; +B_NoneType deactQ_L_23procD___init__ (deactQ_L_23proc L_self, deactQ_main self, int64_t i) { + ((deactQ_L_23proc)(L_self))->self = self; + ((deactQ_L_23proc)(L_self))->i = i; return B_None; } $R deactQ_L_23procD___call__ (deactQ_L_23proc L_self, $Cont C_cont) { - deactQ_main self = L_self->self; - int64_t U_8i = ((B_int)L_self->i)->val; - return (($R (*) (deactQ_main, $Cont, B_int))self->$class->myprocG_local)(self, C_cont, toB_int(U_8i)); + deactQ_main self = ((deactQ_L_23proc)(L_self))->self; + int64_t i = ((int64_t)((deactQ_L_23proc)(L_self))->i); + return (($R (*) ($WORD, $Cont, int64_t))self->$class->myprocG_local)(self, C_cont, i); } $R deactQ_L_23procD___exec__ (deactQ_L_23proc L_self, $Cont C_cont) { - return (($R (*) (deactQ_L_23proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void deactQ_L_23procD___serialize__ (deactQ_L_23proc self, $Serial$state state) { $step_serialize(self->self, state); - $step_serialize(self->i, state); + $val_serialize(I64_ID, &self->i, state); } deactQ_L_23proc deactQ_L_23procD___deserialize__ (deactQ_L_23proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_23proc)); @@ -532,10 +542,11 @@ deactQ_L_23proc deactQ_L_23procD___deserialize__ (deactQ_L_23proc self, $Serial$ self = $DNEW(deactQ_L_23proc, state); } self->self = $step_deserialize(state); - self->i = $step_deserialize(state); + $tmp = $val_deserialize(state); + memcpy(&self->i, &$tmp, sizeof(self->i)); return self; } -deactQ_L_23proc deactQ_L_23procG_new(deactQ_main G_1, B_int G_2) { +deactQ_L_23proc deactQ_L_23procG_new(deactQ_main G_1, int64_t G_2) { deactQ_L_23proc $tmp = acton_malloc(sizeof(struct deactQ_L_23proc)); $tmp->$class = &deactQ_L_23procG_methods; deactQ_L_23procG_methods.__init__($tmp, G_1, G_2); @@ -546,13 +557,13 @@ struct deactQ_L_23procG_class deactQ_L_23procG_methods; return $R_CONT(C_cont, G_act); } B_NoneType deactQ_L_25ContD___init__ (deactQ_L_25Cont L_self, $Cont C_cont, deactQ_Apa G_act) { - L_self->C_cont = C_cont; - L_self->G_act = G_act; + ((deactQ_L_25Cont)(L_self))->C_cont = C_cont; + ((deactQ_L_25Cont)(L_self))->G_act = G_act; return B_None; } $R deactQ_L_25ContD___call__ (deactQ_L_25Cont L_self, B_NoneType G_1) { - $Cont C_cont = L_self->C_cont; - deactQ_Apa G_act = L_self->G_act; + $Cont C_cont = ((deactQ_L_25Cont)(L_self))->C_cont; + deactQ_Apa G_act = ((deactQ_L_25Cont)(L_self))->G_act; return deactQ_L_24C_11cont(C_cont, G_act, G_1); } void deactQ_L_25ContD___serialize__ (deactQ_L_25Cont self, $Serial$state state) { @@ -560,6 +571,7 @@ void deactQ_L_25ContD___serialize__ (deactQ_L_25Cont self, $Serial$state state) $step_serialize(self->G_act, state); } deactQ_L_25Cont deactQ_L_25ContD___deserialize__ (deactQ_L_25Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_25Cont)); @@ -580,20 +592,21 @@ deactQ_L_25Cont deactQ_L_25ContG_new($Cont G_1, deactQ_Apa G_2) { } struct deactQ_L_25ContG_class deactQ_L_25ContG_methods; B_NoneType deactQ_L_26procD___init__ (deactQ_L_26proc L_self, deactQ_Apa G_act) { - L_self->G_act = G_act; + ((deactQ_L_26proc)(L_self))->G_act = G_act; return B_None; } $R deactQ_L_26procD___call__ (deactQ_L_26proc L_self, $Cont C_cont) { - deactQ_Apa G_act = L_self->G_act; - return (($R (*) (deactQ_Apa, $Cont))G_act->$class->__init__)(G_act, C_cont); + deactQ_Apa G_act = ((deactQ_L_26proc)(L_self))->G_act; + return (($R (*) ($WORD, $Cont))G_act->$class->__init__)(G_act, C_cont); } $R deactQ_L_26procD___exec__ (deactQ_L_26proc L_self, $Cont C_cont) { - return (($R (*) (deactQ_L_26proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void deactQ_L_26procD___serialize__ (deactQ_L_26proc self, $Serial$state state) { $step_serialize(self->G_act, state); } deactQ_L_26proc deactQ_L_26procD___deserialize__ (deactQ_L_26proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_26proc)); @@ -616,13 +629,13 @@ struct deactQ_L_26procG_class deactQ_L_26procG_methods; return $R_CONT(C_cont, G_act); } B_NoneType deactQ_L_28ContD___init__ (deactQ_L_28Cont L_self, $Cont C_cont, deactQ_Bepa G_act) { - L_self->C_cont = C_cont; - L_self->G_act = G_act; + ((deactQ_L_28Cont)(L_self))->C_cont = C_cont; + ((deactQ_L_28Cont)(L_self))->G_act = G_act; return B_None; } $R deactQ_L_28ContD___call__ (deactQ_L_28Cont L_self, B_NoneType G_1) { - $Cont C_cont = L_self->C_cont; - deactQ_Bepa G_act = L_self->G_act; + $Cont C_cont = ((deactQ_L_28Cont)(L_self))->C_cont; + deactQ_Bepa G_act = ((deactQ_L_28Cont)(L_self))->G_act; return deactQ_L_27C_13cont(C_cont, G_act, G_1); } void deactQ_L_28ContD___serialize__ (deactQ_L_28Cont self, $Serial$state state) { @@ -630,6 +643,7 @@ void deactQ_L_28ContD___serialize__ (deactQ_L_28Cont self, $Serial$state state) $step_serialize(self->G_act, state); } deactQ_L_28Cont deactQ_L_28ContD___deserialize__ (deactQ_L_28Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_28Cont)); @@ -650,20 +664,21 @@ deactQ_L_28Cont deactQ_L_28ContG_new($Cont G_1, deactQ_Bepa G_2) { } struct deactQ_L_28ContG_class deactQ_L_28ContG_methods; B_NoneType deactQ_L_29procD___init__ (deactQ_L_29proc L_self, deactQ_Bepa G_act) { - L_self->G_act = G_act; + ((deactQ_L_29proc)(L_self))->G_act = G_act; return B_None; } $R deactQ_L_29procD___call__ (deactQ_L_29proc L_self, $Cont C_cont) { - deactQ_Bepa G_act = L_self->G_act; - return (($R (*) (deactQ_Bepa, $Cont))G_act->$class->__init__)(G_act, C_cont); + deactQ_Bepa G_act = ((deactQ_L_29proc)(L_self))->G_act; + return (($R (*) ($WORD, $Cont))G_act->$class->__init__)(G_act, C_cont); } $R deactQ_L_29procD___exec__ (deactQ_L_29proc L_self, $Cont C_cont) { - return (($R (*) (deactQ_L_29proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void deactQ_L_29procD___serialize__ (deactQ_L_29proc self, $Serial$state state) { $step_serialize(self->G_act, state); } deactQ_L_29proc deactQ_L_29procD___deserialize__ (deactQ_L_29proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_29proc)); @@ -686,13 +701,13 @@ struct deactQ_L_29procG_class deactQ_L_29procG_methods; return $R_CONT(C_cont, G_act); } B_NoneType deactQ_L_31ContD___init__ (deactQ_L_31Cont L_self, $Cont C_cont, deactQ_main G_act) { - L_self->C_cont = C_cont; - L_self->G_act = G_act; + ((deactQ_L_31Cont)(L_self))->C_cont = C_cont; + ((deactQ_L_31Cont)(L_self))->G_act = G_act; return B_None; } $R deactQ_L_31ContD___call__ (deactQ_L_31Cont L_self, B_NoneType G_1) { - $Cont C_cont = L_self->C_cont; - deactQ_main G_act = L_self->G_act; + $Cont C_cont = ((deactQ_L_31Cont)(L_self))->C_cont; + deactQ_main G_act = ((deactQ_L_31Cont)(L_self))->G_act; return deactQ_L_30C_15cont(C_cont, G_act, G_1); } void deactQ_L_31ContD___serialize__ (deactQ_L_31Cont self, $Serial$state state) { @@ -700,6 +715,7 @@ void deactQ_L_31ContD___serialize__ (deactQ_L_31Cont self, $Serial$state state) $step_serialize(self->G_act, state); } deactQ_L_31Cont deactQ_L_31ContD___deserialize__ (deactQ_L_31Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_31Cont)); @@ -720,23 +736,24 @@ deactQ_L_31Cont deactQ_L_31ContG_new($Cont G_1, deactQ_main G_2) { } struct deactQ_L_31ContG_class deactQ_L_31ContG_methods; B_NoneType deactQ_L_32procD___init__ (deactQ_L_32proc L_self, deactQ_main G_act, B_Env env) { - L_self->G_act = G_act; - L_self->env = env; + ((deactQ_L_32proc)(L_self))->G_act = G_act; + ((deactQ_L_32proc)(L_self))->env = env; return B_None; } $R deactQ_L_32procD___call__ (deactQ_L_32proc L_self, $Cont C_cont) { - deactQ_main G_act = L_self->G_act; - B_Env env = L_self->env; - return (($R (*) (deactQ_main, $Cont, B_Env))G_act->$class->__init__)(G_act, C_cont, env); + deactQ_main G_act = ((deactQ_L_32proc)(L_self))->G_act; + B_Env env = ((deactQ_L_32proc)(L_self))->env; + return (($R (*) ($WORD, $Cont, B_Env))G_act->$class->__init__)(G_act, C_cont, env); } $R deactQ_L_32procD___exec__ (deactQ_L_32proc L_self, $Cont C_cont) { - return (($R (*) (deactQ_L_32proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void deactQ_L_32procD___serialize__ (deactQ_L_32proc self, $Serial$state state) { $step_serialize(self->G_act, state); $step_serialize(self->env, state); } deactQ_L_32proc deactQ_L_32procD___deserialize__ (deactQ_L_32proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_L_32proc)); @@ -757,28 +774,28 @@ deactQ_L_32proc deactQ_L_32procG_new(deactQ_main G_1, B_Env G_2) { } struct deactQ_L_32procG_class deactQ_L_32procG_methods; $R deactQ_ApaD___init__ (deactQ_Apa self, $Cont C_cont) { - return (($R (*) (deactQ_Apa, $Cont, $action))self->$class->setupG_local)(self, (($Cont)deactQ_L_2ContG_new(C_cont)), (($action)deactQ_L_4actionG_new(self))); + return (($R (*) ($WORD, $Cont, $action))self->$class->setupG_local)(self, (($Cont)deactQ_L_2ContG_new(C_cont)), (($action)deactQ_L_4actionG_new(self))); } #line 2 "test/src/deact.act" $R deactQ_ApaD_setupG_local (deactQ_Apa self, $Cont C_cont, $action cb) { #line 3 "test/src/deact.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("setup")), B_None, B_None, B_None, B_None); #line 4 "test/src/deact.act" - ((B_Msg (*) ($action, B_int))cb->$class->__asyn__)(cb, toB_int(0LL)); + ((B_Msg (*) ($WORD, B_int))cb->$class->__asyn__)(cb, toB_int(0LL)); return $R_CONT(C_cont, B_None); } #line 5 "test/src/deact.act" $R deactQ_ApaD_computeG_local (deactQ_Apa self, $Cont C_cont, $action cb) { #line 6 "test/src/deact.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("compute")), B_None, B_None, B_None, B_None); - return $AWAIT((($Cont)deactQ_L_6ContG_new(cb, C_cont)), ((B_Msg)((B_Msg (*) ($action, B_int))cb->$class->__asyn__)(cb, toB_int(1LL)))); + return $AWAIT((($Cont)deactQ_L_6ContG_new(cb, C_cont)), ((B_Msg)((B_Msg (*) ($WORD, B_int))cb->$class->__asyn__)(cb, toB_int(1LL)))); } #line 10 "test/src/deact.act" -$R deactQ_ApaD_noticeG_local (deactQ_Apa self, $Cont C_cont, B_int i) { +$R deactQ_ApaD_noticeG_local (deactQ_Apa self, $Cont C_cont, int64_t i) { #line 11 "test/src/deact.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("notice")), B_None, B_None, B_None, B_None); - int64_t U_9N_1tmp = (((B_int)i)->val + 1LL); - return $R_CONT(C_cont, toB_int(U_9N_1tmp)); + int64_t N_1tmp = (((int64_t)(i + 1LL))); + return $R_CONT(C_cont, toB_int(N_1tmp)); } B_Msg deactQ_ApaD_setup (deactQ_Apa self, $action cb) { return $ASYNC((($Actor)self), (($Cont)deactQ_L_7procG_new(self, cb))); @@ -786,13 +803,14 @@ B_Msg deactQ_ApaD_setup (deactQ_Apa self, $action cb) { B_Msg deactQ_ApaD_compute (deactQ_Apa self, $action cb) { return ((B_Msg)$ASYNC((($Actor)self), (($Cont)deactQ_L_8procG_new(self, cb)))); } -B_Msg deactQ_ApaD_notice (deactQ_Apa self, B_int i) { +B_Msg deactQ_ApaD_notice (deactQ_Apa self, int64_t i) { return ((B_Msg)$ASYNC((($Actor)self), (($Cont)deactQ_L_9procG_new(self, i)))); } void deactQ_ApaD___serialize__ (deactQ_Apa self, $Serial$state state) { $ActorG_methods.__serialize__(($Actor)self, state); } deactQ_Apa deactQ_ApaD___deserialize__ (deactQ_Apa self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_Apa)); @@ -820,19 +838,20 @@ struct deactQ_ApaG_class deactQ_ApaG_methods; return $R_CONT(C_cont, B_None); } #line 18 "test/src/deact.act" -$R deactQ_BepaD_callbackG_local (deactQ_Bepa self, $Cont C_cont, B_int i) { +$R deactQ_BepaD_callbackG_local (deactQ_Bepa self, $Cont C_cont, int64_t i) { #line 19 "test/src/deact.act" - ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("callback"), i), B_None, B_None, B_None, B_None); - int64_t U_10N_2tmp = (((B_int)i)->val + 1LL); - return $R_CONT(C_cont, toB_int(U_10N_2tmp)); + ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("callback"), toB_int(i)), B_None, B_None, B_None, B_None); + int64_t N_2tmp = (((int64_t)(i + 1LL))); + return $R_CONT(C_cont, toB_int(N_2tmp)); } -B_Msg deactQ_BepaD_callback (deactQ_Bepa self, B_int i) { +B_Msg deactQ_BepaD_callback (deactQ_Bepa self, int64_t i) { return ((B_Msg)$ASYNC((($Actor)self), (($Cont)deactQ_L_10procG_new(self, i)))); } void deactQ_BepaD___serialize__ (deactQ_Bepa self, $Serial$state state) { $ActorG_methods.__serialize__(($Actor)self, state); } deactQ_Bepa deactQ_BepaD___deserialize__ (deactQ_Bepa self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_Bepa)); @@ -855,21 +874,21 @@ void deactQ_BepaD_GCfinalizer (void *obj, void *cdata) { } struct deactQ_BepaG_class deactQ_BepaG_methods; $R deactQ_mainD___init__ (deactQ_main self, $Cont C_cont, B_Env env) { - self->env = env; + ((deactQ_main)(self))->env = env; return deactQ_ApaG_newact((($Cont)deactQ_L_22ContG_new(self, C_cont))); } #line 24 "test/src/deact.act" -$R deactQ_mainD_myprocG_local (deactQ_main self, $Cont C_cont, B_int i) { +$R deactQ_mainD_myprocG_local (deactQ_main self, $Cont C_cont, int64_t i) { #line 25 "test/src/deact.act" - ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("myproc"), i), B_None, B_None, B_None, B_None); + ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("myproc"), toB_int(i)), B_None, B_None, B_None, B_None); #line 26 "test/src/deact.act" - if ((((B_int)i)->val == 2LL)) { + if (i == 2LL) { #line 27 "test/src/deact.act" - ((B_Msg (*) (B_Env, B_int))self->env->$class->exit)(self->env, toB_int(0LL)); + ((B_Msg (*) ($WORD, int64_t))((deactQ_main)(self))->env->$class->exit)(((deactQ_main)(self))->env, 0LL); } - return $R_CONT(C_cont, i); + return $R_CONT(C_cont, toB_int(i)); } -B_Msg deactQ_mainD_myproc (deactQ_main self, B_int i) { +B_Msg deactQ_mainD_myproc (deactQ_main self, int64_t i) { return ((B_Msg)$ASYNC((($Actor)self), (($Cont)deactQ_L_23procG_new(self, i)))); } void deactQ_mainD___serialize__ (deactQ_main self, $Serial$state state) { @@ -878,9 +897,10 @@ void deactQ_mainD___serialize__ (deactQ_main self, $Serial$state state) { $step_serialize(self->a, state); $step_serialize(self->b, state); $step_serialize(self->x, state); - $step_serialize(self->r, state); + $val_serialize(I64_ID, &self->r, state); } deactQ_main deactQ_mainD___deserialize__ (deactQ_main self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct deactQ_main)); @@ -894,7 +914,8 @@ deactQ_main deactQ_mainD___deserialize__ (deactQ_main self, $Serial$state state) self->a = $step_deserialize(state); self->b = $step_deserialize(state); self->x = $step_deserialize(state); - self->r = $step_deserialize(state); + $tmp = $val_deserialize(state); + memcpy(&self->r, &$tmp, sizeof(self->r)); return self; } void deactQ_mainD_GCfinalizer (void *obj, void *cdata) { @@ -932,8 +953,8 @@ void deactQ___init__ () { deactQ_L_2ContG_methods.__bool__ = (B_bool (*) (deactQ_L_2Cont))B_valueG_methods.__bool__; deactQ_L_2ContG_methods.__str__ = (B_str (*) (deactQ_L_2Cont))B_valueG_methods.__str__; deactQ_L_2ContG_methods.__repr__ = (B_str (*) (deactQ_L_2Cont))B_valueG_methods.__repr__; - deactQ_L_2ContG_methods.__init__ = deactQ_L_2ContD___init__; - deactQ_L_2ContG_methods.__call__ = deactQ_L_2ContD___call__; + deactQ_L_2ContG_methods.__init__ = (B_NoneType (*) (deactQ_L_2Cont, $Cont))deactQ_L_2ContD___init__; + deactQ_L_2ContG_methods.__call__ = ($R (*) (deactQ_L_2Cont, B_NoneType))deactQ_L_2ContD___call__; deactQ_L_2ContG_methods.__serialize__ = deactQ_L_2ContD___serialize__; deactQ_L_2ContG_methods.__deserialize__ = deactQ_L_2ContD___deserialize__; $register(&deactQ_L_2ContG_methods); @@ -944,10 +965,10 @@ void deactQ___init__ () { deactQ_L_4actionG_methods.__bool__ = (B_bool (*) (deactQ_L_4action))B_valueG_methods.__bool__; deactQ_L_4actionG_methods.__str__ = (B_str (*) (deactQ_L_4action))B_valueG_methods.__str__; deactQ_L_4actionG_methods.__repr__ = (B_str (*) (deactQ_L_4action))B_valueG_methods.__repr__; - deactQ_L_4actionG_methods.__init__ = deactQ_L_4actionD___init__; - deactQ_L_4actionG_methods.__call__ = deactQ_L_4actionD___call__; - deactQ_L_4actionG_methods.__exec__ = deactQ_L_4actionD___exec__; - deactQ_L_4actionG_methods.__asyn__ = deactQ_L_4actionD___asyn__; + deactQ_L_4actionG_methods.__init__ = (B_NoneType (*) (deactQ_L_4action, deactQ_Apa))deactQ_L_4actionD___init__; + deactQ_L_4actionG_methods.__call__ = ($R (*) (deactQ_L_4action, $Cont, B_int))deactQ_L_4actionD___call__; + deactQ_L_4actionG_methods.__exec__ = ($R (*) (deactQ_L_4action, $Cont, B_int))deactQ_L_4actionD___exec__; + deactQ_L_4actionG_methods.__asyn__ = (B_Msg (*) (deactQ_L_4action, B_int))deactQ_L_4actionD___asyn__; deactQ_L_4actionG_methods.__serialize__ = deactQ_L_4actionD___serialize__; deactQ_L_4actionG_methods.__deserialize__ = deactQ_L_4actionD___deserialize__; $register(&deactQ_L_4actionG_methods); @@ -958,8 +979,8 @@ void deactQ___init__ () { deactQ_L_6ContG_methods.__bool__ = (B_bool (*) (deactQ_L_6Cont))B_valueG_methods.__bool__; deactQ_L_6ContG_methods.__str__ = (B_str (*) (deactQ_L_6Cont))B_valueG_methods.__str__; deactQ_L_6ContG_methods.__repr__ = (B_str (*) (deactQ_L_6Cont))B_valueG_methods.__repr__; - deactQ_L_6ContG_methods.__init__ = deactQ_L_6ContD___init__; - deactQ_L_6ContG_methods.__call__ = deactQ_L_6ContD___call__; + deactQ_L_6ContG_methods.__init__ = (B_NoneType (*) (deactQ_L_6Cont, $action, $Cont))deactQ_L_6ContD___init__; + deactQ_L_6ContG_methods.__call__ = ($R (*) (deactQ_L_6Cont, B_int))deactQ_L_6ContD___call__; deactQ_L_6ContG_methods.__serialize__ = deactQ_L_6ContD___serialize__; deactQ_L_6ContG_methods.__deserialize__ = deactQ_L_6ContD___deserialize__; $register(&deactQ_L_6ContG_methods); @@ -970,9 +991,9 @@ void deactQ___init__ () { deactQ_L_7procG_methods.__bool__ = (B_bool (*) (deactQ_L_7proc))B_valueG_methods.__bool__; deactQ_L_7procG_methods.__str__ = (B_str (*) (deactQ_L_7proc))B_valueG_methods.__str__; deactQ_L_7procG_methods.__repr__ = (B_str (*) (deactQ_L_7proc))B_valueG_methods.__repr__; - deactQ_L_7procG_methods.__init__ = deactQ_L_7procD___init__; - deactQ_L_7procG_methods.__call__ = deactQ_L_7procD___call__; - deactQ_L_7procG_methods.__exec__ = deactQ_L_7procD___exec__; + deactQ_L_7procG_methods.__init__ = (B_NoneType (*) (deactQ_L_7proc, deactQ_Apa, $action))deactQ_L_7procD___init__; + deactQ_L_7procG_methods.__call__ = ($R (*) (deactQ_L_7proc, $Cont))deactQ_L_7procD___call__; + deactQ_L_7procG_methods.__exec__ = ($R (*) (deactQ_L_7proc, $Cont))deactQ_L_7procD___exec__; deactQ_L_7procG_methods.__serialize__ = deactQ_L_7procD___serialize__; deactQ_L_7procG_methods.__deserialize__ = deactQ_L_7procD___deserialize__; $register(&deactQ_L_7procG_methods); @@ -983,9 +1004,9 @@ void deactQ___init__ () { deactQ_L_8procG_methods.__bool__ = (B_bool (*) (deactQ_L_8proc))B_valueG_methods.__bool__; deactQ_L_8procG_methods.__str__ = (B_str (*) (deactQ_L_8proc))B_valueG_methods.__str__; deactQ_L_8procG_methods.__repr__ = (B_str (*) (deactQ_L_8proc))B_valueG_methods.__repr__; - deactQ_L_8procG_methods.__init__ = deactQ_L_8procD___init__; - deactQ_L_8procG_methods.__call__ = deactQ_L_8procD___call__; - deactQ_L_8procG_methods.__exec__ = deactQ_L_8procD___exec__; + deactQ_L_8procG_methods.__init__ = (B_NoneType (*) (deactQ_L_8proc, deactQ_Apa, $action))deactQ_L_8procD___init__; + deactQ_L_8procG_methods.__call__ = ($R (*) (deactQ_L_8proc, $Cont))deactQ_L_8procD___call__; + deactQ_L_8procG_methods.__exec__ = ($R (*) (deactQ_L_8proc, $Cont))deactQ_L_8procD___exec__; deactQ_L_8procG_methods.__serialize__ = deactQ_L_8procD___serialize__; deactQ_L_8procG_methods.__deserialize__ = deactQ_L_8procD___deserialize__; $register(&deactQ_L_8procG_methods); @@ -996,9 +1017,9 @@ void deactQ___init__ () { deactQ_L_9procG_methods.__bool__ = (B_bool (*) (deactQ_L_9proc))B_valueG_methods.__bool__; deactQ_L_9procG_methods.__str__ = (B_str (*) (deactQ_L_9proc))B_valueG_methods.__str__; deactQ_L_9procG_methods.__repr__ = (B_str (*) (deactQ_L_9proc))B_valueG_methods.__repr__; - deactQ_L_9procG_methods.__init__ = deactQ_L_9procD___init__; - deactQ_L_9procG_methods.__call__ = deactQ_L_9procD___call__; - deactQ_L_9procG_methods.__exec__ = deactQ_L_9procD___exec__; + deactQ_L_9procG_methods.__init__ = (B_NoneType (*) (deactQ_L_9proc, deactQ_Apa, int64_t))deactQ_L_9procD___init__; + deactQ_L_9procG_methods.__call__ = ($R (*) (deactQ_L_9proc, $Cont))deactQ_L_9procD___call__; + deactQ_L_9procG_methods.__exec__ = ($R (*) (deactQ_L_9proc, $Cont))deactQ_L_9procD___exec__; deactQ_L_9procG_methods.__serialize__ = deactQ_L_9procD___serialize__; deactQ_L_9procG_methods.__deserialize__ = deactQ_L_9procD___deserialize__; $register(&deactQ_L_9procG_methods); @@ -1009,9 +1030,9 @@ void deactQ___init__ () { deactQ_L_10procG_methods.__bool__ = (B_bool (*) (deactQ_L_10proc))B_valueG_methods.__bool__; deactQ_L_10procG_methods.__str__ = (B_str (*) (deactQ_L_10proc))B_valueG_methods.__str__; deactQ_L_10procG_methods.__repr__ = (B_str (*) (deactQ_L_10proc))B_valueG_methods.__repr__; - deactQ_L_10procG_methods.__init__ = deactQ_L_10procD___init__; - deactQ_L_10procG_methods.__call__ = deactQ_L_10procD___call__; - deactQ_L_10procG_methods.__exec__ = deactQ_L_10procD___exec__; + deactQ_L_10procG_methods.__init__ = (B_NoneType (*) (deactQ_L_10proc, deactQ_Bepa, int64_t))deactQ_L_10procD___init__; + deactQ_L_10procG_methods.__call__ = ($R (*) (deactQ_L_10proc, $Cont))deactQ_L_10procD___call__; + deactQ_L_10procG_methods.__exec__ = ($R (*) (deactQ_L_10proc, $Cont))deactQ_L_10procD___exec__; deactQ_L_10procG_methods.__serialize__ = deactQ_L_10procD___serialize__; deactQ_L_10procG_methods.__deserialize__ = deactQ_L_10procD___deserialize__; $register(&deactQ_L_10procG_methods); @@ -1022,10 +1043,10 @@ void deactQ___init__ () { deactQ_L_14actionG_methods.__bool__ = (B_bool (*) (deactQ_L_14action))B_valueG_methods.__bool__; deactQ_L_14actionG_methods.__str__ = (B_str (*) (deactQ_L_14action))B_valueG_methods.__str__; deactQ_L_14actionG_methods.__repr__ = (B_str (*) (deactQ_L_14action))B_valueG_methods.__repr__; - deactQ_L_14actionG_methods.__init__ = deactQ_L_14actionD___init__; - deactQ_L_14actionG_methods.__call__ = deactQ_L_14actionD___call__; - deactQ_L_14actionG_methods.__exec__ = deactQ_L_14actionD___exec__; - deactQ_L_14actionG_methods.__asyn__ = deactQ_L_14actionD___asyn__; + deactQ_L_14actionG_methods.__init__ = (B_NoneType (*) (deactQ_L_14action, deactQ_Apa))deactQ_L_14actionD___init__; + deactQ_L_14actionG_methods.__call__ = ($R (*) (deactQ_L_14action, $Cont, B_int))deactQ_L_14actionD___call__; + deactQ_L_14actionG_methods.__exec__ = ($R (*) (deactQ_L_14action, $Cont, B_int))deactQ_L_14actionD___exec__; + deactQ_L_14actionG_methods.__asyn__ = (B_Msg (*) (deactQ_L_14action, B_int))deactQ_L_14actionD___asyn__; deactQ_L_14actionG_methods.__serialize__ = deactQ_L_14actionD___serialize__; deactQ_L_14actionG_methods.__deserialize__ = deactQ_L_14actionD___deserialize__; $register(&deactQ_L_14actionG_methods); @@ -1036,10 +1057,10 @@ void deactQ___init__ () { deactQ_L_16actionG_methods.__bool__ = (B_bool (*) (deactQ_L_16action))B_valueG_methods.__bool__; deactQ_L_16actionG_methods.__str__ = (B_str (*) (deactQ_L_16action))B_valueG_methods.__str__; deactQ_L_16actionG_methods.__repr__ = (B_str (*) (deactQ_L_16action))B_valueG_methods.__repr__; - deactQ_L_16actionG_methods.__init__ = deactQ_L_16actionD___init__; - deactQ_L_16actionG_methods.__call__ = deactQ_L_16actionD___call__; - deactQ_L_16actionG_methods.__exec__ = deactQ_L_16actionD___exec__; - deactQ_L_16actionG_methods.__asyn__ = deactQ_L_16actionD___asyn__; + deactQ_L_16actionG_methods.__init__ = (B_NoneType (*) (deactQ_L_16action, deactQ_Bepa))deactQ_L_16actionD___init__; + deactQ_L_16actionG_methods.__call__ = ($R (*) (deactQ_L_16action, $Cont, B_int))deactQ_L_16actionD___call__; + deactQ_L_16actionG_methods.__exec__ = ($R (*) (deactQ_L_16action, $Cont, B_int))deactQ_L_16actionD___exec__; + deactQ_L_16actionG_methods.__asyn__ = (B_Msg (*) (deactQ_L_16action, B_int))deactQ_L_16actionD___asyn__; deactQ_L_16actionG_methods.__serialize__ = deactQ_L_16actionD___serialize__; deactQ_L_16actionG_methods.__deserialize__ = deactQ_L_16actionD___deserialize__; $register(&deactQ_L_16actionG_methods); @@ -1050,10 +1071,10 @@ void deactQ___init__ () { deactQ_L_19actionG_methods.__bool__ = (B_bool (*) (deactQ_L_19action))B_valueG_methods.__bool__; deactQ_L_19actionG_methods.__str__ = (B_str (*) (deactQ_L_19action))B_valueG_methods.__str__; deactQ_L_19actionG_methods.__repr__ = (B_str (*) (deactQ_L_19action))B_valueG_methods.__repr__; - deactQ_L_19actionG_methods.__init__ = deactQ_L_19actionD___init__; - deactQ_L_19actionG_methods.__call__ = deactQ_L_19actionD___call__; - deactQ_L_19actionG_methods.__exec__ = deactQ_L_19actionD___exec__; - deactQ_L_19actionG_methods.__asyn__ = deactQ_L_19actionD___asyn__; + deactQ_L_19actionG_methods.__init__ = (B_NoneType (*) (deactQ_L_19action, deactQ_main))deactQ_L_19actionD___init__; + deactQ_L_19actionG_methods.__call__ = ($R (*) (deactQ_L_19action, $Cont, B_int))deactQ_L_19actionD___call__; + deactQ_L_19actionG_methods.__exec__ = ($R (*) (deactQ_L_19action, $Cont, B_int))deactQ_L_19actionD___exec__; + deactQ_L_19actionG_methods.__asyn__ = (B_Msg (*) (deactQ_L_19action, B_int))deactQ_L_19actionD___asyn__; deactQ_L_19actionG_methods.__serialize__ = deactQ_L_19actionD___serialize__; deactQ_L_19actionG_methods.__deserialize__ = deactQ_L_19actionD___deserialize__; $register(&deactQ_L_19actionG_methods); @@ -1064,8 +1085,8 @@ void deactQ___init__ () { deactQ_L_20ContG_methods.__bool__ = (B_bool (*) (deactQ_L_20Cont))B_valueG_methods.__bool__; deactQ_L_20ContG_methods.__str__ = (B_str (*) (deactQ_L_20Cont))B_valueG_methods.__str__; deactQ_L_20ContG_methods.__repr__ = (B_str (*) (deactQ_L_20Cont))B_valueG_methods.__repr__; - deactQ_L_20ContG_methods.__init__ = deactQ_L_20ContD___init__; - deactQ_L_20ContG_methods.__call__ = deactQ_L_20ContD___call__; + deactQ_L_20ContG_methods.__init__ = (B_NoneType (*) (deactQ_L_20Cont, deactQ_main, $Cont))deactQ_L_20ContD___init__; + deactQ_L_20ContG_methods.__call__ = ($R (*) (deactQ_L_20Cont, B_int))deactQ_L_20ContD___call__; deactQ_L_20ContG_methods.__serialize__ = deactQ_L_20ContD___serialize__; deactQ_L_20ContG_methods.__deserialize__ = deactQ_L_20ContD___deserialize__; $register(&deactQ_L_20ContG_methods); @@ -1076,8 +1097,8 @@ void deactQ___init__ () { deactQ_L_21ContG_methods.__bool__ = (B_bool (*) (deactQ_L_21Cont))B_valueG_methods.__bool__; deactQ_L_21ContG_methods.__str__ = (B_str (*) (deactQ_L_21Cont))B_valueG_methods.__str__; deactQ_L_21ContG_methods.__repr__ = (B_str (*) (deactQ_L_21Cont))B_valueG_methods.__repr__; - deactQ_L_21ContG_methods.__init__ = deactQ_L_21ContD___init__; - deactQ_L_21ContG_methods.__call__ = deactQ_L_21ContD___call__; + deactQ_L_21ContG_methods.__init__ = (B_NoneType (*) (deactQ_L_21Cont, deactQ_main, $Cont))deactQ_L_21ContD___init__; + deactQ_L_21ContG_methods.__call__ = ($R (*) (deactQ_L_21Cont, deactQ_Bepa))deactQ_L_21ContD___call__; deactQ_L_21ContG_methods.__serialize__ = deactQ_L_21ContD___serialize__; deactQ_L_21ContG_methods.__deserialize__ = deactQ_L_21ContD___deserialize__; $register(&deactQ_L_21ContG_methods); @@ -1088,8 +1109,8 @@ void deactQ___init__ () { deactQ_L_22ContG_methods.__bool__ = (B_bool (*) (deactQ_L_22Cont))B_valueG_methods.__bool__; deactQ_L_22ContG_methods.__str__ = (B_str (*) (deactQ_L_22Cont))B_valueG_methods.__str__; deactQ_L_22ContG_methods.__repr__ = (B_str (*) (deactQ_L_22Cont))B_valueG_methods.__repr__; - deactQ_L_22ContG_methods.__init__ = deactQ_L_22ContD___init__; - deactQ_L_22ContG_methods.__call__ = deactQ_L_22ContD___call__; + deactQ_L_22ContG_methods.__init__ = (B_NoneType (*) (deactQ_L_22Cont, deactQ_main, $Cont))deactQ_L_22ContD___init__; + deactQ_L_22ContG_methods.__call__ = ($R (*) (deactQ_L_22Cont, deactQ_Apa))deactQ_L_22ContD___call__; deactQ_L_22ContG_methods.__serialize__ = deactQ_L_22ContD___serialize__; deactQ_L_22ContG_methods.__deserialize__ = deactQ_L_22ContD___deserialize__; $register(&deactQ_L_22ContG_methods); @@ -1100,9 +1121,9 @@ void deactQ___init__ () { deactQ_L_23procG_methods.__bool__ = (B_bool (*) (deactQ_L_23proc))B_valueG_methods.__bool__; deactQ_L_23procG_methods.__str__ = (B_str (*) (deactQ_L_23proc))B_valueG_methods.__str__; deactQ_L_23procG_methods.__repr__ = (B_str (*) (deactQ_L_23proc))B_valueG_methods.__repr__; - deactQ_L_23procG_methods.__init__ = deactQ_L_23procD___init__; - deactQ_L_23procG_methods.__call__ = deactQ_L_23procD___call__; - deactQ_L_23procG_methods.__exec__ = deactQ_L_23procD___exec__; + deactQ_L_23procG_methods.__init__ = (B_NoneType (*) (deactQ_L_23proc, deactQ_main, int64_t))deactQ_L_23procD___init__; + deactQ_L_23procG_methods.__call__ = ($R (*) (deactQ_L_23proc, $Cont))deactQ_L_23procD___call__; + deactQ_L_23procG_methods.__exec__ = ($R (*) (deactQ_L_23proc, $Cont))deactQ_L_23procD___exec__; deactQ_L_23procG_methods.__serialize__ = deactQ_L_23procD___serialize__; deactQ_L_23procG_methods.__deserialize__ = deactQ_L_23procD___deserialize__; $register(&deactQ_L_23procG_methods); @@ -1113,8 +1134,8 @@ void deactQ___init__ () { deactQ_L_25ContG_methods.__bool__ = (B_bool (*) (deactQ_L_25Cont))B_valueG_methods.__bool__; deactQ_L_25ContG_methods.__str__ = (B_str (*) (deactQ_L_25Cont))B_valueG_methods.__str__; deactQ_L_25ContG_methods.__repr__ = (B_str (*) (deactQ_L_25Cont))B_valueG_methods.__repr__; - deactQ_L_25ContG_methods.__init__ = deactQ_L_25ContD___init__; - deactQ_L_25ContG_methods.__call__ = deactQ_L_25ContD___call__; + deactQ_L_25ContG_methods.__init__ = (B_NoneType (*) (deactQ_L_25Cont, $Cont, deactQ_Apa))deactQ_L_25ContD___init__; + deactQ_L_25ContG_methods.__call__ = ($R (*) (deactQ_L_25Cont, B_NoneType))deactQ_L_25ContD___call__; deactQ_L_25ContG_methods.__serialize__ = deactQ_L_25ContD___serialize__; deactQ_L_25ContG_methods.__deserialize__ = deactQ_L_25ContD___deserialize__; $register(&deactQ_L_25ContG_methods); @@ -1125,9 +1146,9 @@ void deactQ___init__ () { deactQ_L_26procG_methods.__bool__ = (B_bool (*) (deactQ_L_26proc))B_valueG_methods.__bool__; deactQ_L_26procG_methods.__str__ = (B_str (*) (deactQ_L_26proc))B_valueG_methods.__str__; deactQ_L_26procG_methods.__repr__ = (B_str (*) (deactQ_L_26proc))B_valueG_methods.__repr__; - deactQ_L_26procG_methods.__init__ = deactQ_L_26procD___init__; - deactQ_L_26procG_methods.__call__ = deactQ_L_26procD___call__; - deactQ_L_26procG_methods.__exec__ = deactQ_L_26procD___exec__; + deactQ_L_26procG_methods.__init__ = (B_NoneType (*) (deactQ_L_26proc, deactQ_Apa))deactQ_L_26procD___init__; + deactQ_L_26procG_methods.__call__ = ($R (*) (deactQ_L_26proc, $Cont))deactQ_L_26procD___call__; + deactQ_L_26procG_methods.__exec__ = ($R (*) (deactQ_L_26proc, $Cont))deactQ_L_26procD___exec__; deactQ_L_26procG_methods.__serialize__ = deactQ_L_26procD___serialize__; deactQ_L_26procG_methods.__deserialize__ = deactQ_L_26procD___deserialize__; $register(&deactQ_L_26procG_methods); @@ -1138,8 +1159,8 @@ void deactQ___init__ () { deactQ_L_28ContG_methods.__bool__ = (B_bool (*) (deactQ_L_28Cont))B_valueG_methods.__bool__; deactQ_L_28ContG_methods.__str__ = (B_str (*) (deactQ_L_28Cont))B_valueG_methods.__str__; deactQ_L_28ContG_methods.__repr__ = (B_str (*) (deactQ_L_28Cont))B_valueG_methods.__repr__; - deactQ_L_28ContG_methods.__init__ = deactQ_L_28ContD___init__; - deactQ_L_28ContG_methods.__call__ = deactQ_L_28ContD___call__; + deactQ_L_28ContG_methods.__init__ = (B_NoneType (*) (deactQ_L_28Cont, $Cont, deactQ_Bepa))deactQ_L_28ContD___init__; + deactQ_L_28ContG_methods.__call__ = ($R (*) (deactQ_L_28Cont, B_NoneType))deactQ_L_28ContD___call__; deactQ_L_28ContG_methods.__serialize__ = deactQ_L_28ContD___serialize__; deactQ_L_28ContG_methods.__deserialize__ = deactQ_L_28ContD___deserialize__; $register(&deactQ_L_28ContG_methods); @@ -1150,9 +1171,9 @@ void deactQ___init__ () { deactQ_L_29procG_methods.__bool__ = (B_bool (*) (deactQ_L_29proc))B_valueG_methods.__bool__; deactQ_L_29procG_methods.__str__ = (B_str (*) (deactQ_L_29proc))B_valueG_methods.__str__; deactQ_L_29procG_methods.__repr__ = (B_str (*) (deactQ_L_29proc))B_valueG_methods.__repr__; - deactQ_L_29procG_methods.__init__ = deactQ_L_29procD___init__; - deactQ_L_29procG_methods.__call__ = deactQ_L_29procD___call__; - deactQ_L_29procG_methods.__exec__ = deactQ_L_29procD___exec__; + deactQ_L_29procG_methods.__init__ = (B_NoneType (*) (deactQ_L_29proc, deactQ_Bepa))deactQ_L_29procD___init__; + deactQ_L_29procG_methods.__call__ = ($R (*) (deactQ_L_29proc, $Cont))deactQ_L_29procD___call__; + deactQ_L_29procG_methods.__exec__ = ($R (*) (deactQ_L_29proc, $Cont))deactQ_L_29procD___exec__; deactQ_L_29procG_methods.__serialize__ = deactQ_L_29procD___serialize__; deactQ_L_29procG_methods.__deserialize__ = deactQ_L_29procD___deserialize__; $register(&deactQ_L_29procG_methods); @@ -1163,8 +1184,8 @@ void deactQ___init__ () { deactQ_L_31ContG_methods.__bool__ = (B_bool (*) (deactQ_L_31Cont))B_valueG_methods.__bool__; deactQ_L_31ContG_methods.__str__ = (B_str (*) (deactQ_L_31Cont))B_valueG_methods.__str__; deactQ_L_31ContG_methods.__repr__ = (B_str (*) (deactQ_L_31Cont))B_valueG_methods.__repr__; - deactQ_L_31ContG_methods.__init__ = deactQ_L_31ContD___init__; - deactQ_L_31ContG_methods.__call__ = deactQ_L_31ContD___call__; + deactQ_L_31ContG_methods.__init__ = (B_NoneType (*) (deactQ_L_31Cont, $Cont, deactQ_main))deactQ_L_31ContD___init__; + deactQ_L_31ContG_methods.__call__ = ($R (*) (deactQ_L_31Cont, B_NoneType))deactQ_L_31ContD___call__; deactQ_L_31ContG_methods.__serialize__ = deactQ_L_31ContD___serialize__; deactQ_L_31ContG_methods.__deserialize__ = deactQ_L_31ContD___deserialize__; $register(&deactQ_L_31ContG_methods); @@ -1175,9 +1196,9 @@ void deactQ___init__ () { deactQ_L_32procG_methods.__bool__ = (B_bool (*) (deactQ_L_32proc))B_valueG_methods.__bool__; deactQ_L_32procG_methods.__str__ = (B_str (*) (deactQ_L_32proc))B_valueG_methods.__str__; deactQ_L_32procG_methods.__repr__ = (B_str (*) (deactQ_L_32proc))B_valueG_methods.__repr__; - deactQ_L_32procG_methods.__init__ = deactQ_L_32procD___init__; - deactQ_L_32procG_methods.__call__ = deactQ_L_32procD___call__; - deactQ_L_32procG_methods.__exec__ = deactQ_L_32procD___exec__; + deactQ_L_32procG_methods.__init__ = (B_NoneType (*) (deactQ_L_32proc, deactQ_main, B_Env))deactQ_L_32procD___init__; + deactQ_L_32procG_methods.__call__ = ($R (*) (deactQ_L_32proc, $Cont))deactQ_L_32procD___call__; + deactQ_L_32procG_methods.__exec__ = ($R (*) (deactQ_L_32proc, $Cont))deactQ_L_32procD___exec__; deactQ_L_32procG_methods.__serialize__ = deactQ_L_32procD___serialize__; deactQ_L_32procG_methods.__deserialize__ = deactQ_L_32procD___deserialize__; $register(&deactQ_L_32procG_methods); @@ -1190,13 +1211,13 @@ void deactQ___init__ () { deactQ_ApaG_methods.__repr__ = (B_str (*) (deactQ_Apa))$ActorG_methods.__repr__; deactQ_ApaG_methods.__resume__ = (B_NoneType (*) (deactQ_Apa))$ActorG_methods.__resume__; deactQ_ApaG_methods.__cleanup__ = (B_NoneType (*) (deactQ_Apa))$ActorG_methods.__cleanup__; - deactQ_ApaG_methods.__init__ = deactQ_ApaD___init__; - deactQ_ApaG_methods.setupG_local = deactQ_ApaD_setupG_local; - deactQ_ApaG_methods.computeG_local = deactQ_ApaD_computeG_local; - deactQ_ApaG_methods.noticeG_local = deactQ_ApaD_noticeG_local; - deactQ_ApaG_methods.setup = deactQ_ApaD_setup; - deactQ_ApaG_methods.compute = deactQ_ApaD_compute; - deactQ_ApaG_methods.notice = deactQ_ApaD_notice; + deactQ_ApaG_methods.__init__ = ($R (*) (deactQ_Apa, $Cont))deactQ_ApaD___init__; + deactQ_ApaG_methods.setupG_local = ($R (*) (deactQ_Apa, $Cont, $action))deactQ_ApaD_setupG_local; + deactQ_ApaG_methods.computeG_local = ($R (*) (deactQ_Apa, $Cont, $action))deactQ_ApaD_computeG_local; + deactQ_ApaG_methods.noticeG_local = ($R (*) (deactQ_Apa, $Cont, int64_t))deactQ_ApaD_noticeG_local; + deactQ_ApaG_methods.setup = (B_Msg (*) (deactQ_Apa, $action))deactQ_ApaD_setup; + deactQ_ApaG_methods.compute = (B_Msg (*) (deactQ_Apa, $action))deactQ_ApaD_compute; + deactQ_ApaG_methods.notice = (B_Msg (*) (deactQ_Apa, int64_t))deactQ_ApaD_notice; deactQ_ApaG_methods.__serialize__ = deactQ_ApaD___serialize__; deactQ_ApaG_methods.__deserialize__ = deactQ_ApaD___deserialize__; $register(&deactQ_ApaG_methods); @@ -1209,9 +1230,9 @@ void deactQ___init__ () { deactQ_BepaG_methods.__repr__ = (B_str (*) (deactQ_Bepa))$ActorG_methods.__repr__; deactQ_BepaG_methods.__resume__ = (B_NoneType (*) (deactQ_Bepa))$ActorG_methods.__resume__; deactQ_BepaG_methods.__cleanup__ = (B_NoneType (*) (deactQ_Bepa))$ActorG_methods.__cleanup__; - deactQ_BepaG_methods.__init__ = deactQ_BepaD___init__; - deactQ_BepaG_methods.callbackG_local = deactQ_BepaD_callbackG_local; - deactQ_BepaG_methods.callback = deactQ_BepaD_callback; + deactQ_BepaG_methods.__init__ = ($R (*) (deactQ_Bepa, $Cont))deactQ_BepaD___init__; + deactQ_BepaG_methods.callbackG_local = ($R (*) (deactQ_Bepa, $Cont, int64_t))deactQ_BepaD_callbackG_local; + deactQ_BepaG_methods.callback = (B_Msg (*) (deactQ_Bepa, int64_t))deactQ_BepaD_callback; deactQ_BepaG_methods.__serialize__ = deactQ_BepaD___serialize__; deactQ_BepaG_methods.__deserialize__ = deactQ_BepaD___deserialize__; $register(&deactQ_BepaG_methods); @@ -1224,9 +1245,9 @@ void deactQ___init__ () { deactQ_mainG_methods.__repr__ = (B_str (*) (deactQ_main))$ActorG_methods.__repr__; deactQ_mainG_methods.__resume__ = (B_NoneType (*) (deactQ_main))$ActorG_methods.__resume__; deactQ_mainG_methods.__cleanup__ = (B_NoneType (*) (deactQ_main))$ActorG_methods.__cleanup__; - deactQ_mainG_methods.__init__ = deactQ_mainD___init__; - deactQ_mainG_methods.myprocG_local = deactQ_mainD_myprocG_local; - deactQ_mainG_methods.myproc = deactQ_mainD_myproc; + deactQ_mainG_methods.__init__ = ($R (*) (deactQ_main, $Cont, B_Env))deactQ_mainD___init__; + deactQ_mainG_methods.myprocG_local = ($R (*) (deactQ_main, $Cont, int64_t))deactQ_mainD_myprocG_local; + deactQ_mainG_methods.myproc = (B_Msg (*) (deactQ_main, int64_t))deactQ_mainD_myproc; deactQ_mainG_methods.__serialize__ = deactQ_mainD___serialize__; deactQ_mainG_methods.__deserialize__ = deactQ_mainD___deserialize__; $register(&deactQ_mainG_methods); diff --git a/compiler/lib/test/9-codegen/deact.h b/compiler/lib/test/9-codegen/deact.h index 2d86ff181..dd4872e79 100644 --- a/compiler/lib/test/9-codegen/deact.h +++ b/compiler/lib/test/9-codegen/deact.h @@ -83,8 +83,7 @@ struct deactQ_L_4action { struct deactQ_L_4actionG_class *$class; deactQ_Apa L_3obj; }; -$R deactQ_U_L_5C_3cont ($action, $Cont, int64_t); -$R deactQ_L_5C_3cont ($action, $Cont, B_int); +$R deactQ_L_5C_3cont ($action, $Cont, int64_t); struct deactQ_L_6ContG_class { char *$GCINFO; int $class_id; @@ -142,7 +141,7 @@ struct deactQ_L_9procG_class { char *$GCINFO; int $class_id; $SuperG_class $superclass; - B_NoneType (*__init__) (deactQ_L_9proc, deactQ_Apa, B_int); + B_NoneType (*__init__) (deactQ_L_9proc, deactQ_Apa, int64_t); void (*__serialize__) (deactQ_L_9proc, $Serial$state); deactQ_L_9proc (*__deserialize__) (deactQ_L_9proc, $Serial$state); B_bool (*__bool__) (deactQ_L_9proc); @@ -154,13 +153,13 @@ struct deactQ_L_9procG_class { struct deactQ_L_9proc { struct deactQ_L_9procG_class *$class; deactQ_Apa self; - B_int i; + int64_t i; }; struct deactQ_L_10procG_class { char *$GCINFO; int $class_id; $SuperG_class $superclass; - B_NoneType (*__init__) (deactQ_L_10proc, deactQ_Bepa, B_int); + B_NoneType (*__init__) (deactQ_L_10proc, deactQ_Bepa, int64_t); void (*__serialize__) (deactQ_L_10proc, $Serial$state); deactQ_L_10proc (*__deserialize__) (deactQ_L_10proc, $Serial$state); B_bool (*__bool__) (deactQ_L_10proc); @@ -172,7 +171,7 @@ struct deactQ_L_10procG_class { struct deactQ_L_10proc { struct deactQ_L_10procG_class *$class; deactQ_Bepa self; - B_int i; + int64_t i; }; struct deactQ_L_14actionG_class { char *$GCINFO; @@ -228,8 +227,7 @@ struct deactQ_L_19action { struct deactQ_L_19actionG_class *$class; deactQ_main L_18obj; }; -$R deactQ_U_1L_17C_9cont (deactQ_main, $Cont, int64_t); -$R deactQ_L_17C_9cont (deactQ_main, $Cont, B_int); +$R deactQ_L_17C_9cont (deactQ_main, $Cont, int64_t); struct deactQ_L_20ContG_class { char *$GCINFO; int $class_id; @@ -287,7 +285,7 @@ struct deactQ_L_23procG_class { char *$GCINFO; int $class_id; $SuperG_class $superclass; - B_NoneType (*__init__) (deactQ_L_23proc, deactQ_main, B_int); + B_NoneType (*__init__) (deactQ_L_23proc, deactQ_main, int64_t); void (*__serialize__) (deactQ_L_23proc, $Serial$state); deactQ_L_23proc (*__deserialize__) (deactQ_L_23proc, $Serial$state); B_bool (*__bool__) (deactQ_L_23proc); @@ -299,7 +297,7 @@ struct deactQ_L_23procG_class { struct deactQ_L_23proc { struct deactQ_L_23procG_class *$class; deactQ_main self; - B_int i; + int64_t i; }; $R deactQ_L_24C_11cont ($Cont, deactQ_Apa, B_NoneType); struct deactQ_L_25ContG_class { @@ -421,10 +419,10 @@ struct deactQ_ApaG_class { B_NoneType (*__cleanup__) (deactQ_Apa); $R (*setupG_local) (deactQ_Apa, $Cont, $action); $R (*computeG_local) (deactQ_Apa, $Cont, $action); - $R (*noticeG_local) (deactQ_Apa, $Cont, B_int); + $R (*noticeG_local) (deactQ_Apa, $Cont, int64_t); B_Msg (*setup) (deactQ_Apa, $action); B_Msg (*compute) (deactQ_Apa, $action); - B_Msg (*notice) (deactQ_Apa, B_int); + B_Msg (*notice) (deactQ_Apa, int64_t); }; struct deactQ_Apa { struct deactQ_ApaG_class *$class; @@ -451,8 +449,8 @@ struct deactQ_BepaG_class { B_str (*__repr__) (deactQ_Bepa); B_NoneType (*__resume__) (deactQ_Bepa); B_NoneType (*__cleanup__) (deactQ_Bepa); - $R (*callbackG_local) (deactQ_Bepa, $Cont, B_int); - B_Msg (*callback) (deactQ_Bepa, B_int); + $R (*callbackG_local) (deactQ_Bepa, $Cont, int64_t); + B_Msg (*callback) (deactQ_Bepa, int64_t); }; struct deactQ_Bepa { struct deactQ_BepaG_class *$class; @@ -479,8 +477,8 @@ struct deactQ_mainG_class { B_str (*__repr__) (deactQ_main); B_NoneType (*__resume__) (deactQ_main); B_NoneType (*__cleanup__) (deactQ_main); - $R (*myprocG_local) (deactQ_main, $Cont, B_int); - B_Msg (*myproc) (deactQ_main, B_int); + $R (*myprocG_local) (deactQ_main, $Cont, int64_t); + B_Msg (*myproc) (deactQ_main, int64_t); }; struct deactQ_main { struct deactQ_mainG_class *$class; @@ -498,7 +496,7 @@ struct deactQ_main { deactQ_Apa a; deactQ_Bepa b; B_Msg x; - B_int r; + int64_t r; }; $R deactQ_ApaG_newact ($Cont); $R deactQ_BepaG_newact ($Cont); @@ -514,9 +512,9 @@ deactQ_L_7proc deactQ_L_7procG_new(deactQ_Apa, $action); extern struct deactQ_L_8procG_class deactQ_L_8procG_methods; deactQ_L_8proc deactQ_L_8procG_new(deactQ_Apa, $action); extern struct deactQ_L_9procG_class deactQ_L_9procG_methods; -deactQ_L_9proc deactQ_L_9procG_new(deactQ_Apa, B_int); +deactQ_L_9proc deactQ_L_9procG_new(deactQ_Apa, int64_t); extern struct deactQ_L_10procG_class deactQ_L_10procG_methods; -deactQ_L_10proc deactQ_L_10procG_new(deactQ_Bepa, B_int); +deactQ_L_10proc deactQ_L_10procG_new(deactQ_Bepa, int64_t); extern struct deactQ_L_14actionG_class deactQ_L_14actionG_methods; deactQ_L_14action deactQ_L_14actionG_new(deactQ_Apa); extern struct deactQ_L_16actionG_class deactQ_L_16actionG_methods; @@ -530,7 +528,7 @@ deactQ_L_21Cont deactQ_L_21ContG_new(deactQ_main, $Cont); extern struct deactQ_L_22ContG_class deactQ_L_22ContG_methods; deactQ_L_22Cont deactQ_L_22ContG_new(deactQ_main, $Cont); extern struct deactQ_L_23procG_class deactQ_L_23procG_methods; -deactQ_L_23proc deactQ_L_23procG_new(deactQ_main, B_int); +deactQ_L_23proc deactQ_L_23procG_new(deactQ_main, int64_t); extern struct deactQ_L_25ContG_class deactQ_L_25ContG_methods; deactQ_L_25Cont deactQ_L_25ContG_new($Cont, deactQ_Apa); extern struct deactQ_L_26procG_class deactQ_L_26procG_methods; diff --git a/compiler/lib/test/9-codegen/deact.input b/compiler/lib/test/9-codegen/deact.input index fe20e4c27..db1230c9b 100644 --- a/compiler/lib/test/9-codegen/deact.input +++ b/compiler/lib/test/9-codegen/deact.input @@ -19,20 +19,18 @@ class L_4action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin_ return None # recursive group: proc def __call__ (L_self : L_4action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_4action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_4action, G_1 : __builtin__.int) -> __builtin__.int: L_3obj: Apa = L_self.L_3obj return L_3obj.notice(G_1) # (recursive group) -proc def U_L_5C_3cont (cb : $action[(__builtin__.int,), __builtin__.int], C_cont : $Cont[__builtin__.int], U_2C_4res : __builtin__.int) -> $R: - U_3v: __builtin__.int = U_2C_4res +proc def L_5C_3cont (cb : $action[(__builtin__.int,), __builtin__.int], C_cont : $Cont[__builtin__.int], C_4res : UNBOXED __builtin__.int) -> $R: + v: UNBOXED __builtin__.int = (UNBOX __builtin__.int C_4res) m: __builtin__.Msg[__builtin__.int] = cb.__asyn__((BOX __builtin__.int (UNBOX __builtin__.int 2))) - U_4N_tmp: __builtin__.int = (U_3v * (UNBOX __builtin__.int 10)) - return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int U_4N_tmp)) -proc def L_5C_3cont (cb : $action[(__builtin__.int,), __builtin__.int], C_cont : $Cont[__builtin__.int], C_4res : __builtin__.int) -> $R: - return U_L_5C_3cont(cb, C_cont, (UNBOX __builtin__.int C_4res)) + N_tmp: UNBOXED __builtin__.int = ((UNBOX __builtin__.int v) * (UNBOX __builtin__.int 10)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int N_tmp)) class L_6Cont ($Cont[__builtin__.int], __builtin__.value): @property cb : $action[(__builtin__.int,), __builtin__.int] @@ -85,15 +83,15 @@ class L_9proc ($proc[(), __builtin__.int], __builtin__.value): self : Apa @property i : __builtin__.int - pure def __init__ (L_self : L_9proc, self : Apa, i : __builtin__.int) -> None: + pure def __init__ (L_self : L_9proc, self : Apa, i : UNBOXED __builtin__.int) -> None: L_self.self = self - L_self.i = i + L_self.i = (UNBOX __builtin__.int i) return None # recursive group: proc def __call__ (L_self : L_9proc, C_cont : $Cont[__builtin__.int]) -> $R: self: Apa = L_self.self - U_5i: __builtin__.int = (UNBOX __builtin__.int L_self.i) - return self.noticeG_local(C_cont, (BOX __builtin__.int U_5i)) + i: UNBOXED __builtin__.int = L_self.i + return self.noticeG_local(C_cont, (UNBOX __builtin__.int i)) proc def __exec__ (L_self : L_9proc, C_cont : $Cont[__builtin__.int]) -> $R: return L_self.__call__(C_cont) # (recursive group) @@ -102,15 +100,15 @@ class L_10proc ($proc[(), __builtin__.int], __builtin__.value): self : Bepa @property i : __builtin__.int - pure def __init__ (L_self : L_10proc, self : Bepa, i : __builtin__.int) -> None: + pure def __init__ (L_self : L_10proc, self : Bepa, i : UNBOXED __builtin__.int) -> None: L_self.self = self - L_self.i = i + L_self.i = (UNBOX __builtin__.int i) return None # recursive group: proc def __call__ (L_self : L_10proc, C_cont : $Cont[__builtin__.int]) -> $R: self: Bepa = L_self.self - U_6i: __builtin__.int = (UNBOX __builtin__.int L_self.i) - return self.callbackG_local(C_cont, (BOX __builtin__.int U_6i)) + i: UNBOXED __builtin__.int = L_self.i + return self.callbackG_local(C_cont, (UNBOX __builtin__.int i)) proc def __exec__ (L_self : L_10proc, C_cont : $Cont[__builtin__.int]) -> $R: return L_self.__call__(C_cont) # (recursive group) @@ -122,9 +120,9 @@ class L_14action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin return None # recursive group: proc def __call__ (L_self : L_14action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_14action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_14action, G_1 : __builtin__.int) -> __builtin__.int: L_13obj: Apa = L_self.L_13obj return L_13obj.notice(G_1) @@ -137,9 +135,9 @@ class L_16action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin return None # recursive group: proc def __call__ (L_self : L_16action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_16action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_16action, G_1 : __builtin__.int) -> __builtin__.int: L_15obj: Bepa = L_self.L_15obj return L_15obj.callback(G_1) @@ -152,21 +150,19 @@ class L_19action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin return None # recursive group: proc def __call__ (L_self : L_19action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_19action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_19action, G_1 : __builtin__.int) -> __builtin__.int: L_18obj: main = L_self.L_18obj return L_18obj.myproc(G_1) # (recursive group) -proc def U_1L_17C_9cont (self : main, C_cont : $Cont[None], U_7C_10res : __builtin__.int) -> $R: - self.r = (BOX __builtin__.int U_7C_10res) - print@[(__builtin__.str, __builtin__.int)](("\"r =\"", self.r), None, None, None, None) +proc def L_17C_9cont (self : main, C_cont : $Cont[None], C_10res : UNBOXED __builtin__.int) -> $R: + self.r = (UNBOX __builtin__.int C_10res) + print@[(__builtin__.str, __builtin__.int)](("\"r =\"", (BOX __builtin__.int self.r)), None, None, None, None) (async self.a.compute)(L_19action(self)) print@[(__builtin__.str,)](("\"main\"",), None, None, None, None) return $R_CONT@[None](C_cont, None) -proc def L_17C_9cont (self : main, C_cont : $Cont[None], C_10res : __builtin__.int) -> $R: - return U_1L_17C_9cont(self, C_cont, (UNBOX __builtin__.int C_10res)) class L_20Cont ($Cont[__builtin__.int], __builtin__.value): @property self : main @@ -220,15 +216,15 @@ class L_23proc ($proc[(), __builtin__.int], __builtin__.value): self : main @property i : __builtin__.int - pure def __init__ (L_self : L_23proc, self : main, i : __builtin__.int) -> None: + pure def __init__ (L_self : L_23proc, self : main, i : UNBOXED __builtin__.int) -> None: L_self.self = self - L_self.i = i + L_self.i = (UNBOX __builtin__.int i) return None # recursive group: proc def __call__ (L_self : L_23proc, C_cont : $Cont[__builtin__.int]) -> $R: self: main = L_self.self - U_8i: __builtin__.int = (UNBOX __builtin__.int L_self.i) - return self.myprocG_local(C_cont, (BOX __builtin__.int U_8i)) + i: UNBOXED __builtin__.int = L_self.i + return self.myprocG_local(C_cont, (UNBOX __builtin__.int i)) proc def __exec__ (L_self : L_23proc, C_cont : $Cont[__builtin__.int]) -> $R: return L_self.__call__(C_cont) # (recursive group) @@ -330,26 +326,26 @@ class Apa ($Actor, __builtin__.value): proc def computeG_local (self : Apa, C_cont : $Cont[__builtin__.int], cb : $action[(__builtin__.int,), __builtin__.int]) -> $R: print@[(__builtin__.str,)](("\"compute\"",), None, None, None, None) return $AWAIT@[__builtin__.int](L_6Cont(cb, C_cont), cb.__asyn__((BOX __builtin__.int (UNBOX __builtin__.int 1)))) - proc def noticeG_local (self : Apa, C_cont : $Cont[__builtin__.int], i : __builtin__.int) -> $R: + proc def noticeG_local (self : Apa, C_cont : $Cont[__builtin__.int], i : UNBOXED __builtin__.int) -> $R: print@[(__builtin__.str,)](("\"notice\"",), None, None, None, None) - U_9N_1tmp: __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) - return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int U_9N_1tmp)) + N_1tmp: UNBOXED __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int N_1tmp)) action def setup (self : Apa, cb : $action[(__builtin__.int,), __builtin__.int]) -> None: return $ASYNC@[None](self, L_7proc(self, cb)) - action def compute (self : Apa, cb : $action[(__builtin__.int,), __builtin__.int]) -> __builtin__.int: + action def compute (self : Apa, cb : $action[(__builtin__.int,), __builtin__.int]) -> UNBOXED __builtin__.int: return $ASYNC@[__builtin__.int](self, L_8proc(self, cb)) - action def notice (self : Apa, i : __builtin__.int) -> __builtin__.int: - return $ASYNC@[__builtin__.int](self, L_9proc(self, i)) + action def notice (self : Apa, i : UNBOXED __builtin__.int) -> UNBOXED __builtin__.int: + return $ASYNC@[__builtin__.int](self, L_9proc(self, (UNBOX __builtin__.int i))) class Bepa ($Actor, __builtin__.value): proc def __init__ (self : Bepa, C_cont : $Cont[None]) -> $R: print@[(__builtin__.str,)](("\"Bepa\"",), None, None, None, None) return $R_CONT@[None](C_cont, None) - proc def callbackG_local (self : Bepa, C_cont : $Cont[__builtin__.int], i : __builtin__.int) -> $R: - print@[(__builtin__.str, __builtin__.int)](("\"callback\"", i), None, None, None, None) - U_10N_2tmp: __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) - return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int U_10N_2tmp)) - action def callback (self : Bepa, i : __builtin__.int) -> __builtin__.int: - return $ASYNC@[__builtin__.int](self, L_10proc(self, i)) + proc def callbackG_local (self : Bepa, C_cont : $Cont[__builtin__.int], i : UNBOXED __builtin__.int) -> $R: + print@[(__builtin__.str, __builtin__.int)](("\"callback\"", (BOX __builtin__.int i)), None, None, None, None) + N_2tmp: UNBOXED __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int N_2tmp)) + action def callback (self : Bepa, i : UNBOXED __builtin__.int) -> UNBOXED __builtin__.int: + return $ASYNC@[__builtin__.int](self, L_10proc(self, (UNBOX __builtin__.int i))) class main ($Actor, __builtin__.value): @property env : __builtin__.Env @@ -364,13 +360,13 @@ class main ($Actor, __builtin__.value): proc def __init__ (self : main, C_cont : $Cont[None], env : __builtin__.Env) -> $R: self.env = env return ApaG_newact(L_22Cont(self, C_cont)) - proc def myprocG_local (self : main, C_cont : $Cont[__builtin__.int], i : __builtin__.int) -> $R: - print@[(__builtin__.str, __builtin__.int)](("\"myproc\"", i), None, None, None, None) + proc def myprocG_local (self : main, C_cont : $Cont[__builtin__.int], i : UNBOXED __builtin__.int) -> $R: + print@[(__builtin__.str, __builtin__.int)](("\"myproc\"", (BOX __builtin__.int i)), None, None, None, None) if (BOX __builtin__.bool ((UNBOX __builtin__.int i) == (UNBOX __builtin__.int 2))): - (async self.env.exit)((BOX __builtin__.int (UNBOX __builtin__.int 0))) - return $R_CONT@[__builtin__.int](C_cont, i) - action def myproc (self : main, i : __builtin__.int) -> __builtin__.int: - return $ASYNC@[__builtin__.int](self, L_23proc(self, i)) + (async self.env.exit)((UNBOX __builtin__.int 0)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int i)) + action def myproc (self : main, i : UNBOXED __builtin__.int) -> UNBOXED __builtin__.int: + return $ASYNC@[__builtin__.int](self, L_23proc(self, (UNBOX __builtin__.int i))) proc def ApaG_newact (C_cont : $Cont[Apa]) -> $R: G_act: Apa = $NEWACTOR@[Apa]() $InstallFinalizer@[Apa](G_act) diff --git a/compiler/lib/test/9-codegen/ints.c b/compiler/lib/test/9-codegen/ints.c index 21f38558a..11ef535ae 100644 --- a/compiler/lib/test/9-codegen/ints.c +++ b/compiler/lib/test/9-codegen/ints.c @@ -1,41 +1,29 @@ /* Acton impl hash: test-hash */ #include "rts/common.h" #include "out/types/ints.h" -int64_t intsQ_U_int64_min; -B_int intsQ_int64_min; -int64_t intsQ_U_1int64_max; -B_int intsQ_int64_max; -int32_t intsQ_U_2int32_min; -B_i32 intsQ_int32_min; -int32_t intsQ_U_3int32_max; -B_i32 intsQ_int32_max; -int16_t intsQ_U_4int16_min; -B_i16 intsQ_int16_min; -int16_t intsQ_U_5int16_max; -B_i16 intsQ_int16_max; -B_Number intsQ_W_int8_min_2; -B_i8 intsQ_int8_min; -B_Number intsQ_W_int8_max_2; -B_i8 intsQ_int8_max; -uint64_t intsQ_U_6uint64_min; -B_u64 intsQ_uint64_min; -uint64_t intsQ_U_7uint64_max; -B_u64 intsQ_uint64_max; -uint32_t intsQ_U_8uint32_min; -B_u32 intsQ_uint32_min; -uint32_t intsQ_U_9uint32_max; -B_u32 intsQ_uint32_max; -uint16_t intsQ_U_10uint16_min; -B_u16 intsQ_uint16_min; -uint16_t intsQ_U_11uint16_max; -B_u16 intsQ_uint16_max; -B_Number intsQ_W_uint8_min_2; -B_u8 intsQ_uint8_min; -B_Number intsQ_W_uint8_max_2; -B_u8 intsQ_uint8_max; +int64_t intsQ_int64_min; +int64_t intsQ_int64_max; +int32_t intsQ_int32_min; +int32_t intsQ_int32_max; +int16_t intsQ_int16_min; +int16_t intsQ_int16_max; +int8_t intsQ_int8_min; +int8_t intsQ_int8_max; +uint64_t intsQ_uint64_min; +uint64_t intsQ_uint64_max; +uint32_t intsQ_uint32_min; +uint32_t intsQ_uint32_max; +uint16_t intsQ_uint16_min; +uint16_t intsQ_uint16_max; +uint8_t intsQ_uint8_min; +uint8_t intsQ_uint8_max; +B_Number intsQ_W_bigint_small_2; B_bigint intsQ_bigint_small; +B_Number intsQ_W_bigint_neg_small_2; B_bigint intsQ_bigint_neg_small; +B_Number intsQ_W_bigint_i64_max_2; B_bigint intsQ_bigint_i64_max; +B_Number intsQ_W_bigint_i64_min_2; B_bigint intsQ_bigint_i64_min; B_bigint intsQ_bigint_i64_underflow; B_bigint intsQ_bigint_u64_edge; @@ -46,77 +34,53 @@ int intsQ_done$ = 0; void intsQ___init__ () { if (intsQ_done$) return; intsQ_done$ = 1; - int64_t U_int64_min = -9223372036854775808LL; - intsQ_U_int64_min = U_int64_min; - B_int int64_min = toB_int(intsQ_U_int64_min); + int64_t int64_min = (-9223372036854775807LL - 1LL); intsQ_int64_min = int64_min; - int64_t U_1int64_max = 9223372036854775807LL; - intsQ_U_1int64_max = U_1int64_max; - B_int int64_max = toB_int(intsQ_U_1int64_max); + int64_t int64_max = 9223372036854775807LL; intsQ_int64_max = int64_max; - int32_t U_2int32_min = -2147483648; - intsQ_U_2int32_min = U_2int32_min; - B_i32 int32_min = toB_i32(intsQ_U_2int32_min); + int32_t int32_min = -2147483648; intsQ_int32_min = int32_min; - int32_t U_3int32_max = 2147483647; - intsQ_U_3int32_max = U_3int32_max; - B_i32 int32_max = toB_i32(intsQ_U_3int32_max); + int32_t int32_max = 2147483647; intsQ_int32_max = int32_max; - int16_t U_4int16_min = -32768; - intsQ_U_4int16_min = U_4int16_min; - B_i16 int16_min = toB_i16(intsQ_U_4int16_min); + int16_t int16_min = -32768; intsQ_int16_min = int16_min; - int16_t U_5int16_max = 32767; - intsQ_U_5int16_max = U_5int16_max; - B_i16 int16_max = toB_i16(intsQ_U_5int16_max); + int16_t int16_max = 32767; intsQ_int16_max = int16_max; - B_Number W_int8_min_2 = (B_Number)B_IntegralD_i8G_witness; - intsQ_W_int8_min_2 = W_int8_min_2; - B_i8 int8_min = ((B_i8 (*) (B_Number, B_atom))intsQ_W_int8_min_2->$class->__fromatom__)(intsQ_W_int8_min_2, ((B_atom)toB_bigint2("-128"))); + int8_t int8_min = -128; intsQ_int8_min = int8_min; - B_Number W_int8_max_2 = (B_Number)B_IntegralD_i8G_witness; - intsQ_W_int8_max_2 = W_int8_max_2; - B_i8 int8_max = ((B_i8 (*) (B_Number, B_atom))intsQ_W_int8_max_2->$class->__fromatom__)(intsQ_W_int8_max_2, ((B_atom)toB_bigint(127UL))); + int8_t int8_max = 127; intsQ_int8_max = int8_max; - uint64_t U_6uint64_min = 0UL; - intsQ_U_6uint64_min = U_6uint64_min; - B_u64 uint64_min = toB_u64(intsQ_U_6uint64_min); + uint64_t uint64_min = 0UL; intsQ_uint64_min = uint64_min; - uint64_t U_7uint64_max = 18446744073709551615UL; - intsQ_U_7uint64_max = U_7uint64_max; - B_u64 uint64_max = toB_u64(intsQ_U_7uint64_max); + uint64_t uint64_max = 18446744073709551615UL; intsQ_uint64_max = uint64_max; - uint32_t U_8uint32_min = 0; - intsQ_U_8uint32_min = U_8uint32_min; - B_u32 uint32_min = toB_u32(intsQ_U_8uint32_min); + uint32_t uint32_min = 0; intsQ_uint32_min = uint32_min; - uint32_t U_9uint32_max = 4294967295; - intsQ_U_9uint32_max = U_9uint32_max; - B_u32 uint32_max = toB_u32(intsQ_U_9uint32_max); + uint32_t uint32_max = 4294967295; intsQ_uint32_max = uint32_max; - uint16_t U_10uint16_min = 0; - intsQ_U_10uint16_min = U_10uint16_min; - B_u16 uint16_min = toB_u16(intsQ_U_10uint16_min); + uint16_t uint16_min = 0; intsQ_uint16_min = uint16_min; - uint16_t U_11uint16_max = 65535; - intsQ_U_11uint16_max = U_11uint16_max; - B_u16 uint16_max = toB_u16(intsQ_U_11uint16_max); + uint16_t uint16_max = 65535; intsQ_uint16_max = uint16_max; - B_Number W_uint8_min_2 = (B_Number)B_IntegralD_u8G_witness; - intsQ_W_uint8_min_2 = W_uint8_min_2; - B_u8 uint8_min = ((B_u8 (*) (B_Number, B_atom))intsQ_W_uint8_min_2->$class->__fromatom__)(intsQ_W_uint8_min_2, ((B_atom)toB_bigint(0UL))); + uint8_t uint8_min = 0; intsQ_uint8_min = uint8_min; - B_Number W_uint8_max_2 = (B_Number)B_IntegralD_u8G_witness; - intsQ_W_uint8_max_2 = W_uint8_max_2; - B_u8 uint8_max = ((B_u8 (*) (B_Number, B_atom))intsQ_W_uint8_max_2->$class->__fromatom__)(intsQ_W_uint8_max_2, ((B_atom)toB_bigint(255UL))); + uint8_t uint8_max = 255; intsQ_uint8_max = uint8_max; - B_bigint bigint_small = ((B_bigint)toB_bigint(42UL)); + B_Number W_bigint_small_2 = (B_Number)B_IntegralD_bigintG_witness; + intsQ_W_bigint_small_2 = W_bigint_small_2; + B_bigint bigint_small = ((B_bigint (*) ($WORD, B_atom))intsQ_W_bigint_small_2->$class->__fromatom__)(intsQ_W_bigint_small_2, ((B_atom)toB_bigint(42UL))); intsQ_bigint_small = bigint_small; - B_bigint bigint_neg_small = ((B_bigint)toB_bigint2("-1")); + B_Number W_bigint_neg_small_2 = (B_Number)B_IntegralD_bigintG_witness; + intsQ_W_bigint_neg_small_2 = W_bigint_neg_small_2; + B_bigint bigint_neg_small = ((B_bigint (*) ($WORD, B_atom))intsQ_W_bigint_neg_small_2->$class->__fromatom__)(intsQ_W_bigint_neg_small_2, ((B_atom)toB_bigint2("-1"))); intsQ_bigint_neg_small = bigint_neg_small; - B_bigint bigint_i64_max = ((B_bigint)toB_bigint(9223372036854775807UL)); + B_Number W_bigint_i64_max_2 = (B_Number)B_IntegralD_bigintG_witness; + intsQ_W_bigint_i64_max_2 = W_bigint_i64_max_2; + B_bigint bigint_i64_max = ((B_bigint (*) ($WORD, B_atom))intsQ_W_bigint_i64_max_2->$class->__fromatom__)(intsQ_W_bigint_i64_max_2, ((B_atom)toB_bigint(9223372036854775807UL))); intsQ_bigint_i64_max = bigint_i64_max; - B_bigint bigint_i64_min = ((B_bigint)toB_bigint2("-9223372036854775808")); + B_Number W_bigint_i64_min_2 = (B_Number)B_IntegralD_bigintG_witness; + intsQ_W_bigint_i64_min_2 = W_bigint_i64_min_2; + B_bigint bigint_i64_min = ((B_bigint (*) ($WORD, B_atom))intsQ_W_bigint_i64_min_2->$class->__fromatom__)(intsQ_W_bigint_i64_min_2, ((B_atom)toB_bigint2("-9223372036854775808"))); intsQ_bigint_i64_min = bigint_i64_min; B_bigint bigint_i64_underflow = ((B_bigint)toB_bigint2("-9223372036854775809")); intsQ_bigint_i64_underflow = bigint_i64_underflow; diff --git a/compiler/lib/test/9-codegen/ints.h b/compiler/lib/test/9-codegen/ints.h index 7a3c0f657..62ab3183e 100644 --- a/compiler/lib/test/9-codegen/ints.h +++ b/compiler/lib/test/9-codegen/ints.h @@ -2,41 +2,29 @@ #pragma once #include "builtin/builtin.h" #include "rts/rts.h" -extern int64_t intsQ_U_int64_min; -extern B_int intsQ_int64_min; -extern int64_t intsQ_U_1int64_max; -extern B_int intsQ_int64_max; -extern int32_t intsQ_U_2int32_min; -extern B_i32 intsQ_int32_min; -extern int32_t intsQ_U_3int32_max; -extern B_i32 intsQ_int32_max; -extern int16_t intsQ_U_4int16_min; -extern B_i16 intsQ_int16_min; -extern int16_t intsQ_U_5int16_max; -extern B_i16 intsQ_int16_max; -extern B_Number intsQ_W_int8_min_2; -extern B_i8 intsQ_int8_min; -extern B_Number intsQ_W_int8_max_2; -extern B_i8 intsQ_int8_max; -extern uint64_t intsQ_U_6uint64_min; -extern B_u64 intsQ_uint64_min; -extern uint64_t intsQ_U_7uint64_max; -extern B_u64 intsQ_uint64_max; -extern uint32_t intsQ_U_8uint32_min; -extern B_u32 intsQ_uint32_min; -extern uint32_t intsQ_U_9uint32_max; -extern B_u32 intsQ_uint32_max; -extern uint16_t intsQ_U_10uint16_min; -extern B_u16 intsQ_uint16_min; -extern uint16_t intsQ_U_11uint16_max; -extern B_u16 intsQ_uint16_max; -extern B_Number intsQ_W_uint8_min_2; -extern B_u8 intsQ_uint8_min; -extern B_Number intsQ_W_uint8_max_2; -extern B_u8 intsQ_uint8_max; +extern int64_t intsQ_int64_min; +extern int64_t intsQ_int64_max; +extern int32_t intsQ_int32_min; +extern int32_t intsQ_int32_max; +extern int16_t intsQ_int16_min; +extern int16_t intsQ_int16_max; +extern int8_t intsQ_int8_min; +extern int8_t intsQ_int8_max; +extern uint64_t intsQ_uint64_min; +extern uint64_t intsQ_uint64_max; +extern uint32_t intsQ_uint32_min; +extern uint32_t intsQ_uint32_max; +extern uint16_t intsQ_uint16_min; +extern uint16_t intsQ_uint16_max; +extern uint8_t intsQ_uint8_min; +extern uint8_t intsQ_uint8_max; +extern B_Number intsQ_W_bigint_small_2; extern B_bigint intsQ_bigint_small; +extern B_Number intsQ_W_bigint_neg_small_2; extern B_bigint intsQ_bigint_neg_small; +extern B_Number intsQ_W_bigint_i64_max_2; extern B_bigint intsQ_bigint_i64_max; +extern B_Number intsQ_W_bigint_i64_min_2; extern B_bigint intsQ_bigint_i64_min; extern B_bigint intsQ_bigint_i64_underflow; extern B_bigint intsQ_bigint_u64_edge; diff --git a/compiler/lib/test/9-codegen/ints.input b/compiler/lib/test/9-codegen/ints.input index 4004fd917..2746a1ac3 100644 --- a/compiler/lib/test/9-codegen/ints.input +++ b/compiler/lib/test/9-codegen/ints.input @@ -1,80 +1,56 @@ -U_int64_min: __builtin__.int = (UNBOX __builtin__.int -9223372036854775808) +int64_min: UNBOXED __builtin__.int = (UNBOX __builtin__.int -9223372036854775808) -int64_min: __builtin__.int = (BOX __builtin__.int U_int64_min) +int64_max: UNBOXED __builtin__.int = (UNBOX __builtin__.int 9223372036854775807) -U_1int64_max: __builtin__.int = (UNBOX __builtin__.int 9223372036854775807) +int32_min: UNBOXED __builtin__.i32 = (UNBOX __builtin__.i32 -2147483648) -int64_max: __builtin__.int = (BOX __builtin__.int U_1int64_max) +int32_max: UNBOXED __builtin__.i32 = (UNBOX __builtin__.i32 2147483647) -U_2int32_min: __builtin__.i32 = (UNBOX __builtin__.i32 -2147483648) +int16_min: UNBOXED __builtin__.i16 = (UNBOX __builtin__.i16 -32768) -int32_min: __builtin__.i32 = (BOX __builtin__.i32 U_2int32_min) +int16_max: UNBOXED __builtin__.i16 = (UNBOX __builtin__.i16 32767) -U_3int32_max: __builtin__.i32 = (UNBOX __builtin__.i32 2147483647) +int8_min: UNBOXED __builtin__.i8 = (UNBOX __builtin__.i8 -128) -int32_max: __builtin__.i32 = (BOX __builtin__.i32 U_3int32_max) +int8_max: UNBOXED __builtin__.i8 = (UNBOX __builtin__.i8 127) -U_4int16_min: __builtin__.i16 = (UNBOX __builtin__.i16 -32768) +uint64_min: UNBOXED __builtin__.u64 = (UNBOX __builtin__.u64 0) -int16_min: __builtin__.i16 = (BOX __builtin__.i16 U_4int16_min) +uint64_max: UNBOXED __builtin__.u64 = (UNBOX __builtin__.u64 18446744073709551615) -U_5int16_max: __builtin__.i16 = (UNBOX __builtin__.i16 32767) +uint32_min: UNBOXED __builtin__.u32 = (UNBOX __builtin__.u32 0) -int16_max: __builtin__.i16 = (BOX __builtin__.i16 U_5int16_max) +uint32_max: UNBOXED __builtin__.u32 = (UNBOX __builtin__.u32 4294967295) -W_int8_min_2: __builtin__.Number[__builtin__.i8] = __builtin__.IntegralD_i8() +uint16_min: UNBOXED __builtin__.u16 = (UNBOX __builtin__.u16 0) -int8_min: __builtin__.i8 = W_int8_min_2.__fromatom__(-128) +uint16_max: UNBOXED __builtin__.u16 = (UNBOX __builtin__.u16 65535) -W_int8_max_2: __builtin__.Number[__builtin__.i8] = __builtin__.IntegralD_i8() +uint8_min: UNBOXED __builtin__.u8 = (UNBOX __builtin__.u8 0) -int8_max: __builtin__.i8 = W_int8_max_2.__fromatom__(127) +uint8_max: UNBOXED __builtin__.u8 = (UNBOX __builtin__.u8 255) -U_6uint64_min: __builtin__.u64 = (UNBOX __builtin__.u64 0) +W_bigint_small_2: __builtin__.Number[__builtin__.bigint] = __builtin__.IntegralD_bigint() -uint64_min: __builtin__.u64 = (BOX __builtin__.u64 U_6uint64_min) +bigint_small: __builtin__.bigint = W_bigint_small_2.__fromatom__(42) -U_7uint64_max: __builtin__.u64 = (UNBOX __builtin__.u64 18446744073709551615) +W_bigint_neg_small_2: __builtin__.Number[__builtin__.bigint] = __builtin__.IntegralD_bigint() -uint64_max: __builtin__.u64 = (BOX __builtin__.u64 U_7uint64_max) +bigint_neg_small: __builtin__.bigint = W_bigint_neg_small_2.__fromatom__(-1) -U_8uint32_min: __builtin__.u32 = (UNBOX __builtin__.u32 0) +W_bigint_i64_max_2: __builtin__.Number[__builtin__.bigint] = __builtin__.IntegralD_bigint() -uint32_min: __builtin__.u32 = (BOX __builtin__.u32 U_8uint32_min) +bigint_i64_max: __builtin__.bigint = W_bigint_i64_max_2.__fromatom__(9223372036854775807) -U_9uint32_max: __builtin__.u32 = (UNBOX __builtin__.u32 4294967295) +W_bigint_i64_min_2: __builtin__.Number[__builtin__.bigint] = __builtin__.IntegralD_bigint() -uint32_max: __builtin__.u32 = (BOX __builtin__.u32 U_9uint32_max) - -U_10uint16_min: __builtin__.u16 = (UNBOX __builtin__.u16 0) - -uint16_min: __builtin__.u16 = (BOX __builtin__.u16 U_10uint16_min) - -U_11uint16_max: __builtin__.u16 = (UNBOX __builtin__.u16 65535) - -uint16_max: __builtin__.u16 = (BOX __builtin__.u16 U_11uint16_max) - -W_uint8_min_2: __builtin__.Number[__builtin__.u8] = __builtin__.IntegralD_u8() - -uint8_min: __builtin__.u8 = W_uint8_min_2.__fromatom__(0) - -W_uint8_max_2: __builtin__.Number[__builtin__.u8] = __builtin__.IntegralD_u8() - -uint8_max: __builtin__.u8 = W_uint8_max_2.__fromatom__(255) - -bigint_small: __builtin__.bigint = 42 - -bigint_neg_small: __builtin__.bigint = -1 - -bigint_i64_max: __builtin__.bigint = 9223372036854775807 - -bigint_i64_min: __builtin__.bigint = -9223372036854775808 +bigint_i64_min: __builtin__.bigint = W_bigint_i64_min_2.__fromatom__(-9223372036854775808) bigint_i64_underflow: __builtin__.bigint = -9223372036854775809 -bigint_u64_edge: __builtin__.bigint = bigint(18446744073709551615, None) +bigint_u64_edge: __builtin__.bigint = bigint((BOX __builtin__.u64 18446744073709551615), None) -bigint_u64_edge_minus1: __builtin__.bigint = bigint(18446744073709551614, None) +bigint_u64_edge_minus1: __builtin__.bigint = bigint((BOX __builtin__.u64 18446744073709551614), None) bigint_u64_overflow: __builtin__.bigint = 18446744073709551616 diff --git a/compiler/lib/test/9-codegen/lines.c b/compiler/lib/test/9-codegen/lines.c index bf2996bd5..a59dfb51a 100644 --- a/compiler/lib/test/9-codegen/lines.c +++ b/compiler/lib/test/9-codegen/lines.c @@ -8,19 +8,19 @@ B_Eq linesQ_W_Apa_331; B_Eq linesQ_W_Apa_785; $R linesQ_L_1C_1cont (linesQ_Apa self, $Cont C_cont, B_NoneType C_2res) { #line 18 "test/src/lines.act" - self->z = toB_int(1LL); + ((linesQ_Apa)(self))->z = 1LL; #line 19 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("Apa")), B_None, B_None, B_None, B_None); return $R_CONT(C_cont, B_None); } B_NoneType linesQ_L_2ContD___init__ (linesQ_L_2Cont L_self, linesQ_Apa self, $Cont C_cont) { - L_self->self = self; - L_self->C_cont = C_cont; + ((linesQ_L_2Cont)(L_self))->self = self; + ((linesQ_L_2Cont)(L_self))->C_cont = C_cont; return B_None; } $R linesQ_L_2ContD___call__ (linesQ_L_2Cont L_self, B_NoneType G_1) { - linesQ_Apa self = L_self->self; - $Cont C_cont = L_self->C_cont; + linesQ_Apa self = ((linesQ_L_2Cont)(L_self))->self; + $Cont C_cont = ((linesQ_L_2Cont)(L_self))->C_cont; return linesQ_L_1C_1cont(self, C_cont, G_1); } void linesQ_L_2ContD___serialize__ (linesQ_L_2Cont self, $Serial$state state) { @@ -28,6 +28,7 @@ void linesQ_L_2ContD___serialize__ (linesQ_L_2Cont self, $Serial$state state) { $step_serialize(self->C_cont, state); } linesQ_L_2Cont linesQ_L_2ContD___deserialize__ (linesQ_L_2Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_2Cont)); @@ -48,23 +49,24 @@ linesQ_L_2Cont linesQ_L_2ContG_new(linesQ_Apa G_1, $Cont G_2) { } struct linesQ_L_2ContG_class linesQ_L_2ContG_methods; B_NoneType linesQ_L_4actionD___init__ (linesQ_L_4action L_self, linesQ_Apa L_3obj) { - L_self->L_3obj = L_3obj; + ((linesQ_L_4action)(L_self))->L_3obj = L_3obj; return B_None; } $R linesQ_L_4actionD___call__ (linesQ_L_4action L_self, $Cont L_cont, B_int G_1) { - return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) (linesQ_L_4action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } $R linesQ_L_4actionD___exec__ (linesQ_L_4action L_self, $Cont L_cont, B_int G_1) { - return $R_CONT(L_cont, ((B_value)((B_Msg (*) (linesQ_L_4action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $R_CONT(L_cont, ((B_value)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } B_Msg linesQ_L_4actionD___asyn__ (linesQ_L_4action L_self, B_int G_1) { - linesQ_Apa L_3obj = L_self->L_3obj; - return ((B_Msg)((B_Msg (*) (linesQ_Apa, B_int))L_3obj->$class->notice)(L_3obj, G_1)); + linesQ_Apa L_3obj = ((linesQ_L_4action)(L_self))->L_3obj; + return ((B_Msg)((B_Msg (*) ($WORD, int64_t))L_3obj->$class->notice)(L_3obj, ((B_int)G_1)->val)); } void linesQ_L_4actionD___serialize__ (linesQ_L_4action self, $Serial$state state) { $step_serialize(self->L_3obj, state); } linesQ_L_4action linesQ_L_4actionD___deserialize__ (linesQ_L_4action self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_4action)); @@ -83,32 +85,30 @@ linesQ_L_4action linesQ_L_4actionG_new(linesQ_Apa G_1) { return $tmp; } struct linesQ_L_4actionG_class linesQ_L_4actionG_methods; -$R linesQ_U_L_5C_3cont ($action cb, $Cont C_cont, int64_t U_2C_4res) { +$R linesQ_L_5C_3cont ($action cb, $Cont C_cont, int64_t C_4res) { #line 9 "test/src/lines.act" - int64_t U_3v = U_2C_4res; + int64_t v = C_4res; #line 10 "test/src/lines.act" - B_Msg m = ((B_Msg)((B_Msg (*) ($action, B_int))cb->$class->__asyn__)(cb, toB_int(2LL))); - int64_t U_4N_tmp = (U_3v * 10LL); - return $R_CONT(C_cont, toB_int(U_4N_tmp)); -} -$R linesQ_L_5C_3cont ($action cb, $Cont C_cont, B_int C_4res) { - return linesQ_U_L_5C_3cont(cb, C_cont, ((B_int)C_4res)->val); + B_Msg m = ((B_Msg)((B_Msg (*) ($WORD, B_int))cb->$class->__asyn__)(cb, toB_int(2LL))); + int64_t N_tmp = (((int64_t)(v * 10LL))); + return $R_CONT(C_cont, toB_int(N_tmp)); } B_NoneType linesQ_L_6ContD___init__ (linesQ_L_6Cont L_self, $action cb, $Cont C_cont) { - L_self->cb = cb; - L_self->C_cont = C_cont; + ((linesQ_L_6Cont)(L_self))->cb = cb; + ((linesQ_L_6Cont)(L_self))->C_cont = C_cont; return B_None; } $R linesQ_L_6ContD___call__ (linesQ_L_6Cont L_self, B_int G_1) { - $action cb = L_self->cb; - $Cont C_cont = L_self->C_cont; - return linesQ_L_5C_3cont(cb, C_cont, G_1); + $action cb = ((linesQ_L_6Cont)(L_self))->cb; + $Cont C_cont = ((linesQ_L_6Cont)(L_self))->C_cont; + return linesQ_L_5C_3cont(cb, C_cont, ((B_int)G_1)->val); } void linesQ_L_6ContD___serialize__ (linesQ_L_6Cont self, $Serial$state state) { $step_serialize(self->cb, state); $step_serialize(self->C_cont, state); } linesQ_L_6Cont linesQ_L_6ContD___deserialize__ (linesQ_L_6Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_6Cont)); @@ -129,23 +129,24 @@ linesQ_L_6Cont linesQ_L_6ContG_new($action G_1, $Cont G_2) { } struct linesQ_L_6ContG_class linesQ_L_6ContG_methods; B_NoneType linesQ_L_7procD___init__ (linesQ_L_7proc L_self, linesQ_Apa self, $action cb) { - L_self->self = self; - L_self->cb = cb; + ((linesQ_L_7proc)(L_self))->self = self; + ((linesQ_L_7proc)(L_self))->cb = cb; return B_None; } $R linesQ_L_7procD___call__ (linesQ_L_7proc L_self, $Cont C_cont) { - linesQ_Apa self = L_self->self; - $action cb = L_self->cb; - return (($R (*) (linesQ_Apa, $Cont, $action))self->$class->setupG_local)(self, C_cont, cb); + linesQ_Apa self = ((linesQ_L_7proc)(L_self))->self; + $action cb = ((linesQ_L_7proc)(L_self))->cb; + return (($R (*) ($WORD, $Cont, $action))self->$class->setupG_local)(self, C_cont, cb); } $R linesQ_L_7procD___exec__ (linesQ_L_7proc L_self, $Cont C_cont) { - return (($R (*) (linesQ_L_7proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void linesQ_L_7procD___serialize__ (linesQ_L_7proc self, $Serial$state state) { $step_serialize(self->self, state); $step_serialize(self->cb, state); } linesQ_L_7proc linesQ_L_7procD___deserialize__ (linesQ_L_7proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_7proc)); @@ -166,23 +167,24 @@ linesQ_L_7proc linesQ_L_7procG_new(linesQ_Apa G_1, $action G_2) { } struct linesQ_L_7procG_class linesQ_L_7procG_methods; B_NoneType linesQ_L_8procD___init__ (linesQ_L_8proc L_self, linesQ_Apa self, $action cb) { - L_self->self = self; - L_self->cb = cb; + ((linesQ_L_8proc)(L_self))->self = self; + ((linesQ_L_8proc)(L_self))->cb = cb; return B_None; } $R linesQ_L_8procD___call__ (linesQ_L_8proc L_self, $Cont C_cont) { - linesQ_Apa self = L_self->self; - $action cb = L_self->cb; - return (($R (*) (linesQ_Apa, $Cont, $action))self->$class->computeG_local)(self, C_cont, cb); + linesQ_Apa self = ((linesQ_L_8proc)(L_self))->self; + $action cb = ((linesQ_L_8proc)(L_self))->cb; + return (($R (*) ($WORD, $Cont, $action))self->$class->computeG_local)(self, C_cont, cb); } $R linesQ_L_8procD___exec__ (linesQ_L_8proc L_self, $Cont C_cont) { - return (($R (*) (linesQ_L_8proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void linesQ_L_8procD___serialize__ (linesQ_L_8proc self, $Serial$state state) { $step_serialize(self->self, state); $step_serialize(self->cb, state); } linesQ_L_8proc linesQ_L_8procD___deserialize__ (linesQ_L_8proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_8proc)); @@ -202,24 +204,25 @@ linesQ_L_8proc linesQ_L_8procG_new(linesQ_Apa G_1, $action G_2) { return $tmp; } struct linesQ_L_8procG_class linesQ_L_8procG_methods; -B_NoneType linesQ_L_9procD___init__ (linesQ_L_9proc L_self, linesQ_Apa self, B_int i) { - L_self->self = self; - L_self->i = i; +B_NoneType linesQ_L_9procD___init__ (linesQ_L_9proc L_self, linesQ_Apa self, int64_t i) { + ((linesQ_L_9proc)(L_self))->self = self; + ((linesQ_L_9proc)(L_self))->i = i; return B_None; } $R linesQ_L_9procD___call__ (linesQ_L_9proc L_self, $Cont C_cont) { - linesQ_Apa self = L_self->self; - int64_t U_5i = ((B_int)L_self->i)->val; - return (($R (*) (linesQ_Apa, $Cont, B_int))self->$class->noticeG_local)(self, C_cont, toB_int(U_5i)); + linesQ_Apa self = ((linesQ_L_9proc)(L_self))->self; + int64_t i = ((int64_t)((linesQ_L_9proc)(L_self))->i); + return (($R (*) ($WORD, $Cont, int64_t))self->$class->noticeG_local)(self, C_cont, i); } $R linesQ_L_9procD___exec__ (linesQ_L_9proc L_self, $Cont C_cont) { - return (($R (*) (linesQ_L_9proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void linesQ_L_9procD___serialize__ (linesQ_L_9proc self, $Serial$state state) { $step_serialize(self->self, state); - $step_serialize(self->i, state); + $val_serialize(I64_ID, &self->i, state); } linesQ_L_9proc linesQ_L_9procD___deserialize__ (linesQ_L_9proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_9proc)); @@ -229,34 +232,36 @@ linesQ_L_9proc linesQ_L_9procD___deserialize__ (linesQ_L_9proc self, $Serial$sta self = $DNEW(linesQ_L_9proc, state); } self->self = $step_deserialize(state); - self->i = $step_deserialize(state); + $tmp = $val_deserialize(state); + memcpy(&self->i, &$tmp, sizeof(self->i)); return self; } -linesQ_L_9proc linesQ_L_9procG_new(linesQ_Apa G_1, B_int G_2) { +linesQ_L_9proc linesQ_L_9procG_new(linesQ_Apa G_1, int64_t G_2) { linesQ_L_9proc $tmp = acton_malloc(sizeof(struct linesQ_L_9proc)); $tmp->$class = &linesQ_L_9procG_methods; linesQ_L_9procG_methods.__init__($tmp, G_1, G_2); return $tmp; } struct linesQ_L_9procG_class linesQ_L_9procG_methods; -B_NoneType linesQ_L_10procD___init__ (linesQ_L_10proc L_self, linesQ_Bepa self, B_int i) { - L_self->self = self; - L_self->i = i; +B_NoneType linesQ_L_10procD___init__ (linesQ_L_10proc L_self, linesQ_Bepa self, int64_t i) { + ((linesQ_L_10proc)(L_self))->self = self; + ((linesQ_L_10proc)(L_self))->i = i; return B_None; } $R linesQ_L_10procD___call__ (linesQ_L_10proc L_self, $Cont C_cont) { - linesQ_Bepa self = L_self->self; - int64_t U_6i = ((B_int)L_self->i)->val; - return (($R (*) (linesQ_Bepa, $Cont, B_int))self->$class->callbackG_local)(self, C_cont, toB_int(U_6i)); + linesQ_Bepa self = ((linesQ_L_10proc)(L_self))->self; + int64_t i = ((int64_t)((linesQ_L_10proc)(L_self))->i); + return (($R (*) ($WORD, $Cont, int64_t))self->$class->callbackG_local)(self, C_cont, i); } $R linesQ_L_10procD___exec__ (linesQ_L_10proc L_self, $Cont C_cont) { - return (($R (*) (linesQ_L_10proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void linesQ_L_10procD___serialize__ (linesQ_L_10proc self, $Serial$state state) { $step_serialize(self->self, state); - $step_serialize(self->i, state); + $val_serialize(I64_ID, &self->i, state); } linesQ_L_10proc linesQ_L_10procD___deserialize__ (linesQ_L_10proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_10proc)); @@ -266,10 +271,11 @@ linesQ_L_10proc linesQ_L_10procD___deserialize__ (linesQ_L_10proc self, $Serial$ self = $DNEW(linesQ_L_10proc, state); } self->self = $step_deserialize(state); - self->i = $step_deserialize(state); + $tmp = $val_deserialize(state); + memcpy(&self->i, &$tmp, sizeof(self->i)); return self; } -linesQ_L_10proc linesQ_L_10procG_new(linesQ_Bepa G_1, B_int G_2) { +linesQ_L_10proc linesQ_L_10procG_new(linesQ_Bepa G_1, int64_t G_2) { linesQ_L_10proc $tmp = acton_malloc(sizeof(struct linesQ_L_10proc)); $tmp->$class = &linesQ_L_10procG_methods; linesQ_L_10procG_methods.__init__($tmp, G_1, G_2); @@ -277,23 +283,24 @@ linesQ_L_10proc linesQ_L_10procG_new(linesQ_Bepa G_1, B_int G_2) { } struct linesQ_L_10procG_class linesQ_L_10procG_methods; B_NoneType linesQ_L_14actionD___init__ (linesQ_L_14action L_self, linesQ_Apa L_13obj) { - L_self->L_13obj = L_13obj; + ((linesQ_L_14action)(L_self))->L_13obj = L_13obj; return B_None; } $R linesQ_L_14actionD___call__ (linesQ_L_14action L_self, $Cont L_cont, B_int G_1) { - return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) (linesQ_L_14action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } $R linesQ_L_14actionD___exec__ (linesQ_L_14action L_self, $Cont L_cont, B_int G_1) { - return $R_CONT(L_cont, ((B_value)((B_Msg (*) (linesQ_L_14action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $R_CONT(L_cont, ((B_value)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } B_Msg linesQ_L_14actionD___asyn__ (linesQ_L_14action L_self, B_int G_1) { - linesQ_Apa L_13obj = L_self->L_13obj; - return ((B_Msg)((B_Msg (*) (linesQ_Apa, B_int))L_13obj->$class->notice)(L_13obj, G_1)); + linesQ_Apa L_13obj = ((linesQ_L_14action)(L_self))->L_13obj; + return ((B_Msg)((B_Msg (*) ($WORD, int64_t))L_13obj->$class->notice)(L_13obj, ((B_int)G_1)->val)); } void linesQ_L_14actionD___serialize__ (linesQ_L_14action self, $Serial$state state) { $step_serialize(self->L_13obj, state); } linesQ_L_14action linesQ_L_14actionD___deserialize__ (linesQ_L_14action self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_14action)); @@ -313,23 +320,24 @@ linesQ_L_14action linesQ_L_14actionG_new(linesQ_Apa G_1) { } struct linesQ_L_14actionG_class linesQ_L_14actionG_methods; B_NoneType linesQ_L_16actionD___init__ (linesQ_L_16action L_self, linesQ_Bepa L_15obj) { - L_self->L_15obj = L_15obj; + ((linesQ_L_16action)(L_self))->L_15obj = L_15obj; return B_None; } $R linesQ_L_16actionD___call__ (linesQ_L_16action L_self, $Cont L_cont, B_int G_1) { - return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) (linesQ_L_16action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } $R linesQ_L_16actionD___exec__ (linesQ_L_16action L_self, $Cont L_cont, B_int G_1) { - return $R_CONT(L_cont, ((B_value)((B_Msg (*) (linesQ_L_16action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $R_CONT(L_cont, ((B_value)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } B_Msg linesQ_L_16actionD___asyn__ (linesQ_L_16action L_self, B_int G_1) { - linesQ_Bepa L_15obj = L_self->L_15obj; - return ((B_Msg)((B_Msg (*) (linesQ_Bepa, B_int))L_15obj->$class->callback)(L_15obj, G_1)); + linesQ_Bepa L_15obj = ((linesQ_L_16action)(L_self))->L_15obj; + return ((B_Msg)((B_Msg (*) ($WORD, int64_t))L_15obj->$class->callback)(L_15obj, ((B_int)G_1)->val)); } void linesQ_L_16actionD___serialize__ (linesQ_L_16action self, $Serial$state state) { $step_serialize(self->L_15obj, state); } linesQ_L_16action linesQ_L_16actionD___deserialize__ (linesQ_L_16action self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_16action)); @@ -349,23 +357,24 @@ linesQ_L_16action linesQ_L_16actionG_new(linesQ_Bepa G_1) { } struct linesQ_L_16actionG_class linesQ_L_16actionG_methods; B_NoneType linesQ_L_19actionD___init__ (linesQ_L_19action L_self, linesQ_main L_18obj) { - L_self->L_18obj = L_18obj; + ((linesQ_L_19action)(L_self))->L_18obj = L_18obj; return B_None; } $R linesQ_L_19actionD___call__ (linesQ_L_19action L_self, $Cont L_cont, B_int G_1) { - return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) (linesQ_L_19action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $AWAIT(L_cont, ((B_Msg)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } $R linesQ_L_19actionD___exec__ (linesQ_L_19action L_self, $Cont L_cont, B_int G_1) { - return $R_CONT(L_cont, ((B_value)((B_Msg (*) (linesQ_L_19action, B_int))L_self->$class->__asyn__)(L_self, G_1))); + return $R_CONT(L_cont, ((B_value)((B_Msg (*) ($WORD, B_int))L_self->$class->__asyn__)(L_self, G_1))); } B_Msg linesQ_L_19actionD___asyn__ (linesQ_L_19action L_self, B_int G_1) { - linesQ_main L_18obj = L_self->L_18obj; - return ((B_Msg)((B_Msg (*) (linesQ_main, B_int))L_18obj->$class->myproc)(L_18obj, G_1)); + linesQ_main L_18obj = ((linesQ_L_19action)(L_self))->L_18obj; + return ((B_Msg)((B_Msg (*) ($WORD, int64_t))L_18obj->$class->myproc)(L_18obj, ((B_int)G_1)->val)); } void linesQ_L_19actionD___serialize__ (linesQ_L_19action self, $Serial$state state) { $step_serialize(self->L_18obj, state); } linesQ_L_19action linesQ_L_19actionD___deserialize__ (linesQ_L_19action self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_19action)); @@ -385,20 +394,21 @@ linesQ_L_19action linesQ_L_19actionG_new(linesQ_main G_1) { } struct linesQ_L_19actionG_class linesQ_L_19actionG_methods; B_NoneType linesQ_L_20procD___init__ (linesQ_L_20proc L_self, linesQ_main self) { - L_self->self = self; + ((linesQ_L_20proc)(L_self))->self = self; return B_None; } $R linesQ_L_20procD___call__ (linesQ_L_20proc L_self, $Cont C_cont) { - linesQ_main self = L_self->self; - return (($R (*) (linesQ_main, $Cont, B_int))self->$class->myprocG_local)(self, C_cont, toB_int(0LL)); + linesQ_main self = ((linesQ_L_20proc)(L_self))->self; + return (($R (*) ($WORD, $Cont, int64_t))self->$class->myprocG_local)(self, C_cont, 0LL); } $R linesQ_L_20procD___exec__ (linesQ_L_20proc L_self, $Cont C_cont) { - return (($R (*) (linesQ_L_20proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void linesQ_L_20procD___serialize__ (linesQ_L_20proc self, $Serial$state state) { $step_serialize(self->self, state); } linesQ_L_20proc linesQ_L_20procD___deserialize__ (linesQ_L_20proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_20proc)); @@ -417,27 +427,27 @@ linesQ_L_20proc linesQ_L_20procG_new(linesQ_main G_1) { return $tmp; } struct linesQ_L_20procG_class linesQ_L_20procG_methods; -$R linesQ_U_1L_17C_9cont (linesQ_main self, $Cont C_cont, int64_t U_7C_10res) { +$R linesQ_L_17C_9cont (linesQ_main self, $Cont C_cont, int64_t C_10res) { #line 38 "test/src/lines.act" - self->r = toB_int(U_7C_10res); + ((linesQ_main)(self))->r = C_10res; #line 39 "test/src/lines.act" - ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("r ="), self->r), B_None, B_None, B_None, B_None); + ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("r ="), toB_int(((int64_t)((linesQ_main)(self))->r))), B_None, B_None, B_None, B_None); #line 40 "test/src/lines.act" - ((B_Msg (*) (linesQ_Apa, $action))self->a->$class->compute)(self->a, (($action)linesQ_L_19actionG_new(self))); + ((B_Msg (*) ($WORD, $action))((linesQ_main)(self))->a->$class->compute)(((linesQ_main)(self))->a, (($action)linesQ_L_19actionG_new(self))); #line 41 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("main")), B_None, B_None, B_None, B_None); #line 44 "test/src/lines.act" - self->v = toB_int(0LL); + ((linesQ_main)(self))->v = 0LL; #line 45 "test/src/lines.act" - if ((((B_int)self->v)->val == 0LL)) { + if (((int64_t)((linesQ_main)(self))->v) == 0LL) { #line 46 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("if branch")), B_None, B_None, B_None, B_None); #line 47 "test/src/lines.act" - if ((((B_int)self->v)->val < 1LL)) { + if (((int64_t)((linesQ_main)(self))->v) < 1LL) { #line 48 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("nested if")), B_None, B_None, B_None, B_None); } - else if ((((B_int)self->v)->val == -1LL)) { + else if (((int64_t)((linesQ_main)(self))->v) == -1LL) { #line 50 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("nested elif")), B_None, B_None, B_None, B_None); } @@ -446,7 +456,7 @@ struct linesQ_L_20procG_class linesQ_L_20procG_methods; ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("nested else")), B_None, B_None, B_None, B_None); } } - else if ((((B_int)self->v)->val == 1LL)) { + else if (((int64_t)((linesQ_main)(self))->v) == 1LL) { #line 54 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("outer elif")), B_None, B_None, B_None, B_None); } @@ -455,10 +465,10 @@ struct linesQ_L_20procG_class linesQ_L_20procG_methods; ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("outer else")), B_None, B_None, B_None, B_None); } #line 59 "test/src/lines.act" - self->i = toB_int(0LL); + ((linesQ_main)(self))->i = 0LL; #line 60 "test/src/lines.act" while (true) { - if ((((B_int)self->i)->val < 3LL)) { + if (((int64_t)((linesQ_main)(self))->i) < 3LL) { } else { #line 70 "test/src/lines.act" @@ -466,31 +476,31 @@ struct linesQ_L_20procG_class linesQ_L_20procG_methods; break; } #line 61 "test/src/lines.act" - self->i = toB_int((((B_int)self->i)->val + 1LL)); + ((linesQ_main)(self))->i = (((int64_t)(((int64_t)((linesQ_main)(self))->i) + 1LL))); #line 62 "test/src/lines.act" - if ((((B_int)self->i)->val == 1LL)) { + if (((int64_t)((linesQ_main)(self))->i) == 1LL) { #line 63 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("continue path")), B_None, B_None, B_None, B_None); #line 64 "test/src/lines.act" continue; } #line 65 "test/src/lines.act" - if ((((B_int)self->i)->val == 2LL)) { + if (((int64_t)((linesQ_main)(self))->i) == 2LL) { #line 66 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("break path")), B_None, B_None, B_None, B_None); #line 67 "test/src/lines.act" break; } #line 68 "test/src/lines.act" - ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("loop body"), self->i), B_None, B_None, B_None, B_None); + ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("loop body"), toB_int(((int64_t)((linesQ_main)(self))->i))), B_None, B_None, B_None, B_None); } - B_Iterator N_3iter = ((B_Iterator (*) (B_Iterable, B_list))linesQ_W_Apa_779->$class->__iter__)(linesQ_W_Apa_779, B_mk_list(3, toB_int(1LL) , toB_int(2LL) , toB_int(3LL))); + B_Iterator N_3iter = ((B_Iterator (*) ($WORD, B_list))linesQ_W_Apa_779->$class->__iter__)(linesQ_W_Apa_779, B_mk_list(3, toB_int(1LL) , toB_int(2LL) , toB_int(3LL))); if ($PUSH()) { #line 73 "test/src/lines.act" while (true) { - B_int j = ((B_int (*) (B_Iterator))N_3iter->$class->__next__)(N_3iter); + B_int j = ((B_int (*) ($WORD))N_3iter->$class->__next__)(N_3iter); #line 74 "test/src/lines.act" - if (((B_bool)((B_bool (*) (B_Eq, B_int, B_int))linesQ_W_Apa_759->$class->__eq__)(linesQ_W_Apa_759, j, toB_int(2LL)))->val) { + if (((B_bool)((B_bool (*) ($WORD, B_int, B_int))linesQ_W_Apa_759->$class->__eq__)(linesQ_W_Apa_759, j, toB_int(2LL)))->val) { #line 75 "test/src/lines.act" continue; } @@ -505,15 +515,17 @@ struct linesQ_L_20procG_class linesQ_L_20procG_methods; } else { $RAISE(N_5x); + __builtin_unreachable(); } } B_BaseException N_7xx; if ($PUSHF()) { if ($PUSH()) { #line 80 "test/src/lines.act" - if (((B_bool)((B_bool (*) (B_Eq, B_int, B_int))linesQ_W_Apa_785->$class->__eq__)(linesQ_W_Apa_785, self->v, toB_int(0LL)))->val) { + if (((B_bool)((B_bool (*) ($WORD, B_int, B_int))linesQ_W_Apa_785->$class->__eq__)(linesQ_W_Apa_785, toB_int(((int64_t)((linesQ_main)(self))->v)), toB_int(0LL)))->val) { #line 81 "test/src/lines.act" $RAISE(((B_BaseException)B_ValueErrorG_new(to$str("boom")))); + __builtin_unreachable(); } #line 82 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("unreached")), B_None, B_None, B_None, B_None); @@ -529,9 +541,11 @@ struct linesQ_L_20procG_class linesQ_L_20procG_methods; } else { $RAISE(N_6x); + __builtin_unreachable(); } } $RAISE(((B_BaseException)$SEQG_new())); + __builtin_unreachable(); } else { N_7xx = $POP(); @@ -541,30 +555,29 @@ struct linesQ_L_20procG_class linesQ_L_20procG_methods; } else { $RAISE(N_7xx); + __builtin_unreachable(); } } #line 89 "test/src/lines.act" $AFTER(toB_float(1), (($Cont)linesQ_L_20procG_new(self))); - return (($R (*) (linesQ_main, $Cont))self->$class->nopG_local)(self, C_cont); -} -$R linesQ_L_17C_9cont (linesQ_main self, $Cont C_cont, B_int C_10res) { - return linesQ_U_1L_17C_9cont(self, C_cont, ((B_int)C_10res)->val); + return (($R (*) ($WORD, $Cont))self->$class->nopG_local)(self, C_cont); } B_NoneType linesQ_L_21ContD___init__ (linesQ_L_21Cont L_self, linesQ_main self, $Cont C_cont) { - L_self->self = self; - L_self->C_cont = C_cont; + ((linesQ_L_21Cont)(L_self))->self = self; + ((linesQ_L_21Cont)(L_self))->C_cont = C_cont; return B_None; } $R linesQ_L_21ContD___call__ (linesQ_L_21Cont L_self, B_int G_1) { - linesQ_main self = L_self->self; - $Cont C_cont = L_self->C_cont; - return linesQ_L_17C_9cont(self, C_cont, G_1); + linesQ_main self = ((linesQ_L_21Cont)(L_self))->self; + $Cont C_cont = ((linesQ_L_21Cont)(L_self))->C_cont; + return linesQ_L_17C_9cont(self, C_cont, ((B_int)G_1)->val); } void linesQ_L_21ContD___serialize__ (linesQ_L_21Cont self, $Serial$state state) { $step_serialize(self->self, state); $step_serialize(self->C_cont, state); } linesQ_L_21Cont linesQ_L_21ContD___deserialize__ (linesQ_L_21Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_21Cont)); @@ -586,23 +599,23 @@ linesQ_L_21Cont linesQ_L_21ContG_new(linesQ_main G_1, $Cont G_2) { struct linesQ_L_21ContG_class linesQ_L_21ContG_methods; $R linesQ_L_12C_7cont (linesQ_main self, $Cont C_cont, linesQ_Bepa C_8res) { #line 34 "test/src/lines.act" - self->b = C_8res; + ((linesQ_main)(self))->b = C_8res; #line 35 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("-----")), B_None, B_None, B_None, B_None); #line 36 "test/src/lines.act" - ((B_Msg (*) (linesQ_Apa, $action))self->a->$class->setup)(self->a, (($action)linesQ_L_14actionG_new(self->a))); + ((B_Msg (*) ($WORD, $action))((linesQ_main)(self))->a->$class->setup)(((linesQ_main)(self))->a, (($action)linesQ_L_14actionG_new(((linesQ_main)(self))->a))); #line 37 "test/src/lines.act" - self->x = ((B_Msg (*) (linesQ_Apa, $action))self->a->$class->compute)(self->a, (($action)linesQ_L_16actionG_new(self->b))); - return $AWAIT((($Cont)linesQ_L_21ContG_new(self, C_cont)), self->x); + ((linesQ_main)(self))->x = ((B_Msg (*) ($WORD, $action))((linesQ_main)(self))->a->$class->compute)(((linesQ_main)(self))->a, (($action)linesQ_L_16actionG_new(((linesQ_main)(self))->b))); + return $AWAIT((($Cont)linesQ_L_21ContG_new(self, C_cont)), ((linesQ_main)(self))->x); } B_NoneType linesQ_L_22ContD___init__ (linesQ_L_22Cont L_self, linesQ_main self, $Cont C_cont) { - L_self->self = self; - L_self->C_cont = C_cont; + ((linesQ_L_22Cont)(L_self))->self = self; + ((linesQ_L_22Cont)(L_self))->C_cont = C_cont; return B_None; } $R linesQ_L_22ContD___call__ (linesQ_L_22Cont L_self, linesQ_Bepa G_1) { - linesQ_main self = L_self->self; - $Cont C_cont = L_self->C_cont; + linesQ_main self = ((linesQ_L_22Cont)(L_self))->self; + $Cont C_cont = ((linesQ_L_22Cont)(L_self))->C_cont; return linesQ_L_12C_7cont(self, C_cont, G_1); } void linesQ_L_22ContD___serialize__ (linesQ_L_22Cont self, $Serial$state state) { @@ -610,6 +623,7 @@ void linesQ_L_22ContD___serialize__ (linesQ_L_22Cont self, $Serial$state state) $step_serialize(self->C_cont, state); } linesQ_L_22Cont linesQ_L_22ContD___deserialize__ (linesQ_L_22Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_22Cont)); @@ -631,17 +645,17 @@ linesQ_L_22Cont linesQ_L_22ContG_new(linesQ_main G_1, $Cont G_2) { struct linesQ_L_22ContG_class linesQ_L_22ContG_methods; $R linesQ_L_11C_5cont (linesQ_main self, $Cont C_cont, linesQ_Apa C_6res) { #line 33 "test/src/lines.act" - self->a = C_6res; + ((linesQ_main)(self))->a = C_6res; return linesQ_BepaG_newact((($Cont)linesQ_L_22ContG_new(self, C_cont))); } B_NoneType linesQ_L_23ContD___init__ (linesQ_L_23Cont L_self, linesQ_main self, $Cont C_cont) { - L_self->self = self; - L_self->C_cont = C_cont; + ((linesQ_L_23Cont)(L_self))->self = self; + ((linesQ_L_23Cont)(L_self))->C_cont = C_cont; return B_None; } $R linesQ_L_23ContD___call__ (linesQ_L_23Cont L_self, linesQ_Apa G_1) { - linesQ_main self = L_self->self; - $Cont C_cont = L_self->C_cont; + linesQ_main self = ((linesQ_L_23Cont)(L_self))->self; + $Cont C_cont = ((linesQ_L_23Cont)(L_self))->C_cont; return linesQ_L_11C_5cont(self, C_cont, G_1); } void linesQ_L_23ContD___serialize__ (linesQ_L_23Cont self, $Serial$state state) { @@ -649,6 +663,7 @@ void linesQ_L_23ContD___serialize__ (linesQ_L_23Cont self, $Serial$state state) $step_serialize(self->C_cont, state); } linesQ_L_23Cont linesQ_L_23ContD___deserialize__ (linesQ_L_23Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_23Cont)); @@ -668,24 +683,25 @@ linesQ_L_23Cont linesQ_L_23ContG_new(linesQ_main G_1, $Cont G_2) { return $tmp; } struct linesQ_L_23ContG_class linesQ_L_23ContG_methods; -B_NoneType linesQ_L_24procD___init__ (linesQ_L_24proc L_self, linesQ_main self, B_int i) { - L_self->self = self; - L_self->i = i; +B_NoneType linesQ_L_24procD___init__ (linesQ_L_24proc L_self, linesQ_main self, int64_t i) { + ((linesQ_L_24proc)(L_self))->self = self; + ((linesQ_L_24proc)(L_self))->i = i; return B_None; } $R linesQ_L_24procD___call__ (linesQ_L_24proc L_self, $Cont C_cont) { - linesQ_main self = L_self->self; - int64_t U_8i = ((B_int)L_self->i)->val; - return (($R (*) (linesQ_main, $Cont, B_int))self->$class->myprocG_local)(self, C_cont, toB_int(U_8i)); + linesQ_main self = ((linesQ_L_24proc)(L_self))->self; + int64_t i = ((int64_t)((linesQ_L_24proc)(L_self))->i); + return (($R (*) ($WORD, $Cont, int64_t))self->$class->myprocG_local)(self, C_cont, i); } $R linesQ_L_24procD___exec__ (linesQ_L_24proc L_self, $Cont C_cont) { - return (($R (*) (linesQ_L_24proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void linesQ_L_24procD___serialize__ (linesQ_L_24proc self, $Serial$state state) { $step_serialize(self->self, state); - $step_serialize(self->i, state); + $val_serialize(I64_ID, &self->i, state); } linesQ_L_24proc linesQ_L_24procD___deserialize__ (linesQ_L_24proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_24proc)); @@ -695,10 +711,11 @@ linesQ_L_24proc linesQ_L_24procD___deserialize__ (linesQ_L_24proc self, $Serial$ self = $DNEW(linesQ_L_24proc, state); } self->self = $step_deserialize(state); - self->i = $step_deserialize(state); + $tmp = $val_deserialize(state); + memcpy(&self->i, &$tmp, sizeof(self->i)); return self; } -linesQ_L_24proc linesQ_L_24procG_new(linesQ_main G_1, B_int G_2) { +linesQ_L_24proc linesQ_L_24procG_new(linesQ_main G_1, int64_t G_2) { linesQ_L_24proc $tmp = acton_malloc(sizeof(struct linesQ_L_24proc)); $tmp->$class = &linesQ_L_24procG_methods; linesQ_L_24procG_methods.__init__($tmp, G_1, G_2); @@ -706,20 +723,21 @@ linesQ_L_24proc linesQ_L_24procG_new(linesQ_main G_1, B_int G_2) { } struct linesQ_L_24procG_class linesQ_L_24procG_methods; B_NoneType linesQ_L_25procD___init__ (linesQ_L_25proc L_self, linesQ_main self) { - L_self->self = self; + ((linesQ_L_25proc)(L_self))->self = self; return B_None; } $R linesQ_L_25procD___call__ (linesQ_L_25proc L_self, $Cont C_cont) { - linesQ_main self = L_self->self; - return (($R (*) (linesQ_main, $Cont))self->$class->nopG_local)(self, C_cont); + linesQ_main self = ((linesQ_L_25proc)(L_self))->self; + return (($R (*) ($WORD, $Cont))self->$class->nopG_local)(self, C_cont); } $R linesQ_L_25procD___exec__ (linesQ_L_25proc L_self, $Cont C_cont) { - return (($R (*) (linesQ_L_25proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void linesQ_L_25procD___serialize__ (linesQ_L_25proc self, $Serial$state state) { $step_serialize(self->self, state); } linesQ_L_25proc linesQ_L_25procD___deserialize__ (linesQ_L_25proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_25proc)); @@ -742,13 +760,13 @@ struct linesQ_L_25procG_class linesQ_L_25procG_methods; return $R_CONT(C_cont, G_act); } B_NoneType linesQ_L_27ContD___init__ (linesQ_L_27Cont L_self, $Cont C_cont, linesQ_Apa G_act) { - L_self->C_cont = C_cont; - L_self->G_act = G_act; + ((linesQ_L_27Cont)(L_self))->C_cont = C_cont; + ((linesQ_L_27Cont)(L_self))->G_act = G_act; return B_None; } $R linesQ_L_27ContD___call__ (linesQ_L_27Cont L_self, B_NoneType G_1) { - $Cont C_cont = L_self->C_cont; - linesQ_Apa G_act = L_self->G_act; + $Cont C_cont = ((linesQ_L_27Cont)(L_self))->C_cont; + linesQ_Apa G_act = ((linesQ_L_27Cont)(L_self))->G_act; return linesQ_L_26C_11cont(C_cont, G_act, G_1); } void linesQ_L_27ContD___serialize__ (linesQ_L_27Cont self, $Serial$state state) { @@ -756,6 +774,7 @@ void linesQ_L_27ContD___serialize__ (linesQ_L_27Cont self, $Serial$state state) $step_serialize(self->G_act, state); } linesQ_L_27Cont linesQ_L_27ContD___deserialize__ (linesQ_L_27Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_27Cont)); @@ -776,20 +795,21 @@ linesQ_L_27Cont linesQ_L_27ContG_new($Cont G_1, linesQ_Apa G_2) { } struct linesQ_L_27ContG_class linesQ_L_27ContG_methods; B_NoneType linesQ_L_28procD___init__ (linesQ_L_28proc L_self, linesQ_Apa G_act) { - L_self->G_act = G_act; + ((linesQ_L_28proc)(L_self))->G_act = G_act; return B_None; } $R linesQ_L_28procD___call__ (linesQ_L_28proc L_self, $Cont C_cont) { - linesQ_Apa G_act = L_self->G_act; - return (($R (*) (linesQ_Apa, $Cont))G_act->$class->__init__)(G_act, C_cont); + linesQ_Apa G_act = ((linesQ_L_28proc)(L_self))->G_act; + return (($R (*) ($WORD, $Cont))G_act->$class->__init__)(G_act, C_cont); } $R linesQ_L_28procD___exec__ (linesQ_L_28proc L_self, $Cont C_cont) { - return (($R (*) (linesQ_L_28proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void linesQ_L_28procD___serialize__ (linesQ_L_28proc self, $Serial$state state) { $step_serialize(self->G_act, state); } linesQ_L_28proc linesQ_L_28procD___deserialize__ (linesQ_L_28proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_28proc)); @@ -812,13 +832,13 @@ struct linesQ_L_28procG_class linesQ_L_28procG_methods; return $R_CONT(C_cont, G_act); } B_NoneType linesQ_L_30ContD___init__ (linesQ_L_30Cont L_self, $Cont C_cont, linesQ_Bepa G_act) { - L_self->C_cont = C_cont; - L_self->G_act = G_act; + ((linesQ_L_30Cont)(L_self))->C_cont = C_cont; + ((linesQ_L_30Cont)(L_self))->G_act = G_act; return B_None; } $R linesQ_L_30ContD___call__ (linesQ_L_30Cont L_self, B_NoneType G_1) { - $Cont C_cont = L_self->C_cont; - linesQ_Bepa G_act = L_self->G_act; + $Cont C_cont = ((linesQ_L_30Cont)(L_self))->C_cont; + linesQ_Bepa G_act = ((linesQ_L_30Cont)(L_self))->G_act; return linesQ_L_29C_13cont(C_cont, G_act, G_1); } void linesQ_L_30ContD___serialize__ (linesQ_L_30Cont self, $Serial$state state) { @@ -826,6 +846,7 @@ void linesQ_L_30ContD___serialize__ (linesQ_L_30Cont self, $Serial$state state) $step_serialize(self->G_act, state); } linesQ_L_30Cont linesQ_L_30ContD___deserialize__ (linesQ_L_30Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_30Cont)); @@ -846,20 +867,21 @@ linesQ_L_30Cont linesQ_L_30ContG_new($Cont G_1, linesQ_Bepa G_2) { } struct linesQ_L_30ContG_class linesQ_L_30ContG_methods; B_NoneType linesQ_L_31procD___init__ (linesQ_L_31proc L_self, linesQ_Bepa G_act) { - L_self->G_act = G_act; + ((linesQ_L_31proc)(L_self))->G_act = G_act; return B_None; } $R linesQ_L_31procD___call__ (linesQ_L_31proc L_self, $Cont C_cont) { - linesQ_Bepa G_act = L_self->G_act; - return (($R (*) (linesQ_Bepa, $Cont))G_act->$class->__init__)(G_act, C_cont); + linesQ_Bepa G_act = ((linesQ_L_31proc)(L_self))->G_act; + return (($R (*) ($WORD, $Cont))G_act->$class->__init__)(G_act, C_cont); } $R linesQ_L_31procD___exec__ (linesQ_L_31proc L_self, $Cont C_cont) { - return (($R (*) (linesQ_L_31proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void linesQ_L_31procD___serialize__ (linesQ_L_31proc self, $Serial$state state) { $step_serialize(self->G_act, state); } linesQ_L_31proc linesQ_L_31procD___deserialize__ (linesQ_L_31proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_31proc)); @@ -882,13 +904,13 @@ struct linesQ_L_31procG_class linesQ_L_31procG_methods; return $R_CONT(C_cont, G_act); } B_NoneType linesQ_L_33ContD___init__ (linesQ_L_33Cont L_self, $Cont C_cont, linesQ_main G_act) { - L_self->C_cont = C_cont; - L_self->G_act = G_act; + ((linesQ_L_33Cont)(L_self))->C_cont = C_cont; + ((linesQ_L_33Cont)(L_self))->G_act = G_act; return B_None; } $R linesQ_L_33ContD___call__ (linesQ_L_33Cont L_self, B_NoneType G_1) { - $Cont C_cont = L_self->C_cont; - linesQ_main G_act = L_self->G_act; + $Cont C_cont = ((linesQ_L_33Cont)(L_self))->C_cont; + linesQ_main G_act = ((linesQ_L_33Cont)(L_self))->G_act; return linesQ_L_32C_15cont(C_cont, G_act, G_1); } void linesQ_L_33ContD___serialize__ (linesQ_L_33Cont self, $Serial$state state) { @@ -896,6 +918,7 @@ void linesQ_L_33ContD___serialize__ (linesQ_L_33Cont self, $Serial$state state) $step_serialize(self->G_act, state); } linesQ_L_33Cont linesQ_L_33ContD___deserialize__ (linesQ_L_33Cont self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_33Cont)); @@ -916,23 +939,24 @@ linesQ_L_33Cont linesQ_L_33ContG_new($Cont G_1, linesQ_main G_2) { } struct linesQ_L_33ContG_class linesQ_L_33ContG_methods; B_NoneType linesQ_L_34procD___init__ (linesQ_L_34proc L_self, linesQ_main G_act, B_Env env) { - L_self->G_act = G_act; - L_self->env = env; + ((linesQ_L_34proc)(L_self))->G_act = G_act; + ((linesQ_L_34proc)(L_self))->env = env; return B_None; } $R linesQ_L_34procD___call__ (linesQ_L_34proc L_self, $Cont C_cont) { - linesQ_main G_act = L_self->G_act; - B_Env env = L_self->env; - return (($R (*) (linesQ_main, $Cont, B_Env))G_act->$class->__init__)(G_act, C_cont, env); + linesQ_main G_act = ((linesQ_L_34proc)(L_self))->G_act; + B_Env env = ((linesQ_L_34proc)(L_self))->env; + return (($R (*) ($WORD, $Cont, B_Env))G_act->$class->__init__)(G_act, C_cont, env); } $R linesQ_L_34procD___exec__ (linesQ_L_34proc L_self, $Cont C_cont) { - return (($R (*) (linesQ_L_34proc, $Cont))L_self->$class->__call__)(L_self, C_cont); + return (($R (*) ($WORD, $Cont))L_self->$class->__call__)(L_self, C_cont); } void linesQ_L_34procD___serialize__ (linesQ_L_34proc self, $Serial$state state) { $step_serialize(self->G_act, state); $step_serialize(self->env, state); } linesQ_L_34proc linesQ_L_34procD___deserialize__ (linesQ_L_34proc self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_L_34proc)); @@ -954,33 +978,33 @@ linesQ_L_34proc linesQ_L_34procG_new(linesQ_main G_1, B_Env G_2) { struct linesQ_L_34procG_class linesQ_L_34procG_methods; $R linesQ_ApaD___init__ (linesQ_Apa self, $Cont C_cont) { #line 2 "test/src/lines.act" - self->apa = toB_int(2001LL); + ((linesQ_Apa)(self))->apa = 2001LL; #line 6 "test/src/lines.act" - self->apb = toB_int(2002LL); + ((linesQ_Apa)(self))->apb = 2002LL; #line 16 "test/src/lines.act" - self->y = toB_int(123LL); - return (($R (*) (linesQ_Apa, $Cont, $action))self->$class->setupG_local)(self, (($Cont)linesQ_L_2ContG_new(self, C_cont)), (($action)linesQ_L_4actionG_new(self))); + ((linesQ_Apa)(self))->y = 123LL; + return (($R (*) ($WORD, $Cont, $action))self->$class->setupG_local)(self, (($Cont)linesQ_L_2ContG_new(self, C_cont)), (($action)linesQ_L_4actionG_new(self))); } #line 3 "test/src/lines.act" $R linesQ_ApaD_setupG_local (linesQ_Apa self, $Cont C_cont, $action cb) { #line 4 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("setup")), B_None, B_None, B_None, B_None); #line 5 "test/src/lines.act" - ((B_Msg (*) ($action, B_int))cb->$class->__asyn__)(cb, toB_int(0LL)); + ((B_Msg (*) ($WORD, B_int))cb->$class->__asyn__)(cb, toB_int(0LL)); return $R_CONT(C_cont, B_None); } #line 7 "test/src/lines.act" $R linesQ_ApaD_computeG_local (linesQ_Apa self, $Cont C_cont, $action cb) { #line 8 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("compute")), B_None, B_None, B_None, B_None); - return $AWAIT((($Cont)linesQ_L_6ContG_new(cb, C_cont)), ((B_Msg)((B_Msg (*) ($action, B_int))cb->$class->__asyn__)(cb, toB_int(1LL)))); + return $AWAIT((($Cont)linesQ_L_6ContG_new(cb, C_cont)), ((B_Msg)((B_Msg (*) ($WORD, B_int))cb->$class->__asyn__)(cb, toB_int(1LL)))); } #line 12 "test/src/lines.act" -$R linesQ_ApaD_noticeG_local (linesQ_Apa self, $Cont C_cont, B_int i) { +$R linesQ_ApaD_noticeG_local (linesQ_Apa self, $Cont C_cont, int64_t i) { #line 13 "test/src/lines.act" ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(1, to$str("notice")), B_None, B_None, B_None, B_None); - int64_t U_9N_1tmp = (((B_int)i)->val + 1LL); - return $R_CONT(C_cont, toB_int(U_9N_1tmp)); + int64_t N_1tmp = (((int64_t)(i + 1LL))); + return $R_CONT(C_cont, toB_int(N_1tmp)); } B_Msg linesQ_ApaD_setup (linesQ_Apa self, $action cb) { return $ASYNC((($Actor)self), (($Cont)linesQ_L_7procG_new(self, cb))); @@ -988,17 +1012,18 @@ B_Msg linesQ_ApaD_setup (linesQ_Apa self, $action cb) { B_Msg linesQ_ApaD_compute (linesQ_Apa self, $action cb) { return ((B_Msg)$ASYNC((($Actor)self), (($Cont)linesQ_L_8procG_new(self, cb)))); } -B_Msg linesQ_ApaD_notice (linesQ_Apa self, B_int i) { +B_Msg linesQ_ApaD_notice (linesQ_Apa self, int64_t i) { return ((B_Msg)$ASYNC((($Actor)self), (($Cont)linesQ_L_9procG_new(self, i)))); } void linesQ_ApaD___serialize__ (linesQ_Apa self, $Serial$state state) { $ActorG_methods.__serialize__(($Actor)self, state); - $step_serialize(self->apa, state); - $step_serialize(self->apb, state); - $step_serialize(self->y, state); - $step_serialize(self->z, state); + $val_serialize(I64_ID, &self->apa, state); + $val_serialize(I64_ID, &self->apb, state); + $val_serialize(I64_ID, &self->y, state); + $val_serialize(I64_ID, &self->z, state); } linesQ_Apa linesQ_ApaD___deserialize__ (linesQ_Apa self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_Apa)); @@ -1008,10 +1033,14 @@ linesQ_Apa linesQ_ApaD___deserialize__ (linesQ_Apa self, $Serial$state state) { self = $DNEW(linesQ_Apa, state); } $ActorG_methods.__deserialize__(($Actor)self, state); - self->apa = $step_deserialize(state); - self->apb = $step_deserialize(state); - self->y = $step_deserialize(state); - self->z = $step_deserialize(state); + $tmp = $val_deserialize(state); + memcpy(&self->apa, &$tmp, sizeof(self->apa)); + $tmp = $val_deserialize(state); + memcpy(&self->apb, &$tmp, sizeof(self->apb)); + $tmp = $val_deserialize(state); + memcpy(&self->y, &$tmp, sizeof(self->y)); + $tmp = $val_deserialize(state); + memcpy(&self->z, &$tmp, sizeof(self->z)); return self; } void linesQ_ApaD_GCfinalizer (void *obj, void *cdata) { @@ -1030,19 +1059,20 @@ struct linesQ_ApaG_class linesQ_ApaG_methods; return $R_CONT(C_cont, B_None); } #line 22 "test/src/lines.act" -$R linesQ_BepaD_callbackG_local (linesQ_Bepa self, $Cont C_cont, B_int i) { +$R linesQ_BepaD_callbackG_local (linesQ_Bepa self, $Cont C_cont, int64_t i) { #line 23 "test/src/lines.act" - ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("callback"), i), B_None, B_None, B_None, B_None); - int64_t U_10N_2tmp = (((B_int)i)->val + 1LL); - return $R_CONT(C_cont, toB_int(U_10N_2tmp)); + ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("callback"), toB_int(i)), B_None, B_None, B_None, B_None); + int64_t N_2tmp = (((int64_t)(i + 1LL))); + return $R_CONT(C_cont, toB_int(N_2tmp)); } -B_Msg linesQ_BepaD_callback (linesQ_Bepa self, B_int i) { +B_Msg linesQ_BepaD_callback (linesQ_Bepa self, int64_t i) { return ((B_Msg)$ASYNC((($Actor)self), (($Cont)linesQ_L_10procG_new(self, i)))); } void linesQ_BepaD___serialize__ (linesQ_Bepa self, $Serial$state state) { $ActorG_methods.__serialize__(($Actor)self, state); } linesQ_Bepa linesQ_BepaD___deserialize__ (linesQ_Bepa self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_Bepa)); @@ -1065,26 +1095,26 @@ void linesQ_BepaD_GCfinalizer (void *obj, void *cdata) { } struct linesQ_BepaG_class linesQ_BepaG_methods; $R linesQ_mainD___init__ (linesQ_main self, $Cont C_cont, B_Env env) { - self->env = env; + ((linesQ_main)(self))->env = env; return linesQ_ApaG_newact((($Cont)linesQ_L_23ContG_new(self, C_cont))); } #line 28 "test/src/lines.act" -$R linesQ_mainD_myprocG_local (linesQ_main self, $Cont C_cont, B_int i) { +$R linesQ_mainD_myprocG_local (linesQ_main self, $Cont C_cont, int64_t i) { #line 29 "test/src/lines.act" - ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("myproc"), i), B_None, B_None, B_None, B_None); + ((B_NoneType (*) (B_tuple, B_str, B_str, B_bool, B_bool))B_print)($NEWTUPLE(2, to$str("myproc"), toB_int(i)), B_None, B_None, B_None, B_None); #line 30 "test/src/lines.act" - if (((B_bool)((B_bool (*) (B_Eq, B_int, B_int))linesQ_W_Apa_331->$class->__eq__)(linesQ_W_Apa_331, i, toB_int(2LL)))->val) { + if (((B_bool)((B_bool (*) ($WORD, B_int, B_int))linesQ_W_Apa_331->$class->__eq__)(linesQ_W_Apa_331, toB_int(i), toB_int(2LL)))->val) { #line 31 "test/src/lines.act" - ((B_Msg (*) (B_Env, B_int))self->env->$class->exit)(self->env, toB_int(0LL)); + ((B_Msg (*) ($WORD, int64_t))((linesQ_main)(self))->env->$class->exit)(((linesQ_main)(self))->env, 0LL); } - return $R_CONT(C_cont, i); + return $R_CONT(C_cont, toB_int(i)); } #line 92 "test/src/lines.act" $R linesQ_mainD_nopG_local (linesQ_main self, $Cont C_cont) { #line 93 "test/src/lines.act" return $R_CONT(C_cont, B_None); } -B_Msg linesQ_mainD_myproc (linesQ_main self, B_int i) { +B_Msg linesQ_mainD_myproc (linesQ_main self, int64_t i) { return ((B_Msg)$ASYNC((($Actor)self), (($Cont)linesQ_L_24procG_new(self, i)))); } B_Msg linesQ_mainD_nop (linesQ_main self) { @@ -1096,11 +1126,12 @@ void linesQ_mainD___serialize__ (linesQ_main self, $Serial$state state) { $step_serialize(self->a, state); $step_serialize(self->b, state); $step_serialize(self->x, state); - $step_serialize(self->r, state); - $step_serialize(self->v, state); - $step_serialize(self->i, state); + $val_serialize(I64_ID, &self->r, state); + $val_serialize(I64_ID, &self->v, state); + $val_serialize(I64_ID, &self->i, state); } linesQ_main linesQ_mainD___deserialize__ (linesQ_main self, $Serial$state state) { + $WORD $tmp; if (!self) { if (!state) { self = acton_malloc(sizeof(struct linesQ_main)); @@ -1114,9 +1145,12 @@ linesQ_main linesQ_mainD___deserialize__ (linesQ_main self, $Serial$state state) self->a = $step_deserialize(state); self->b = $step_deserialize(state); self->x = $step_deserialize(state); - self->r = $step_deserialize(state); - self->v = $step_deserialize(state); - self->i = $step_deserialize(state); + $tmp = $val_deserialize(state); + memcpy(&self->r, &$tmp, sizeof(self->r)); + $tmp = $val_deserialize(state); + memcpy(&self->v, &$tmp, sizeof(self->v)); + $tmp = $val_deserialize(state); + memcpy(&self->i, &$tmp, sizeof(self->i)); return self; } void linesQ_mainD_GCfinalizer (void *obj, void *cdata) { @@ -1154,8 +1188,8 @@ void linesQ___init__ () { linesQ_L_2ContG_methods.__bool__ = (B_bool (*) (linesQ_L_2Cont))B_valueG_methods.__bool__; linesQ_L_2ContG_methods.__str__ = (B_str (*) (linesQ_L_2Cont))B_valueG_methods.__str__; linesQ_L_2ContG_methods.__repr__ = (B_str (*) (linesQ_L_2Cont))B_valueG_methods.__repr__; - linesQ_L_2ContG_methods.__init__ = linesQ_L_2ContD___init__; - linesQ_L_2ContG_methods.__call__ = linesQ_L_2ContD___call__; + linesQ_L_2ContG_methods.__init__ = (B_NoneType (*) (linesQ_L_2Cont, linesQ_Apa, $Cont))linesQ_L_2ContD___init__; + linesQ_L_2ContG_methods.__call__ = ($R (*) (linesQ_L_2Cont, B_NoneType))linesQ_L_2ContD___call__; linesQ_L_2ContG_methods.__serialize__ = linesQ_L_2ContD___serialize__; linesQ_L_2ContG_methods.__deserialize__ = linesQ_L_2ContD___deserialize__; $register(&linesQ_L_2ContG_methods); @@ -1166,10 +1200,10 @@ void linesQ___init__ () { linesQ_L_4actionG_methods.__bool__ = (B_bool (*) (linesQ_L_4action))B_valueG_methods.__bool__; linesQ_L_4actionG_methods.__str__ = (B_str (*) (linesQ_L_4action))B_valueG_methods.__str__; linesQ_L_4actionG_methods.__repr__ = (B_str (*) (linesQ_L_4action))B_valueG_methods.__repr__; - linesQ_L_4actionG_methods.__init__ = linesQ_L_4actionD___init__; - linesQ_L_4actionG_methods.__call__ = linesQ_L_4actionD___call__; - linesQ_L_4actionG_methods.__exec__ = linesQ_L_4actionD___exec__; - linesQ_L_4actionG_methods.__asyn__ = linesQ_L_4actionD___asyn__; + linesQ_L_4actionG_methods.__init__ = (B_NoneType (*) (linesQ_L_4action, linesQ_Apa))linesQ_L_4actionD___init__; + linesQ_L_4actionG_methods.__call__ = ($R (*) (linesQ_L_4action, $Cont, B_int))linesQ_L_4actionD___call__; + linesQ_L_4actionG_methods.__exec__ = ($R (*) (linesQ_L_4action, $Cont, B_int))linesQ_L_4actionD___exec__; + linesQ_L_4actionG_methods.__asyn__ = (B_Msg (*) (linesQ_L_4action, B_int))linesQ_L_4actionD___asyn__; linesQ_L_4actionG_methods.__serialize__ = linesQ_L_4actionD___serialize__; linesQ_L_4actionG_methods.__deserialize__ = linesQ_L_4actionD___deserialize__; $register(&linesQ_L_4actionG_methods); @@ -1180,8 +1214,8 @@ void linesQ___init__ () { linesQ_L_6ContG_methods.__bool__ = (B_bool (*) (linesQ_L_6Cont))B_valueG_methods.__bool__; linesQ_L_6ContG_methods.__str__ = (B_str (*) (linesQ_L_6Cont))B_valueG_methods.__str__; linesQ_L_6ContG_methods.__repr__ = (B_str (*) (linesQ_L_6Cont))B_valueG_methods.__repr__; - linesQ_L_6ContG_methods.__init__ = linesQ_L_6ContD___init__; - linesQ_L_6ContG_methods.__call__ = linesQ_L_6ContD___call__; + linesQ_L_6ContG_methods.__init__ = (B_NoneType (*) (linesQ_L_6Cont, $action, $Cont))linesQ_L_6ContD___init__; + linesQ_L_6ContG_methods.__call__ = ($R (*) (linesQ_L_6Cont, B_int))linesQ_L_6ContD___call__; linesQ_L_6ContG_methods.__serialize__ = linesQ_L_6ContD___serialize__; linesQ_L_6ContG_methods.__deserialize__ = linesQ_L_6ContD___deserialize__; $register(&linesQ_L_6ContG_methods); @@ -1192,9 +1226,9 @@ void linesQ___init__ () { linesQ_L_7procG_methods.__bool__ = (B_bool (*) (linesQ_L_7proc))B_valueG_methods.__bool__; linesQ_L_7procG_methods.__str__ = (B_str (*) (linesQ_L_7proc))B_valueG_methods.__str__; linesQ_L_7procG_methods.__repr__ = (B_str (*) (linesQ_L_7proc))B_valueG_methods.__repr__; - linesQ_L_7procG_methods.__init__ = linesQ_L_7procD___init__; - linesQ_L_7procG_methods.__call__ = linesQ_L_7procD___call__; - linesQ_L_7procG_methods.__exec__ = linesQ_L_7procD___exec__; + linesQ_L_7procG_methods.__init__ = (B_NoneType (*) (linesQ_L_7proc, linesQ_Apa, $action))linesQ_L_7procD___init__; + linesQ_L_7procG_methods.__call__ = ($R (*) (linesQ_L_7proc, $Cont))linesQ_L_7procD___call__; + linesQ_L_7procG_methods.__exec__ = ($R (*) (linesQ_L_7proc, $Cont))linesQ_L_7procD___exec__; linesQ_L_7procG_methods.__serialize__ = linesQ_L_7procD___serialize__; linesQ_L_7procG_methods.__deserialize__ = linesQ_L_7procD___deserialize__; $register(&linesQ_L_7procG_methods); @@ -1205,9 +1239,9 @@ void linesQ___init__ () { linesQ_L_8procG_methods.__bool__ = (B_bool (*) (linesQ_L_8proc))B_valueG_methods.__bool__; linesQ_L_8procG_methods.__str__ = (B_str (*) (linesQ_L_8proc))B_valueG_methods.__str__; linesQ_L_8procG_methods.__repr__ = (B_str (*) (linesQ_L_8proc))B_valueG_methods.__repr__; - linesQ_L_8procG_methods.__init__ = linesQ_L_8procD___init__; - linesQ_L_8procG_methods.__call__ = linesQ_L_8procD___call__; - linesQ_L_8procG_methods.__exec__ = linesQ_L_8procD___exec__; + linesQ_L_8procG_methods.__init__ = (B_NoneType (*) (linesQ_L_8proc, linesQ_Apa, $action))linesQ_L_8procD___init__; + linesQ_L_8procG_methods.__call__ = ($R (*) (linesQ_L_8proc, $Cont))linesQ_L_8procD___call__; + linesQ_L_8procG_methods.__exec__ = ($R (*) (linesQ_L_8proc, $Cont))linesQ_L_8procD___exec__; linesQ_L_8procG_methods.__serialize__ = linesQ_L_8procD___serialize__; linesQ_L_8procG_methods.__deserialize__ = linesQ_L_8procD___deserialize__; $register(&linesQ_L_8procG_methods); @@ -1218,9 +1252,9 @@ void linesQ___init__ () { linesQ_L_9procG_methods.__bool__ = (B_bool (*) (linesQ_L_9proc))B_valueG_methods.__bool__; linesQ_L_9procG_methods.__str__ = (B_str (*) (linesQ_L_9proc))B_valueG_methods.__str__; linesQ_L_9procG_methods.__repr__ = (B_str (*) (linesQ_L_9proc))B_valueG_methods.__repr__; - linesQ_L_9procG_methods.__init__ = linesQ_L_9procD___init__; - linesQ_L_9procG_methods.__call__ = linesQ_L_9procD___call__; - linesQ_L_9procG_methods.__exec__ = linesQ_L_9procD___exec__; + linesQ_L_9procG_methods.__init__ = (B_NoneType (*) (linesQ_L_9proc, linesQ_Apa, int64_t))linesQ_L_9procD___init__; + linesQ_L_9procG_methods.__call__ = ($R (*) (linesQ_L_9proc, $Cont))linesQ_L_9procD___call__; + linesQ_L_9procG_methods.__exec__ = ($R (*) (linesQ_L_9proc, $Cont))linesQ_L_9procD___exec__; linesQ_L_9procG_methods.__serialize__ = linesQ_L_9procD___serialize__; linesQ_L_9procG_methods.__deserialize__ = linesQ_L_9procD___deserialize__; $register(&linesQ_L_9procG_methods); @@ -1231,9 +1265,9 @@ void linesQ___init__ () { linesQ_L_10procG_methods.__bool__ = (B_bool (*) (linesQ_L_10proc))B_valueG_methods.__bool__; linesQ_L_10procG_methods.__str__ = (B_str (*) (linesQ_L_10proc))B_valueG_methods.__str__; linesQ_L_10procG_methods.__repr__ = (B_str (*) (linesQ_L_10proc))B_valueG_methods.__repr__; - linesQ_L_10procG_methods.__init__ = linesQ_L_10procD___init__; - linesQ_L_10procG_methods.__call__ = linesQ_L_10procD___call__; - linesQ_L_10procG_methods.__exec__ = linesQ_L_10procD___exec__; + linesQ_L_10procG_methods.__init__ = (B_NoneType (*) (linesQ_L_10proc, linesQ_Bepa, int64_t))linesQ_L_10procD___init__; + linesQ_L_10procG_methods.__call__ = ($R (*) (linesQ_L_10proc, $Cont))linesQ_L_10procD___call__; + linesQ_L_10procG_methods.__exec__ = ($R (*) (linesQ_L_10proc, $Cont))linesQ_L_10procD___exec__; linesQ_L_10procG_methods.__serialize__ = linesQ_L_10procD___serialize__; linesQ_L_10procG_methods.__deserialize__ = linesQ_L_10procD___deserialize__; $register(&linesQ_L_10procG_methods); @@ -1244,10 +1278,10 @@ void linesQ___init__ () { linesQ_L_14actionG_methods.__bool__ = (B_bool (*) (linesQ_L_14action))B_valueG_methods.__bool__; linesQ_L_14actionG_methods.__str__ = (B_str (*) (linesQ_L_14action))B_valueG_methods.__str__; linesQ_L_14actionG_methods.__repr__ = (B_str (*) (linesQ_L_14action))B_valueG_methods.__repr__; - linesQ_L_14actionG_methods.__init__ = linesQ_L_14actionD___init__; - linesQ_L_14actionG_methods.__call__ = linesQ_L_14actionD___call__; - linesQ_L_14actionG_methods.__exec__ = linesQ_L_14actionD___exec__; - linesQ_L_14actionG_methods.__asyn__ = linesQ_L_14actionD___asyn__; + linesQ_L_14actionG_methods.__init__ = (B_NoneType (*) (linesQ_L_14action, linesQ_Apa))linesQ_L_14actionD___init__; + linesQ_L_14actionG_methods.__call__ = ($R (*) (linesQ_L_14action, $Cont, B_int))linesQ_L_14actionD___call__; + linesQ_L_14actionG_methods.__exec__ = ($R (*) (linesQ_L_14action, $Cont, B_int))linesQ_L_14actionD___exec__; + linesQ_L_14actionG_methods.__asyn__ = (B_Msg (*) (linesQ_L_14action, B_int))linesQ_L_14actionD___asyn__; linesQ_L_14actionG_methods.__serialize__ = linesQ_L_14actionD___serialize__; linesQ_L_14actionG_methods.__deserialize__ = linesQ_L_14actionD___deserialize__; $register(&linesQ_L_14actionG_methods); @@ -1258,10 +1292,10 @@ void linesQ___init__ () { linesQ_L_16actionG_methods.__bool__ = (B_bool (*) (linesQ_L_16action))B_valueG_methods.__bool__; linesQ_L_16actionG_methods.__str__ = (B_str (*) (linesQ_L_16action))B_valueG_methods.__str__; linesQ_L_16actionG_methods.__repr__ = (B_str (*) (linesQ_L_16action))B_valueG_methods.__repr__; - linesQ_L_16actionG_methods.__init__ = linesQ_L_16actionD___init__; - linesQ_L_16actionG_methods.__call__ = linesQ_L_16actionD___call__; - linesQ_L_16actionG_methods.__exec__ = linesQ_L_16actionD___exec__; - linesQ_L_16actionG_methods.__asyn__ = linesQ_L_16actionD___asyn__; + linesQ_L_16actionG_methods.__init__ = (B_NoneType (*) (linesQ_L_16action, linesQ_Bepa))linesQ_L_16actionD___init__; + linesQ_L_16actionG_methods.__call__ = ($R (*) (linesQ_L_16action, $Cont, B_int))linesQ_L_16actionD___call__; + linesQ_L_16actionG_methods.__exec__ = ($R (*) (linesQ_L_16action, $Cont, B_int))linesQ_L_16actionD___exec__; + linesQ_L_16actionG_methods.__asyn__ = (B_Msg (*) (linesQ_L_16action, B_int))linesQ_L_16actionD___asyn__; linesQ_L_16actionG_methods.__serialize__ = linesQ_L_16actionD___serialize__; linesQ_L_16actionG_methods.__deserialize__ = linesQ_L_16actionD___deserialize__; $register(&linesQ_L_16actionG_methods); @@ -1272,10 +1306,10 @@ void linesQ___init__ () { linesQ_L_19actionG_methods.__bool__ = (B_bool (*) (linesQ_L_19action))B_valueG_methods.__bool__; linesQ_L_19actionG_methods.__str__ = (B_str (*) (linesQ_L_19action))B_valueG_methods.__str__; linesQ_L_19actionG_methods.__repr__ = (B_str (*) (linesQ_L_19action))B_valueG_methods.__repr__; - linesQ_L_19actionG_methods.__init__ = linesQ_L_19actionD___init__; - linesQ_L_19actionG_methods.__call__ = linesQ_L_19actionD___call__; - linesQ_L_19actionG_methods.__exec__ = linesQ_L_19actionD___exec__; - linesQ_L_19actionG_methods.__asyn__ = linesQ_L_19actionD___asyn__; + linesQ_L_19actionG_methods.__init__ = (B_NoneType (*) (linesQ_L_19action, linesQ_main))linesQ_L_19actionD___init__; + linesQ_L_19actionG_methods.__call__ = ($R (*) (linesQ_L_19action, $Cont, B_int))linesQ_L_19actionD___call__; + linesQ_L_19actionG_methods.__exec__ = ($R (*) (linesQ_L_19action, $Cont, B_int))linesQ_L_19actionD___exec__; + linesQ_L_19actionG_methods.__asyn__ = (B_Msg (*) (linesQ_L_19action, B_int))linesQ_L_19actionD___asyn__; linesQ_L_19actionG_methods.__serialize__ = linesQ_L_19actionD___serialize__; linesQ_L_19actionG_methods.__deserialize__ = linesQ_L_19actionD___deserialize__; $register(&linesQ_L_19actionG_methods); @@ -1286,9 +1320,9 @@ void linesQ___init__ () { linesQ_L_20procG_methods.__bool__ = (B_bool (*) (linesQ_L_20proc))B_valueG_methods.__bool__; linesQ_L_20procG_methods.__str__ = (B_str (*) (linesQ_L_20proc))B_valueG_methods.__str__; linesQ_L_20procG_methods.__repr__ = (B_str (*) (linesQ_L_20proc))B_valueG_methods.__repr__; - linesQ_L_20procG_methods.__init__ = linesQ_L_20procD___init__; - linesQ_L_20procG_methods.__call__ = linesQ_L_20procD___call__; - linesQ_L_20procG_methods.__exec__ = linesQ_L_20procD___exec__; + linesQ_L_20procG_methods.__init__ = (B_NoneType (*) (linesQ_L_20proc, linesQ_main))linesQ_L_20procD___init__; + linesQ_L_20procG_methods.__call__ = ($R (*) (linesQ_L_20proc, $Cont))linesQ_L_20procD___call__; + linesQ_L_20procG_methods.__exec__ = ($R (*) (linesQ_L_20proc, $Cont))linesQ_L_20procD___exec__; linesQ_L_20procG_methods.__serialize__ = linesQ_L_20procD___serialize__; linesQ_L_20procG_methods.__deserialize__ = linesQ_L_20procD___deserialize__; $register(&linesQ_L_20procG_methods); @@ -1299,8 +1333,8 @@ void linesQ___init__ () { linesQ_L_21ContG_methods.__bool__ = (B_bool (*) (linesQ_L_21Cont))B_valueG_methods.__bool__; linesQ_L_21ContG_methods.__str__ = (B_str (*) (linesQ_L_21Cont))B_valueG_methods.__str__; linesQ_L_21ContG_methods.__repr__ = (B_str (*) (linesQ_L_21Cont))B_valueG_methods.__repr__; - linesQ_L_21ContG_methods.__init__ = linesQ_L_21ContD___init__; - linesQ_L_21ContG_methods.__call__ = linesQ_L_21ContD___call__; + linesQ_L_21ContG_methods.__init__ = (B_NoneType (*) (linesQ_L_21Cont, linesQ_main, $Cont))linesQ_L_21ContD___init__; + linesQ_L_21ContG_methods.__call__ = ($R (*) (linesQ_L_21Cont, B_int))linesQ_L_21ContD___call__; linesQ_L_21ContG_methods.__serialize__ = linesQ_L_21ContD___serialize__; linesQ_L_21ContG_methods.__deserialize__ = linesQ_L_21ContD___deserialize__; $register(&linesQ_L_21ContG_methods); @@ -1311,8 +1345,8 @@ void linesQ___init__ () { linesQ_L_22ContG_methods.__bool__ = (B_bool (*) (linesQ_L_22Cont))B_valueG_methods.__bool__; linesQ_L_22ContG_methods.__str__ = (B_str (*) (linesQ_L_22Cont))B_valueG_methods.__str__; linesQ_L_22ContG_methods.__repr__ = (B_str (*) (linesQ_L_22Cont))B_valueG_methods.__repr__; - linesQ_L_22ContG_methods.__init__ = linesQ_L_22ContD___init__; - linesQ_L_22ContG_methods.__call__ = linesQ_L_22ContD___call__; + linesQ_L_22ContG_methods.__init__ = (B_NoneType (*) (linesQ_L_22Cont, linesQ_main, $Cont))linesQ_L_22ContD___init__; + linesQ_L_22ContG_methods.__call__ = ($R (*) (linesQ_L_22Cont, linesQ_Bepa))linesQ_L_22ContD___call__; linesQ_L_22ContG_methods.__serialize__ = linesQ_L_22ContD___serialize__; linesQ_L_22ContG_methods.__deserialize__ = linesQ_L_22ContD___deserialize__; $register(&linesQ_L_22ContG_methods); @@ -1323,8 +1357,8 @@ void linesQ___init__ () { linesQ_L_23ContG_methods.__bool__ = (B_bool (*) (linesQ_L_23Cont))B_valueG_methods.__bool__; linesQ_L_23ContG_methods.__str__ = (B_str (*) (linesQ_L_23Cont))B_valueG_methods.__str__; linesQ_L_23ContG_methods.__repr__ = (B_str (*) (linesQ_L_23Cont))B_valueG_methods.__repr__; - linesQ_L_23ContG_methods.__init__ = linesQ_L_23ContD___init__; - linesQ_L_23ContG_methods.__call__ = linesQ_L_23ContD___call__; + linesQ_L_23ContG_methods.__init__ = (B_NoneType (*) (linesQ_L_23Cont, linesQ_main, $Cont))linesQ_L_23ContD___init__; + linesQ_L_23ContG_methods.__call__ = ($R (*) (linesQ_L_23Cont, linesQ_Apa))linesQ_L_23ContD___call__; linesQ_L_23ContG_methods.__serialize__ = linesQ_L_23ContD___serialize__; linesQ_L_23ContG_methods.__deserialize__ = linesQ_L_23ContD___deserialize__; $register(&linesQ_L_23ContG_methods); @@ -1335,9 +1369,9 @@ void linesQ___init__ () { linesQ_L_24procG_methods.__bool__ = (B_bool (*) (linesQ_L_24proc))B_valueG_methods.__bool__; linesQ_L_24procG_methods.__str__ = (B_str (*) (linesQ_L_24proc))B_valueG_methods.__str__; linesQ_L_24procG_methods.__repr__ = (B_str (*) (linesQ_L_24proc))B_valueG_methods.__repr__; - linesQ_L_24procG_methods.__init__ = linesQ_L_24procD___init__; - linesQ_L_24procG_methods.__call__ = linesQ_L_24procD___call__; - linesQ_L_24procG_methods.__exec__ = linesQ_L_24procD___exec__; + linesQ_L_24procG_methods.__init__ = (B_NoneType (*) (linesQ_L_24proc, linesQ_main, int64_t))linesQ_L_24procD___init__; + linesQ_L_24procG_methods.__call__ = ($R (*) (linesQ_L_24proc, $Cont))linesQ_L_24procD___call__; + linesQ_L_24procG_methods.__exec__ = ($R (*) (linesQ_L_24proc, $Cont))linesQ_L_24procD___exec__; linesQ_L_24procG_methods.__serialize__ = linesQ_L_24procD___serialize__; linesQ_L_24procG_methods.__deserialize__ = linesQ_L_24procD___deserialize__; $register(&linesQ_L_24procG_methods); @@ -1348,9 +1382,9 @@ void linesQ___init__ () { linesQ_L_25procG_methods.__bool__ = (B_bool (*) (linesQ_L_25proc))B_valueG_methods.__bool__; linesQ_L_25procG_methods.__str__ = (B_str (*) (linesQ_L_25proc))B_valueG_methods.__str__; linesQ_L_25procG_methods.__repr__ = (B_str (*) (linesQ_L_25proc))B_valueG_methods.__repr__; - linesQ_L_25procG_methods.__init__ = linesQ_L_25procD___init__; - linesQ_L_25procG_methods.__call__ = linesQ_L_25procD___call__; - linesQ_L_25procG_methods.__exec__ = linesQ_L_25procD___exec__; + linesQ_L_25procG_methods.__init__ = (B_NoneType (*) (linesQ_L_25proc, linesQ_main))linesQ_L_25procD___init__; + linesQ_L_25procG_methods.__call__ = ($R (*) (linesQ_L_25proc, $Cont))linesQ_L_25procD___call__; + linesQ_L_25procG_methods.__exec__ = ($R (*) (linesQ_L_25proc, $Cont))linesQ_L_25procD___exec__; linesQ_L_25procG_methods.__serialize__ = linesQ_L_25procD___serialize__; linesQ_L_25procG_methods.__deserialize__ = linesQ_L_25procD___deserialize__; $register(&linesQ_L_25procG_methods); @@ -1361,8 +1395,8 @@ void linesQ___init__ () { linesQ_L_27ContG_methods.__bool__ = (B_bool (*) (linesQ_L_27Cont))B_valueG_methods.__bool__; linesQ_L_27ContG_methods.__str__ = (B_str (*) (linesQ_L_27Cont))B_valueG_methods.__str__; linesQ_L_27ContG_methods.__repr__ = (B_str (*) (linesQ_L_27Cont))B_valueG_methods.__repr__; - linesQ_L_27ContG_methods.__init__ = linesQ_L_27ContD___init__; - linesQ_L_27ContG_methods.__call__ = linesQ_L_27ContD___call__; + linesQ_L_27ContG_methods.__init__ = (B_NoneType (*) (linesQ_L_27Cont, $Cont, linesQ_Apa))linesQ_L_27ContD___init__; + linesQ_L_27ContG_methods.__call__ = ($R (*) (linesQ_L_27Cont, B_NoneType))linesQ_L_27ContD___call__; linesQ_L_27ContG_methods.__serialize__ = linesQ_L_27ContD___serialize__; linesQ_L_27ContG_methods.__deserialize__ = linesQ_L_27ContD___deserialize__; $register(&linesQ_L_27ContG_methods); @@ -1373,9 +1407,9 @@ void linesQ___init__ () { linesQ_L_28procG_methods.__bool__ = (B_bool (*) (linesQ_L_28proc))B_valueG_methods.__bool__; linesQ_L_28procG_methods.__str__ = (B_str (*) (linesQ_L_28proc))B_valueG_methods.__str__; linesQ_L_28procG_methods.__repr__ = (B_str (*) (linesQ_L_28proc))B_valueG_methods.__repr__; - linesQ_L_28procG_methods.__init__ = linesQ_L_28procD___init__; - linesQ_L_28procG_methods.__call__ = linesQ_L_28procD___call__; - linesQ_L_28procG_methods.__exec__ = linesQ_L_28procD___exec__; + linesQ_L_28procG_methods.__init__ = (B_NoneType (*) (linesQ_L_28proc, linesQ_Apa))linesQ_L_28procD___init__; + linesQ_L_28procG_methods.__call__ = ($R (*) (linesQ_L_28proc, $Cont))linesQ_L_28procD___call__; + linesQ_L_28procG_methods.__exec__ = ($R (*) (linesQ_L_28proc, $Cont))linesQ_L_28procD___exec__; linesQ_L_28procG_methods.__serialize__ = linesQ_L_28procD___serialize__; linesQ_L_28procG_methods.__deserialize__ = linesQ_L_28procD___deserialize__; $register(&linesQ_L_28procG_methods); @@ -1386,8 +1420,8 @@ void linesQ___init__ () { linesQ_L_30ContG_methods.__bool__ = (B_bool (*) (linesQ_L_30Cont))B_valueG_methods.__bool__; linesQ_L_30ContG_methods.__str__ = (B_str (*) (linesQ_L_30Cont))B_valueG_methods.__str__; linesQ_L_30ContG_methods.__repr__ = (B_str (*) (linesQ_L_30Cont))B_valueG_methods.__repr__; - linesQ_L_30ContG_methods.__init__ = linesQ_L_30ContD___init__; - linesQ_L_30ContG_methods.__call__ = linesQ_L_30ContD___call__; + linesQ_L_30ContG_methods.__init__ = (B_NoneType (*) (linesQ_L_30Cont, $Cont, linesQ_Bepa))linesQ_L_30ContD___init__; + linesQ_L_30ContG_methods.__call__ = ($R (*) (linesQ_L_30Cont, B_NoneType))linesQ_L_30ContD___call__; linesQ_L_30ContG_methods.__serialize__ = linesQ_L_30ContD___serialize__; linesQ_L_30ContG_methods.__deserialize__ = linesQ_L_30ContD___deserialize__; $register(&linesQ_L_30ContG_methods); @@ -1398,9 +1432,9 @@ void linesQ___init__ () { linesQ_L_31procG_methods.__bool__ = (B_bool (*) (linesQ_L_31proc))B_valueG_methods.__bool__; linesQ_L_31procG_methods.__str__ = (B_str (*) (linesQ_L_31proc))B_valueG_methods.__str__; linesQ_L_31procG_methods.__repr__ = (B_str (*) (linesQ_L_31proc))B_valueG_methods.__repr__; - linesQ_L_31procG_methods.__init__ = linesQ_L_31procD___init__; - linesQ_L_31procG_methods.__call__ = linesQ_L_31procD___call__; - linesQ_L_31procG_methods.__exec__ = linesQ_L_31procD___exec__; + linesQ_L_31procG_methods.__init__ = (B_NoneType (*) (linesQ_L_31proc, linesQ_Bepa))linesQ_L_31procD___init__; + linesQ_L_31procG_methods.__call__ = ($R (*) (linesQ_L_31proc, $Cont))linesQ_L_31procD___call__; + linesQ_L_31procG_methods.__exec__ = ($R (*) (linesQ_L_31proc, $Cont))linesQ_L_31procD___exec__; linesQ_L_31procG_methods.__serialize__ = linesQ_L_31procD___serialize__; linesQ_L_31procG_methods.__deserialize__ = linesQ_L_31procD___deserialize__; $register(&linesQ_L_31procG_methods); @@ -1411,8 +1445,8 @@ void linesQ___init__ () { linesQ_L_33ContG_methods.__bool__ = (B_bool (*) (linesQ_L_33Cont))B_valueG_methods.__bool__; linesQ_L_33ContG_methods.__str__ = (B_str (*) (linesQ_L_33Cont))B_valueG_methods.__str__; linesQ_L_33ContG_methods.__repr__ = (B_str (*) (linesQ_L_33Cont))B_valueG_methods.__repr__; - linesQ_L_33ContG_methods.__init__ = linesQ_L_33ContD___init__; - linesQ_L_33ContG_methods.__call__ = linesQ_L_33ContD___call__; + linesQ_L_33ContG_methods.__init__ = (B_NoneType (*) (linesQ_L_33Cont, $Cont, linesQ_main))linesQ_L_33ContD___init__; + linesQ_L_33ContG_methods.__call__ = ($R (*) (linesQ_L_33Cont, B_NoneType))linesQ_L_33ContD___call__; linesQ_L_33ContG_methods.__serialize__ = linesQ_L_33ContD___serialize__; linesQ_L_33ContG_methods.__deserialize__ = linesQ_L_33ContD___deserialize__; $register(&linesQ_L_33ContG_methods); @@ -1423,9 +1457,9 @@ void linesQ___init__ () { linesQ_L_34procG_methods.__bool__ = (B_bool (*) (linesQ_L_34proc))B_valueG_methods.__bool__; linesQ_L_34procG_methods.__str__ = (B_str (*) (linesQ_L_34proc))B_valueG_methods.__str__; linesQ_L_34procG_methods.__repr__ = (B_str (*) (linesQ_L_34proc))B_valueG_methods.__repr__; - linesQ_L_34procG_methods.__init__ = linesQ_L_34procD___init__; - linesQ_L_34procG_methods.__call__ = linesQ_L_34procD___call__; - linesQ_L_34procG_methods.__exec__ = linesQ_L_34procD___exec__; + linesQ_L_34procG_methods.__init__ = (B_NoneType (*) (linesQ_L_34proc, linesQ_main, B_Env))linesQ_L_34procD___init__; + linesQ_L_34procG_methods.__call__ = ($R (*) (linesQ_L_34proc, $Cont))linesQ_L_34procD___call__; + linesQ_L_34procG_methods.__exec__ = ($R (*) (linesQ_L_34proc, $Cont))linesQ_L_34procD___exec__; linesQ_L_34procG_methods.__serialize__ = linesQ_L_34procD___serialize__; linesQ_L_34procG_methods.__deserialize__ = linesQ_L_34procD___deserialize__; $register(&linesQ_L_34procG_methods); @@ -1438,13 +1472,13 @@ void linesQ___init__ () { linesQ_ApaG_methods.__repr__ = (B_str (*) (linesQ_Apa))$ActorG_methods.__repr__; linesQ_ApaG_methods.__resume__ = (B_NoneType (*) (linesQ_Apa))$ActorG_methods.__resume__; linesQ_ApaG_methods.__cleanup__ = (B_NoneType (*) (linesQ_Apa))$ActorG_methods.__cleanup__; - linesQ_ApaG_methods.__init__ = linesQ_ApaD___init__; - linesQ_ApaG_methods.setupG_local = linesQ_ApaD_setupG_local; - linesQ_ApaG_methods.computeG_local = linesQ_ApaD_computeG_local; - linesQ_ApaG_methods.noticeG_local = linesQ_ApaD_noticeG_local; - linesQ_ApaG_methods.setup = linesQ_ApaD_setup; - linesQ_ApaG_methods.compute = linesQ_ApaD_compute; - linesQ_ApaG_methods.notice = linesQ_ApaD_notice; + linesQ_ApaG_methods.__init__ = ($R (*) (linesQ_Apa, $Cont))linesQ_ApaD___init__; + linesQ_ApaG_methods.setupG_local = ($R (*) (linesQ_Apa, $Cont, $action))linesQ_ApaD_setupG_local; + linesQ_ApaG_methods.computeG_local = ($R (*) (linesQ_Apa, $Cont, $action))linesQ_ApaD_computeG_local; + linesQ_ApaG_methods.noticeG_local = ($R (*) (linesQ_Apa, $Cont, int64_t))linesQ_ApaD_noticeG_local; + linesQ_ApaG_methods.setup = (B_Msg (*) (linesQ_Apa, $action))linesQ_ApaD_setup; + linesQ_ApaG_methods.compute = (B_Msg (*) (linesQ_Apa, $action))linesQ_ApaD_compute; + linesQ_ApaG_methods.notice = (B_Msg (*) (linesQ_Apa, int64_t))linesQ_ApaD_notice; linesQ_ApaG_methods.__serialize__ = linesQ_ApaD___serialize__; linesQ_ApaG_methods.__deserialize__ = linesQ_ApaD___deserialize__; $register(&linesQ_ApaG_methods); @@ -1457,9 +1491,9 @@ void linesQ___init__ () { linesQ_BepaG_methods.__repr__ = (B_str (*) (linesQ_Bepa))$ActorG_methods.__repr__; linesQ_BepaG_methods.__resume__ = (B_NoneType (*) (linesQ_Bepa))$ActorG_methods.__resume__; linesQ_BepaG_methods.__cleanup__ = (B_NoneType (*) (linesQ_Bepa))$ActorG_methods.__cleanup__; - linesQ_BepaG_methods.__init__ = linesQ_BepaD___init__; - linesQ_BepaG_methods.callbackG_local = linesQ_BepaD_callbackG_local; - linesQ_BepaG_methods.callback = linesQ_BepaD_callback; + linesQ_BepaG_methods.__init__ = ($R (*) (linesQ_Bepa, $Cont))linesQ_BepaD___init__; + linesQ_BepaG_methods.callbackG_local = ($R (*) (linesQ_Bepa, $Cont, int64_t))linesQ_BepaD_callbackG_local; + linesQ_BepaG_methods.callback = (B_Msg (*) (linesQ_Bepa, int64_t))linesQ_BepaD_callback; linesQ_BepaG_methods.__serialize__ = linesQ_BepaD___serialize__; linesQ_BepaG_methods.__deserialize__ = linesQ_BepaD___deserialize__; $register(&linesQ_BepaG_methods); @@ -1472,11 +1506,11 @@ void linesQ___init__ () { linesQ_mainG_methods.__repr__ = (B_str (*) (linesQ_main))$ActorG_methods.__repr__; linesQ_mainG_methods.__resume__ = (B_NoneType (*) (linesQ_main))$ActorG_methods.__resume__; linesQ_mainG_methods.__cleanup__ = (B_NoneType (*) (linesQ_main))$ActorG_methods.__cleanup__; - linesQ_mainG_methods.__init__ = linesQ_mainD___init__; - linesQ_mainG_methods.myprocG_local = linesQ_mainD_myprocG_local; - linesQ_mainG_methods.nopG_local = linesQ_mainD_nopG_local; - linesQ_mainG_methods.myproc = linesQ_mainD_myproc; - linesQ_mainG_methods.nop = linesQ_mainD_nop; + linesQ_mainG_methods.__init__ = ($R (*) (linesQ_main, $Cont, B_Env))linesQ_mainD___init__; + linesQ_mainG_methods.myprocG_local = ($R (*) (linesQ_main, $Cont, int64_t))linesQ_mainD_myprocG_local; + linesQ_mainG_methods.nopG_local = ($R (*) (linesQ_main, $Cont))linesQ_mainD_nopG_local; + linesQ_mainG_methods.myproc = (B_Msg (*) (linesQ_main, int64_t))linesQ_mainD_myproc; + linesQ_mainG_methods.nop = (B_Msg (*) (linesQ_main))linesQ_mainD_nop; linesQ_mainG_methods.__serialize__ = linesQ_mainD___serialize__; linesQ_mainG_methods.__deserialize__ = linesQ_mainD___deserialize__; $register(&linesQ_mainG_methods); diff --git a/compiler/lib/test/9-codegen/lines.h b/compiler/lib/test/9-codegen/lines.h index 3edab9c6c..2c6d9d00d 100644 --- a/compiler/lib/test/9-codegen/lines.h +++ b/compiler/lib/test/9-codegen/lines.h @@ -88,8 +88,7 @@ struct linesQ_L_4action { struct linesQ_L_4actionG_class *$class; linesQ_Apa L_3obj; }; -$R linesQ_U_L_5C_3cont ($action, $Cont, int64_t); -$R linesQ_L_5C_3cont ($action, $Cont, B_int); +$R linesQ_L_5C_3cont ($action, $Cont, int64_t); struct linesQ_L_6ContG_class { char *$GCINFO; int $class_id; @@ -147,7 +146,7 @@ struct linesQ_L_9procG_class { char *$GCINFO; int $class_id; $SuperG_class $superclass; - B_NoneType (*__init__) (linesQ_L_9proc, linesQ_Apa, B_int); + B_NoneType (*__init__) (linesQ_L_9proc, linesQ_Apa, int64_t); void (*__serialize__) (linesQ_L_9proc, $Serial$state); linesQ_L_9proc (*__deserialize__) (linesQ_L_9proc, $Serial$state); B_bool (*__bool__) (linesQ_L_9proc); @@ -159,13 +158,13 @@ struct linesQ_L_9procG_class { struct linesQ_L_9proc { struct linesQ_L_9procG_class *$class; linesQ_Apa self; - B_int i; + int64_t i; }; struct linesQ_L_10procG_class { char *$GCINFO; int $class_id; $SuperG_class $superclass; - B_NoneType (*__init__) (linesQ_L_10proc, linesQ_Bepa, B_int); + B_NoneType (*__init__) (linesQ_L_10proc, linesQ_Bepa, int64_t); void (*__serialize__) (linesQ_L_10proc, $Serial$state); linesQ_L_10proc (*__deserialize__) (linesQ_L_10proc, $Serial$state); B_bool (*__bool__) (linesQ_L_10proc); @@ -177,7 +176,7 @@ struct linesQ_L_10procG_class { struct linesQ_L_10proc { struct linesQ_L_10procG_class *$class; linesQ_Bepa self; - B_int i; + int64_t i; }; struct linesQ_L_14actionG_class { char *$GCINFO; @@ -250,8 +249,7 @@ struct linesQ_L_20proc { struct linesQ_L_20procG_class *$class; linesQ_main self; }; -$R linesQ_U_1L_17C_9cont (linesQ_main, $Cont, int64_t); -$R linesQ_L_17C_9cont (linesQ_main, $Cont, B_int); +$R linesQ_L_17C_9cont (linesQ_main, $Cont, int64_t); struct linesQ_L_21ContG_class { char *$GCINFO; int $class_id; @@ -309,7 +307,7 @@ struct linesQ_L_24procG_class { char *$GCINFO; int $class_id; $SuperG_class $superclass; - B_NoneType (*__init__) (linesQ_L_24proc, linesQ_main, B_int); + B_NoneType (*__init__) (linesQ_L_24proc, linesQ_main, int64_t); void (*__serialize__) (linesQ_L_24proc, $Serial$state); linesQ_L_24proc (*__deserialize__) (linesQ_L_24proc, $Serial$state); B_bool (*__bool__) (linesQ_L_24proc); @@ -321,7 +319,7 @@ struct linesQ_L_24procG_class { struct linesQ_L_24proc { struct linesQ_L_24procG_class *$class; linesQ_main self; - B_int i; + int64_t i; }; struct linesQ_L_25procG_class { char *$GCINFO; @@ -460,10 +458,10 @@ struct linesQ_ApaG_class { B_NoneType (*__cleanup__) (linesQ_Apa); $R (*setupG_local) (linesQ_Apa, $Cont, $action); $R (*computeG_local) (linesQ_Apa, $Cont, $action); - $R (*noticeG_local) (linesQ_Apa, $Cont, B_int); + $R (*noticeG_local) (linesQ_Apa, $Cont, int64_t); B_Msg (*setup) (linesQ_Apa, $action); B_Msg (*compute) (linesQ_Apa, $action); - B_Msg (*notice) (linesQ_Apa, B_int); + B_Msg (*notice) (linesQ_Apa, int64_t); }; struct linesQ_Apa { struct linesQ_ApaG_class *$class; @@ -477,10 +475,10 @@ struct linesQ_Apa { $int64 $consume_hd; $Catcher $catcher; $long $globkey; - B_int apa; - B_int apb; - B_int y; - B_int z; + int64_t apa; + int64_t apb; + int64_t y; + int64_t z; }; struct linesQ_BepaG_class { char *$GCINFO; @@ -494,8 +492,8 @@ struct linesQ_BepaG_class { B_str (*__repr__) (linesQ_Bepa); B_NoneType (*__resume__) (linesQ_Bepa); B_NoneType (*__cleanup__) (linesQ_Bepa); - $R (*callbackG_local) (linesQ_Bepa, $Cont, B_int); - B_Msg (*callback) (linesQ_Bepa, B_int); + $R (*callbackG_local) (linesQ_Bepa, $Cont, int64_t); + B_Msg (*callback) (linesQ_Bepa, int64_t); }; struct linesQ_Bepa { struct linesQ_BepaG_class *$class; @@ -522,9 +520,9 @@ struct linesQ_mainG_class { B_str (*__repr__) (linesQ_main); B_NoneType (*__resume__) (linesQ_main); B_NoneType (*__cleanup__) (linesQ_main); - $R (*myprocG_local) (linesQ_main, $Cont, B_int); + $R (*myprocG_local) (linesQ_main, $Cont, int64_t); $R (*nopG_local) (linesQ_main, $Cont); - B_Msg (*myproc) (linesQ_main, B_int); + B_Msg (*myproc) (linesQ_main, int64_t); B_Msg (*nop) (linesQ_main); }; struct linesQ_main { @@ -543,9 +541,9 @@ struct linesQ_main { linesQ_Apa a; linesQ_Bepa b; B_Msg x; - B_int r; - B_int v; - B_int i; + int64_t r; + int64_t v; + int64_t i; }; $R linesQ_ApaG_newact ($Cont); $R linesQ_BepaG_newact ($Cont); @@ -561,9 +559,9 @@ linesQ_L_7proc linesQ_L_7procG_new(linesQ_Apa, $action); extern struct linesQ_L_8procG_class linesQ_L_8procG_methods; linesQ_L_8proc linesQ_L_8procG_new(linesQ_Apa, $action); extern struct linesQ_L_9procG_class linesQ_L_9procG_methods; -linesQ_L_9proc linesQ_L_9procG_new(linesQ_Apa, B_int); +linesQ_L_9proc linesQ_L_9procG_new(linesQ_Apa, int64_t); extern struct linesQ_L_10procG_class linesQ_L_10procG_methods; -linesQ_L_10proc linesQ_L_10procG_new(linesQ_Bepa, B_int); +linesQ_L_10proc linesQ_L_10procG_new(linesQ_Bepa, int64_t); extern struct linesQ_L_14actionG_class linesQ_L_14actionG_methods; linesQ_L_14action linesQ_L_14actionG_new(linesQ_Apa); extern struct linesQ_L_16actionG_class linesQ_L_16actionG_methods; @@ -579,7 +577,7 @@ linesQ_L_22Cont linesQ_L_22ContG_new(linesQ_main, $Cont); extern struct linesQ_L_23ContG_class linesQ_L_23ContG_methods; linesQ_L_23Cont linesQ_L_23ContG_new(linesQ_main, $Cont); extern struct linesQ_L_24procG_class linesQ_L_24procG_methods; -linesQ_L_24proc linesQ_L_24procG_new(linesQ_main, B_int); +linesQ_L_24proc linesQ_L_24procG_new(linesQ_main, int64_t); extern struct linesQ_L_25procG_class linesQ_L_25procG_methods; linesQ_L_25proc linesQ_L_25procG_new(linesQ_main); extern struct linesQ_L_27ContG_class linesQ_L_27ContG_methods; diff --git a/compiler/lib/test/9-codegen/lines.input b/compiler/lib/test/9-codegen/lines.input index 7c8d1b867..bd6250d4d 100644 --- a/compiler/lib/test/9-codegen/lines.input +++ b/compiler/lib/test/9-codegen/lines.input @@ -10,7 +10,7 @@ W_Apa_785: __builtin__.Eq[?__builtin__.int] = $EqOpt@[__builtin__.int](W_Apa_109 # recursive group: proc def L_1C_1cont (self : Apa, C_cont : $Cont[None], C_2res : None) -> $R: - self.z = (BOX __builtin__.int (UNBOX __builtin__.int 1)) + self.z = (UNBOX __builtin__.int 1) print@[(__builtin__.str,)](("\"Apa\"",), None, None, None, None) return $R_CONT@[None](C_cont, None) class L_2Cont ($Cont[None], __builtin__.value): @@ -34,20 +34,18 @@ class L_4action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin_ return None # recursive group: proc def __call__ (L_self : L_4action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_4action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_4action, G_1 : __builtin__.int) -> __builtin__.int: L_3obj: Apa = L_self.L_3obj return L_3obj.notice(G_1) # (recursive group) -proc def U_L_5C_3cont (cb : $action[(__builtin__.int,), __builtin__.int], C_cont : $Cont[__builtin__.int], U_2C_4res : __builtin__.int) -> $R: - U_3v: __builtin__.int = U_2C_4res +proc def L_5C_3cont (cb : $action[(__builtin__.int,), __builtin__.int], C_cont : $Cont[__builtin__.int], C_4res : UNBOXED __builtin__.int) -> $R: + v: UNBOXED __builtin__.int = (UNBOX __builtin__.int C_4res) m: __builtin__.Msg[__builtin__.int] = cb.__asyn__((BOX __builtin__.int (UNBOX __builtin__.int 2))) - U_4N_tmp: __builtin__.int = (U_3v * (UNBOX __builtin__.int 10)) - return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int U_4N_tmp)) -proc def L_5C_3cont (cb : $action[(__builtin__.int,), __builtin__.int], C_cont : $Cont[__builtin__.int], C_4res : __builtin__.int) -> $R: - return U_L_5C_3cont(cb, C_cont, (UNBOX __builtin__.int C_4res)) + N_tmp: UNBOXED __builtin__.int = ((UNBOX __builtin__.int v) * (UNBOX __builtin__.int 10)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int N_tmp)) class L_6Cont ($Cont[__builtin__.int], __builtin__.value): @property cb : $action[(__builtin__.int,), __builtin__.int] @@ -100,15 +98,15 @@ class L_9proc ($proc[(), __builtin__.int], __builtin__.value): self : Apa @property i : __builtin__.int - pure def __init__ (L_self : L_9proc, self : Apa, i : __builtin__.int) -> None: + pure def __init__ (L_self : L_9proc, self : Apa, i : UNBOXED __builtin__.int) -> None: L_self.self = self - L_self.i = i + L_self.i = (UNBOX __builtin__.int i) return None # recursive group: proc def __call__ (L_self : L_9proc, C_cont : $Cont[__builtin__.int]) -> $R: self: Apa = L_self.self - U_5i: __builtin__.int = (UNBOX __builtin__.int L_self.i) - return self.noticeG_local(C_cont, (BOX __builtin__.int U_5i)) + i: UNBOXED __builtin__.int = L_self.i + return self.noticeG_local(C_cont, (UNBOX __builtin__.int i)) proc def __exec__ (L_self : L_9proc, C_cont : $Cont[__builtin__.int]) -> $R: return L_self.__call__(C_cont) # (recursive group) @@ -117,15 +115,15 @@ class L_10proc ($proc[(), __builtin__.int], __builtin__.value): self : Bepa @property i : __builtin__.int - pure def __init__ (L_self : L_10proc, self : Bepa, i : __builtin__.int) -> None: + pure def __init__ (L_self : L_10proc, self : Bepa, i : UNBOXED __builtin__.int) -> None: L_self.self = self - L_self.i = i + L_self.i = (UNBOX __builtin__.int i) return None # recursive group: proc def __call__ (L_self : L_10proc, C_cont : $Cont[__builtin__.int]) -> $R: self: Bepa = L_self.self - U_6i: __builtin__.int = (UNBOX __builtin__.int L_self.i) - return self.callbackG_local(C_cont, (BOX __builtin__.int U_6i)) + i: UNBOXED __builtin__.int = L_self.i + return self.callbackG_local(C_cont, (UNBOX __builtin__.int i)) proc def __exec__ (L_self : L_10proc, C_cont : $Cont[__builtin__.int]) -> $R: return L_self.__call__(C_cont) # (recursive group) @@ -137,9 +135,9 @@ class L_14action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin return None # recursive group: proc def __call__ (L_self : L_14action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_14action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_14action, G_1 : __builtin__.int) -> __builtin__.int: L_13obj: Apa = L_self.L_13obj return L_13obj.notice(G_1) @@ -152,9 +150,9 @@ class L_16action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin return None # recursive group: proc def __call__ (L_self : L_16action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_16action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_16action, G_1 : __builtin__.int) -> __builtin__.int: L_15obj: Bepa = L_self.L_15obj return L_15obj.callback(G_1) @@ -167,9 +165,9 @@ class L_19action ($action[(__builtin__.int,), __builtin__.int], $proc[(__builtin return None # recursive group: proc def __call__ (L_self : L_19action, L_cont : $Cont[__builtin__.int], G_1 : __builtin__.int) -> $R: - return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__(G_1)) + return $AWAIT@[__builtin__.int](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) proc def __exec__ (L_self : L_19action, L_cont : $Cont[__builtin__.value], G_1 : __builtin__.int) -> $R: - return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__(G_1)) + return $R_CONT@[__builtin__.value](L_cont, L_self.__asyn__((BOX __builtin__.int G_1))) action def __asyn__ (L_self : L_19action, G_1 : __builtin__.int) -> __builtin__.int: L_18obj: main = L_self.L_18obj return L_18obj.myproc(G_1) @@ -183,43 +181,43 @@ class L_20proc ($proc[(), __builtin__.int], __builtin__.value): # recursive group: proc def __call__ (L_self : L_20proc, C_cont : $Cont[__builtin__.int]) -> $R: self: main = L_self.self - return self.myprocG_local(C_cont, (BOX __builtin__.int (UNBOX __builtin__.int 0))) + return self.myprocG_local(C_cont, (UNBOX __builtin__.int 0)) proc def __exec__ (L_self : L_20proc, C_cont : $Cont[__builtin__.int]) -> $R: return L_self.__call__(C_cont) # (recursive group) -proc def U_1L_17C_9cont (self : main, C_cont : $Cont[None], U_7C_10res : __builtin__.int) -> $R: - self.r = (BOX __builtin__.int U_7C_10res) - print@[(__builtin__.str, __builtin__.int)](("\"r =\"", self.r), None, None, None, None) +proc def L_17C_9cont (self : main, C_cont : $Cont[None], C_10res : UNBOXED __builtin__.int) -> $R: + self.r = (UNBOX __builtin__.int C_10res) + print@[(__builtin__.str, __builtin__.int)](("\"r =\"", (BOX __builtin__.int self.r)), None, None, None, None) (async self.a.compute)(L_19action(self)) print@[(__builtin__.str,)](("\"main\"",), None, None, None, None) - self.v = (BOX __builtin__.int (UNBOX __builtin__.int 0)) - if (BOX __builtin__.bool ((UNBOX __builtin__.int self.v) == (UNBOX __builtin__.int 0))): + self.v = (UNBOX __builtin__.int 0) + if (BOX __builtin__.bool (self.v == (UNBOX __builtin__.int 0))): print@[(__builtin__.str,)](("\"if branch\"",), None, None, None, None) - if (BOX __builtin__.bool ((UNBOX __builtin__.int self.v) < (UNBOX __builtin__.int 1))): + if (BOX __builtin__.bool (self.v < (UNBOX __builtin__.int 1))): print@[(__builtin__.str,)](("\"nested if\"",), None, None, None, None) - elif (BOX __builtin__.bool ((UNBOX __builtin__.int self.v) == (UNBOX __builtin__.int -1))): + elif (BOX __builtin__.bool (self.v == (UNBOX __builtin__.int -1))): print@[(__builtin__.str,)](("\"nested elif\"",), None, None, None, None) else: print@[(__builtin__.str,)](("\"nested else\"",), None, None, None, None) - elif (BOX __builtin__.bool ((UNBOX __builtin__.int self.v) == (UNBOX __builtin__.int 1))): + elif (BOX __builtin__.bool (self.v == (UNBOX __builtin__.int 1))): print@[(__builtin__.str,)](("\"outer elif\"",), None, None, None, None) else: print@[(__builtin__.str,)](("\"outer else\"",), None, None, None, None) - self.i = (BOX __builtin__.int (UNBOX __builtin__.int 0)) + self.i = (UNBOX __builtin__.int 0) while True: - if (BOX __builtin__.bool ((UNBOX __builtin__.int self.i) < (UNBOX __builtin__.int 3))): + if (BOX __builtin__.bool (self.i < (UNBOX __builtin__.int 3))): pass else: print@[(__builtin__.str,)](("\"while else\"",), None, None, None, None) break - self.i = (BOX __builtin__.int ((UNBOX __builtin__.int self.i) + (UNBOX __builtin__.int 1))) - if (BOX __builtin__.bool ((UNBOX __builtin__.int self.i) == (UNBOX __builtin__.int 1))): + self.i = (self.i + (UNBOX __builtin__.int 1)) + if (BOX __builtin__.bool (self.i == (UNBOX __builtin__.int 1))): print@[(__builtin__.str,)](("\"continue path\"",), None, None, None, None) continue - if (BOX __builtin__.bool ((UNBOX __builtin__.int self.i) == (UNBOX __builtin__.int 2))): + if (BOX __builtin__.bool (self.i == (UNBOX __builtin__.int 2))): print@[(__builtin__.str,)](("\"break path\"",), None, None, None, None) break - print@[(__builtin__.str, __builtin__.int)](("\"loop body\"", self.i), None, None, None, None) + print@[(__builtin__.str, __builtin__.int)](("\"loop body\"", (BOX __builtin__.int self.i)), None, None, None, None) N_3iter: __builtin__.Iterator[?__builtin__.int] = W_Apa_779.__iter__([(BOX __builtin__.int (UNBOX __builtin__.int 1)), (BOX __builtin__.int (UNBOX __builtin__.int 2)), (BOX __builtin__.int (UNBOX __builtin__.int 3))]) if $PUSH(): while True: @@ -240,7 +238,7 @@ proc def U_1L_17C_9cont (self : main, C_cont : $Cont[None], U_7C_10res : __built $RAISE(N_5x) if $PUSHF(): if $PUSH(): - if W_Apa_785.__eq__(self.v, (BOX __builtin__.int (UNBOX __builtin__.int 0))): + if W_Apa_785.__eq__((BOX __builtin__.int self.v), (BOX __builtin__.int (UNBOX __builtin__.int 0))): $RAISE(ValueError("\"boom\"")) print@[(__builtin__.str,)](("\"unreached\"",), None, None, None, None) $DROP() @@ -261,8 +259,6 @@ proc def U_1L_17C_9cont (self : main, C_cont : $Cont[None], U_7C_10res : __built $RAISE(N_7xx) $AFTER@[__builtin__.int]((BOX __builtin__.float (UNBOX __builtin__.float 1)), L_20proc(self)) return self.nopG_local(C_cont) -proc def L_17C_9cont (self : main, C_cont : $Cont[None], C_10res : __builtin__.int) -> $R: - return U_1L_17C_9cont(self, C_cont, (UNBOX __builtin__.int C_10res)) class L_21Cont ($Cont[__builtin__.int], __builtin__.value): @property self : main @@ -316,15 +312,15 @@ class L_24proc ($proc[(), __builtin__.int], __builtin__.value): self : main @property i : __builtin__.int - pure def __init__ (L_self : L_24proc, self : main, i : __builtin__.int) -> None: + pure def __init__ (L_self : L_24proc, self : main, i : UNBOXED __builtin__.int) -> None: L_self.self = self - L_self.i = i + L_self.i = (UNBOX __builtin__.int i) return None # recursive group: proc def __call__ (L_self : L_24proc, C_cont : $Cont[__builtin__.int]) -> $R: self: main = L_self.self - U_8i: __builtin__.int = (UNBOX __builtin__.int L_self.i) - return self.myprocG_local(C_cont, (BOX __builtin__.int U_8i)) + i: UNBOXED __builtin__.int = L_self.i + return self.myprocG_local(C_cont, (UNBOX __builtin__.int i)) proc def __exec__ (L_self : L_24proc, C_cont : $Cont[__builtin__.int]) -> $R: return L_self.__call__(C_cont) # (recursive group) @@ -439,9 +435,9 @@ class Apa ($Actor, __builtin__.value): @property z : __builtin__.int proc def __init__ (self : Apa, C_cont : $Cont[None]) -> $R: - self.apa = (BOX __builtin__.int (UNBOX __builtin__.int 2001)) - self.apb = (BOX __builtin__.int (UNBOX __builtin__.int 2002)) - self.y = (BOX __builtin__.int (UNBOX __builtin__.int 123)) + self.apa = (UNBOX __builtin__.int 2001) + self.apb = (UNBOX __builtin__.int 2002) + self.y = (UNBOX __builtin__.int 123) return self.setupG_local(L_2Cont(self, C_cont), L_4action(self)) proc def setupG_local (self : Apa, C_cont : $Cont[None], cb : $action[(__builtin__.int,), __builtin__.int]) -> $R: print@[(__builtin__.str,)](("\"setup\"",), None, None, None, None) @@ -450,26 +446,26 @@ class Apa ($Actor, __builtin__.value): proc def computeG_local (self : Apa, C_cont : $Cont[__builtin__.int], cb : $action[(__builtin__.int,), __builtin__.int]) -> $R: print@[(__builtin__.str,)](("\"compute\"",), None, None, None, None) return $AWAIT@[__builtin__.int](L_6Cont(cb, C_cont), cb.__asyn__((BOX __builtin__.int (UNBOX __builtin__.int 1)))) - proc def noticeG_local (self : Apa, C_cont : $Cont[__builtin__.int], i : __builtin__.int) -> $R: + proc def noticeG_local (self : Apa, C_cont : $Cont[__builtin__.int], i : UNBOXED __builtin__.int) -> $R: print@[(__builtin__.str,)](("\"notice\"",), None, None, None, None) - U_9N_1tmp: __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) - return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int U_9N_1tmp)) + N_1tmp: UNBOXED __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int N_1tmp)) action def setup (self : Apa, cb : $action[(__builtin__.int,), __builtin__.int]) -> None: return $ASYNC@[None](self, L_7proc(self, cb)) - action def compute (self : Apa, cb : $action[(__builtin__.int,), __builtin__.int]) -> __builtin__.int: + action def compute (self : Apa, cb : $action[(__builtin__.int,), __builtin__.int]) -> UNBOXED __builtin__.int: return $ASYNC@[__builtin__.int](self, L_8proc(self, cb)) - action def notice (self : Apa, i : __builtin__.int) -> __builtin__.int: - return $ASYNC@[__builtin__.int](self, L_9proc(self, i)) + action def notice (self : Apa, i : UNBOXED __builtin__.int) -> UNBOXED __builtin__.int: + return $ASYNC@[__builtin__.int](self, L_9proc(self, (UNBOX __builtin__.int i))) class Bepa ($Actor, __builtin__.value): proc def __init__ (self : Bepa, C_cont : $Cont[None]) -> $R: print@[(__builtin__.str,)](("\"Bepa\"",), None, None, None, None) return $R_CONT@[None](C_cont, None) - proc def callbackG_local (self : Bepa, C_cont : $Cont[__builtin__.int], i : __builtin__.int) -> $R: - print@[(__builtin__.str, __builtin__.int)](("\"callback\"", i), None, None, None, None) - U_10N_2tmp: __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) - return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int U_10N_2tmp)) - action def callback (self : Bepa, i : __builtin__.int) -> __builtin__.int: - return $ASYNC@[__builtin__.int](self, L_10proc(self, i)) + proc def callbackG_local (self : Bepa, C_cont : $Cont[__builtin__.int], i : UNBOXED __builtin__.int) -> $R: + print@[(__builtin__.str, __builtin__.int)](("\"callback\"", (BOX __builtin__.int i)), None, None, None, None) + N_2tmp: UNBOXED __builtin__.int = ((UNBOX __builtin__.int i) + (UNBOX __builtin__.int 1)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int N_2tmp)) + action def callback (self : Bepa, i : UNBOXED __builtin__.int) -> UNBOXED __builtin__.int: + return $ASYNC@[__builtin__.int](self, L_10proc(self, (UNBOX __builtin__.int i))) class main ($Actor, __builtin__.value): @property env : __builtin__.Env @@ -488,16 +484,16 @@ class main ($Actor, __builtin__.value): proc def __init__ (self : main, C_cont : $Cont[None], env : __builtin__.Env) -> $R: self.env = env return ApaG_newact(L_23Cont(self, C_cont)) - proc def myprocG_local (self : main, C_cont : $Cont[__builtin__.int], i : __builtin__.int) -> $R: - print@[(__builtin__.str, __builtin__.int)](("\"myproc\"", i), None, None, None, None) - if W_Apa_331.__eq__(i, (BOX __builtin__.int (UNBOX __builtin__.int 2))): - (async self.env.exit)((BOX __builtin__.int (UNBOX __builtin__.int 0))) - return $R_CONT@[__builtin__.int](C_cont, i) + proc def myprocG_local (self : main, C_cont : $Cont[__builtin__.int], i : UNBOXED __builtin__.int) -> $R: + print@[(__builtin__.str, __builtin__.int)](("\"myproc\"", (BOX __builtin__.int i)), None, None, None, None) + if W_Apa_331.__eq__((BOX __builtin__.int i), (BOX __builtin__.int (UNBOX __builtin__.int 2))): + (async self.env.exit)((UNBOX __builtin__.int 0)) + return $R_CONT@[__builtin__.int](C_cont, (BOX __builtin__.int i)) proc def nopG_local (self : main, C_cont : $Cont[None]) -> $R: pass return $R_CONT@[None](C_cont, None) - action def myproc (self : main, i : __builtin__.int) -> __builtin__.int: - return $ASYNC@[__builtin__.int](self, L_24proc(self, i)) + action def myproc (self : main, i : UNBOXED __builtin__.int) -> UNBOXED __builtin__.int: + return $ASYNC@[__builtin__.int](self, L_24proc(self, (UNBOX __builtin__.int i))) action def nop (self : main) -> None: return $ASYNC@[None](self, L_25proc(self)) proc def ApaG_newact (C_cont : $Cont[Apa]) -> $R: diff --git a/examples/sumto.act b/examples/sumto.act index 41694dd85..716eef17d 100644 --- a/examples/sumto.act +++ b/examples/sumto.act @@ -1,3 +1,5 @@ +import acton.rts + def sumto(n): res = 0 for i in range(n): @@ -10,4 +12,6 @@ actor main(env): else: target = int(123) print(sumto(int(target))) + print("gc time", acton.rts.get_gc_time(env.syscap).total, "millisecs") + print("Total heap memory allocated",acton.rts.get_gc_total_bytes(env.syscap),"bytes") env.exit(0) diff --git a/std/src/std/crypto/hash/md5.ext.c b/std/src/std/crypto/hash/md5.ext.c index 0096404d8..f58f20c10 100644 --- a/std/src/std/crypto/hash/md5.ext.c +++ b/std/src/std/crypto/hash/md5.ext.c @@ -5,15 +5,15 @@ void *zig_crypto_hash_md5_update(void *hasher, B_bytes data); void *zig_crypto_hash_md5_finalize(void *hasher, B_bytes output); B_NoneType stdQ_cryptoQ_hashQ_md5Q_HasherD__init (stdQ_cryptoQ_hashQ_md5Q_Hasher self) { - self->_hasher = zig_crypto_hash_md5_init(); + self->_hasher = (uint64_t)(uintptr_t)zig_crypto_hash_md5_init(); return B_None; } B_NoneType stdQ_cryptoQ_hashQ_md5Q_HasherD_update (stdQ_cryptoQ_hashQ_md5Q_Hasher self, B_bytes data) { - zig_crypto_hash_md5_update(self->_hasher, data); + zig_crypto_hash_md5_update((void *)(uintptr_t)self->_hasher, data); return B_None; } B_bytes stdQ_cryptoQ_hashQ_md5Q_HasherD_finalize (stdQ_cryptoQ_hashQ_md5Q_Hasher self) { B_bytes output = to$bytes("1234567890abcdef"); - zig_crypto_hash_md5_finalize(self->_hasher, output); + zig_crypto_hash_md5_finalize((void *)(uintptr_t)self->_hasher, output); return output; } diff --git a/std/src/std/hash/wyhash.ext.c b/std/src/std/hash/wyhash.ext.c index 19ddecd62..52816f9e1 100644 --- a/std/src/std/hash/wyhash.ext.c +++ b/std/src/std/hash/wyhash.ext.c @@ -5,23 +5,21 @@ void zig_hash_wyhash_update(void *hasher, B_bytes data); uint64_t zig_hash_wyhash_final(void *hasher); uint64_t zig_hash_wyhash_hash(uint64_t seed, B_bytes data); -B_NoneType stdQ_hashQ_wyhashQ_HasherD__init (stdQ_hashQ_wyhashQ_Hasher self, B_u64 seed) { - self->_hasher = zig_hash_wyhash_init(fromB_u64(seed)); +B_NoneType stdQ_hashQ_wyhashQ_HasherD__init (stdQ_hashQ_wyhashQ_Hasher self, uint64_t seed) { + self->_hasher = (uint64_t)(uintptr_t)zig_hash_wyhash_init(seed); return B_None; } B_NoneType stdQ_hashQ_wyhashQ_HasherD_update (stdQ_hashQ_wyhashQ_Hasher self, B_bytes data) { - zig_hash_wyhash_update(self->_hasher, data); + zig_hash_wyhash_update((void *)(uintptr_t)self->_hasher, data); return B_None; } -B_u64 stdQ_hashQ_wyhashQ_HasherD_finalize (stdQ_hashQ_wyhashQ_Hasher self) { - uint64_t h = zig_hash_wyhash_final(self->_hasher); - B_u64 result = toB_u64(h); - return result; +uint64_t stdQ_hashQ_wyhashQ_HasherD_finalize (stdQ_hashQ_wyhashQ_Hasher self) { + return zig_hash_wyhash_final((void *)(uintptr_t)self->_hasher); } -uint64_t stdQ_hashQ_wyhashQ_U_1hash (uint64_t seed, B_bytes data) { +uint64_t stdQ_hashQ_wyhashQ_hash (uint64_t seed, B_bytes data) { uint64_t result = zig_hash_wyhash_hash(seed, data); return result; } diff --git a/std/src/std/random.ext.c b/std/src/std/random.ext.c index b8bb2aead..5b7a6f7f1 100644 --- a/std/src/std/random.ext.c +++ b/std/src/std/random.ext.c @@ -39,6 +39,6 @@ long stdQ_randomQ_randlong (long min, long max) { return min + r%range; } -int64_t stdQ_randomQ_U_randint(int64_t min, int64_t max) { +int64_t stdQ_randomQ_randint(int64_t min, int64_t max) { return stdQ_randomQ_randlong(min,max); } diff --git a/std/src/std/re.ext.c b/std/src/std/re.ext.c index 506e6cd50..c74182859 100644 --- a/std/src/std/re.ext.c +++ b/std/src/std/re.ext.c @@ -23,7 +23,7 @@ void stdQ_reQ___ext_init__() { // TODO: use u64 instead of int for arg_start_pos -stdQ_reQ_Match stdQ_reQ_U__match (B_str arg_pattern, B_str arg_text, int64_t arg_start_pos) { +stdQ_reQ_Match stdQ_reQ__match (B_str arg_pattern, B_str arg_text, int64_t arg_start_pos) { B_Hashable hwit = (B_Hashable)B_HashableD_strG_witness; B_SequenceD_list swit = B_SequenceD_listG_witness; B_list groups = B_listG_new(NULL, NULL); @@ -152,5 +152,5 @@ stdQ_reQ_Match stdQ_reQ_U__match (B_str arg_pattern, B_str arg_text, int64_t arg pcre2_match_data_free(match_data); pcre2_code_free(re); - return stdQ_reQ_MatchG_new(arg_pattern, arg_text, toB_int(match_start), toB_int(match_end), groups, named_groups); + return stdQ_reQ_MatchG_new(arg_pattern, arg_text, match_start, match_end, groups, named_groups); } diff --git a/test/builtins_auto/int.act b/test/builtins_auto/int.act index ef3c6f6d7..89b3410f9 100644 --- a/test/builtins_auto/int.act +++ b/test/builtins_auto/int.act @@ -156,8 +156,8 @@ def test_i16(): raise ValueError('i16("0b1111") gives wrong result') if i16("1234",7) != 466: raise ValueError('i16("1234",7) gives wrong result') - #if i16(2**15-1) + 1 != -2**15: - # raise ValueError("i16 wraparound failed") + if i16(2**15-1) + 1 != -2**15: + raise ValueError("i16 wraparound failed") return True def test_i32(): @@ -265,8 +265,8 @@ def test_u16(): raise ValueError('u16("1234",7) gives wrong result') if int(x) != 0: raise ValueError("unexpected: int(x) != 0") - #if u16(2**16-1) + 1 != 0: - # raise ValueError("u16 wraparound failed") + if u16(2**16-1) + 1 != 0: + raise ValueError("u16 wraparound failed") return True def test_u32(): diff --git a/test/regression_auto/not_implemented.ext.c b/test/regression_auto/not_implemented.ext.c index 4a58838b1..108b9e975 100644 --- a/test/regression_auto/not_implemented.ext.c +++ b/test/regression_auto/not_implemented.ext.c @@ -2,7 +2,7 @@ void not_implementedQ___ext_init__() { // NOP } -int64_t not_implementedQ_U_1there (B_str x) { +int64_t not_implementedQ_there (B_str x) { return 0; } @@ -13,6 +13,6 @@ int64_t not_implementedQ_U_1there (B_str x) { return x; } -$R not_implementedQ_mainD_absentG_local (not_implementedQ_main __self__, $Cont c$cont, B_int i) { - return $R_CONT(c$cont, i); +$R not_implementedQ_mainD_absentG_local (not_implementedQ_main __self__, $Cont c$cont, int64_t i) { + return $R_CONT(c$cont, toB_int(i)); }