Skip to content

Commit

Permalink
simple async function call working
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Jul 21, 2019
1 parent 54e716a commit 72e9836
Show file tree
Hide file tree
Showing 7 changed files with 448 additions and 66 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ set(ZIG_MAIN_SRC "${CMAKE_SOURCE_DIR}/src/main.cpp")
set(ZIG0_SHIM_SRC "${CMAKE_SOURCE_DIR}/src/userland.cpp")

set(ZIG_SOURCES
"${CMAKE_SOURCE_DIR}/src/glibc.cpp"
"${CMAKE_SOURCE_DIR}/src/analyze.cpp"
"${CMAKE_SOURCE_DIR}/src/ast_render.cpp"
"${CMAKE_SOURCE_DIR}/src/bigfloat.cpp"
Expand All @@ -438,6 +437,7 @@ set(ZIG_SOURCES
"${CMAKE_SOURCE_DIR}/src/compiler.cpp"
"${CMAKE_SOURCE_DIR}/src/errmsg.cpp"
"${CMAKE_SOURCE_DIR}/src/error.cpp"
"${CMAKE_SOURCE_DIR}/src/glibc.cpp"
"${CMAKE_SOURCE_DIR}/src/ir.cpp"
"${CMAKE_SOURCE_DIR}/src/ir_print.cpp"
"${CMAKE_SOURCE_DIR}/src/libc_installation.cpp"
Expand Down
30 changes: 30 additions & 0 deletions src/all_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,7 @@ enum ZigTypeId {
ZigTypeIdBoundFn,
ZigTypeIdArgTuple,
ZigTypeIdOpaque,
ZigTypeIdCoroFrame,
ZigTypeIdVector,
ZigTypeIdEnumLiteral,
};
Expand All @@ -1265,6 +1266,11 @@ struct ZigTypeOpaque {
Buf *bare_name;
};

struct ZigTypeCoroFrame {
ZigFn *fn;
ZigType *locals_struct;
};

struct ZigType {
ZigTypeId id;
Buf name;
Expand All @@ -1290,6 +1296,7 @@ struct ZigType {
ZigTypeBoundFn bound_fn;
ZigTypeVector vector;
ZigTypeOpaque opaque;
ZigTypeCoroFrame frame;
} data;

// use these fields to make sure we don't duplicate type table entries for the same type
Expand Down Expand Up @@ -1340,6 +1347,7 @@ struct ZigFn {
ScopeBlock *def_scope; // parent is child_scope
Buf symbol_name;
ZigType *type_entry; // function type
ZigType *frame_type; // coro frame type
// in the case of normal functions this is the implicit return type
// in the case of async functions this is the implicit return type according to the
// zig source code, not according to zig ir
Expand All @@ -1356,6 +1364,7 @@ struct ZigFn {

ZigList<IrInstructionAllocaGen *> alloca_gen_list;
ZigList<ZigVar *> variable_list;
ZigList<IrBasicBlock *> resume_blocks;

Buf *section_name;
AstNode *set_alignstack_node;
Expand All @@ -1365,6 +1374,7 @@ struct ZigFn {
ZigList<GlobalExport> export_list;

LLVMValueRef valgrind_client_request_array;
LLVMBasicBlockRef preamble_llvm_block;

FnInline fn_inline;
FnAnalState anal_state;
Expand Down Expand Up @@ -1512,6 +1522,7 @@ enum PanicMsgId {
PanicMsgIdBadEnumValue,
PanicMsgIdFloatToInt,
PanicMsgIdPtrCastNull,
PanicMsgIdBadResume,

PanicMsgIdCount,
};
Expand Down Expand Up @@ -1755,6 +1766,7 @@ struct CodeGen {
ZigType *entry_global_error_set;
ZigType *entry_arg_tuple;
ZigType *entry_enum_literal;
ZigType *entry_frame_header;
} builtin_types;
ZigType *align_amt_type;
ZigType *stack_trace_type;
Expand Down Expand Up @@ -2119,6 +2131,8 @@ struct IrBasicBlock {
size_t ref_count;
// index into the basic block list
size_t index;
// for coroutines, the resume_index which corresponds to this block
size_t resume_index;
LLVMBasicBlockRef llvm_block;
LLVMBasicBlockRef llvm_exit_block;
// The instruction that referenced this basic block and caused us to
Expand Down Expand Up @@ -2297,6 +2311,8 @@ enum IrInstructionId {
IrInstructionIdEndExpr,
IrInstructionIdPtrOfArrayToSlice,
IrInstructionIdUnionInitNamedField,
IrInstructionIdSuspendBegin,
IrInstructionIdSuspendBr,
};

struct IrInstruction {
Expand Down Expand Up @@ -3511,6 +3527,18 @@ struct IrInstructionPtrOfArrayToSlice {
IrInstruction *result_loc;
};

struct IrInstructionSuspendBegin {
IrInstruction base;

IrBasicBlock *resume_block;
};

struct IrInstructionSuspendBr {
IrInstruction base;

IrBasicBlock *resume_block;
};

enum ResultLocId {
ResultLocIdInvalid,
ResultLocIdNone,
Expand Down Expand Up @@ -3593,6 +3621,8 @@ static const size_t maybe_null_index = 1;
static const size_t err_union_err_index = 0;
static const size_t err_union_payload_index = 1;

static const size_t coro_resume_index_index = 0;

// TODO call graph analysis to find out what this number needs to be for every function
// MUST BE A POWER OF TWO.
static const size_t stack_trace_ptr_count = 32;
Expand Down
Loading

0 comments on commit 72e9836

Please sign in to comment.