all repos — min @ 53e02d84748acebec51341296829a592bdc00cd5

A small but practical concatenative programming language.

minpkg/lib/min_binary.nim

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
import 
  ../core/parser, 
  ../core/value, 
  ../core/interpreter, 
  ../core/utils

proc binary_module*(i: In)=

  let def = i.define()

  def.symbol("bitand") do (i: In):
    let vals = i.expect("int","int")
    let b = vals[0]
    let a = vals[1]
    
    i.push newVal(a.intVal and b.intVal)

  def.symbol("bitnot") do (i: In):
    let vals = i.expect("int")
    let a = vals[0]
    
    i.push newVal(not a.intVal)

  def.symbol("bitor") do (i: In):
    let vals = i.expect("int","int")
    let b = vals[0]
    let a = vals[1]
    
    i.push newVal(a.intVal or b.intVal)

  def.symbol("bitxor") do (i: In):
    let vals = i.expect("int","int")
    let b = vals[0]
    let a = vals[1]
    
    i.push newVal(a.intVal xor b.intVal)

  def.symbol("shl") do (i: In):
    let vals = i.expect("int","int")
    let b = vals[0]
    let a = vals[1]
    
    i.push newVal(a.intVal shl b.intVal)

  def.symbol("shr") do (i: In):
    let vals = i.expect("int","int")
    let b = vals[0]
    let a = vals[1]
    
    i.push newVal(a.intVal shr b.intVal)

  def.finalize("binary")