diff --git a/lib/kernel/all.rb b/lib/kernel/all.rb index 67f6c7dc..208f9350 100644 --- a/lib/kernel/all.rb +++ b/lib/kernel/all.rb @@ -1,4 +1,5 @@ require_relative "integer" require_relative "string" +require_relative "array" require_relative "system" require_relative "object" diff --git a/lib/kernel/array.rb b/lib/kernel/array.rb new file mode 100644 index 00000000..30fe1e74 --- /dev/null +++ b/lib/kernel/array.rb @@ -0,0 +1,19 @@ +module Salama + class Array + module ClassMethods + def get context , index = Virtual::Integer + get_function = Virtual::CompiledMethod.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer ) + return get_function + end + def set context , index = Virtual::Integer , object = Virtual::Reference + set_function = Virtual::CompiledMethod.new(:set , [Virtual::Integer, Virtual::Reference] ) + return set_function + end + def push context , object = Virtual::Reference + push_function = Virtual::CompiledMethod.new(:push , [Virtual::Reference] ) + return push_function + end + end + extend ClassMethods + end +end diff --git a/lib/parfait/array.rb b/lib/parfait/array.rb index 8f0abef6..492c5cd7 100644 --- a/lib/parfait/array.rb +++ b/lib/parfait/array.rb @@ -2,15 +2,8 @@ # instead it is parsed by salama to define part of the program that runs class Array < BaseObject - def initialize size - - end - - def at(index) - - end - - def set(index , value) - - end + #many basic array functions can not be defined in ruby, such as + # get/set/length/add/delete + # so they must be defined as CompiledMethods in Salama::Kernel + end diff --git a/lib/virtual/boot_space.rb b/lib/virtual/boot_space.rb index d8f416e3..87b125e0 100644 --- a/lib/virtual/boot_space.rb +++ b/lib/virtual/boot_space.rb @@ -82,6 +82,10 @@ module Virtual #puts "Boot String::#{f}" obj.add_instance_method Salama::String.send(f , @context) end + obj = get_or_create_class :Array + [:get , :set , :push].each do |f| + obj.add_instance_method Salama::Array.send(f , @context) + end end # Objects are data and get assembled after functions