diff --git a/lib/bosl/compiler.rb b/lib/bosl/compiler.rb index baed2044..589dabdd 100644 --- a/lib/bosl/compiler.rb +++ b/lib/bosl/compiler.rb @@ -34,13 +34,14 @@ module Bosl end require_relative "compiler/basic_expressions" -require_relative "compiler/name_expression" require_relative "compiler/callsite_expression" require_relative "compiler/compound_expressions" -require_relative "compiler/if_expression" +require_relative "compiler/expression_list" +require_relative "compiler/field_def" require_relative "compiler/function_expression" +require_relative "compiler/if_expression" require_relative "compiler/module_expression" +require_relative "compiler/name_expression" require_relative "compiler/operator_expressions" require_relative "compiler/return_expression" require_relative "compiler/while_expression" -require_relative "compiler/expression_list" diff --git a/lib/bosl/compiler/field_def.rb b/lib/bosl/compiler/field_def.rb new file mode 100644 index 00000000..b523d5fd --- /dev/null +++ b/lib/bosl/compiler/field_def.rb @@ -0,0 +1,16 @@ +module Bosl + Compiler.class_eval do + + def on_field_def expression + type , name , value = *expression + name = name + index = method.ensure_local( name ) + + if value + value = process( value ) + end + + Virtual::Return.new( value ) + end + end +end diff --git a/lib/bosl/compiler/function_expression.rb b/lib/bosl/compiler/function_expression.rb index b03a886c..534907ba 100644 --- a/lib/bosl/compiler/function_expression.rb +++ b/lib/bosl/compiler/function_expression.rb @@ -2,10 +2,11 @@ module Bosl Compiler.class_eval do # function attr_reader :name, :params, :body , :receiver def on_function expression +# puts expression.inspect return_type , name , parameters, kids = *expression name = name.to_a.first args = parameters.to_a.collect do |p| - raise "error, argument must be a identifier, not #{p}" unless p.type == :field + raise "error, argument must be a identifier, not #{p}" unless p.type == :parameter p[2] end diff --git a/test/fragments/test_all.rb b/test/fragments/test_all.rb index 3e21ea46..4e5bfb03 100644 --- a/test/fragments/test_all.rb +++ b/test/fragments/test_all.rb @@ -1,7 +1,7 @@ require_relative "test_foo" require_relative "test_if" -#require_relative "test_functions" +require_relative "test_functions" #require_relative "test_string_class" #require_relative "test_hello" #require_relative "test_putint" diff --git a/test/fragments/test_functions.rb b/test/fragments/test_functions.rb index 66cb9281..35ebe33c 100644 --- a/test/fragments/test_functions.rb +++ b/test/fragments/test_functions.rb @@ -5,23 +5,26 @@ class TestFunctions < MiniTest::Test def test_functions @string_input = <