diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-07-23 22:23:03 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-07-23 22:42:31 -0700 |
| commit | 7b8cb881df7e034a8626caabf355055ee81a0fef (patch) | |
| tree | e56858cd22ccf90217a49c51c7d8ff7df49ab0f3 /src/Air.zig | |
| parent | f9798108f8434f277de6089502446f2544ee98b3 (diff) | |
| download | zig-7b8cb881df7e034a8626caabf355055ee81a0fef.tar.gz zig-7b8cb881df7e034a8626caabf355055ee81a0fef.zip | |
stage2: improvements towards `zig test`
* There is now a main_pkg in addition to root_pkg. They are usually the
same. When using `zig test`, main_pkg is the user's source file and
root_pkg has the test runner.
* scanDecl no longer looks for test decls outside the package being
tested. honoring `--test-filter` is still TODO.
* test runner main function has a void return value rather than
`anyerror!void`
* Sema is improved to generate better AIR for for loops on slices.
* Sema: fix incorrect capacity calculation in zirBoolBr
* Sema: add compile errors for trying to use slice fields as an lvalue.
* Sema: fix type coercion for error unions
* Sema: fix analyzeVarRef generating garbage AIR
* C codegen: fix renderValue for error unions with 0 bit payload
* C codegen: implement function pointer calls
* CLI: fix usage text
Adds 4 new AIR instructions:
* slice_len, slice_ptr: to get the ptr and len fields of a slice.
* slice_elem_val, ptr_slice_elem_val: to get the element value of
a slice, and a pointer to a slice.
AstGen gains a new functionality:
* One of the unused flags of struct decls is now used to indicate
structs that are known to have non-zero size based on the AST alone.
Diffstat (limited to 'src/Air.zig')
| -rw-r--r-- | src/Air.zig | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/Air.zig b/src/Air.zig index 718123818b..9451f8b763 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -247,6 +247,21 @@ pub const Inst = struct { /// Given a pointer to a struct and a field index, returns a pointer to the field. /// Uses the `ty_pl` field, payload is `StructField`. struct_field_ptr, + /// Given a slice value, return the length. + /// Result type is always usize. + /// Uses the `ty_op` field. + slice_len, + /// Given a slice value, return the pointer. + /// Uses the `ty_op` field. + slice_ptr, + /// Given a slice value, and element index, return the element value at that index. + /// Result type is the element type of the slice operand. + /// Uses the `bin_op` field. + slice_elem_val, + /// Given a pointer to a slice, and element index, return the element value at that index. + /// Result type is the element type of the slice operand (2 element type operations). + /// Uses the `bin_op` field. + ptr_slice_elem_val, pub fn fromCmpOp(op: std.math.CompareOperator) Tag { return switch (op) { @@ -450,6 +465,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type { .unwrap_errunion_err_ptr, .wrap_errunion_payload, .wrap_errunion_err, + .slice_ptr, => return air.getRefType(datas[inst].ty_op.ty), .loop, @@ -465,12 +481,24 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type { .store, => return Type.initTag(.void), - .ptrtoint => return Type.initTag(.usize), + .ptrtoint, + .slice_len, + => return Type.initTag(.usize), .call => { const callee_ty = air.typeOf(datas[inst].pl_op.operand); return callee_ty.fnReturnType(); }, + + .slice_elem_val => { + const slice_ty = air.typeOf(datas[inst].bin_op.lhs); + return slice_ty.elemType(); + }, + .ptr_slice_elem_val => { + const ptr_slice_ty = air.typeOf(datas[inst].bin_op.lhs); + const slice_ty = ptr_slice_ty.elemType(); + return slice_ty.elemType(); + }, } } |
