GIB: Added ifnot, fixed several bugs, updated zoom.gib yet again.

This commit is contained in:
Brian Koropoff 2003-01-31 03:43:56 +00:00
parent 783602e6a4
commit 47d35f3e2d
5 changed files with 40 additions and 36 deletions

View file

@ -34,8 +34,8 @@ global mult
global zoomed global zoomed
// clamp returns the second argument clamped // clamp returns the second argument clamped
// between the first and second // between the first and third
function clamp { function zoom::clamp {
if ($args[2] < $args[1]) { if ($args[2] < $args[1]) {
return $args[1] return $args[1]
} else if ($args[2] > $args[3]) { } else if ($args[2] > $args[3]) {
@ -88,18 +88,18 @@ function zoom::toggle {
} }
function zoom::increase { function zoom::increase {
if (!$zoomed) { ifnot $zoomed {
return return
} }
mult = `clamp $min ($mult*$step) $max` mult = `zoom::clamp $min ($mult*$step) $max`
zoom::adjust zoom::adjust
} }
function zoom::decrease { function zoom::decrease {
if (!$zoomed) { ifnot $zoomed {
return return
} }
mult = `clamp $min ($mult/$step) $max` mult = `zoom::clamp $min ($mult/$step) $max`
zoom::adjust zoom::adjust
} }

View file

@ -33,16 +33,15 @@
#define __GIB_TREE_H #define __GIB_TREE_H
#define TREE_NORMAL 0 // Normal node #define TREE_NORMAL 0 // Normal node
#define TREE_PERM 1 // Permanent (part of a function) #define TREE_CONCAT 1 // Concatenate to previous
#define TREE_CONCAT 2 // Concatenate to previous #define TREE_EMBED 2 // Embedded command (expect return value)
#define TREE_EMBED 4 // Embedded command (expect return value) #define TREE_P_EMBED 4 // Embedded stuff needs to be processed
#define TREE_P_EMBED 8 // Embedded stuff needs to be processed #define TREE_ASPLIT 8 // Token is the name of an array that should be split
#define TREE_P_MATH 16 // Math needs be evaluated #define TREE_FUNC 16 // Node is the first in a function
#define TREE_ASPLIT 32 // Token is the name of an array that should be split #define TREE_COND 32 // Conditional jump (if or while command)
#define TREE_FUNC 64 // Node is the first in a function #define TREE_NOT 64
#define TREE_COND 128 // Conditional jump (if or while command) #define TREE_END 128 // Node ends a loop or conditional
#define TREE_END 256 // Node ends a loop or conditional #define TREE_FORNEXT 256 // For loop is starting again
#define TREE_FORNEXT 512 // For loop is starting again
typedef struct gib_tree_s { typedef struct gib_tree_s {
const char *str; const char *str;

View file

@ -359,14 +359,16 @@ GIB_Slice_f (void)
len = strlen (GIB_Argv(1)); len = strlen (GIB_Argv(1));
start = atoi (GIB_Argv(2)); start = atoi (GIB_Argv(2));
end = atoi (GIB_Argv(3)); end = atoi (GIB_Argv(3));
while (start < 0) if (end < 1)
start += len-1;
while (end < 0)
end += len; end += len;
if (start >= len) else if (end > len)
return;
if (end > len || !end)
end = len; end = len;
if (start < 0) {
start += len;
if (start < 0)
start = 0;
} else if (start >= len || start >= end)
return;
if ((ret = GIB_Return (0))) if ((ret = GIB_Return (0)))
dstring_appendsubstr (ret, GIB_Argv(1)+start, end-start); dstring_appendsubstr (ret, GIB_Argv(1)+start, end-start);
} }

View file

@ -93,16 +93,18 @@ GIB_Execute_Split_Array (cbuf_t *cbuf)
break; break;
} }
cbuf->args->argc--; cbuf->args->argc--;
if (!(var = GIB_Var_Get_Complex (&GIB_DATA(cbuf)->locals, &gib_globals, str, &i, false))) if (!(var = GIB_Var_Get_Complex (&GIB_DATA(cbuf)->locals, &GIB_DATA(cbuf)->globals, str, &i, false)))
return; return;
while (start < 0) if (end < 1)
start += var->size-1;
while (end < 0)
end += var->size; end += var->size;
if (start >= var->size) else if (end > var->size)
return;
if (end >= var->size || !end)
end = var->size; end = var->size;
if (start < 0) {
start += var->size;
if (start < 0)
start = 0;
} else if (start >= var->size || start >= end)
return;
for (i = start; i < end; i++) { for (i = start; i < end; i++) {
if (var->array[i]) if (var->array[i])
Cbuf_ArgsAdd (cbuf->args, var->array[i]->str); Cbuf_ArgsAdd (cbuf->args, var->array[i]->str);
@ -137,7 +139,7 @@ GIB_Execute_Prepare_Line (cbuf_t *cbuf, gib_tree_t *line)
Cbuf_ArgsAdd (args, cur->str); Cbuf_ArgsAdd (args, cur->str);
args->argm[args->argc-1] = cur; args->argm[args->argc-1] = cur;
} }
if (cur->flags & TREE_P_MATH && GIB_Process_Math (args->argv[args->argc-1], pos)) if (cur->delim == '(' && GIB_Process_Math (args->argv[args->argc-1], pos))
return -1; return -1;
if (cur->flags & TREE_ASPLIT) if (cur->flags & TREE_ASPLIT)
GIB_Execute_Split_Array (cbuf); GIB_Execute_Split_Array (cbuf);
@ -168,6 +170,7 @@ GIB_Execute (cbuf_t *cbuf)
gib_buffer_data_t *g = GIB_DATA (cbuf); gib_buffer_data_t *g = GIB_DATA (cbuf);
gib_builtin_t *b; gib_builtin_t *b;
gib_function_t *f; gib_function_t *f;
int cond;
if (!g->program) if (!g->program)
return; return;
@ -177,7 +180,8 @@ GIB_Execute (cbuf_t *cbuf)
if (GIB_Execute_Prepare_Line (cbuf, g->ip)) if (GIB_Execute_Prepare_Line (cbuf, g->ip))
return; return;
if (g->ip->flags & TREE_COND) { if (g->ip->flags & TREE_COND) {
if (!atoi(cbuf->args->argv[1]->str)) cond = g->ip->flags & TREE_NOT ? atoi (cbuf->args->argv[1]->str) : !atoi (cbuf->args->argv[1]->str);
if (cond)
g->ip = g->ip->jump; g->ip = g->ip->jump;
} else if (g->ip->flags & TREE_FORNEXT) { } else if (g->ip->flags & TREE_FORNEXT) {
if (GIB_Execute_For_Next (cbuf)) if (GIB_Execute_For_Next (cbuf))

View file

@ -289,11 +289,8 @@ GIB_Parse_Tokens (const char *program, unsigned int *i, unsigned int flags, gib_
// We can handle escape characters now // We can handle escape characters now
} else if (cur->delim == '\"') } else if (cur->delim == '\"')
GIB_Process_Escapes (str); GIB_Process_Escapes (str);
cur->str = str; cur->str = str;
// Set proper flags for GIB_Execute_Prepare_Line
if (cur->delim == '(')
cur->flags |= TREE_P_MATH;
if (cat) { if (cat) {
cur->flags |= TREE_CONCAT; cur->flags |= TREE_CONCAT;
cat = false; cat = false;
@ -320,7 +317,7 @@ GIB_Parse_Semantic_Preprocess (gib_tree_t *line)
{ {
gib_tree_t *p, *start = line; gib_tree_t *p, *start = line;
unsigned int flags = line->flags; unsigned int flags = line->flags;
while (!strcmp (line->children->str, "if")) { while (!strcmp (line->children->str, "if") || !strcmp (line->children->str, "ifnot")) {
// Sanity checking // Sanity checking
if (!line->children->next || !line->children->next->next || !line->children->next->next->children || line->flags & TREE_EMBED) { if (!line->children->next || !line->children->next->next || !line->children->next->next->children || line->flags & TREE_EMBED) {
gib_parse_error = true; gib_parse_error = true;
@ -328,6 +325,8 @@ GIB_Parse_Semantic_Preprocess (gib_tree_t *line)
} }
// Set conditional flag // Set conditional flag
line->flags |= TREE_COND; line->flags |= TREE_COND;
if (line->children->str[2])
line->flags |= TREE_NOT;
// Save our spot // Save our spot
p = line; p = line;
// Move subprogram inline // Move subprogram inline