Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NI-RUN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Štěpánek
NI-RUN
Commits
638f995e
Commit
638f995e
authored
1 year ago
by
Michal Štěpánek
Browse files
Options
Downloads
Patches
Plain Diff
Little bit of code fixing
parent
4dfe740d
No related branches found
No related tags found
1 merge request
!4
Task 3 odevzdání
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/bc_compiler.c
+12
-12
12 additions, 12 deletions
src/bc_compiler.c
src/bc_compiler.h
+2
-2
2 additions, 2 deletions
src/bc_compiler.h
with
14 additions
and
14 deletions
src/bc_compiler.c
+
12
−
12
View file @
638f995e
...
...
@@ -84,23 +84,23 @@ LocalScope * create_function_scope ( u8 parameters ) {
u16
get_string_index
(
BCCompilerState
*
state
,
Str
str
)
{
u16
i
;
for
(
i
=
0
;
i
<
state
->
constants
.
constant_count
;
++
i
)
if
(
state
->
constants
.
constants
[
i
]
.
kind
==
CONSTANT_STRING
&&
str_eq
(
state
->
constants
.
constants
[
i
]
.
string
,
str
)
)
;
if
(
state
->
constants
.
constants
[
i
]
.
kind
==
CONSTANT_STRING
&&
str_eq
(
state
->
constants
.
constants
[
i
]
.
string
,
str
)
)
return
i
;
insert_constant
(
state
,
(
BCConstant
)
{
.
kind
=
CONSTANT_STRING
,
.
string
=
str
}
);
return
i
;
}
u16
get_local_index
(
BCCompilerState
*
state
,
Str
name
)
{
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
];
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
]
.
function
;
LocalScope
*
scope
=
state
->
scope
;
size_t
i
;
while
(
scope
)
{
for
(
i
=
0
;
i
<
scope
->
used_locals
;
++
i
)
if
(
str_eq
(
scope
->
locals
[
i
],
name
)
)
return
function
->
parameters
+
(
scope
->
prev
?
scope
->
prev
->
local_count
+
i
);
return
function
->
parameters
+
(
scope
->
prev
?
scope
->
prev
->
local_count
+
i
:
i
);
scope
=
scope
->
prev
;
}
u
32
*
n
=
state
->
scope
->
local_count
;
u
16
*
n
=
state
->
scope
->
local_count
;
assert
(
*
n
!=
256
*
256
);
state
->
scope
->
locals
[
*
n
]
=
name
;
++
(
*
n
);
...
...
@@ -213,7 +213,7 @@ void ast_to_bc ( BCCompilerState * state, Ast * ast ) {
ast_to_bc
(
state
,
call
->
function
);
for
(
size_t
i
=
0
;
i
<
call
->
argument_cnt
;
++
i
)
ast_to_bc
(
state
,
call
->
arguments
[
i
]
);
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
];
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
]
.
function
;
string_write_byte
(
&
function
->
bc
,
0x08
);
string_write_byte
(
&
function
->
bc
,
call
->
argument_cnt
&
255
);
return
;
...
...
@@ -223,7 +223,7 @@ void ast_to_bc ( BCCompilerState * state, Ast * ast ) {
u16
index
=
get_string_index
(
state
,
print
->
format
);
for
(
size_t
i
=
0
;
i
<
print
->
argument_cnt
;
++
i
)
ast_to_bc
(
state
,
print
->
arguments
[
i
]
);
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
];
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
]
.
function
;
string_write_byte
(
&
function
->
bc
,
0x02
);
string_write_u16
(
&
function
->
bc
,
index
);
string_write_byte
(
&
function
->
bc
,
print
->
argument_cnt
&
255
);
...
...
@@ -235,7 +235,7 @@ void ast_to_bc ( BCCompilerState * state, Ast * ast ) {
if
(
!
state
->
scope
->
prev
)
{
// GLOBAL
u16
index
=
get_string_index
(
state
,
def
->
name
);
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
];
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
]
.
function
;
u16
*
count
=
&
state
->
globals
.
global_count
;
for
(
size_t
i
=
0
;
i
<
*
count
;
++
i
)
if
(
state
->
globals
.
names
[
i
]
==
index
)
...
...
@@ -247,7 +247,7 @@ void ast_to_bc ( BCCompilerState * state, Ast * ast ) {
}
else
{
// LOCAL
u16
index
=
get_local_index
(
state
,
def
->
name
);
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
];
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
]
.
function
;
string_write_byte
(
&
function
->
bc
,
0x09
);
string_write_u16
(
&
function
->
bc
,
index
);
}
...
...
@@ -258,7 +258,7 @@ void ast_to_bc ( BCCompilerState * state, Ast * ast ) {
if
(
!
state
->
scope
->
prev
)
{
// GLOBAL
u16
index
=
get_string_index
(
state
,
var
->
name
);
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
];
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
]
.
function
;
u16
*
count
=
&
state
->
globals
.
global_count
;
size_t
i
;
for
(
i
=
0
;
i
<
*
count
;
++
i
)
...
...
@@ -271,7 +271,7 @@ void ast_to_bc ( BCCompilerState * state, Ast * ast ) {
}
else
{
// LOCAL
u16
index
=
get_local_index
(
state
,
var
->
name
);
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
];
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
]
.
function
;
string_write_byte
(
&
function
->
bc
,
0x0A
);
string_write_u16
(
&
function
->
bc
,
index
);
}
...
...
@@ -285,7 +285,7 @@ void ast_to_bc ( BCCompilerState * state, Ast * ast ) {
u16
constants
=
state
->
constants
.
constant_count
;
u16
index
=
get_string_index
(
state
,
assign
->
name
);
assert
(
constants
==
state
->
constants
.
constant_count
);
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
];
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
]
.
function
;
u16
*
count
=
&
state
->
globals
.
global_count
;
size_t
i
;
for
(
i
=
0
;
i
<
*
count
;
++
i
)
...
...
@@ -300,7 +300,7 @@ void ast_to_bc ( BCCompilerState * state, Ast * ast ) {
u16
locals
=
state
->
scope
->
local_count
;
u16
index
=
get_local_index
(
state
,
assign
->
name
);
assert
(
locals
==
state
->
scope
->
local_count
);
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
];
BCFunction
*
function
=
&
state
->
constants
.
constants
[
state
->
fp
]
.
function
;
string_write_byte
(
&
function
->
bc
,
0x09
);
string_write_u16
(
&
function
->
bc
,
index
);
}
...
...
This diff is collapsed.
Click to expand it.
src/bc_compiler.h
+
2
−
2
View file @
638f995e
...
...
@@ -69,14 +69,14 @@ typedef struct BCCompilerState {
u16 ep;
} BCCompilerState;
BCConstant create_function (
Str name,
u8 parameters );
BCConstant create_function ( u8 parameters );
LocalScope * create_function_scope ( u8 parameters );
u16 get_string_index ( BCCompilerState * state, Str str );
u16 get_local_index ( BCCompilerState * state, Str name );
void gen_bc_constant ( BCCompilerState * state, u16 index );
void insert_constant ( BCCompilerState * state, Constant constant );
void insert_constant ( BCCompilerState * state,
BC
Constant constant );
void bc_state_init ( BCCompilerState * state );
void bc_state_destroy ( BCCompilerState * state );
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment