From b93bb1f5c9a232ed9676069a2771eb632630bef1 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sat, 20 Aug 2011 05:05:19 +0300 Subject: [PATCH] ExprI1 now can do numeric comparisons; added some samples --- doc/ChangeLog | 3 +++ doc/beer/Jamfile | 1 + doc/beer/Jamfile.beer1 | 33 +++++++++++++++++++++++++++++++++ src/builtins.c | 15 ++++++++++++--- src/hcache.c | 2 +- src/progress.c | 36 ++++++++++++++++++++++++++++++++++-- target_test/Jamfile.comps | 8 ++++++++ target_test/{Jamfile => Jamfile.tt} | 0 8 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 doc/beer/Jamfile.beer1 create mode 100644 target_test/Jamfile.comps rename target_test/{Jamfile => Jamfile.tt} (100%) diff --git a/doc/ChangeLog b/doc/ChangeLog index 87e34cf..6d8b769 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -144,6 +144,7 @@ [+] new built-in: [ ExprI1 num0 op num1 ] integer math; understands 5 standard ops ('%' as C '%') [ ExprI1 40 + 2 ] ==> "42" + it also understands "<", "<=", ">", ">=", "=" and "!=" [+] new built-in: [ Split str : delims ] split `str` using `delims` [ Split "a,b,c;d" : ",;" ] ==> a b c d @@ -169,3 +170,5 @@ [+] new variables: CFLAGS.all, OPTIM.all, LINKFLAGS.all, LINKLIBS.all profile now sets *.all flags + + [+] K8JAM-PROGRESS-TIME-DELTA variable (float, seconds between progress/time indicator) diff --git a/doc/beer/Jamfile b/doc/beer/Jamfile index 5caf2b3..8c9af82 100644 --- a/doc/beer/Jamfile +++ b/doc/beer/Jamfile @@ -1,3 +1,4 @@ InstallFile $(INSTALLDIR_DOCS)/beer : Jamfile.beer + Jamfile.beer1 ; diff --git a/doc/beer/Jamfile.beer1 b/doc/beer/Jamfile.beer1 new file mode 100644 index 0000000..07ebc70 --- /dev/null +++ b/doc/beer/Jamfile.beer1 @@ -0,0 +1,33 @@ +# Jamfile for 99 Bottles of beer on the wall. +# David Brandon (brandon@aspentech.com) + +ALWAYS beer ; + + +rule SorSS { + if $(1) = 1 { return "" ; } else { return "s" ; } +} + +rule Drink { + local beers b ; + + beers = 99 ; + while $(beers) != 0 { + b = [ SorSS $(beers) ] ; + Echo "$(beers) bottle$(b) of $(<) on the wall, $(beers) bottle$(b) of $(<)." ; + beers = [ ExprI1 $(beers) - 1 ] ; + if $(beers) = 0 { + Echo "Take one down and pass it around, no more bottles of $(<) on the wall." ; + Echo ; + Echo "No more bottles of $(<) on the wall, no more bottles of $(<)." ; + Exit "Go to the store and buy some more, 99 bottles of $(<) on the wall." ; + } else { + b = [ SorSS $(beers) ] ; + Echo "Take one down and pass it around, $(beers) bottle$(b) of $(<) on the wall." ; + Echo ; + } + } +} + + +Drink beer ; diff --git a/src/builtins.c b/src/builtins.c index db7e845..e53dbc3 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -520,9 +520,7 @@ LIST *builtin_command (PARSE *parse, LOL *args, int *jmp) { LIST *builtin_expri1 (PARSE *parse, LOL *args, int *jmp) { char buffer[100]; - int op0; - int op1; - int res; + int op0, op1, res, comp = 0; LIST *el = lol_get(args, 0); // if (!el || !el->next || !el->next->next) return L0; @@ -535,10 +533,21 @@ LIST *builtin_expri1 (PARSE *parse, LOL *args, int *jmp) { case '*': res = op0*op1; break; case '/': res = op0/op1; break; case '%': res = op0%op1; break; + case '<': + comp = 1; + if (el->next->string[1] == '=') res = op0<=op1; else res = op0': + comp = 1; + if (el->next->string[1] == '=') res = op0>=op1; else res = op0>op1; + break; default: printf("jam: rule ExprI1: unknown operator: '%s'\n", el->next->string); exit(EXITBAD); } + if (comp) return res?list_new(L0, "tan", 0):L0; sprintf(buffer, "%d", res); return list_new(L0, buffer, 0); } diff --git a/src/hcache.c b/src/hcache.c index d44a7e2..4783108 100644 --- a/src/hcache.c +++ b/src/hcache.c @@ -82,7 +82,7 @@ static const char *hcacheFileName (void) { pushsettings(t->settings); t->boundname = search(t->name, &t->time); popsettings(t->settings); - if (hcachevar) name = copystr(t->boundname); + if (t->boundname) name = copystr(t->boundname); } } return name; diff --git a/src/progress.c b/src/progress.c index 307bd00..e7b4d3c 100644 --- a/src/progress.c +++ b/src/progress.c @@ -2,9 +2,19 @@ #include #include +#include "jam.h" +#include "lists.h" +#include "parse.h" +#include "rules.h" +#include "newstr.h" +#include "hash.h" +#include "variable.h" +#include "search.h" + #include "progress.h" -#define PROGRESS_WINDOW 10 + +#define PROGRESS_WINDOW (10) typedef struct { @@ -20,6 +30,27 @@ struct _PROGRESS { }; +static double getTimeDelta (void) { + static double res = 10.0; + static int checked = 0; + if (!checked) { + LIST *var = var_get("K8JAM-PROGRESS-TIME-DELTA"); /*FIXME: a perfectly idiotic name*/ + if (var) { + TARGET *t = bindtarget(var->string); + pushsettings(t->settings); + t->boundname = search(t->name, &t->time); + popsettings(t->settings); + if (t->boundname) { + res = atof(t->boundname); + if (res < 0.0) res = 0.0; + } + checked = 1; + } + } + return res; +} + + #define LAST_STAMP(p) ((p)->stamps[(p)->stampcount-1]) #define FIRST_STAMP(p) ((p)->stamps[0]) @@ -51,10 +82,11 @@ static double progress_estimate (PROGRESS *progress) { double progress_update (PROGRESS *progress, int completed) { time_t now; + double dd = getTimeDelta(); // time(&now); /* only return progress every 10 seconds */ - if (progress->stampcount > 0 && difftime(now, LAST_STAMP(progress).when) < 10.0) return 0.0; + if (progress->stampcount > 0 && (dd <= 0.00001 || difftime(now, LAST_STAMP(progress).when) < dd)) return 0.0; if (progress->stampcount == PROGRESS_WINDOW) { memmove(progress->stamps, progress->stamps+1, sizeof(progress->stamps[0])*(PROGRESS_WINDOW-1)); --progress->stampcount; diff --git a/target_test/Jamfile.comps b/target_test/Jamfile.comps new file mode 100644 index 0000000..ea63aa6 --- /dev/null +++ b/target_test/Jamfile.comps @@ -0,0 +1,8 @@ +t = [ ExprI1 10 "<" 5 ]; +Echo "a" "|" $(t) "|" ; + +if 10 < 5 { Echo "00"; } else { Echo "01" ; } +Echo "should be 00" ; + +if [ ExprI1 10 "<" 5 ] { Echo "02"; } else { Echo "03" ; } +Echo "should be 03" ; diff --git a/target_test/Jamfile b/target_test/Jamfile.tt similarity index 100% rename from target_test/Jamfile rename to target_test/Jamfile.tt -- 2.11.4.GIT