Skip to content

Commit

Permalink
flow update
Browse files Browse the repository at this point in the history
  • Loading branch information
ctxcode committed Aug 30, 2023
1 parent b8175dd commit 41622f2
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 17 deletions.
6 changes: 4 additions & 2 deletions lib/src/http/client-request.ki
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ class ClientRequest {
}
}

let headers = @swap res.headers with Map[String]{};

return ClientResponse {
status: res.status,
headers: res.headers,
body: res.body,
headers: @swap res.headers with Map[String]{},
body: @swap res.body with "",
};
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/http/server.ki
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ class Server {

let req = Request{
http_con: &http_con,
headers: res.headers,
method: res.method,
path: res.path,
body: res.body,
headers: @swap res.headers with Map[String]{},
method: @swap res.method with "",
body: @swap res.body with "",
path: @swap res.path with "",
};
let resp = handler(req);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/net/socket-tcp.ki
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SocketTCP async {
- addrinfo: sys.cstruct_addrinfo;
- connection: ?Connection = null;

static fn new(host: String, port: u16, blocking: bool = true) SocketTCP !os_socket_create !invalid_host {
static fn new(host: *String, port: u16, blocking: bool = true) SocketTCP !os_socket_create !invalid_host {

#if OS == win
os:WSA_init();
Expand Down Expand Up @@ -63,7 +63,7 @@ class SocketTCP async {
#end

return SocketTCP{
host: host,
host: host + "",
port: port,
fd: fd,
blocking: blocking,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/net/socket.ki
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ header "sys" as sys;
use io;

class Socket {
static fn new_tcp(host: String, port: u16, blocking: bool = true) SocketTCP !init_error {
static fn new_tcp(host: *String, port: u16, blocking: bool = true) SocketTCP !init_error {
return SocketTCP.new(host, port, blocking) !! throw init_error;;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/type/string.ki
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use mem;
use os;

class String type:ptr rc {
class String type:ptr track rc {

/////////////////////
// Core
Expand Down
3 changes: 2 additions & 1 deletion src/build/stage-1-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void stage_1_class(Fc *fc, bool is_struct) {
class->scope = scope_init(fc->alc, sct_class, fc->scope, false);
class->is_struct = is_struct;
class->is_rc = !is_struct;
class->track_ownership = false;
class->track_ownership = !is_struct;
class->def_chunk = def_chunk;

array_push(fc->classes, class);
Expand Down Expand Up @@ -265,6 +265,7 @@ void stage_1_class(Fc *fc, bool is_struct) {
while (strcmp(token, "{") != 0) {
if (strcmp(token, "type") == 0) {
class->is_rc = false;
class->track_ownership = false;
tok_expect(fc, ":", true, false);
tok(fc, token, true, false);
if (strcmp(token, "ptr") == 0) {
Expand Down
11 changes: 7 additions & 4 deletions src/build/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,14 @@ void type_check(Fc *fc, Type *t1, Type *t2) {
}
}

bool type_tracks_usage(Type *type) {
//
return type_tracks_ownership(type) || type_is_rc(type);
}

bool type_is_rc(Type *type) {
Class *class = type->class;
if (!class)
return false;
return class->is_rc;
//
return type->class && type->class->is_rc;
}

bool type_tracks_ownership(Type *type) {
Expand Down
4 changes: 2 additions & 2 deletions src/build/value-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ Value *vgen_class_pa(Allocator *alc, Scope *scope, Value *on, ClassProp *prop) {
if (scope && type_tracks_ownership(prop_type)) {

item->cache_llvm_val = true;
if (prop_type->class && prop_type->class->is_circular)
prop_type->shared_ref = true;
// if (prop_type->class && prop_type->class->is_circular)
prop_type->shared_ref = true;

Value *from = vgen_ir_from(alc, res);
item->deref_token = tgen_ref_change_exec(alc, scope, from, -1);
Expand Down
3 changes: 3 additions & 0 deletions src/build/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ Value *read_value(Fc *fc, Allocator *alc, Scope *scope, bool sameline, int prio,
sprintf(fc->sbuf, "The first argument in '@swap' must be assignable. e.g. a variable");
fc_error(fc);
}
value_disable_upref_deref(var);

if (var->type == v_decl) {
Decl *decl = var->item;
if (!decl->is_mut) {
Expand Down Expand Up @@ -1754,6 +1756,7 @@ void value_disable_upref_deref(Value *val) {
exec = pa->upref_token->item;
exec->enable = false;
}
val->rett = pa->prop->type;
}
if (val->type == v_array_item) {
VArrayItem *ai = val->item;
Expand Down
1 change: 1 addition & 0 deletions src/headers/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ char *type_to_str(Type *t, char *res, bool simple);
void type_check(Fc *fc, Type *t1, Type *t2);
Type *type_clone(Allocator *alc, Type *type);
bool type_tracks_ownership(Type *type);
bool type_tracks_usage(Type *type);
bool type_is_rc(Type *type);
bool type_allowed_async(Type *type, bool recursive);
Type *type_get_inline(Allocator *alc, Type *type);
Expand Down

0 comments on commit 41622f2

Please sign in to comment.