[scheme] Clean up a pile of rotten bits

This commit is contained in:
Bill Currie 2020-03-03 17:35:14 +09:00
parent b186332da0
commit 7976eec2ce
4 changed files with 32 additions and 28 deletions

View file

@ -14,6 +14,7 @@
int line;
string source;
}
+ (void) finishCollecting;
+ (void) collectCheckPoint;
- (void) mark;
- (void) markReachable;

View file

@ -1,13 +1,13 @@
@extern void (string str) print = #0;
@extern int () errno = #0;
@extern string (int err) strerror = #0;
@extern int (...) open = #0; // string path, float flags[, float mode]
@extern int (int handle) close = #0;
@extern string read (int handle, int count, int *result) = #0;
@extern int (int handle, string buffer, int count) write = #0;
@extern int (int handle, int pos, int whence) seek = #0;
@extern void (string str) print;
@extern int () errno;
@extern string (int err) strerror;
@extern int (...) open; // string path, float flags[, float mode]
@extern int (int handle) close;
@extern string read (int handle, int count, int *result);
@extern int (int handle, string buffer, int count) write;
@extern int (int handle, int pos, int whence) seek;
@extern void() traceon = #0; // turns statment trace on
@extern void() traceoff = #0;
@extern void() traceon; // turns statment trace on
@extern void() traceoff;
@extern void (...) printf = #0;
@extern void (...) printf;

View file

@ -3,7 +3,7 @@ int () errno = #0;
string (int err) strerror = #0;
int (...) open = #0; // string path, float flags[, float mode]
int (int handle) close = #0;
string (int handle, int count, int []result) read = #0;
string read (int handle, int count, int *result) = #0;
int (int handle, string buffer, int count) write = #0;
int (int handle, int pos, int whence) seek = #0;

View file

@ -22,23 +22,23 @@ string readfile (string filename)
str_copy(res, acc);
return res;
}
int main (int argc, string []argv)
int main (int argc, string *argv)
{
local Parser parser;
local CompiledCode code;
local Compiler comp;
local Machine vm;
local Lambda lm;
local SchemeObject stuff, res;
local Parser *parser;
local CompiledCode *code;
local Compiler *comp;
local Machine *vm;
local Lambda *lm;
local SchemeObject *stuff, *res;
local Error *err;
if (argc < 1) {
return -1;
}
//traceon();
parser = [Parser newFromSource: readfile(argv[1]) file: argv[1]];
vm = [Machine new];
[vm makeRootCell];
@ -46,26 +46,29 @@ int main (int argc, string []argv)
builtin_addtomachine (vm);
while ((stuff = [parser read])) {
if ([stuff isError]) {
printf(">> %s: %i\n", [stuff source], [stuff line]);
printf(">> Error (%s): %s\n", [stuff type], [stuff message]);
err = (Error *) stuff;
printf(">> %s: %i\n", [err source], [err line]);
printf(">> Error (%s): %s\n", [err type], [err message]);
return -1;
}
comp = [Compiler newWithLambda: cons ([Symbol forString: "lambda"],
cons ([Nil nil],
cons(stuff, [Nil nil])))
scope: nil];
code = (CompiledCode) [comp compile];
code = (CompiledCode *) [comp compile];
if ([code isError]) {
printf(">> %s: %i\n", [code source], [code line]);
printf(">> Error (%s): %s\n", [code type], [code message]);
err = (Error *) code;
printf(">> %s: %i\n", [err source], [err line]);
printf(">> Error (%s): %s\n", [err type], [err message]);
return -1;
}
lm = [Lambda newWithCode: code environment: nil];
[lm invokeOnMachine: vm];
res = [vm run];
if ([res isError]) {
printf(">> %s: %i\n", [res source], [res line]);
printf(">> Error (%s): %s\n", [res type], [res message]);
err = (Error *) res;
printf(">> %s: %i\n", [err source], [err line]);
printf(">> Error (%s): %s\n", [err type], [err message]);
return -1;
}
[vm reset];