From a69534fc217666d53a418605de0ebb0879cbb2f7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 29 Oct 2004 11:22:49 +0000 Subject: * Drop ATmake / ATMatcher also in handling store expressions. --- src/libexpr/Makefile.am | 11 ++--- src/libexpr/aterm-helper.pl | 108 ------------------------------------------- src/libexpr/constructors.def | 53 --------------------- src/libexpr/eval.cc | 4 +- src/libexpr/nixexpr-ast.def | 55 ++++++++++++++++++++++ src/libexpr/nixexpr.cc | 4 +- src/libexpr/parser.cc | 2 +- src/libexpr/parser.y | 2 +- src/libexpr/primops.cc | 2 +- 9 files changed, 67 insertions(+), 174 deletions(-) delete mode 100755 src/libexpr/aterm-helper.pl delete mode 100644 src/libexpr/constructors.def create mode 100644 src/libexpr/nixexpr-ast.def (limited to 'src/libexpr') diff --git a/src/libexpr/Makefile.am b/src/libexpr/Makefile.am index a52b4710d235..d7de30855c11 100644 --- a/src/libexpr/Makefile.am +++ b/src/libexpr/Makefile.am @@ -3,10 +3,9 @@ noinst_LIBRARIES = libexpr.a libexpr_a_SOURCES = nixexpr.cc nixexpr.hh parser.cc parser.hh \ eval.cc eval.hh primops.cc \ lexer-tab.c lexer-tab.h parser-tab.c parser-tab.h \ - constructors.hh + nixexpr-ast.hh -EXTRA_DIST = lexer.l parser.y constructors.def constructors.cc \ - aterm-helper.pl +EXTRA_DIST = lexer.l parser.y nixexpr-ast.def nixexpr-ast.cc AM_CXXFLAGS = \ -I.. ${bdb_include} ${aterm_include} -I../libutil -I../libstore @@ -27,10 +26,10 @@ lexer-tab.c lexer-tab.h: lexer.l # ATerm helper function generation. -constructors.cc constructors.hh: aterm-helper.pl constructors.def - $(perl) aterm-helper.pl constructors.hh constructors.cc < constructors.def +nixexpr-ast.cc nixexpr-ast.hh: ../aterm-helper.pl nixexpr-ast.def + $(perl) ../aterm-helper.pl nixexpr-ast.hh nixexpr-ast.cc < nixexpr-ast.def -nixexpr.hh: constructors.hh +nixexpr.hh: nixexpr-ast.hh CLEANFILES = diff --git a/src/libexpr/aterm-helper.pl b/src/libexpr/aterm-helper.pl deleted file mode 100755 index 9a1a931a91b6..000000000000 --- a/src/libexpr/aterm-helper.pl +++ /dev/null @@ -1,108 +0,0 @@ -#! /usr/bin/perl -w - -die if scalar @ARGV != 2; - -my $syms = ""; -my $init = ""; - -open HEADER, ">$ARGV[0]"; -open IMPL, ">$ARGV[1]"; - -while () { - next if (/^\s*$/); - - if (/^\s*(\w+)\s*\|([^\|]*)\|\s*(\w+)\s*\|\s*(\w+)?/) { - my $const = $1; - my @types = split ' ', $2; - my $result = $3; - my $funname = $4; - $funname = $const unless defined $funname; - - my $formals = ""; - my $formals2 = ""; - my $args = ""; - my $unpack = ""; - my $n = 1; - foreach my $type (@types) { - $args .= ", "; - if ($type eq "string") { -# $args .= "(ATerm) ATmakeAppl0(ATmakeAFun((char *) e$n, 0, ATtrue))"; -# $type = "const char *"; - $type = "ATerm"; - $args .= "e$n"; - } elsif ($type eq "int") { - $args .= "(ATerm) ATmakeInt(e$n)"; - } elsif ($type eq "ATermList" || $type eq "ATermBlob") { - $args .= "(ATerm) e$n"; - } else { - $args .= "e$n"; - } - $formals .= ", " if $formals ne ""; - $formals .= "$type e$n"; - $formals2 .= ", "; - $formals2 .= "$type & e$n"; - my $m = $n - 1; - if ($type eq "int") { - $unpack .= " e$n = ATgetInt((ATermInt) ATgetArgument(e, $m));\n"; - } elsif ($type eq "ATermList") { - $unpack .= " e$n = (ATermList) ATgetArgument(e, $m);\n"; - } elsif ($type eq "ATermBlob") { - $unpack .= " e$n = (ATermBlob) ATgetArgument(e, $m);\n"; - } else { - $unpack .= " e$n = ATgetArgument(e, $m);\n"; - } - $n++; - } - - my $arity = scalar @types; - - print HEADER "extern AFun sym$funname;\n\n"; - - print IMPL "AFun sym$funname = 0;\n"; - - print HEADER "static inline $result make$funname($formals) {\n"; - print HEADER " return (ATerm) ATmakeAppl$arity(sym$funname$args);\n"; - print HEADER "}\n\n"; - - print HEADER "#ifdef __cplusplus\n"; - print HEADER "static inline bool match$funname(ATerm e$formals2) {\n"; - print HEADER " if (ATgetType(e) != AT_APPL || ATgetAFun(e) != sym$funname) return false;\n"; - print HEADER "$unpack"; - print HEADER " return true;\n"; - print HEADER "}\n"; - print HEADER "#endif\n\n\n"; - - $init .= " sym$funname = ATmakeAFun(\"$const\", $arity, ATfalse);\n"; - $init .= " ATprotectAFun(sym$funname);\n"; - } - - elsif (/^\s*(\w+)\s*=\s*(.*)$/) { - my $name = $1; - my $value = $2; - print HEADER "extern ATerm $name;\n"; - print IMPL "ATerm $name = 0;\n"; - $init .= " $name = $value;\n"; - } - - else { - die "bad line: `$_'"; - } -} - -print HEADER "void initSyms();\n\n"; - -print HEADER "static inline ATerm string2ATerm(const char * s) {\n"; -print HEADER " return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue));\n"; -print HEADER "}\n\n"; - -print HEADER "static inline const char * aterm2String(ATerm t) {\n"; -print HEADER " return (const char *) ATgetName(ATgetAFun(t));\n"; -print HEADER "}\n\n"; - -print IMPL "\n"; -print IMPL "void initSyms() {\n"; -print IMPL "$init"; -print IMPL "}\n"; - -close HEADER; -close IMPL; diff --git a/src/libexpr/constructors.def b/src/libexpr/constructors.def deleted file mode 100644 index 497cd33c336d..000000000000 --- a/src/libexpr/constructors.def +++ /dev/null @@ -1,53 +0,0 @@ -Pos | string int int | Pos | -NoPos | | Pos | - -Function | ATermList Expr Pos | Expr | -Function1 | string Expr Pos | Expr | -Assert | Expr Expr Pos | Expr | -With | Expr Expr Pos | Expr | -If | Expr Expr Expr | Expr | -OpNot | Expr | Expr | -OpEq | Expr Expr | Expr | -OpNEq | Expr Expr | Expr | -OpAnd | Expr Expr | Expr | -OpOr | Expr Expr | Expr | -OpImpl | Expr Expr | Expr | -OpUpdate | Expr Expr | Expr | -SubPath | Expr Expr | Expr | -OpHasAttr | Expr string | Expr | -OpPlus | Expr Expr | Expr | -Call | Expr Expr | Expr | -Select | Expr string | Expr | -Var | string | Expr | -Int | int | Expr | -Str | string | Expr | -Path | string | Expr | -Uri | string | Expr | -List | ATermList | Expr | -BlackHole | | Expr | -Undefined | | Expr | -PrimOp | int ATermBlob ATermList | Expr | -Attrs | ATermList | Expr | -Closed | Expr | Expr | -Rec | ATermList ATermList | Expr | -Bool | ATerm | Expr | -Null | | Expr | - -Bind | string Expr Pos | ATerm | -Bind | string Expr | ATerm | Bind2 -Inherit | Expr ATermList Pos | ATerm | - -Scope | | Expr | - -NoDefFormal | string | ATerm | -DefFormal | string Expr | ATerm | - -True | | ATerm | -False | | ATerm | - -PrimOpDef | int ATermBlob | ATerm | - -AttrRHS | Expr Pos | ATerm | - -eTrue = makeBool(makeTrue()) -eFalse = makeBool(makeFalse()) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 88362333c29d..cef346002962 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1,6 +1,6 @@ #include "eval.hh" #include "parser.hh" -#include "constructors.hh" +#include "nixexpr-ast.hh" EvalState::EvalState() @@ -10,7 +10,7 @@ EvalState::EvalState() nrEvaluated = nrCached = 0; - initSyms(); + initNixExprHelpers(); addPrimOps(); } diff --git a/src/libexpr/nixexpr-ast.def b/src/libexpr/nixexpr-ast.def new file mode 100644 index 000000000000..19601847cf32 --- /dev/null +++ b/src/libexpr/nixexpr-ast.def @@ -0,0 +1,55 @@ +init initNixExprHelpers + +Pos | string int int | Pos | +NoPos | | Pos | + +Function | ATermList Expr Pos | Expr | +Function1 | string Expr Pos | Expr | +Assert | Expr Expr Pos | Expr | +With | Expr Expr Pos | Expr | +If | Expr Expr Expr | Expr | +OpNot | Expr | Expr | +OpEq | Expr Expr | Expr | +OpNEq | Expr Expr | Expr | +OpAnd | Expr Expr | Expr | +OpOr | Expr Expr | Expr | +OpImpl | Expr Expr | Expr | +OpUpdate | Expr Expr | Expr | +SubPath | Expr Expr | Expr | +OpHasAttr | Expr string | Expr | +OpPlus | Expr Expr | Expr | +Call | Expr Expr | Expr | +Select | Expr string | Expr | +Var | string | Expr | +Int | int | Expr | +Str | string | Expr | +Path | string | Expr | +Uri | string | Expr | +List | ATermList | Expr | +BlackHole | | Expr | +Undefined | | Expr | +PrimOp | int ATermBlob ATermList | Expr | +Attrs | ATermList | Expr | +Closed | Expr | Expr | +Rec | ATermList ATermList | Expr | +Bool | ATerm | Expr | +Null | | Expr | + +Bind | string Expr Pos | ATerm | +Bind | string Expr | ATerm | Bind2 +Inherit | Expr ATermList Pos | ATerm | + +Scope | | Expr | + +NoDefFormal | string | ATerm | +DefFormal | string Expr | ATerm | + +True | | ATerm | +False | | ATerm | + +PrimOpDef | int ATermBlob | ATerm | + +AttrRHS | Expr Pos | ATerm | + +eTrue = makeBool(makeTrue()) +eFalse = makeBool(makeFalse()) diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index cbfb5576bf04..56e053fd7ae4 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -2,8 +2,8 @@ #include "storeexpr.hh" -#include "constructors.hh" -#include "constructors.cc" +#include "nixexpr-ast.hh" +#include "nixexpr-ast.cc" ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct) diff --git a/src/libexpr/parser.cc b/src/libexpr/parser.cc index a0a6c01df762..8a199c00263f 100644 --- a/src/libexpr/parser.cc +++ b/src/libexpr/parser.cc @@ -7,7 +7,7 @@ #include "aterm.hh" #include "parser.hh" -#include "constructors.hh" +#include "nixexpr-ast.hh" struct ParseData diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 2864b1600e73..8573697b634d 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -18,7 +18,7 @@ typedef ATerm Expr; typedef ATerm Pos; -#include "constructors.hh" +#include "nixexpr-ast.hh" void setParseResult(void * data, ATerm t); void parseError(void * data, char * error, int line, int column); diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index e230d35ce6b1..830a2c095839 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1,7 +1,7 @@ #include "normalise.hh" #include "eval.hh" #include "globals.hh" -#include "constructors.hh" +#include "nixexpr-ast.hh" /* Load and evaluate an expression from path specified by the -- cgit 1.4.1