-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnative_impl.c
89 lines (76 loc) · 3.05 KB
/
native_impl.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// NanoVM, a tiny java VM for the Atmel AVR family
// Copyright (C) 2005 by Till Harbaum <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
// native_impl.c
//
#include "config.h"
#include "error.h"
#include "vm.h"
#include "nvmfile.h"
#include "native.h"
#include "native_impl.h"
#include "stack.h"
#include "native_stdio.h"
#include "native_math.h"
#include "native_formatter.h"
void native_java_lang_object_invoke(uint8_t mref) {
if(mref == NATIVE_METHOD_INIT) {
/* ignore object constructor ... */
stack_pop(); // pop object reference
} else
error(ERROR_NATIVE_UNKNOWN_METHOD);
}
void native_new(uint16_t mref) {
if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_STRINGBUFFER) {
// create empty stringbuf object and push reference onto stack
stack_push(NVM_TYPE_HEAP | heap_alloc(FALSE, 1));
} else
error(ERROR_NATIVE_UNKNOWN_CLASS);
}
void native_invoke(uint16_t mref) {
// check for native classes/methods
if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_OBJECT) {
native_java_lang_object_invoke(NATIVE_ID2METHOD(mref));
} else if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_PRINTSTREAM) {
native_java_io_printstream_invoke(NATIVE_ID2METHOD(mref));
} else if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_INPUTSTREAM) {
native_java_io_inputstream_invoke(NATIVE_ID2METHOD(mref));
} else if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_STRINGBUFFER) {
native_java_lang_stringbuffer_invoke(NATIVE_ID2METHOD(mref));
// the math class
} else if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_MATH) {
native_math_invoke(NATIVE_ID2METHOD(mref));
// the formatter class
} else if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_FORMATTER) {
native_formatter_invoke(NATIVE_ID2METHOD(mref));
// the avr specific classes
// (not used in asuro, although its avr based)
} else if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_AVR) {
//native_avr_avr_invoke(NATIVE_ID2METHOD(mref));
} else if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_PORT) {
//native_avr_port_invoke(NATIVE_ID2METHOD(mref));
} else if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_TIMER) {
//native_avr_timer_invoke(NATIVE_ID2METHOD(mref));
} else if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_ADC) {
//native_avr_adc_invoke(NATIVE_ID2METHOD(mref));
} else if(NATIVE_ID2CLASS(mref) == NATIVE_CLASS_PWM) {
//native_avr_pwm_invoke(NATIVE_ID2METHOD(mref));
} else
error(ERROR_NATIVE_UNKNOWN_CLASS);
}