all repos — min @ deca3939ac32bee5104de66fb10ae50af3946252

A small but practical concatenative programming language.

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

  # Common stack operations
  
define("stack")

  .symbol("id") do (i: In):
    discard
  
  .symbol("pop") do (i: In):
    discard i.pop
  
  .symbol("dup") do (i: In):
    i.push i.peek
  
  .symbol("dip") do (i: In):
    var q: MinValue
    i.reqQuotation q
    let v = i.pop
    i.unquote("<dip>", q)
    i.push v
  
  .symbol("swap") do (i: In):
    let a = i.pop
    let b = i.pop
    i.push a
    i.push b
  
  .symbol("sip") do (i: In):
    var a, b: MinValue 
    i.reqTwoQuotations a, b
    i.push b
    i.unquote("<sip>", a)
    i.push b

  .finalize()