Coder Social home page Coder Social logo

wa-lang / ugo Goto Github PK

View Code? Open in Web Editor NEW
49.0 4.0 11.0 236 KB

µGo编程语言(从头开发一个迷你Go语言编译器)

Home Page: https://wa-lang.org/ugo-compiler-book

Go 90.87% Makefile 0.53% C 0.24% LLVM 7.70% JavaScript 0.66%
go golang parser compiler aeeembly llvm webassembly wasm lexer ugo

ugo's Introduction

µGo 编程语言

µGo 是 Go 语言的真子集(不含标准库部分), 可以直接作为Go代码编译执行.

例子

例子 (_example/hello.ugo):

package main

func main() {
	for n := 2; n <= 30; n = n + 1 {
		var isPrime int = 1
		for i := 2; i*i <= n; i = i + 1 {
			if x := n % i; x == 0 {
				isPrime = 0
			}
		}
		if isPrime != 0 {
			println(n)
		}
	}
}

运行:

$ ugo run _examples/hello.ugo 
2
3
5
7
11
13
17
19
23
29

版权

个人学习目的可自由使用.

ugo's People

Contributors

chai2010 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ugo's Issues

Huge Logical Error

In compiler.go

			// if.body
			func() {
				defer p.restoreScope(p.scope)
				p.enterScope()

				fmt.Fprintf(w, "\n%s:\n", ifBody)
				if stmt.Else != nil {
					p.compileStmt(w, stmt.Body)
					fmt.Fprintf(w, "\tbr label %%%s\n", ifElse) // here
				} else {
					p.compileStmt(w, stmt.Body)
					fmt.Fprintf(w, "\tbr label %%%s\n", ifEnd)
				}
			}()

the ifElse should be ifEnd !

By the way, I am also curious about why labels ifInit and ifCond are needed, since they are branched to immediately.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.