Skip to content

Commit

Permalink
Add recognition and classification of WebAssembly (github-linguist#3650)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis authored May 30, 2017
1 parent 60f864a commit b6460f8
Show file tree
Hide file tree
Showing 13 changed files with 659 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -851,3 +851,6 @@
[submodule "vendor/grammars/language-closure-templates"]
path = vendor/grammars/language-closure-templates
url = https://github.com/mthadley/language-closure-templates
[submodule "vendor/grammars/language-webassembly"]
path = vendor/grammars/language-webassembly
url = https://github.com/Alhadis/language-webassembly
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ vendor/grammars/language-viml:
vendor/grammars/language-wavefront:
- source.wavefront.mtl
- source.wavefront.obj
vendor/grammars/language-webassembly:
- source.webassembly
vendor/grammars/language-xbase:
- source.harbour
vendor/grammars/language-xcompose:
Expand Down
15 changes: 15 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,7 @@ Makefile:
- Makefile.frag
- Makefile.in
- Makefile.inc
- Makefile.wat
- makefile
- makefile.sco
- mkfile
Expand Down Expand Up @@ -4693,6 +4694,20 @@ Web Ontology Language:
tm_scope: text.xml
ace_mode: xml
language_id: 394
WebAssembly:
type: programming
color: "#04133b"
extensions:
- ".wast"
- ".wat"
aliases:
- wast
- wasm
tm_scope: source.webassembly
ace_mode: lisp
codemirror_mode: commonlisp
codemirror_mime_type: text/x-common-lisp
language_id: 956556503
WebIDL:
type: programming
extensions:
Expand Down
248 changes: 248 additions & 0 deletions samples/Makefile/filenames/Makefile.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
#
# The FreeType Project LICENSE
# ----------------------------
#
# Copyright 1996-1999 by
# David Turner, Robert Wilhelm, and Werner Lemberg
#
#
#
# Introduction
# ============
#
# The FreeType Project is distributed in several archive packages;
# some of them may contain, in addition to the FreeType font engine,
# various tools and contributions which rely on, or relate to, the
# FreeType Project.
#
# This license applies to all files found in such packages, and
# which do not fall under their own explicit license. The license
# affects thus the FreeType font engine, the test programs,
# documentation and makefiles, at the very least.
#
# This license was inspired by the BSD, Artistic, and IJG
# (Independent JPEG Group) licenses, which all encourage inclusion
# and use of free software in commercial and freeware products
# alike. As a consequence, its main points are that:
#
# o We don't promise that this software works. However, we are be
# interested in any kind of bug reports. (`as is' distribution)
#
# o You can use this software for whatever you want, in parts or
# full form, without having to pay us. (`royalty-free' usage)
#
# o You may not pretend that you wrote this software. If you use
# it, or only parts of it, in a program, you must acknowledge
# somewhere in your documentation that you've used the FreeType
# code. (`credits')
#
# We specifically permit and encourage the inclusion of this
# software, with or without modifications, in commercial products,
# provided that all warranty or liability claims are assumed by the
# product vendor.
#
#
# Legal Terms
# ===========
#
# 0. Definitions
# --------------
#
# Throughout this license, the terms `package', `FreeType Project',
# and `FreeType archive' refer to the set of files originally
# distributed by the authors (David Turner, Robert Wilhelm, and
# Werner Lemberg) as the `FreeType project', be they named as alpha,
# beta or final release.
#
# `You' refers to the licensee, or person using the project, where
# `using' is a generic term including compiling the project's source
# code as well as linking it to form a `program' or `executable'.
# This program is referred to as `a program using the FreeType
# engine'.
#
# This license applies to all files distributed in the original
# FreeType archive, including all source code, binaries and
# documentation, unless otherwise stated in the file in its
# original, unmodified form as distributed in the original archive.
# If you are unsure whether or not a particular file is covered by
# this license, you must contact us to verify this.
#
# The FreeType project is copyright (C) 1996-1999 by David Turner,
# Robert Wilhelm, and Werner Lemberg. All rights reserved except as
# specified below.
#
# 1. No Warranty
# --------------
#
# THE FREETYPE ARCHIVE IS PROVIDED `AS IS' WITHOUT WARRANTY OF ANY
# KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE. IN NO EVENT WILL ANY OF THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE OR THE INABILITY TO
# USE, OF THE FREETYPE PROJECT.
#
# As you have not signed this license, you are not required to
# accept it. However, as the FreeType project is copyrighted
# material, only this license, or another one contracted with the
# authors, grants you the right to use, distribute, and modify it.
# Therefore, by using, distributing, or modifying the FreeType
# project, you indicate that you understand and accept all the terms
# of this license.
#
# 2. Redistribution
# -----------------
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# o Redistribution of source code must retain this license file
# (`licence.txt') unaltered; any additions, deletions or changes
# to the original files must be clearly indicated in
# accompanying documentation. The copyright notices of the
# unaltered, original files must be preserved in all copies of
# source files.
#
# o Redistribution in binary form must provide a disclaimer that
# states that the software is based in part of the work of the
# FreeType Team, in the distribution documentation. We also
# encourage you to put an URL to the FreeType web page in your
# documentation, though this isn't mandatory.
#
# These conditions apply to any software derived from or based on
# the FreeType code, not just the unmodified files. If you use our
# work, you must acknowledge us. However, no fee need be paid to
# us.
#
# 3. Advertising
# --------------
#
# The names of FreeType's authors and contributors may not be used
# to endorse or promote products derived from this software without
# specific prior written permission.
#
# We suggest, but do not require, that you use one or more of the
# following phrases to refer to this software in your documentation
# or advertising materials: `FreeType Project', `FreeType Engine',
# `FreeType library', or `FreeType Distribution'.
#
# 4. Contacts
# -----------
#
# There are two mailing lists related to FreeType:
#
# o [email protected]
#
# Discusses general use and applications of FreeType, as well as
# future and wanted additions to the library and distribution.
# If you are looking for support, start in this list if you
# haven't found anything to help you in the documentation.
#
# o [email protected]
#
# Discusses bugs, as well as engine internals, design issues,
# specific licenses, porting, etc.
#
# o http://www.freetype.org
#
# Holds the current FreeType web page, which will allow you to
# download our latest development version and read online
# documentation.
#
# You can also contact us individually at:
#
# David Turner <[email protected]>
# Robert Wilhelm <[email protected]>
# Werner Lemberg <[email protected]>
#
#
# --- end of license ---
#
# This file is part of the FreeType project.
#
# This builds the Watcom library with Watcom's wcc386 under OS/2.
#
# You'll need Watcom's wmake.
#
#
# Invoke by "wmake -f arch\os2\Makefile.wat" when in the "lib" directory
#
# This will build "freetype\lib\libttf.lib"

ARCH = arch\os2
FT_MAKEFILE = $(ARCH)\Makefile.wat
FT_MAKE = wmake -h


.EXTENSIONS:
.EXTENSIONS: .lib .obj .c .h
.obj:.;.\extend;.\$(ARCH)
.c:.;.\extend;.\$(ARCH)
.h:.;.\extend;.\$(ARCH)

CC = wcc386

CCFLAGS = /otexanl+ /s /w5 /zq -Iarch\os2 -I. -Iextend

TTFILE = .\ttfile.c
TTMEMORY = .\ttmemory.c
TTMUTEX = .\ttmutex.c

TTFILE_OBJ = ttfile.obj
TTMEMORY_OBJ = ttmemory.obj
TTMUTEX_OBJ = ttmutex.obj

PORT = $(TTFILE) $(TTMEMORY) $(TTMUTEX)
PORT_OBJS = $(TTFILE_OBJ) $(TTMEMORY_OBJ) $(TTMUTEX_OBJ)

SRC_X = extend\ftxgasp.c extend\ftxkern.c extend\ftxpost.c &
extend\ftxcmap.c extend\ftxwidth.c extend\ftxsbit.c &
extend\ftxgsub.c extend\ftxgpos.c extend\ftxopen.c &
extend\ftxgdef.c

OBJS_X = extend\ftxgasp.obj extend\ftxkern.obj extend\ftxpost.obj &
extend\ftxcmap.obj extend\ftxwidth.obj extend\ftxsbit.obj &
extend\ftxgsub.obj extend\ftxgpos.obj extend\ftxopen.obj &
extend\ftxgdef.obj

SRC_M = ttapi.c ttcache.c ttcalc.c ttcmap.c &
ttgload.c ttinterp.c ttload.c ttobjs.c &
ttraster.c ttextend.c $(PORT)

OBJS_M = ttapi.obj ttcache.obj ttcalc.obj ttcmap.obj &
ttgload.obj ttinterp.obj ttload.obj ttobjs.obj &
ttraster.obj ttextend.obj $(PORT_OBJS) $(OBJS_X)

SRC_S = freetype.c
OBJ_S = freetype.obj
OBJS_S = $(OBJ_S) $(OBJS_X)


.c.obj:
$(CC) $(CCFLAGS) $[* /fo=$[*.obj

all: .symbolic
$(FT_MAKE) -f $(FT_MAKEFILE) libttf.lib

debug: .symbolic
$(FT_MAKE) -f $(FT_MAKEFILE) LIB_FILES="$(OBJS_M)" libttf.lib


libttf.lib: $(OBJS_M)
wlib -q -n libttf.lib $(OBJS_M)

# is this correct? Know nothing about wmake and the Watcom compiler...
$(OBJ_S): $(SRC_S) $(SRC_M)
$(CC) $(CCFLAGS) $(SRC_S) /fo=$(OBJ_S)

clean: .symbolic
@-erase $(OBJS_M)
@-erase *.err

distclean: .symbolic clean
@-erase libttf.lib

new: .symbolic
@-wtouch *.c

# end of Makefile.wat
14 changes: 14 additions & 0 deletions samples/WebAssembly/add.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(module
(import "env" "printInt" (func $printInt (param i32)))
(func $add (param $lhs i32) (param $rhs i32) (result i32)
get_local $lhs
get_local $rhs
i32.add
)

(func $main
(call $printInt
(call $add (i32.const 9) (i32.const 8))))

(export "main" (func $main))
)
41 changes: 41 additions & 0 deletions samples/WebAssembly/fibonacci.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(module
(import "env" "printInt" (func $printInt (param i32)))
(import "env" "print" (func $print (param i32 i32)))

(memory $memory 1)
(data (i32.const 0) "\n")
(data (i32.const 1) " ")

(func $endl
(call $print (i32.const 0) (i32.const 1)))
(func $space
(call $print (i32.const 1) (i32.const 1)))

(func $fibonacci_rec (param $a i32) (param $b i32) (param $n i32) (result i32)
(if (i32.eqz (get_local $n)) (return (get_local $a)))
(call $printInt (get_local $b))
(call $space)
(set_local $a (i32.add (get_local $a) (get_local $b)))
(call $fibonacci_rec (get_local $b) (get_local $a) (i32.sub (get_local $n) (i32.const 1)))
)

(func $fibonacci_iter (param $a i32) (param $b i32) (param $n i32) (result i32)
(loop $fi
(if (i32.eqz (get_local $n)) (return (get_local $a)))
(call $printInt (get_local $b))
(call $space)
(set_local $b (i32.add (get_local $a) (get_local $b)))
(set_local $a (i32.sub (get_local $b) (get_local $a)))
(set_local $n (i32.sub (get_local $n) (i32.const 1)))
(br $fi))
(get_local $b))

(func $main
(drop (call $fibonacci_rec (i32.const 0) (i32.const 1) (i32.const 9)))
(call $endl)
(drop (call $fibonacci_iter (i32.const 0) (i32.const 1) (i32.const 9))))

(export "main" (func $main))
(export "memory" (memory $memory))
)

48 changes: 48 additions & 0 deletions samples/WebAssembly/imported-min.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(module
(memory 256 256)
(data (i32.const 10) "waka waka waka waka waka")
;; stack imports are special
(import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32))
(import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32))
;; other imports must not be touched!
(import "env" "tempDoublePtr" (global $tempDoublePtr i32))
(export "test1" $test1)
(export "test2" $test2)
(export "test3" $test3)
;; ok to modify a global, if we keep it the same value
(global $mine (mut i32) (i32.const 1))
;; stack imports are ok to use. their uses are the same as other
;; globals - must keep the same value (which means, unwind the stack)
;; here the global names are "minified"
(global $global0 (mut i32) (get_global $STACKTOP$asm2wasm$import))
(global $global1 (mut i32) (get_global $STACK_MAX$asm2wasm$import))
;; a global initialized by an import, so bad, but ok if not used
(global $do-not-use (mut i32) (get_global $tempDoublePtr))
(func $test1
(local $temp i32)
(set_global $mine (i32.const 1))
(set_local $temp (get_global $global0))
(set_global $global0 (i32.const 1337)) ;; bad
(set_global $global0 (get_local $temp)) ;; save us
(set_global $global1 (i32.const 913370)) ;; bad
(set_global $global1 (get_local $temp)) ;; save us
;; use the stack memory
(i32.store (get_local $temp) (i32.const 1337))
(if
(i32.ne
(i32.load (get_local $temp))
(i32.const 1337)
)
(unreachable) ;; they should be equal, never get here
)
;; finally, do a valid store
(i32.store8 (i32.const 12) (i32.const 115))
)
(func $test2
(set_global $tempDoublePtr (i32.const 1)) ;; bad!
(i32.store8 (i32.const 13) (i32.const 115))
)
(func $test3
(i32.store8 (i32.const 14) (i32.const 115))
)
)
Loading

0 comments on commit b6460f8

Please sign in to comment.