Skip to content

Commit

Permalink
Allow expr's == to fallback to string comparision.
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Dec 16, 2009
1 parent 4c8feef commit 6f81dc9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
6 changes: 0 additions & 6 deletions TODO
Expand Up @@ -4,12 +4,6 @@ Big Goals

Tasks/Bugs:

2. This should not print anything, but prints "yes", presumably due to
numeric coercion - tcl allows strings to be matched in this way, if
numeric coercion fails {library/init.tcl}

if {[set a not-empty] == ""} {puts yes}

3. [unknown] - invoking a non-existant command should
result in a tcl error, not a parrot error.
{t/tcl_misc.t; t/tcl_catch.t}
Expand Down
4 changes: 4 additions & 0 deletions build/Makefile.in
Expand Up @@ -39,6 +39,7 @@ NQP_LANG_DIR = $(PARROT_LIB_DIR)/languages/nqp

PARTCL_EXE = partcl$(EXE)
PARTCL_G_PIR = src/gen/partcl-grammar.pir
PARTCL_O_PIR = src/gen/partcl-operators.pir
PARTCL_A_PIR = src/gen/partcl-actions.pir
PARTCL_C_PIR = src/gen/partcl-compiler.pir
PARTCL_B_PIR = src/gen/partcl-commands-main.pir
Expand All @@ -57,6 +58,7 @@ INIT_PIR = src/gen/init.pir
PARTCL_SOURCES = \
src/Partcl.pir \
$(PARTCL_G_PIR) \
$(PARTCL_O_PIR) \
$(PARTCL_A_PIR) \
$(PARTCL_C_PIR) \
$(PARTCL_B_PIR) \
Expand Down Expand Up @@ -90,6 +92,8 @@ $(PARTCL_EXE) : $(PARTCL_SOURCES)
$(PARROT) -o partcl.pbc src/Partcl.pir
$(PBC_TO_EXE) partcl.pbc

$(PARTCL_O_PIR): src/Partcl/Operators.pm
$(PARROT_NQP) --target=pir -o $(PARTCL_O_PIR) src/Partcl/Operators.pm
$(PARTCL_G_PIR): src/Partcl/Grammar.pm
$(PARROT_NQP) --target=pir -o $(PARTCL_G_PIR) src/Partcl/Grammar.pm
$(PARTCL_A_PIR): src/Partcl/Actions.pm
Expand Down
1 change: 1 addition & 0 deletions src/Partcl.pir
Expand Up @@ -18,6 +18,7 @@
.include 'src/gen/partcl-grammar.pir'
.include 'src/gen/partcl-actions.pir'
.include 'src/gen/partcl-compiler.pir'
.include 'src/gen/partcl-operators.pir'
.include 'src/gen/partcl-commands-main.pir'
.include 'src/gen/partcl-commands-file.pir'
.include 'src/gen/partcl-commands-info.pir'
Expand Down
2 changes: 1 addition & 1 deletion src/Partcl/Grammar.pm
Expand Up @@ -139,7 +139,7 @@ token infix:sym«<=» { <sym> <O('%compare_numeric, :pirop<isle Inn>')> }
token infix:sym«>» { <sym> <O('%compare_numeric, :pirop<isgt Inn>')> }
token infix:sym«>=» { <sym> <O('%compare_numeric, :pirop<isge Inn>')> }

token infix:sym<==> { <sym> <O('%equality_numeric, :pirop<iseq Inn>')> }
token infix:sym<==> { <sym> <O('%equality_numeric')> }
token infix:sym<!=> { <sym> <O('%equality_numeric, :pirop<isne Inn>')> }

token infix:sym<eq> { <sym> <O('%equality_string, :pirop<iseq Iss>')> }
Expand Down
13 changes: 13 additions & 0 deletions src/Partcl/Operators.pm
@@ -0,0 +1,13 @@
sub &infix:<==>($a, $b) {
# Try to do a numeric compare first (XXX this is integer for now)
try {
return pir::set__iP($a) == pir::set__iP($b);
CATCH {
# Not numeric. Try as string...
return $a eq $b;
}
}

}

# vim: filetype=perl6:

0 comments on commit 6f81dc9

Please sign in to comment.