@@ -11,7 +11,9 @@ import {
1111 CallExpression ,
1212 SpreadElement ,
1313 JSXNamespacedName ,
14- FunctionDeclaration , Identifier , TSTypeAnnotation , ReturnStatement ,
14+ FunctionDeclaration ,
15+ Identifier ,
16+ ReturnStatement ,
1517} from '@babel/types' ;
1618
1719export function passBlockStatement ( parent : BlockStatement , ctx : Context , builder : llvm . IRBuilder ) {
@@ -97,6 +99,11 @@ function buildFromCallExpression(
9799}
98100
99101function buildFromIdentifier ( block : Identifier , ctx : Context , builder : llvm . IRBuilder ) : llvm . Value {
102+ const variable = ctx . variables . get ( block . name ) ;
103+ if ( variable ) {
104+ return variable ;
105+ }
106+
100107 return ctx . llvmModule . getFunction ( block . name ) ;
101108}
102109
@@ -125,6 +132,10 @@ export function passVariableDeclaration(block: VariableDeclaration, ctx: Context
125132 if ( declaration . init ) {
126133 const right = buildFromExpression ( declaration . init , ctx , builder ) ;
127134
135+ if ( declaration . id . type === 'Identifier' ) {
136+ ctx . variables . set ( declaration . id . name , right ) ;
137+ }
138+
128139 return ;
129140 }
130141
@@ -154,9 +165,14 @@ export function passStatement(stmt: Statement, ctx: Context, builder: llvm.IRBui
154165 }
155166}
156167
168+ class SymbolTable extends Map < string , llvm . Value > {
169+
170+ }
171+
157172class Context {
158173 public llvmContext : llvm . LLVMContext ;
159174 public llvmModule : llvm . Module ;
175+ public variables : SymbolTable = new SymbolTable ( ) ;
160176
161177 public constructor ( ) {
162178 this . llvmContext = new llvm . LLVMContext ( ) ;
0 commit comments