pretty print multi demension array keys
[nedit-bw.git] / pushImmed.patch
blob7219ae4eb42e19746fc5e09ac2a9e214ea6f58ba
1 From: Bert Wesarg <bert.wesarg@googlemail.com>
2 Subject: [PATCH] skip indirection for NUMBER tokens
4 IMHO we need not the additional indirection through a CONST_SYM symbol
5 for immediate values.
7 Create a new op PUSH_IMMED for numeric constants.
9 ---
11 source/interpret.c | 26 ++++++++++++++++++++++++++
12 source/ops.h | 1 +
13 source/parse.y | 16 ++++++----------
14 3 files changed, 33 insertions(+), 10 deletions(-)
16 diff --quilt old/source/interpret.c new/source/interpret.c
17 --- old/source/interpret.c
18 +++ new/source/interpret.c
19 @@ -1300,6 +1300,28 @@ static int pushSymVal(void)
20 return STAT_OK;
23 +/*
24 +** push immediate onto the stack
25 +** Before: Prog-> [immediate], next, ...
26 +** TheStack-> next, ...
27 +** After: Prog-> immediate, [next], ...
28 +** TheStack-> [immediate], next, ...
29 +*/
30 +static int pushImmed(void)
32 + int immed;
34 + DISASM_RT(PC-1, 2);
35 + STACKDUMP(0, 3);
37 + immed = PC->value;
38 + PC++;
40 + PUSH_INT(immed);
42 + return STAT_OK;
45 static int pushArgVal(void)
47 int nArgs, argNum;
48 @@ -3001,6 +3023,10 @@ static void disasm(Inst *inst, int nInst
50 ++i;
52 + else if (j == OP_PUSH_IMMED) {
53 + printf("i=%d", inst[i+1].value);
54 + ++i;
55 + }
56 else if (j == OP_BRANCH || j == OP_BRANCH_FALSE ||
57 j == OP_BRANCH_NEVER || j == OP_BRANCH_TRUE) {
58 printf("to=(%d) %p", inst[i+1].value,
59 diff --quilt old/source/parse.y new/source/parse.y
60 --- old/source/parse.y
61 +++ new/source/parse.y
62 @@ -82,16 +82,17 @@ static int AllowDefine;
63 %union {
64 Symbol *sym;
65 Inst *inst;
66 - int nArgs;
67 + int num;
68 struct {
69 AccumulatorData *acc;
70 Symbol *sym;
71 } define;
73 -%token <sym> NUMBER STRING SYMBOL
74 +%token <sym> STRING SYMBOL
75 +%token <num> NUMBER
76 %token DELETE ARG_LOOKUP
77 %token IF WHILE ELSE FOR BREAK CONTINUE RETURN DEFINE
78 -%type <nArgs> arglist
79 +%type <num> arglist
80 %type <inst> cond comastmts for while else and or arrayexpr
81 %type <sym> evalsym
82 %type <define> definesym
83 @@ -384,7 +385,7 @@ arrayexpr: numexpr {
86 numexpr: NUMBER {
87 - ADD_OP(OP_PUSH_SYM); ADD_SYM($1);
88 + ADD_OP(OP_PUSH_IMMED); ADD_IMMED($1);
90 | STRING {
91 ADD_OP(OP_PUSH_SYM); ADD_SYM($1);
92 @@ -615,13 +616,8 @@ static int yylex(void)
94 /* process number tokens */
95 if (isdigit((unsigned char)*InPtr)) { /* number */
96 - char name[28];
97 - sscanf(InPtr, "%d%n", &value.val.n, &len);
98 - sprintf(name, "const %d", value.val.n);
99 + sscanf(InPtr, "%d%n", &yylval.num, &len);
100 InPtr += len;
101 - value.tag = INT_TAG;
102 - if ((yylval.sym=LookupSymbol(name)) == NULL)
103 - yylval.sym = InstallSymbol(name, CONST_SYM, value);
104 return NUMBER;
107 diff --quilt old/source/ops.h new/source/ops.h
108 --- old/source/ops.h
109 +++ new/source/ops.h
110 @@ -6,6 +6,7 @@
111 OP(RETURN_NO_VAL, returnNoVal) /* rewind */
112 OP(RETURN, returnVal) /* pop(ret), rewind, push(ret) */
113 OP(PUSH_SYM, pushSymVal) /* sym */ /* push(sym.v) */
114 +OP(PUSH_IMMED, pushImmed) /* immed */ /* push(immed) */
115 OP(DUP, dupStack) /* pop(v), push(v,v) */
116 OP(ADD, add) /* pop(v2,v1), push(v1 + v2) */
117 OP(SUB, subtract) /* pop(v2,v1), push(v1 - v2) */