[display] (wip) first words

Signed-off-by: Gwenhael Le Moine <gwenhael.le.moine@gmail.com>
This commit is contained in:
Gwenhael Le Moine 2022-05-31 16:43:31 +02:00
parent 48be6a643e
commit 010460a230
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
4 changed files with 54 additions and 4 deletions

View file

@ -14,6 +14,7 @@ class Rpl < Interpreter
end
prepend RplLang::Words::Branch
prepend RplLang::Words::Display
prepend RplLang::Words::FileSystem
prepend RplLang::Words::General
prepend RplLang::Words::Logarithm

View file

@ -7,6 +7,24 @@ require 'bigdecimal/util'
require 'rpl/dictionary'
require 'rpl/types'
class BitArray
def initialize
@mask = 0
end
def []=(position, value)
if value.zero?
@mask ^= (1 << position)
else
@mask |= (1 << position)
end
end
def [](position)
@mask[position]
end
end
class Interpreter
include BigMath
include Types
@ -23,7 +41,12 @@ class Interpreter
@dictionary = dictionary
@stack = stack
@display = Array.new( 131, Array.new( 80 ) )
initialize_display
end
def initialize_display
@display = BitArray.new
end
def run( input )
@ -37,10 +60,8 @@ class Interpreter
@stack << elt
else
command = @dictionary.lookup( elt.value )
if command.nil?
# if there isn't a command by that name then it's a name
# elt[:type] = :name
if command.nil?
@stack << elt
elsif command.is_a?( Proc )
command.call

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
require 'rpl/words/branch'
require 'rpl/words/display'
require 'rpl/words/general'
require 'rpl/words/mode'
require 'rpl/words/operations'

27
lib/rpl/words/display.rb Normal file
View file

@ -0,0 +1,27 @@
# frozen_string_literal: true
module RplLang
module Words
module Display
include Types
def populate_dictionary
super
@dictionary.add_word( ['erase'],
'Display',
'( -- ) erase display',
proc do
initialize_display
end )
@dictionary.add_word( ['display→', 'display->'],
'Display',
'( -- pict ) put current display state on stack',
proc do
@stack << @display # FIXME: RplPict type
end )
end
end
end
end