if ($expr instanceof AtSign) { return 'new AtSign()'; } if ($expr instanceof Symbol) { return "Symbol::Make('{$expr->name}')"; } if ($expr instanceof Lambda) { return '<lambda:' . Expression::Render($expr->arguments) . '>'; } if ($expr instanceof Macro) { return '<macro:' . Expression::Render($expr->arguments) . '>'; } return '<' . get_class($expr) . '>'; } } $cmd = @$_SERVER['argv'][1]; if (is_readable($cmd)) { $start = microtime(TRUE); $input = file_get_contents($cmd); $expressions = Expression::Parse($input); echo "parsed {$_SERVER['argv'][1]} in " . number_format(microtime(TRUE) - $start, 4) . "s\n"; $compiler = new LizpCompiler(); $start = microtime(TRUE); foreach ($expressions as $expr) { $compiler->Compile($expr); } $outfile = preg_replace('/\\.lizp$/', '.php', $cmd); $compiler->Optimize(); file_put_contents($outfile, $compiler->GetAsm() . "\n"); echo "{$outfile} created.\n"; }
function lizp_internal_fn_eval($env, $args) { if (count($args) != 1 || !is_string(@$args[0])) { throw new Exception("syntax (EVAL <str>)"); } $expr = Expression::Parse($args[0]); if (count($expr) > 1) { throw new Exception("Error: Multiple expressions given in " . Expression::Render($arg[0])); } return $env->Evaluate(@$expr[0]); }