From c34b8a6d0bc56e217fc2c5656b4748b4c8d46015 Mon Sep 17 00:00:00 2001 From: Ted Reed Date: Sun, 16 Aug 2009 19:50:18 -0700 Subject: [PATCH 01/11] Properly fix == with bools. (joeri++) Also adds some tests and adds test:bool to the test:basic (and therefore test:all) targets. --- Rakefile | 2 +- src/builtins/cmp.pir | 19 +++++++++++++++++-- t/bool.t | 9 ++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 2199694..4e06698 100644 --- a/Rakefile +++ b/Rakefile @@ -365,7 +365,7 @@ namespace :test do |ns| task :all => [:add, :block, :capitalize, :chops, :cmp, :concat, :downcase, :empty, :eq, :mult, :new, :quote, :random_access, :reverse, :upcase] end - task :basic => [:sanity, :stmts, :functions, :return, :indexed, :opcmp, :loops, :class, :test, :regex, :slurpy, :gather, :other, :alias, :assignment, :blocks, :constants, :continuation, :freeze, :gc, :nil, :proc, :range, :splat, :time, :yield, :zip] + task :basic => [:sanity, :stmts, :functions, :return, :indexed, :opcmp, :loops, :class, :test, :regex, :slurpy, :gather, :other, :alias, :assignment, :bool, :blocks, :constants, :continuation, :freeze, :gc, :nil, :proc, :range, :splat, :time, :yield, :zip] task :all => [:basic, "array:all", "file:all", "hash:all", "integer:all", "kernel:all", "math:all", "range:all", "string:all"] do dur_seconds = Time.now.to_i - $start.to_i dur_minutes = 0 diff --git a/src/builtins/cmp.pir b/src/builtins/cmp.pir index e458207..a201aa3 100644 --- a/src/builtins/cmp.pir +++ b/src/builtins/cmp.pir @@ -45,20 +45,35 @@ Swiped from Rakudo. .return ($P0) .end -.sub 'infix:==' :multi(TrueClass,FalseClass) +.sub 'infix:==' :multi(TrueClass,_) .param pmc a .param pmc b $P0 = get_hll_global 'false' .return ($P0) .end -.sub 'infix:==' :multi(FalseClass,TrueClass) +.sub 'infix:==' :multi(FalseClass,_) .param pmc a .param pmc b $P0 = get_hll_global 'false' .return ($P0) .end +.sub 'infix:==' :multi(_,TrueClass) + .param pmc a + .param pmc b + $P0 = get_hll_global 'false' + .return ($P0) +.end + +.sub 'infix:==' :multi(_,FalseClass) + .param pmc a + .param pmc b + $P0 = get_hll_global 'false' + .return ($P0) +.end + + .sub 'infix:==' :multi(Integer,Integer) .param pmc a .param pmc b diff --git a/t/bool.t b/t/bool.t index 9c7d9d9..6cf593e 100644 --- a/t/bool.t +++ b/t/bool.t @@ -1,8 +1,15 @@ require "Test" include Test -plan 3 +plan 10 is true, true, "true == true" is false, false, "false == false" isnt true, false, "true != false" +isnt true, 1, "true != 1" +isnt true, 0, "true != 0" +isnt false, 0, "false != 0" +isnt -1, false, "-1 != false" +isnt -1, true, "-1 != false" +isnt "", false, "empty string isn't false" +isnt "", true, "empty string isn't true" From 7f1a943ec139c5d3500f4cc6b7d6e02ebf1e7598 Mon Sep 17 00:00:00 2001 From: Ted Reed Date: Mon, 17 Aug 2009 13:39:14 -0700 Subject: [PATCH 02/11] Floats need to have at least one digit prior to the radix. --- src/parser/grammar.pg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/grammar.pg b/src/parser/grammar.pg index ad65b78..897ca82 100644 --- a/src/parser/grammar.pg +++ b/src/parser/grammar.pg @@ -423,7 +423,7 @@ token literal { } token float { - '-'? \d* '.' \d+ + '-'? \d+ '.' \d+ {*} } From 298dbf055d6fb5909c60506caa96bef5b0f39edc Mon Sep 17 00:00:00 2001 From: Ted Reed Date: Mon, 17 Aug 2009 14:01:32 -0700 Subject: [PATCH 03/11] foo++ and foo-- don't exist in Ruby --- src/parser/grammar.pg | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/parser/grammar.pg b/src/parser/grammar.pg index 897ca82..c17c80e 100644 --- a/src/parser/grammar.pg +++ b/src/parser/grammar.pg @@ -551,12 +551,6 @@ proto 'infix:/' is equiv('infix:*') { ... } proto 'infix:%' is equiv('infix:*') is pirop('mod') { ... } -proto 'postfix:++' is tighter('infix:*') - is pirop('n_add') { ... } - -proto 'postfix:--' is tighter('infix:*') - is pirop('n_sub') { ... } -# #proto 'prefix:+' is tighter('infix:*') { ... } #proto 'prefix:-' is equiv('prefix:+') { ... } #proto 'prefix:!' is equiv('prefix:+') { ... } From 7ae0541fa6fd8f8a9536ed3f67d7713dca5347bd Mon Sep 17 00:00:00 2001 From: Joeri Samson Date: Sun, 16 Aug 2009 22:33:51 +0200 Subject: [PATCH 04/11] Remove postfix ++ and -- --- src/builtins/op.pir | 18 ------------------ src/classes/Range.pir | 5 +++-- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/builtins/op.pir b/src/builtins/op.pir index 4dc10af..22e2463 100644 --- a/src/builtins/op.pir +++ b/src/builtins/op.pir @@ -102,24 +102,6 @@ src/builtins/op.pir - Cardinal ops .return ($P0) .end - -## autoincrement -.sub 'postfix:++' :multi(_) - .param pmc a - $P0 = clone a - inc a - .return ($P0) - #.return (a) -.end - -.sub 'postfix:--' :multi(_) - .param pmc a - $P0 = clone a - dec a - .return ($P0) -.end - - =back =cut diff --git a/src/classes/Range.pir b/src/classes/Range.pir index 1a6df49..3ff6130 100644 --- a/src/classes/Range.pir +++ b/src/classes/Range.pir @@ -328,7 +328,8 @@ Generate the next element at the front of the CardinalRange. .local pmc from, fromexc, value from = getattribute self, '$!from' fromexc = getattribute self, '$!from_exclusive' - value = 'postfix:++'(from) + value = clone from + inc from unless fromexc goto have_value value = clone from have_value: @@ -353,7 +354,7 @@ Return true if there are any more values to iterate over. fromexc = getattribute self, '$!from_exclusive' unless fromexc goto have_value from = clone from - 'postfix:++'(from) + inc from have_value: $I0 = self.'!to_test'(from) .return ($I0) From 6061f7e02eef32f0ea94fa2f1e2d3c37c8210254 Mon Sep 17 00:00:00 2001 From: Joeri Samson Date: Sun, 16 Aug 2009 03:25:49 +0200 Subject: [PATCH 05/11] Use real true and false when testing GC --- t/gc.t | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/gc.t b/t/gc.t index 4b457b0..84d9f3c 100644 --- a/t/gc.t +++ b/t/gc.t @@ -5,13 +5,13 @@ plan 4 # TODO rework this test after we can loop thru all the object in the system, then we can verify they were destroyed status = GC.disable -is status, 'false', '.disable on GC' +is status, false, '.disable on GC' status = GC.enable -is status, 'true', '.enable on GC' +is status, true, '.enable on GC' status = GC.disable -is status, 'false', '.disable on GC' +is status, false, '.disable on GC' GC.start pass '.start on GC' From 0560029ccd16ebee006b62937f9717ba8c59e101 Mon Sep 17 00:00:00 2001 From: Ted Reed Date: Mon, 17 Aug 2009 16:31:37 -0700 Subject: [PATCH 06/11] Actually have GC's methods return true and false, rather than strings. --- src/classes/GC.pir | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/classes/GC.pir b/src/classes/GC.pir index 1e39551..93a2c47 100644 --- a/src/classes/GC.pir +++ b/src/classes/GC.pir @@ -54,12 +54,10 @@ Perform initializations and create the GC class $P1 = 1 setattribute self, '$!disabled', $P1 collectoff - $P0 = new 'CardinalString' - $P0 = 'false' + $P0 = get_hll_global 'false' .return ($P0) already_disabled: - $P0 = new 'CardinalString' - $P0 = 'true' + $P0 = get_hll_global 'true' .return ($P0) .end @@ -68,16 +66,14 @@ Perform initializations and create the GC class if $P0 == 1 goto enable goto already_enabled already_enabled: - $P0 = new 'CardinalString' - $P0 = 'false' + $P0 = get_hll_global 'false' .return ($P0) enable: $P1 = new 'CardinalInteger' $P1 = 0 setattribute self, '$!disabled', $P1 collecton - $P0 = new 'CardinalString' - $P0 = 'true' + $P0 = get_hll_global 'true' .return ($P0) .end From 171e24bc6fc3a8840be6b1bb57834384a9a5a759 Mon Sep 17 00:00:00 2001 From: Joeri Samson Date: Sun, 16 Aug 2009 22:42:54 +0200 Subject: [PATCH 07/11] Make all proto ops look the same --- src/parser/grammar.pg | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/parser/grammar.pg b/src/parser/grammar.pg index c17c80e..3b5fcc6 100644 --- a/src/parser/grammar.pg +++ b/src/parser/grammar.pg @@ -190,8 +190,6 @@ rule args { rule 'arg' is optable { ... } -proto 'infix:=' is precedence('1') is pasttype('copy') is lvalue(1) { ... } - token basic_primary { | {*} #= literal | {*} #= funcall @@ -488,10 +486,10 @@ proto 'infix:&=' is equiv('infix:=') { ... } proto 'infix:~=' is equiv('infix:=') { ... } -proto infix:«>>=» is equiv('infix:=') +proto 'infix:>>=' is equiv('infix:=') is pirop('shr') { ... } -proto infix:«<<=» is equiv('infix:=') +proto 'infix:<<=' is equiv('infix:=') is pirop('shl') { ... } proto 'infix:&&=' is equiv('infix:=') @@ -521,23 +519,23 @@ proto 'infix:!=' is equiv('infix:==') { ... } proto 'infix:=~' is equiv('infix:==') { ... } proto 'infix:!~' is equiv('infix:==') { ... } proto 'infix:===' is equiv('infix:==') { ... } -proto infix:«<=>» is equiv('infix:==') { ... } +proto 'infix:<=>' is equiv('infix:==') { ... } -proto infix:«>» is tighter('infix:===') { ... } -proto infix:«<» is tighter('infix:===') { ... } -proto infix:«<=» is tighter('infix:===') { ... } -proto infix:«>=» is tighter('infix:===') { ... } +proto 'infix:>' is tighter('infix:===') { ... } +proto 'infix:<' is equiv('infix:>') { ... } +proto 'infix:<=' is equiv('infix:>') { ... } +proto 'infix:>=' is equiv('infix:>') { ... } proto 'infix:|' is tighter('infix:<=') { ... } proto 'infix:^' is equiv('infix:|') { ... } proto 'infix:&' is tighter('infix:|') { ... } -proto infix:«<<» is tighter('infix:&') { ... } -proto infix:«>>» is equiv(infix:«<<») { ... } +proto 'infix:<<' is tighter('infix:&') { ... } +proto 'infix:>>' is equiv('infix:<<') { ... } -proto 'infix:+' is tighter(infix:«<<») { ... } +proto 'infix:+' is tighter('infix:<<') { ... } proto 'infix:-' is equiv('infix:+') { ... } #is pirop('sub') { ... } From 4ca9cd219b748321d11dfabde356af3cf57bab21 Mon Sep 17 00:00:00 2001 From: Joeri Samson Date: Mon, 17 Aug 2009 04:43:28 +0800 Subject: [PATCH 08/11] Add support for () in expressions Signed-off-by: Ted Reed --- src/builtins/op.pir | 5 +++++ src/parser/grammar.pg | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/builtins/op.pir b/src/builtins/op.pir index 22e2463..d482cec 100644 --- a/src/builtins/op.pir +++ b/src/builtins/op.pir @@ -102,6 +102,11 @@ src/builtins/op.pir - Cardinal ops .return ($P0) .end +.sub 'circumfix:( )' + .param pmc a + .return (a) +.end + =back =cut diff --git a/src/parser/grammar.pg b/src/parser/grammar.pg index 3b5fcc6..457e9b6 100644 --- a/src/parser/grammar.pg +++ b/src/parser/grammar.pg @@ -556,3 +556,5 @@ proto 'infix:%' is equiv('infix:*') proto 'term:' is tighter('infix:*') is parsed(&primary) { ... } + +proto 'circumfix:( )' is equiv('term:') { ... } From 37af6e91727faa76600c251ffa8cd6cff1a24328 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Mon, 17 Aug 2009 17:55:34 +0800 Subject: [PATCH 09/11] fix build with make Signed-off-by: Ted Reed --- build/Makefile.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/Makefile.in b/build/Makefile.in index babbd44..5a75e00 100644 --- a/build/Makefile.in +++ b/build/Makefile.in @@ -48,14 +48,15 @@ BUILTINS_PIR = \ src/builtins/cmp.pir \ src/builtins/op.pir \ src/classes/Object.pir \ + src/classes/Exception.pir \ src/classes/NilClass.pir \ src/classes/String.pir \ src/classes/Integer.pir \ src/classes/Array.pir \ src/classes/Hash.pir \ - src/classes/Any.pir \ src/classes/Range.pir \ - src/classes/Bool.pir \ + src/classes/TrueClass.pir \ + src/classes/FalseClass.pir \ src/classes/Kernel.pir \ src/classes/Time.pir \ src/classes/Math.pir \ From c34fa1833df80cf89fe3ea00d3f75edb494282d3 Mon Sep 17 00:00:00 2001 From: Ted Reed Date: Mon, 17 Aug 2009 19:21:57 -0700 Subject: [PATCH 10/11] Cause the Makefile to use the rakefile for testing. --- build/Makefile.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/Makefile.in b/build/Makefile.in index 5a75e00..97669c8 100644 --- a/build/Makefile.in +++ b/build/Makefile.in @@ -133,13 +133,13 @@ help: @echo "" test: all - $(PERL) t/harness + rake test:all arraytest: all - $(PERL) t/harness --tests-from-dir=array + rake test:array:all hashtest: all - $(PERL) t/harness --tests-from-dir=hash + rake test:hash:all # this target has nothing to do testclean: From 66a059aea40a201a79c5c28fa1e7cf3cf8315d25 Mon Sep 17 00:00:00 2001 From: Ted Reed Date: Tue, 18 Aug 2009 22:56:09 -0700 Subject: [PATCH 11/11] Miscellaneous changes/fixes to the Rakefile. * Now has targets for clean/clobber. * Main targets have descriptions. * As a result, the main targets can be listed with 'rake -T'. * Tests now generate cardinal.pbc on demand, without depending on it. * Tests output the full task name with namespace when running. --- Rakefile | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 4e06698..73e99a0 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,16 @@ +require 'rake/classic_namespace' +require 'rake/clean' + +CLEAN.include('gen_*.pir') +CLEAN.include('*/gen_*.pir') +CLEAN.include('*/*/gen_*.pir') +CLEAN.include('Test.pir') +CLEAN.include('build.yaml') +CLEAN.include('*.c') +CLEAN.include('*.o') +CLOBBER.include('cardinal') +CLOBBER.include('*.pbc') + DEBUG = ENV['debug'] || false ALTERNATIVE_RUBY = ENV['test_with'] || false CONFIG = {} @@ -75,11 +88,14 @@ def test(file, name="") end else file "t/#{pir_file}" => [:config, "t/#{file}", "src/gen_actions.pir", "src/gen_grammar.pir"] do + unless File.exists?('cardinal.pbc') + Task['cardinal.pbc'].invoke + end parrot("t/#{file}", "t/#{pir_file}", "cardinal.pbc", "pir") end puts "named #{name}" if DEBUG - task name => [:config, "t/#{pir_file}", "cardinal.pbc", "Test.pir"] do - run_test pir_file, name + task name => [:config, "t/#{pir_file}", "cardinal.pbc", "Test.pir"] do |t| + run_test pir_file, "#{t.scope.join(':')}:#{name}" end end end @@ -153,10 +169,11 @@ def run_test(file,name="") result = "Complete failure... no plan given" $failures += 1 end - puts "Running test #{name} #{result}" + puts "Running #{name} #{result}" end end +desc "Determine configuration information" task :config => "build.yaml" do require 'yaml' File.open("build.yaml","r") do |f| @@ -187,6 +204,7 @@ file "build.yaml" do end end +desc "Make the cardinal binary." file "cardinal" => [:config, "cardinal.pbc"] do make_exe("cardinal.pbc") end @@ -292,6 +310,7 @@ namespace :test do |ns| test "array/values_at.t" test "array/warray.t" + desc "Run tests on Array." task :all => [:array, :assign, :at, :clear, :collect, :compact, :concat, :delete, :empty, :equals, :fetch, :fill, :first, :flatten, :grep, :include, :index, :insert, :intersection, :join, :mathop, :nitems, :pop, :push, :reject, :replace, :reverse, :shift, :slice, :sort, :to_s, :uniq, :values_at, :warray] end @@ -300,6 +319,7 @@ namespace :test do |ns| test "file/file.t" test "file/stat.t" + desc "Run tests on File." task :all => [:dir, :file, :stat] end @@ -307,6 +327,7 @@ namespace :test do |ns| test "hash/hash.t" test "hash/exists.t" + desc "Run tests on Hash." task :all => [:hash, :exists] end @@ -315,6 +336,7 @@ namespace :test do |ns| test "integer/times.t" test "integer/cmp.t" + desc "Run tests on Integer." task :all => [:integer, :times, :cmp] end @@ -323,12 +345,14 @@ namespace :test do |ns| test "kernel/open.t" test "kernel/sprintf.t" + desc "Run tests on Kernel." task :all => [:exit, :open, :sprintf] end namespace :math do test "math/functions.t" + desc "Run tests on Math." task :all => [:functions] end @@ -342,6 +366,7 @@ namespace :test do |ns| test "range/to_s.t" test "range/tofrom-variants.t" + desc "Run tests on Range." task :all => [:each, :infixexclusive, :infixinclusive, :membershipvariants, :new, :to_a, :to_s, :tofromvariants] end @@ -362,10 +387,14 @@ namespace :test do |ns| test "string/reverse.t" test "string/upcase.t" + desc "Run tests on String." task :all => [:add, :block, :capitalize, :chops, :cmp, :concat, :downcase, :empty, :eq, :mult, :new, :quote, :random_access, :reverse, :upcase] end + desc "Run basic tests." task :basic => [:sanity, :stmts, :functions, :return, :indexed, :opcmp, :loops, :class, :test, :regex, :slurpy, :gather, :other, :alias, :assignment, :bool, :blocks, :constants, :continuation, :freeze, :gc, :nil, :proc, :range, :splat, :time, :yield, :zip] + + desc "Run the entire test suite." task :all => [:basic, "array:all", "file:all", "hash:all", "integer:all", "kernel:all", "math:all", "range:all", "string:all"] do dur_seconds = Time.now.to_i - $start.to_i dur_minutes = 0 @@ -426,6 +455,7 @@ namespace :test do |ns| puts " -- CLEAN FOR COMMIT --" if clean? end + desc "Run test:all *and* produce stats about known issues." task :stats => [:all] do $pl = $issue_counts.size > 1 unless $issue_counts.empty?