108 lines
1.9 KiB
Go
108 lines
1.9 KiB
Go
package generator
|
|
|
|
import "testing"
|
|
|
|
func TestFunction (test *testing.T) {
|
|
testString (test,
|
|
`
|
|
`,
|
|
`
|
|
[puts string: *Byte]: Index
|
|
[write file:I32 buffer:*Byte count:Index]: Index
|
|
|
|
[printDigit digit:Byte] = {
|
|
digit = [+ digit '0']
|
|
[write 1 [@digit] 1]
|
|
}
|
|
|
|
[main] = {
|
|
[puts 'printing']
|
|
[printDigit 0]
|
|
[printDigit 1]
|
|
[printDigit 2]
|
|
[printDigit 3]
|
|
[puts '\nprinted']
|
|
}
|
|
`)
|
|
}
|
|
// [write 1 (* 72 101 108 108 111 114 108 100 0) 7]
|
|
|
|
// [puts string:*Byte]:I32
|
|
// [main argc:I32 argv:**Byte] = {
|
|
// loop {
|
|
// [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]]]
|
|
// }
|
|
|
|
// [puts string: *Byte]: Index
|
|
//
|
|
// Greeter: (message: String)
|
|
// Greeter.[greet] = [puts [@[.this.message 0]]]
|
|
//
|
|
// [main] = {
|
|
// greeter: Greeter = (
|
|
// message: 'hello\0'
|
|
// )
|
|
// greeter.[doNothing]
|
|
// }
|
|
//
|
|
// Greeter.[doNothing] = { }
|
|
//
|
|
// Greeter.[getMessage]: String = {
|
|
// [puts 'getting']
|
|
// this.message
|
|
// [puts 'got']
|
|
// this.message
|
|
// }
|
|
|
|
// [puts string: *Byte]: Index
|
|
// [firstByte str:String]: *Byte = [@[.str 0]]
|
|
// [main] = {
|
|
// str:String = 'xx'
|
|
// [.str 2] = 0
|
|
// if [= [.str 2] 0] then [puts 'zero'] else [puts 'nonzero']
|
|
// first:*Byte = [firstByte str]
|
|
// [puts first]
|
|
// }
|
|
|
|
// [puts string: *Byte]: Index
|
|
// [write file:I32 buffer:*Byte count:Index]: Index
|
|
//
|
|
// [firstByte str:String]: *Byte = [@[.str 0]]
|
|
//
|
|
// [print string: String] = loop {
|
|
// if [< [#string] 1] then {break}
|
|
// byte: Byte = [. string 0]
|
|
// [write 1 [@byte] 1]
|
|
// string = [\string 1:]
|
|
// }
|
|
//
|
|
// [main] = {
|
|
// str:String = 'xx'
|
|
// [print str]
|
|
// }
|