String literals can be assigned to strings now
This commit is contained in:
@@ -69,7 +69,6 @@ func (this *Tree) analyzeLiteralString (
|
||||
fillUTF16 := func () {
|
||||
literal.ValueUTF16 = utf16.Encode([]rune(literal.ValueUTF8))
|
||||
}
|
||||
|
||||
switch base := base.(type) {
|
||||
case *entity.TypeInt:
|
||||
var length int; switch {
|
||||
@@ -97,7 +96,7 @@ func (this *Tree) analyzeLiteralString (
|
||||
}
|
||||
case *entity.TypeArray:
|
||||
element := ReduceToBase(base.Element)
|
||||
if element, ok := element.(*entity.TypeInt); !ok {
|
||||
if element, ok := element.(*entity.TypeInt); ok {
|
||||
var length int; switch {
|
||||
case element.Width >= 32:
|
||||
fillUTF32()
|
||||
@@ -120,7 +119,7 @@ func (this *Tree) analyzeLiteralString (
|
||||
}
|
||||
case *entity.TypeSlice:
|
||||
element := ReduceToBase(base.Element)
|
||||
if element, ok := element.(*entity.TypeInt); !ok {
|
||||
if element, ok := element.(*entity.TypeInt); ok {
|
||||
if element.Width >= 32 {
|
||||
fillUTF32()
|
||||
} else if element.Width >= 16 {
|
||||
|
||||
@@ -5,6 +5,8 @@ import "github.com/alecthomas/participle/v2/lexer"
|
||||
|
||||
// Type is any type notation.
|
||||
type Type interface {
|
||||
fmt.Stringer
|
||||
|
||||
// Equals reports whether this type is equivalent to another type.
|
||||
Equals (ty Type) bool
|
||||
|
||||
|
||||
@@ -7,27 +7,15 @@ testString (test,
|
||||
`
|
||||
`,
|
||||
`
|
||||
[puts string:*Byte]:I32
|
||||
[read fd:Int buf:*Byte count:Index]:Index
|
||||
[puts string: *Byte]: Index
|
||||
|
||||
[itoa value:Int buffer:String base:Int]:String = {
|
||||
if [== base 0] then { base = 10 }
|
||||
index:Index = 0
|
||||
Greeter: (message: String)
|
||||
Greeter.[greet] = [puts [@[.this.message 0]]]
|
||||
|
||||
loop {
|
||||
digit:Int = [% value base]
|
||||
[.buffer index] = [~Byte [+ digit '0']]
|
||||
value = [/ value base]
|
||||
index = [++index]
|
||||
}
|
||||
|
||||
buffer
|
||||
}
|
||||
|
||||
[main argc:I32 argv:**Byte] = {
|
||||
[itoa 5 string:16:Byte 10]
|
||||
[.string 15] = 0
|
||||
[puts [.[@string]]]
|
||||
[main] = {
|
||||
greeter: Greeter = (
|
||||
message: 'hello\0'
|
||||
)
|
||||
}
|
||||
`)
|
||||
}
|
||||
@@ -39,3 +27,27 @@ testString (test,
|
||||
// [puts (* 100 100 0)]
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// [puts string:*Byte]:I32
|
||||
// [read fd:Int buf:*Byte count:Index]:Index
|
||||
//
|
||||
// [itoa value:Int buffer:String base:Int]:String = {
|
||||
// if [== base 0] then { base = 10 }
|
||||
// index:Index = 0
|
||||
//
|
||||
// loop {
|
||||
// digit:Int = [% value base]
|
||||
// [.buffer index] = [~Byte [+ digit '0']]
|
||||
// value = [/ value base]
|
||||
// index = [++index]
|
||||
// }
|
||||
//
|
||||
// buffer
|
||||
// }
|
||||
//
|
||||
// [main argc:I32 argv:**Byte] = {
|
||||
// [itoa 5 string:16:Byte 10]
|
||||
// [.string 15] = 0
|
||||
// [puts [.[@string]]]
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user