feat: add this keyword support with method detection and error handling

Introduce TOKEN_THIS token and `this` keyword parsing in the compiler, enabling the `this` expression for method contexts. Add `isMethod` flag to Compiler struct to track whether the current function is a method, and pass it through `initCompiler`. Implement `this_` parsing function that emits appropriate bytecode or errors when used outside a method. Remove the now-unnecessary `numLocals` field from ObjFn struct in vm.h. Add test cases for `this` at top level (expects error), in a method (valid usage), in a top-level function (expects error), and as a variable name (expects error).
This commit is contained in:
Bob Nystrom
2013-11-09 23:42:23 +00:00
parent 04dda643d0
commit 98d6bbbcc1
6 changed files with 76 additions and 38 deletions
+1
View File
@@ -0,0 +1 @@
this // expect error