mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
JavaScript unmarshalling WIP
This commit is contained in:
40
src/runtime/javascript/expr.ts
Normal file
40
src/runtime/javascript/expr.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
export class Type {
|
||||||
|
hypos!: Hypo[]
|
||||||
|
name!: string
|
||||||
|
exprs!: Expr[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Hypo {
|
||||||
|
bind_type!: boolean
|
||||||
|
var!: string
|
||||||
|
type!: Type
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Expr {
|
||||||
|
dummy!: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ExprAbs extends Expr {
|
||||||
|
|
||||||
|
}
|
||||||
|
export class ExprApp extends Expr {
|
||||||
|
|
||||||
|
}
|
||||||
|
export class ExprLit extends Expr {
|
||||||
|
|
||||||
|
}
|
||||||
|
export class ExprMeta extends Expr {
|
||||||
|
|
||||||
|
}
|
||||||
|
export class ExprFun extends Expr {
|
||||||
|
|
||||||
|
}
|
||||||
|
export class ExprVar extends Expr {
|
||||||
|
|
||||||
|
}
|
||||||
|
export class ExprTyped extends Expr {
|
||||||
|
|
||||||
|
}
|
||||||
|
export class ExprImplArg extends Expr {
|
||||||
|
|
||||||
|
}
|
||||||
68
src/runtime/javascript/ffi.ts
Normal file
68
src/runtime/javascript/ffi.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
|
|
||||||
|
import ffi from 'ffi-napi'
|
||||||
|
import ref, { Pointer } from 'ref-napi'
|
||||||
|
import ref_struct from 'ref-struct-di'
|
||||||
|
const Struct = ref_struct(ref)
|
||||||
|
|
||||||
|
export const PgfExpr = ref.refType(ref.types.void)
|
||||||
|
export const PgfLiteral = ref.refType(ref.types.void)
|
||||||
|
|
||||||
|
const PgfUnmarshallerVtbl = Struct({
|
||||||
|
eabs: ref.refType(ref.types.void),
|
||||||
|
eapp: ref.refType(ref.types.void),
|
||||||
|
elit: ref.refType(ref.types.void),
|
||||||
|
emeta: ref.refType(ref.types.void),
|
||||||
|
efun: ref.refType(ref.types.void),
|
||||||
|
evar: ref.refType(ref.types.void),
|
||||||
|
etyped: ref.refType(ref.types.void),
|
||||||
|
eimplarg: ref.refType(ref.types.void),
|
||||||
|
lint: ref.refType(ref.types.void),
|
||||||
|
lflt: ref.refType(ref.types.void),
|
||||||
|
lstr: ref.refType(ref.types.void),
|
||||||
|
dtyp: ref.refType(ref.types.void),
|
||||||
|
free_ref: ref.refType(ref.types.void)
|
||||||
|
})
|
||||||
|
export const PgfUnmarshaller = Struct({
|
||||||
|
vtbl: ref.refType(PgfUnmarshallerVtbl)
|
||||||
|
})
|
||||||
|
|
||||||
|
const elit = ffi.Callback(PgfExpr, [PgfUnmarshaller, PgfLiteral],
|
||||||
|
function (self, lit: Pointer<any>): any { // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||||
|
console.log('myelit')
|
||||||
|
console.log(' lit', lit)
|
||||||
|
return lit.deref()
|
||||||
|
})
|
||||||
|
|
||||||
|
const lint = ffi.Callback(PgfLiteral, [PgfUnmarshaller, ref.types.size_t, ref.refType(ref.types.uint)],
|
||||||
|
function (self, size: number, val: Pointer<number>): any { // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||||
|
console.log('mylint')
|
||||||
|
console.log(' size', size)
|
||||||
|
console.log(' val', val.deref())
|
||||||
|
// const x: number = val.deref()
|
||||||
|
return val
|
||||||
|
})
|
||||||
|
|
||||||
|
const free_ref = ffi.Callback(ref.types.void, [PgfUnmarshaller, ref.refType(ref.types.void)],
|
||||||
|
function (self, x: any): void { // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||||
|
console.log('free_ref')
|
||||||
|
})
|
||||||
|
|
||||||
|
const vtbl = new PgfUnmarshallerVtbl({
|
||||||
|
eabs: ref.alloc('void').ref(),
|
||||||
|
eapp: ref.alloc('void').ref(),
|
||||||
|
elit: elit as any,
|
||||||
|
emeta: ref.alloc('void').ref(),
|
||||||
|
efun: ref.alloc('void').ref(),
|
||||||
|
evar: ref.alloc('void').ref(),
|
||||||
|
etyped: ref.alloc('void').ref(),
|
||||||
|
eimplarg: ref.alloc('void').ref(),
|
||||||
|
lint: lint as any,
|
||||||
|
lflt: ref.alloc('void').ref(),
|
||||||
|
lstr: ref.alloc('void').ref(),
|
||||||
|
dtyp: ref.alloc('void').ref(),
|
||||||
|
free_ref: free_ref as any
|
||||||
|
})
|
||||||
|
|
||||||
|
export const unmarshaller = new PgfUnmarshaller({ vtbl: vtbl.ref() })
|
||||||
|
export const marshaller = {}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
|
|
||||||
import errno from './errno'
|
import errno from './errno'
|
||||||
|
import { Expr } from './expr'
|
||||||
|
import { unmarshaller, PgfUnmarshaller, PgfExpr, PgfLiteral } from './ffi'
|
||||||
|
|
||||||
import ffi from 'ffi-napi'
|
import ffi from 'ffi-napi'
|
||||||
import ref, { Pointer } from 'ref-napi'
|
import ref, { Pointer } from 'ref-napi'
|
||||||
import ref_struct, { StructObject } from 'ref-struct-di'
|
import ref_struct, { StructObject } from 'ref-struct-di'
|
||||||
@@ -40,13 +43,13 @@ const PgfType = ref.types.void // TODO
|
|||||||
const PgfTypeHypo = ref.types.void // TODO
|
const PgfTypeHypo = ref.types.void // TODO
|
||||||
const PgfTypeHypoPtr = ref.refType(PgfTypeHypo)
|
const PgfTypeHypoPtr = ref.refType(PgfTypeHypo)
|
||||||
|
|
||||||
const PgfExpr = ref.types.void // TODO
|
// const PgfExpr = ref.types.void // TODO
|
||||||
const PgfLiteral = ref.types.void // TODO
|
// const PgfLiteral = ref.types.void // TODO
|
||||||
|
|
||||||
const PgfPrintContext = ref.types.void // TODO
|
const PgfPrintContext = ref.types.void // TODO
|
||||||
const PgfPrintContextPtr = ref.refType(PgfPrintContext)
|
const PgfPrintContextPtr = ref.refType(PgfPrintContext)
|
||||||
|
|
||||||
const PgfUnmarshaller = ref.types.void // TODO
|
// const PgfUnmarshaller = ref.types.void // TODO
|
||||||
const PgfUnmarshallerPtr = ref.refType(PgfUnmarshaller)
|
const PgfUnmarshallerPtr = ref.refType(PgfUnmarshaller)
|
||||||
|
|
||||||
const PgfMarshaller = ref.types.void // TODO
|
const PgfMarshaller = ref.types.void // TODO
|
||||||
@@ -289,6 +292,14 @@ function newNGF (abstract_name: string, path?: string): PGFGrammar {
|
|||||||
return new PGFGrammar(db, rev)
|
return new PGFGrammar(db, rev)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readExpr (str: string): Expr {
|
||||||
|
const txt = PgfText_FromString(str)
|
||||||
|
const expr = runtime.pgf_read_expr(txt, unmarshaller.ref())
|
||||||
|
console.log('expr', expr)
|
||||||
|
|
||||||
|
return new Expr()
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Exposed library API
|
// Exposed library API
|
||||||
|
|
||||||
@@ -297,5 +308,7 @@ export default {
|
|||||||
readPGF,
|
readPGF,
|
||||||
bootNGF,
|
bootNGF,
|
||||||
readNGF,
|
readNGF,
|
||||||
newNGF
|
newNGF,
|
||||||
|
|
||||||
|
readExpr
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user