-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-examples.ts
48 lines (33 loc) · 1.36 KB
/
build-examples.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { readFileSync, writeFileSync } from 'fs'
import { parseScript } from 'esprima'
import { generate } from 'escodegen'
import { compile } from '..'
const build1Bit = () => {
console.log( '1 bit' )
const gameYukiSource = readFileSync( './examples/1-bit/src/game.yuki.js', 'utf8' )
const gameLibSource = readFileSync( './examples/1-bit/src/lib.js', 'utf8' )
const yukiAst = parseScript( gameYukiSource, { loc: true } )
const libAst = parseScript( gameLibSource )
const { main, memoryUsed, programSize } = compile( yukiAst, { lib: libAst } )
const source = generate( main )
writeFileSync( './examples/1-bit/main.js', source, 'utf8' )
console.log( { memoryUsed, programSize } )
}
const buildChannelY = () => {
console.log( 'channel Y' )
const gameYukiSource = readFileSync( './examples/channel-y/src/game.yuki.js', 'utf8' )
const gameLibSource = readFileSync( './examples/channel-y/src/lib.js', 'utf8' )
const yukiAst = parseScript( gameYukiSource, { loc: true } )
const libAst = parseScript( gameLibSource )
const { main, memoryUsed, programSize } = compile( yukiAst, {
lib: libAst,
maxProgramSize: 2048,
memorySize: 64,
requiredSubroutines: [ 'tick' ]
} )
const source = generate( main )
writeFileSync( './examples/channel-y/main.js', source, 'utf8' )
console.log( { memoryUsed, programSize } )
}
build1Bit()
buildChannelY()