summary refs log tree commit diff stats
path: root/lib/std/private/bitops_utils.nim
blob: 0b9484416793e02b27eb979bd6214f4409cd879e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
template forwardImpl*(impl, arg) {.dirty.} =
  when sizeof(x) <= 4:
    when x is SomeSignedInt:
      impl(cast[uint32](x.int32))
    else:
      impl(x.uint32)
  else:
    when x is SomeSignedInt:
      impl(cast[uint64](x.int64))
    else:
      impl(x.uint64)

# this could also be implemented via:
# import std/typetraits
# template castToUnsigned*(x: SomeInteger): auto = cast[toUnsigned(typeof(x))](x)

template castToUnsigned*(x: int8): uint8 = cast[uint8](x)
template castToUnsigned*(x: int16): uint16 = cast[uint16](x)
template castToUnsigned*(x: int32): uint32 = cast[uint32](x)
template castToUnsigned*(x: int64): uint64 = cast[uint64](x)
template castToUnsigned*(x: int): uint = cast[uint](x)
template castToUnsigned*[T: SomeUnsignedInt](x: T): T = x
:(code) void check_for_misuse_of_real_hardware(const recipe_ordinal r) { const recipe& caller = get(Recipe, r); if (caller.name == "main") return; if (starts_with(caller.name, "scenario_")) return; trace(9991, "transform") << "--- check if recipe " << caller.name << " has any dependency-injection mistakes" << end(); for (int index = 0; index < SIZE(caller.steps); ++index) { const instruction& inst = caller.steps.at(index); if (is_primitive(inst.operation)) continue; for (int i = 0; i < SIZE(inst.ingredients); ++i) { const reagent& ing = inst.ingredients.at(i); if (!is_literal(ing) || ing.name != "0") continue; const recipe& callee = get(Recipe, inst.operation); if (!callee.has_header) continue; if (i >= SIZE(callee.ingredients)) continue; const reagent& expected_ing = callee.ingredients.at(i); for (int j = 0; j < SIZE(Real_hardware_types); ++j) { if (*Real_hardware_types.at(j) == *expected_ing.type) raise << maybe(caller.name) << "'" << to_original_string(inst) << "': only 'main' can pass 0 into a " << to_string(expected_ing.type) << '\n' << end(); } } } } :(scenarios transform) :(scenario warn_on_using_real_screen_directly_in_non_main_recipe) % Hide_errors = true; def foo [ print 0, 34 ] +error: foo: 'print 0, 34': only 'main' can pass 0 into a (address screen)