Skip to content

Instantly share code, notes, and snippets.

@Acconut
Created January 21, 2016 10:27
Show Gist options
  • Save Acconut/3e13088495b561f8bcd8 to your computer and use it in GitHub Desktop.
Save Acconut/3e13088495b561f8bcd8 to your computer and use it in GitHub Desktop.
[c] func printf(fmt: ^u8, ...) -> int;
func main() -> int {
list := default(LinkedList);
C::printf("list.first = %d\n", list.first);
C::printf("None = %d . Value = %d\n", Entry::None, Entry::Value);
return 0;
}
type Entry enum {
None,
Value,
};
type LinkedList struct {
first: Entry = Entry::None,
};
$ ark --loglevel=debug build ./enum-default.ark
Started lexing enum-default
[ 0: 1: separator] `[`
[ 1: 2: identifier] `c`
[ 2: 3: separator] `]`
[ 4: 8: identifier] `func`
[ 9: 15: identifier] `printf`
[ 15: 16: separator] `(`
[ 16: 19: identifier] `fmt`
[ 19: 20: operator] `:`
[ 21: 22: operator] `^`
[ 22: 24: identifier] `u8`
[ 24: 25: separator] `,`
[ 26: 27: separator] `.`
[ 27: 28: separator] `.`
[ 28: 29: separator] `.`
[ 29: 30: separator] `)`
[ 31: 33: operator] `->`
[ 34: 37: identifier] `int`
[ 37: 38: separator] `;`
[ 40: 44: identifier] `func`
[ 45: 49: identifier] `main`
[ 49: 50: separator] `(`
[ 50: 51: separator] `)`
[ 52: 54: operator] `->`
[ 55: 58: identifier] `int`
[ 59: 60: separator] `{`
[ 63: 67: identifier] `list`
[ 68: 69: operator] `:`
[ 69: 70: operator] `=`
[ 71: 78: identifier] `default`
[ 78: 79: separator] `(`
[ 79: 89: identifier] `LinkedList`
[ 89: 90: separator] `)`
[ 90: 91: separator] `;`
[ 95: 96: identifier] `C`
[ 96: 98: operator] `::`
[ 98: 104: identifier] `printf`
[ 104: 105: separator] `(`
[ 106: 123: string] `list.first = %d\n`
[ 124: 125: separator] `,`
[ 126: 130: identifier] `list`
[ 130: 131: separator] `.`
[ 131: 136: identifier] `first`
[ 136: 137: separator] `)`
[ 137: 138: separator] `;`
[ 141: 142: identifier] `C`
[ 142: 144: operator] `::`
[ 144: 150: identifier] `printf`
[ 150: 151: separator] `(`
[ 152: 176: string] `None = %d . Value = %d\n`
[ 177: 178: separator] `,`
[ 179: 184: identifier] `Entry`
[ 184: 186: operator] `::`
[ 186: 190: identifier] `None`
[ 190: 191: separator] `,`
[ 192: 197: identifier] `Entry`
[ 197: 199: operator] `::`
[ 199: 204: identifier] `Value`
[ 204: 205: separator] `)`
[ 205: 206: separator] `;`
[ 209: 215: identifier] `return`
[ 216: 217: number] `0`
[ 217: 218: separator] `;`
[ 219: 220: separator] `}`
[ 222: 226: identifier] `type`
[ 227: 232: identifier] `Entry`
[ 233: 237: identifier] `enum`
[ 238: 239: separator] `{`
[ 242: 246: identifier] `None`
[ 246: 247: separator] `,`
[ 250: 255: identifier] `Value`
[ 255: 256: separator] `,`
[ 257: 258: separator] `}`
[ 258: 259: separator] `;`
[ 261: 265: identifier] `type`
[ 266: 276: identifier] `LinkedList`
[ 277: 283: identifier] `struct`
[ 284: 285: separator] `{`
[ 288: 293: identifier] `first`
[ 293: 294: operator] `:`
[ 295: 300: identifier] `Entry`
[ 301: 302: operator] `=`
[ 303: 308: identifier] `Entry`
[ 308: 310: operator] `::`
[ 310: 314: identifier] `None`
[ 314: 315: separator] `,`
[ 316: 317: separator] `}`
[ 317: 318: separator] `;`
Ended lexing enum-default (0.67ms)
Started parsing enum-default
Ended parsing enum-default (11.31ms)
Started read/lex/parse phase
Ended read/lex/parse phase (0.00ms)
Started cyclic dependency check
Ended cyclic dependency check (0.00ms)
Started construction phase
Started constructing module __main
Started constructing submodule enum-default
Ended constructing submodule enum-default (0.06ms)
Ended constructing module __main (0.08ms)
Ended construction phase (0.12ms)
Started resolve phase
Ended resolve phase (20.13ms)
Started inference phase
AST of submodule `__main/enum-default`:
(FunctionDecl: (Function: [c] printf (VariableDecl: (Variable: fmt <_V3fmt> ^u8)): int <_M6__main_F6printf_p2u8>))
(FunctionDecl: (Function: main: int (Block:
(VariableDecl: (Variable: list <_V4list> LinkedList) = (DefaultExpr: LinkedList))
(CallStat: (CallExpr: (FunctionAccessExpr: printf) (StringLiteral: list.first = %d\n ^u8) (StructAccessExpr: struct(VariableAccessExpr: list), member first) int))
(CallStat: (CallExpr: (FunctionAccessExpr: printf) (StringLiteral: None = %d . Value = %d\n ^u8) (EnumLiteral:) (EnumLiteral:) int))
(ReturnStat: (NumericLiteral: 0 int))
) <main>))
(TypeDecl: (NamedType: Entry = enum {None: (), Value: ()}))
(TypeDecl: (NamedType: LinkedList = struct {first: Entry}))
Ended inference phase (0.21ms)
Started semantic analysis phase
Ended semantic analysis phase (0.07ms)
Started codegen phase
Started codegenning __main
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x60 pc=0x483c03]
goroutine 1 [running]:
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).getVariable(0xc82015e1e0, 0x0, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:287 +0xb3
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genAccessGEP(0xc82015e1e0, 0x7fcc0526bf08, 0xc820134cb0, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:737 +0xe4b
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genAccessExpr(0xc82015e1e0, 0x7fcc0526bf08, 0xc820134cb0, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:730 +0x3ce
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genExpr(0xc82015e1e0, 0x7fcc0526bf08, 0xc820134cb0, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:675 +0x132
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genStructLiteral(0xc82015e1e0, 0xc8201199c0, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:966 +0x430
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genDefaultValue(0xc82015e1e0, 0x7fcc05ab0338, 0xc820130840, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:1351 +0x139
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genDefaultExpr(0xc82015e1e0, 0xc820152390, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:1341 +0x51
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genExpr(0xc82015e1e0, 0x7fcc0526bd80, 0xc820152390, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:681 +0x2ec
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genVariableDecl(0xc82015e1e0, 0xc8201306c0, 0x7b259801, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:624 +0x2b6
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genDecl(0xc82015e1e0, 0x7fcc0526d710, 0xc8201306c0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:541 +0xa4
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genNode(0xc82015e1e0, 0x7fcc0526bc50, 0xc8201306c0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:303 +0xad
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genBlock(0xc82015e1e0, 0xc82014c460)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:370 +0xec
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genFunctionBody(0xc82015e1e0, 0xc82013c3c0, 0x26f2428)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:589 +0x589
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genFunctionDecl(0xc82015e1e0, 0xc82014c5a0, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:559 +0xd2
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genDecl(0xc82015e1e0, 0x7fcc0526d650, 0xc82014c5a0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:539 +0x11f
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).genNode(0xc82015e1e0, 0x7fcc0526bc98, 0xc82014c5a0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:303 +0xad
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).Generate.func1()
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:144 +0x222
github.com/ark-lang/ark/src/util/log.Timed(0x8fcdd0, 0xb, 0xc82015b7e8, 0x7, 0xc82015ba88)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/util/log/timed.go:28 +0x2f8
github.com/ark-lang/ark/src/codegen/LLVMCodegen.(*Codegen).Generate(0xc82015e1e0, 0xc82010e1b8, 0x1, 0x1)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/codegen/LLVMCodegen/codegen.go:158 +0x750
main.build.func4()
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/cmd/ark/main.go:293 +0x51
github.com/ark-lang/ark/src/util/log.Timed(0x8fcdb0, 0xd, 0x0, 0x0, 0xc82015be30)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/util/log/timed.go:28 +0x2f8
main.build(0xc82010c620, 0x1, 0x1, 0x8f0978, 0x4, 0x8f06f0, 0x4, 0x3, 0x0)
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/cmd/ark/main.go:294 +0x364
main.main()
/home/marius/workspace/go/src/github.com/ark-lang/ark/src/cmd/ark/main.go:45 +0x2aa
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1696 +0x1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment