all repos — min @ f7c8ccacbc3c0a2ff5d0ca7bde239e881157ec5a

A small but practical concatenative programming language.

lib/stack.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
import tables
import 
  ../core/types,
  ../core/parser, 
  ../core/interpreter, 
  ../core/utils

# Common stack operations

minsym "id", i:
  discard

minsym "pop", i:
  discard i.pop

minsym "dup", i:
  i.push i.peek

minsym "dip", i:
  let q = i.pop
  if not q.isQuotation:
    i.error errNoQuotation
  let v = i.pop
  for item in q.qVal:
    i.push item
  i.push v

minsym "swap", i:
  let a = i.pop
  let b = i.pop
  i.push a
  i.push b

minsym "sip", i:
  let a = i.pop
  let b = i.pop
  if a.isQuotation and b.isQuotation:
    i.push b
    i.push a.qVal
    i.push b
  else:
    i.error(errIncorrect, "Two quotations are required on the stack")