Lox::Compiler
Constants
ARBITRARY = Token.new(TokenType::Nil, "", 0, 0)
The initial state of previous and current doesn't really matter,
because they get filled in with actual tokens from the scanner when we do
the compilation.
Instance methods
add_local!(name : Token)
The instructions to work with local variables refer to them by slot index, and that index is stored in a single-byte operand, which means our VM only supports up to Byte::MAX local variables in scope at a time.
advance!
Sourceand!(precedence : Precedence) : Nil
Sourceargument_list!
Compiles the arguments passed to a function and returns the number of arguments compiled.
begin_scope!
Sourcebinary!(precedence : Precedence) : Nil
Sourceblock!
Sourcecall!(precedence : Precedence) : Nil
Sourcecompile(input : String) : FunctionObject | Nil
TODO: Maybe this should return an error of some kind instead of Nil if the input fails to compile?
consume!(type : TokenType, message : String)
Sourcecurrent_chunk
Sourcecurrent_token_is(type : TokenType) : Bool
Sourcedeclaration!
Sourcedeclare_variable!
Sourcedefine_variable!(index : Byte)
Sourceemit_byte!(byte : Byte)
Sourceemit_bytes!(*bytes : Byte)
Sourceemit_constant!(value : Lox::Value)
Sourceemit_jump!(instruction : Opcode) : Int
Sourceemit_loop!(loop_start : Int)
Sourceemit_return!
Sourceend_scope!
Sourceerror!(message : String)
Sourceerror_at!(token : Token, message : String)
Sourceerror_at_current!(message : String)
Sourceexpression!
Sourceexpression_statement!
Sourcefor_statement!
Sourcefunction!(type : FunctionType)
Sourcefunction_declaration!
Sourcefunction_scope(name : String) : Scope
Sourcegrouping!(precedence : Precedence) : Nil
Sourceidentifier_constant!(name : Token) : Byte
Sourceif_statement!
Sourceliteral!(precedence : Precedence) : Nil
Sourcemark_initialized!
Sourcematch!(type : TokenType) : Bool
Sourcenamed_variable!(name : Token, precedence : Precedence)
Sourcenumber!(precedence : Precedence) : Nil
Sourceor!(precedence : Precedence) : Nil
Sourceparse_precedence!(precedence : Precedence)
Sourceparse_rule(operator_type : TokenType) : ParseRule
Sourceparse_variable!(error_msg : String) : Byte
Sourcepatch_jump!(offset : Int)
Sourceprevious_token_is(type : TokenType) : Bool
Sourceprint_statement!
Sourceresolve_local(scope : Scope, name : Token) : Byte | Nil
Sourcereturn_statement!
Sourcescope(enclosing : Scope | Nil, name : String, function_type : FunctionType) : Scope
Sourcescript_scope
Sourcestatement!
Sourcestring!(precedence : Precedence) : Nil
Sourcesynchronize!
Sourceunary!(precedence : Precedence) : Nil
Sourcevariable!(precedence : Precedence) : Nil
Sourcevariable_declaration!
Sourcewhile_statement!
Source