Class: Stone::AST::StringLiteral
- Inherits:
-
Expression
- Object
- Stone::AST
- Expression
- Stone::AST::StringLiteral
- Defined in:
- lib/stone/ast/string_literal.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Stone::AST
Class Method Summary collapse
Instance Method Summary collapse
-
#bytesize ⇒ Object
Byte count (for system/memory operations).
-
#initialize(value) ⇒ StringLiteral
constructor
A new instance of StringLiteral.
-
#length ⇒ Object
Character count (for user-facing string length).
- #to_llir(builder, mod, _scope = Stone::Scope.top_level) ⇒ Object
- #type(_context = nil) ⇒ Object
Constructor Details
#initialize(value) ⇒ StringLiteral
Returns a new instance of StringLiteral.
18 19 20 21 |
# File 'lib/stone/ast/string_literal.rb', line 18 def initialize(value) @name = :string_literal @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
16 17 18 |
# File 'lib/stone/ast/string_literal.rb', line 16 def value @value end |
Class Method Details
Instance Method Details
#bytesize ⇒ Object
Byte count (for system/memory operations)
24 25 26 |
# File 'lib/stone/ast/string_literal.rb', line 24 def bytesize @value.bytesize end |
#length ⇒ Object
Character count (for user-facing string length)
29 30 31 |
# File 'lib/stone/ast/string_literal.rb', line 29 def length @value.length end |
#to_llir(builder, mod, _scope = Stone::Scope.top_level) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/stone/ast/string_literal.rb', line 33 def to_llir(builder, mod, _scope = Stone::Scope.top_level) string_global = create_global_string(mod) # Get pointer to the string data (GEP to first element) # Array size is bytesize + 1 for null terminator builder.gep2( LLVM::Type.array(LLVM::Int8, @value.bytesize + 1), string_global, [LLVM::Int64.from_i(0), LLVM::Int64.from_i(0)], "string_ptr" ) # Return pointer directly - no ptr2int (CHERI-safe) end |