func main() { var action string = "" if len(os.Args) > 1 { action = os.Args[1] } switch action { case "help": fmt.Println(helpText) case "run": if len(os.Args) < 3 { fmt.Println("run command requires a filename as argument") os.Exit(1) } fileName := os.Args[2] core.ShowStates(compileProgramFromFile(fileName)) case "build": if len(os.Args) < 3 { fmt.Println("build command requires a filename as argument") os.Exit(1) } fileName := os.Args[2] compile.SaveLLVMIR(compile.GenLLVMIR(compileProgramFromFile(fileName))) default: fmt.Println("Starting puff REPL") replLoop() fmt.Println("\nGoodbye! Thanks for using puff.") } }
func replLoop() { fmt.Println(` __ __ _ __ _ _ / _|/ _| | '_ \| | | | |_| |_ | |_) | |_| | _| _| | .__/ \__,_|_| |_| |_| `) reader := bufio.NewReader(os.Stdin) // H := jit.addModule(module) var globals string for { fmt.Print("puff> ") text, err := reader.ReadString('\n') if err == io.EOF { break } if strings.HasPrefix(text, "fn ") { globals = globals + "\n" + text } else { program := compile.Translate(globals+"\n"+"fn main() => "+text, "repl") core.ShowStates(core.Compile(program)) } } }