File tree Expand file tree Collapse file tree 7 files changed +15
-5
lines changed
Expand file tree Collapse file tree 7 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -497,8 +497,13 @@ def emitNumLit (t : IRType) (v : Nat) : M Unit := do
497497 else
498498 if v < UInt32.size then
499499 emit v
500+ else if t == .usize then
501+ emit "((size_t)"
502+ emit v
503+ emit "ULL)"
500504 else
501- emit v; emit "ULL"
505+ emit v
506+ emit "ULL"
502507
503508def emitLit (z : VarId) (t : IRType) (v : LitVal) : M Unit := do
504509 emitLhs z;
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ def lowerLitValue (v : LCNF.LitValue) : LitVal :=
7070 | .uint8 v => .num (UInt8.toNat v)
7171 | .uint16 v => .num (UInt16.toNat v)
7272 | .uint32 v => .num (UInt32.toNat v)
73- | .uint64 v => .num (UInt64.toNat v)
73+ | .uint64 v | .usize v => .num (UInt64.toNat v)
7474
7575-- TODO: This should be cached.
7676def lowerEnumToScalarType (name : Name) : M (Option IRType) := do
Original file line number Diff line number Diff line change @@ -40,7 +40,9 @@ inductive LitValue where
4040 | uint16 (val : UInt16)
4141 | uint32 (val : UInt32)
4242 | uint64 (val : UInt64)
43- -- TODO: add constructors for `Int`, `Float`, `USize` ...
43+ -- USize has a maximum size of 64 bits
44+ | usize (val : UInt64)
45+ -- TODO: add constructors for `Int`, `Float`, ...
4446 deriving Inhabited, BEq, Hashable
4547
4648def LitValue.toExpr : LitValue → Expr
@@ -50,6 +52,7 @@ def LitValue.toExpr : LitValue → Expr
5052 | .uint16 v => .app (.const ``UInt16.ofNat []) (.lit (.natVal (UInt16.toNat v)))
5153 | .uint32 v => .app (.const ``UInt32.ofNat []) (.lit (.natVal (UInt32.toNat v)))
5254 | .uint64 v => .app (.const ``UInt64.ofNat []) (.lit (.natVal (UInt64.toNat v)))
55+ | .usize v => .app (.const ``USize.ofNat []) (.lit (.natVal (UInt64.toNat v)))
5356
5457inductive Arg where
5558 | erased
Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ def ofLCNFLit : LCNF.LitValue → Value
177177| .uint8 v => ofNat (UInt8.toNat v)
178178| .uint16 v => ofNat (UInt16.toNat v)
179179| .uint32 v => ofNat (UInt32.toNat v)
180- | .uint64 v => ofNat (UInt64.toNat v)
180+ | .uint64 v | .usize v => ofNat (UInt64.toNat v)
181181
182182partial def proj : Value → Nat → Value
183183| .ctor _ vs , i => vs.getD i bot
Original file line number Diff line number Diff line change @@ -109,6 +109,7 @@ def inferLitValueType (value : LitValue) : Expr :=
109109 | .uint16 .. => mkConst ``UInt16
110110 | .uint32 .. => mkConst ``UInt32
111111 | .uint64 .. => mkConst ``UInt64
112+ | .usize .. => mkConst ``USize
112113
113114mutual
114115 partial def inferArgType (arg : Arg) : InferTypeM Expr :=
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ def ppArgs (args : Array Arg) : M Format := do
5858
5959def ppLitValue (lit : LitValue) : M Format := do
6060 match lit with
61- | .nat v | .uint8 v | .uint16 v | .uint32 v | .uint64 v => return format v
61+ | .nat v | .uint8 v | .uint16 v | .uint32 v | .uint64 v | .usize v => return format v
6262 | .str v => return format (repr v)
6363
6464def ppLetValue (e : LetValue) : M Format := do
Original file line number Diff line number Diff line change @@ -368,6 +368,7 @@ def conversionFolders : List (Name × Folder) := [
368368 (``UInt16.ofNat, Folder.ofNat (fun v => .uint16 (UInt16.ofNat v))),
369369 (``UInt32.ofNat, Folder.ofNat (fun v => .uint32 (UInt32.ofNat v))),
370370 (``UInt64.ofNat, Folder.ofNat (fun v => .uint64 (UInt64.ofNat v))),
371+ (``USize.ofNat, Folder.ofNat (fun v => .usize (UInt64.ofNat v))),
371372]
372373
373374/--
You can’t perform that action at this time.
0 commit comments