Project

nudge

0.0
No commit activity in last 3 years
No release in over 3 years
Provides a Ruby library & CLI implementing a flexible Nudge Language interpreter, plus a set of generators for adding domain-specific instructions and types.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme
# encoding: UTF-8
require File.expand_path("nudge", File.dirname(__FILE__))

script = NudgeWriter.new.random
# script = "block { ref x block { ref x do int_multiply ref x value «int» do int_add value «int» do int_multiply } do int_multiply }
# «int»6
# «int»22"
exe = NudgeExecutable.new(script)

exe.bind(:x1 => Value.new(:int, 100), :x2 => Value.new(:int, 200))
exe.bind(:x => Value.new(:int, 100))
#exe.run

puts script
puts "-----------"

3000.times do
  break unless top = exe.stacks[:exec].last
  
  case top
    when BlockPoint, RefPoint
    when ValuePoint
      puts "«#{top.instance_variable_get(:@value_type)}» #{top.instance_variable_get(:@value).slice(0..30)}"
    when DoPoint
      puts "do #{top.instance_variable_get(:@instruction_name)}"
  end
  
  exe.step
  
  unless top.is_a?(BlockPoint) || top.is_a?(RefPoint)
    puts
    puts "  bool:  " + exe.stacks[:bool].inspect
    puts "  code:  " + exe.stacks[:code].length.to_s
    puts "  error: " + exe.stacks[:error].length.to_s
    puts "  float: " + exe.stacks[:float].inspect
    puts "  int:   " + exe.stacks[:int].inspect
    puts "  name:  " + exe.stacks[:name].inspect
    puts "  ppn:   " + exe.stacks[:proportion].inspect
    puts "-----------"
  end
end