Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Shaw Summa <[email protected]>
  • Loading branch information
ShawSumma committed Oct 25, 2024
1 parent 10a5314 commit 8b3c059
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 230 deletions.
26 changes: 0 additions & 26 deletions js.txt

This file was deleted.

72 changes: 0 additions & 72 deletions lua.txt

This file was deleted.

4 changes: 3 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BASE_LDFLAGS := ${OPT} ${LDFLAGS} ${LIBM_FLAGS}
# object files and depends
MAIN_SRCS = main/minivm.c
VM_SRCS := $(shell find vm | grep \\.c)
# MI_SRCS := vendor/mimalloc/src/prim/prim.c vendor/mimalloc/src/alloc-posix.c vendor/mimalloc/src/alloc-aligned.c vendor/mimalloc/src/alloc.c vendor/mimalloc/src/arena.c vendor/mimalloc/src/bitmap.c vendor/mimalloc/src/heap.c vendor/mimalloc/src/init.c vendor/mimalloc/src/libc.c vendor/mimalloc/src/options.c vendor/mimalloc/src/os.c vendor/mimalloc/src/page.c vendor/mimalloc/src/random.c vendor/mimalloc/src/segment-map.c vendor/mimalloc/src/segment.c vendor/mimalloc/src/stats.c
MI_SRCS := vendor/mimalloc/src/prim/prim.c vendor/mimalloc/src/alloc-posix.c vendor/mimalloc/src/alloc-aligned.c vendor/mimalloc/src/alloc.c vendor/mimalloc/src/arena.c vendor/mimalloc/src/bitmap.c vendor/mimalloc/src/heap.c vendor/mimalloc/src/init.c vendor/mimalloc/src/libc.c vendor/mimalloc/src/options.c vendor/mimalloc/src/os.c vendor/mimalloc/src/page.c vendor/mimalloc/src/random.c vendor/mimalloc/src/segment-map.c vendor/mimalloc/src/segment.c vendor/mimalloc/src/stats.c
TS_SRCS += vendor/tree-sitter/lib/src/alloc.c vendor/tree-sitter/lib/src/get_changed_ranges.c vendor/tree-sitter/lib/src/language.c vendor/tree-sitter/lib/src/lexer.c vendor/tree-sitter/lib/src/node.c vendor/tree-sitter/lib/src/parser.c vendor/tree-sitter/lib/src/query.c vendor/tree-sitter/lib/src/stack.c vendor/tree-sitter/lib/src/subtree.c vendor/tree-sitter/lib/src/tree_cursor.c vendor/tree-sitter/lib/src/tree.c vendor/tree-sitter/lib/src/wasm_store.c
IC_SRCS := vendor/isocline/src/isocline.c
MAIN_SRCS += ${VM_SRCS} ${TS_SRCS} ${IC_SRCS} ${MI_SRCS}
Expand Down Expand Up @@ -54,13 +54,15 @@ gcc-pgo: .dummy
build/bin/minivm test/lua/fib/fib.lua
build/bin/minivm test/lua/tables/trees.lua
build/bin/minivm test/lua/closure/funcret.lua
build/bin/minivm test/lang/lr1.lua
$(MAKE) -Bj minivm OPT="$(OPT) -fgcse-sm -fgcse-las -fipa-pta -fdevirtualize-at-ltrans -fdevirtualize-speculatively -fno-exceptions -fomit-frame-pointer -fprofile-use"

clang-pgo: .dummy
$(MAKE) -Bj minivm OPT="$(OPT) -mllvm -polly -fno-exceptions -fprofile-instr-generate"
build/bin/minivm test/lua/fib/fib.lua
build/bin/minivm test/lua/tables/trees.lua
build/bin/minivm test/lua/closure/funcret.lua
build/bin/minivm test/lang/lr1.lua
$(LLVM_PROFDATA) merge default.profraw -o default.profdata
$(MAKE) -Bj minivm OPT="$(OPT) -mllvm -polly -fno-exceptions -fprofile-use"

Expand Down
44 changes: 38 additions & 6 deletions test/lua/parser/lr1.js → test/lang/lr1.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ function parse(G, { action, goTo }, input) {
nodes.push({ symbol: lookahead, offset })
stack.push(n)
lookahead = input[++offset]
if (lookahead == null) {
lookahead = '$'
}
} else if (/^r/.test(a)) {
let symbol = G[n][0]
let arity = G[n].length - 1
Expand All @@ -189,20 +192,49 @@ function parse(G, { action, goTo }, input) {
if (gt === undefined) throw new Error(`undefined goto for state=${state} symbol=${symbol}`)
stack.push(gt)
} else if (a === 'acc') {
return { symbol: firstSymbol, children: nodes }
return nodes.pop()
} else {
throw new Error(`unexpected value for action ${a}`)
}
}
}

function format(ast) {
if (ast.children != null) {
return '(' + [ast.symbol, ...ast.children.map(format)].join(' ') + ')'
} else {
return ast.symbol
}
}

let grammar = [
[ "S", "S" ],
[ "S", "X", "X" ],
[ "X", "a", "X" ],
[ "X", "b" ]
[ "START", "E" ],
[ "E", "2", "E", "E" ],
[ "E", "1", "E" ],
[ "E", "0" ],
]
let sets = itemSets(grammar)
// console.log(sets)
let tab = createTable(grammar, sets)
console.log(tab)

let input = []

function add(n) {
if (n == 0) {
input.push('0')
} else {
input.push('2')
input.push('1')
add(n-1)
input.push('1')
add(n-1)
}
}

add(process.argv[2] || 16)

parse(grammar, tab, input)

console.log(format(parse(grammar, tab, ['2', '1', '0', '1', '0'])))

// console.log(tab)
Loading

0 comments on commit 8b3c059

Please sign in to comment.