Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
c957ea0f
wa
项目概览
wa-lang
/
wa
10 个月 前同步成功
通知
68
Star
655
Fork
45
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
wa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c957ea0f
编写于
6月 30, 2023
作者:
chai2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
移植部分 image 实现, 未完
上级
48db574b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
79 addition
and
65 deletion
+79
-65
internal/backends/compiler_wat/compile_func.go
internal/backends/compiler_wat/compile_func.go
+1
-1
internal/parser/parser.go
internal/parser/parser.go
+7
-7
waroot/src/image/bmp/reader.wa
waroot/src/image/bmp/reader.wa
+3
-3
waroot/src/image/geom.wa
waroot/src/image/geom.wa
+37
-35
waroot/src/image/image.wa
waroot/src/image/image.wa
+31
-19
未找到文件。
internal/backends/compiler_wat/compile_func.go
浏览文件 @
c957ea0f
...
...
@@ -430,7 +430,7 @@ func (g *functionGenerator) genUnOp(inst *ssa.UnOp) (insts []wat.Inst, ret_type
return
g
.
module
.
EmitUnOp
(
x
.
value
,
wat
.
OpCodeSub
)
default
:
logger
.
Fatal
(
"Todo"
)
logger
.
Fatal
f
(
"Todo: %[1]v: %[1]T"
,
inst
)
}
return
...
...
internal/parser/parser.go
浏览文件 @
c957ea0f
...
...
@@ -2494,19 +2494,19 @@ func (p *parser) parseFuncDecl() *ast.FuncDecl {
scope
:=
ast
.
NewScope
(
p
.
topScope
)
// function scope
var
recv
*
ast
.
FieldList
if
p
.
wagoMode
{
if
p
.
tok
==
token
.
LPAREN
{
recv
=
p
.
parseParameters
(
scope
,
false
)
}
//if p.wagoMode {
if
p
.
tok
==
token
.
LPAREN
{
recv
=
p
.
parseParameters
(
scope
,
false
)
}
//}
ident
:=
p
.
parseIdent
()
// func Type.method()
if
!
p
.
wagoMode
{
if
recv
!=
nil
{
panic
(
"unreachable"
)
}
//
if recv != nil {
//
panic("unreachable")
//
}
if
p
.
tok
==
token
.
PERIOD
{
thisIdent
:=
&
ast
.
Ident
{
Name
:
"this"
}
thisField
:=
&
ast
.
Field
{
...
...
waroot/src/image/bmp/reader.wa
浏览文件 @
c957ea0f
...
...
@@ -2,9 +2,9 @@
import (
"errors"
//
"image"
"image"
//"image/color"
//
"io"
"io"
)
// ErrUnsupported means that the input BMP image uses a valid but unsupported
...
...
@@ -20,7 +20,6 @@ func readUint32(b: []byte) => uint32 {
}
/*
// decodeRGB reads a 24 bit-per-pixel BMP image from r.
// If topDown is false, the image rows will be read bottom-up.
...
...
@@ -52,6 +51,7 @@ func decodeRGB(r: io.Reader, c: image.Config, topDown: bool) => (m: image.Image,
}
/*
// decodePaletted reads an 8 bit-per-pixel BMP image from r.
// If topDown is false, the image rows will be read bottom-up.
func decodePaletted(r: io.Reader, c: image.Config, topDown: bool) => (m: image.Image, err: error) {
...
...
waroot/src/image/geom.wa
浏览文件 @
c957ea0f
// 版权 @2023 凹语言 作者。保留所有权利。
import (
//
"image/color"
"image/color"
"strconv"
)
...
...
@@ -41,10 +41,9 @@ func Point.In(r: Rectangle) => bool {
r.Min.Y <= this.Y && this.Y < r.Max.Y
}
/*
// Mod returns the point q in r such that p.X-q.X is a multiple of r's width
// and p.Y-q.Y is a multiple of r's height.
func (p
Point) Mod(r Rectangle)
Point {
func (p
: Point) Mod(r: Rectangle) =>
Point {
w, h := r.Dx(), r.Dy()
p = p.Sub(r.Min)
p.X = p.X % w
...
...
@@ -59,20 +58,19 @@ func (p Point) Mod(r Rectangle) Point {
}
// Eq reports whether p and q are equal.
func (p
Point) Eq(q Point)
bool {
func (p
: Point) Eq(q: Point) =>
bool {
return p == q
}
// ZP is the zero Point.
//
// Deprecated: Use a literal image.Point{} instead.
var ZP Point
var ZP
:
Point
// Pt is shorthand for Point{X, Y}.
func Pt(X, Y
int)
Point {
func Pt(X, Y
: int) =>
Point {
return Point{X, Y}
}
*/
// A Rectangle contains the points with Min.X <= X < Max.X, Min.Y <= Y < Max.Y.
// It is well-formed if Min.X <= Max.X and likewise for Y. Points are always
...
...
@@ -91,19 +89,18 @@ func Rectangle.String => string {
return this.Min.String() + "-" + this.Max.String()
}
/*
// Dx returns r's width.
func (r
Rectangle) Dx()
int {
func (r
: Rectangle) Dx =>
int {
return r.Max.X - r.Min.X
}
// Dy returns r's height.
func (r
Rectangle) Dy()
int {
func (r
: Rectangle) Dy =>
int {
return r.Max.Y - r.Min.Y
}
// Size returns r's width and height.
func (r
Rectangle) Size()
Point {
func (r
: Rectangle) Size =>
Point {
return Point{
r.Max.X - r.Min.X,
r.Max.Y - r.Min.Y,
...
...
@@ -111,7 +108,7 @@ func (r Rectangle) Size() Point {
}
// Add returns the rectangle r translated by p.
func (r
Rectangle) Add(p Point)
Rectangle {
func (r
: Rectangle) Add(p: Point) =>
Rectangle {
return Rectangle{
Point{r.Min.X + p.X, r.Min.Y + p.Y},
Point{r.Max.X + p.X, r.Max.Y + p.Y},
...
...
@@ -119,7 +116,7 @@ func (r Rectangle) Add(p Point) Rectangle {
}
// Sub returns the rectangle r translated by -p.
func (r
Rectangle) Sub(p Point)
Rectangle {
func (r
: Rectangle) Sub(p: Point) =>
Rectangle {
return Rectangle{
Point{r.Min.X - p.X, r.Min.Y - p.Y},
Point{r.Max.X - p.X, r.Max.Y - p.Y},
...
...
@@ -129,7 +126,7 @@ func (r Rectangle) Sub(p Point) Rectangle {
// Inset returns the rectangle r inset by n, which may be negative. If either
// of r's dimensions is less than 2*n then an empty rectangle near the center
// of r will be returned.
func (r
Rectangle) Inset(n int)
Rectangle {
func (r
: Rectangle) Inset(n: int) =>
Rectangle {
if r.Dx() < 2*n {
r.Min.X = (r.Min.X + r.Max.X) / 2
r.Max.X = r.Min.X
...
...
@@ -149,7 +146,7 @@ func (r Rectangle) Inset(n int) Rectangle {
// Intersect returns the largest rectangle contained by both r and s. If the
// two rectangles do not overlap then the zero rectangle will be returned.
func (r
Rectangle) Intersect(s Rectangle)
Rectangle {
func (r
: Rectangle) Intersect(s: Rectangle) =>
Rectangle {
if r.Min.X < s.Min.X {
r.Min.X = s.Min.X
}
...
...
@@ -173,7 +170,7 @@ func (r Rectangle) Intersect(s Rectangle) Rectangle {
}
// Union returns the smallest rectangle that contains both r and s.
func (r
Rectangle) Union(s Rectangle)
Rectangle {
func (r
: Rectangle) Union(s: Rectangle) =>
Rectangle {
if r.Empty() {
return s
}
...
...
@@ -196,25 +193,25 @@ func (r Rectangle) Union(s Rectangle) Rectangle {
}
// Empty reports whether the rectangle contains no points.
func (r
Rectangle) Empty()
bool {
func (r
: Rectangle) Empty =>
bool {
return r.Min.X >= r.Max.X || r.Min.Y >= r.Max.Y
}
// Eq reports whether r and s contain the same set of points. All empty
// rectangles are considered equal.
func (r
Rectangle) Eq(s Rectangle)
bool {
func (r
: Rectangle) Eq(s: Rectangle) =>
bool {
return r == s || r.Empty() && s.Empty()
}
// Overlaps reports whether r and s have a non-empty intersection.
func (r
Rectangle) Overlaps(s Rectangle)
bool {
func (r
: Rectangle) Overlaps(s: Rectangle) =>
bool {
return !r.Empty() && !s.Empty() &&
r.Min.X < s.Max.X && s.Min.X < r.Max.X &&
r.Min.Y < s.Max.Y && s.Min.Y < r.Max.Y
}
// In reports whether every point in r is in s.
func (r
Rectangle) In(s Rectangle)
bool {
func (r
: Rectangle) In(s: Rectangle) =>
bool {
if r.Empty() {
return true
}
...
...
@@ -226,7 +223,7 @@ func (r Rectangle) In(s Rectangle) bool {
// Canon returns the canonical version of r. The returned rectangle has minimum
// and maximum coordinates swapped if necessary so that it is well-formed.
func (r
Rectangle) Canon()
Rectangle {
func (r
: Rectangle) Canon =>
Rectangle {
if r.Max.X < r.Min.X {
r.Min.X, r.Max.X = r.Max.X, r.Min.X
}
...
...
@@ -237,40 +234,42 @@ func (r Rectangle) Canon() Rectangle {
}
// At implements the Image interface.
func (r Rectangle) At(x, y int) color.Color {
if (Point{x, y}).In(r) {
return color.Opaque
func (r: Rectangle) At(x, y: int) => color.Color {
pt := Point{x, y}
if (pt).In(r) {
return &color.Opaque
}
return color.Transparent
return
&
color.Transparent
}
// RGBA64At implements the RGBA64Image interface.
func (r Rectangle) RGBA64At(x, y int) color.RGBA64 {
if (Point{x, y}).In(r) {
func (r: Rectangle) RGBA64At(x, y: int) => color.RGBA64 {
pt := Point{x, y}
if (pt).In(r) {
return color.RGBA64{0xffff, 0xffff, 0xffff, 0xffff}
}
return color.RGBA64{}
}
// Bounds implements the Image interface.
func (r
Rectangle) Bounds()
Rectangle {
func (r
: Rectangle) Bounds =>
Rectangle {
return r
}
// ColorModel implements the Image interface.
func (r
Rectangle) ColorModel()
color.Model {
func (r
: Rectangle) ColorModel =>
color.Model {
return color.Alpha16Model
}
// ZR is the zero Rectangle.
//
// Deprecated: Use a literal image.Rectangle{} instead.
var ZR Rectangle
var ZR
:
Rectangle
// Rect is shorthand for Rectangle{Pt(x0, y0), Pt(x1, y1)}. The returned
// rectangle has minimum and maximum coordinates swapped if necessary so that
// it is well-formed.
func Rect(x0, y0, x1, y1
int)
Rectangle {
func Rect(x0, y0, x1, y1
: int) =>
Rectangle {
if x0 > x1 {
x0, x1 = x1, x0
}
...
...
@@ -282,10 +281,13 @@ func Rect(x0, y0, x1, y1 int) Rectangle {
// mul3NonNeg returns (x * y * z), unless at least one argument is negative or
// if the computation overflows the int type, in which case it returns -1.
func mul3NonNeg(x
int, y int, z int)
int {
func mul3NonNeg(x
: int, y: int, z: int) =>
int {
if (x < 0) || (y < 0) || (z < 0) {
return -1
}
// todo(chai2010): 补充 bits 包
return 0
/*
hi, lo := bits.Mul64(uint64(x), uint64(y))
if hi != 0 {
return -1
...
...
@@ -299,11 +301,13 @@ func mul3NonNeg(x int, y int, z int) int {
return -1
}
return a
*/
}
// add2NonNeg returns (x + y), unless at least one argument is negative or if
// the computation overflows the int type, in which case it returns -1.
func add2NonNeg(x
int, y int)
int {
func add2NonNeg(x
: int, y: int) =>
int {
if (x < 0) || (y < 0) {
return -1
}
...
...
@@ -313,5 +317,3 @@ func add2NonNeg(x int, y int) int {
}
return a
}
*/
\ No newline at end of file
waroot/src/image/image.wa
浏览文件 @
c957ea0f
...
...
@@ -46,6 +46,8 @@ type PalettedImage interface {
/*
*/
// pixelBufferLength returns the length of the []uint8 typed Pix slice field
// for the NewXxx functions. Conceptually, this is just (bpp * width * height),
// but this function panics if at least one of those is negative or if the
...
...
@@ -61,6 +63,7 @@ func pixelBufferLength(bytesPerPixel :int, r :Rectangle, imageTypeName :string)
return totalLength
}
// RGBA is an in-memory image whose At method returns color.RGBA values.
type RGBA struct {
// Pix holds the image's pixels, in R, G, B, A order. The pixel at
...
...
@@ -73,16 +76,18 @@ type RGBA struct {
}
func (p
*RGBA) ColorModel()
color.Model { return color.RGBAModel }
func (p
: *RGBA) ColorModel =>
color.Model { return color.RGBAModel }
func (p
*RGBA) Bounds()
Rectangle { return p.Rect }
func (p
: *RGBA) Bounds =>
Rectangle { return p.Rect }
func (p *RGBA) At(x, y int) color.Color {
return p.RGBAAt(x, y)
func (p: *RGBA) At(x, y: int) => color.Color {
c := p.RGBAAt(x, y)
return &c
}
func (p *RGBA) RGBA64At(x, y int) color.RGBA64 {
if !(Point{x, y}.In(p.Rect)) {
func (p: *RGBA) RGBA64At(x, y: int) => color.RGBA64 {
pt := Point{x, y}
if !(pt.In(p.Rect)) {
return color.RGBA64{}
}
i := p.PixOffset(x, y)
...
...
@@ -99,8 +104,9 @@ func (p *RGBA) RGBA64At(x, y int) color.RGBA64 {
}
}
func (p *RGBA) RGBAAt(x, y int) color.RGBA {
if !(Point{x, y}.In(p.Rect)) {
func (p: *RGBA) RGBAAt(x, y: int) => color.RGBA {
pt := Point{x, y}
if !(pt.In(p.Rect)) {
return color.RGBA{}
}
i := p.PixOffset(x, y)
...
...
@@ -110,16 +116,17 @@ func (p *RGBA) RGBAAt(x, y int) color.RGBA {
// PixOffset returns the index of the first element of Pix that corresponds to
// the pixel at (x, y).
func (p
*RGBA) PixOffset(x, y int)
int {
func (p
: *RGBA) PixOffset(x, y: int) =>
int {
return (y-p.Rect.Min.Y)*p.Stride + (x-p.Rect.Min.X)*4
}
func (p *RGBA) Set(x, y int, c color.Color) {
if !(Point{x, y}.In(p.Rect)) {
func (p: *RGBA) Set(x, y: int, c: color.Color) {
pt := Point{x, y}
if !(pt.In(p.Rect)) {
return
}
i := p.PixOffset(x, y)
c1 := color.RGBAModel.Convert(c).(color.RGBA)
c1 := color.RGBAModel.Convert(c).(
*
color.RGBA)
s := p.Pix[i : i+4 : i+4] // Small cap improves performance, see https://golang.org/issue/27857
s[0] = c1.R
s[1] = c1.G
...
...
@@ -127,8 +134,9 @@ func (p *RGBA) Set(x, y int, c color.Color) {
s[3] = c1.A
}
func (p *RGBA) SetRGBA64(x, y int, c color.RGBA64) {
if !(Point{x, y}.In(p.Rect)) {
func (p: *RGBA) SetRGBA64(x, y: int, c: color.RGBA64) {
pt := Point{x, y}
if !pt.In(p.Rect) {
return
}
i := p.PixOffset(x, y)
...
...
@@ -139,8 +147,9 @@ func (p *RGBA) SetRGBA64(x, y int, c color.RGBA64) {
s[3] = uint8(c.A >> 8)
}
func (p *RGBA) SetRGBA(x, y int, c color.RGBA) {
if !(Point{x, y}.In(p.Rect)) {
func (p: *RGBA) SetRGBA(x, y: int, c: color.RGBA) {
pt := Point{x, y}
if !(pt.In(p.Rect)) {
return
}
i := p.PixOffset(x, y)
...
...
@@ -153,7 +162,7 @@ func (p *RGBA) SetRGBA(x, y int, c color.RGBA) {
// SubImage returns an image representing the portion of the image p visible
// through r. The returned value shares pixels with the original image.
func (p
*RGBA) SubImage(r Rectangle)
Image {
func (p
: *RGBA) SubImage(r: Rectangle) =>
Image {
r = r.Intersect(p.Rect)
// If r1 and r2 are Rectangles, r1.Intersect(r2) is not guaranteed to be inside
// either r1 or r2 if the intersection is empty. Without explicitly checking for
...
...
@@ -170,7 +179,7 @@ func (p *RGBA) SubImage(r Rectangle) Image {
}
// Opaque scans the entire image and reports whether it is fully opaque.
func (p
*RGBA) Opaque()
bool {
func (p
: *RGBA) Opaque =>
bool {
if p.Rect.Empty() {
return true
}
...
...
@@ -188,7 +197,7 @@ func (p *RGBA) Opaque() bool {
}
// NewRGBA returns a new RGBA image with the given bounds.
func NewRGBA(r
Rectangle)
*RGBA {
func NewRGBA(r
: Rectangle) =>
*RGBA {
return &RGBA{
Pix: make([]uint8, pixelBufferLength(4, r, "RGBA")),
Stride: 4 * r.Dx(),
...
...
@@ -196,6 +205,9 @@ func NewRGBA(r Rectangle) *RGBA {
}
}
/*
// RGBA64 is an in-memory image whose At method returns color.RGBA64 values.
type RGBA64 struct {
// Pix holds the image's pixels, in R, G, B, A order and big-endian format. The pixel at
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录