Merge pull request 'type-section-rework' (#6) from type-section-rework into main
Reviewed-on: arf/arf#6
This commit is contained in:
commit
844b1562c4
@ -4,6 +4,6 @@ require "io"
|
|||||||
|
|
||||||
func ro main
|
func ro main
|
||||||
> arguments:{String ..}
|
> arguments:{String ..}
|
||||||
< status:Int 0
|
< status:Int:<0>
|
||||||
---
|
---
|
||||||
io.println "hello world"
|
io.println "hello world"
|
||||||
|
|||||||
@ -5,18 +5,18 @@ require "io"
|
|||||||
---
|
---
|
||||||
|
|
||||||
# this is a global variable
|
# this is a global variable
|
||||||
data pv helloText:String "Hello, world!"
|
data pv helloText:String:<"Hello, world!">
|
||||||
|
|
||||||
# this is a struct definition
|
# this is a struct definition
|
||||||
objt ro Greeter:Obj
|
type ro Greeter:Obj:(
|
||||||
rw text:String "Hi."
|
.rw text:String:<"Hi.">)
|
||||||
|
|
||||||
# this is a function
|
# this is a function
|
||||||
func ro main
|
func ro main
|
||||||
> arguments:{String ..}
|
> arguments:{String ..}
|
||||||
< status:Int 0
|
< status:Int:<0>
|
||||||
---
|
---
|
||||||
= greeter:Greeter:mut
|
let greeter:Greeter:mut
|
||||||
greeter.setText helloText
|
greeter.setText helloText
|
||||||
greeter.greet
|
greeter.greet
|
||||||
|
|
||||||
|
|||||||
@ -192,6 +192,16 @@ func (lexer *LexingOperation) tokenizeSymbolBeginning () (err error) {
|
|||||||
token.kind = TokenKindComma
|
token.kind = TokenKindComma
|
||||||
lexer.addToken(token)
|
lexer.addToken(token)
|
||||||
err = lexer.nextRune()
|
err = lexer.nextRune()
|
||||||
|
case '(':
|
||||||
|
token := lexer.newToken()
|
||||||
|
token.kind = TokenKindLParen
|
||||||
|
lexer.addToken(token)
|
||||||
|
err = lexer.nextRune()
|
||||||
|
case ')':
|
||||||
|
token := lexer.newToken()
|
||||||
|
token.kind = TokenKindRParen
|
||||||
|
lexer.addToken(token)
|
||||||
|
err = lexer.nextRune()
|
||||||
case '[':
|
case '[':
|
||||||
token := lexer.newToken()
|
token := lexer.newToken()
|
||||||
token.kind = TokenKindLBracket
|
token.kind = TokenKindLBracket
|
||||||
|
|||||||
@ -138,6 +138,8 @@ func TestTokenizeAll (test *testing.T) {
|
|||||||
quickToken(1, TokenKindDot, nil),
|
quickToken(1, TokenKindDot, nil),
|
||||||
quickToken(1, TokenKindComma, nil),
|
quickToken(1, TokenKindComma, nil),
|
||||||
quickToken(2, TokenKindElipsis, nil),
|
quickToken(2, TokenKindElipsis, nil),
|
||||||
|
quickToken(1, TokenKindLParen, nil),
|
||||||
|
quickToken(1, TokenKindRParen, nil),
|
||||||
quickToken(1, TokenKindLBracket, nil),
|
quickToken(1, TokenKindLBracket, nil),
|
||||||
quickToken(1, TokenKindRBracket, nil),
|
quickToken(1, TokenKindRBracket, nil),
|
||||||
quickToken(1, TokenKindLBrace, nil),
|
quickToken(1, TokenKindLBrace, nil),
|
||||||
|
|||||||
@ -28,6 +28,8 @@ const (
|
|||||||
TokenKindElipsis
|
TokenKindElipsis
|
||||||
TokenKindComma
|
TokenKindComma
|
||||||
|
|
||||||
|
TokenKindLParen
|
||||||
|
TokenKindRParen
|
||||||
TokenKindLBracket
|
TokenKindLBracket
|
||||||
TokenKindRBracket
|
TokenKindRBracket
|
||||||
TokenKindLBrace
|
TokenKindLBrace
|
||||||
@ -166,6 +168,10 @@ func (tokenKind TokenKind) Describe () (description string) {
|
|||||||
description = "Elipsis"
|
description = "Elipsis"
|
||||||
case TokenKindComma:
|
case TokenKindComma:
|
||||||
description = "Comma"
|
description = "Comma"
|
||||||
|
case TokenKindLParen:
|
||||||
|
description = "LParen"
|
||||||
|
case TokenKindRParen:
|
||||||
|
description = "RParen"
|
||||||
case TokenKindLBracket:
|
case TokenKindLBracket:
|
||||||
description = "LBracket"
|
description = "LBracket"
|
||||||
case TokenKindRBracket:
|
case TokenKindRBracket:
|
||||||
|
|||||||
@ -29,12 +29,6 @@ func (section TypeSection) Kind () (kind SectionKind) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kind returns the section's kind (SectionKindObjt).
|
|
||||||
func (section ObjtSection) Kind () (kind SectionKind) {
|
|
||||||
kind = SectionKindObjt
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kind returns the section's kind (SectionKindEnum).
|
// Kind returns the section's kind (SectionKindEnum).
|
||||||
func (section EnumSection) Kind () (kind SectionKind) {
|
func (section EnumSection) Kind () (kind SectionKind) {
|
||||||
kind = SectionKindEnum
|
kind = SectionKindEnum
|
||||||
@ -111,23 +105,23 @@ func (what Type) Points () (points Type) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Values returns an iterator for the initialization values.
|
// MembersLength returns the amount of new members the type specifier defines.
|
||||||
func (values ObjectInitializationValues) Sections () (
|
// If it defines no new members, it returns zero.
|
||||||
iterator types.Iterator[Argument],
|
func (what Type) MembersLength () (length int) {
|
||||||
) {
|
length = len(what.members)
|
||||||
iterator = types.NewIterator(values.attributes)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Length returns the amount of values.
|
// Member returns the member at index.
|
||||||
func (values ArrayInitializationValues) Length () (length int) {
|
func (what Type) Member (index int) (member TypeMember) {
|
||||||
length = len(values.values)
|
member = what.members[index]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Item returns the value at index.
|
// BitWidth returns the bit width of the type member. If it is zero, it should
|
||||||
func (values ArrayInitializationValues) Value (index int) (value Argument) {
|
// be treated as unspecified.
|
||||||
value = values.values[index]
|
func (member TypeMember) BitWidth () (width uint64) {
|
||||||
|
width = member.bitWidth
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||