Esempio n. 1
0
func run(str string) string { //Almost Done
	// contentProgram := core.Compile(core.Program{
	//            core.ScDefn{"main", []core.Name{}, Translate(string(str))},
	//    	})

	program := Translate(string(str), "Program")

	mainFound := false
	for _, sc := range program {
		if string(sc.Name) == "main" {
			mainFound = true
			break
		}
	}

	if mainFound == false {
		fmt.Println("No main function found in program. Aborting.")
		return ""
	}

	contentProgram := core.Compile(program)

	result := core.EvalState(contentProgram) // []GmState
	fmt.Println(result)
	return string("result")
}
Esempio n. 2
0
func compileProgramFromFile(fileName string) core.GmState {
	b, err := ioutil.ReadFile(fileName)

	fmt.Println(string(b))
	if err != nil {
		panic(err)
	}
	// Generate the LLVM-IR code for Input file
	/*
	   contentProgram := core.Compile(core.Program{
	           core.ScDefn{"main", []core.Name{}, compile.Translate(string(b))},
	       })
	*/
	program := compile.Translate(string(b), fileName)

	mainFound := false
	for _, sc := range program {
		if string(sc.Name) == "main" {
			mainFound = true
			break
		}
	}

	if mainFound == false {
		panic("No main function found in program. Aborting.")
	}

	return core.Compile(program)
}
Esempio n. 3
0
// func MainLoop(module llvm.Module, jit llvm.ExecutionEngine) {
func MainLoop() {

	reader := bufio.NewReader(os.Stdin)
	// H := jit.addModule(module)
	for {
		fmt.Print("puff> ")
		text, err := reader.ReadString('\n')

		if err == io.EOF {
			break
		}

		if text == "4" {
			fmt.Print("4")
			continue
		}

		// llvm.compile.Compile(text, module).Dump()
		// compiledSc := core.CompileSc(core.ScDefn{"main", []core.Name{}, compile.Translate(text)})
		// fmt.Println(compiledSc)
		// core.PrintBody(compiledSc.Body())
		fmt.Println(core.Compile(core.Program{
			core.ScDefn{"main", []core.Name{}, compile.Translate(text)},
		}))
	}
}
Esempio n. 4
0
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))
		}
	}
}