Skip to content

Commit

Permalink
Re-translated scanner back to C. itp reads init.ps before executing s…
Browse files Browse the repository at this point in the history
…tdin.
  • Loading branch information
luser-dr00g committed Jul 23, 2013
1 parent ce2233b commit 52f971e
Show file tree
Hide file tree
Showing 11 changed files with 434 additions and 917 deletions.
4 changes: 4 additions & 0 deletions di.c
Expand Up @@ -306,6 +306,10 @@ void dicput(context *ctx, mfile *mem, object d, object k, object v) {
dicgrow(ctx, d);
goto retry;
}
if (type(e[0]) == invalidtype) {
fprintf(stderr, "warning: invalidtype key in dict\n");
e[0] = null;
}
if (type(e[0]) == nulltype) {
if (dicfull(mem, d)) {
//error("dict full");
Expand Down
58 changes: 38 additions & 20 deletions itp.c
Expand Up @@ -290,28 +290,44 @@ void evalarray(context *ctx) {
}

void evalstring(context *ctx) {
object s;
object b,t,s;
s = pop(ctx->lo, ctx->es);
push(ctx->lo, ctx->os, s);
push(ctx->lo, ctx->es, consoper(ctx, "if", NULL,0,0));
push(ctx->lo, ctx->es, consoper(ctx, "cvx", NULL,0,0));
push(ctx->lo, ctx->es, cvlit(arrstrhandler));
push(ctx->lo, ctx->es, consname(ctx, "toke"));
//push(ctx->lo, ctx->es, consoper(ctx, "if", NULL,0,0));
//push(ctx->lo, ctx->es, consoper(ctx, "cvx", NULL,0,0));
//push(ctx->lo, ctx->es, cvlit(arrstrhandler));
//push(ctx->lo, ctx->es, consname(ctx, "token"));
opexec(ctx, consoper(ctx, "token",NULL,0,0).mark_.padw);
b = pop(ctx->lo, ctx->os);
if (b.int_.val) {
t = pop(ctx->lo, ctx->os);
s = pop(ctx->lo, ctx->os);
push(ctx->lo, ctx->es, s);
push(ctx->lo, type(t)==arraytype? ctx->os: ctx->es, t);
}
}

void evalfile(context *ctx) {
object f;
object b,f,t;
f = pop(ctx->lo, ctx->es);
if (filestatus(ctx->lo, f)) {
object fs;
object str;
long fz;
push(ctx->lo, ctx->os, f);
//if (filestatus(ctx->lo, f)) {
//object fs;
//object str;
//long fz;
//push(ctx->lo, ctx->es, f);
//fs = consfile(ctx->lo, statementedit(filefile(ctx->lo, f)));
//fz = filebytesavailable(ctx->lo, fs);
//str = consbst(ctx, fz, NULL);
//fread(charstr(ctx, str), 1, fz, filefile(ctx->lo, fs));
//push(ctx->lo, ctx->es, cvx(str));
//}
opexec(ctx, consoper(ctx, "token",NULL,0,0).mark_.padw);
b = pop(ctx->lo, ctx->os);
if (b.int_.val) {
t = pop(ctx->lo, ctx->os);
push(ctx->lo, ctx->es, f);
fs = consfile(ctx->lo, statementedit(filefile(ctx->lo, f)));
fz = filebytesavailable(ctx->lo, fs);
str = consbst(ctx, fz, NULL);
fread(charstr(ctx, str), 1, fz, filefile(ctx->lo, fs));
push(ctx->lo, ctx->es, cvx(str));
push(ctx->lo, type(t)==arraytype? ctx->os: ctx->es, t);
}
}

Expand Down Expand Up @@ -427,19 +443,21 @@ int main(void) {
//push(ctx->lo, ctx->os, consbst(ctx, CNT_STR(" {1 2 3.14 true} ")));
//push(ctx->lo, ctx->os, consbst(ctx, CNT_STR(" //false ")));
//push(ctx->lo, ctx->es, cvx(consbst(ctx, CNT_STR(" 1 2 add 3 mul 4 div "))));
push(ctx->lo, ctx->es, cvx(consbst(ctx, CNT_STR(" \n\
(%stdin)(r) file cvx exec \
"))));
push(ctx->lo, ctx->es, cvx(consbst(ctx,
CNT_STR(" (init.ps) (r) file cvx exec (%stdin) run quit "))));

//push(ctx->lo, ctx->os, cvx(consname(ctx,"toke")));
//push(ctx->lo, ctx->os, cvx(consname(ctx,"token")));
//dumpobject(top(ctx->lo, ctx->os, 0));
//dumpstack(ctx->gl, adrent(ctx->gl, NAMES));
//dumpdic(ctx->gl, top(ctx->lo, ctx->ds, 0));
fflush(NULL);
//push(ctx->lo, ctx->es, consname(ctx, "load"));
//push(ctx->lo, ctx->es, cvx(consname(ctx, "tokeloop")));
//dumpoper(ctx, 12);

printf("ctx->lo:\n");
dumpmfile(ctx->lo);
dumpmtab(ctx->lo, 0);

ctx->quit = 0;
mainloop(ctx);

Expand Down
8 changes: 4 additions & 4 deletions nm.c
Expand Up @@ -149,25 +149,25 @@ int main(void) {
printf("pop ");
dumpobject(consname(ctx, "pop"));
printf("NAMES at %u\n", adrent(ctx->gl, NAMES));
dumpstack(ctx->gl, adrent(ctx->gl, NAMES)); puts("");
//dumpstack(ctx->gl, adrent(ctx->gl, NAMES)); puts("");

printf("apple ");
dumpobject(consname(ctx, "apple"));
dumpobject(consname(ctx, "apple"));
//printf("NAMES at %u\n", adrent(ctx->gl, NAMES));
dumpstack(ctx->gl, adrent(ctx->gl, NAMES)); puts("");
//dumpstack(ctx->gl, adrent(ctx->gl, NAMES)); puts("");

printf("banana ");
dumpobject(consname(ctx, "banana"));
dumpobject(consname(ctx, "banana"));
//printf("NAMES at %u\n", adrent(ctx->gl, NAMES));
dumpstack(ctx->gl, adrent(ctx->gl, NAMES)); puts("");
//dumpstack(ctx->gl, adrent(ctx->gl, NAMES)); puts("");

printf("currant ");
dumpobject(consname(ctx, "currant"));
dumpobject(consname(ctx, "currant"));
//printf("NAMES at %u\n", adrent(ctx->gl, NAMES));
dumpstack(ctx->gl, adrent(ctx->gl, NAMES)); puts("");
//dumpstack(ctx->gl, adrent(ctx->gl, NAMES)); puts("");

printf("apple ");
dumpobject(consname(ctx, "apple"));
Expand Down
6 changes: 6 additions & 0 deletions ob.c
Expand Up @@ -18,6 +18,12 @@ int faccess(object o) {
return (o.tag & FACCESS) >> FACCESSO;
}

object setfaccess(object o, int access) {
o.tag &= ~FACCESS;
o.tag |= (access << FACCESSO);
return o;
}

int isreadable(object o) {
if (type(o) == filetype) {
return faccess(o) == readonly;
Expand Down
1 change: 1 addition & 0 deletions ob.h
Expand Up @@ -111,6 +111,7 @@ int type(object o);
int isx(object o);
int islit(object o);
int faccess(object o);
object setfaccess(object o, int access);
int isreadable(object o);
int iswriteable(object o);

Expand Down
36 changes: 12 additions & 24 deletions op.c
Expand Up @@ -257,55 +257,43 @@ void initop(context *ctx) {
initops(ctx, sd);

//#ifdef DEBUGOP
printf("\nops:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nops:\n"); dumpdic(ctx->gl, sd); fflush(NULL);
//#endif

op = consoper(ctx, "breakhere", breakhere, 0, 0); INSTALL;

initopst(ctx, sd);
printf("\nopst:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nopst:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

initopar(ctx, sd);
printf("\nopar:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nopar:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

initopdi(ctx, sd);
printf("\nopdi:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nopdi:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

initopb(ctx, sd);
printf("\nopb:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nopb:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

initopc(ctx, sd);
printf("\nopc:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nopc:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

initopt(ctx, sd);
printf("\nopt:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nopt:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

initoptok(ctx, sd);
printf("\noptok:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\noptok:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

initopm(ctx, sd);
printf("\nopm:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nopm:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

initopf(ctx, sd);
printf("\nopf:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nopf:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

initopv(ctx, sd);
printf("\nopv:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nopv:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

initopx(ctx, sd);
printf("\nopx:\n");
dumpdic(ctx->gl, sd); fflush(NULL);
//printf("\nopx:\n"); dumpdic(ctx->gl, sd); fflush(NULL);

//push(ctx->lo, ctx->ds, sd); // push systemdict on dictstack

Expand Down
1 change: 1 addition & 0 deletions opar.h
@@ -1,4 +1,5 @@
/* array operators */

void arrtomark(context *ctx);
void initopar(context *ctx, object sd);

6 changes: 5 additions & 1 deletion opdi.c
@@ -1,4 +1,4 @@
//#define DEBUGLOAD
#define DEBUGLOAD

#include <stdbool.h>
#include <stdio.h>
Expand Down Expand Up @@ -52,7 +52,11 @@ void Zend(context *ctx) {
/* key value def -
associate key with value in current dict */
void Adef(context *ctx, object K, object V) {
object D = top(ctx->lo, ctx->ds, 0);
dumpdic(bank(ctx, D), D); puts("");
bdcput(ctx, top(ctx->lo, ctx->ds, 0), K, V);
puts("!def!");
dumpdic(bank(ctx, D), D); puts("");
}

/* dict key known bool
Expand Down
7 changes: 7 additions & 0 deletions opf.c
Expand Up @@ -188,6 +188,12 @@ void Zcurrentfile (context *ctx) {
push(ctx->lo, ctx->os, consfile(ctx->lo, NULL));
}

void Sprint (context *ctx, object S) {
char *s;
s = charstr(ctx, S);
fwrite(s, 1, S.comp_.sz, stdout);
}

void Becho (context *ctx, object b) {
if (b.int_.val)
echoon(stdin);
Expand All @@ -214,6 +220,7 @@ void initopf (context *ctx, object sd) {
op = consoper(ctx, "resetfile", Fresetfile, 0, 1, filetype); INSTALL;
op = consoper(ctx, "status", Fstatus, 1, 1, filetype); INSTALL;
op = consoper(ctx, "currentfile", Zcurrentfile, 1, 0); INSTALL;
op = consoper(ctx, "print", Sprint, 0, 1, stringtype); INSTALL;
op = consoper(ctx, "echo", Becho, 0, 1, booleantype); INSTALL;

/* dumpdic(ctx->gl, sd); fflush(NULL);
Expand Down

0 comments on commit 52f971e

Please sign in to comment.