summaryrefslogtreecommitdiff
path: root/usr/austin/eval/expr.go
AgeCommit message (Collapse)AuthorFilesLines
2009-10-14move austin/eval and austin/ogle to exp/eval and exp/ogleRuss Cox1-2007/+0
R=r OCL=35736 CL=35746
2009-10-11interpreter checkpoint.Russ Cox1-11/+160
* generate different versions of binary operators for each size of int and float, so that proper truncating happens after each operation to simulate the various sized ops. * add slice expressions * publish World.CompileStmtList, CompileDeclList, CompileExpr * handle type-less expressions in CompileExpr R=austin DELTA=1459 (1327 added, 11 deleted, 121 changed) OCL=34382 CL=35581
2009-09-25s/switch _ :=/switch/Austin Clements1-2/+2
R=rsc APPROVED=rsc DELTA=36 (0 added, 0 deleted, 36 changed) OCL=34971 CL=35006
2009-09-24Fix declared and not used errors and unused import errors inAustin Clements1-23/+19
the interpreter and update code to use ast.BasicDecl and multi-type switch. There are still a lot of "switch _ := x.(type)" that should make use of the new type switch syntax, but those will be a different CL. R=rsc APPROVED=rsc DELTA=58 (16 added, 23 deleted, 19 changed) OCL=34853 CL=34963
2009-09-03Thread Thread into Value Get/Set/Assign so other ValueAustin Clements1-6/+6
implementations can abort. Make genConstant get values lazily since we need the Thread now. R=rsc APPROVED=rsc DELTA=299 (8 added, 19 deleted, 272 changed) OCL=34353 CL=34353
2009-09-03convert testing to World.Russ Cox1-41/+6
start on Decl, but not working yet R=austin DELTA=762 (201 added, 205 deleted, 356 changed) OCL=34335 CL=34349
2009-09-02convenience wrapperRuss Cox1-1/+19
R=austin DELTA=142 (128 added, 4 deleted, 10 changed) OCL=34275 CL=34284
2009-09-02move abortChan into Thread.Russ Cox1-10/+10
reuse Thread in function calls. R=austin DELTA=59 (8 added, 7 deleted, 44 changed) OCL=34266 CL=34266
2009-09-02s/vm/Thread/Russ Cox1-75/+80
change eval functions from taking *Frame to *Thread R=austin DELTA=500 (7 added, 4 deleted, 489 changed) OCL=34256 CL=34260
2009-09-01add generator for expr1.goRuss Cox1-97/+0
R=austin DELTA=959 (404 added, 99 deleted, 456 changed) OCL=34214 CL=34237
2009-09-01Switch back to returning Value from the public expressionAustin Clements1-23/+35
interface, but implement it better this time. Also, work around a 6g bug in asInterface. R=rsc APPROVED=rsc DELTA=39 (13 added, 1 deleted, 25 changed) OCL=34211 CL=34217
2009-09-01Clean up the statement and expression public interfaces. TheAustin Clements1-36/+25
only visible change is that evaluating an expression returns a interface{} instead of a Value. R=rsc APPROVED=rsc DELTA=60 (15 added, 26 deleted, 19 changed) OCL=34206 CL=34208
2009-09-01move generated code into its own file.Russ Cox1-866/+92
simplify expr by merging all simple eval functions into a single eval interface{}. R=austin DELTA=1597 (730 added, 780 deleted, 87 changed) OCL=34182 CL=34198
2009-08-28Implement cap, len, and make, as well as the general frameworkAustin Clements1-66/+326
for built-in functions and type conversions. Extract out common operations on expression nodes for converting them to ints and implicitly dereferencing arrays. R=rsc APPROVED=rsc DELTA=442 (365 added, 50 deleted, 27 changed) OCL=34064 CL=34064
2009-08-28Give NamedTypes a public interfaceAustin Clements1-1/+1
R=rsc APPROVED=rsc DELTA=32 (14 added, 1 deleted, 17 changed) OCL=34043 CL=34043
2009-08-28Implement runtime errors, divide-by-zero checking, nil pointerAustin Clements1-92/+59
checking, bounds checking, and map key checking. R=rsc APPROVED=rsc DELTA=202 (108 added, 72 deleted, 22 changed) OCL=33981 CL=34031
2009-08-27Make the statement compiler not use the AST visitor.Austin Clements1-2/+9
In the process, I made error handling in the statement compiler much saner. Instead of separately tracking various error flags with weird relations, I just track if any error messages have been produced. R=rsc APPROVED=rsc DELTA=308 (98 added, 135 deleted, 75 changed) OCL=33870 CL=33961
2009-08-25Make the expression compiler not use the AST visitor. TheAustin Clements1-446/+460
statement compiler will be fixed in a later CL. The input and output of the expression compiler are now clearly distinguished. In the process, I made the individual expression compilers operate on the compiled form of their children instead of AST nodes. As a result, there are now fewer places where I hand-craft intermediate expression nodes. The diff looks scarier than it is, mostly because exprCompiler has been split into the input and output types, resulting in lots of little renames. R=rsc APPROVED=rsc DELTA=774 (204 added, 199 deleted, 371 changed) OCL=33851 CL=33851
2009-08-24Make it only necessary to exit blocks, not scopes. AllowAustin Clements1-0/+2
variables to be given initial values in some cases, to make building global scopes more convenient. R=rsc APPROVED=rsc DELTA=29 (17 added, 0 deleted, 12 changed) OCL=33760 CL=33766
2009-08-21Implement map typesAustin Clements1-11/+139
R=rsc APPROVED=rsc DELTA=329 (301 added, 2 deleted, 26 changed) OCL=33696 CL=33706
2009-08-17Implement slice typesAustin Clements1-35/+139
R=rsc APPROVED=rsc DELTA=286 (217 added, 42 deleted, 27 changed) OCL=33319 CL=33383
2009-08-12Convert interpreter to whole-package compilation.Austin Clements1-30/+0
R=rsc APPROVED=rsc DELTA=334 (110 added, 211 deleted, 13 changed) OCL=33135 CL=33137
2009-08-10Implement switch statement. Can now extract effects fromAustin Clements1-24/+49
non-addressable expressions. R=rsc APPROVED=rsc DELTA=241 (202 added, 15 deleted, 24 changed) OCL=32790 CL=32995
2009-08-05Implement struct types, selector expressions, and typeAustin Clements1-9/+167
declarations. R=rsc APPROVED=rsc DELTA=587 (519 added, 21 deleted, 47 changed) OCL=32754 CL=32788
2009-07-31Implement type compatibility and fix places where I thoughtAustin Clements1-53/+46
types were supposed to be identical but only needed to be compatible. This gets rid of the Type.literal method. I renamed the Type.rep method to Type.lit because I believe it corresponds to the term "literal" as used in the spec. R=rsc APPROVED=rsc DELTA=228 (57 added, 35 deleted, 136 changed) OCL=32606 CL=32608
2009-07-30Implement labels, goto, labeled break, and labeled continue.Austin Clements1-4/+5
Return checking is now done as a general flow check at the end of function compilation, since break and goto complicated the way I was doing return checking before. Goto-over-declaration checking is also done as a final flow check. Temporary variables used for effect extraction are now actually temporary. Otherwise "op=", "++", and "--" appear as declarations that cannot be jumped over. R=rsc APPROVED=rsc DELTA=421 (344 added, 38 deleted, 39 changed) OCL=32527 CL=32535
2009-07-29Flatten the Frame tree. Now each function call produces aAustin Clements1-28/+40
single frame and non-overlapping variables reuse frame slots. As a result, entering and exiting blocks no longer requires code execution, which means jumps across block boundaries should be doable now. Frame slot initialization happens at definition time now, instead of at frame creation time. As an added bonus, Scope's are now exclusively compile-time objects and we no longer need to specially track the function activation frame for access to out vars. R=rsc APPROVED=rsc DELTA=313 (102 added, 90 deleted, 121 changed) OCL=32416 CL=32420
2009-07-28Implement comparison operators.Austin Clements1-21/+302
R=rsc APPROVED=rsc DELTA=304 (281 added, 0 deleted, 23 changed) OCL=32361 CL=32382
2009-07-27Implement multi-valued functions, multi-valued return, andAustin Clements1-79/+209
unpacking for assignments, call arguments, and returns. This change revamps the whole assignment compilation system to be multi-valued, using the new MultiType type and multiV value. Function calls, returns, and assignments now share a lot of code and produce very consistent error messages. R=rsc APPROVED=rsc DELTA=510 (335 added, 74 deleted, 101 changed) OCL=32248 CL=32258
2009-07-27Implement single-valued, non-variadic function literals andAustin Clements1-107/+368
function calling. Implement a type compiler and named types. Implement a universal scope containing built-in named types, and some built-in constants. Implement a simple virtual machine for executing statements and single-valued return. Fix many places that incorrectly dealt with named types. In particular, the Type.Zero methods now use the type's bit count to determine the appropriate value representation. As a result, a bit count of 0 now means architecture-dependent and bounded types use unsafe.Sizeof to determine the correct bounds. Previously, the bounds on a 32-bit machine would have been wrong. Eliminated Type.compatible, since the implementation is equivalent for all types. Added Type.rep that shallowly strips named types. Replaced almost all uses of Type.literal with Type.rep. Fix implementation of assign-op's so it only evaluates the left side once. As part of this, there is now a generic way to separate out the effect and value of an expression. R=rsc APPROVED=rsc DELTA=1530 (1244 added, 68 deleted, 218 changed) OCL=32184 CL=32230
2009-07-21Implement assignment. Move convertTo.Austin Clements1-93/+202
R=rsc APPROVED=rsc DELTA=591 (497 added, 76 deleted, 18 changed) OCL=31933 CL=31955
2009-07-21Cleanup of Type/Value interface. Add Type.ZeroVal, replaceAustin Clements1-16/+20
all type-specific value functions, and use ZeroVal to create new frames. Remove Value.Type; it was unused and difficult for values with composite types. Add Value.Assign methods. R=rsc APPROVED=rsc DELTA=282 (135 added, 90 deleted, 57 changed) OCL=31894 CL=31930
2009-07-20Implement array types and index expressions.Austin Clements1-40/+182
Some cleanup. Elem() on PtrType is now just Elem and matches with ArrayType. Generators now switch over the result type instead of the operand type. Delete unused diag function. R=rsc APPROVED=rsc DELTA=281 (219 added, 18 deleted, 44 changed) OCL=31876 CL=31891
2009-07-17Gather errors in a go.scanner.ErrorList instead of printingAustin Clements1-31/+33
them as we go. Lots of bug fixes. Let the parser toss illegal character and string literals. Compile unary + correctly. Allow float OP ideal. Compile unary * correctly. Implement min and max float values. R=rsc APPROVED=rsc DELTA=64 (29 added, 7 deleted, 28 changed) OCL=31811 CL=31814
2009-07-17Finish shift implementation for ideals.Austin Clements1-34/+46
R=rsc APPROVED=rsc DELTA=65 (29 added, 17 deleted, 19 changed) OCL=31775 CL=31777
2009-07-17Cleanup func literals. "func (" -> "func("Austin Clements1-39/+39
R=rsc APPROVED=rsc DELTA=41 (0 added, 0 deleted, 41 changed) OCL=31773 CL=31773
2009-07-17Implement all unary and binary arithmetic operators.Austin Clements1-186/+504
R=rsc APPROVED=rsc DELTA=689 (497 added, 169 deleted, 23 changed) OCL=31755 CL=31772
2009-07-15Make Value always represent an l-value and never a genericAustin Clements1-146/+295
container for values. Instead of having one evaluator function that returns a generic Value, there is now an evaluator function for each generalized type that simply returns a native type. The compiler is more type-safe now because there are almost no type conversions at evaluation time and it's impossible to invoke a nil evaluator function during evaluation. This also makes ideals and pointers really clean. As an added bonus, expression evaluation should be faster because it doesn't require heap allocation for every intermediate value, type switches, or lots of conversions to and from Value. It also involves fewer function calls. R=rsc APPROVED=rsc DELTA=431 (280 added, 115 deleted, 36 changed) OCL=31705 CL=31709
2009-07-15Beginnings of a Go interpreter. This implements basic andAustin Clements1-0/+695
pointer types, supports literals, identifiers, type-checking most unary and binary operators, "compiling" a few unary and binary operators, and assignment and declaration statements. R=rsc APPROVED=rsc DELTA=1751 (1751 added, 0 deleted, 0 changed) OCL=31309 CL=31691