Take input in standalone. Print numbers as chars
This commit is contained in:
parent
f8176fef4f
commit
e0153528a1
|
@ -230,7 +230,11 @@ struct Environment defaultEnv()
|
||||||
{"ap", &append}, {"pre", &prepend},
|
{"ap", &append}, {"pre", &prepend},
|
||||||
{"at", &at}, {"rest", &rest}, {"rev", &reverse},
|
{"at", &at}, {"rest", &rest}, {"rev", &reverse},
|
||||||
{"isnum", &isNum}, {"isstr", &isString},
|
{"isnum", &isNum}, {"isstr", &isString},
|
||||||
{"prn", &print}, {"penv", &printEnvO}, {"eval", &parseEvalO},
|
{"prn", &print}, {"pch", &pChar}, {"penv", &printEnvO},
|
||||||
|
{"eval", &parseEvalO},
|
||||||
|
#ifdef STANDALONE
|
||||||
|
{"inp", &takeInput},
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
for(unsigned i = 0; i < sizeof(symFuncs)/sizeof(symFuncs[0]); i++) {
|
for(unsigned i = 0; i < sizeof(symFuncs)/sizeof(symFuncs[0]); i++) {
|
||||||
|
|
|
@ -406,6 +406,15 @@ Object print(Object p, Object ignore, struct Environment *env)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object pChar(Object c, Object i1, struct Environment *i2)
|
||||||
|
{
|
||||||
|
if(c.type != TYPE_NUMBER) {
|
||||||
|
return errorObject(BAD_NUMBER);
|
||||||
|
}
|
||||||
|
printf("%c", c.number % 256);
|
||||||
|
return numberObject(0);
|
||||||
|
}
|
||||||
|
|
||||||
Object printEnvO(Object i1, Object i2, struct Environment *env) {
|
Object printEnvO(Object i1, Object i2, struct Environment *env) {
|
||||||
while(env->outer) {
|
while(env->outer) {
|
||||||
env = env-> outer;
|
env = env-> outer;
|
||||||
|
@ -423,6 +432,15 @@ Object parseEvalO(Object text, Object ignore, struct Environment *env)
|
||||||
return parseEval(text.string, env);
|
return parseEval(text.string, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef STANDALONE
|
||||||
|
Object takeInput(Object i1, Object i2, struct Environment *i3)
|
||||||
|
{
|
||||||
|
char input[256] = "";
|
||||||
|
fgets(input, 256, stdin);
|
||||||
|
return stringFromSlice(input, strlen(input) - 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void copySlice(char * dest, struct Slice *src)
|
void copySlice(char * dest, struct Slice *src)
|
||||||
{
|
{
|
||||||
if(!dest || !src)
|
if(!dest || !src)
|
||||||
|
|
|
@ -59,7 +59,12 @@ Object isNum(Object test, Object ignore, struct Environment *ignore2);
|
||||||
Object isString(Object test, Object ignore, struct Environment *ignore2);
|
Object isString(Object test, Object ignore, struct Environment *ignore2);
|
||||||
|
|
||||||
Object print(Object p, Object ignore, struct Environment *ignore2);
|
Object print(Object p, Object ignore, struct Environment *ignore2);
|
||||||
|
Object pChar(Object c, Object i1, struct Environment *i2);
|
||||||
Object printEnvO(Object i1, Object i2, struct Environment *env);
|
Object printEnvO(Object i1, Object i2, struct Environment *env);
|
||||||
Object parseEvalO(Object text, Object ignore, struct Environment *env);
|
Object parseEvalO(Object text, Object ignore, struct Environment *env);
|
||||||
|
|
||||||
|
#ifdef STANDALONE
|
||||||
|
Object takeInput(Object i1, Object i2, struct Environment *i3);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue