This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 說明:https://openhome.cc/Gossip/WebAssembly/Array.html | |
(module | |
(import "env" "log" (func $log (param i32))) | |
(memory 1) | |
;; 建立新陣列 | |
(func $arr (param $len i32) (result i32) | |
(local $offset i32) ;; 記錄陣列偏移量 | |
(set_local $offset (i32.load (i32.const 0))) ;; 取得偏移量 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Num: | |
def __init__(self, value): | |
self.value = value | |
def bc_instructn(self, bytecodes): | |
bytecodes.append(f'push {self.value}') | |
return bytecodes | |
class Add: | |
def __init__(self, left, right): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Num: | |
def __init__(self, value): | |
self.value = value | |
def evaluate(self, stack): | |
push(stack, self.value) | |
return stack | |
class Add: | |
def __init__(self, left, right): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.request import urlopen | |
def download(url, file): | |
with urlopen(url) as url, open(file, 'wb') as f: | |
f.write(url.read()) | |
urls = [ | |
'http://openhome.cc/Gossip/Encoding/', | |
'http://openhome.cc/Gossip/Scala/', | |
'http://openhome.cc/Gossip/JavaScript/', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from concurrent.futures import ThreadPoolExecutor | |
import time | |
import random | |
def doAsync(task): | |
g = task() | |
future = next(g) | |
while True: | |
try: | |
future = g.send(future.result()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ast | |
code = ''' | |
def add(n1, n2): | |
return n1 + n2 | |
print(add(3, 4)) | |
''' | |
class CrazyTransformer(ast.NodeTransformer): | |
def visit_BinOp(self, node): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, re, ast | |
type_hints_re = re.compile(r'([a-zA-Z]+):\s*([a-zA-Z]+)') | |
code = ''' | |
"""x: int""" | |
x = 2 | |
''' | |
node = ast.parse(code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// === Tokenizer | |
class Tokens { | |
constructor(tokens) { | |
this.head = tokens[0]; | |
this.tail = tokens.slice(1); | |
} | |
} | |
class Tokenizer { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function println(v) { | |
console.log(v.toString()); | |
} | |
class List { | |
constructor(array) { | |
this.array = array; | |
} | |
get first() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class List { | |
constructor(array) { | |
this.array = array; | |
} | |
get first() { | |
return this.array[0]; | |
} | |
get tail() { |
NewerOlder