ref: dcb761aebd2815fdf2d04c0b05724292de9dc98b
dir: /value.c/
#include <u.h>
#include <libc.h>
#include <thread.h>
#include "dat.h"
#include "fns.h"
/* Anything that can have a name in LPA: Arrays, functions, ... */
char *
printval(void *v)
{
if(v)
return smprint("some value: %p :)", v);
else
return smprint("no value :(");
}
void *
parseval(char *buf, char **errp)
{
Ast *ast;
void *val = nil;
TokenList *tokens = scan(buf, errp);
if(tokens == nil)
goto end;
ast = parse(tokens, errp);
if(ast == nil)
goto end;
/* Check that the ast is either a single function definition,
* or a single constant.
*/
if(!(ast->tag == AstProg && ast->childcount == 1)){
*errp = "Expected single value or function definition";
goto end;
}
ast = ast->children[0];
switch(ast->tag){
case AstConst:
val = ast->val;
break;
case AstFunc:
*errp = "Functions not supported yet";
break;
default:
*errp = "Expected constant or function definition";
goto end;
}
end:
return val;
}