Skip to content

2023

Symbol Table and Context Value Implementation

After learning briefly about compiler, with the motivation of walker inside astjson, it's a bit compulsory to master some knowledge about symbol table as it helps to understand management of variables/states in a large different scales.

This blog talks first about the symbol table itself, and then check how Go language maintains the values among contexts in src/context. Note that it doesn't talk anything else rather than values in context.

Go Type System and Type Conversion

A Failure of Assignment

Recently, my friend asked me a question, why inthe following go code, b cannot be assigned to f? With knowledges about AST, I got intrigue on it than ever before.

type (
    Bar string
    Foo Bar
)

func main() {
    var f Foo
    var b Bar
    f = b
}
/main.go:17:6: cannot use b (variable of type Bar) as type Foo in assignment
func main() {
    var f Foo = "foo"
    var b Bar
}

The failure is caused by Bar and Foo are not same type, hence, they cannot be assigned to each other. However, assign a string to Bar or Foo directly is valid.

This blog talks why the conversion fails and will introduce the type, type definition, properities of types with some examples.

Precise Lose Between Float64 and Uint64

In astjson library, the lexer scans the number and stores the respective bytes. Then the parser will parse the bytes to number which is expressed by a float64. It works well at beginning, however, once I added a corner case of number with value math.MaxUint64(1<<64 - 1 or decimal value 18446744073709551615), the parser cannot work as expected. It's indeed a bug issue.

The simplified problem is the value through debug of f is 18446744073709552000 instead of 18446744073709551615.

f, _ = strconv.ParseFloat("18446744073709551615", 64)

Tar Wrapped by Cli Tool Fails to Write

Our internal CLI tool will try to download a proto file by git achieve command, and then tar it to /usr/local/include. One user reported in his desktop tar cannot unzip file:

xxx.proto: Can't create 'xxx.proto'
tar: Error exit delayed from previous errors.
ERROR fail to extract xxx.proto into '/usr/local/include/xxx.proto' 
via this script: 'tar -xf xxx.tar -C /usr/local/include'.

Type and Typeclass in Haskell

When I was reading the haskell aeson library implementation, I still a little confusing with type system especially for multiple constructors.

Hence, I learned it again and record some ideas here. It reviews the value constructor, type constructor and the strict type in type constructor.