Skip to content

Commit

Permalink
(fix) fix compiler errors
Browse files Browse the repository at this point in the history
Generic schenanigans with function overloading equals to disasters. Got
it.
  • Loading branch information
xTrayambak committed Sep 7, 2024
1 parent 9b7bf5d commit 9a56f8d
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/mirage/ir/generator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,34 @@ proc addOp*(gen: IRGenerator, operation: IROperation): uint {.inline.} =
raise newException(FieldDefect, "Cannot find any clause with name: " & gen.currModule)

proc loadInt*[V: SomeInteger](
gen: IRGenerator, position: uint, value: V | MAtom
gen: IRGenerator, position: uint, value: V
): uint {.inline, discardable.} =
## Load an integer into the memory space.
## This is an overloadable function and can be provided:
## * any kind of integer type (`int`, `int8`, `int16`, `int32`, `int64` or their unsigned counterparts)
## * a `MAtom` that contains an integer.
## This is an overloadable function and can be provided any kind of integer type (`int`, `int8`, `int16`, `int32`, `int64` or their unsigned counterparts)
##
## **See also:**
## * `loadFloat proc<#loadFloat, IRGenerator, uint, MAtom`
## * `loadInt proc<#loadInt, IRGenerator, uint, MAtom>`
## * `loadFloat proc<#loadFloat, IRGenerator, uint, MAtom>`

when value is V:
gen.addOp(
IROperation(opCode: LoadInt, arguments: @[uinteger position, integer value])
)
else:
if value.kind != Integer:
raise
newException(ValueError, "Attempt to load " & $value.kind & " as an integer.")
gen.addOp(
IROperation(opCode: LoadInt, arguments: @[uinteger position, integer value])
)

proc loadInt*(
gen: IRGenerator, position: uint, value: MAtom
): uint {.inline, discardable.} =
## Load an integer into the memory space.
## This is an overloadable function and can be provided a `MAtom` that contains an integer.
##
## **See also:**
## * `loadInt proc<#loadInt, IRGenerator, uint, SomeInteger>`
## * `loadFloat proc<#loadFloat, IRGenerator, uint, MAtom>`

if value.kind != Integer:
raise
newException(ValueError, "Attempt to load " & $value.kind & " as an integer.")

gen.addOp(IROperation(opCode: LoadInt, arguments: @[uinteger position, value]))
gen.addOp(IROperation(opCode: LoadInt, arguments: @[uinteger position, value]))

proc loadList*(gen: IRGenerator, position: uint): uint {.inline, discardable.} =
## Load a list (vector, sequence, whatever you like to call it) into memory.
Expand Down

0 comments on commit 9a56f8d

Please sign in to comment.